/**
  * Install a given package.
  */
 public function install()
 {
     $this->requireAdmin();
     $package = $this->getParam('package', null);
     $version = $this->getParam('version', '*');
     $json = $this->getComposerJson();
     $json['require'][$package] = $version;
     $this->setComposerJson($json);
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'plugin?w=' . $package);
     return $response;
 }
 /**
  * Returns the appropriate build status image in SVG format for a given project.
  */
 public function image($projectId)
 {
     $status = $this->getStatus($projectId);
     if (is_null($status)) {
         $response = new b8\Http\Response\RedirectResponse();
         $response->setHeader('Location', '/');
         return $response;
     }
     $color = $status == 'passing' ? 'green' : 'red';
     $image = file_get_contents('http://img.shields.io/badge/build-' . $status . '-' . $color . '.svg');
     $this->response->disableLayout();
     $this->response->setHeader('Content-Type', 'image/svg+xml');
     $this->response->setContent($image);
     return $this->response;
 }
Beispiel #3
0
 /**
  * Initialise PHPCI - Handles session verification, routing, etc.
  */
 public function init()
 {
     $request =& $this->request;
     $route = '/:controller/:action';
     $opts = array('controller' => 'Home', 'action' => 'index');
     // Inlined as a closure to fix "using $this when not in object context" on 5.3
     $validateSession = function () {
         if (!empty($_SESSION['phpci_user_id'])) {
             $user = b8\Store\Factory::getStore('User')->getByPrimaryKey($_SESSION['phpci_user_id']);
             if ($user) {
                 $_SESSION['phpci_user'] = $user;
                 return true;
             }
             unset($_SESSION['phpci_user_id']);
         }
         return false;
     };
     $skipAuth = array($this, 'shouldSkipAuth');
     // Handler for the route we're about to register, checks for a valid session where necessary:
     $routeHandler = function (&$route, Response &$response) use(&$request, $validateSession, $skipAuth) {
         $skipValidation = in_array($route['controller'], array('session', 'webhook', 'build-status'));
         if (!$skipValidation && !$validateSession() && (!is_callable($skipAuth) || !$skipAuth())) {
             if ($request->isAjax()) {
                 $response->setResponseCode(401);
                 $response->setContent('');
             } else {
                 $_SESSION['phpci_login_redirect'] = substr($request->getPath(), 1);
                 $response = new RedirectResponse($response);
                 $response->setHeader('Location', PHPCI_URL . 'session/login');
             }
             return false;
         }
         return true;
     };
     $this->router->clearRoutes();
     $this->router->register($route, $opts, $routeHandler);
 }
Beispiel #4
0
 /**
  * Edit a project. Handles both the form and processing.
  */
 public function edit($projectId)
 {
     $this->requireAdmin();
     $method = $this->request->getMethod();
     $project = $this->projectStore->getById($projectId);
     if (empty($project)) {
         throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
     }
     $this->layout->title = $project->getTitle();
     $this->layout->subtitle = Lang::get('edit_project');
     $values = $project->getDataArray();
     $values['key'] = $values['ssh_private_key'];
     $values['pubkey'] = $values['ssh_public_key'];
     if ($values['type'] == "gitlab") {
         $accessInfo = $project->getAccessInformation();
         $reference = $accessInfo["user"] . '@' . $accessInfo["domain"] . ':' . $accessInfo["port"] . '/' . ltrim($project->getReference(), '/') . ".git";
         $values['reference'] = $reference;
     }
     if ($method == 'POST') {
         $values = $this->getParams();
     }
     $form = $this->projectForm($values, 'edit/' . $projectId);
     if ($method != 'POST' || $method == 'POST' && !$form->validate()) {
         $view = new b8\View('ProjectForm');
         $view->type = 'edit';
         $view->project = $project;
         $view->form = $form;
         $view->key = $values['pubkey'];
         return $view->render();
     }
     $title = $this->getParam('title', Lang::get('new_project'));
     $reference = $this->getParam('reference', null);
     $type = $this->getParam('type', null);
     $options = array('ssh_private_key' => $this->getParam('key', null), 'ssh_public_key' => $this->getParam('pubkey', null), 'build_config' => $this->getParam('build_config', null), 'allow_public_status' => $this->getParam('allow_public_status', 0), 'archived' => $this->getParam('archived', 0), 'branch' => $this->getParam('branch', null), 'group' => $this->getParam('group_id', null));
     $project = $this->projectService->updateProject($project, $title, $type, $reference, $options);
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'project/view/' . $project->getId());
     return $response;
 }
 /**
  * Returns the appropriate build status image in SVG format for a given project.
  */
 public function image($projectId)
 {
     $style = $this->getParam('style', 'plastic');
     $label = $this->getParam('label', 'build');
     $status = $this->getStatus($projectId);
     if (is_null($status)) {
         $response = new b8\Http\Response\RedirectResponse();
         $response->setHeader('Location', '/');
         return $response;
     }
     $color = $status == 'passing' ? 'green' : 'red';
     $image = file_get_contents(sprintf('http://img.shields.io/badge/%s-%s-%s.svg?style=%s', $label, $status, $color, $style));
     $this->response->disableLayout();
     $this->response->setHeader('Content-Type', 'image/svg+xml');
     $this->response->setContent($image);
     return $this->response;
 }
