/** 
  * Process stored event
  */
 function process()
 {
     list($group_id, $shortname, $is_used) = $this->getParametersAsArray();
     if ($project = $this->getProject($group_id)) {
         // If 'CVS' was activated, create the repo (if it does not exist) and regenerate cvs_root_allow.
         // if 'CVS' was inactivated... keep the repository, and do nothing.
         if ($shortname == 'cvs' && $is_used) {
             // This function will not create the repo if it already exists
             if (!Backend::instance('CVS')->createProjectCVS($group_id)) {
                 $this->error("Could not create CVS repo for project {$group_id} after service activation");
                 return false;
             }
             Backend::instance('CVS')->setCVSRootListNeedUpdate();
         }
         // Same as for CVS.
         if ($shortname == 'svn' && $is_used) {
             $backendSVN = Backend::instance('SVN');
             if (!$backendSVN->createProjectSVN($group_id)) {
                 $this->error("Could not create SVN repo for project {$group_id} after service activation");
                 return false;
             }
             $backendSVN->setSVNApacheConfNeedUpdate();
         }
         $this->done();
         return true;
     }
     return false;
 }
 public function process()
 {
     global $sys_allow_restricted_users;
     $parameters = $this->getParametersAsArray();
     $project = null;
     if (!empty($parameters[0])) {
         $project = $this->getProject($parameters[0]);
     } else {
         $this->error('Missing argument project id');
         return false;
     }
     $repositoryName = '';
     if (!empty($parameters[1])) {
         $repositoryName = $parameters[1];
     } else {
         $this->error('Missing argument repository name');
         return false;
     }
     $userId = 0;
     if (!empty($parameters[2])) {
         $userId = $parameters[2];
     } else {
         $this->error('Missing argument user id');
         return false;
     }
     try {
         $repository = new GitRepository();
         $repository->setBackend(Backend::instance('Git', 'GitBackend'));
         $repository->setDescription('-- Default description --');
         //default access is private when restricted users are allowed
         if ($sys_allow_restricted_users == 1) {
             $repository->setAccess(GitRepository::PRIVATE_ACCESS);
         } else {
             $repository->setAccess(GitRepository::PUBLIC_ACCESS);
         }
         $user = null;
         if (!empty($userId)) {
             $user = UserManager::instance()->getUserById($userId);
         }
         if (!empty($user)) {
             $repository->setCreator($user);
         }
         $repository->setProject($project);
         $repository->setName($repositoryName);
         $repository->create();
         $this->done();
     } catch (GitDaoException $e) {
         $this->error($e->getMessage());
         return false;
     } catch (GitDriverException $e) {
         $this->error($e->getMessage());
         return false;
     } catch (GitBackendException $e) {
         $this->error($e->getMessage());
         return false;
     } catch (Exception $e) {
         $this->error($e->getMessage());
         return false;
     }
 }
 /**
  * Perform user creation on system
  * 
  * @param PFUser $user
  * 
  * @return Boolean
  */
 private function createUser(PFUser $user)
 {
     Backend::instance('Aliases')->setNeedUpdateMailAliases();
     $system_backend = Backend::instance('System');
     $system_backend->flushNscdAndFsCache();
     return $system_backend->createUserHome($user);
 }
 public function getProcessForQueue($request_queue)
 {
     $owner = SystemEvent::OWNER_APP;
     $custom_queues = array();
     $this->event_manager->processEvent(Event::SYSTEM_EVENT_GET_CUSTOM_QUEUES, array('queues' => &$custom_queues));
     if (isset($custom_queues[$request_queue])) {
         $this->logger = $custom_queues[$request_queue]->getLogger();
         $this->logger->debug('Processing ' . $request_queue . ' queue.');
         $process = new SystemEventProcessCustomQueue($request_queue);
         $owner = $custom_queues[$request_queue]->getOwner();
     } else {
         switch ($request_queue) {
             case SystemEvent::OWNER_APP:
                 $this->logger->debug('Processing default queue as app user.');
                 $process = new SystemEventProcessApplicationOwnerDefaultQueue();
                 break;
             case SystemEvent::DEFAULT_QUEUE:
                 $this->logger->debug('Processing default queue as root user.');
                 $owner = SystemEvent::OWNER_ROOT;
                 $process = new SystemEventProcessRootDefaultQueue();
                 break;
             default:
                 $this->logger->debug('Ignoring ' . $request_queue . ' queue.');
                 exit(0);
         }
     }
     if ($owner === SystemEvent::OWNER_APP) {
         return new SystemEventProcessor_ApplicationOwner($process, $this->system_event_manager, new SystemEventDao(), $this->logger);
     }
     return new SystemEventProcessor_Root($process, $this->system_event_manager, new SystemEventDao(), $this->logger, Backend::instance('Aliases'), Backend::instance('CVS'), Backend::instance('SVN'), Backend::instance('System'), new SiteCache($this->logger));
 }
