/** * Returns all the blog posts. * * @return View */ public function getIndex() { $response = ''; if (!Auth::check()) { return Redirect::to('/')->with('error', Lang::get('genera.must_login')); } return View::make('site/serviceStatus/index', array('vars' => array(Lang::get('site.docker_service') => xDockerEngine::getDockerServiceStatus(), Lang::get('site.webservice') => xDockerEngine::getxDockerServiceStatus()))); }
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; }
/** * Returns all the blog posts. * * @return View */ public function getIndex() { if (Auth::check()) { //$deployments = Deployment::where('user_id', Auth::id())->get(); $deployments = DeploymentQueryHelper::getQuery($this->deployments, 10); } else { $deployments = array(); } try { $search_term = Input::get('q'); if (empty($search_term)) { $search_term = 'xdocker'; } $response = xDockerEngine::dockerHubGet($search_term); $dockerInstances = !empty($response) ? $response->results : ''; } catch (Exception $e) { Log::error('Exception while loading docker images!'); $dockerInstances = array(); } // Show the page return View::make('site/home/index', array('deployments' => $deployments, 'search_term' => $search_term, 'dockerInstances' => $dockerInstances)); }
/** * 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')); } }
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; }
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! '); } } }
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); }
<!-- <button alt="Terminates the Instance from your AWS account." title="Terminates the Instance from your AWS account." type="submit" class="btn btn-warning pull-right" role="button"><span class="glyphicon glyphicon-trash"></span></button> --> </form> <div class="media-body"> <h4 class="media-heading">{{ String::title($deployment->name) }} </h4> <p> <?php $url = URL::to('deployment/' . $deployment->id . '/instanceAction'); $downloadUrl = URL::to('deployment/' . $deployment->id . '/downloadKey'); $logUrl = URL::to('deployment/' . $deployment->id . '/log'); if (in_array($deployment->status, array('Completed', 'start', 'stop'))) { $instanceState = CloudProvider::getState($deployment->cloudAccountId, $result->instance_id); $anchor = '<a target="_blank" href="' . xDockerEngine::getProtocol($deployment->docker_name) . $result->public_dns . xDockerEngine::urlAppend($deployment->docker_name) . '">' . xDockerEngine::getDisplayName($deployment->docker_name) . '</a>'; echo $result->instance_id . ' ' . $instanceState . ' | ' . xDockerEngine::getDockerUrl($deployment->docker_name) . ' | ' . $anchor . ' | ' . xDockerEngine::documentationUrl($deployment->docker_name) . ' | <a title="Support" alt="Support" class="glyphicon glyphicon-envelope" href="mailto:support@xervmon.com"></a>' . ' | <a title="Contact Xervmon to manage this" alt="Contact Xervmon to manage this" href="mailto:support@xervmon.com"><img src="' . asset('assets/ico/favicon.ico') . '"/></a>' . ' | <a title="Download" href="#" onclick="downloadKey(\'' . $downloadUrl . '\',\'' . $result->instance_id . '\', \'' . csrf_token() . '\')"><span class="glyphicon glyphicon-cloud-download"> </span> Pem </a>' . ' | <a title="ViewLog" href="' . $logUrl . '" ><span class="glyphicon glyphicon-th-list"> </span> </a>'; } else { echo xDockerEngine::getDockerUrl($deployment->docker_name) . ' | ' . xDockerEngine::getDisplayName($deployment->docker_name) . ' | ' . xDockerEngine::documentationUrl($deployment->docker_name) . ' | <a title="Support" alt="Support" class="glyphicon glyphicon-envelope" href="mailto:support@xervmon.com"></a>' . ' | <a title="Contact Xervmon to manage this" alt="Contact Xervmon to manage this" href="mailto:support@xervmon.com"><img src="' . asset('assets/ico/favicon.ico') . '"/></a>' . ' | <a title="Download" href="#" onclick="downloadKey(\'' . $downloadUrl . '\',\'' . $result->instance_id . '\', \'' . csrf_token() . '\')"><span class="glyphicon glyphicon-cloud-download"> </span> Pem </a>' . ' | <a title="ViewLog" href="' . $logUrl . '" ><span class="glyphicon glyphicon-th-list"> </span> </a>'; } ?> @if($deployment->status == 'Completed' && isset($result->public_dns)) @if (strpos($instanceState, 'running') !== false) <span title="Created At"><a href="{{{URL::to('deployment/docker/'.$deployment->id.'/Containers')}}}">{{ ' | '}}<span class="fa fa-info"></span></a> </span> @endif @endif </p> <p> {{UIHelper::getDataOrganized($deployment->parameters)}} </p>