forked from zer.ooo/web
[wip]
This commit is contained in:
parent
81875e455e
commit
23c3cf530e
3 changed files with 42 additions and 15 deletions
|
@ -1,12 +1,15 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
namespace Zerobae\Panel;
|
||||
$basedir = realpath(__DIR__ . '/../');
|
||||
# All calls are now relative to the root directory
|
||||
chdir($basedir);
|
||||
|
||||
include __DIR__ . '/../vendor/autoload.php';
|
||||
include $basedir . '/vendor/autoload.php';
|
||||
|
||||
$core = new \Eater\Glim\Core();
|
||||
$core->startTimer(["total"]);
|
||||
$core->boot($basedir);
|
||||
echo $core->get('user')->createInvite();
|
||||
$core->endTimer(["total"]);
|
||||
|
||||
$config = new Config();
|
||||
$controller = new Controller($config);
|
||||
|
||||
echo $controller->createInvite() . "\n";
|
||||
|
|
|
@ -46,21 +46,32 @@ class Server extends Main
|
|||
|
||||
/** @var CA $ca */
|
||||
$ca = $this->get('ca');
|
||||
|
||||
$data['signature'] = $ca->signWithCA($server->getFingerprint());
|
||||
|
||||
$data['signature'] = bin2hex($ca->signWithCA($server->getFingerprint()));
|
||||
|
||||
$json = json_encode($data);
|
||||
|
||||
$password = bin2hex(openssl_random_pseudo_bytes(32));
|
||||
$pubKey = openssl_get_publickey($server->getPublicKey());
|
||||
|
||||
$success = openssl_public_encrypt($json, $crypted, $pubKey, OPENSSL_NO_PADDING);
|
||||
$success = openssl_public_encrypt($password, $crypted, $pubKey, OPENSSL_PKCS1_PADDING);
|
||||
|
||||
if (!$success) {
|
||||
throw new \Exception('Encrypting data failed: ' . openssl_error_string() . openssl_error_string());
|
||||
}
|
||||
|
||||
$this->get('logger')->addDebug('Password: ' . $password);
|
||||
|
||||
$body = [
|
||||
bin2hex($crypted),
|
||||
bin2hex(openssl_encrypt($server->getCertificate(), 'aes-256-cbc', $password, 'help'))
|
||||
];
|
||||
|
||||
$this->get('logger')->addDebug('Help: ' . var_export([$json, $body], true));
|
||||
|
||||
|
||||
return $client->post('http://' . $server->getExternalIp() . ':' . static::MANAGEMENT_PORT . $path, [
|
||||
'body' => $crypted
|
||||
'json' => $body
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Eater\Glim\Service;
|
|||
|
||||
use Eater\Glim\Model\Base\UserQuery;
|
||||
use Eater\Glim\Model\InviteQuery;
|
||||
use Eater\Glim\Model\Invite;
|
||||
use Eater\Glim\Model\User as UserModel;
|
||||
|
||||
class User extends Main
|
||||
|
@ -44,7 +45,7 @@ class User extends Main
|
|||
public function exists($username)
|
||||
{
|
||||
$amount = UserQuery::create()->findByUsername($username)->count();
|
||||
|
||||
|
||||
return $amount > 0;
|
||||
}
|
||||
|
||||
|
@ -55,7 +56,19 @@ class User extends Main
|
|||
if ($user === null || !password_verify($password, $user->getPassword())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function createInvite()
|
||||
{
|
||||
$invite = new Invite();
|
||||
$invite->setInvite(bin2hex(openssl_random_pseudo_bytes(20)));
|
||||
$invite->save();
|
||||
|
||||
return $invite->getInvite();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue