> [php] New Server, Script to generate updates.ini online
Nuno Brito
post Oct 8 2007, 12:10 AM
Post #1


Advanced Member
***

Group: .script developer
Posts: 4,153
Joined: 13-July 06
From: Azores
Member No.: 1


Portugal


Hi everyone!

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.


CODE

<?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, and
a matching function to write to a .INI file, both of which are binary safe.

Version 1.0

Copyright © 2005 Justin Frim <phpcoder@cyberpimp.pimpdomain.com>

Sections can use any character excluding ASCII control characters and ASCII
DEL. (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 comment
character.

Values are binary safe (encoded with C-style backslash escape codes) and may
be enclosed by double-quotes (to retain leading & trailing spaces).

User-defined comment character can be any non-white-space ASCII character
excluding ASCII opening bracket ([).

readINIfile() is case-insensitive when reading sections and keys, returning
an array with lower-case keys.
writeINIfile() writes sections and keys with first character capitalization.
Invalid characters are converted to ASCII dash / hyphen (-). Values are
always enclosed by double-quotes.

writeINIfile() also provides a method to automatically prepend a comment
header from ASCII text with line breaks, regardless of whether CRLF, LFCR,
CR, or just LF line break sequences are used! (All line breaks are
translated 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 file
if (file_exists($output_filename))
{
if (!unlink($output_filename))
{
die("Failed to create $filename");
}
else touch($output_filename);
}




/////////////////////////////////////////////////////////////////////// Start Here ///////////////////////////////////////////////////////


// Add the header to our file
output ("; 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 directory
getDirectory( "." );


// Small test to indiv
//list_folders ("./Tools");
//list_files ("./Tools");


?>


(IMG:../forums/style_emoticons/default/smile.gif)
Go to the top of the page
 
+Quote Post
Digg this topic Add to my del.icio.us  
Start new topic
Replies (1 - 2)
psc
post Oct 10 2007, 07:44 AM
Post #2


Guru
***

Group: .script developer
Posts: 2,983
Joined: 14-July 06
From: Korschenbroich, Germany
Member No.: 3


Germany


QUOTE(Nuno Brito @ Oct 8 2007, 02:10 AM) *
Hi everyone!

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


I tried and it works well for me (IMG:../forums/style_emoticons/default/thumbup.gif)

This will remarkably decrease the time (and the complexity) to upload non-script files.

Two suggestions:
  • If the output file does not exist, simply create it rather than to preceed all linews with 'not writable'
  • I have a server structure like this:
    Attached Image

    And would like to exclude LiveXP20070731. An empty flag file for including (or omitting) would be nice
Peter
Go to the top of the page
 
+Quote Post
Nuno Brito
post Oct 10 2007, 08:20 AM
Post #3


Advanced Member
***

Group: .script developer
Posts: 4,153
Joined: 13-July 06
From: Azores
Member No.: 1


Portugal


Thanks for testing Peter! (IMG:../forums/style_emoticons/default/thumbsup.gif)


- Under windows the new file is generated straight away but on debian it seems necessary to have the proper permissions to create a file - does anyone here know how solve this detail? Will have to dig in a bit further and see how it can be done.

- Will try to add a folder exclusion list

(IMG:../forums/style_emoticons/default/smile.gif)
Go to the top of the page
 
+Quote Post
« Next Oldest · Development · Next Newest »
 

Fast ReplyReply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

Collapse

> Similar Topics

  Topic Replies Topic Starter Views Last Action
No new Pinned: New features on WinBuilder.exe
Post your ideas and suggestions for the next version
36 Nuno Brito 3,221 Today, 12:32 AM
Last post by: sokolofskid
No new Pinned: Topic has attachmentsNew nativeEx WEB site
27 psc 1,867 10th October 2007 - 04:48 PM
Last post by: psc
No new votes Poll: New slogan for WinBuilder
Replacing the "Build bootable Environments"
24 Nuno Brito 1,394 9th October 2007 - 08:58 PM
Last post by: phox
No new votes Poll: New name for WinXPE/WindowsXPE project
7 h7se 636 9th October 2007 - 05:46 PM
Last post by: MedEvil
No New Posts Newbie How to?
0 lundholmster 320 25th September 2007 - 07:18 PM
Last post by: lundholmster


 

Display Mode: Switch to: Standard · Linear+ · Switch to: Outline

Track this topic · Email this topic · Print this topic · Subscribe to this forum

- Lo-Fi Version Time is now: 12th October 2007 - 04:43 AM

MKPortal ©2003-2006 mkportal.it