Пример #5
0
 public static function Instance()
 {
     if (self::$instance == null) {
         self::$instance = new Backend();
     }
     return self::$instance;
 }
 public function process()
 {
     // Need to update aliases
     Backend::instance('Aliases')->setNeedUpdateMailAliases();
     $this->done();
     return true;
 }
 /** 
  * Process stored event
  */
 function process()
 {
     list($group_id, $project_is_private) = $this->getParametersAsArray();
     if ($project = $this->getProject($group_id)) {
         if ($project->usesCVS()) {
             if (!Backend::instance('CVS')->setCVSPrivacy($project, $project_is_private)) {
                 $this->error("Could not set cvs privacy for project {$group_id}");
                 return false;
             }
         }
         if ($project->usesSVN()) {
             $backendSVN = Backend::instance('SVN');
             if (!$backendSVN->setSVNPrivacy($project, $project_is_private)) {
                 $this->error("Could not set svn privacy for project {$group_id}");
                 return false;
             }
             if (!$backendSVN->updateSVNAccess($group_id)) {
                 $this->error("Could not update svn access file for project {$group_id}");
                 return false;
             }
         }
         //allows to link plugins to this system event
         $this->callSystemEventListeners(__CLASS__);
         $this->done();
         return true;
     }
     return false;
 }
 /** 
  * Process stored event
  */
 function process()
 {
     list($group_id, $user_id) = $this->getParametersAsArray();
     if ($project = $this->getProject($group_id)) {
         if ($user_id == 0) {
             return $this->setErrorBadParam();
         }
         // CVS writers
         if ($project->usesCVS()) {
             if (!Backend::instance('CVS')->updateCVSwriters($group_id)) {
                 $this->error("Could not update CVS writers for group {$group_id}");
                 return false;
             }
         }
         // SVN access file
         if ($project->usesSVN()) {
             if (!Backend::instance('SVN')->updateSVNAccess($group_id)) {
                 $this->error("Could not update SVN access file ({$group_id})");
                 return false;
             }
         }
         // Need to update system group cache
         Backend::instance('System')->setNeedRefreshGroupCache();
         $this->done();
         return true;
     }
     return false;
 }
Пример #9
0
 /**
  * Some files might have been generated as root but should be owned by codendiadm
  */
 public function restoreOwnership()
 {
     $backend = Backend::instance();
     $this->logger->debug("Restore ownership to " . $GLOBALS['Language']->getCacheDirectory());
     $backend->recurseChownChgrp($GLOBALS['Language']->getCacheDirectory(), ForgeConfig::get('sys_http_user'), ForgeConfig::get('sys_http_user'));
     $plugin_manager = PluginManager::instance();
     $this->logger->debug("Restore ownership to " . $plugin_manager->getCacheFile());
     $backend->changeOwnerGroupMode($plugin_manager->getCacheFile(), ForgeConfig::get('sys_http_user'), ForgeConfig::get('sys_http_user'), 0600);
 }
