public function testRegenerate()
 {
     $firstId = session_id();
     $this->object->regenerate(true);
     $secondId = session_id();
     $this->assertThat($firstId, $this->logicalNot($this->equalTo($secondId)));
 }
Example #2
0
 private function initRegion(GeoIP $geoIP)
 {
     $storage = new SessionStorage();
     // TODO use binding
     if (!$storage->has('region')) {
         $storage->set('region', $this->getRegionByIp($geoIP));
     }
     $this->region = $storage->get('region');
 }
 /**
  * Constructor
  *
  * @access protected
  * @param string $storage
  * @param array 	$options 	optional parameters
  */
 protected function __construct($store = 'none', $options = array())
 {
     //Need to destroy any existing sessions started with session.auto_start
     if (session_id()) {
         session_unset();
         session_destroy();
     }
     //set default sessios save handler
     ini_set('session.save_handler', 'files');
     //disable transparent sid support
     ini_set('session.use_trans_sid', '0');
     //create handler
     if ($store != 'none' || $store != 'file') {
         require_once FRAMEWORK . '/session/SessionStorage.class.php';
         $this->_store = SessionStorage::getInstance($store, $options);
     }
     //set options
     $this->_setOptions($options);
     //load the session
     $this->_start();
     //initialise the session
     $this->_setCounter();
     $this->_setTimers();
     $this->_state = 'active';
     // perform security checks
     $this->_validate();
 }
Example #4
0
 static function logout()
 {
     SessionStorage::destroy(SJB_Session::getSessionId());
     $forumPath = SJB_Settings::getSettingByName('forum_path');
     if (empty($forumPath)) {
         return;
     }
     $url = SJB_System::getSystemSettings('SITE_URL') . $forumPath . '/';
     $client = new Zend_Http_Client($url, array('useragent' => SJB_Request::getUserAgent()));
     $client->setCookie($_COOKIE);
     $client->setCookieJar();
     try {
         $response = $client->request();
         $matches = array();
         if (preg_match('/\\.\\/ucp.php\\?mode=logout\\&sid=([\\w\\d]+)"/', $response->getBody(), $matches)) {
             $sid = $matches[1];
             $client->setUri($url . 'ucp.php?mode=logout&sid=' . $sid);
             $response = $client->request();
             foreach ($response->getHeaders() as $key => $header) {
                 if ('set-cookie' == strtolower($key)) {
                     if (is_array($header)) {
                         foreach ($header as $val) {
                             header("Set-Cookie: " . $val, false);
                         }
                     } else {
                         header("Set-Cookie: " . $header, false);
                     }
                 }
             }
         }
     } catch (Exception $ex) {
     }
 }
Example #5
0
 public static function archive($name = false, $listFilesAndFolders, $export_files_dir, $export_files_dir_name, $backupName, $move = false, $identifier, $type)
 {
     if (empty($export_files_dir)) {
         return;
     }
     $dir_separator = DIRECTORY_SEPARATOR;
     $backupName = 'backup' . $dir_separator . $backupName;
     $installFilePath = 'system' . $dir_separator . 'admin-scripts' . $dir_separator . 'miscellaneous' . $dir_separator;
     $dbSQLFilePath = 'backup' . $dir_separator;
     $old_path = getcwd();
     chdir($export_files_dir);
     $tar = new Archive_Tar($backupName, 'gz');
     if (SJB_System::getIfTrialModeIsOn()) {
         $tar->setIgnoreList(array('system/plugins/mobile', 'system/plugins/facebook_app', 'templates/mobile', 'templates/Facebook'));
     }
     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
     switch ($type) {
         case 'full':
             $tar->addModify("{$installFilePath}install.php", '', $installFilePath);
             $tar->addModify($dbSQLFilePath . $name, '', $dbSQLFilePath);
             $tar->addModify($listFilesAndFolders, '');
             SJB_Filesystem::delete($export_files_dir . $dbSQLFilePath . $name);
             break;
         case 'files':
             $tar->addModify("{$installFilePath}install.php", '', $installFilePath);
             $tar->addModify($listFilesAndFolders, '');
             break;
         case 'database':
             $tar->addModify($dbSQLFilePath . $listFilesAndFolders, '', $dbSQLFilePath);
             SJB_Filesystem::delete($export_files_dir . $dbSQLFilePath . $listFilesAndFolders);
             break;
     }
     chdir($old_path);
     return true;
 }
 public function regenerate($destroy = false)
 {
     if (!self::$regenerated) {
         session_regenerate_id($destroy);
         self::$regenerated = true;
     }
 }
