Description
This beta script is mostly meant for developers who wish to upload a few files to a web server and need to modify the updates.ini file.
It will avoid having to maintain a mirror server on their computer or manually editing the changes on the updates.ini
What it will do:
Will output a new updates.ini based on the contents of the subfolders and files from where it is placed.
Usage
-- Upload to the same folder where your updates.ini is placed
-- Change permissions of the output file to 777
-- Run this script - example: http://myserver.com/new_server.php
Beta testing
This script was tested under xampp running PHP5 in windows - I've noticed that under the boot-land.net server (which is based on debian), a few modifications had to be made.
Please help by reporting any bugs you notice - if you have experience with PHP and know how to fix it, I would appreciate any help!
By default - this script will output to a file called test.txt - you'll be able to change these settings inside the script itself
Advantages
This means that you can upload your scripts at any given time to your download server and then use this script to generate a new valid updates.ini to be used along with wb.
<?php// This file will generate an updates file based on the all files and subfolders available// It is supposed to be used with the download center from winbuilder// Main Configuration - edit if needed //// How should the updates file be called?$output_filename = 'test.txt';$update_section = 'Updates';function output ($somecontent) // this function will output both on the webpage as on the text file { // Output this text on the web page - Add // to make it faster or avoid any output echo "$somecontent</br>"; $output_filename = 'test.txt'; // Let's make sure the file exists and is writable first.if (is_writable($output_filename)) { if (!$handle = fopen($output_filename, 'a+')) { echo "Cannot open file ($output_filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent."\n") === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle);} else { echo "The file $output_filename is not writable";} }function text_decode ($my_string) { $str_processed = str_replace(" ", "#\$s",$my_string); $str_processed = str_replace(",", "#\$c",$str_processed); return $str_processed; }function GetMD5_text($chkfilename, $chkPath) { // let's convert a few / with \ and remove any dots on the path $CleanDir01 = str_replace("./", ".",$chkPath); $CleanDir02 = str_replace(".", "",$CleanDir01); $CleanDir03 = str_replace("/", "\\",$CleanDir02); ////////////////// /* $myMD5 = dirname(__FILE__)."\\".$CleanDir03."\\".$chkfilename; $chkmd5return = md5_file("$myMD5"); */ //$myMD5 = dirname(__FILE__)."//".$CleanDir03."//".$chkfilename; //echo "-------[$chkPath/$chkfilename]---</br>"; $myMD5 = "$chkPath/$chkfilename"; @$chkmd5return = md5_file("$myMD5"); //////////////////// // Next step is to identify which sort of file we're talking about. $path_parts = pathinfo($chkPath."/".$chkfilename); $myExtension = strtolower($path_parts['extension']); $script_extension = array('script','project'); // Let's see what sort of file this is.. if( !in_array( $myExtension, $script_extension ) ) { // Output results for non script files output ("$chkfilename=$CleanDir02/$chkfilename,$chkmd5return,#".filesize($chkPath."/".$chkfilename)); } // Let's process this script file else { // Parse with sections //@$ini_array = parse_ini_file($chkPath."/".$chkfilename, true); $ini_array = readINIfile ($chkPath."/".$chkfilename, ';'); $script_title = text_decode ($ini_array['main']['title']); $script_description = text_decode ($ini_array['main']['description']); $script_website = text_decode ($ini_array['main']['contact']); $script_author = text_decode ($ini_array['main']['author']); $script_version = $ini_array['main']['version']; $script_size = "#".filesize($chkPath."/".$chkfilename); $script_download_level = $ini_array['main']['download_level']; /* Test output echo "$script_version</br>$script_title</br>$script_description</br>$script_author</br>$script_website</br>$script_size</br>$script_download_level</br>"; die (""); */ // Final Output output ("$chkfilename=$CleanDir02/$chkfilename,$chkmd5return,$script_version,$script_title,$script_description,$script_author,$script_website,$script_size,$script_download_level"); } } // end function function getDirectory( $path = '.', $level = 0 ){ $ignore = array( 'cgi-bin', '.', '..', basename(__FILE__), 'updates.ini'); // Directories to ignore when listing output. Many hosts // will deny PHP access to the cgi-bin. // It will also ignore this file - making it invisible on the listing ////////////////// First loop to display only folders $dh = @opendir( $path ); // Open the directory to the handle $dh ////////////////// Second loop to spider inside directories while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory if( !in_array( $file, $ignore ) ){ // Check that this file is not to be ignored if( is_dir( "$path/$file" ) ){ // Its a directory, so we need to keep reading down... // let's convert a few / with \ and remove any dots on the path $CleanDir01 = str_replace(".", "",$path); $CleanDir02 = str_replace("/", "\\",$CleanDir01); output(""); output("[Updates$CleanDir02\\$file]"); $new_list = $path."/".$file; $custom_folder = substr($CleanDir02."\\".$file."\\",1); list_folders ($new_list, $custom_folder); list_files ($new_list); getDirectory( "$path/$file", ($level+1) ); // Re-call this same function but on a new directory. // this is what makes function recursive. } else { //GetMD5_text($file, $path); } // Is dir or File? } // Should it be ignored? } // While we find files closedir( $dh ); // Close the directory handle}// finished function function list_files ($Start_Path) { if ($handle = opendir($Start_Path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $myDir = realpath($Start_Path."\\".$file); if( is_dir($myDir)) { //echo "$file=folder</br>"; } else { GetMD5_text ($file, $Start_Path); //echo "Not dir -- $file</br>"; } } } closedir($handle); } } function list_folders ($Start_Path, $extra = '') { if ($handle = opendir($Start_Path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { //$myDir = realpath($Start_Path."\\".$file); $myDir = realpath($Start_Path."/".$file); if( is_dir($myDir)) { //echo "$extra$file=folder</br>"; output ("$extra$file=folder"); } //else //echo "Not dir -- $file</br>"; } } closedir($handle); } } /*Function to replace PHP's parse_ini_file() with much fewer restritions, anda matching function to write to a .INI file, both of which are binary safe.Version 1.0Copyright © 2005 Justin Frim <phpcoder@cyberpimp.pimpdomain.com>Sections can use any character excluding ASCII control characters and ASCIIDEL. (You may even use [ and ] characters as literals!)Keys can use any character excluding ASCII control characters, ASCII DEL,ASCII equals sign (=), and not start with the user-defined commentcharacter.Values are binary safe (encoded with C-style backslash escape codes) and maybe enclosed by double-quotes (to retain leading & trailing spaces).User-defined comment character can be any non-white-space ASCII characterexcluding ASCII opening bracket ([).readINIfile() is case-insensitive when reading sections and keys, returningan array with lower-case keys.writeINIfile() writes sections and keys with first character capitalization.Invalid characters are converted to ASCII dash / hyphen (-). Values arealways enclosed by double-quotes.writeINIfile() also provides a method to automatically prepend a commentheader from ASCII text with line breaks, regardless of whether CRLF, LFCR,CR, or just LF line break sequences are used! (All line breaks aretranslated to CRLF)*/function readINIfile ($filename, $commentchar) { $array1 = file($filename); $section = ''; foreach ($array1 as $filedata) { $dataline = trim($filedata); $firstchar = substr($dataline, 0, 1); if ($firstchar!=$commentchar && $dataline!='') { //It's an entry (not a comment and not a blank line) if ($firstchar == '[' && substr($dataline, -1, 1) == ']') { //It's a section $section = strtolower(substr($dataline, 1, -1)); }else{ //It's a key... $delimiter = strpos($dataline, '='); if ($delimiter > 0) { //...with a value $key = strtolower(trim(substr($dataline, 0, $delimiter))); $value = trim(substr($dataline, $delimiter + 1)); if (substr($value, 1, 1) == '"' && substr($value, -1, 1) == '"') { $value = substr($value, 1, -1); } $array2[$section][$key] = stripcslashes($value); }else{ //...without a value $array2[$section][strtolower(trim($dataline))]=''; } } }else{ //It's a comment or blank line. Ignore. } } return $array2;}function writeINIfile ($filename, $array1, $commentchar, $commenttext) { $handle = fopen($filename, 'wb'); if ($commenttext!='') { $comtext = $commentchar. str_replace($commentchar, "\r\n".$commentchar, str_replace ("\r", $commentchar, str_replace("\n", $commentchar, str_replace("\n\r", $commentchar, str_replace("\r\n", $commentchar, $commenttext) ) ) ) ) ; if (substr($comtext, -1, 1)==$commentchar && substr($comtext, -1, 1)!=$commentchar) { $comtext = substr($comtext, 0, -1); } fwrite ($handle, $comtext."\r\n"); } foreach ($array1 as $sections => $items) { //Write the section if (isset($section)) { fwrite ($handle, "\r\n"); } //$section = ucfirst(preg_replace('/[-\37]|[\177-\377]/', "-", $sections)); $section = ucfirst(preg_replace('/[-\37]|\177/', "-", $sections)); fwrite ($handle, "[".$section."]\r\n"); foreach ($items as $keys => $values) { //Write the key/value pairs //$key = ucfirst(preg_replace('/[-\37]|=|[\177-\377]/', "-", $keys)); $key = ucfirst(preg_replace('/[-\37]|=|\177/', "-", $keys)); if (substr($key, 0, 1)==$commentchar) { $key = '-'.substr($key, 1); } $value = ucfirst(addcslashes($values,'')); fwrite ($handle, ' '.$key.' = "'.$value."\"\r\n"); } } fclose($handle);} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Let's create a new fileif (file_exists($output_filename)) { if (!unlink($output_filename)) { die("Failed to create $filename"); } else touch($output_filename); } /////////////////////////////////////////////////////////////////////// Start Here /////////////////////////////////////////////////////// // Add the header to our fileoutput ("; This file is used by the Download Center from WinBuilder");output ("; to know wich files are available for update and download");output ("");output ("[info]");output ("Title=Downloads");output ("Version=072");output ("Beta=0");output ("");output ("[$update_section]"); // List initial folders (ignore any files on root)list_folders (".");// Get the current directorygetDirectory( "." );// Small test to indiv//list_folders ("./Tools");//list_files ("./Tools");?>