Пример #10
0
 /**
  * Return a Backend instance
  *
  * Let plugins propose their own backend. If none provided, use the default one.
  *
  * @return Backend
  */
 public static function getBackend()
 {
     $backend = null;
     $params = array('backend' => &$backend);
     EventManager::instance()->processEvent('backend_factory_get_backend', $params);
     if ($backend === null) {
         $backend = Backend::instance();
     }
     return $backend;
 }
Пример #11
0
 public function get_system_event_class($params)
 {
     switch ($params['type']) {
         case 'SVN_CREATE_REPOSITORY':
             include_once dirname(__FILE__) . '/events/SystemEvent_SVN_CREATE_REPOSITORY.class.php';
             $params['class'] = 'SystemEvent_SVN_CREATE_REPOSITORY';
             $params['dependencies'] = array(Backend::instance(Backend::SVN));
             break;
     }
 }
Пример #12
0
 public function tearDown()
 {
     parent::tearDown();
     EventManager::clearInstance();
     unset($GLOBALS['homedir_prefix']);
     $backend = Backend::instance();
     $backend->recurseDeleteInDir($this->toto_home);
     rmdir($this->toto_home);
     $backend->recurseDeleteInDir($this->foobar_home);
     rmdir($this->foobar_home);
 }
 public function process()
 {
     $user_id = $this->getIdFromParam($this->parameters);
     if ($user = UserManager::instance()->getUserById($user_id)) {
         if (!Backend::instance('System')->dumpSSHKeysForUser($user)) {
             $this->error("Could not dump ssh keys for user " . $user->getUserName());
             return false;
         }
     } else {
         $this->error("Could not create/initialize user object");
         return false;
     }
     $this->done();
     return true;
 }
 /** 
  * Process stored event
  */
 function process()
 {
     list($group_id, $cvs_is_private) = $this->getParametersAsArray();
     if ($project = $this->getProject($group_id)) {
         if ($project->usesCVS()) {
             if (!Backend::instance('CVS')->setCVSPrivacy($project, $cvs_is_private)) {
                 $this->error("Could not set cvs is private for group {$group_id}");
                 return false;
             }
         }
         $this->done();
         return true;
     }
     return false;
 }
 /** 
  * Process stored event
  */
 function process()
 {
     // Check parameters
     $group_list_id = $this->getIdFromParam($this->parameters);
     if ($group_list_id == 0) {
         return $this->setErrorBadParam();
     }
     if (!Backend::instance('MailingList')->createList($group_list_id)) {
         $this->error("Could not create mailing list {$group_list_id}");
         return false;
     }
     // Need to add list aliases
     Backend::instance('Aliases')->setNeedUpdateMailAliases();
     $this->done();
     return true;
 }
Пример #16
0
 /**
  * Some files might have been generated as root but should be owned by codendiadm
  */
 public function restoreOwnership()
 {
     $backend = Backend::instance();
     $cache_directory = ForgeConfig::get('codendi_cache_dir');
     $this->logger->debug('Restore ownership to ' . $cache_directory);
     $backend->changeOwnerGroupMode($cache_directory, ForgeConfig::get('sys_http_user'), ForgeConfig::get('sys_http_user'), 0750);
     $combined_cache_directory = ForgeConfig::get('sys_combined_dir');
     $this->logger->debug('Restore ownership to ' . $combined_cache_directory);
     $backend->recurseChownChgrp($combined_cache_directory, ForgeConfig::get('sys_http_user'), ForgeConfig::get('sys_http_user'));
     $language_cache_directory = $GLOBALS['Language']->getCacheDirectory();
     $this->logger->debug('Restore ownership to ' . $language_cache_directory);
     $backend->recurseChownChgrp($language_cache_directory, ForgeConfig::get('sys_http_user'), ForgeConfig::get('sys_http_user'));
     $plugin_manager = PluginManager::instance();
     $plugin_cache_file = $plugin_manager->getCacheFile();
     $this->logger->debug('Restore ownership to ' . $plugin_cache_file);
     $backend->changeOwnerGroupMode($plugin_cache_file, ForgeConfig::get('sys_http_user'), ForgeConfig::get('sys_http_user'), 0600);
 }
 /** 
  * Process stored event
  */
 function process()
 {
     // Check parameters
     $user_id = $this->getIdFromParam($this->parameters);
     if ($user_id == 0) {
         return $this->setErrorBadParam();
     }
     // Need to remove user alias
     Backend::instance('Aliases')->setNeedUpdateMailAliases();
     // Archive user home directory
     if (!Backend::instance('System')->archiveUserHome($user_id)) {
         $this->error("Could not archive user home");
         return false;
     }
     $this->done();
     return true;
 }
 /**
  * Process stored event
  */
 public function process()
 {
     // Re-dumping ssh keys should be done only once a day as:
     // - It's I/O intensive
     // - It's stress gitolite backend
     // - SSH keys should already be dumped via EDIT_SSH_KEY event
     $backend_system = Backend::instance('System');
     $backend_system->dumpSSHKeys();
     // User home sanity check should be done only once a day as
     // it is slooow (due to libnss-mysql)
     $this->userHomeSanityCheck($backend_system);
     try {
         $this->_getEventManager()->processEvent('root_daily_start', array());
         $this->done();
     } catch (Exception $e) {
         $this->error($e->getMessage());
     }
     return true;
 }
