Ejemplo n.º 1
0
$authType = @$_POST['alauda_auth_type'];
$token = @$_POST['alauda_token'];
$username = @$_POST['alauda_username'];
$password = @$_POST['alauda_password'];
if (!$authType or $authType != 'token' and $authType != 'password' or $authType == 'token' and !$token or $authType == 'password' and (!$username or !$password)) {
    echo json_encode(['status' => 1, 'msg' => '信息不完整']);
    exit;
}
try {
    if ($authType == 'password') {
        // get token
        $apiReturn = AlaudaApi::generateToken($username, $password);
        $token = $apiReturn['token'];
    }
    // fetch service info
    $result = AlaudaApi::getService($username, 'xjc-shadowsocks', $token);
    if (!isset($result['is_deploying']) or $result['is_deploying']) {
        // deploying
        $return = ['status' => 0, 'stage' => 1];
    } else {
        // deploy successfully
        $env = json_decode($result['instance_envvars'], true);
        $return = ['status' => 0, 'stage' => 2, 'data' => ['default_domain_name' => $result['default_domain_name'], 'service_port' => $result['instance_ports'][0]['service_port'], 'method' => $env['METHOD'], 'ss_password' => $env['PASSWORD']]];
    }
    echo json_encode($return);
    exit;
} catch (Exception $e) {
    $message = $e->getMessage();
    if (preg_match('/Unable to login with provided credentials/', $message)) {
        $return = ['status' => 1, 'msg' => $message];
    } elseif (preg_match('/Not found/', $message)) {
Ejemplo n.º 2
0
$timeout = @$_POST['ss_timeout'];
$method = @$_POST['ss_method'];
$workers = @$_POST['ss_workers'];
$authType = @$_POST['alauda_auth_type'];
$token = @$_POST['alauda_token'];
$username = @$_POST['alauda_username'];
$password = @$_POST['alauda_password'];
if (!$ssPassword or !$timeout or !$method or !$workers or !$authType or $authType != 'token' and $authType != 'password' or $authType == 'token' and !$token or $authType == 'password' and (!$username or !$password)) {
    echo json_encode(['status' => 1, 'msg' => '信息不完整']);
    exit;
}
try {
    if ($authType == 'password') {
        // get token
        $apiReturn = AlaudaApi::generateToken($username, $password);
        $token = $apiReturn['token'];
    }
    $payload = ['service_name' => 'xjc-shadowsocks', 'image_name' => 'index.alauda.cn/xjchengo/shadowsocks', 'image_tag' => 'latest', 'instance_size' => 'XS', 'scaling_mode' => 'MANUAL', 'target_state' => 'STARTED', 'target_num_instances' => '1', 'instance_envvars' => ['PASSWORD' => (string) $ssPassword, 'TIMEOUT' => (string) $timeout, 'METHOD' => (string) $method, 'WORKERS' => (string) $workers], 'instance_ports' => [['container_port' => 8388, 'protocol' => 'tcp']]];
    $result = AlaudaApi::createService($username, $payload, $token);
    if ($result != null) {
        echo json_encode(['status' => 1, 'msg' => json_encode($result)]);
        error_log(json_encode($result) . "\n", 3, './error.log');
    } else {
        echo json_encode(['status' => 0]);
    }
    exit;
} catch (Exception $e) {
    echo json_encode(['status' => 1, 'msg' => $e->getMessage()]);
    error_log($e->getMessage() . "\n", 3, './error.log');
    exit;
}