コード例 #1
0
 /**
  * Main action.
  *
  * @return void
  */
 public function index()
 {
     $this->loadModel('System.Options');
     $languages = LocaleToolbox::languagesList();
     $arrayContext = ['schema' => ['site_title' => 'string', 'site_slogan' => 'string', 'site_description' => 'string', 'site_email' => 'string', 'site_contents_home' => 'integer', 'site_maintenance' => 'boolean', 'site_maintenance_ip' => 'string', 'site_maintenance_message' => 'string', 'default_language' => 'string', 'url_locale_prefix' => 'string'], 'defaults' => [], 'errors' => []];
     $variables = $this->Options->find()->where(['name IN' => array_keys($arrayContext['schema'])])->all();
     foreach ($variables as $var) {
         $arrayContext['defaults'][$var->name] = $var->value;
     }
     if ($this->request->data()) {
         $validator = $this->_mockValidator();
         $errors = $validator->errors($this->request->data());
         if (empty($errors)) {
             foreach ($this->request->data() as $k => $v) {
                 $this->Options->update($k, $v, null, false);
             }
             snapshot();
             $this->Flash->success(__d('system', 'Configuration successfully saved!'));
             $this->redirect($this->referer());
         } else {
             $arrayContext['errors'] = $errors;
             $this->Flash->danger(__d('system', 'Configuration could not be saved, please check your information.'));
         }
     }
     $pluginSettings = plugin()->filter(function ($plugin) {
         return !$plugin->isTheme && $plugin->hasSettings;
     });
     $this->title(__d('system', 'Site’ Configuration'));
     $this->set(compact('arrayContext', 'languages', 'variables', 'pluginSettings'));
     $this->Breadcrumb->push('/admin/system/configuration');
 }
コード例 #2
0
 /**
  * Last step of the installation process.
  *
  * Here we say "thanks" and redirect to site's frontend or backend.
  *
  * @return void
  */
 public function finish()
 {
     if ($this->request->data()) {
         if (rename(ROOT . '/config/settings.php.tmp', ROOT . '/config/settings.php')) {
             snapshot();
             $this->request->session()->delete('Startup');
             if (!empty($this->request->data['home'])) {
                 $this->redirect('/');
             } else {
                 $this->redirect('/admin');
             }
         } else {
             $this->Flash->danger(__d('installer', 'Unable to continue, check write permission for the "/config" directory.'));
         }
     }
     $this->title(__d('installer', 'Finish Installation'));
 }