Example #7
0
 public function init()
 {
     $this->_logger = Zend_Registry::get('logger');
     $this->_storage = SessionStorage::getInstance();
     $this->_user = new User();
     $this->view->loggedIn = $this->_user->loggedIn;
     $this->view->active = $this->_storage->project;
 }
Example #8
0
 function __construct()
 {
     $this->_storage = SessionStorage::getInstance();
     if (isset($this->_storage->path->fileName)) {
         $this->_pathname = $this->_storage->path->filePath;
         $this->_name = $this->_storage->path->fileName;
     }
 }
Example #9
0
 /**
  * Constructor recreates current directory array
  */
 function __construct()
 {
     $this->_logger = Zend_Registry::get('logger');
     $this->_storage = SessionStorage::getInstance();
     $this->_pathBase = $this->_storage->getDataPath();
     //$this->_logger->log($this->_pathBase, Zend_Log::INFO);
     $this->_dirArray = $this->_storage->getDirArray();
     $this->_updatePath();
 }
 static function sread($id)
 {
     $sessionconn = self::get_sessionconn();
     if (!$sessionconn) {
         return false;
     }
     $sql = "SELECT 1,`value` FROM `sessions` WHERE `sessionid` = '{$id}'";
     $result = $sessionconn->query($sql);
     if (mysqli_error($sessionconn) || !$result || !mysqli_num_rows($result)) {
         return false;
     }
     self::$data = $result->fetch_assoc();
     return stripslashes(self::$data['value']);
 }
 /**
  * Constructor
  *
  * @access protected
  * @param array $options optional parameters
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     $params = $options;
     $this->_compress = isset($params['compression']) ? $params['compression'] : 0;
     $this->_persistent = isset($params['persistent']) ? $params['persistent'] : false;
     // This will be an array of loveliness
     if (array_key_exists('servers', $params)) {
         $this->_servers = $params['servers'];
     }
     if ($params['cache']) {
         $this->_db = $params['cache'];
     }
 }
 /**
  * Initialize this Storage.
  *
  * @param Context A Context instance.
  * @param array   An associative array of initialization parameters.
  *
  * @return bool true, if initialization completes successfully, otherwise
  *              false.
  *
  * @throws <b>InitializationException</b> If an error occurs while
  *                                        initializing this Storage.
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  3.0.0
  */
 public function initialize($context, $parameters = null)
 {
     // disable auto_start
     $this->setParameter('auto_start', false);
     // initialize the parent
     parent::initialize($context, $parameters);
     if (!$this->hasParameter('db_table')) {
         // missing required 'db_table' parameter
         $error = 'Factory configuration file is missing required ' . '"db_table" parameter for the Storage category';
         throw new InitializationException($error);
     }
     // use this object as the session handler
     session_set_save_handler(array($this, 'sessionOpen'), array($this, 'sessionClose'), array($this, 'sessionRead'), array($this, 'sessionWrite'), array($this, 'sessionDestroy'), array($this, 'sessionGC'));
     // start our session
     session_start();
 }
Example #13
0
 /**
  * @covers Cart\SessionStorage::exportToDB
  * @todo   Implement testExportToDB().
  */
 public function testExportToDB()
 {
     /** Save to storage * */
     $this->object->setData(NULL);
     /** Sproduct array * */
     $data["SProducts_71_82"] = array('instance' => 'SProducts', 'id' => 82, 'quantity' => 5);
     /** ShopKit array * */
     $data['ShopKit_16'] = array('instance' => 'ShopKit', 'id' => 16, 'quantity' => 5);
     /** Save to storage * */
     $this->object->setData($data);
     /** Login **/
     doLogin();
     /** Clear database storage **/
     $dbStorage = new \Cart\DBStorage();
     $dbStorage->setData(NULL);
     $result = (bool) $this->object->exportToDB();
     $this->assertTrue($result);
 }
