Esempio n. 1
0
# Web: http://www.uniformserver.com
# V1.0 29-6-2009
###############################################################################
*/
#error_reporting(0);  // Disable PHP errors and warnings
// Comment to Enable for testing
chdir(dirname(__FILE__));
// Change wd to this files location
include_once "../../main/includes/config.inc.php";
include_once "../../main/includes/functions.php";
run_location_tracker();
// Have servers moved update configuration accordingly
//=== Update shebang in all files in folder cgi-bin and sub-folders ===========
print "\n ============== PERL SHEBANG UPDATE =============\n\n";
if (perl_installed()) {
    $start_dir = $us_cgi_bin;
    // Main Perl folder
    $file_type = '/(\\.pl|\\.cgi)/';
    // List of file types
    $search_str = "/#!.*/";
    // Old shebang
    $replace_str = "#!" . $base_f . "/usr/bin/perl.exe";
    // New shebang
    recursive_search_replace($start_dir, $file_type, $search_str, $replace_str);
    print " Updated shebang in files: *.pl and *.cgi\n\n";
    print " In folder UniServer\\cgi-bin and all sub-folders.\n\n";
} else {
    print " No action taken!\n\n";
    print " Perl not installed\n\n";
}
exit;
Esempio n. 2
0
function recursive_search_replace($start_dir, $file_type, $search_str, $replace_str)
{
    $dirlist = opendir($start_dir);
    // Open start directory
    while ($file = readdir($dirlist)) {
        // Iterate through list
        if ($file != '.' && $file != '..') {
            // Skip if . or ..
            $newpath = $start_dir . '/' . $file;
            // Create path. Either dir or file
            if (is_dir($newpath)) {
                // Is it a folder
                // yes: Repeat this function
                recursive_search_replace($newpath, $file_type, $search_str, $replace_str);
            } else {
                // no: Its a file
                if (preg_match($file_type, $newpath)) {
                    // Filter by file extension.
                    $fh = fopen($newpath, 'r');
                    // Open file for read
                    $Data = fread($fh, filesize($newpath));
                    // Read all data into variable
                    fclose($fh);
                    // Close file handle
                    $Data = preg_replace($search_str, $replace_str, $Data, -1, $count);
                    // S & R
                    if ($count) {
                        // Was a replacement made
                        $fh = fopen($newpath, 'w');
                        // yes: Open file for write
                        fwrite($fh, $Data);
                        // Write new $Data to file
                        fclose($fh);
                        // Close file handle
                    }
                }
            }
            //eof else
        }
    }
    //eof while
    closedir($dirlist);
    // Close handle
    return true;
    // Return
}