$from = $context['path_to_root'] . Files::get_path($last_parent->get_reference()) . '/' . $file->item['file_name']; $dir = $context['path_to_root'] . Files::get_path($target->get_reference()); $to = $dir . '/' . $file->item['file_name']; // check that dir exists if (!is_dir($dir)) { Safe::make_path($dir); } Safe::rename($from, $to); // move thumb if any if ($file->item['thumbnail_url']) { $from = Files::get_path($last_parent->get_reference()) . '/thumbs/' . $file->item['file_name']; // make directory thumbs $to = $dir . '/thumbs/' . $file->item['file_name']; // check that dir exist if (!is_dir($dir . '/thumbs')) { Safe::mkdir($dir . '/thumbs'); } Safe::rename($from, $to); } } } // we return some JSON $output = json_encode($output); // allow for data compression render_raw('application/json; charset=' . $context['charset']); // actual transmission except on a HEAD request if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'HEAD') { echo $output; } // the post-processing hook, then exit finalize_page(TRUE);
// end of the form $context['text'] .= '</div></form>'; // set the focus Page::insert_script('$("#files_extensions").focus();'); // general help on this form $help = '<p>' . i18n::s('Shared files are not put in the database, but in the file system of the web server.') . '</p>' . '<p>' . i18n::s('If you cannot upload files because of permissions settings, use the configuration panel for users to disable all uploads.') . '</p>'; $context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help'); // no modifications in demo mode } elseif (file_exists($context['path_to_root'] . 'parameters/demo.flag')) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation in demonstration mode.')); // save updated parameters } else { // backup the old version Safe::unlink($context['path_to_root'] . 'parameters/files.include.php.bak'); Safe::rename($context['path_to_root'] . 'parameters/files.include.php', $context['path_to_root'] . 'parameters/files.include.php.bak'); // build the new configuration file $content = '<?php' . "\n" . '// This file has been created by the configuration script files/configure.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, for ' . Surfer::get_name() . '. Please do not modify it manually.' . "\n" . 'global $context;' . "\n"; if (isset($_REQUEST['files_extensions'])) { $content .= '$context[\'files_extensions\']=\'' . addcslashes($_REQUEST['files_extensions'], "\\'") . "';\n"; } if (isset($_REQUEST['files_on_ftp'])) { $content .= '$context[\'files_on_ftp\']=\'' . addcslashes($_REQUEST['files_on_ftp'], "\\'") . "';\n"; } if (isset($_REQUEST['files_path'])) { $content .= '$context[\'files_path\']=\'' . addcslashes($_REQUEST['files_path'], "\\'") . "';\n"; } if (isset($_REQUEST['files_url'])) { $content .= '$context[\'files_url\']=\'' . addcslashes($_REQUEST['files_url'], "\\'") . "';\n"; } $content .= '?>' . "\n";
} // include all scripts named 'hook.php' recursively foreach ($scanned as $name) { include_hook($context['path_to_root'] . $name); } global $scanned_directories; if ($scanned_directories > 1) { $context['text'] .= sprintf(i18n::s('%d directories have been scanned.'), $scanned_directories) . BR . "\n"; } // no hook has been found if (!count($hooks)) { $context['text'] .= i18n::s('No item has been found.'); } else { // backup the old version Safe::unlink('../parameters/hooks.include.php.bak'); Safe::rename('../parameters/hooks.include.php', '../parameters/hooks.include.php.bak'); // what we have to produce $called_items = array(); $included_items = array(); $included_items['tick'] = ''; $linked_items = array(); $served_items = array(); // we will remember a xml file as well $xml = ''; // consider each hook foreach ($hooks as $hook) { // bad script! if (!$hook['id'] || !$hook['type'] || $hook['type'] != 'call' && !$hook['script']) { $context['text'] .= '<p><strong>' . i18n::s('Bad hook:') . '</strong>' . BR . "\n"; foreach ($hook as $name => $value) { $context['text'] .= $name . ': ' . $value . BR;
} elseif ($file && !preg_match('/(\\.css|template\\.php)$/i', $file)) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // ensure the file already exists } elseif ($file && !file_exists($context['path_to_root'] . 'skins/' . $skin . '/' . $file)) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // save the content of an updated file } elseif (isset($_REQUEST['content']) && $_REQUEST['content']) { // warning if modification of some reference skin if (isset($_REQUEST['content']) && $_REQUEST['content'] && preg_match('/^(boxesandarrows|digital|joi|skeleton)$/', $skin)) { Logger::error(sprintf(i18n::s('Do not attempt to modify a reference theme directly, your changes would be overwritten on next software update. %s instead to preserve your work over time.'), Skin::build_link('skins/derive.php', i18n::s('Derive a theme'), 'shortcut'))); } // backup the old version, if any Safe::unlink($context['path_to_root'] . 'skins/' . $skin . '/' . $file . '.bak'); Safe::rename($context['path_to_root'] . 'skins/' . $skin . '/' . $file, $context['path_to_root'] . 'skins/' . $skin . '/' . $file . '.bak'); // actual save if (Safe::file_put_contents('skins/' . $skin . '/' . $file, $_REQUEST['content']) != strlen($_REQUEST['content'])) { Logger::error(sprintf(i18n::s('The target file %s may have been corrupted. Please check file content manually, and revert to the backup file, with the extension .bak, if necessary.'), 'skins/' . $skin . '/' . $file)); } else { $context['text'] .= '<p>' . sprintf(i18n::s('The target file %s has been successfully updated.'), 'skins/' . $skin . '/' . $file) . '</p>'; // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array(); $menu = array_merge($menu, array('skins/test.php?skin=' . urlencode($skin) => i18n::s('Test this theme'))); $menu = array_merge($menu, array('skins/edit.php?skin=' . urlencode($skin) => i18n::s('Edit this theme'))); $menu = array_merge($menu, array('skins/' => i18n::s('Themes'))); $menu = array_merge($menu, array('skins/configure.php' => i18n::s('Configure the page factory'))); $follow_up .= Skin::build_list($menu, 'menu_bar'); $context['text'] .= Skin::build_block($follow_up, 'bottom'); }
/** * move a new file * * @param string the source file * @param string the destination file * @return TRUE on success, FALSE on failure */ public static function move_uploaded_file($source, $destination) { // translate the path $destination = Safe::realpath($destination); // file may have been already loaded through ajax if (file_exists($source)) { return Safe::rename($source, $destination); } // ensure call is allowed if (is_callable('move_uploaded_file')) { return @move_uploaded_file($source, $destination); } // tough luck return FALSE; }
function process($template, $directory = 'blogger_import') { global $context; // we also have to prepare a skin -- the skin split is for scripts/validate.php $skin = '<?php' . "\n" . 'class Sk' . 'in extends Skin_skeleton {' . "\n"; // fix images relative path $template = preg_replace('/src="(.+?)"/ie', "'src=\"'.fix_relative('\$1', '{$directory}').'\"'", $template); $template = preg_replace('/background="(.+?)"/ie', "'background=\"'.fix_relative('\$1', '{$directory}').'\"'", $template); $template = preg_replace('/url\\((.+?)\\)/ie', "'url('.fix_relative('\$1', '{$directory}').')'", $template); // <$BlogArchiveFileName$> $from = '/<\\$BlogArchiveFileName\\$>/i'; $to = '<?php echo $context[\'url_to_root\'].\'categories/view.php?id=monthly\'; ?>'; $template = preg_replace($from, $to, $template); // <$BlogArchiveName$> $from = '/<\\$BlogArchiveName\\$>/i'; $to = '<?php echo \'Monthly Archives\'; ?>'; $template = preg_replace($from, $to, $template); // <$BlogArchiveLink$> $from = '/<\\$BlogArchiveLink\\$>/i'; $to = '<?php echo $context[\'url_to_root\'].\'categories/view.php?id=monthly\'; ?>'; $template = preg_replace($from, $to, $template); // <$BlogArchiveURL$> $from = '/<\\$BlogArchiveURL\\$>/i'; $to = '<?php echo $context[\'url_to_root\'].\'categories/view.php?id=monthly\'; ?>'; $template = preg_replace($from, $to, $template); // <$BlogDescription$> $from = '/<\\$BlogDescription\\$>/i'; $to = '<?php' . "\n" . 'if(is_object($anchor))' . "\n" . ' echo $anchor->get_teaser();' . "\n" . '?>'; $template = preg_replace($from, $to, $template); // <$BlogMemberProfile$> $from = '/<\\$BlogMemberProfile\\$>/i'; $to = '<?php echo $context[\'creator_profile\']; ?>'; $template = preg_replace($from, $to, $template); // <$BlogMetaData$> $from = '/<\\$BlogMetaData\\$>/i'; $to = '<?php echo $context[\'page_header\']; ?>'; $template = preg_replace($from, $to, $template); // <$BlogPageTitle$> $from = '/<\\$BlogPageTitle\\$>/i'; $to = '<?php echo ucfirst(strip_tags($context[\'page_title\'])); ?>'; $template = preg_replace($from, $to, $template); // <$BlogTitle$> $from = '/<\\$BlogTitle\\$>/i'; $to = '<?php echo ucfirst(strip_tags($context[\'page_title\'])); ?>'; $template = preg_replace($from, $to, $template); // <$BlogURL$> $from = '/<\\$BlogURL\\$>/i'; $to = '<?php echo $context[\'url_to_home\'].$context[\'url_to_root\']; ?>'; $template = preg_replace($from, $to, $template); // only one type of new lines $template = str_replace("\r\n", "\n", $template); $template = str_replace("\r", "\n", $template); // <MainOrArchivePage> $from = '/<MainOrArchivePage>(.*?)<\\/MainOrArchivePage>/is'; $to = ''; $template = preg_replace($from, $to, $template); // the <BlogItemComments>...</BlogItemComments> block $areas = preg_split('/<BlogItemComments>(.*?)<\\/BlogItemComments>/is', trim($template), -1, PREG_SPLIT_DELIM_CAPTURE); $template = ''; $index = 0; foreach ($areas as $area) { switch ($index % 3) { case 0: // prefix block $template .= $area; break; case 1: // commenting area // <$BlogCommentDateTime$> $from = '/<\\$BlogCommentDateTime\\$>/i'; $to = '\'.Skin::build_date($item[\'create_date\']).\''; $area = preg_replace($from, $to, $area); // <$BlogCommentNumber$> $from = '/<\\$BlogCommentNumber\\$>/i'; $to = '\'.$item[\'id\'].\''; $area = preg_replace($from, $to, $area); // <$BlogCommentAuthor$> $from = '/<\\$BlogCommentAuthor\\$>/i'; $to = '\'.$item[\'create_name\'].\''; $area = preg_replace($from, $to, $area); // <$BlogCommentAuthorNickname$> $from = '/<\\$BlogCommentAuthorNickname\\$>/i'; $to = '\'.$item[\'create_name\'].\''; $area = preg_replace($from, $to, $area); // <$BlogCommentBody$> $comment_prefix .= 'unset($BlogCommentBody);' . "\n" . '$BlogCommentBody .= Codes::beautify(trim($item[\'description\']));' . "\n" . "\n"; $from = '/<\\$BlogCommentBody\\$>/i'; $to = '\'.$BlogCommentBody.\''; $area = preg_replace($from, $to, $area); // make a skin $skin .= "\n" . ' function layout_comment($item, $variant = \'compact\') {' . "\n" . ' global $context;' . "\n" . ' ' . str_replace("\n", "\n\t\t", $comment_prefix) . "\n" . ' // array($prefix, $title, $suffix, $type, $icon)' . "\n" . ' $prefix = \'' . trim($item_prefix) . '\';' . "\n" . ' $title = \'_\';' . "\n" . ' $suffix = \'' . trim($area) . '\';' . "\n" . ' return array($prefix, $title, $suffix, \'comment\', NULL);' . "\n" . "\t}\n"; break; case 2: // suffix block $template .= $area; break; } $index++; } // the <Blogger>...</Blogger> block $areas = preg_split('/<Blogger>(.*?)<\\/Blogger>/is', trim($template), -1, PREG_SPLIT_DELIM_CAPTURE); $template = ''; $index = 0; foreach ($areas as $area) { // blogging area if ($index == 1) { $template .= '<?php ' . "\n" . '// display the menu bar, if any' . "\n" . 'if(@count($context[\'page_menu\']) > 0)' . "\n" . ' echo Skin::build_list($context[\'page_menu\'], \'page_menu\');' . "\n" . "\n" . '// display the prefix, if any' . "\n" . 'if($context[\'prefix\'])' . "\n" . ' echo $context[\'prefix\'];' . "\n" . "\n" . '// display the error message, if any' . "\n" . 'if($context[\'error\'])' . "\n" . ' echo Skin::build_block($context[\'error\'], \'error\');' . "\n" . "\n" . '// display the page image, if any' . "\n" . 'if($context[\'page_image\'])' . "\n" . ' echo \'<img src="\'.$context[\'page_image\'].\'" class="icon" alt="" />\';' . "\n" . "\n" . '// the main part of the page' . "\n" . 'echo $context[\'text\'];' . "\n" . "\n" . '// display the suffix, if any' . "\n" . 'if($context[\'suffix\'])' . "\n" . ' echo \'<p>\'.$context[\'suffix\'].\'</p>\';' . "\n" . '?>'; // make a skin for each item of the blogging area // break lines to not interfere with regular code $area = str_replace("\n", "'\n\t\t\t.'", addcslashes(trim($area), "'")); // <$BlogDateHeaderDate$> $from = '/<\\$BlogDateHeaderDate\\$>/i'; $to = '\'.Skin::build_date($item[\'create_date\']).\''; $area = preg_replace($from, $to, $area); // <$BlogItemArchiveFileName$> $from = '/<\\$BlogItemArchiveFileName\\$>/i'; $to = '\'.$context[\'url_to_root\'].Articles::get_permalink($item).\''; $area = preg_replace($from, $to, $area); // <$BlogItemAuthor$> $from = '/<\\$BlogItemAuthor\\$>/i'; $to = '\'.$item[\'create_name\'].\''; $area = preg_replace($from, $to, $area); // <$BlogItemAuthorNickname$> $from = '/<\\$BlogItemAuthorNickname\\$>/i'; $to = '\'.$item[\'create_name\'].\''; $area = preg_replace($from, $to, $area); // <$BlogItemBody$> $article_prefix .= 'unset($BlogItemBody);' . "\n" . '// the introduction' . "\n" . 'if($item[\'introduction\'])' . "\n" . ' $BlogItemBody .= Codes::beautify(trim($item[\'introduction\']));' . "\n" . 'elseif(!is_object($overlay)) {' . "\n" . ' // extract up to markup, if any' . "\n" . ' $raw = preg_split(\'/(\\[|<)/\', $item[\'description\']);' . "\n" . ' $BlogItemBody .= Skin::strip(trim($raw[0]), 30);' . "\n" . '}' . "\n" . 'if($suffix)' . "\n" . ' $BlogItemBody = \' - \'.$suffix;' . "\n" . "\n" . '// insert overlay data, if any' . "\n" . 'if(is_object($overlay))' . "\n" . ' $BlogItemBody .= $overlay->get_text(\'list\', $item);' . "\n" . "\n"; $from = '/<\\$BlogItemBody\\$>/i'; $to = '\'.$BlogItemBody.\''; $area = preg_replace($from, $to, $area); // <$BlogItemCommentCount$> $article_prefix .= 'unset($BlogItemCommentCount);' . "\n" . '// info on related comments' . "\n" . 'include_once $context[\'path_to_root\'].\'comments/comments.php\';' . "\n" . '$BlogItemCommentCount = Comments::count_for_anchor(\'article:\'.$item[\'id\']);' . "\n" . "\n"; $from = '/<\\$BlogItemCommentCount\\$>/i'; $to = '\'.$BlogItemCommentCount.\''; $area = preg_replace($from, $to, $area); // <$BlogItemControl$> -- the menu bar for associates and poster $article_prefix .= 'unset($BlogItemControl);' . "\n" . 'if(Surfer::is_associate() || Surfer::is($item[\'create_id\']) || Surfer::is($item[\'edit_id\'])) {' . "\n" . ' $menu = array( Articles::get_url($item[\'id\'], \'edit\') => i18n::s(\'edit\'),' . "\n" . ' Articles::get_url($item[\'id\'], \'delete\') => i18n::s(\'delete\') );' . "\n" . ' $BlogItemControl = \' \'.Skin::build_list($menu, \'menu\');' . "\n" . '}' . "\n" . "\n"; $from = '/<\\$BlogItemControl\\$>/i'; $to = '\'.$BlogItemControl.\''; $area = preg_replace($from, $to, $area); // <$BlogItemDateTime$> $from = '/<\\$BlogItemDateTime\\$>/i'; $to = '\'.Skin::build_date($item[\'create_date\']).\''; $area = preg_replace($from, $to, $area); // <$BlogItemNumber$> $from = '/<\\$BlogItemNumber\\$>/i'; $to = '\'.$item[\'id\'].\''; $area = preg_replace($from, $to, $area); // <$BlogItemPermalinkURL$> $from = '/<\\$BlogItemPermalinkURL\\$>/i'; $to = '\'.$context[\'url_to_root\'].Articles::get_permalink($item).\''; $area = preg_replace($from, $to, $area); // <$BlogItemTitle$> -- it has to be the last one for this item $from = '/<\\$BlogItemTitle\\$>/i'; list($item_prefix, $item_suffix) = preg_split($from, $area); // make a skin $skin .= "\n" . ' function layout_article($item, $variant = \'compact\') {' . "\n" . ' global $context;' . "\n" . ' ' . str_replace("\n", "\n\t\t", $article_prefix) . "\n" . ' // array($prefix, $title, $suffix, $type, $icon)' . "\n" . ' $prefix = \'' . trim($item_prefix) . '\';' . "\n" . ' $title = trim($item[\'title\']);' . "\n" . ' $suffix = \'' . trim($item_suffix) . '\';' . "\n" . ' return array($prefix, $title, $suffix, \'article\', NULL);' . "\n" . "\t}\n"; } else { // suffix block $template .= $area; } $index++; } // skin end $skin .= "}\n" . '?>' . "\n"; // backup the old skin, if any Safe::unlink($context['path_to_root'] . 'skins/' . $directory . '/skin.php.bak'); Safe::rename($context['path_to_root'] . 'skins/' . $directory . '/skin.php', $context['path_to_root'] . 'skins/' . $directory . '/skin.php.bak'); // create a new skin file if (!$skin) { Logger::error(i18n::s('No blogging block has been found.')); } elseif (!Safe::make_path('skins/' . $directory)) { Logger::error(sprintf(i18n::s('Impossible to create path %s.'), 'skins/' . $directory)); } elseif (!($handle = Safe::fopen($context['path_to_root'] . 'skins/' . $directory . '/skin.php', 'wb'))) { Logger::error(sprintf(i18n::s('Impossible to write to %s.'), $context['path_to_root'] . 'skins/' . $directory . '/skin.php')); } else { fwrite($handle, $skin); fclose($handle); } // backup the old template, if any Safe::unlink($context['path_to_root'] . 'skins/' . $directory . '/template.php.bak'); if (!$template) { Logger::error(i18n::s('Empty template file')); } else { Safe::rename($context['path_to_root'] . 'skins/' . $directory . '/template.php', $context['path_to_root'] . 'skins/' . $directory . '/template.php.bak'); } // create a new template file if (!Safe::make_path('skins/' . $directory)) { Logger::error(sprintf(i18n::s('Impossible to create path %s.'), 'skins/' . $directory)); } elseif (!($handle = Safe::fopen($context['path_to_root'] . 'skins/' . $directory . '/template.php', 'wb'))) { Logger::error(sprintf(i18n::s('Impossible to write to %s.'), $context['path_to_root'] . 'skins/' . $directory . '/template.php')); } else { fwrite($handle, $template); fclose($handle); $context['text'] .= '<p>' . sprintf(i18n::s('Template has been imported. Check skin %s'), Skin::build_link('skins/test.php?skin=' . $directory, $directory, 'shortcut')) . "</p>\n"; } return NULL; }
function explode_callback($name) { global $context; // reject all files put in sub-folders if (($path = substr($name, strlen($context['uploaded_path'] . '/'))) && strpos($path, '/') !== FALSE) { Safe::unlink($name); } elseif (!Files::is_authorized($name)) { Safe::unlink($name); } else { // make it easy to download $ascii = utf8::to_ascii(basename($name)); Safe::rename($name, $context['uploaded_path'] . '/' . $ascii); // remember this name $context['uploaded_files'][] = $ascii; } }
/** * flag all scripts in scripts/run_once * */ public static function purge_run_once() { global $context; // silently purge pending run-once scripts, if any if ($handle = Safe::opendir($context['path_to_root'] . 'scripts/run_once')) { // process every file in the directory while (($node = Safe::readdir($handle)) !== FALSE) { // skip special entries if ($node[0] == '.') { continue; } // we are only interested in php scripts if (!preg_match('/\\.php$/i', $node)) { continue; } // full name $target = $context['path_to_root'] . 'scripts/run_once/' . $node; // skip directories and links if (!is_file($target)) { continue; } // check we have enough permissions if (!is_readable($target)) { continue; } // stamp the file to remember execution time Safe::touch($target); // flag script as being already processed Safe::unlink($target . '.done'); Safe::rename($target, $target . '.done'); } Safe::closedir($handle); } }
} // version 8.4 if (!defined('YACS')) { define('YACS', TRUE); } // version 8.5 - new side menu if (!isset($context['page_tools'])) { $context['page_tools'] = array(); } if (!isset($context['script_url'])) { $context['script_url'] = ''; } // version 8.6 - new page components if (!isset($context['page_tags'])) { $context['page_tags'] = ''; } if (!isset($_SESSION['surfer_interface'])) { $_SESSION['surfer_interface'] = 'C'; } // force a refresh of compacted javascript libraries if ($items = Safe::glob($context['path_to_root'] . 'temporary/cache_*.js')) { foreach ($items as $name) { Safe::unlink($name); } } // safe copy of footprints.php to the root directory Safe::unlink($context['path_to_root'] . 'footprints.php.bak'); Safe::rename($context['path_to_root'] . 'footprints.php', $context['path_to_root'] . 'footprints.php.bak'); Safe::copy($context['path_to_root'] . 'scripts/staging/footprints.php', $context['path_to_root'] . 'footprints.php'); // remember this as a significant event --i18n::s does not exist before 6.12 Logger::remember('scripts/update_trailer.php: update trailer has been executed');
// get the file locally if (file_exists($local_reference)) { $content = Safe::file_get_contents($local_reference); } elseif (($content = http::proceed($remote_reference)) === FALSE) { $local['error_en'] = 'Unable to get ' . $file; $local['error_fr'] = 'Impossible d\'obtenir ' . $file; echo i18n::user('error') . "<br />\n"; } // we have something in hand if ($content) { // create missing directories where applicable Safe::make_path(dirname($file)); // create backups, if possible if (file_exists($context['path_to_root'] . $file)) { Safe::unlink($context['path_to_root'] . $file . '.bak'); Safe::rename($context['path_to_root'] . $file, $context['path_to_root'] . $file . '.bak'); } // update the target file if (!Safe::file_put_contents($file, $content)) { $local['label_en'] = 'Impossible to write to the file ' . $file . '.'; $local['label_fr'] = 'Impossible d\'écrire le fichier ' . $file . '.'; echo i18n::user('label') . "<br />\n"; } else { $local['label_en'] = 'has been updated'; $local['label_fr'] = 'a été mis à jour'; echo $file . ' ' . i18n::user('label') . "<br />\n"; } } // next one $count += 1; Safe::set_time_limit(30);
/** * dynamically generate the page * * @see skins/index.php */ function send_body() { global $context, $action; // check that the user is an admin, but only if there is at least one user record $query = "SELECT count(*) FROM " . SQL::table_name('users'); if (!Surfer::is_associate() && SQL::query($query) !== FALSE) { Safe::header('Status: 401 Unauthorized', TRUE, 401); echo '<p>' . i18n::s('You are not allowed to perform this operation.') . "</p>\n"; return; } // log the current surfer as an associate if not yet the case if (!Surfer::is_associate()) { $fields = array(); $fields['id'] = 1; $fields['nick_name'] = 'admin'; $fields['email'] = ''; $fields['capability'] = 'A'; Surfer::set($fields); echo '<p>' . i18n::s('You have associate privilege') . '</p>'; } // check every table of the database if ($action == 'build') { // maybe we will have to switch the server off $temporary_off = FALSE; // ensure nobody else will access the database during the operation if (file_exists('../parameters/switch.on')) { if (Safe::rename($context['path_to_root'] . 'parameters/switch.on', $context['path_to_root'] . 'parameters/switch.off')) { echo BR . i18n::s('The server has been switched off.'); $temporary_off = TRUE; } // let concurrent on-going transactions finish properly Safe::sleep(3); // first installation } elseif (!file_exists('../parameters/switch.off')) { echo '<p>' . i18n::s('Review provided information and go to the bottom of the page to move forward.') . "</a></p>\n"; } // ensure utf8 character set for this database $query = "ALTER DATABASE `" . $context['database'] . "` DEFAULT CHARACTER SET utf8"; SQL::query($query); // create tables for users echo Users::setup(); // create tables for activities echo Activities::setup(); // create tables for notifications include_once '../users/notifications.php'; echo Notifications::setup(); // create tables for messages echo Mailer::setup(); // create tables for visits include_once '../users/visits.php'; echo Visits::setup(); // create tables for sections echo Sections::setup(); // create tables for articles echo Articles::setup(); // create tables for images include_once '../images/images.php'; echo Images::setup(); // create tables for tables include_once '../tables/tables.php'; echo Tables::setup(); // create tables for files echo Files::setup(); // create tables for links include_once '../links/links.php'; echo Links::setup(); // create tables for locations include_once '../locations/locations.php'; echo Locations::setup(); // create tables for comments include_once '../comments/comments.php'; echo Comments::setup(); // create tables for categories echo Categories::setup(); // create tables for members include_once '../shared/members.php'; echo Members::setup(); // create tables for dates include_once '../dates/dates.php'; echo Dates::setup(); // create tables for servers include_once '../servers/servers.php'; echo Servers::setup(); // create tables for versions include_once '../versions/versions.php'; echo Versions::setup(); // create tables for enrolments include_once '../shared/enrolments.php'; echo Enrolments::setup(); // create tables for values include_once '../shared/values.php'; echo Values::setup(); // create tables for the cache echo Cache::setup(); // create tables for the php documentation include_once '../scripts/phpdoc.php'; echo PhpDoc::setup(); // the setup hook if (is_callable(array('Hooks', 'include_scripts'))) { echo Hooks::include_scripts('control/setup.php'); } // reopen the server for others if ($temporary_off && Safe::rename($context['path_to_root'] . 'parameters/switch.off', $context['path_to_root'] . 'parameters/switch.on')) { echo '<p>' . i18n::s('The server has been switched on.') . '</p>'; } // in the middle of an update if (file_exists('../parameters/switch.off')) { echo Skin::build_block('<form method="get" action="../scripts/run_once.php">' . "\n" . '<p class="assistant_bar">' . Skin::build_submit_button(i18n::s('Run one-time scripts and go to the Control Panel')) . '</p>' . "\n" . '</form>', 'bottom'); // this may take several minutes echo '<p>' . i18n::s('When you will click on the button the server will be immediately requested to proceed. However, because of the so many things to do on the back-end, you may have to wait for minutes before getting a response displayed. Thank you for your patience.') . '</p>'; // populate the database on first installation } elseif (!file_exists('../parameters/switch.on')) { echo Skin::build_block('<form method="get" action="populate.php">' . "\n" . '<p class="assistant_bar">' . Skin::build_submit_button(i18n::s('Initialize the database')) . '</p>' . "\n" . '</form>', 'bottom'); // or back to the control panel } else { $menu = array('control/' => i18n::s('Control Panel')); echo Skin::build_list($menu, 'menu_bar'); } // clear the cache Cache::clear(); // remember the change $label = i18n::c('The database has been optimised'); Logger::remember('control/setup.php: ' . $label); // ask for confirmation } else { // the splash message echo '<p>' . i18n::s('This script will check the structure of the database and optimize data storage:') . '</p>' . "\n" . '<ul>' . "\n" . '<li>' . i18n::s('Missing tables will be created, if necessary.') . '</li>' . "\n" . '<li>' . i18n::s('Some columns may be created or converted if their type has evolved.') . '</li>' . "\n" . '<li>' . i18n::s('All indexes will be (re)built.') . '</li>' . "\n" . '<li>' . i18n::s('Data files will be optimized as well.') . '</li>' . "\n" . '</ul>' . "\n"; // the submit button echo '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . Skin::build_submit_button(i18n::s('Ensure the database structure is accurate'), NULL, NULL, 'confirmed') . '<input type="hidden" name="action" value="build" />' . '</p></form>'; // the script used for form handling at the browser Page::insert_script('$("#confirmed").focus();'); // this may take several minutes echo '<p>' . i18n::s('When you will click on the button the server will be immediately requested to proceed. However, because of the so many things to do on the back-end, you may have to wait for minutes before getting a response displayed. Thank you for your patience.') . '</p>'; } }
$content .= $chunk; } } // with Indexes if (isset($_SESSION['htaccess']['indexes'])) { if (!($chunk = Safe::file_get_contents('control/htaccess/indexes/.htaccess'))) { Logger::error(sprintf(i18n::s('Impossible to read %s.'), 'control/htaccess/indexes/.htaccess')); } else { $content .= $chunk; } } // ensure smooth operations if ($content && !count($context['error'])) { // backup the old version Safe::unlink($context['path_to_root'] . '.htaccess.bak'); Safe::rename($context['path_to_root'] . '.htaccess', $context['path_to_root'] . '.htaccess.bak'); // update the parameters file if (!Safe::file_put_contents($context['path_to_root'] . '.htaccess', $content)) { Logger::error(sprintf(i18n::s('ERROR: Impossible to write to the file %s. The configuration has not been saved.'), $context['path_to_root'] . '.htaccess')); // allow for a manual update $context['text'] .= '<p style="text-decoration: blink;">' . sprintf(i18n::s('To actually change the configuration, please copy and paste following lines by yourself in file %s.'), $context['path_to_root'] . '.htaccess') . "</p>\n"; // job done } else { $context['text'] .= '<p>' . sprintf(i18n::s('The following configuration has been saved into the file %s.'), '.htaccess') . "</p>\n"; // remember the change $label = sprintf(i18n::c('%s has been updated'), '.htaccess'); Logger::remember('control/htaccess/index.php: ' . $label); } // display updated parameters $context['text'] .= Skin::build_box(i18n::s('Configuration parameters'), str_replace("\n", BR, htmlspecialchars($content)), 'folded'); // follow-up commands
/** * internal method to store patterns of this serveur in a file * this to spare time for parsing each extension in /codes at page loading * @see method render * * @global array $context * @param array $patterns_map */ private static function save_patterns($patterns_map) { global $context; // backup the old version Safe::unlink($context['path_to_root'] . 'codes/patterns.auto.php.bak'); Safe::rename($context['path_to_root'] . 'codes/patterns.auto.php', $context['path_to_root'] . 'codes/auto.patterns.auto.php.bak'); $content = '<?php' . "\n" . '// This file has been created by the script codes/codes.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, Please do not modify it manually.' . "\n"; foreach ($patterns_map as $pattern => $action) { $content .= '$patterns_map[\'' . $pattern . '\']="' . addcslashes(str_replace("\n", '\\n', $action), '"') . "\";\n"; } if (!Safe::file_put_contents('codes/patterns.auto.php', $content)) { Logger::error(sprintf(i18n::s('ERROR: Impossible to write to the file %s. The configuration has not been saved.'), 'codes/patterns.auto.php')); } }
/** * dynamically generate the page * * @see skins/index.php */ function send_body() { global $context, $local; // $local is required to localize included scripts // include every script that has to be run once global $scripts, $scripts_count; if (@count($scripts)) { // the alphabetical order may be used to control script execution order sort($scripts); reset($scripts); // process each script one by one foreach ($scripts as $item) { // do not execute on first installation if (file_exists('../parameters/switch.on') || file_exists('../parameters/switch.off')) { // ensure we have a valid database resource if (!$context['connection']) { break; } // remember this as an event Logger::remember('scripts/run_once.php: ' . sprintf(i18n::c('script %s has been executed'), $item)); // where scripts actually are $actual_item = str_replace('//', '/', $context['path_to_root'] . 'scripts/run_once/' . $item); // include the script to execute it $scripts_count++; echo Skin::build_block($item, 'subtitle'); include $actual_item; echo "\n"; } // ensure enough overall execution time Safe::set_time_limit(30); // stamp the file to remember execution time Safe::touch($actual_item); // rename the script to avoid further execution Safe::unlink($actual_item . '.done'); Safe::rename($actual_item, $actual_item . '.done'); } // refresh javascript libraries Cache::purge('js'); } // report on actual execution if ($scripts_count) { echo '<p> </p><p>' . sprintf(i18n::ns('%d script has been executed', '%d scripts have been executed', $scripts_count), $scripts_count) . "</p>\n"; } else { echo '<p>' . i18n::s('No script has been executed') . "</p>\n"; } // display the total execution time $time = round(get_micro_time() - $context['start_time'], 2); if ($time > 30) { echo '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>'; } // if the server has been switched off, go back to the control panel if (file_exists('../parameters/switch.off')) { echo '<form method="get" action="' . $context['url_to_root'] . 'control/">' . "\n" . '<p class="assistant_bar">' . Skin::build_submit_button(i18n::s('Control Panel')) . '</p>' . "\n" . '</form>' . "\n"; // else back to the control panel as well, but without a button } else { $menu = array('control/' => i18n::s('Control Panel')); echo Skin::build_list($menu, 'menu_bar'); } // purge the cache, since it is likely that we have modified some data Cache::clear(); }
// end of the form $context['text'] .= '</div></form>'; // set the focus Page::insert_script('$("#flash_font_r").focus();'); // general help on this form $help = '<p>' . i18n::s('Do not set any background color to achieve a transparent object.') . '</p>'; $context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help'); // no modifications in demo mode } elseif (file_exists($context['path_to_root'] . 'parameters/demo.flag')) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation in demonstration mode.')); // save updated parameters } else { // backup the old version Safe::unlink($context['path_to_root'] . 'parameters/feeds.flash.include.php.bak'); Safe::rename($context['path_to_root'] . 'parameters/feeds.flash.include.php', $context['path_to_root'] . 'parameters/feeds.flash.include.php.bak'); // build the new configuration file $content = '<?php' . "\n" . '// This file has been created by the configuration script feeds/flash/configure.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, for ' . Surfer::get_name() . '. Please do not modify it manually.' . "\n"; if (isset($_REQUEST['flash_font_r'])) { $content .= '$context[\'flash_font_r\']=' . addcslashes($_REQUEST['flash_font_r'], "\\'") . ";\n"; } if (isset($_REQUEST['flash_font_g'])) { $content .= '$context[\'flash_font_g\']=' . addcslashes($_REQUEST['flash_font_g'], "\\'") . ";\n"; } if (isset($_REQUEST['flash_font_b'])) { $content .= '$context[\'flash_font_b\']=' . addcslashes($_REQUEST['flash_font_b'], "\\'") . ";\n"; } if (isset($_REQUEST['flash_background_r'])) { $content .= '$context[\'flash_background_r\']=' . addcslashes($_REQUEST['flash_background_r'], "\\'") . ";\n"; } if (isset($_REQUEST['flash_background_g'])) {
} if (isset($_REQUEST['switch_contact'])) { $content .= '$context[\'switch_contact\']=\'' . addcslashes($_REQUEST['switch_contact'], "\\'") . "';\n"; } $content .= '?>' . "\n"; // save switch parameters, if any if (!Safe::file_put_contents('parameters/switch.include.php', $content)) { // not enough rights to write the file Logger::error(sprintf(i18n::s('Impossible to write to %s.'), 'parameters/switch.include.php.')); // allow for a manual update $context['text'] .= '<p style="text-decoration: blink;">' . sprintf(i18n::s('To actually change the configuration, please copy and paste following lines by yourself in file %s.'), 'parameters/switch.include.php') . "</p>\n"; // display updated parameters $context['text'] .= Skin::build_box(i18n::s('Configuration'), Safe::highlight_string($content), 'folded'); } // rename the switch file if (Safe::rename($context['path_to_root'] . 'parameters/switch.on', $context['path_to_root'] . 'parameters/switch.off')) { Logger::error(i18n::s('The server has been switched OFF. Switch it back on as soon as possible.')); // remember the change $label = i18n::c('The server has been switched off.'); Logger::remember('control/switch.php: ' . $label); // if the server is currently switched off } elseif (file_exists($context['path_to_root'] . 'parameters/switch.off')) { Logger::error(i18n::s('The server is currently switched off. All users are redirected to the closed page.')); } else { Logger::error(i18n::s('Impossible to rename the file parameters/switch.on to parameters/switch.off. Do it yourself manually if you like.')); } // follow-up commands $menu = array(); // do it again if (file_exists($context['path_to_root'] . 'parameters/switch.off')) { $menu = array_merge($menu, array('control/switch.php?action=on' => i18n::s('Switch on')));
// remember the change $label = sprintf(i18n::c('%s has been deleted'), $file); Logger::remember('control/virtual.php: ' . $label); } // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array(); $menu = array_merge($menu, array('control/virtual.php' => i18n::s('Manage virtual hosts'))); $menu = array_merge($menu, array('control/' => i18n::s('Control Panel'))); $follow_up .= Skin::build_list($menu, 'menu_bar'); $context['text'] .= Skin::build_block($follow_up, 'bottom'); // save the content of an updated file } elseif ($id && isset($_REQUEST['content']) && $_REQUEST['content']) { // backup the old version, if any Safe::unlink($context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php.bak'); Safe::rename($context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php', $context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php.bak'); // actual save if (Safe::file_put_contents('parameters/virtual_' . $id . '.include.php', $_REQUEST['content']) != strlen($_REQUEST['content'])) { Logger::error(sprintf(i18n::s('The target file %s may have been corrupted. Please check file content manually, and revert to the backup file, with the extension .bak, if necessary.'), 'parameters/virtual_' . $id . '.include.php')); } else { $context['text'] .= '<p>' . sprintf(i18n::s('The target file %s has been successfully updated.'), 'parameters/virtual_' . $id . '.include.php') . '</p>'; $context['text'] .= Skin::build_box(i18n::s('Configuration'), Safe::highlight_string($_REQUEST['content']), 'unfolded'); // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array(); $menu = array_merge($menu, array('control/virtual.php?id=' . urlencode($id) => i18n::s('View the configuration file'))); $menu = array_merge($menu, array('control/virtual.php' => i18n::s('Manage virtual hosts'))); $menu = array_merge($menu, array('control/' => i18n::s('Control Panel'))); $follow_up .= Skin::build_list($menu, 'menu_bar'); $context['text'] .= Skin::build_block($follow_up, 'bottom'); }