Example #14
0
 private function makeFullBackup($identifier, $scriptPath, $dirSeparator)
 {
     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
     $backupDir = $scriptPath;
     $name = 'db.sql';
     SJB_Backup::dump($name, $scriptPath, $identifier);
     $d = dir($scriptPath);
     $contentDir = array();
     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore', $name);
     while (false !== ($entry = $d->read())) {
         if (!in_array($entry, $folders)) {
             $contentDir[] = $entry;
         }
     }
     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
     $backupName = 'full_backup_' . date('Y_m_d__H_i') . '.tar.gz';
     $exportFilesDirName = '..' . $dirSeparator;
     if (SJB_Backup::archive($name, $listFilesAndFolders, $backupDir, $exportFilesDirName, $backupName, true, $identifier, 'full')) {
         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
     }
     if (SJB_System::getSettingByName('ftp_backup')) {
         $this->sendBackupToFtp($scriptPath . 'backup' . $dirSeparator . $backupName, $backupName);
     }
 }
Example #15
0
 public function execute()
 {
     ini_set('max_execution_time', 0);
     $errors = array();
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $dir_separator = DIRECTORY_SEPARATOR;
     $script_path = explode(SJB_System::getSystemSettings('SYSTEM_URL_BASE'), __FILE__);
     $script_path = array_shift($script_path);
     $identifier = SJB_Request::getVar('identifier', time());
     $filename = SJB_Request::getVar('filename', false);
     $settings = array();
     if ($filename) {
         SJB_Backup::sendArchiveFile($filename, $script_path . 'backup' . $dir_separator . $filename);
     }
     if (SJB_Request::getVar('action') == "save") {
         $expPeriod = SJB_Request::getVar('backup_expired_period');
         if (!empty($expPeriod) && (!is_numeric($expPeriod) || $expPeriod < 0)) {
             $errors[] = 'EXP_PERIOD_NOT_VALID';
         }
         $ftpValid = $this->isFTPDataValid();
         if (SJB_Request::getVar('autobackup', false) && SJB_Request::getVar('ftp_backup', false) && !$ftpValid) {
             $errors[] = 'FTP_DETAILS_NOT_VALID';
         }
         if (empty($errors)) {
             $backupSettings = $_REQUEST;
             foreach ($backupSettings as $setting => $value) {
                 if (!SJB_Settings::saveSetting($setting, $value)) {
                     $errors['SETTINGS_SAVED_WITH_PROBLEMS'] = "SETTINGS_SAVED_WITH_PROBLEMS";
                 }
             }
             if (empty($errors)) {
                 $tp->assign('successSaveMessage', true);
             }
         } else {
             $settings = $_REQUEST;
         }
     }
     switch ($action) {
         case 'backup':
             if (SJB_System::getSystemSettings('isDemo')) {
                 $i18N = SJB_I18N::getInstance();
                 $str = $i18N->gettext('Backend', 'Error: You don\'t have permissions for it. This is a Demo version of the software.');
                 SJB_Session::setValue('error', $str);
                 break;
             }
             if (SJB_System::getIfTrialModeIsOn() && $_SERVER['REMOTE_ADDR'] != "91.205.51.231") {
                 $i18N = SJB_I18N::getInstance();
                 $str = $i18N->gettext('Backend', 'Error: You don\'t have permissions for it. This is a Trial version of the software.');
                 SJB_Session::setValue('error', $str);
                 break;
             }
             SessionStorage::destroy('backup_' . $identifier);
             SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
             SJB_Session::unsetValue('restore');
             SJB_Session::unsetValue('error');
             $backup_type = SJB_Request::getVar('backup_type');
             $backupDir = $script_path . 'backup' . $dir_separator;
             try {
                 $this->prepareBackupDir($backupDir);
             } catch (Exception $e) {
                 SJB_Session::setValue('error', $e->getMessage());
                 exit;
             }
             switch ($backup_type) {
                 case 'full':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $backupDir = $script_path;
                     $name = 'db.sql';
                     SJB_Backup::dump($name, $script_path, $identifier);
                     $d = dir($script_path);
                     $contentDir = array();
                     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore', $name);
                     while (false !== ($entry = $d->read())) {
                         if (!in_array($entry, $folders)) {
                             $contentDir[] = $entry;
                         }
                     }
                     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
                     $backupName = 'full_backup_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '..' . $dir_separator;
                     if (SJB_Backup::archive($name, $listFilesAndFolders, $backupDir, $export_files_dir_name, $backupName, true, $identifier, 'full')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
                 case 'database':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $name = 'db.sql';
                     $backupName = 'mysqldump_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '../backup' . $dir_separator;
                     SJB_Backup::dump($name, $script_path, $identifier);
                     if (SJB_Backup::archive(false, $name, $script_path, $export_files_dir_name, $backupName, false, $identifier, 'database')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
                 case 'files':
                     SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time())));
                     $backupDir = $script_path;
                     $d = dir($script_path);
                     $contentDir = array();
                     $folders = array('.', '..', 'backup', '.svn', '.settings', '.cache', 'restore');
                     while (false !== ($entry = $d->read())) {
                         if (!in_array($entry, $folders)) {
                             $contentDir[] = $entry;
                         }
                     }
                     $listFilesAndFolders = !empty($contentDir) ? $contentDir : false;
                     $backupName = 'backup_' . date('Y_m_d__H_i') . '.tar.gz';
                     $export_files_dir_name = '..' . $dir_separator;
                     if (SJB_Backup::archive(false, $listFilesAndFolders, $backupDir, $export_files_dir_name, $backupName, true, $identifier, 'files')) {
                         SessionStorage::write('backup_' . $identifier, serialize(array('name' => $backupName)));
                     }
                     exit;
                     break;
             }
             break;
         case 'restore':
             if (SJB_System::getSystemSettings('isDemo')) {
                 SJB_Session::setValue('error', 'Error: You don\'t have permissions for it. This is a Demo version of the software.');
                 exit;
             }
             if (SJB_System::getIfTrialModeIsOn()) {
                 SJB_Session::setValue('error', 'Error: You don\'t have permissions for it. This is a Trial version of the software.');
                 exit;
             }
             SJB_Session::unsetValue('restore');
             SJB_Session::unsetValue('error');
             $error = false;
             $restoreDir = $script_path . 'restore' . $dir_separator;
             try {
                 $fileName = $this->moveUploadedFile($restoreDir);
                 $tar = new Archive_Tar($restoreDir . $fileName, 'gz');
                 $tar->_error_class = 'SJB_PEAR_Exception';
                 $tar->extractList('db.sql', $restoreDir);
                 $tar->extract($script_path);
                 if (is_file($restoreDir . 'db.sql')) {
                     SJB_Backup::restore_base_tables($restoreDir . 'db.sql');
                 }
                 SJB_Cache::getInstance()->clean();
             } catch (Exception $ex) {
                 $error = $ex->getMessage();
             }
             SJB_Filesystem::delete($restoreDir);
             if (is_file($script_path . 'install.php')) {
                 SJB_Filesystem::delete($script_path . 'install.php');
             }
             if ($error) {
                 SJB_Session::setValue('error', $error);
             } else {
                 SJB_Session::setValue('restore', 1);
             }
             exit;
             break;
         case 'send_archive':
             $name = SJB_Request::getVar('name', false);
             $archive_file_path = SJB_Path::combine(SJB_BASE_DIR . 'backup' . $dir_separator, $name);
             if ($name) {
                 SJB_Backup::sendArchiveFile($name, $archive_file_path);
             }
             break;
         case 'check':
             $sessionBackup = SessionStorage::read('backup_' . $identifier);
             $sessionBackup = $sessionBackup ? unserialize($sessionBackup) : array();
             $sessionRestore = SJB_Session::getValue('restore');
             $sessionError = SJB_Session::getValue('error');
             if (!empty($sessionBackup['name'])) {
                 $name = $sessionBackup['name'];
                 SessionStorage::destroy('backup_' . $identifier);
                 echo SJB_System::getSystemSettings('SITE_URL') . "/backup/?action=send_archive&name={$name}";
                 exit;
             } elseif (!empty($sessionRestore)) {
                 SJB_Session::unsetValue('restore');
                 echo SJB_System::getSystemSettings('SITE_URL') . '/backup/#restore';
                 exit;
             } elseif (!empty($sessionError)) {
                 echo 'Error';
                 if (SJB_System::getSystemSettings('isDemo')) {
                     echo ': You don\'t have permissions for it. This is a Demo version of the software.';
                 }
                 if (SJB_System::getIfTrialModeIsOn()) {
                     echo ': You don\'t have permissions for it. This is a Trial version of the software.';
                 }
                 exit;
             } elseif (!empty($sessionBackup['last_time'])) {
                 $period = (time() - $sessionBackup['last_time']) / 60;
                 if ($period < 5) {
                     echo 1;
                 } else {
                     SJB_Session::setValue('error', 'The backup generation process was unexpectedly interrupted. Please try again.');
                     echo 'error';
                 }
                 exit;
             } else {
                 echo 1;
             }
             exit;
             break;
         case 'delete_backup':
             $name = SJB_Request::getVar('name', false);
             if ($name) {
                 $backup = $script_path . 'backup' . $dir_separator . $name;
                 if (is_file($backup)) {
                     SJB_Filesystem::delete($backup);
                     SJB_Autobackup::deleteFileFromFtp($name);
                 } else {
                     $errors['FILE_NOT_FOUND'] = 1;
                 }
             }
             $tp->assign('errors', $errors);
             $tp->assign('delBackup', 1);
         case 'created_backups':
             $path = $script_path . 'backup' . $dir_separator;
             if (is_dir($path)) {
                 $di = new DirectoryIterator($path);
                 $backupsArr = array();
                 foreach ($di as $file) {
                     $fileName = $file->getFilename();
                     if (!$file->isDir() && !$file->isLink() && $fileName != '.htaccess') {
                         $cTime = $file->getCTime();
                         $backupsArr[$cTime]['name'] = $fileName;
                         if (preg_match('/mysqldump/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Site database only';
                         } elseif (preg_match('/full_backup/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Full site backup';
                         } elseif (preg_match('/backup/', $fileName)) {
                             $backupsArr[$cTime]['type'] = 'Site files only';
                         } else {
                             $backupsArr[$cTime]['type'] = 'Unknown';
                         }
                         $pattern = '/(\\w+)_(\\d+)_(\\d+)_(\\d+)__(\\d+)_(\\d+).tar.gz/i';
                         $replacement = '$2-$3-$4 $5:$6';
                         $backupsArr[$cTime]['date'] = preg_replace($pattern, $replacement, $fileName);
                     }
                 }
                 krsort($backupsArr);
                 $tp->assign('created_backups', $backupsArr);
             }
             $tp->display('created_backups.tpl');
             exit;
             break;
         case 'error':
             $sessionError = SJB_Session::getValue('error');
             if (!is_null($sessionError)) {
                 echo '<p class="error">' . $sessionError . '</p>';
                 exit;
             }
             break;
     }
     if (empty($settings)) {
         $settings = SJB_Settings::getSettings();
     }
     $tp->assign('errors', $errors);
     $tp->assign('settings', $settings);
     $tp->assign('identifier', $identifier);
     $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize());
     $tp->display('backup.tpl');
 }
