MINI Sh3ll
<?
class Request {
public $_id;
public $received;
public $shortcode;
public $mobileno;
public $msisdn;
public $source;
public $server_addr;
public $server_port;
public $operator;
public $circle;
public $keyword;
public $raw_message;
public $message;
public $coding;
public $charset;
public $client_id;
public $ipaddress;
public $objMongoDB;
public $objMySQLDB;
public function __construct(){
$this->_id = "";
$this->received = "";
$this->shortcode = "";
$this->mobileno = "";
$this->msisdn = "";
$this->source = "";
$this->server_addr = "";
$this->server_port = "";
$this->operator = "";
$this->circle = "";
$this->keyword = "";
$this->message = "";
$this->coding = 0;
$this->charset = "";
$this->client_id = 0;
$this->tsp_response = "";
$this->objMongoDB = new mongo_database;
$this->objMySQLDB = new database;
}
function consumeRequest($data){
$this->received = localToUTCDate(date('Y-m-d H:i:s'));
$this->shortcode = isset($data['shortcode']) ? $data['shortcode'] : '55757';
$this->source = $data['source'];
$this->server_addr = $data['server_addr'];
$this->server_port = $data['server_port'];
$this->mobileno = str_replace('+', '', $data['mobileno']);
$this->msisdn = substr($this->mobileno, 2);
$this->operator = isset($data['operator']) ? $data['operator'] : $data['network'];
$this->raw_message = $data['message'];
$this->message = $data['message'];
while(strpos($this->message, ' ') !== false){
$this->message = str_replace(' ', ' ', $this->message);
}
$this->keyword = strtoupper(explode(' ', $this->message)[0]);
$this->ipaddress = $_SERVER['REMOTE_ADDR'];
}
function saveToDB(){
$tmp_objMongoDB = $this->objMongoDB;
$tmp_objMySQLDB = $this->objMySQLDB;
unset($this->objMongoDB);
unset($this->objMySQLDB);
//y($this);
//x($mrecord);
if($this->_id == ""){
unset($this->_id);
$this->_id = $tmp_objMongoDB->saveOneRecord('requests', $this);
}
else {
//x($this);
$where = ['_id' => new \MongoDB\BSON\ObjectID($this->_id)];
$tmp_id = $this->_id;
unset($this->_id);
//x($this);
$tmp_objMongoDB->updateOneRecord('requests', $where, $this);
$this->_id = $tmp_id;
}
$this->objMongoDB = $tmp_objMongoDB;
$this->objMySQLDB = $tmp_objMySQLDB;
}
function loadConfigurations(){
$sql = "SELECT * FROM (SELECT 1 `order`, 'keyword' config_type, k.response_type, k.response_text, k.request_method, k.response_url, k.url_parameters, k.client_id FROM keywords k LEFT JOIN shortcodes s ON k.shortcode_id = s.id
WHERE k.`status` = 1 AND s.`status` = 1
AND k.keyword = '".mysql_escape($this->objMySQLDB->connection, $this->keyword)."' AND s.shortcode = '".mysql_escape($this->objMySQLDB->connection, $this->shortcode)."' ORDER BY k.id asc LIMIT 1) AS kw union
SELECT * FROM (SELECT 2 `order`, 'shortcode' config_type, s.response_type, s.response_text, s.request_method, s.response_url, s.url_parameters, s.client_id FROM shortcodes s
WHERE s.`status` = 1
AND s.shortcode = '".mysql_escape($this->objMySQLDB->connection, $this->shortcode)."' ORDER BY s.id asc LIMIT 1) AS sh ORDER BY `order` asc";
//y($sql);
$result = $this->objMySQLDB->get_records($sql);
if($result && count($result) > 0){
$this->config_type = $result[0]['config_type'];
$this->client_id = (int)$result[0]['client_id'];
$this->response_type = $result[0]['response_type'];
$this->response_text = $result[0]['response_text'];
$this->response_url = $result[0]['response_url'];
$this->url_parameters = $result[0]['url_parameters'];
}
else {
$this->config_type = "NA";
$this->client_id = 0;
$this->response_type = "";
$this->response_text = "";
$this->response_url = "";
$this->url_parameters = "";
}
//$result = $objdb->get_records($query);
//x($result);
}
function processRequest() {
switch($this->response_type){
case "0":
$this->response_text = trim($this->response_text);
break;
case "1":
$params = $this->url_parameters;
$params = str_replace('@text', urlencode($this->message), $params);
$params = str_replace('@rawtext', urlencode($this->raw_message), $params);
$params = str_replace('@keyword', urlencode($this->keyword), $params);
$params = str_replace('@mobileno', $this->mobileno, $params);
$params = str_replace('@msisdn', $this->msisdn, $params);
$params = str_replace('@operator', urlencode(trim($this->operator.' '.$this->circle)), $params);
$params = str_replace('@smsc', urlencode(trim($this->operator)), $params);
$params = str_replace('@circle', urlencode(trim($this->circle)), $params);
$params = str_replace('@messageid', urlencode($this->_id), $params);
$params = str_replace('@received', urlencode(date('Y-m-d H:i:s')), $params);
$params = str_replace('@shcode', urlencode($this->shortcode), $params);
$params = str_replace('@ymdhisreceived', urlencode(date('YmdHis')), $params);
$params = str_replace('@coding', urlencode($this->coding), $params);
$params = str_replace('@charset', urlencode($this->charset), $params);
$get_response = make_get_request($this->response_url, $params);
if(is_array($get_response)){
$this->remote_url = trim($get_response['remote_url']);
$this->url_response = trim($get_response['url_response']);
$this->url_response_code = trim($get_response['url_response_code']);
$this->url_response_error = trim($get_response['url_response_error']);
$this->response_text = trim($this->url_response);
}
else {
$this->url_response = ""; // No response received from the URL
$this->url_response_code = "-1";
$this->url_response_error = "Unknown. Please contact client.";
$this->response_text = trim($this->url_response);
}
break;
case "2":
$params = $this->url_parameters;
$params = str_replace('@text', urlencode($this->message), $params);
$params = str_replace('@rawtext', urlencode($this->raw_message), $params);
$params = str_replace('@keyword', urlencode($this->keyword), $params);
$params = str_replace('@mobileno', $this->mobileno, $params);
$params = str_replace('@msisdn', $this->msisdn, $params);
$params = str_replace('@operator', urlencode(trim($this->operator.' '.$this->circle)), $params);
$params = str_replace('@smsc', urlencode(trim($this->operator)), $params);
$params = str_replace('@circle', urlencode(trim($this->circle)), $params);
$params = str_replace('@messageid', urlencode($this->_id), $params);
$params = str_replace('@received', urlencode(date('Y-m-d H:i:s')), $params);
$params = str_replace('@shcode', urlencode($this->shortcode), $params);
$params = str_replace('@ymdhisreceived', urlencode(date('YmdHis')), $params);
$params = str_replace('@coding', urlencode($this->coding), $params);
$params = str_replace('@charset', urlencode($this->charset), $params);
$get_response = make_get_request($this->response_url, $params);
if(is_array($get_response)){
$this->remote_url = trim($get_response['remote_url']);
$this->url_response = trim($get_response['url_response']);
$this->url_response_code = trim($get_response['url_response_code']);
$this->url_response_error = trim($get_response['url_response_error']);
}
else {
$this->url_response = ""; // No response received from the URL
$this->url_response_code = "-1";
$this->url_response_error = "Unknown. Please contact client.";
}
$this->response_text = trim($this->response_text);
break;
default:
$this->response_text = "";
break;
}
}
function processOperatorResponse(){
switch($this->operator){
case "vodafone-idea":
case "vodafone":
//$xml_disallowed = array("&", "<", ">", "'", '"');
//$this->response_text = str_replace($xml_disallowed, " ", $this->response_text);
$this->response_text = htmlspecialchars($this->response_text);
if(trim($this->response_text) != ''){
$this->tsp_response = '<?xml version="1.0" encoding="US-ASCII"?>
<message>
<sms type="mt">
<destination messageid="PS0">
<address>
<number type="international">'.$this->mobileno.'</number>
</address>
</destination>
<source>
<address>
<number type="unknown">'.$this->shortcode.'</number>
</address>
</source>
<rsr type="success_failure"/>
<ud type="text">'.trim($this->response_text).'</ud>
</sms>
</message>';
$this->tsp_content_type = 'text/xml';
//header('Content-Type: text/xml');
//print $output;
}
break;
case "airtel":
$this->response_text = htmlspecialchars($this->response_text);
if(trim($this->response_text) != ''){
$this->tsp_response = '<?xml version="1.0" encoding="US-ASCII"?>
<message>
<sms type="mt">
<destination messageid="PS0">
<address>
<number type="international">'.$this->mobileno.'</number> </address>
</destination>
<source>
<address>
<number type="unknown">'.$this->shortcode.'</number>
</address>
</source>
<rsr type="success_failure"/>
<ud type="text">'.trim($this->response_text).'</ud>
</sms>
</message>';
//logXMLResponse($output);
$this->tsp_content_type = 'text/xml';
//print $output;
}
break;
default:
$this->tsp_content_type = 'text/plain';
$this->tsp_response = $this->response_text;
break;
}
$this->response_sent = localToUTCDate(date('Y-m-d H:i:s'));
}
function returnResponse() {
if($this->tsp_response != ""){
header("Content-Type:".$this->tsp_content_type);
print $this->tsp_response;
}
}
function logRequest(){
$data = (array)$this;
$data['received'] = utcToLocalDate($data['received']);
unset($data['objMongoDB']);
unset($data['objMySQLDB']);
$json = json_encode($data).PHP_EOL;
$logPath = getcwd().'/logger/'.date("F-Y").'/';
if(!file_exists($logPath))
mkdir($logPath, 0777, true);
//x($logPath);
$logFile = $logPath.'requests-'.date('Ymd').'.log';
file_put_contents($logFile, $json, FILE_APPEND | LOCK_EX);
}
function logResponse(){
$data = (array)$this;
$data['received'] = utcToLocalDate($data['received']);
unset($data['objMongoDB']);
unset($data['objMySQLDB']);
$json = json_encode($data).PHP_EOL;
$logPath = getcwd().'/logger/'.date("F-Y").'/';
if(!file_exists($logPath))
mkdir($logPath, 0777, true);
$logFile = $logPath.'responses-'.date('Ymd').'.log';
file_put_contents($logFile, $json, FILE_APPEND | LOCK_EX);
}
}
?>
OHA YOOOO