Пример #19
0
   public static function singleton() 
   {
      if (!isset(self::$instance)) {
      
         $backend = Config::singleton()->Backend;   
         if(!$backend)
         {
            throw new BackendNotSpecifiedException("Backend type not specified, please specify one in the config.");
         }
         
         // The backend type is supplied by the code, so we don't bother to check if the file exists 
         // (it will simply throw an error if it doesn't).
         require_once($_SERVER["DOCUMENT_ROOT"] . 'includes/framework/backends/class.'.$backend.'Backend.php');
      
         $c = $backend.'Backend';
         self::$instance = new $c;
      }

      return self::$instance;
   } 
 /** 
  * Process stored event
  */
 function process()
 {
     $ugroup_name = null;
     $ugroup_old_name = null;
     // Check parameters
     if (count($this->getParametersAsArray()) == 4) {
         list($group_id, $ugroup_id, $ugroup_name, $ugroup_old_name) = $this->getParametersAsArray();
     } else {
         list($group_id, $ugroup_id) = $this->getParametersAsArray();
     }
     if ($project = $this->getProject($group_id)) {
         // Update SVN access file
         if ($project->usesSVN()) {
             $backendSVN = Backend::instance('SVN');
             if (!$backendSVN->updateSVNAccess($group_id, $ugroup_name, $ugroup_old_name)) {
                 $this->error("Could not update SVN access file ({$group_id})");
                 return false;
             }
         }
     }
     $this->done();
     return true;
 }
 /** 
  * Process stored event
  */
 function process()
 {
     $groups = explode(',', $this->parameters);
     $backendSystem = Backend::instance('System');
     // Force NSCD flush (otherwise uid & gid will not exist)
     $backendSystem->flushNscdAndFsCache();
     foreach ($groups as $group_id) {
         if ($project = $this->getProject($group_id)) {
             if (!$backendSystem->createProjectHome($group_id)) {
                 $this->error("Could not create project home");
                 return false;
             }
             if ($project->usesCVS()) {
                 $backendCVS = Backend::instance('CVS');
                 if (!$backendCVS->createProjectCVS($group_id)) {
                     $this->error("Could not create/initialize project CVS repository");
                     return false;
                 }
                 $backendCVS->setCVSRootListNeedUpdate();
                 $backendCVS->setCVSPrivacy($project, !$project->isPublic() || $project->isCVSPrivate());
             }
             if ($project->usesSVN()) {
                 $backendSVN = Backend::instance('SVN');
                 if (!$backendSVN->createProjectSVN($group_id)) {
                     $this->error("Could not create/initialize project SVN repository");
                     return false;
                 }
                 $backendSVN->setSVNApacheConfNeedUpdate();
                 $backendSVN->setSVNPrivacy($project, !$project->isPublic());
             }
             $backendSystem->log("Project " . $project->getUnixName() . " created");
         }
     }
     $this->done();
     return true;
 }