コード例 #3
0
 function createDump($callBack)
 {
     global $modx;
     // Set line feed
     $lf = "\n";
     $tempfile_path = $modx->config['base_path'] . 'assets/backup/temp.php';
     $result = $modx->db->query('SHOW TABLES');
     $tables = $this->result2Array(0, $result);
     foreach ($tables as $tblval) {
         $result = $modx->db->query("SHOW CREATE TABLE `{$tblval}`");
         $createtable[$tblval] = $this->result2Array(1, $result);
     }
     // Set header
     $output = "#{$lf}";
     $output .= "# " . addslashes($modx->config['site_name']) . " Database Dump{$lf}";
     $output .= "# MODX Version:{$modx->config['settings_version']}{$lf}";
     $output .= "# {$lf}";
     $output .= "# Host: {$this->database_server}{$lf}";
     $output .= "# Generation Time: " . $modx->toDateFormat(time()) . $lf;
     $output .= "# Server version: " . $modx->db->getVersion() . $lf;
     $output .= "# PHP Version: " . phpversion() . $lf;
     $output .= "# Database : `{$this->dbname}`{$lf}";
     $output .= "#";
     file_put_contents($tempfile_path, $output, FILE_APPEND | LOCK_EX);
     $output = '';
     // Generate dumptext for the tables.
     if (isset($this->_dbtables) && count($this->_dbtables)) {
         $this->_dbtables = implode(',', $this->_dbtables);
     } else {
         unset($this->_dbtables);
     }
     foreach ($tables as $tblval) {
         // check for selected table
         if (isset($this->_dbtables)) {
             if (strstr(",{$this->_dbtables},", ",{$tblval},") === false) {
                 continue;
             }
         }
         if ($callBack === 'snapshot') {
             /*
             				switch($tblval)
             				{
             					case $modx->db->config['table_prefix'].'event_log':
             					case $modx->db->config['table_prefix'].'manager_log':
             						continue 2;
             				}*/
             if (!preg_match('@^' . $modx->db->config['table_prefix'] . '@', $tblval)) {
                 continue;
             }
         }
         $output .= "{$lf}{$lf}# --------------------------------------------------------{$lf}{$lf}";
         $output .= "#{$lf}# Table structure for table `{$tblval}`{$lf}";
         $output .= "#{$lf}{$lf}";
         // Generate DROP TABLE statement when client wants it to.
         if ($this->isDroptables()) {
             $output .= "DROP TABLE IF EXISTS `{$tblval}`;{$lf}";
         }
         $output .= "{$createtable[$tblval][0]};{$lf}";
         $output .= $lf;
         $output .= "#{$lf}# Dumping data for table `{$tblval}`{$lf}#{$lf}";
         $result = $modx->db->select('*', $tblval);
         $rows = $this->loadObjectList('', $result);
         foreach ($rows as $row) {
             $insertdump = $lf;
             $insertdump .= "INSERT INTO `{$tblval}` VALUES (";
             $arr = $this->object2Array($row);
             foreach ($arr as $key => $value) {
                 $value = addslashes($value);
                 $value = str_replace(array("\r\n", "\r", "\n"), '\\n', $value);
                 $insertdump .= "'{$value}',";
             }
             $output .= rtrim($insertdump, ',') . ");";
             if (1048576 < strlen($output)) {
                 file_put_contents($tempfile_path, $output, FILE_APPEND | LOCK_EX);
                 $output = '';
             }
         }
         file_put_contents($tempfile_path, $output, FILE_APPEND | LOCK_EX);
         $output = '';
     }
     $output = file_get_contents($tempfile_path);
     if (!empty($output)) {
         unlink($tempfile_path);
     }
     switch ($callBack) {
         case 'dumpSql':
             dumpSql($output);
             break;
         case 'snapshot':
             snapshot($output);
             break;
     }
     return true;
 }
コード例 #4
0
 /**
  * Finish this task.
  *
  * @param \CMS\Core\Package\PluginPackage $plugin The plugin being managed
  *  by this task
  * @return bool True on success
  */
 protected function _finish(PluginPackage $plugin)
 {
     $pluginEntity = $this->Plugins->find()->where(['name' => $plugin->name])->first();
     $pluginEntity->set('status', $this->params['status'] === 'enable' ? true : false);
     if (!$this->Plugins->save($pluginEntity)) {
         if ($this->params['status'] === 'enable') {
             $this->err(__d('installer', 'Plugin "{0}" could not be enabled due to an internal error.', $plugin->humanName));
         } else {
             $this->err(__d('installer', 'Plugin "{0}" could not be disabled due to an internal error.', $plugin->humanName));
         }
         return false;
     }
     snapshot();
     if (!$this->params['no-callbacks']) {
         $this->_triggerAfterEvents($plugin);
     }
     return true;
 }
コード例 #5
0
 /**
  * After installation is completed.
  *
  * @return void
  */
 protected function _finish()
 {
     global $classLoader;
     // composer's class loader instance
     snapshot();
     Plugin::dropCache();
     // trick: makes plugin visible to AcoManager
     $classLoader->addPsr4($this->_plugin['name'] . "\\", normalizePath(ROOT . "/plugins/{$this->_plugin['name']}/src"), true);
     AcoManager::buildAcos($this->_plugin['name']);
     $this->_reset();
 }
コード例 #6
0
ファイル: artica.php プロジェクト: BillTheBest/1.6.x
    exit;
}
if (isset($_GET["meta-repair-tables"])) {
    meta_repair_tables();
    exit;
}
if (isset($_GET["webfiltering-events"])) {
    webfiltering_events();
    exit;
}
if (isset($_GET["snapshot-sql"])) {
    snapshot_sql();
    exit;
}
if (isset($_GET["snapshot"])) {
    snapshot();
    exit;
}
if (isset($_GET["meta-tests-smtp"])) {
    artica_meta_server_test_smtp();
    exit;
}
if (isset($_GET["uncompress"])) {
    uncompress();
    exit;
}
if (isset($_GET["save-client-config"])) {
    save_client_config();
    exit;
}
if (isset($_GET["set-backup-server"])) {
コード例 #7
0
 /**
  * Clears any previous installation.
  *
  * @return void
  */
 protected function _clear()
 {
     $folder = new Folder(ROOT . '/plugins/NukedApp/');
     $folder->delete();
     snapshot();
 }
コード例 #8
0
 /**
  * Regenerates snapshot after new content type is created.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\Datasource\EntityInterface $entity The entity that was saved
  * @param \ArrayObject $options Array of options
  * @return void
  */
 public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options = null)
 {
     if ($entity->isNew()) {
         snapshot();
     }
 }
