From a4ba11d87aebb95701dd56a5bfc28bf87aa58976 Mon Sep 17 00:00:00 2001 From: sairuk Date: Sat, 1 May 2010 15:41:17 +0000 Subject: [PATCH] changed: file reading functions to use fgets instead of file(), filezilla filters.xml output now named correctly --- php/listgen/includes/functions.php | 327 ++++++++++++----------------- php/listgen/outputs/filezilla.php | 9 +- 2 files changed, 143 insertions(+), 193 deletions(-) diff --git a/php/listgen/includes/functions.php b/php/listgen/includes/functions.php index 561c5de..ce54f02 100755 --- a/php/listgen/includes/functions.php +++ b/php/listgen/includes/functions.php @@ -3,35 +3,133 @@ # Global Variables global $modname, $fixfile, $ext, $name, $outfile, $xmlhndl, $rompath, $sessionID, $maxviewbytes; -# If page is reloaded from form with ext passed -# populate $ext -if (isset($_POST['rompath'])) -{ - # Set $ext to combo data - $ext = ".".$_POST['ext']; -} else if ($_POST['ext'] == "custom" ) { - - # Set $ext to form data - $ext = ".".$_POST['custext']; -} else { - # Clear $ext - $ext = ""; -} +# If page is reloaded from form with ext passed populate $ext +if (isset($_POST['rompath'])) { $ext = ".".$_POST['ext']; #Set $ext to combo data +} else if ($_POST['ext'] == "custom" ) { $ext = ".".$_POST['custext']; #Set $ext to form data +} else { $ext = ""; } #Clear $ext # Initialise Session Information -session_start(); -$sessionID = session_id(); +session_start();$sessionID = session_id(); # If page is reloaded from form with rompath passed # strip slashes from the path and print path to the # screen -if (isset($_POST['rompath'])) -{ - $rompath = stripslashes($_POST['rompath']); - print $rompath; +if (isset($_POST['rompath'])) { $rompath = stripslashes($_POST['rompath']); } + +/* + * switchOutput + * + * adds in output format data + */ +function switchOutput($pstQueue) { + + global $fixfile, $name, $modname, $outurl; + + $name = substr($fixfile,0,strlen($fixfile)-4); + + # For Debugging + #$pstQueue = "test"; + + # Outputs + switch ($pstQueue) { + case filezilla: + require(DOCROOT.'/outputs/filezilla.php');break; + case wget: + require(DOCROOT.'/outputs/wget.php');break; + case msbat: + require(DOCROOT.'/outputs/msbat.php');break; + case CRCmsbat: + require(DOCROOT.'/outputs/msbat-crc.php');break; + case msbatnumbered: + require(DOCROOT.'/outputs/msbat-numbered.php');break; + case bash: + require(DOCROOT.'/outputs/bash.php');break; + case google: + $modname = 'Google Search'; + $outurl = "http://www.google.com.au/search?q="; + require(DOCROOT.'/outputs/html_generic.php');break; + case ebay: + $modname = 'Ebay Search'; + $outurl = "http://shop.ebay.com/?_nkw="; + require(DOCROOT.'/outputs/html_generic.php');break; + case ebayau: + $modname = "Ebay Australia Search"; + $outurl = "http://shop.ebay.com.au/?_nkw="; + require(DOCROOT.'/outputs/html_generic.php');break; + case binsearch: + $modname = "binsearch.info"; + $outurl = "http://www.binsearch.info/?q="; + require(DOCROOT.'/outputs/html_generic.php'); + case easynews: + $modname = "EasyNews Global Search"; + $outurl = "http://members.easynews.com/global4/search.html?gps="; + require(DOCROOT.'/outputs/html_generic.php');break; + case htmlall: + require(DOCROOT.'/outputs/html_all.php');break; + case mamewah: + require(DOCROOT.'/outputs/mamewah.php');break; + case mamewah168: + require(DOCROOT.'/outputs/mamewah168.php');break; + case mGalaxy: + require(DOCROOT.'/outputs/mgalaxy.php');break; + case xbmclauncher: + require(DOCROOT.'/outputs/xbmc-launcher.php');break; + case test: + require(DOCROOT.'/outputs/test_mamewah168.php');break; + default: + echo "Nothing to do here either jim"; + } + } +/* + * Process all files after upload + * Checks type of file then calls genFunction() + */ +function process_upload($tmpfile) { + + global $fixfile, $sessionID; + $uploaddir = UPLOADPATH .'/'. $sessionID .'/' ; + + # Make the users upload path if it doesnt exist + if (!is_dir($uploaddir)) {mkdir($uploaddir);chmod($uploaddir, 0777);} + + # Set upload information and move uploaded file + $uploadfname = basename($_FILES['fixfile']['name']); + $uploadfile = $uploaddir . $uploadfname; + if (move_uploaded_file($_FILES['fixfile']['tmp_name'], $uploadfile)) { + $fixfile = $uploaddir . $uploadfname; + + # Read in 4 lines from file to establish type + $handle = @fopen($fixfile, "r"); + if ($handle) { + $HDR0 = fread($handle, 512); + fclose($handle); + } + # Check if it is a binary file + if (substr_count($HDR0, "\x00") > 0 ) { + echo "You uploaded a binary file!
Please only upload ascii files."; + exit; + } + if ( preg_match('/You are Missing|You Have/i',$HDR0) ) { #Valid GoodTools File + genFunction("goodtxt","2","Recognised GoodTools style Miss/Have Text");exit; + } elseif ( preg_match('/clrmamepro \(/i',$HDR0 )) { #Valid CMPRO DAT File + genFunction("cmprodat","2","Recognised CMPro DAT");exit; + } elseif ( preg_match('/DOCTYPE mame/',$HDR0) ) { #Valid MAME XML + if ( ! ini_get('memory_limit') < 256 ) { + genFunction("mamexml","85","Recognised MAME XML"); + } else { echo " - (Not Support on this Server)";break; } + $exit; + } elseif ( preg_match('/CREDITS/',$HDR0) ) { #Valid Rommanger + genFunction("rommanager","9","Recognised Rommanager Dat");exit; + } elseif ( preg_match('/datafile/',$HDR0) ) { #Valid CMPRO XML Fixdat + genFunction("cmproxml","0","Recognised CMPro/RC3 XML");exit; + } else { #File Not Recognised, treating as generic listing + genFunction("generic","0","File Not Recognised, treating as generic listing");exit; + } + } +} /* * General Function, used to process all files @@ -49,30 +147,35 @@ function genFunction($inType,$skiplines,$fTypeTitle) { $build = "Current"; $i = "0"; + + # Clean up the name of the file cleanSessionID($outfile); $name = $csIDstr; if (file_exists($fixfile) && is_readable ($fixfile)) { - $outfile = UPLOADPATH .'/'. $sessionID .'/'. $outfile; - print $fTypeTitle."
"; # File write header, open file for writing @unlink($outfile); $xmlhndl = @fopen($outfile,"w"); writeout_header(); - - $lines = file($fixfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - foreach ( $lines as $line ) { - $line = trim($line,"\r\n"); - $i++; - $xmlhndl = @fopen($outfile,"a"); + # File write content, open file for append + $xmlhndl = @fopen($outfile,"a"); + + #$lines = file($fixfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $handle = @fopen($fixfile, "r"); + if ($handle) { + while(!feof($handle)) { + $line = fgets($handle); + $line = trim($line,"\r\n"); + $i++; + # Custom Items Start Here switch ($inType) { # Cowering's Goodtools Have/Miss Text Format case goodtxt: - # Get version number of set + # Get version number of set for $build if (preg_match('/ROMS \(V.*\)/',$line)) { $stringlen = strrpos($line,")"); $stringpos = strpos($line,"(")+1; @@ -150,17 +253,17 @@ function genFunction($inType,$skiplines,$fTypeTitle) { default: echo "Nothing to do here either jim"; } - - } + + } + fclose($handle); + } # File write footer, open file for append - $xmlhndl = @fopen($outfile,"a"); + #$xmlhndl = @fopen($outfile,"a"); writeout_footer(); - } + } - if (file_exists($fixfile)) { - unlink($fixfile); - } + if (file_exists($fixfile)) { unlink($fixfile); } } function build_itemArray($type = "0",$condition = "1",$value,$cloneof,$romof,$ext,$description,$manufucturer,$rom,$size,$crc32,$md5,$sha1,$build) { @@ -229,82 +332,6 @@ function read_mamexml($skiplines) } } -/* - * Process all files after upload - * Checks type of file then calls genFunction() - */ -function process_upload($tmpfile) { - - global $fixfile, $sessionID; - - $uploaddir = UPLOADPATH .'/'. $sessionID .'/' ; - - if (!is_dir($uploaddir)) { - mkdir($uploaddir); - chmod($uploaddir, 0777); - } - - $uploadfname = basename($_FILES['fixfile']['name']); - $uploadfile = $uploaddir . $uploadfname; - if (move_uploaded_file($_FILES['fixfile']['tmp_name'], $uploadfile)) { - $fixfile = $uploaddir . $uploadfname; - - # Check if it is a binary file - $testBIN = fopen($fixfile, "r"); - $blk = fread($testBIN, 512); - fclose($testBIN); - if (substr_count($blk, "\x00") > 0 ) { - echo "You uploaded a binary file!
Please only upload ascii files."; - exit; - } - - $i = 0; - $lines = file($fixfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - foreach ( $lines as $line ) { - $i++; - # Use first 4 lines to determine filetype - if ($i <= "4") { - if ($i == "1") { $HDR1 = $line; } - if ($i == "2") { $HDR2 = $line; } - if ($i == "3") { $HDR3 = $line; } - if ($i == "4") { $HDR4 = $line; } - } else { - $HDR0 = $HDR1.$HDR2.$HDR3.$HDR4; - if ( preg_match('/You are Missing|You Have/i',$HDR0) ) { - # Valid GoodTools File - genFunction("goodtxt","2","Recognised GoodTools style Miss/Have Text"); - exit; - } elseif ( preg_match('/clrmamepro \(/i',$HDR0 )) { - # Valid CMPRO DAT File - genFunction("cmprodat","2","Recognised CMPro DAT"); - exit; - } elseif ( preg_match('/DOCTYPE mame/',$HDR0) ) { - # Valid MAME XML - if ( ! ini_get('memory_limit') < 128 ) { - genFunction("mamexml","85","Recognised MAME XML"); - } else { - echo " - (Not Support on this Server)"; - break; - } - exit; - } elseif ( preg_match('/CREDITS/',$HDR0) ) { - # Valid Rommanger - genFunction("rommanager","9","Recognised Rommanager Dat"); - exit; - } elseif ( preg_match('/datafile/',$HDR0) ) { - # Valid CMPRO XML Fixdat - genFunction("cmproxml","0","Recognised CMPro/RC3 XML"); - exit; - } else { - # File Not Recognised, treating as generic listing - genFunction("generic","0","File Not Recognised, treating as generic listing"); - exit; - } - } - } - - } -} /* * create_link() * @@ -337,83 +364,7 @@ function create_link($zipfile) { } } -function switchOutput($pstQueue) { - - global $fixfile, $name, $modname, $outurl; - - $name = substr($fixfile,0,strlen($fixfile)-4); - # For Debugging - #$pstQueue = "test"; - - # Outputs - switch ($pstQueue) { - case filezilla: - require(DOCROOT.'/outputs/filezilla.php'); - break; - case wget: - require(DOCROOT.'/outputs/wget.php'); - break; - case msbat: - require(DOCROOT.'/outputs/msbat.php'); - break; - case CRCmsbat: - require(DOCROOT.'/outputs/msbat-crc.php'); - break; - case msbatnumbered: - require(DOCROOT.'/outputs/msbat-numbered.php'); - break; - case bash: - require(DOCROOT.'/outputs/bash.php'); - break; - case google: - $modname = 'Google Search'; - $outurl = "http://www.google.com.au/search?q="; - require(DOCROOT.'/outputs/html_generic.php'); - break; - case ebay: - $modname = 'Ebay Search'; - $outurl = "http://shop.ebay.com/?_nkw="; - require(DOCROOT.'/outputs/html_generic.php'); - break; - case ebayau: - $modname = "Ebay Australia Search"; - $outurl = "http://shop.ebay.com.au/?_nkw="; - require(DOCROOT.'/outputs/html_generic.php'); - break; - case binsearch: - $modname = "binsearch.info"; - $outurl = "http://www.binsearch.info/?q="; - require(DOCROOT.'/outputs/html_generic.php'); - break; - case easynews: - $modname = "EasyNews Global Search"; - $outurl = "http://members.easynews.com/global4/search.html?gps="; - require(DOCROOT.'/outputs/html_generic.php'); - break; - case htmlall: - require(DOCROOT.'/outputs/html_all.php'); - break; - case mamewah: - require(DOCROOT.'/outputs/mamewah.php'); - break; - case mamewah168: - require(DOCROOT.'/outputs/mamewah168.php'); - break; - case mGalaxy: - require(DOCROOT.'/outputs/mgalaxy.php'); - break; - case xbmclauncher: - require(DOCROOT.'/outputs/xbmc-launcher.php'); - break; - case test: - require(DOCROOT.'/outputs/test_mamewah168.php'); - break; - default: - echo "Nothing to do here either jim"; - } - -} function cleanSessionID($string) { global $sessionID, $csIDstr; diff --git a/php/listgen/outputs/filezilla.php b/php/listgen/outputs/filezilla.php index 57d9eba..6547e96 100755 --- a/php/listgen/outputs/filezilla.php +++ b/php/listgen/outputs/filezilla.php @@ -4,16 +4,15 @@ # # Builds a filezilla filters.xml -global $modname, $outfile; +global $modname, $outfile, $title; $modname = 'FileZilla Filter'; $outfile = "filters.xml"; +$title = $name; function writeout_header() { - - global $name; - global $xmlhndl; + global $name, $xmlhndl, $title; # Default Filter Settings $applytofiles = "1"; //Apply Filters to Files @@ -25,7 +24,7 @@ function writeout_header() fwrite($xmlhndl ,''."\n"); fwrite($xmlhndl ,' '."\n"); fwrite($xmlhndl ,' '."\n"); - fwrite($xmlhndl ,' '.$name.''."\n"); + fwrite($xmlhndl ,' '.$title.''."\n"); fwrite($xmlhndl ,' '.$applytofiles.''."\n"); fwrite($xmlhndl ,' '.$applytodirs.''."\n"); fwrite($xmlhndl ,' '.$matchtype.''."\n");