Example #16
0
 function __construct()
 {
     $this->_db = Zend_Registry::get('dbAdapter');
     $this->_storage = SessionStorage::getInstance();
     $this->init();
 }
Example #17
0
 public function cloneRepo($name, $email, $owner, $uid)
 {
     $ownerPath2 = substr($this->_worktree, 0, -strlen(strrchr($this->_worktree, '/')));
     $ownerPath = substr($ownerPath2, 0, -strlen(strrchr($ownerPath2, '/'))) . '/' . $owner . '/';
     $clonePath = SessionStorage::getInstance()->getGitClonePath();
     $properPath = $this->_worktree;
     //worktree needs to be set up for ssh based git shells
     $this->_worktree = $clonePath;
     chdir($this->_worktree);
     $target = $uid;
     $this->_logger->log($clonePath, Zend_Log::INFO);
     $this->_logger->log($target, Zend_Log::INFO);
     $result = $this->_run(self::cloneRepo, array($ownerPath, $target));
     //after running clone the proper user folder should exist now
     $this->_worktree = $properPath;
     chdir($this->_worktree);
     $this->_run(self::config_name, $name);
     $this->_run(self::config_email, $email);
 }
Example #18
0
 public function setData($name, $value)
 {
     if ($this->isStarted()) {
         $this->storage->setData($this->id, $name, $value);
     }
 }
 /**
  * @return array|null
  */
 public function fetchCurrentUser()
 {
     if (!$this->userLoggedIn()) {
         return null;
     }
     $username = SessionStorage::getValue('username');
     return $this->_db->fetchOne('users', ['username' => $username]);
 }