Пример #22
0
 /**
  * Instantiate a SystemEvent from a row
  *
  * @param array $row The data of the event
  *
  * @return SystemEvent
  */
 public function getInstanceFromRow($row)
 {
     $em = EventManager::instance();
     $sysevent = null;
     $klass = null;
     $klass_params = null;
     switch ($row['type']) {
         case SystemEvent::TYPE_SYSTEM_CHECK:
         case SystemEvent::TYPE_EDIT_SSH_KEYS:
         case SystemEvent::TYPE_PROJECT_CREATE:
         case SystemEvent::TYPE_PROJECT_DELETE:
         case SystemEvent::TYPE_PROJECT_RENAME:
         case SystemEvent::TYPE_MEMBERSHIP_CREATE:
         case SystemEvent::TYPE_MEMBERSHIP_DELETE:
         case SystemEvent::TYPE_UGROUP_MODIFY:
         case SystemEvent::TYPE_USER_CREATE:
         case SystemEvent::TYPE_USER_DELETE:
         case SystemEvent::TYPE_USER_EMAIL_CHANGED:
         case SystemEvent::TYPE_USER_RENAME:
         case SystemEvent::TYPE_MAILING_LIST_CREATE:
         case SystemEvent::TYPE_MAILING_LIST_DELETE:
         case SystemEvent::TYPE_CVS_IS_PRIVATE:
         case SystemEvent::TYPE_PROJECT_IS_PRIVATE:
         case SystemEvent::TYPE_SERVICE_USAGE_SWITCH:
         case SystemEvent::TYPE_ROOT_DAILY:
         case SystemEvent::TYPE_COMPUTE_MD5SUM:
             $klass = 'SystemEvent_' . $row['type'];
             break;
         case SystemEvent::TYPE_SVN_UPDATE_HOOKS:
             $klass = 'SystemEvent_' . $row['type'];
             $klass_params = array(Backend::instance(Backend::SVN));
             break;
         default:
             $em->processEvent(Event::GET_SYSTEM_EVENT_CLASS, array('type' => $row['type'], 'class' => &$klass, 'dependencies' => &$klass_params));
             break;
     }
     $sysevent = $this->instanciateSystemEventByType($row['id'], class_exists($klass) ? $klass : $row['type'], $row['owner'], $row['parameters'], $row['priority'], $row['status'], $row['create_date'], $row['process_date'], $row['end_date'], $row['log']);
     if ($sysevent && !empty($klass_params)) {
         call_user_func_array(array($sysevent, 'injectDependencies'), $klass_params);
     }
     return $sysevent;
 }
Пример #23
0
 public static function isNameAvailable($newName, &$error)
 {
     $b1 = new Git_Backend_Gitolite(new Git_GitoliteDriver());
     $b2 = Backend::instance('Git', 'GitBackend');
     if (!$b1->isNameAvailable($newName) && !$b2->isNameAvailable($newName)) {
         $error = $GLOBALS['Language']->getText('plugin_git', 'actions_name_not_available');
         return false;
     }
     return true;
 }
Пример #24
0
 private function getProftpdSystemEventManager()
 {
     return new \Tuleap\ProFTPd\SystemEventManager(SystemEventManager::instance(), Backend::instance(), $this->getPermissionsManager(), ProjectManager::instance(), $this->getPluginInfo()->getPropVal('proftpd_base_directory'));
 }
Пример #25
0
 public function updateMainConfIncludes($project)
 {
     if (is_file($this->confFilePath)) {
         $conf = file_get_contents($this->confFilePath);
     } else {
         $conf = '';
     }
     if (strpos($conf, 'include "projects/' . $project->getUnixName() . '.conf"') === false) {
         $backend = Backend::instance();
         if ($conf) {
             $backend->removeBlock($this->confFilePath);
         }
         $newConf = '';
         $dir = new DirectoryIterator('conf/projects');
         foreach ($dir as $file) {
             if (!$file->isDot()) {
                 $newConf .= 'include "projects/' . basename($file->getFilename()) . '"' . PHP_EOL;
             }
         }
         if ($backend->addBlock($this->confFilePath, $newConf)) {
             return $this->gitAdd($this->confFilePath);
         }
         return false;
     }
     return true;
 }
