public function editAction() { $this->view->headTitle('Configuration Management'); $this->view->headLink()->appendStylesheet("/css/template/form.css"); $this->view->headLink()->appendStylesheet("/css/pages/configs_edit.css"); $projects = new GD_Model_ProjectsMapper(); $project_slug = $this->_getParam("project"); if ($project_slug != "") { $project = $projects->getProjectBySlug($project_slug); } $this->view->project = $project; $configs_map = new GD_Model_ConfigsMapper(); $config = new GD_Model_Config(); $config_id = $this->_getParam("id"); $configs_servers_map = new GD_Model_ConfigsServersMapper(); $config_server_ids = array(); $servers_map = new GD_Model_ServersMapper(); $servers = $servers_map->getServersByProject($project->getId()); $this->view->servers = $servers; $user = GD_Auth_Database::GetLoggedInUser(); if ($config_id > 0) { $configs_map->find($config_id, $config); $config_servers = $configs_servers_map->getAllServersForConfig($config->getId()); foreach ($config_servers as $cs) { $config_server_ids[] = $cs->getServersId(); } } else { $config->setProjectsId($project->getId()); $config->setDateAdded(date("Y-m-d H:i:s")); $config->setAddedUsersId($user->getId()); foreach ($servers as $server) { $config_server_ids[] = $server->getId(); } } $this->view->config_server_ids = $config_server_ids; if ($this->getRequest()->isPost()) { // First save the config file itself $config->setFilename($this->_getParam("filename", "")); $config->setContent($this->_getParam("configContent", "")); $config->setUpdatedUsersId($user->getId()); $configs_map->save($config); // Then loop through the config_servers and update $configs_servers_map->deleteAllServersForConfig($config->getId()); $add_to_servers = $this->_getParam("servers", array()); foreach ($add_to_servers as $server_id) { $cs = new GD_Model_ConfigServer(); $cs->setConfigsId($config->getId()); $cs->setServersId($server_id); $configs_servers_map->save($cs); } $this->_redirect($this->getFrontController()->getBaseUrl() . "/project/" . $this->_getParam("project") . "/configs"); } else { $this->view->config = $config; } }
/** * Initialise the navigation system * * (non-PHPdoc) * @see Zend_Controller_Plugin_Abstract::preDispatch() */ public function preDispatch(Zend_Controller_Request_Abstract $request) { // Get the view to populate the navigation and logged_in status $view = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view; $view->logged_in = Zend_Auth::getInstance()->hasIdentity(); // If we are on the error controller, return immediately to prevent // any database errors happening on error page if ($request->controller == "error") { return; } $nav = array(); if ($view->logged_in) { // Always add home link $nav[] = array("label" => "Home", "id" => "home-link", "uri" => "/home"); // If we're in a project, add in the things you can do if ($project_slug = $request->getParam("project")) { $projects = new GD_Model_ProjectsMapper(); $project = $projects->getProjectBySlug($project_slug); if ($project instanceof GD_Model_Project) { $nav[] = array("label" => "History", "id" => "deployments-link", "uri" => "/project/{$project_slug}/history"); $nav[] = array("label" => "Configs", "id" => "configs-link", "uri" => "/project/{$project_slug}/configs"); $nav[] = array("label" => "Settings", "id" => "settings-link", "uri" => "/project/{$project_slug}/settings"); $nav[] = array("label" => "Deploy", "id" => "deploy-link", "uri" => "/project/{$project_slug}/deploy"); } } else { $nav[] = array("label" => "Profile", "id" => "profile-link", "uri" => "/profile"); // Get the logged in user - if they're an admin, add the admin // menu $user = GD_Auth_Database::GetLoggedInUser(); if ($user->isAdmin()) { $nav[] = array("label" => "Admin", "id" => "admin-link", "uri" => "/admin"); } } } else { $nav[] = array("label" => "Login", "id" => "login-link", "uri" => "/auth/login"); } // Create a Zend_Navigation object from the above array $nav = new Zend_Navigation($nav); $view->navigation($nav); // This finds out if the current URL matches one of the menu items // and sets the active page if it does. $uri = $request->getRequestUri(); $page = $view->navigation()->findOneBy("uri", $uri); if ($page) { $page->setActive(); } }
public function changepasswordAction() { $this->view->headTitle('Change Password'); $this->view->headLink()->appendStylesheet("/css/template/form.css"); $this->view->headLink()->appendStylesheet("/css/pages/profile.css"); $form = new GDApp_Form_ChangePassword(); $this->view->form = $form; if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getParams())) { $password = $this->_request->getParam('password'); $crypt = new GD_Crypt(); $user = GD_Auth_Database::GetLoggedInUser(); $userMapper = new GD_Model_UsersMapper(); $user->setPassword($crypt->makeHash($password)); $userMapper->save($user); $this->view->success = true; } } }
public function indexAction() { $this->view->headTitle('New Deployment'); $this->view->headScript()->appendFile($this->getFrontController()->getBaseUrl() . "/js/pages/deploy_setup.js"); $this->view->headLink()->appendStylesheet("/css/template/form.css"); $this->view->headLink()->appendStylesheet("/css/pages/deploy.css"); $projects = new GD_Model_ProjectsMapper(); $project_slug = $this->_getParam("project"); if ($project_slug != "") { $project = $projects->getProjectBySlug($project_slug); } if (is_null($project)) { throw new GD_Exception("Project '{$project_slug}' was not set up."); } $this->view->project = $project; $form = new GDApp_Form_DeploymentSetup($project->getId()); $this->view->form = $form; $deployments = new GD_Model_DeploymentsMapper(); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getParams())) { $user = GD_Auth_Database::GetLoggedInUser(); $server_id = $this->_request->getParam('serverId', false); $last_deployment = $deployments->getLastSuccessfulDeployment($project->getId(), $server_id); if (!is_null($last_deployment)) { $from_rev = $last_deployment->getToRevision(); } else { $from_rev = ""; } $git = GD_Git::FromProject($project); $git->gitPull(); $input_to_rev = $this->_request->getParam('toRevision', false); $comment = $this->_request->getParam('comment', ''); try { $to_rev = $git->getFullHash($input_to_rev); $deployment = new GD_Model_Deployment(); $deployment->setUsersId($user->getId())->setProjectsId($project->getId())->setWhen(date("Y-m-d H:i:s"))->setServersId($server_id)->setFromRevision($from_rev)->setToRevision($to_rev)->setComment($comment)->setDeploymentStatusesId(1); $deployments->save($deployment); // Generate the list of files to deploy and save in deployment_files table try { $files_changed = $git->getFilesChangedList($deployment->getFromRevision(), $deployment->getToRevision()); } catch (GD_Exception $ex) { if ($ex->getStringCode() == GD_Git::GIT_GENERAL_NO_FILES_CHANGED) { $files_changed = array(); } else { throw $ex; } } $deployment_files = new GD_Model_DeploymentFilesMapper(); $deployment_file_statuses = new GD_Model_DeploymentFileStatusesMapper(); $deployment_file_actions = new GD_Model_DeploymentFileActionsMapper(); foreach ($files_changed as $fc) { $deployment_file = new GD_Model_DeploymentFile(); $deployment_file->setDeploymentsId($deployment->getId()); $deployment_file->setDeploymentFileActionsId($deployment_file_actions->getDeploymentFileActionByGitStatus($fc['action'])->getId()); $deployment_file->setDeploymentFileStatusesId($deployment_file_statuses->getDeploymentFileStatusByCode('NEW')->getId()); $deployment_file->setDetails($fc['file']); $deployment_files->save($deployment_file); } // Add any additional configuration files $config_servers_map = new GD_Model_ConfigsServersMapper(); $configs = $config_servers_map->getAllConfigsForServer($server_id); foreach ($configs as $config) { $c = $config->getConfig(); $cfile = "!CFG!{$c->getId()}!{$c->getFilename()}"; $deployment_file = new GD_Model_DeploymentFile(); $deployment_file->setDeploymentsId($deployment->getId()); $deployment_file->setDeploymentFileActionsId($deployment_file_actions->getDeploymentFileActionByGitStatus('M')->getId()); $deployment_file->setDeploymentFileStatusesId($deployment_file_statuses->getDeploymentFileStatusByCode('NEW')->getId()); $deployment_file->setDetails($cfile); $deployment_files->save($deployment_file); } // Forward to either run or preview page... if ($this->_request->getParam('submitRun_x') > 0) { // go to run $this->_redirect($this->getFrontController()->getBaseUrl() . "/project/" . $this->_getParam("project") . "/deploy/run/" . $deployment->getId()); } else { if ($this->_request->getParam('submitPreview_x') > 0) { // go to preview $this->_redirect($this->getFrontController()->getBaseUrl() . "/project/" . $this->_getParam("project") . "/deploy/preview/" . $deployment->getId()); } } } catch (GD_Exception $ex) { if ($ex->getStringCode() === GD_Git::GIT_GENERAL_EMPTY_REF) { $form->toRevision->addError("Empty ref: " . $ex->getMessage()); } else { if ($ex->getStringCode() === GD_Git::GIT_GENERAL_INVALID_REF) { $form->toRevision->addError("This revision could not be found in this project. Please check it."); $form->addError("error"); } else { throw $ex; } } } } } else { $git = GD_Git::FromProject($project); try { $git->checkValidRepository(); } catch (GD_Exception $ex) { if ($ex->getStringCode() == GD_Git::GIT_STATUS_ERROR_NOT_A_REPOSITORY || $ex->getStringCode() == GD_Git::GIT_STATUS_ERROR_DIFFERENT_REPOSITORY) { $return_url = base64_encode($this->_request->getRequestUri()); $this->_redirect($this->getFrontController()->getBaseUrl() . "/error/reclone?project=" . $this->_getParam("project") . "&return=" . $return_url); } else { throw $ex; } } $data = array(); if (count($data) > 0) { $form->populate($data); } } }