[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
|
#!/usr/bin/env php
|
||||||
<?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";
|
|
||||||
|
|
|
@ -47,20 +47,31 @@ class Server extends Main
|
||||||
/** @var CA $ca */
|
/** @var CA $ca */
|
||||||
$ca = $this->get('ca');
|
$ca = $this->get('ca');
|
||||||
|
|
||||||
$data['signature'] = $ca->signWithCA($server->getFingerprint());
|
$data['signature'] = bin2hex($ca->signWithCA($server->getFingerprint()));
|
||||||
|
|
||||||
$json = json_encode($data);
|
$json = json_encode($data);
|
||||||
|
|
||||||
|
$password = bin2hex(openssl_random_pseudo_bytes(32));
|
||||||
$pubKey = openssl_get_publickey($server->getPublicKey());
|
$pubKey = openssl_get_publickey($server->getPublicKey());
|
||||||
|
$success = openssl_public_encrypt($password, $crypted, $pubKey, OPENSSL_PKCS1_PADDING);
|
||||||
$success = openssl_public_encrypt($json, $crypted, $pubKey, OPENSSL_NO_PADDING);
|
|
||||||
|
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
throw new \Exception('Encrypting data failed: ' . openssl_error_string() . openssl_error_string());
|
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, [
|
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\Base\UserQuery;
|
||||||
use Eater\Glim\Model\InviteQuery;
|
use Eater\Glim\Model\InviteQuery;
|
||||||
|
use Eater\Glim\Model\Invite;
|
||||||
use Eater\Glim\Model\User as UserModel;
|
use Eater\Glim\Model\User as UserModel;
|
||||||
|
|
||||||
class User extends Main
|
class User extends Main
|
||||||
|
@ -58,4 +59,16 @@ class User extends Main
|
||||||
|
|
||||||
return $user;
|
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