Senior Member
|
11-25-2017
, 10:18
Help webcompiler
|
#1
|
compiler.config.inc
PHP Code:
<?php
function init_db() { mysql_connect("localhost", "user", "pass"); mysql_select_db("csredblo_database") or die("Could not mysql_select_db()"); } ?>
Webcompiler.php
PHP Code:
<?php # vi: set ts=4 : //note: this will not be difficult to port to metacms. /**********************************************/ require_once('Compiler.class.php');
$go = cvar("go"); if ($go == "" || $go == "disp") { //include('header.inc.php'); disp_compiler(); } else if ($go == "upload") { //include('header.inc.php'); compile_upload(); } else if ($go == "send") { //include('header.inc.php'); compile_text(); } else if ($go == "dl") { download(ivar("id")); } else { //include('header.inc.php'); disp_compiler(); }
/**********************************************/ print "<br />"; $query = "SELECT * FROM amxx_comp3_stats"; $pStats = mysql_query($query); $c = mysql_num_rows($pStats); for ($i=1; $i<=$c; $i++) { $pStat = mysql_fetch_array($pStats); if ($pStat['key'] == "compile_successes") print "<i><font size=1>".(intval($pStat['val']))." successful compiles to date.</font></i><br />"; if ($pStat['key'] == "compile_failures") print "<i><font size=1>".(intval($pStat['val']))." failed compiles to date.</font></i><br />"; } mysql_free_result($pStats); print "<i><font size=1>Old compiler: 101980 compiles failed compiles before decommission.</font></i><br />"; print "<i><font size=1>This tool by: David \"BAILOPAN\" Anderson.</font></i>"; remove_old(); //include('footer.inc.php');
//////////////////////////////////// //////// HELPER FUNCTIONS ////////// ////////////////////////////////////
function download($id) { $pFile = GetFileData($id);
if (!$pFile || intval($pFile['done'])) { print "<b>This file does not exist or has expired past its time limit.</b><br />"; return false; } else { OutputAmxx($pFile['phys_name'], str_replace(".sma", ".amxx", $pFile['real_name'])); exit(); } }
function compile_upload() { $temp_name = strip_filename($_FILES['sma']['tmp_name']).".sma"; $path = TEMP_SRCPATH."/".$temp_name; $real_name = $_FILES['sma']['name']; if (!stristr($real_name, ".sma")) { print "<b>You must upload a valid file!</b><br /><br />"; disp_compiler(); return false; } move_uploaded_file($_FILES['sma']['tmp_name'], $path); if (!file_exists($path)) { print "<b>You must upload a valid file222!</b><br /><br />"; disp_compiler(); return false; }
$bin = TEMP_OUTPATH."/".strip_filename(str_replace(".sma", ".amxx", $path)); TryCompile($path, $bin, $real_name); unlink($path); }
function compile_text() { $path = tempnam(TEMP_SRCPATH, "text"); $code = stripslashes(cvar("scode")); rename($path, $path.'.sma'); $path .= '.sma';
$real_name = ""; if (cvar("fname")) $real_name = str_replace(" ", "", cvar("fname")).".amxx"; else $real_name = str_replace(".sma", ".amxx", strip_filename($path));
$fp = fopen($path, "w"); fwrite($fp, $code); fclose($fp);
$bin = TEMP_OUTPATH."/".str_replace(".sma", ".amxx", strip_filename($path)); $s = TryCompile($path, $bin, $real_name);
print "<br />"; print "<form action=webcompiler.php method=post>\r"; print "Plugin short name: <input type=text name=fname size=15 value='".cvar('fname')."'><br>\r"; print "<textarea name=scode rows=25 cols=70>\r"; print $code; print "</textarea><br>\r"; print "<input type=hidden name=go value=send>\r"; print "<input type=submit value=Compile>\r"; print "</form>\r";
unlink($path); }
function TryCompile($input, $output, $real_name) { $comp = new Compiler($input, $output);
if (!$comp->Compile(true)) { print "<b>Your plugin failed to compile!</b> Read the errors below:<br />\r"; print "<pre>"; print $comp->output; print "</pre>"; IncStatKey("compile_failures"); } else { print "<b>Your plugin successfully compiled!</b><br />"; print "Use the link below to download your plugin. It will be valid for ten minutes.<br />"; print "<br />";
$id = AddTempPlugin($output, $real_name); print "<a href='webcompiler.php?go=dl&id=$id'>http://www.amxmodx.org/webcompiler.php?go=dl&id=$id</a>"; print "<br />"; IncStatKey("compile_successes"); } }
function IncStatKey($key) { $query = "SELECT val FROM amxx_comp3_stats WHERE `key` = '$key'"; $pStats = mysql_query($query); if (!$pStats || !mysql_num_rows($pStats)) return false;
$pStat = mysql_fetch_array($pStats); $query = "UPDATE amxx_comp3_stats SET val = '".(intval($pStat['val'])+1)."' WHERE `key` = '$key'"; mysql_query($query); mysql_free_result($pStats); }
function AddTempPlugin($output, $real_name) { $query = "INSERT INTO amxx_comp3_files VALUES(NULL, '$output', '$real_name', UNIX_TIMESTAMP(), '".getenv("REMOTE_ADDR")."', 0)"; mysql_query($query); return mysql_insert_id(); }
function disp_compiler() { //there are two modes, upload file or a large text box.... print "<b>Welcome to the AMX Mod X 1.60 Web Compiler.</b><br /><br /> You can use this to compile plugins online.<br>\r"; print "Once you upload a file, you will receive the compiler output and a link to the plugin.<br>\r"; print "<br>\r"; print "<form action=webcompiler.php method=post enctype=\"multipart/form-data\">\r"; print "Upload .sma file: <input type=file name=sma maxsize=512000>\r"; print "<input type=hidden name=go value=upload>\r"; print "<input type=submit value=Compile>\r"; print "</form>\r"; print "<br>If you want, you can also paste plugin source code into the box below:<br>\r"; print "<form action=webcompiler.php method=post>\r"; print "Plugin short name: <input type=text name=fname size=15><br>\r"; print "<textarea name=scode rows=25 cols=70>\r"; print "</textarea><br>\r"; print "<input type=hidden name=go value=send>\r"; print "<input type=submit value=Compile>\r"; print "</form>\r"; }
function cvar($var) { if (isset($_GET[$var])) return $_GET[$var]; if (isset($_POST[$var])) return $_POST[$var]; return false; }
function ivar($var) { return intval(cvar($var)); }
function remove_old() { $query = "SELECT * FROM amxx_comp3_files WHERE compiled + 600 < UNIX_TIMESTAMP() AND done = 0"; $Plugins = mysql_query($query); if (!$Plugins) return false; $c = mysql_num_rows($Plugins); for ($i=1; $i<=$c; $i++) { $Plugin = mysql_fetch_array($Plugins); if (file_exists($Plugin['phys_name'])) unlink($Plugin['phys_name']); } mysql_query("UPDATE amxx_comp3_files SET done = 1 WHERE compiled + 600 < UNIX_TIMESTAMP() AND done = 0"); mysql_free_result($Plugins); }
function GetFileData($file_id) { $query = "SELECT * FROM amxx_comp3_files WHERE id = $file_id"; $pFiles = mysql_query($query);
if (!$pFiles) return false;
if (!mysql_num_rows($pFiles)) return false;
$pFile = mysql_fetch_array($pFiles); mysql_free_result($pFiles); return $pFile; } ?>
Compiler.class..php
PHP Code:
<? include 'compiler.config.inc';
init_db();
define('COMPILER_PATH', 'scripting'); define('TEMP_OUTPATH', 'temp/bin'); define('PLUG_SRCPATH', 'plugin/src'); define('TEMP_SRCPATH', 'temp/src'); define('PLUG_OUTPATH', 'plugin/bin'); define('SMA_TEMP', 1); define('SMA_PLUGIN', 1);
/////////////////////////////// //// HELPER FUNCTIONS HERE //// ///////////////////////////////
function OutputAmxx($phys_file, $filename) { $HTTP_USER_AGENT = ""; if (!empty($_SERVER['HTTP_USER_AGENT'])) { $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; } else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) { $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT']; } else if (!isset($HTTP_USER_AGENT)) { $HTTP_USER_AGENT = ''; }
if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[2]; $browser_agent = 'opera'; } else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'ie'; } else if (ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'omniweb'; } else if (ereg('Netscape([0-9]{1})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'netscape'; } else if (ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'mozilla'; } else if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'konqueror'; } else { $browser_version = 0; $browser_agent = 'other'; }
// Correct the mime type - we force application/octetstream for all files, except images // Please do not change this, it is a security precaution $mimetype = ($browser_agent == 'ie' || $browser_agent == 'opera') ? 'application/octetstream' : 'application/octet-stream';
// Now the tricky part... let's dance @ob_end_clean(); @ini_set('zlib.output_compression', 'Off'); header('Pragma: public'); header('Content-Transfer-Encoding: none');
// Send out the Headers header('Content-Type: ' . $mimetype . '; name="' . $filename . '"'); header('Content-Disposition: inline; filename="' . $filename . '"');
$size = @filesize($phys_file); if ($size) { header("Content-length: $size"); }
readfile($phys_file); }
class Compiler { var $source; var $bin; var $output;
function Compiler($path, $bin) { $this->bin= $bin; $this->source = $path; }
function Compile($save_output) { if (file_exists($this->bin)) unlink($this->bin); $exec = "./amxxpc -i".COMPILER_PATH." ".$this->source." -o".$this->bin; $pwd = getcwd(); chdir(COMPILER_PATH); if ($save_output) { $this->output = shell_exec($exec); } else { exec($exec); $this->output = $this->bin; } chdir($pwd); if (file_exists($this->bin) && filesize($this->bin) > 0) { return true; } else { if (file_exists($this->bin)) unlink($this->bin); $tempfile = str_replace(".amxx", ".amx", $this->bin); if (file_exists($tempfile)) unlink($tempfile); return false; } } }
function strip_filename($fname) { preg_match("/([^\/]+)$/", $fname, $matches);
return $matches[0]; }
//physical plugin filename to output path function GetOutputPath($file, $mode) { $obj = str_replace(".sma", ".amxx", strip_filename($file)); $out = ""; if ($mode==SMA_PLUGIN) { $out = PLUG_OUTPATH; } else { $out = TEMP_OUTPATH; } $out = "$out/$obj"; return $out; } ?>
error
PHP Code:
[25-Nov-2017 01:16:06 UTC] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Compiler has a deprecated constructor in /home/csredblo/public_html/webcompiler/Compiler.class.php on line 93 [25-Nov-2017 01:16:06 UTC] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/csredblo/public_html/webcompiler/compiler.config.inc:5 Stack trace: #0 /home/csredblo/public_html/webcompiler/Compiler.class.php(4): init_db() #1 /home/csredblo/public_html/webcompiler/webcompiler.php(5): require_once('/home/csredblo/...') #2 {main} thrown in /home/csredblo/public_html/webcompiler/compiler.config.inc on line 5 [25-Nov-2017 01:22:28 UTC] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Compiler has a deprecated constructor in /home/csredblo/public_html/webcompiler/Compiler.class.php on line 93 [25-Nov-2017 01:22:28 UTC] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/csredblo/public_html/webcompiler/compiler.config.inc:5 Stack trace: #0 /home/csredblo/public_html/webcompiler/Compiler.class.php(4): init_db() #1 /home/csredblo/public_html/webcompiler/webcompiler.php(5): require_once('/home/csredblo/...') #2 {main} thrown in /home/csredblo/public_html/webcompiler/compiler.config.inc on line 5 [25-Nov-2017 01:22:39 UTC] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Compiler has a deprecated constructor in /home/csredblo/public_html/webcompiler/Compiler.class.php on line 93 [25-Nov-2017 01:22:39 UTC] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/csredblo/public_html/webcompiler/compiler.config.inc:5 Stack trace: #0 /home/csredblo/public_html/webcompiler/Compiler.class.php(4): init_db() #1 /home/csredblo/public_html/webcompiler/webcompiler.php(5): require_once('/home/csredblo/...') #2 {main} thrown in /home/csredblo/public_html/webcompiler/compiler.config.inc on line 5 [25-Nov-2017 01:24:26 UTC] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Compiler has a deprecated constructor in /home/csredblo/public_html/webcompiler/Compiler.class.php on line 93 [25-Nov-2017 01:24:26 UTC] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/csredblo/public_html/webcompiler/compiler.config.inc:5 Stack trace: #0 /home/csredblo/public_html/webcompiler/Compiler.class.php(4): init_db() #1 /home/csredblo/public_html/webcompiler/webcompiler.php(5): require_once('/home/csredblo/...') #2 {main} thrown in /home/csredblo/public_html/webcompiler/compiler.config.inc on line 5
__________________
Free Palestine ♥
Last edited by plazma; 11-25-2017 at 10:41.
|
|