Example #1
0
 public static function logIt($arr)
 {
     $engineLog = new EngineLog();
     $engineLog->user_id = $arr['user_id'];
     $engineLog->method = $arr['method'];
     $engineLog->status_message = $arr['return'];
     if (!$engineLog->save()) {
         Log::error('Engine Log Save ' . $engineLog->errors());
     }
 }
Example #2
0
 public static function executeAction($instanceAction, $account, $instanceID)
 {
     $response = '';
     switch ($instanceAction) {
         case 'start':
             $response = self::getDriver($account)->startInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID)));
             break;
         case 'stop':
             $response = self::getDriver($account)->stopInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID)));
             break;
         case 'restart':
             $response = self::getDriver($account)->restartInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID)));
             break;
         case 'terminate':
             $response = self::getDriver($account)->terminateInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID)));
             break;
         case 'describeInstances':
             $response = self::getDriver($account)->describeInstances(array('DryRun' => false, 'InstanceIds' => array($instanceID)));
             break;
         case 'downloadKey':
             $responseJson = xDockerEngine::authenticate(array('username' => Auth::user()->username, 'password' => md5(Auth::user()->engine_key)));
             EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'authenticate-executeAction', 'return' => $responseJson));
             $obj = json_decode($responseJson);
             if (!empty($obj) && $obj->status == 'OK') {
                 $response = xDockerEngine::downloadKey(array('token' => $obj->token, 'cloudProvider' => $account->cloudProvider, 'instanceRegion' => $account->instanceRegion));
                 Log::info('downloadKey Json:' . $response);
                 if (StringHelper::isJson($response)) {
                     $response = json_decode($response, true);
                     $response['message'] = 'Key is returned in field key';
                 } else {
                     $response = array('status' => 'error', 'message' => 'Error occured while downloading keys');
                 }
             } else {
                 if (!empty($obj) && $obj->status == 'error') {
                     Log::error('Error occured while downloading key' . $obj->message);
                     $response = array('status' => $obj->status, 'message' => 'Unexpected error! Contact Support');
                 } else {
                     Log::error('Error occured while downloading key');
                     $response = array('status' => 'error', 'message' => 'Unexpected error! Contact Support');
                 }
             }
             break;
     }
     return $response;
 }
Example #3
0
 /**
  * Remove the specified user from storage.
  *
  * @param $user
  * @return Response
  */
 public function postDelete($user)
 {
     // Check if we are not trying to delete ourselves
     if ($user->id === Confide::user()->id) {
         // Redirect to the user management page
         return Redirect::to('admin/users')->with('error', Lang::get('admin/users/messages.delete.impossible'));
     }
     AssignedRoles::where('user_id', $user->id)->delete();
     $id = $user->id;
     $username = $user->username;
     $responseJson = xDockerEngine::authenticate(array('username' => $user->username, 'password' => md5($user->engine_key)));
     EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'authenticate', 'return' => $responseJson));
     $obj = json_decode($responseJson);
     if (!empty($obj) && $obj->status == 'OK') {
         $response = xDockerEngine::removeUsername(array('token' => $obj->token));
         Log::info('xDocker Engine user is deleted!');
     }
     if (!empty($obj) && $obj->status == 'error') {
         Log::error('xDocker Engine user deletion : Failed in authentication');
     } else {
         Log::error('xDocker Engine user deletion - Unexpected error');
     }
     $user->delete();
     // Was the comment post deleted?
     $user = User::find($id);
     if (empty($user)) {
         // TODO needs to delete all of that user's content
         return Redirect::to('admin/users')->with('success', Lang::get('admin/users/messages.delete.success'));
     } else {
         // There was a problem deleting the user
         return Redirect::to('admin/users')->with('error', Lang::get('admin/users/messages.delete.error'));
     }
 }
Example #4
0
 public static function getxDockerServiceStatus()
 {
     $responseJson = xDockerEngine::authenticate(array('username' => Auth::user()->username, 'password' => md5(Auth::user()->engine_key)));
     EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'getxDockerServiceStatus : authenticate', 'return' => $responseJson));
     $status = 'error';
     if (StringHelper::isJson($responseJson)) {
         $obj = json_decode($responseJson);
         if (!empty($obj) && $obj->status == 'OK') {
             $status = 'OK';
         }
     }
     return $status;
 }
Example #5
0
 public function getLogs($id)
 {
     $this->check();
     $deployment = Deployment::where('user_id', Auth::id())->find($id);
     if (!empty($deployment) && isset($deployment->job_id)) {
         $responseJson = xDockerEngine::authenticate(array('username' => Auth::user()->username, 'password' => md5(Auth::user()->engine_key)));
         EngineLog::logIt(array('user_id' => Auth::id(), 'method' => 'authenticate', 'return' => $responseJson));
         $obj = json_decode($responseJson);
         if (!empty($obj) && $obj->status == 'OK') {
             $response = xDockerEngine::getLog(array('token' => $obj->token, 'job_id' => $deployment->job_id, "line_num" => 10));
             return View::make('site/deployment/logs', array('response' => $response, 'deployment' => $deployment));
         } else {
             if (!empty($obj) && $obj->status == 'error') {
                 Log::error('Request to deploy failed :' . $obj2->fail_code . ':' . $obj2->fail_message);
                 Log::error('Log :' . implode(' ', $obj2->job_log));
                 return Redirect::to('deployment')->with('error', $obj->fail_message);
             } else {
                 return Redirect::to('ServiceStatus')->with('error', 'Backend API is down, please try again later!');
             }
         }
     } else {
         if (empty($deployment)) {
             return Redirect::to('deployment')->with('info', 'No deployments found! ');
         } else {
             return Redirect::to('deployment')->with('info', 'No logs found! ');
         }
     }
 }
Example #6
0
 private static function checkSocialEmailAndLogin($email)
 {
     // Check if user with email exists, otherwise create one and finaly log them in
     // Used by socialLogin and amazonLogin
     $user = User::where('email', $email)->first();
     if (empty($user)) {
         // Register
         $user = new User();
         $user->email = $email;
         // Generate a username from the email for compatibility with Confide's schema
         $user->username = preg_replace('/[\\s\\W]+/', '_', $email);
         // Assign a random password for compatibility with Confide's Auth
         $randomPass = Hash::make(uniqid(mt_rand(), true));
         $user->password = $randomPass;
         $user->password_confirmation = $randomPass;
         $user->confirmation_code = md5(uniqid(mt_rand(), true));
         // Set as confirmed by default since we have social proof
         $user->confirmed = 1;
         $user->display_name = $user->username;
         $user->engine_key = Hash::make(uniqid(mt_rand(), true));
         // var_dump('created', $user->save() , $user->errors());
         if (!$user->save()) {
             throw new Exception($user->errors());
         }
         // Register the user on the engine
         $return = xDockerEngine::register(array('username' => $user->username, 'password' => $user->engine_key));
         Log::info("Return Status : " . $return);
         EngineLog::logIt(array('user_id' => $user->id, 'method' => 'register', 'return' => $return));
     }
     // return Confide::logAttempt((array) $user);
     return Auth::loginUsingId($user->id);
 }