<?php
require_once "../../maincore.php";
if( goodRequest())
{
error_reporting(0);
$ex = explode(" ", $_GET[sms], 2);
$ex[1] = strtolower($ex[1]);
$numeris = dbarray(dbquery("SELECT * FROM ".$db_prefix."money_numbers WHERE smsraktas = '".$ex[0]."' and salis = '".$_GET[country]."' and numeris = '".$_GET[to]."'"));
$result = dbquery("UPDATE ".$db_prefix."money_users SET `pinigai` = `pinigai`+'".$numeris[pinigaiisaskaita]."' WHERE `userid` = '".$ex[1]."' LIMIT 1 ;");
$sndyra = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
$result = dbquery("INSERT INTO ".$db_prefix."money_sms (`sms`, `inumeri`, `isnumerio`, `operatorius`, `smskaina`, `smsid`, `transaction`, `smsdata`, `smstxt`) VALUES('".$_GET[sms]."', '".$_GET[to]."', '".$_GET[from]."', '".$_GET[operator]."', '".$_GET[amount]."', '".$_GET[id]."', '".$_GET[transaction]."', '".$sndyra."', '".$ex[1]."')");
if(dbcount("(*)", "users", "user_id='".$ex[1]."'") > 0){
$user = dbarray(dbquery("SELECT * FROM ".$db_prefix."users WHERE user_id = '".$ex[1]."'"));
$goldsettings = dbarray(dbquery("SELECT * FROM ".$db_prefix."money_settings"));
$numeris[pinigaiisaskaitalt] = $numeris[pinigaiisaskaita]/100;
$respond_text = "OK ";# Šito nelieciam
echo $respond_text .= "Sveikiname ".$user[user_name].", jusu saskaita papildyta ".$numeris[pinigaiisaskaitalt]." ".$goldsettings[valiuta].". Aciu, jog naudojatës musu paslaugomis!";
}else{
echo "Jusu zinute negauta. Vartotojas kurio id ".$ex[1]." nerastas arba jus nesate prisiregistrave!";
}
exit;
} else {
exit('Ivyko klaida!');
}
function getCert($cert = null) {
$fp = fsockopen("downloads.webtopay.com", 80, $errno, $errstr, 30);
if (!$fp)
exit("Cert error: $errstr ($errno)<br />\n");
else {
$out = "GET /download/" . ($cert ? $cert : 'public.key') . " HTTP/1.1\r\n";
$out .= "Host: downloads.webtopay.com\r\n";
$out .= "Connection: Close\r\n\r\n";
$content = '';
fwrite($fp, $out);
while (!feof($fp)) $content .= fgets($fp, 8192);
fclose($fp);
list($header, $content) = explode("\r\n\r\n", $content, 2);
return $content;
}
}
function checkCert($cert = null) {
$pKeyP = getCert($cert);
if (!$pKeyP) return false;
$pKey = openssl_pkey_get_public($pKeyP);
if (!$pKey) return false;
$_SS2 = "";
foreach ($_GET As $key => $value) if ($key!='_ss2') $_SS2 .= "{$value}|";
$ok = openssl_verify($_SS2, base64_decode($_GET['_ss2']), $pKey);
return ($ok === 1);
}
function goodRequest() {
if (checkCert()) return true;
return checkCert('public_old.key');
}
?>