Пример #26
0
EventManager::instance()->processEvent(Event::SYSTEM_EVENT_GET_CUSTOM_QUEUES, array('queues' => &$custom_queues));
if (isset($custom_queues[$request_queue])) {
    $logger = $custom_queues[$request_queue]->getLogger();
    $logger->debug('Processing ' . $request_queue . ' queue.');
    $process = new SystemEventProcessCustomQueue($request_queue);
    $owner = $custom_queues[$request_queue]->getOwner();
} else {
    switch ($request_queue) {
        case SystemEvent::OWNER_APP:
            $logger->debug('Processing default queue as app user.');
            $process = new SystemEventProcessApplicationOwnerDefaultQueue();
            break;
        case SystemEvent::DEFAULT_QUEUE:
            $logger->debug('Processing default queue as root user.');
            $owner = SystemEvent::OWNER_ROOT;
            $process = new SystemEventProcessRootDefaultQueue();
            break;
        default:
            $logger->debug('Ignoring ' . $request_queue . ' queue.');
            exit(0);
    }
}
if ($owner === SystemEvent::OWNER_APP) {
    require_once 'common/system_event/SystemEventProcessor_ApplicationOwner.class.php';
    $processor = new SystemEventProcessor_ApplicationOwner($process, $system_event_manager, new SystemEventDao(), $logger);
} else {
    require_once 'common/system_event/SystemEventProcessor_Root.class.php';
    $processor = new SystemEventProcessor_Root($process, $system_event_manager, new SystemEventDao(), $logger, Backend::instance('Aliases'), Backend::instance('CVS'), Backend::instance('SVN'), Backend::instance('System'), new SiteCache($logger));
}
$mutex = new SystemEventProcessorMutex(new SystemEventProcessManager(), $processor);
$mutex->execute();
Пример #27
0
 public function get_system_event_class($params)
 {
     switch ($params['type']) {
         case 'PLUGIN_LDAP_UPDATE_LOGIN':
             include_once dirname(__FILE__) . '/system_event/SystemEvent_PLUGIN_LDAP_UPDATE_LOGIN.class.php';
             $params['class'] = 'SystemEvent_PLUGIN_LDAP_UPDATE_LOGIN';
             $params['dependencies'] = array(UserManager::instance(), Backend::instance(Backend::SVN), ProjectManager::instance(), new LDAP_ProjectManager());
             break;
     }
 }
Пример #28
0
 public function removeTemporaryDirectory()
 {
     $backend = Backend::instance('System');
     if (is_dir($this->dir)) {
         $backend->recurseDeleteInDir($this->dir);
         rmdir($this->dir);
     }
 }
Пример #29
0
 /**
  * Display git backend statistics in CSV format
  *
  * @param Array $params parameters of the event
  *
  * @return void
  */
 public function statistics_collector($params)
 {
     if (!empty($params['formatter'])) {
         include_once 'GitBackend.class.php';
         $formatter = $params['formatter'];
         $gitBackend = Backend::instance('Git', 'GitBackend');
         echo $gitBackend->getBackendStatistics($formatter);
     }
 }
Пример #30
0
 /**
  * Display git backend statistics in CSV format
  *
  * @param Array $params parameters of the event
  *
  * @return void
  */
 public function statistics_collector($params)
 {
     if (!empty($params['formatter'])) {
         include_once 'GitBackend.class.php';
         $formatter = $params['formatter'];
         $gitBackend = Backend::instance('Git', 'GitBackend', array($this->getGitRepositoryUrlManager()));
         echo $gitBackend->getBackendStatistics($formatter);
     }
 }