示例#1
0
文件: validate.php 项目: rair/yacs
/**
 * dynamically generate the page
 *
 * @see skins/index.php
 */
function send_body()
{
    global $context;
    // only associates can proceed
    if (!Surfer::is_associate()) {
        Safe::header('Status: 401 Unauthorized', TRUE, 401);
        echo '<p>' . i18n::s('You are not allowed to perform this operation.') . "</p>\n";
        // forward to the index page
        $menu = array('scripts/' => i18n::s('Server software'));
        echo Skin::build_list($menu, 'menu_bar');
        // ask for confirmation
    } elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
        // the splash message
        echo '<p>' . i18n::s('This tool will include most of the running reference PHP scripts. Any syntax error should be spotted easily.') . '</p>';
        // the submit button
        echo '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . Skin::build_submit_button(i18n::s('Yes, I want to validate scripts'), NULL, NULL, 'confirmed') . '</p></form>';
        // set the focus on the button
        Page::insert_script('$("#confirmed").focus();');
        // this may take some time
        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>';
        // just do it
    } else {
        // the splash message
        echo '<p>' . i18n::s('All reference scripts are included, to show evidence of possible syntax errors.') . "</p>\n";
        // list running scripts
        echo '<p>' . i18n::s('Listing files...') . BR . "\n";
        // locate script files starting at root
        $scripts = Scripts::list_scripts_at(NULL);
        if (is_array($scripts) && count($scripts)) {
            echo BR . sprintf(i18n::s('%d scripts have been found.'), count($scripts)) . "\n";
            natsort($scripts);
        }
        echo "</p>\n";
        // including scripts
        echo '<p>' . i18n::s('Including reference scripts...') . BR . "\n";
        // strip as much output as possible
        $_SERVER['REQUEST_METHOD'] = 'HEAD';
        // we will finalize this page later on
        global $finalizing_fuse;
        $finalizing_fuse = FALSE;
        // take care of dependancies
        include_once '../behaviors/behavior.php';
        include_once '../services/codec.php';
        include_once '../users/authenticator.php';
        // analyse each script
        $included_files = 0;
        $links_to_be_checked_manually = array();
        foreach ($scripts as $file) {
            // ensure we have enough time to process this script
            Safe::set_time_limit(30);
            // skip run once scripts
            if (strpos($file, 'run_once/')) {
                continue;
            }
            // don't include ourself
            if ($file == 'scripts/validate.php') {
                continue;
            }
            // process only reference scripts
            if (!Scripts::hash($file)) {
                continue;
            }
            // check file content
            if (!($handle = Safe::fopen($file, 'rb'))) {
                echo sprintf(i18n::s('%s has no readable content.'), $file) . BR . "\n";
                continue;
            }
            // look at the beginning of the file
            if (!($header = fread($handle, 16384))) {
                echo sprintf(i18n::s('%s has no readable content.'), $file) . BR . "\n";
                fclose($handle);
                continue;
            }
            fclose($handle);
            // skip scripts that generate content asynchronously
            if (stripos($header, 'send_body') || stripos($header, 'page::content')) {
                $links_to_be_checked_manually[$file] = '(asynchronous)';
                continue;
            }
            // skip scripts that would redefine our skin
            if (stripos($header, 'extends skin_skeleton')) {
                $links_to_be_checked_manually[$file] = '(skin)';
                continue;
            }
            // log script inclusion on development host
            if ($context['with_debug'] == 'Y') {
                logger::remember('scripts/validate.php: inclusion of ' . $file, '', 'debug');
            }
            // include the script and display any error
            $included_files += 1;
            $validate_stamp = time();
            echo sprintf(i18n::s('inclusion of %s'), $file) . "\n";
            Safe::chdir($context['path_to_root'] . dirname($file));
            include_once $context['path_to_root'] . $file;
            $duration = time() - $validate_stamp;
            if ($duration) {
                echo ' (' . $duration . 's.)';
            }
            echo BR;
        }
        // memory status
        $used_memory = '';
        if (is_callable('memory_get_usage')) {
            $used_memory = ' (' . memory_get_usage() . ' bytes)';
        }
        // report of included files
        if ($included_files > 1) {
            echo '<p>' . sprintf(i18n::s('%d files have been included.'), $included_files) . $used_memory . '</p>';
        }
        // list files to be checked manually
        if (count($links_to_be_checked_manually)) {
            echo '<p>' . i18n::s('Following scripts have to be included separately:') . BR . "\n";
            ksort($links_to_be_checked_manually);
            foreach ($links_to_be_checked_manually as $file => $label) {
                echo Skin::build_link($file, $file, 'basic') . ' ' . $label . BR . "\n";
            }
            echo sprintf(i18n::s('%d files to be checked manually.'), count($links_to_be_checked_manually)) . '</p>' . "\n";
        }
        // display the execution time
        $time = round(get_micro_time() - $context['start_time'], 2);
        echo '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>';
        // forward to the referential building
        echo '<form method="get" action="' . $context['url_to_root'] . 'scripts/build.php"><p>' . "\n" . Skin::build_submit_button(i18n::s('If no error has popped up, build the reference set >>')) . "\n" . '</p></form>' . "\n";
        // this may take some time
        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>';
        // clear text some scripts could have added
        $context['debug'] = '';
        $context['extra'] = '';
        $context['navigation'] = '';
        $context['suffix'] = '';
        $context['text'] = '';
        $context['page_details'] = '';
        $context['page_footer'] = '';
        $context['page_menu'] = array();
        $context['page_tags'] = '';
        $context['page_tools'] = '';
        // now we will finalize this page
        global $finalizing_fuse;
        unset($finalizing_fuse);
    }
}
示例#2
0
文件: chmod.php 项目: rair/yacs
$context['page_title'] = i18n::s('Update file permissions');
// anonymous users are invited to log in or to register
if (!Surfer::is_logged()) {
    Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode('control/chmod.php'));
} elseif (!Surfer::is_associate() && !(file_exists($context['path_to_root'] . 'parameters/switch.on') || file_exists($context['path_to_root'] . 'parameters/switch.off'))) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // forward to the index page
    $menu = array('control/' => i18n::s('Control Panel'));
    $context['text'] .= Skin::build_list($menu, 'menu_bar');
    // do the action
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'confirm') {
    // list running scripts
    $context['text'] .= '<p>' . i18n::s('Listing files...') . BR . "\n";
    // locate script files starting at root
    $scripts = Scripts::list_scripts_at(NULL);
    if (is_array($scripts)) {
        $context['text'] .= BR . sprintf(i18n::s('%d scripts have been found.'), count($scripts)) . "\n";
    }
    $context['text'] .= "</p>\n";
    // chmod each file
    $context['text'] .= '<p>' . i18n::s('Updating file permissions...') . BR . "\n";
    // analyse each script
    $count = 0;
    foreach ($scripts as $file) {
        // this will be filtered by umask anyway
        Safe::chmod($context['path_to_root'] . $file, $context['file_mask']);
        $count++;
        // avoid timeouts
        if (!($count % 50)) {
            Safe::set_time_limit(30);
示例#3
0
文件: scripts.php 项目: rair/yacs
 /**
  * list running scripts below a certain path
  *
  * This script is used to list scripts below the YACS installation path.
  * Special directories 'scripts/reference' and 'scripts/staging' are skipped.
  * Also directory entries named either 'files' or 'images' are not recursively scanned,
  * because of the potential high number of uninteresting files they can contain.
  *
  * Also echo '.' (one per file) and '!' (one per directory) during the scan,
  * if the verbose parameter is set to TRUE.
  *
  * @param string the path to scan
  * @param boolean TRUE to animate the screen, FALSE to stay silent
  * @return an array of file names
  *
  * @see scripts/build.php
  */
 public static function list_scripts_at($path, $verbose = TRUE)
 {
     global $context, $script_count;
     // we want a list of files
     $files = array();
     $path_translated = $context['path_to_root'];
     if ($path) {
         $path_translated .= '/' . $path;
     }
     if ($handle = Safe::opendir($path_translated)) {
         while (($node = Safe::readdir($handle)) !== FALSE) {
             if ($node[0] == '.') {
                 continue;
             }
             // avoid listing of special directories
             if ($node == 'reference' || $node == 'staging') {
                 continue;
             }
             // make a real name
             if ($path) {
                 $target = $path . '/' . $node;
             } else {
                 $target = $node;
             }
             $target_translated = $path_translated . '/' . $node;
             // scan a sub directory
             if (is_dir($target_translated)) {
                 // skip files and images, because of so many sub directories
                 if (strpos($path, 'files/') !== FALSE || strpos($path, 'images/') !== FALSE) {
                     continue;
                 }
                 // already included
                 if (strpos($path, 'included/') !== FALSE) {
                     continue;
                 }
                 // extend the list recursively
                 $files = array_merge($files, Scripts::list_scripts_at($target));
                 // animate the screen
                 if ($verbose) {
                     $context['text'] .= '!';
                 }
                 if ($script_count++ > 50) {
                     $script_count = 0;
                     if ($verbose) {
                         $context['text'] .= BR . "\n";
                     }
                 }
                 // scan a file
             } elseif (preg_match('/\\.php$/i', $node) && is_readable($target_translated)) {
                 // append the script to the list
                 if ($path) {
                     $files[] = $path . '/' . $node;
                 } else {
                     $files[] = $node;
                 }
                 // animate the screen
                 if ($verbose) {
                     $context['text'] .= '.';
                 }
                 if ($script_count++ > 50) {
                     $script_count = 0;
                     if ($verbose) {
                         $context['text'] .= BR . "\n";
                     }
                     Safe::set_time_limit(30);
                 }
             }
         }
         Safe::closedir($handle);
     }
     return $files;
 }