コード例 #1
0
ファイル: account.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * Read SSH key
  *
  * @return string - .ssh/authorized_keys file content
  */
 private function readKey()
 {
     // Webdav path
     $base = DS . 'webdav' . DS . 'home';
     $user = DS . $this->member->get('username');
     $ssh = DS . '.ssh';
     $auth = DS . 'authorized_keys';
     // Real home directory
     $homeDir = $this->member->get('homeDirectory');
     $key = '';
     // First, make sure webdav is there and that the necessary folders are there
     if (!Filesystem::exists($base)) {
         // Not sure what to do here
         return $key = false;
     }
     if (!Filesystem::exists($homeDir)) {
         // Try to create their home directory
         require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'helpers' . DS . 'utils.php';
         if (!\Components\Tools\Helpers\Utils::createHomeDirectory($this->member->get('username'))) {
             return $key = false;
         }
     }
     if (!Filesystem::exists($base . $user . $ssh)) {
         // User doesn't have an ssh directory, so try to create one (with appropriate permissions)
         if (!Filesystem::makeDirectory($base . $user . $ssh, 0700, true, true)) {
             return $key = false;
         }
     }
     if (!Filesystem::exists($base . $user . $ssh . $auth)) {
         // Try to create their authorized keys file
         $content = '';
         // J25 passes param by reference so couldn't use constant below
         Filesystem::write($base . $user . $ssh . $auth, $content);
         if (!Filesystem::exists($base . $user . $ssh . $auth)) {
             return $key = false;
         } else {
             // Set correct permissions on authorized_keys file
             Filesystem::setPermissions($base . $user . $ssh . $auth, '0600');
             return $key;
         }
     }
     // Read the file contents
     $key = Filesystem::read($base . $user . $ssh . $auth);
     return $key;
 }
コード例 #2
0
ファイル: source.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Method to store the source file contents.
  *
  * @param	array	The souce data to save.
  *
  * @return	boolean	True on success, false otherwise and internal error set.
  * @since	1.6
  */
 public function save($data)
 {
     // Get the template.
     $template = $this->getTemplate();
     if (empty($template)) {
         return false;
     }
     $fileName = $this->getState('filename');
     $client = JApplicationHelper::getClientInfo($template->client_id);
     $filePath = \Hubzero\Filesystem\Util::normalizePath($client->path . '/templates/' . $template->element . '/' . $fileName);
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     // Try to make the template file writeable.
     if (!$ftp['enabled'] && JPath::isOwner($filePath) && !Filesystem::setPermissions($filePath, '0644')) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'));
         return false;
     }
     // Trigger the onExtensionBeforeSave event.
     $result = Event::trigger('extension.onExtensionBeforeSave', array('com_templates.source', &$data, false));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // [!] HUBZERO - Force line endings to be consistent with the server environment
     $data['source'] = preg_replace('~\\R~u', PHP_EOL, $data['source']);
     $return = Filesystem::write($filePath, $data['source']);
     // Try to make the template file unwriteable.
     if (!$ftp['enabled'] && JPath::isOwner($filePath) && !Filesystem::setPermissions($filePath, '0444')) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE'));
         return false;
     } elseif (!$return) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName));
         return false;
     }
     // Trigger the onExtensionAfterSave event.
     Event::trigger('extension.onExtensionAfterSave', array('com_templates.source', &$table, false));
     return true;
 }
コード例 #3
0
ファイル: projects.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * Activate provisioned project
  *
  * @return     void
  */
 public function activateTask()
 {
     // Cannot proceed without project id/alias
     if (!$this->model->exists()) {
         throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404);
         return;
     }
     // Must be project creator
     if (!$this->model->access('owner')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Must be a provisioned project to be activated
     if (!$this->model->isProvisioned()) {
         // Redirect to project page
         App::redirect(Route::url($this->model->link()));
         return;
     }
     // Redirect to setup if activation not complete
     if ($this->model->inSetup()) {
         App::redirect(Route::url($this->model->link('setup')));
         return;
     }
     // Get publication of a provisioned project
     $pub = $this->model->getPublication();
     if (empty($pub)) {
         throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404);
         return;
     }
     // Incoming
     $name = trim(Request::getVar('new-alias', '', 'post'));
     $title = trim(Request::getVar('title', '', 'post'));
     $confirm = trim(Request::getInt('confirm', 0, 'post'));
     $name = preg_replace('/ /', '', $name);
     $name = strtolower($name);
     // Check incoming data
     $verified = $this->model->check($name, $this->model->get('id'));
     if ($confirm && !$verified) {
         $error = $this->model->getError() ? $this->model->getError() : Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY');
         $this->setError($error);
     } elseif ($confirm && ($title == '' || strlen($title) < 3)) {
         $this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY'));
     }
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     // Display page
     if (!$confirm || $this->getError()) {
         $this->view->setLayout('provisioned');
         $this->view->model = $this->model;
         $this->view->team = $this->model->_tblOwner->getOwnerNames($this->model->get('alias'));
         // Output HTML
         $this->view->pub = isset($pub) ? $pub : '';
         $this->view->suggested = $name;
         $this->view->verified = $verified;
         $this->view->suggested = $verified ? $this->view->suggested : '';
         $this->view->title = $this->title;
         $this->view->active = $this->active;
         $this->view->task = $this->_task;
         $this->view->authorized = 1;
         $this->view->option = $this->_option;
         $this->view->msg = $this->_getNotifications('success');
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         $this->view->display();
         return;
     }
     // Save new alias & title
     if (!$this->getError()) {
         $this->model->set('title', \Hubzero\Utility\String::truncate($title, 250));
         $this->model->set('alias', $name);
         $state = $this->_setupComplete == 3 ? 0 : 1;
         $this->model->set('state', $state);
         $this->model->set('setup_stage', 2);
         $this->model->set('provisioned', 0);
         $this->model->set('modified', Date::toSql());
         $this->model->set('modified_by', User::get('id'));
         // Save changes
         if (!$this->model->store()) {
             $this->setError($this->model->getError());
         }
     }
     // Get project parent directory
     $path = Helpers\Html::getProjectRepoPath($this->model->get('alias'));
     $newpath = Helpers\Html::getProjectRepoPath($name, 'files', true);
     // Rename project parent directory
     if ($path && is_dir($path)) {
         if (!Filesystem::copyDirectory($path, $newpath)) {
             $this->setError(Lang::txt('COM_PROJECTS_FAILED_TO_COPY_FILES'));
         } else {
             // Correct permissions to 0755
             Filesystem::setPermissions($newpath);
             // Delete original repo
             Filesystem::deleteDirectory($path);
         }
     }
     // Log activity
     $this->_logActivity($this->model->get('id'), 'provisioned', 'activate', 'save', 1);
     // Send to continue setup
     App::redirect(Route::url($this->model->link('setup')));
     return;
 }