// This is Ali's ZIP2SFTP Interface - version for uploading files from any server // Script created by Savas Ali Tokmen - https://ali.tokmen.com/ // Date: 16 November 2024, version 2024.11.16 // STARTUP PARAMETERS // You can call Ali's ZIP 2 SFTP Interface with the following paramaters // [filename].php?host=HOST&user=USER&pass=PASS&port=PORT&folder=FOLDER&zipFile=ZIPFILE // // WHERE: // HOST is the host name // USER is the user name // PASS is the password // PORT is the port number // FOLDER is the folder name // ZIPFILE is the address of the remote ZIP file to upload // // Of course, all those items are optional. The first option should be called // preceeded by a "?" sign and the others by a "&" sign. // // This way, you can launch without much pain the ZIP 2 SFTP Interface with the // parameters you want. The user would then only have to choose a ZIP file // and press "Go !" :) // Read a php.ini-style value, defaults to megabytes function return_mbytes($val) { $val = trim($val); $last = strtolower($val[strlen($val)-1]); switch($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val = intval($val); break; case 'k': $val /= 1024; } return $val; } // Finds out the maximal POST upload size, in MB function getMaxULSize() { $post = return_mbytes(ini_get('post_max_size')); $memory = return_mbytes(ini_get('memory_limit')); if($memory < 1) { return $post; } return $memory; } // Maximal size of ZIP files, in megabytes $zipFileSizeLimit_MB=getMaxULSize(); error_reporting(E_ERROR); extract($_REQUEST); // PHP < 4.1.0 DIDN'T HAVE $_* BUT $HTTP_*_VARS if(version_compare(phpversion(),"4.1.0")==-1){ $_SERVER = $HTTP_SERVER_VARS; $_SESSION = $HTTP_SESSION_VARS; $_FILES = $HTTP_POST_FILES; } function filterHTML($what){ return str_replace(array("&","<",">","\""),array("&","<",">","""),$what); } function unfilterHTML($what){ return str_replace(array("<",">",""","&"),array("<",">","\"","&"),$what); } $scriptName=basename($_SERVER["SCRIPT_NAME"]); $scriptName=filterHTML($scriptName); if($do=="getSource"){ // Download method depends on the browser $user_agent=strtolower($_SERVER["HTTP_USER_AGENT"]); header("Content-type: application/force-download"); if((is_integer(strpos($user_agent,"msie")))&&(is_integer(strpos($user_agent,"win")))){ header("Content-Disposition: filename=\"zip2sftp.php\""); }else{ header("Content-Disposition: attachment; filename=\"zip2ftp.php\""); } header("Content-Description: File Transfert"); // Send file readfile($scriptName); // Send e-mail if needed (for usage statistics) if (strpos($user_agent,"bot") === false && strpos($_SERVER["SERVER_NAME"], "alishomepage.com") === false) { mail( "opensource@alishomepage.com", "ZIP2SFTP Interface (Remote Edition): another one downloaded :)", "This part will be referred to when the browser sends out no referrer information\n\n" . "Server name: ".$_SERVER["SERVER_NAME"]."\n" . "Script name: ".$_SERVER["SCRIPT_NAME"]."\n" . "Translated path: ".$_SERVER["PATH_TRANSLATED"]."\n\n" . "Downloader's info (the referrer is most useful, user agent is to detect bots)\n\n" . "User agent: ".$_SERVER["HTTP_USER_AGENT"]."\n" . "Referrer: ".$_SERVER["HTTP_REFERER"]."\n" . "Request URL: ".$_SERVER["REQUEST_URI"]); } die(); } $port=intval($port); if(!$port || $port<1 || $port>65535){ $port=22; } // PHP < 5 didn't have sys_get_temp_dir if(!is_callable('sys_get_temp_dir',false)) { function sys_get_temp_dir() { $temp=""; if($temp=getenv('TMP')){ return $temp; } if($temp=getenv('TEMP')){ return $temp; } if($temp=getenv('TMPDIR')){ return $temp; } $temp=tempnam('', ''); if(file_exists($temp)){ unlink($temp); return dirname($temp); } return $temp; } } // On some systems, the zip functions do not exist. In this case, try to use // the "unzip" command (available by default on most Linux systems) // Code written by bisqwit at iki dot fi on the zip_open function's comments // on the PHP manual. Thanks to Radek from Poland for telling me about it. if(!is_callable("zip_open",false)){ function ShellFix($s) { return "'". str_replace("'", "'\''", $s)."'"; } function zip_open ($s) { $fp = @fopen ($s, 'rb'); if(!$fp ) return false; $lines = Array(); $cmd = 'unzip -v '.shellfix( $s); exec($cmd, $lines); $contents = Array(); $ok=false; foreach($lines as $line) { if($line[0]== '-') { $ok=!$ok; continue; } if(!$ok) { continue; } $length = (int)$line ; $fn = trim(substr ($line,58)); $contents[] = Array('name' => $fn, 'length' => $length); } return Array('fp' => $fp, 'name' => $s , 'contents' => $contents , 'pointer' => -1); } function zip_read(&$fp) { if(!$fp ) return false; $next = $fp ['pointer'] + 1; if( $next >= count($fp['contents' ])) return false; $fp['pointer' ] = $next; return $fp['contents'][$next]; } function zip_entry_name (&$res) { if(!$res) return false ; return $res['name' ]; } function zip_entry_filesize(&$res ) { if(!$res) return false; return $res['length']; } function zip_entry_open (&$fp, &$res) { if(!$res ) return false; $cmd = 'unzip -p '.shellfix($fp['name' ]).' '.shellfix($res[ 'name']); $res['fp'] = popen($cmd, 'r'); return !! $res['fp']; } function zip_entry_read(&$res, $nbytes) { $contents = ''; while (!feof($res['fp'])) { $contents .= fread($res['fp'], 8192); } return $contents; } function zip_entry_close(&$res) { fclose($res['fp' ]); unset($res['fp']); } function zip_close(&$fp) { fclose( $fp['fp']); } } ?>