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 doBackup() { $settings = SJB_Settings::getSettings(); if ($settings['autobackup'] && !SJB_System::getSystemSettings('isDemo') && !SJB_System::getIfTrialModeIsOn()) { $dirSeparator = DIRECTORY_SEPARATOR; $scriptPath = explode(SJB_System::getSystemSettings('SYSTEM_URL_BASE'), __FILE__); $scriptPath = array_shift($scriptPath); $path = $scriptPath . 'backup' . $dirSeparator; $identifier = time(); $backupsArr = $this->getAllBackups($path); $this->deleteBackupAfterExpired($backupsArr); if ($this->isAutobackup()) { SessionStorage::destroy('backup_' . $identifier); SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time()))); SJB_Session::unsetValue('restore'); SJB_Session::unsetValue('error'); $backupDir = $scriptPath . 'backup' . $dirSeparator; if (!is_dir($backupDir)) { mkdir($backupDir); } if (!file_exists($backupDir . '.htaccess')) { $handle = fopen($backupDir . '.htaccess', 'a'); $text = '# Apache 2.4 <IfModule mod_authz_core.c> <FilesMatch ".*"> Require all denied </FilesMatch> </IfModule> # Apache 2.2 <IfModule !mod_authz_core.c> <FilesMatch ".*"> Order Allow,Deny Deny from all </FilesMatch> </IfModule>'; fwrite($handle, $text); fclose($handle); } $backupType = SJB_System::getSettingByName('backup_type'); switch ($backupType) { case 'full': $this->makeFullBackup($identifier, $scriptPath, $dirSeparator); break; case 'database': $this->makeDatabaseBackup($identifier, $dirSeparator, $scriptPath); break; case 'files': $this->makeFilesBackup($identifier, $scriptPath, $dirSeparator); break; } SJB_Settings::updateSetting('last_autobackup', date("Y-m-d H:i:s")); } } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $module_name = SJB_Request::getVar('module_name', "", 'GET'); $template_name = SJB_Request::getVar('template_name', "", 'GET'); // не работало с юзерской if (empty($template_name)) { $template_name = SJB_Request::getVar('template_name', ''); } if (empty($module_name)) { $module_name = SJB_Request::getVar('module_name', ''); } $theme = SJB_Settings::getValue('TEMPLATE_USER_THEME', 'default'); $template_editor = new SJB_TemplateEditor(); $simple_view = SJB_Request::getVar('simple_view'); if (!$template_editor->doesModuleExists($module_name)) { $tp->assign('ERROR', "MODULE_DOES_NOT_EXIST"); } else { if (!$template_editor->doesModuleTemplateExists($module_name, $template_name)) { $tp->assign('ERROR', "TEMPLATE_DOES_NOT_EXIST"); } else { if (isset($_REQUEST['action'])) { $content = SJB_Request::getVar('template_content'); if ($content) { if (SJB_System::getSystemSettings("isDemo")) { $tp->assign('ERROR', 'NOT_ALLOWED_IN_DEMO'); } elseif (SJB_System::getIfTrialModeIsOn() && SJB_HelperFunctions::findSmartyRestrictedTagsInContent($tp, $content)) { $tp->assign('ERROR', 'Php tags are not allowed'); } else { $result = $template_editor->saveTemplate($template_name, $module_name, $theme, $content); // if ajax request to save if ($simple_view) { if ($result) { echo '<p class="message">Template saved successfully. </p>'; } else { echo "ERROR WHILE SAVE TEMPLATE"; } exit; } if ($_REQUEST['action'] == "save_template") { SJB_HelperFunctions::redirect("?module_name=" . $module_name); } } } } echo SJB_System::executeFunction('template_manager', 'add_template'); $modules = $template_editor->getModuleWithTemplatesList(); $tp->assign('module_name', $module_name); $tp->assign('template_name', $template_name); $tp->assign('theme', $theme); $tp->assign('display_name', $modules[$module_name]['display_name']); $tp->assign('template_display_name', $template_name); $path_to_template = SJB_TemplatePathManager::getAbsoluteTemplatePath($theme, $module_name, $template_name); if (!file_exists($path_to_template)) { $theme = SJB_System::getSystemSettings('SYSTEM_TEMPLATE_DIR'); } if (false === ($template_content = $template_editor->loadTemplate($template_name, $module_name, $theme))) { $tp->assign('ERROR', "CANNOT_FETCH_TEMPLATE"); } else { if (!$template_editor->isTemplateWriteable($module_name, $theme, $template_name) && !SJB_System::getSystemSettings("isDemo")) { $tp->assign('ERROR', "TEMPLATE_IS_NOT_WRITEABLE"); } else { $tp->assign('template_content', $template_content); } } $list_modules = SJB_System::getModulesUserList(); $list_functions = array(); $list_params = array(); foreach ($list_modules as $module) { $functions = SJB_System::getFunctionsUserList($module); foreach ($functions as $keyF => $func) { $list_functions[$module][$keyF] = $func; $params = SJB_System::getParamsList($module, $func); if (isset($params[0])) { foreach ($params as $keyP => $param) { $list_params[$module][$func][$keyP] = $param; } } } } $tp->assign('LIST_MODULES', $list_modules); $tp->assign('LIST_FUNCTIONS', $list_functions); $tp->assign('LIST_PARAMS', $list_params); } } if ($simple_view) { $tp->display('edit_template_simple.tpl'); } else { header('X-XSS-Protection: 0'); $tp->display('edit_template.tpl'); } }
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'); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = ''; if (!isset($_REQUEST['name'])) { $_REQUEST['name'] = ''; } if (!isset($_REQUEST['lang'])) { $_REQUEST['lang'] = ''; } $action = SJB_Request::getVar('action', ''); $form_submitted = SJB_Request::getVar('formSubmitted'); if ($action == 'add') { if (($error = SJB_StaticContentAuxil::isValidNameID($_REQUEST['name'], $_REQUEST['page_id'])) == '') { if (!SJB_StaticContent::getStaticContentByIdAndLang($_REQUEST['page_id'], $_REQUEST['lang'])) { $contentInfo = array('id' => $_REQUEST['page_id'], 'name' => $_REQUEST['name'], 'lang' => $_REQUEST['lang']); if (SJB_StaticContent::addStaticContent($contentInfo)) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/stat-pages/'); } else { $errors = SJB_StaticContentAuxil::warning('Error', 'Cannot add new static page'); } } else { $errors = SJB_StaticContentAuxil::warning('Error', 'Dublicate pare ID and Language. Please specify another ID or/and Language'); } } else { $errors = SJB_StaticContentAuxil::warning('Error', $error); } } if ($action == 'change') { $staticContent = SJB_StaticContent::getStaticContentByIDAndLang($_REQUEST['page_id'], $_REQUEST['lang']); if (!$staticContent || $staticContent['sid'] == $_REQUEST['page_sid']) { $content = SJB_Request::getVar('content'); if ((SJB_System::getSystemSettings('isDemo') || SJB_System::getIfTrialModeIsOn()) && SJB_HelperFunctions::findSmartyRestrictedTagsInContent($tp, $content)) { $errors = SJB_StaticContentAuxil::warning('Error', 'Php tags are not allowed'); } else { $contentInfo = array('id' => $_REQUEST['page_id'], 'name' => $_REQUEST['name'], 'content' => $content, 'lang' => $_REQUEST['lang']); if (SJB_StaticContent::changeStaticContent($contentInfo, $_REQUEST['page_sid'])) { if ($form_submitted == 'save_content') { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/stat-pages/'); } } else { $errors = SJB_StaticContentAuxil::warning('Error', 'Cannot update page'); } } } else { $errors = SJB_StaticContentAuxil::warning('Error', 'Dublicate pare ID and Language. Please specify another ID or/and Language'); } $action = 'edit'; } if ($action == 'delete') { if (SJB_StaticContent::deleteStaticContent($_REQUEST['page_sid'])) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/stat-pages/'); } $errors = SJB_StaticContentAuxil::warning('Error', 'Cannot delete static page'); } $tp->assign('languages', SJB_I18N::getInstance()->getActiveFrontendLanguagesData()); if ($action == 'edit') { $page = SJB_StaticContent::getStaticContent($_REQUEST['page_sid']); $tp->assign('page', array_map('htmlspecialchars', $page)); $pageInfo = array('module' => 'static_content', 'function' => 'show_static_content', 'parameters' => array('pageid' => SJB_Request::getVar('pageid', ''))); $tp->assign('pageInfo', $pageInfo); $tp->assign('page_content', $page['content']); $tp->assign('page_sid', $_REQUEST['page_sid']); $tp->assign('page', $page); $tp->assign('error', $errors); $tp->display('static_content_change.tpl'); return; } $tp->assign('pages', SJB_StaticContent::getStaticContents()); $tp->assign('error', $errors); $tp->display('static_content.tpl'); }
protected function editEmailTemplate($sid, &$errors = array()) { $tplInfo = SJB_EmailTemplateEditor::getEmailTemplateInfoBySID($sid); if ($tplInfo) { $tplInfo = array_merge($tplInfo, $_REQUEST); $emailTemplate = new SJB_EmailTemplate($tplInfo); $emailTemplate->setSID($sid); $emailTemplate_edit_form = new SJB_Form($emailTemplate); $form_is_submitted = SJB_Request::getVar('action'); // php tags are not allowed in trial mode if (SJB_System::getIfTrialModeIsOn() || SJB_System::getSystemSettings('isDemo')) { if (SJB_HelperFunctions::findSmartyRestrictedTagsInContent($this->tp, $emailTemplate->getPropertyValue('text'))) { $errors['Text'] = 'Php tags are not allowed'; } } if ($form_is_submitted && $emailTemplate_edit_form->isDataValid($errors)) { SJB_EmailTemplateEditor::saveEmailTemplate($emailTemplate); if ($form_is_submitted == 'save_info') { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/edit-email-templates/' . $emailTemplate->getPropertyValue('group')); } $this->successMessage = 'You have successfully saved your changes'; } $emailTemplate_edit_form->registerTags($this->tp); // prepare email templates variables info $this->prepareTemplateVarsInfo(SJB_Array::get($tplInfo, 'group'), SJB_Array::get($tplInfo, 'name')); $this->tp->assign('form_fields', $emailTemplate_edit_form->getFormFieldsInfo()); $this->tp->assign('tplInfo', $tplInfo); $this->template = 'edit_email_template.tpl'; } else { $this->error = 'INVALID_EMAIL_TEMPLATE_SID_WAS_SPECIFIED'; } }