コード例 #9
0
 /**
  * Runs uninstallation logic inside a safe transactional thread. This prevent
  * DB inconsistencies on uninstall failure.
  *
  * @return bool True on success, false otherwise
  */
 protected function _runTransactional()
 {
     // to avoid any possible issue
     snapshot();
     if (!is_writable(TMP)) {
         $this->err(__d('installer', 'Enable write permissions in /tmp directory before uninstall any plugin or theme.'));
         return false;
     }
     if (!$this->params['plugin']) {
         $this->err(__d('installer', 'No plugin/theme was given to remove.'));
         return false;
     }
     $this->loadModel('System.Plugins');
     try {
         $plugin = plugin($this->params['plugin']);
         $pluginEntity = $this->Plugins->find()->where(['name' => $this->params['plugin']])->limit(1)->first();
     } catch (\Exception $ex) {
         $plugin = $pluginEntity = false;
     }
     if (!$plugin || !$pluginEntity) {
         $this->err(__d('installer', 'Plugin "{0}" was not found.', $this->params['plugin']));
         return false;
     }
     $this->_plugin = $plugin;
     $type = $plugin->isTheme ? 'theme' : 'plugin';
     if ($plugin->isTheme && in_array($plugin->name, [option('front_theme'), option('back_theme')])) {
         $this->err(__d('installer', '{0} "{1}" is currently being used and cannot be removed.', $type == 'plugin' ? __d('installer', 'The plugin') : __d('installer', 'The theme'), $plugin->humanName));
         return false;
     }
     $requiredBy = Plugin::checkReverseDependency($this->params['plugin']);
     if (!empty($requiredBy)) {
         $names = [];
         foreach ($requiredBy as $p) {
             $names[] = $p->name();
         }
         $this->err(__d('installer', '{0} "{1}" cannot be removed as it is required by: {2}', $type == 'plugin' ? __d('installer', 'The plugin') : __d('installer', 'The theme'), $plugin->humanName, implode(', ', $names)));
         return false;
     }
     if (!$this->_canBeDeleted($plugin->path)) {
         return false;
     }
     if (!$this->params['no-callbacks']) {
         try {
             $event = $this->trigger("Plugin.{$plugin->name}.beforeUninstall");
             if ($event->isStopped() || $event->result === false) {
                 $this->err(__d('installer', 'Task was explicitly rejected by {0}.', $type == 'plugin' ? __d('installer', 'the plugin') : __d('installer', 'the theme')));
                 return false;
             }
         } catch (\Exception $e) {
             $this->err(__d('installer', 'Internal error, {0} did not respond to "beforeUninstall" callback correctly.', $type == 'plugin' ? __d('installer', 'the plugin') : __d('installer', 'the theme')));
             return false;
         }
     }
     if (!$this->Plugins->delete($pluginEntity)) {
         $this->err(__d('installer', '{0} "{1}" could not be unregistered from DB.', $type == 'plugin' ? __d('installer', 'The plugin') : __d('installer', 'The theme'), $plugin->humanName));
         return false;
     }
     $this->_removeOptions();
     $this->_clearAcoPaths();
     $folder = new Folder($plugin->path);
     $folder->delete();
     snapshot();
     if (!$this->params['no-callbacks']) {
         try {
             $this->trigger("Plugin.{$plugin->name}.afterUninstall");
         } catch (\Exception $e) {
             $this->err(__d('installer', '{0} did not respond to "afterUninstall" callback.', $type == 'plugin' ? __d('installer', 'The plugin') : __d('installer', 'The theme')));
         }
     }
     Plugin::unload($plugin->name);
     Plugin::dropCache();
     return true;
 }
