AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.217.103
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/public_html/lrsys_projetos/sopizzas/application/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/public_html/lrsys_projetos/sopizzas/application/models/notification_model.php
<?php
/**
 * Created by Earthtechnology Pvt Ltd.
 * User: Narayan Sarkar
 * Date: 28/11/17
 * Time: 3:58 PM
 */
class notification_model extends CI_Model
{
    /**
     *Send message to registered user
     *$param['push_notif_message'] = ""
     *$param['orderid']
     *$param['msg_to'] = "" // send restaurant when msg is for restaurant
     */
    function sendPushMessage($param = array()) {
        //$this->sendDevEmail($this->config->item("developer_emails"), "Test Push notification for android call", "TEST EMAIL");
        //echo "before push enabled";
        if(!$this->config->item("push_enabled")) return false;
        //echo "push enabled";
        if(!empty($param)){
            $androidApiKey = $this->config->item("push_api_key");
            $message = addslashes($param['push_notif_message']);
            /*$fp=fopen("push-log.txt", 'w+');
            foreach($_POST as $key=>$value) {
                fwrite($fp, $key."==".$value);
            }
            fclose($fp);*/
            $deviceTable = "rt_customer_devices";
            $orderid = $param['orderid'];

            $this->db->select('restaurant_id, ordergenerateid, customer_id');
            $this->db->from("rt_order");
            $this->db->where('orderid',$orderid);
            $this->db->limit('1');
            $order_details = $this->db->get();
            //print_r($order_details->row());
            $this->db->select('restaurant_name');
            $this->db->from("rt_restaurant");
            $this->db->where('restaurant_id',$order_details->row()->restaurant_id);
            $this->db->limit('1');
            $res_details = $this->db->get();
            //print_r($res_details->row());
            $this->db->select('device_type, device_id');
            $this->db->from($deviceTable);
            $this->db->where('customer_id', $order_details->row()->customer_id);
            if(isset($param['msg_to']) && strtolower($param['msg_to']) == "restaurant") {
                $this->db->where('customer_id', $order_details->row()->restaurant_id);
            }
            $this->db->order_by('id','ASC');
            $query = $this->db->get();
            $allDevices = $query->result_array();
            //print_r($allDevices);
            //echo "OOO";
            foreach($allDevices as $k => $row) {
                //print_r($row);

                if( isset($row['device_type']) && $row['device_type'] == 'Android' )
                {
                    $response = $this->androidNotification(array($row['device_id']), $message, SITENAME."-".$res_details->row()->restaurant_name, '', $androidApiKey);

                }
                if( isset($row['device_type']) && $row['device_type'] == 'iOS' )
                {
                    $device_ios = array();
                    array_push($device_ios, array("id" => $row['device_id'], "msg" => $message, "appredirect" => ""));
                    //print_R($device_ios);
                    $this->iosNotification($device_ios, "");
                }
            }
        }
    }

    /**
     * @param $registrationIdsArray
     * @param $message
     * @param $res_name
     * @param $appredirect
     * @param $androidApiKey
     * @param string $orderid
     * @param string $browse_url
     * @param string $has_url
     * @return mixed
     */
    function androidNotification( $registrationIdsArray, $message, $res_name, $appredirect, $androidApiKey, $orderid="", $browse_url="", $has_url="false")
    {
        $messageData = array(
            'message'=> $message,
            'title'=> $res_name,
            'appredirect'=> "",
            'order_id'=>$orderid,
            'browse_url' => $browse_url,
            'has_url' => $has_url,
            'notId' => time(),
            "content-available" => "1",
            "force-start" => 1,
            "visibility" => 1
        );
        $headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $androidApiKey);
        $data = array(
            'data' => $messageData,
            'registration_ids' => $registrationIdsArray,
            "priority" => "high"
        );
        //print_r($data);
        $ch = curl_init();

