Add V5 Scripts

This commit is contained in:
SilicaAndPina 2019-09-05 19:14:33 +12:00
parent e7154086d9
commit 3ef1ebd924
2 changed files with 386 additions and 0 deletions

View File

@ -0,0 +1,86 @@
<?php
$width=0;
$height=0;
$data="";
if(isset($_POST["img_height"]))
{
if(is_numeric($_POST["img_height"]))
{
$height=(int)$_POST["img_height"];
}
else
{
echo("img_height is NaN");
exit();
}
}
else
{
echo("img_height is undefined");
exit();
}
if(isset($_POST["img_width"]))
{
if(is_numeric($_POST["img_width"]))
{
$width=(int)$_POST["img_width"];
}
else
{
echo("img_width is NaN");
exit();
}
}
else
{
echo("img_width is undefined");
exit();
}
if(isset($_POST["img_data"]))
{
$data=$_POST["img_data"];
}
else
{
echo("img_data is undefined");
exit();
}
$img = imagecreatetruecolor($width,$height);
$x = 0;
$y = 0;
$i = 0;
while($x < $width)
{
$y = 0;
while($y < $height)
{
$red = hexdec(substr($data,$i,2));
$i += 2;
$green = hexdec(substr($data,$i,2));
$i += 2;
$blue = hexdec(substr($data,$i,2));
$i += 2;
$color = imagecolorallocate($img,$red,$green,$blue);
imagesetpixel($img,$x,$y,$color);
$y++;
}
$x++;
}
header('Content-Type: image/png');
//chrome doesnt like saving dynamically generated images so..
header('Content-Disposition: attachment; filename="'.md5(rand(0,256)).'.png"');
imagepng($img);
imagedestroy($img);
?>

300
V5/pc/cgi/Famiif.php Normal file
View File

@ -0,0 +1,300 @@
<?php
$ResultCode="OK";
$type = 0;
if(isset($_GET["c"]))
{
if(is_numeric($_GET["c"]))
{
$type = (int)$_GET["c"];
}
}
function startsWith ($string, $startString)
{
$len = strlen($startString);
if(substr($string, 0, $len) === $startString)
{
return true;
}
else
{
return false;
}
}
function read_ini_value(string $ini, string $category, string $key)
{
$stats = fopen($ini, "r");
do{
$line = fgets($stats);
if(feof($stats))
{
fclose($stats);
return false;
}
}
while($line != "[".$category."]\n");
do{
$line = fgets($stats);
if(startsWith($line,"["))
{
fclose($stats);
return "";
}
if(feof($stats))
{
fclose($stats);
return "";
}
}
while(!startsWith($line,$key));
$values = explode("=",$line);
fclose($stats);
return str_replace("\n","",$values[1]);
}
function write_ini_value(string $ini, string $category, string $key, string $value)
{
$sz = filesize($ini);
$stats = fopen($ini, "r+");
do{
$line = fgets($stats);
if(feof($stats))
{
fclose($stats);
return false;
}
}
while($line != "[".$category."]\n");
do{
$line = fgets($stats);
if(startsWith($line,"["))
{
fclose($stats);
return false;
}
if(feof($stats))
{
fclose($stats);
return false;
}
}
while(!startsWith($line,$key));
$curPos = ftell($stats);
$remaining = $sz - $curPos;
$after = fread($stats,$remaining);
$nextPos = $curPos-strlen($line);
fseek($stats,$nextPos,SEEK_SET);
fwrite($stats,$key."=".$value."\n");
fwrite($stats,$after);
fclose($stats);
return true;
}
function get_poll_result(string $country)
{
//Get Total Vote Count
$TotalVotes = 0;
for($i = 1; $i<=6; $i++)
{
$TotalVotes += (int)read_ini_value("stats.ini",$country,$i);
}
$WWAnswer = "";
for($i = 1; $i<=6; $i++)
{
$WWA = (int)read_ini_value("stats.ini",$country,$i);
if($WWA != 0 || $TotalVotes != 0)
{
$WWA = (int)floor(($WWA / $TotalVotes)*100);
}
$WWAnswer .= (string)$i."_".(string)$WWA;
if($i != 6)
{
$WWAnswer .= ",";
}
}
return $WWAnswer;
}
switch($type)
{
case 5: //survey entry
$country = "";
$key = 0;
$character = 0;
//Read "f"
if(isset($_GET["f"]))
{
if(is_string($_GET["f"]))
{
$country = $_GET["f"];
}
else
{
$ResultCode="ERROR";
break;
}
}
else
{
$ResultCode="ERROR";
break;
}
//Read "e"
if(isset($_GET["e"]))
{
if(is_numeric($_GET["e"]))
{
$key = (int)$_GET["e"];
}
else
{
$ResultCode="ERROR";
break;
}
}
else
{
$ResultCode="ERROR";
break;
}
//Read "a"
if(isset($_GET["a"]))
{
if(is_numeric($_GET["a"]))
{
$character = $_GET["a"];
}
else
{
$ResultCode="ERROR";
break;
}
}
else
{
$ResultCode="ERROR";
break;
}
// Sanitize user input (no exploit for u)
if($character < 1 || $character > 6)
{
$ResultCode="ERROR";
break;
}
if($key != 2)
{
$ResultCode="ERROR";
break;
}
if(!($country == "NA" || $country == "EU" || $country == "JP" || $country == "AO"))
{
$ResultCode="ERROR";
break;
}
// Write new statistics (finally)
if(!file_exists("stats.ini")) //initalize
{
$stats = fopen("stats.ini", "w+");
fwrite($stats,"[JP]\n");
for($i = 1;$i<=6;$i++)
{
fwrite($stats,(string)$i."=0\n");
}
fwrite($stats,"[NA]\n");
for($i = 1;$i<=6;$i++)
{
fwrite($stats,(string)$i."=0\n");
}
fwrite($stats,"[EU]\n");
for($i = 1;$i<=6;$i++)
{
fwrite($stats,(string)$i."=0\n");
}
fwrite($stats,"[AO]\n");
for($i = 1;$i<=6;$i++)
{
fwrite($stats,(string)$i."=0\n");
}
fclose($stats);
}
$value = read_ini_value("stats.ini",$country,(string)$character);
if($value == "")
{
error_log("Read_Ini_Failed!".$country.$character);
$ResultCode="ERROR";
break;
}
$newVal = (int)$value+1;
$ret = write_ini_value("stats.ini",$country,(string)$character,(string)$newVal);
if($ret == false)
{
error_log("Write_Ini_Failed!");
$ResultCode="ERROR";
break;
}
//Get Poll Results
$JPAnswer = get_poll_result("JP");
$NAAnswer = get_poll_result("NA");
$EUAnswer = get_poll_result("EU");
$AOAnswer = get_poll_result("AO");
break;
default: //unimplemented - just say success
$ResultCode="OK";
break;
}
$output= Array(
"ResultCode" => $ResultCode
);
if(isset($JPAnswer))
{
$output["JPAnswer"] = $JPAnswer;
}
if(isset($NAAnswer))
{
$output["NAAnswer"] = $NAAnswer;
}
if(isset($EUAnswer))
{
$output["EUAnswer"] = $EUAnswer;
}
if(isset($AOAnswer))
{
$output["AOAnswer"] = $AOAnswer;
}
echo(urldecode(http_build_query($output)));
?>