コード例 #10
0
 /**
  * Regenerates system's snapshot.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\ORM\Entity $language The language entity that was saved
  * @return void
  */
 public function afterDelete(Event $event, Entity $language)
 {
     snapshot();
 }
コード例 #11
0
ファイル: snapshot.php プロジェクト: commiunty/Mytest
<?php

$url = 'www.baidu.com';
//抓取百度
echo snapshot($url);
//输出结果为图片地址
echo snapshot($url, './baidu.png');
//将图片保存至本地baidu.png, 输出内容图片大小
/**
 * 生成网页快照
 *
 * @param string $site 目标地址
 * @param string $path 保存地址, 为空则不保存
 * @param integer $dealy 延迟
 * @return mixed 根据参数返回
 */
function snapshot($site, $path = '', $dealy = 0)
{
    $url = 'http://ppt.cc/yo2/catch.php';
    $query = 'url=' . $site . '&delay=' . $dealy . '&rnd=' . mt_rand(1, 9);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch);
    curl_close($ch);
    if (strlen($data) != 32) {
        exit('无效网址');
    }
    $file = $data[0] . '/' . $data[1] . '/' . $data[2] . '/';
コード例 #12
0
/**
 *	create and delete auto- revisions
 *
 *	this function operates on a specific page and takes SNAPSHOT_MIN_AGE and
 *	SNAPSHOT_MAX_AGE into account.
 *	@param array $args arguments
 *		key 'page' is the page (i.e. page.rev)
 *	@return array response
 *		true if successful
 */
function check_auto_snapshot($args)
{
    if (!isset($args['page'])) {
        return response('Required argument "page" missing', 400);
    }
    if (!page_exists($args['page'])) {
        return response('Page ' . quot($args['page']) . ' does not exist', 400);
    }
    $a = expl('.', $args['page']);
    $revs = revisions_info(array('pagename' => $a[0], 'sort' => 'time'));
    $revs = $revs['#data'];
    if ($a[1] == 'head' && SNAPSHOT_MIN_AGE != 0) {
        // we're dealing with a head revision and taking snapshots
        // find the previous auto- revision
        for ($i = 0; $i < count($revs); $i++) {
            if (substr($revs[$i]['revision'], 0, 5) == 'auto-') {
                // got it, check age
                if (time() - $revs[$i]['time'] < SNAPSHOT_MIN_AGE) {
                    log_msg('debug', 'check_auto_snapshot: age is ' . (time() - $revs[$i]['time']) . ' seconds, not creating a snapshot');
                    break;
                }
                // check if different
                if (dir_is_different(CONTENT_DIR . '/' . str_replace('.', '/', $args['page']), CONTENT_DIR . '/' . str_replace('.', '/', $revs[$i]['page']))) {
                    snapshot($args);
                } else {
                    log_msg('debug', 'check_auto_snapshot: head is identical to ' . $revs[$i]['revision'] . ', not creating a snapshot');
                }
                break;
            }
            if ($i == count($revs) - 1) {
                // no auto- revision?, create one now
                snapshot($args);
            }
        }
    }
    // delete old auto- revisions
    if (SNAPSHOT_MAX_AGE != 0) {
        for ($i = count($revs) - 1; 0 <= $i; $i--) {
            if (substr($revs[$i]['revision'], 0, 5) == 'auto-' && SNAPSHOT_MAX_AGE < time() - $revs[$i]['time']) {
                log_msg('info', 'check_auto_snapshot: deleting an old snapshot');
                delete_page(array('page' => $revs[$i]['page']));
                $i--;
            }
        }
    }
    return response(true);
}
コード例 #13
0
 /**
  * Regenerates system's snapshot.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\ORM\Entity $option The option entity that was saved
  * @return void
  */
 public function afterDelete(Event $event, Entity $option)
 {
     snapshot();
 }
コード例 #14
0
 /**
  * This method automatically regenerates system's snapshot.
  *
  * @param \Cake\Event\Event $event The event that was triggered
  * @param \Cake\ORM\Entity $plugin The Plugin entity that was deleted
  * @param \ArrayObject $options the options passed to the delete method
  * @return void
  */
 public function afterDelete(Event $event, Entity $plugin, ArrayObject $options = null)
 {
     snapshot();
     $this->clearCache();
 }