        //curl_setopt( $ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send" );
        curl_setopt( $ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send" );
        curl_setopt( $ch, CURLOPT_POST, true );
        curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
        curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data) );

        $response = curl_exec($ch);
        curl_close($ch);
        //echo $response;
        //print_r($response);
        $this->sendDevEmail($this->config->item("developer_emails"), "Push notification for android response", json_encode($response));
        return $response;
    }

    /**
     * @param $deviceTokenArray
     * @param $restaurantID
     * @return bool
     */
    function iosNotification($deviceTokenArray, $restaurantID)
    {
        //print_R($deviceTokenArray);
        $message = $deviceTokenArray[0]['msg'];
        $deviceToken = $deviceTokenArray[0]['id'];
        if(!file_exists($_SERVER["DOCUMENT_ROOT"] . '/pushCertificate.pem')) return false;
        $passphrase = '';
        $ctx = stream_context_create();
        //echo $_SERVER["DOCUMENT_ROOT"] . '/' . $restaurantID . '.pem';
        stream_context_set_option($ctx, 'ssl', 'local_cert', $_SERVER["DOCUMENT_ROOT"] . '/pushCertificate.pem');

        //$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
        $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

        $body['aps'] = array('alert' => $message,
            'badge' => 1,
            'sound' => '',
            "content-available" => 1
        );
        $body["notId"] = time();
        $payload = json_encode($body);
        if (!$fp) {
            exit("Failed to connect: $err $errstr" . PHP_EOL);
        }
        //$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
        $msg = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack('n', strlen($payload)) . $payload;

        $result = fwrite($fp, $msg, strlen($msg));
        $this->sendDevEmail($this->config->item("developer_emails"), "Push notification for iOS response", json_encode($result));
        //echo($result);
        //exit();
        fclose($fp);
    }

    /*
     * Must provide $params['to'] = reciever mobile no
     * Must provide $params['message'] = message
     */

    function sendSMSNotification($params) {
        //$fromNumber = "+441769670046";
        //$fromNumber = $CFG["twilio"]["from_no"]; //ETPL 10
        //$fromNumber = "+18179854037";
        $customer_phone = $params["to"];
        //$customer_phone = $this->str_replace_first("0", "44", $customer_phone);
        //$customer_phone = "447479194562";
        //$customer_phone = "919093268094";
        if(strlen($customer_phone) <= 10)
        {
            $customer_phone = "1".$customer_phone;
        }
        $messageBody = $params["message"];
        $this->db->select('twilio_sid, twilio_token, twilio_from_no');
        $this->db->from('rt_sitesetting');
        $this->db->limit('1');
        $queryTwilio = $this->db->get();
        $client = new Services_Twilio($queryTwilio->row()->twilio_sid, $queryTwilio->row()->twilio_token);
        $twiloErr = "";
        try {
            $cusno=str_replace(array( '(', ')' , ' ' , '-' , '+'), '', $customer_phone);
            $message = $client->account->messages->create(array(
                "From" => $queryTwilio->row()->twilio_from_no,//"+15005550006", // From a valid Twilio number
                "To" => '+'.$cusno, // Text this number
                "Body" => $messageBody,
            ));
        }
        catch(Exception $e)
        {
            //echo 'Message: ' .$e->getMessage();
            $twiloErr = $e->getMessage();
        }
        $this->sendDevEmail($this->config->item("developer_emails"), 'Twilio Error', "Twilio messages". $customer_phone . "<br>twiloErr:" . $twiloErr ."<br>". $messageBody);
    }

    /**
     * @param $mail_To
     * @param $mail_subject
     * @param $mail_Body
     * @param string $mail_CC
     */
    function sendEmailNotification($mail_To, $mail_subject, $mail_Body, $mail_CC="")
    {
        $CI =& get_instance();
        $CI->load->library('myemail');
        $mail_From = SITENAME;
        $mail = new PHPMailer();
        //Your SMTP servers details
        $mail->IsSMTP(); // set mailer to use SMTP
        $mail->Host = SMTP_HOST; // specify main and backup server or localhost
        $mail->SMTPAuth = true; // turn on SMTP authentication
        $mail->Username = SMTP_USER; // SMTP username
        $mail->Password = SMTP_PASSWORD; // SMTP password It should be same as that of the SMTP user
        //$mail->AddCustomHeader("Precedence: bulk");
        //$mail->PluginDir = "/home/phpaucti/public_html/website_development/coding/includes/";
        $mail->From = $mail->Username; //Default From email same as smtp user
        $mail->FromName = $mail_From;
        $emailArr = explode(',',$mail_To);
        foreach($emailArr AS $emailVal) {
            $mail->AddAddress($emailVal, ""); //Email address where you wish to receive/collect those emails.
        }

        /*$emailCCArr = explode(',',$mail_CC);
        foreach($emailCCArr AS $emailCCVal) {
        $mail->AddCC($emailCCVal, ""); //Email address where you wish to receive/collect those emails.
        }*/


        $mail->WordWrap = 100; // set word wrap to 50 characters
        $mail->IsHTML(true); // set email format to HTML
        $mail->Subject = $mail_subject;
        $message = $mail_Body;
        $mail->Body = $message;

        if(!$mail->Send())
        {
            /*echo "Message could not be sent. <p>";
            echo "Mailer Error: " . $mail->ErrorInfo;
            exit;*/
        }
        else
        {
            //echo 'ok';
        }
    }
    /**
     * @param $mail_To
     * @param $mail_subject
     * @param $mail_Body
     * @param string $mail_CC
     */
    function sendDevEmail($mail_To, $mail_subject, $mail_Body, $mail_CC="")
    {
        $CI =& get_instance();
        $CI->load->library('myemail');
        $mail_From = SITENAME;
        $mail = new PHPMailer();
        //Your SMTP servers details
        $mail->IsSMTP(); // set mailer to use SMTP
        $mail->Host = SMTP_HOST; // specify main and backup server or localhost
        $mail->SMTPAuth = true; // turn on SMTP authentication
        $mail->Username = SMTP_USER; // SMTP username
        $mail->Password = SMTP_PASSWORD; // SMTP password It should be same as that of the SMTP user
        //$mail->AddCustomHeader("Precedence: bulk");
        //$mail->PluginDir = "/home/phpaucti/public_html/website_development/coding/includes/";
        $mail->From = $mail->Username; //Default From email same as smtp user
        $mail->FromName = $mail_From;
        $emailArr = explode(',',$mail_To);
        foreach($emailArr AS $emailVal) {
            $mail->AddAddress($emailVal, ""); //Email address where you wish to receive/collect those emails.
        }

        /*$emailCCArr = explode(',',$mail_CC);
        foreach($emailCCArr AS $emailCCVal) {
        $mail->AddCC($emailCCVal, ""); //Email address where you wish to receive/collect those emails.
        }*/


        $mail->WordWrap = 100; // set word wrap to 50 characters
        $mail->IsHTML(true); // set email format to HTML
        $mail->Subject = $mail_subject;
        $message = $mail_Body;
        $mail->Body = $message;

        if($this->config->item("developer_email_notification")) {
            if (!$mail->Send()) {
                /*echo "Message could not be sent. <p>";
                echo "Mailer Error: " . $mail->ErrorInfo;
                exit;*/

            } else {
                //echo 'ok';
            }
        }
    }
    /**
    *Example
    * $variables=array(
           '{fname}'=>$_POST['VkUsers']['fname'],
           '{lname}'=>$_POST['VkUsers']['lname'],
           '{email}'=>$_POST['VkUsers']['email'],
           '{dob}'=>$model->dob,
           '{password}'=>$pwd
       );
   $final_array = $this->EmailSendArray($description, $variables);//replace varibles
   */
    function EmailSendArray($message, $variables){
        $searchArray = array_keys($variables);
        $replaceArray = array_values($variables);
        return str_replace($searchArray, $replaceArray, $message);
    }
}

Anon7 - 2022
AnonSec Team