Beispiel #1
0
 function test_scandir_1()
 {
     $files = fbFile::scandir('.');
     $this->assertTrue(is_array($files), 'not an array');
     $this->assertTrue(count($files) > 0, 'array is empty');
     //		$this->assertTrue($this->isSorted($files)), 'is not sorted');
 }
Beispiel #2
0
 function scandir($path, $sorting_order = 0, $recursive = false)
 {
     $files = scandir($path, $sorting_order);
     if ($files === false) {
         return false;
     }
     $rv = array();
     $dirs = array();
     foreach ($files as $file) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         if ($recursive) {
             $file = $path . DIRECTORY_SEPARATOR . $file;
             if (@is_dir($file) && @is_readable($file)) {
                 $dirs[] = $file;
                 continue;
             }
         }
         $rv[] = $file;
     }
     foreach ($dirs as $dir) {
         $files = fbFile::scandir($dir, $sorting_order, $recursive);
         $rv = array_merge($rv, $files);
     }
     switch ($sorting_order) {
         case 0:
             sort($rv);
             break;
         case 1:
             rsort($rv);
             break;
         case false:
         case null:
             break;
         default:
             sort($rv);
             break;
     }
     return $rv;
 }
Beispiel #3
0
// $CVSHeader: _freebeer/bin/make_tests.php,v 1.2 2004/03/07 17:51:14 ross Exp $
// Copyright (c) 2002-2004, Ross Smith.  All rights reserved.
// Licensed under the BSD or LGPL License. See license.txt for details.
error_reporting(2047);
@ini_set('html_errors', false);
@ini_set('track_errors', true);
@ob_implicit_flush(true);
@set_time_limit(0);
defined('FREEBEER_BASE') || define('FREEBEER_BASE', getenv('FREEBEER_BASE') ? getenv('FREEBEER_BASE') : dirname(dirname(__FILE__)));
// should not be required:
//require_once FREEBEER_BASE . '/lib/Pear/Pear.php';
require_once FREEBEER_BASE . '/lib/File.php';
// scandir()
$file_dir = FREEBEER_BASE . '/lib';
$test_dir = FREEBEER_BASE . '/tests';
$files = fbFile::scandir($file_dir, 0, true);
$test_files = array();
foreach ($files as $file) {
    if (!preg_match('/\\.php$/i', $file)) {
        continue;
    }
    if (preg_match('/\\/tests\\//i', $file)) {
        continue;
    }
    $file = strtr($file, "\\", '/');
    $test_files[$file] = $file;
}
//print_r($test_files);
//exit;
foreach ($test_files as $file => $dummy) {
    include_once $file;
Beispiel #4
0
#!/usr/bin/php
<?php 
// $CVSHeader: _freebeer/bin/make_www_lib_tests.php,v 1.2 2004/03/07 17:51:14 ross Exp $
// Copyright (c) 2002-2004, Ross Smith.  All rights reserved.
// Licensed under the BSD or LGPL License. See license.txt for details.
error_reporting(2047);
@ini_set('html_errors', false);
@ini_set('track_errors', true);
@ob_implicit_flush(true);
@set_time_limit(0);
defined('FREEBEER_BASE') || define('FREEBEER_BASE', getenv('FREEBEER_BASE') ? getenv('FREEBEER_BASE') : dirname(dirname(__FILE__)));
require_once FREEBEER_BASE . '/lib/File.php';
// scandir()
$file_dir = FREEBEER_BASE . '/www/lib';
$test_dir = FREEBEER_BASE . '/www/lib/tests';
$files = fbFile::scandir($file_dir, null, true);
//print_r($files);
$test_files = array();
foreach ($files as $file) {
    /// \todo use DIRECTORY_SEPARATOR instead of hardcoded /
    $file = strtr($file, '\\', '/');
    if (!preg_match('/\\.js$/i', $file)) {
        continue;
    }
    if (preg_match('/jsunit\\.net/i', $file)) {
        continue;
    }
    $test_files[$file] = substr($file, strlen(FREEBEER_BASE) + 4);
}
print_r($test_files);
foreach ($test_files as $file => $www_file) {
Beispiel #5
0
@ini_set('track_errors', true);
@ob_implicit_flush(true);
@set_time_limit(0);
defined('FREEBEER_BASE') || define('FREEBEER_BASE', getenv('FREEBEER_BASE') ? getenv('FREEBEER_BASE') : dirname(dirname(__FILE__)));
//if (phpversion() < '5.0') {
//	require_once FREEBEER_BASE . '/lib/Backport.php'; // scandir
//}
//require_once FREEBEER_BASE . '/lib/System.php';
require_once FREEBEER_BASE . '/lib/File.php';
// scandir
$exts = array('cmd' => array('prior' => '@echo off', 'start' => 3, 'prefix' => ':: ', 'suffix' => ''), 'htm' => array('prior' => '', 'start' => 1, 'prefix' => '<!-- ', 'suffix' => ' -->'), 'ini' => array('prior' => '', 'start' => 1, 'prefix' => '# ', 'suffix' => ''), 'js' => array('prior' => '', 'start' => 1, 'prefix' => '// ', 'suffix' => ''), 'php' => array('prior' => '<?php', 'start' => 3, 'prefix' => '// ', 'suffix' => ''), 'pl' => array('prior' => '#!/usr/bin/perl', 'start' => 3, 'prefix' => '# ', 'suffix' => ''), 'po' => array('prior' => '', 'start' => 2, 'prefix' => '# ', 'suffix' => ''), 'sh' => array('prior' => '#!/bin/sh', 'start' => 3, 'prefix' => '# ', 'suffix' => ''), 'sql' => array('prior' => '', 'start' => 1, 'prefix' => '-- ', 'suffix' => ''), 'txt' => array('prior' => '', 'start' => 1, 'prefix' => '', 'suffix' => ''));
$exts['bat'] = $exts['cmd'];
$exts['html'] = $exts['htm'];
$exts['pot'] = $exts['po'];
$search1 = array('|^(\\S+)\\s*\\$CVSHeader[^\\$]*|i' => '$' . 'CVSHeader$', '|^\\s*$|' => '', '|^(\\S+)\\s*Copyright.*Ross\\s+Smith|i' => 'Copyright (c) 2002-2004, Ross Smith.  All rights reserved.', '|^(\\S+)\\s*Licensed\\s+under\\s+the\\s+BSD|i' => 'Licensed under the BSD or LGPL License. See license.txt for details.');
$files = fbFile::scandir(FREEBEER_BASE, 0, true);
foreach ($files as $file) {
    $basename = basename($file);
    $base = $basename;
    $ext = '';
    if (preg_match('/(.+)\\.([^\\.]+)/', $basename, $matches)) {
        $base = $matches[1];
        $ext = $matches[2];
    }
    $found = false;
    foreach ($exts as $extregex => $extrules) {
        if (preg_match('/' . $extregex . '/', $ext, $matches)) {
            $found = true;
            break;
        }
    }
Beispiel #6
0
<?php

// $CVSHeader: _freebeer/www/lib/tests/index.php,v 1.3 2004/03/08 04:29:18 ross Exp $
// Copyright (c) 2002-2004, Ross Smith.  All rights reserved.
// Licensed under the BSD or LGPL License. See license.txt for details.
error_reporting(2047);
defined('FREEBEER_BASE') || define('FREEBEER_BASE', getenv('FREEBEER_BASE') ? getenv('FREEBEER_BASE') : dirname(dirname(dirname(dirname(__FILE__)))));
// no longer required, right?
// require_once FREEBEER_BASE . '/lib/Pear/Pear.php';
require_once FREEBEER_BASE . '/lib/File.php';
// scandir()
require_once FREEBEER_BASE . '/www/fbWeb.php';
$www_root = fbWeb::getWebRoot();
$rootdir = $www_root . '/lib/tests/';
$files = fbFile::scandir('.', null, true);
$files2 = array();
$files3 = array();
foreach ($files as $file) {
    $file = substr($file, 2);
    /// \todo change to DIRECTORY_SEPARATOR, or remove
    $file = strtr($file, "\\", '/');
    if (!preg_match('/\\.(php|htm|html)$/i', $file)) {
        continue;
    }
    if (preg_match('/^index\\.php$/i', $file)) {
        continue;
    }
    if (preg_match('/^_.*\\.php$/i', $file)) {
        continue;
    }
    $path = $rootdir . $file;
Beispiel #7
0
function update_htaccess($dir, $depth)
{
    if (preg_match('|/CVS$|', $dir)) {
        return true;
    }
    if (preg_match('|/opt$|', $dir)) {
        return true;
    }
    if (preg_match('|/wip$|', $dir)) {
        return true;
    }
    if (preg_match('|/www$|', $dir)) {
        return true;
    }
    $files = fbFile::scandir($dir, 0, false);
    $dirs = array();
    $found = false;
    foreach ($files as $file) {
        $path = $dir . '/' . $file;
        if (@is_dir($path)) {
            $dirs[] = $path;
            continue;
        }
        if ($file == '.htaccess') {
            $found = true;
            continue;
        }
    }
    // foreach($files as $file)
    $cvsheader_found = false;
    $deny_found = false;
    $lines = array();
    $path = $dir . '/.htaccess';
    if ($found) {
        $lines = file($path);
        if ($lines === false) {
            die(sprintf("Can't open '%s': %s", $file, $php_errormsg));
        }
        for ($i = 0; $i < count($lines); ++$i) {
            if (preg_match('/(allow|deny)\\s+from\\s+all/i', $lines[$i])) {
                $deny_found = true;
            }
            if (preg_match('/\\$CVSHeader[^\\$]*\\$/', $lines[$i])) {
                $cvsheader_found = true;
            }
            if ($deny_found && $cvsheader_found) {
                break;
            }
        }
    }
    if (!$deny_found || !$cvsheader_found) {
        if (!$deny_found) {
            $lines[] = "Deny from all\n";
        }
        if (!$cvsheader_found) {
            $lines[] = "\n# \$CVSHeader\$\n";
        }
        if ($found) {
            $file_tmp = $path . '.tmp';
            $file_bak = $path . '.bak';
        } else {
            $file_tmp = $path;
        }
        $fp = fopen($file_tmp, 'wb');
        if (!$fp) {
            die(sprintf("Can't create '%s': %s", $file_tmp, $php_errormsg));
        }
        for ($i = 0; $i < count($lines); ++$i) {
            fwrite($fp, $lines[$i]);
        }
        fclose($fp);
        printf("Updated %s\n", $path);
        if ($found) {
            if (!@rename($path, $file_bak)) {
                die(sprintf("Can't rename '%s' to '%s': %s", $path, $file_bak, $php_errormsg));
            }
            if (!@rename($file_tmp, $path)) {
                die(sprintf("Can't rename '%s' to '%s': %s", $file_tmp, $path, $php_errormsg));
            }
        }
    }
    // if (!$deny_found || !$cvsheader_found)
    if ($depth == 0) {
        foreach ($dirs as $dir) {
            if (!update_htaccess($dir, $depth + 1)) {
                return false;
            }
        }
    }
    return true;
}