Beispiel #6
0
 /**
  * Delete a build.
  */
 public function delete($buildId)
 {
     $this->requireAdmin();
     $build = BuildFactory::getBuildById($buildId);
     if (empty($build)) {
         throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
     }
     $this->buildService->deleteBuild($build);
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'project/view/' . $build->getProjectId());
     return $response;
 }
 /**
  * Github redirects users back to this URL when t
  */
 public function githubCallback()
 {
     $code = $this->getParam('code', null);
     $github = $this->settings['phpci']['github'];
     if (!is_null($code)) {
         $http = new HttpClient();
         $url = 'https://github.com/login/oauth/access_token';
         $params = array('client_id' => $github['id'], 'client_secret' => $github['secret'], 'code' => $code);
         $resp = $http->post($url, $params);
         if ($resp['success']) {
             parse_str($resp['body'], $resp);
             $this->settings['phpci']['github']['token'] = $resp['access_token'];
             $this->storeSettings();
             $response = new b8\Http\Response\RedirectResponse();
             $response->setHeader('Location', PHPCI_URL . 'settings?linked=1');
             return $response;
         }
     }
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'settings?linked=2');
     return $response;
 }
 /**
  * Allows the user to change their password after a password reset email.
  * @param $userId
  * @param $key
  * @return string
  */
 public function resetPassword($userId, $key)
 {
     $user = $this->userStore->getById($userId);
     $userKey = md5(date('Y-m-d') . $user->getHash());
     if (empty($user) || $key != $userKey) {
         $this->view->error = Lang::get('reset_invalid');
         return $this->view->render();
     }
     if ($this->request->getMethod() == 'POST') {
         $hash = password_hash($this->getParam('password'), PASSWORD_DEFAULT);
         $user->setHash($hash);
         $_SESSION['phpci_user'] = $this->userStore->save($user);
         $_SESSION['phpci_user_id'] = $user->getId();
         $response = new b8\Http\Response\RedirectResponse();
         $response->setHeader('Location', PHPCI_URL);
         return $response;
     }
     $this->view->id = $userId;
     $this->view->key = $key;
     return $this->view->render();
 }
Beispiel #9
0
 /**
  * Delete a project group.
  * @param $groupId
  * @return b8\Http\Response\RedirectResponse
  */
 public function delete($groupId)
 {
     $this->requireAdmin();
     $group = $this->groupStore->getById($groupId);
     $this->groupStore->delete($group);
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'group');
     return $response;
 }
Beispiel #10
0
 /**
  * Delete a user.
  */
 public function delete($userId)
 {
     $this->requireAdmin();
     $user = $this->userStore->getById($userId);
     if (empty($user)) {
         throw new NotFoundException(Lang::get('user_n_not_found', $userId));
     }
     $this->userService->deleteUser($user);
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'user');
     return $response;
 }
Beispiel #11
0
 /**
  * Callback if permission denied to access
  *
  * @param $user
  * @param $uri
  * @param $response
  */
 protected function permissionDenied($user, $uri, &$response)
 {
     $_SESSION['GlobalMessage']['error'] = 'You do not have permission to access: ' . $uri;
     $log = Log::create(Log::TYPE_PERMISSION, 'user', 'Unauthorised access attempt.');
     $log->setUser($user);
     $log->setLink($uri);
     $log->save();
     $response = new RedirectResponse($response);
     $response->setHeader('Location', $this->config->get('site.full_admin_url'));
     $response->flush();
 }