434 lines
12 KiB
PHP
Executable File
434 lines
12 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* @framework iResponse Framework
|
|
* @version 1.0
|
|
* @author Amine Idrissi <contact@iresponse.tech>
|
|
* @date 2019
|
|
* @name help.php
|
|
*/
|
|
|
|
# help methods
|
|
|
|
/**
|
|
* @name getIp
|
|
* @description get client ip
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
function getIp()
|
|
{
|
|
$ip = "";
|
|
if (!empty($_SERVER['HTTP_CLIENT_IP']))
|
|
{
|
|
$_SERVER['HTTP_X_FORWARDED_FOR'] = htmlspecialchars($_SERVER['HTTP_X_FORWARDED_FOR']);
|
|
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
|
$ip = htmlspecialchars($ip, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
|
|
{
|
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
}
|
|
else
|
|
{
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
|
}
|
|
|
|
|
|
if(filter_var($ip,FILTER_VALIDATE_IP,FILTER_FLAG_IPV6))
|
|
{
|
|
$ipv4 = hexdec(substr($ip, 0, 2)). "." . hexdec(substr($ip, 2, 2)). "." . hexdec(substr($ip, 5, 2)). "." . hexdec(substr($ip, 7, 2));
|
|
$ip = $ipv4;
|
|
}
|
|
|
|
if(!filter_var($ip,FILTER_VALIDATE_IP,FILTER_FLAG_IPV4))
|
|
{
|
|
$match = array();
|
|
|
|
if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/',$ip, $match))
|
|
{
|
|
$ip = count($match) > 0 && filter_var($match[0],FILTER_VALIDATE_IP) ? $match[0] : "";
|
|
}
|
|
}
|
|
|
|
return $ip;
|
|
}
|
|
|
|
|
|
/**
|
|
* @name decryptUrl
|
|
* @description decrypt a value
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
function decryptUrl($value)
|
|
{
|
|
|
|
$output = false;
|
|
$value=str_replace( array('ZPDER','SLHOR', '_'),array('+', '/','='), $value);
|
|
$secret_key = '$p_tracking_enc_key';
|
|
|
|
$key = hash('sha256', $secret_key);
|
|
$iv = substr($key, 0, 16);
|
|
|
|
$output = openssl_decrypt(base64_decode($value), "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv);
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
/**
|
|
* @name decrypt
|
|
* @description decrypt a value
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
function decrypt($value)
|
|
{
|
|
$encrypted = base64_decode($value);
|
|
$salt = substr($encrypted,0,32);
|
|
$encrypted = substr($encrypted,32);
|
|
$salted = $dx = '';
|
|
while (strlen($salted) < 48)
|
|
{
|
|
$dx = md5($dx . '$p_tracking_enc_key' . $salt, true);
|
|
$salted .= $dx;
|
|
}
|
|
$key = substr($salted,0,32);
|
|
$iv = substr($salted,32,16);
|
|
return openssl_decrypt($encrypted, 'aes-256-cbc', $key,OPENSSL_RAW_DATA, $iv);
|
|
}
|
|
|
|
/**
|
|
* @name cmd
|
|
* @description executes a system command
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
function cmd($command,$return = 'output',$type = 'string')
|
|
{
|
|
$result = ['output' => '' , 'error' => ''];
|
|
|
|
if(isset($command) && $command != '')
|
|
{
|
|
$descriptorspec = [
|
|
0 => ["pipe", "r"],
|
|
1 => ["pipe", "w"],
|
|
2 => ["pipe", "w"],
|
|
];
|
|
|
|
$pipes = [];
|
|
$process = proc_open($command, $descriptorspec,$pipes, dirname(__FILE__), null);
|
|
|
|
if(is_resource($process))
|
|
{
|
|
if($return == 'output')
|
|
{
|
|
if($type == 'string')
|
|
{
|
|
$result['output'] = trim(stream_get_contents($pipes[1]));
|
|
$result['error'] = trim(stream_get_contents($pipes[2]));
|
|
}
|
|
else
|
|
{
|
|
$result['output'] = explode(PHP_EOL,trim(stream_get_contents($pipes[1])));
|
|
$result['error'] = explode(PHP_EOL,trim(stream_get_contents($pipes[2])));
|
|
}
|
|
}
|
|
|
|
# close all pipes
|
|
fclose($pipes[1]);
|
|
fclose($pipes[2]);
|
|
|
|
# close the process
|
|
proc_close($process);
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @name sendPostRequest
|
|
* @description send post request
|
|
* @access public
|
|
* @param string $url
|
|
* @param boolean $data
|
|
* @return mixed
|
|
*/
|
|
function sendPostRequest($url,$data)
|
|
{
|
|
$response = null;
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
|
curl_setopt($ch, CURLOPT_URL,$url);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
$response = curl_exec($ch);
|
|
curl_close($ch);
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* @name reindex
|
|
* @description reindexes the supplied array from 0 to number of values - 1.
|
|
* @param array $source
|
|
* @return
|
|
*/
|
|
function reindex(array &$source)
|
|
{
|
|
$temp = $source;
|
|
$source = [];
|
|
|
|
foreach ($temp as $value)
|
|
{
|
|
$source[] = $value;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @name checkForImage
|
|
* @description checks if the link is an image
|
|
* @param string $url
|
|
* @return
|
|
*/
|
|
function checkForImage($url,$domain)
|
|
{
|
|
$parts = explode('.',$url);
|
|
$extention = end($parts);
|
|
$extention = strtolower($extention);
|
|
|
|
if(in_array($extention,['jpg','jpeg','png','gif','bmp']))
|
|
{
|
|
//$image = "$domain/media/" . end(explode(RDS,$url));
|
|
$image = "$domain/media/" . end(explode("_",end(explode(RDS,$url))));
|
|
header("Content-type:image/{$extention}");
|
|
echo file_get_contents($image);
|
|
die();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @name parseURL
|
|
* @description parse url
|
|
* @param string $url
|
|
* @return
|
|
*/
|
|
function parseURL($url)
|
|
{
|
|
$data = [];
|
|
$output = [];
|
|
if(strpos($url,'.php?') !== FALSE)
|
|
{
|
|
|
|
$params = explode('.',$url);
|
|
|
|
|
|
$value=decodeStringNew($params[count($params)-1]);
|
|
|
|
$allIds = explode('.',$value);
|
|
|
|
if(count($allIds))
|
|
{
|
|
if(in_array($allIds[0],['op','cl','un','oop','od1','od2','od3','od4']))
|
|
{
|
|
if(count($allIds) == 7)
|
|
{
|
|
$output["act"] = $allIds[0];
|
|
$output["pid"] = $allIds[1];
|
|
$output["uid"] = $allIds[2];
|
|
$output["vid"] = $allIds[3];
|
|
$output["ofid"] = $allIds[4];
|
|
$output["lid"] = $allIds[5];
|
|
$output["cid"] = $allIds[6];
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$Spliter=['.','&','-','2DF','*','='];
|
|
if(strpos($url,'act=') === FALSE)
|
|
{
|
|
foreach ($Spliter as $delim) {if(substr_count($url, $delim)>5){ $url=str_replace($delim,"/",$url);}}
|
|
}
|
|
|
|
if(strpos($url,'/') === FALSE && strpos($url,'act') === FALSE)
|
|
{
|
|
$url = decryptUrl($url);
|
|
}
|
|
|
|
$parts = parse_url("http://{$_SERVER['HTTP_HOST']}/{$url}");
|
|
$query = key_exists('query',$parts) ? $parts['query'] : null;
|
|
$path = $parts['path'];
|
|
|
|
|
|
if($query != '' && empty($output))
|
|
{
|
|
if(strpos($query,'act=') !== FALSE)
|
|
{
|
|
$params = explode('&',$query);
|
|
|
|
if($params != null && count($params) > 0)
|
|
{
|
|
foreach ($params as $param)
|
|
{
|
|
$keyValue = explode('=',$param);
|
|
|
|
if($keyValue != null && count($keyValue) == 2)
|
|
{
|
|
$output[$keyValue[0]] = $keyValue[1];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if(strpos(trim($path,'/'),'/') !== FALSE && empty($output))
|
|
{
|
|
$paramspath = explode('/',trim($path,'/'));
|
|
$params="";
|
|
for ($i = 0; $i <count($paramspath); $i++)
|
|
{
|
|
if (!preg_match('/[a-zA-Z0-9]{10,30}/', $paramspath[$i])) { $params.="/".decodeString($paramspath[$i]); }
|
|
}
|
|
|
|
$params = explode('/',trim($params,'/'));
|
|
|
|
if(count($params))
|
|
{
|
|
if(in_array($params[0],['op','cl','un','oop','od1','od2','od3','od4']))
|
|
{
|
|
if(count($params) == 7)
|
|
{
|
|
$output["act"] = $params[0];
|
|
$output["pid"] = $params[1];
|
|
$output["uid"] = $params[2];
|
|
$output["vid"] = $params[3];
|
|
$output["ofid"] = $params[4];
|
|
$output["lid"] = $params[5];
|
|
$output["cid"] = $params[6];
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if(count($output) == 0)
|
|
{
|
|
die('<pre>Could not parse url !</pre>');
|
|
}
|
|
|
|
if(count($output) && key_exists('act',$output))
|
|
{
|
|
$data['act'] = key_exists('pid',$output) ? $output['act'] : 0;
|
|
$data['process-id'] = 0;
|
|
|
|
if(key_exists('pid',$output))
|
|
{
|
|
if(strpos($output['pid'],'_') === FALSE)
|
|
{
|
|
$data['process-id'] = intval($output['pid']);
|
|
$data['process-type'] = 'md';
|
|
}
|
|
else
|
|
{
|
|
$parts = explode('_',$output['pid']);
|
|
|
|
if(count($parts) == 2)
|
|
{
|
|
$data['process-id'] = intval($parts[0]);
|
|
$data['process-type'] = $parts[1];
|
|
}
|
|
}
|
|
}
|
|
|
|
$data['user-id'] = key_exists('uid',$output) ? intval($output['uid']) : 0;
|
|
$data['vmta-id'] = key_exists('vid',$output) ? intval($output['vid']) : 0;
|
|
$data['offer-id'] = key_exists('ofid',$output) ? intval($output['ofid']) : 0;
|
|
$data['list-id'] = key_exists('lid',$output) ? intval($output['lid']) : 0;
|
|
$data['client-id'] = key_exists('cid',$output) ? intval($output['cid']) : 0;
|
|
}
|
|
else
|
|
{
|
|
die('<pre>Could not parse url !</pre>');
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
function decodeString(String $param): string
|
|
{
|
|
$result ="";
|
|
$Maper=array("0"=>"F","1"=>"H","2"=>"O","3"=>"T","4"=>"n","5"=>"7","6"=>"c","7"=>"2","8"=>"Y","9"=>"v","A"=>"t","B"=>"_","C"=>"B","D"=>"k","E"=>"M","F"=>"W","G"=>"f","H"=>"E","I"=>"J","J"=>"z","K"=>"X","L"=>"V","M"=>"5","N"=>"e","O"=>"P","P"=>"h","Q"=>"a","R"=>"r","S"=>"L","T"=>"q","U"=>"o","V"=>"N","W"=>"j","X"=>"p","Y"=>"9","Z"=>"l","_"=>"8","a"=>"b","b"=>"x","c"=>"m","d"=>"0","e"=>"3","f"=>"I","g"=>"R","h"=>"G","i"=>"U","j"=>"s","k"=>"d","l"=>"i","m"=>"y","n"=>"u","o"=>"A","p"=>"C","q"=>"Z","r"=>"1","s"=>"D","t"=>"Q","u"=>"g","v"=>"4","w"=>"K","x"=>"6","y"=>"S","z"=>"w");
|
|
|
|
foreach (str_split( $param) as $value) {
|
|
if(in_array($value,$Maper))
|
|
{
|
|
$result .=$Maper[$value];
|
|
}else{
|
|
$result .=$value;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
function decodeStringNew(String $param)
|
|
{
|
|
$result ="";
|
|
$Maper=["d"=>"0","r"=>"1","7"=>"2","e"=>"3","v"=>"4","M"=>"5","x"=>"6","5"=>"7","p"=>"8","Y"=>"9","B"=>"_","0"=>".","Q"=>"a","a"=>"b","6"=>"c","k"=>"d","N"=>"e","G"=>"f","u"=>"g","P"=>"h","l"=>"i","W"=>"j","D"=>"k","Z"=>"l","c"=>"m","4"=>"n","U"=>"o","X"=>"p","T"=>"q","R"=>"r","j"=>"s","A"=>"t","n"=>"u","9"=>"v","z"=>"w","b"=>"x","m"=>"y","J"=>"z"];
|
|
|
|
foreach (str_split( $param) as $value) {
|
|
if(isset($Maper[$value]))
|
|
{
|
|
$result .=$Maper[$value];
|
|
}else{
|
|
$result .=$value;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @name random
|
|
* @description generates random text
|
|
* @access public
|
|
* @param integer $size the size of generated text
|
|
* @param boolean $letters boolean value to tell the function whether use letters or not
|
|
* @param boolean $numbers boolean value to tell the function whether use uppercase letters too or not
|
|
* @param boolean $uppercase boolean value to tell the function whether use numbers or not
|
|
* @param boolean $special boolean value to tell the function whether use special characters or not
|
|
* @return string
|
|
*/
|
|
function random(int $size = 5, bool $letters = true, bool $numbers = true, bool $uppercase = false, bool $special = false) : string
|
|
{
|
|
$result = '';
|
|
$characters = '';
|
|
|
|
if($letters)
|
|
{
|
|
$characters .= 'abcdefghijklmnopqrstuvwxyz';
|
|
if($uppercase)
|
|
{
|
|
$characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
}
|
|
}
|
|
|
|
if($numbers)
|
|
{
|
|
$characters .= '0123456789';
|
|
}
|
|
|
|
if($special)
|
|
{
|
|
$characters .= '@\\/_*$&-#[](){}';
|
|
}
|
|
|
|
for ($i = 0; $i <$size; $i++)
|
|
{
|
|
$result .= $characters[rand(0, strlen($characters) - 1)];
|
|
}
|
|
|
|
return $result;
|
|
} |