Example #1
0
 public static function mms_z_dysku($plik)
 {
     if (is_uploaded_file($plik['tmp_name'])) {
         $f = file_get_contents($plik['tmp_name']);
         return SerwerSMS::pliki(array(plik_mms => $f));
     } else {
         return false;
     }
 }
Example #2
0
 public static function sendSMS($phone, $text, $params = array(), $detail = false)
 {
     $params = array_merge(array('phone' => $phone, 'text' => $text, 'sender' => $sender), $params);
     $result = SerwerSMS::call($params);
     if ($detail) {
         return $result;
     } else {
         return $result['success'] == '1' ? true : false;
     }
 }
Example #3
0
 function SendSMS($number, $message, $messageid = 0)
 {
     global $MT;
     $msg_len = mb_strlen($message);
     if (!$msg_len) {
         return trans('SMS message is empty!');
     }
     if (!empty($this->CONFIG['sms']['debug_phone'])) {
         $number = $this->CONFIG['sms']['debug_phone'];
     }
     $prefix = !empty($this->CONFIG['sms']['prefix']) ? $this->CONFIG['sms']['prefix'] : '';
     $number = preg_replace('/[^0-9]/', '', $number);
     $number = preg_replace('/^0+/', '', $number);
     // add prefix to the number if needed
     if ($prefix && substr($number, 0, strlen($prefix)) != $prefix) {
         if (strtoupper(get_conf('sms.service')) != 'MIKROTIK') {
             $number = $prefix . $number;
         }
     }
     // message ID must be unique
     if (!$messageid) {
         $messageid = '0.' . time();
     }
     $message = preg_replace("/\r/", "", $message);
     $data = array('number' => $number, 'message' => $message, 'messageid' => $messageid);
     // call external SMS handler(s)
     $data = $this->ExecHook('send_sms_before', $data);
     if ($data['abort']) {
         return $data['result'];
     }
     $number = $data['number'];
     $message = $data['message'];
     $messageid = $data['messageid'];
     if (empty($this->CONFIG['sms']['service'])) {
         return trans('SMS "service" not set!');
     } else {
         $service = $this->CONFIG['sms']['service'];
     }
     switch ($service) {
         case 'smscenter':
             if (!function_exists('curl_init')) {
                 return trans('Curl extension not loaded!');
             }
             if (empty($this->CONFIG['sms']['username'])) {
                 return trans('SMSCenter username not set!');
             }
             if (empty($this->CONFIG['sms']['password'])) {
                 return trans('SMSCenter username not set!');
             }
             if (empty($this->CONFIG['sms']['from'])) {
                 return trans('SMS "from" not set!');
             } else {
                 $from = $this->CONFIG['sms']['from'];
             }
             if ($msg_len < 160) {
                 $type_sms = 'sms';
             } else {
                 if ($msg_len <= 459) {
                     $type_sms = 'concat';
                 } else {
                     return trans('SMS Message too long!');
                 }
             }
             if (strlen($number) > 16 || strlen($number) < 4) {
                 return trans('Wrong phone number format!');
             }
             $type = !empty($this->CONFIG['sms']['smscenter_type']) ? $this->CONFIG['sms']['smscenter_type'] : 'dynamic';
             $message .= $type == 'static' ? "\n\n" . $from : '';
             $args = array('user' => $this->CONFIG['sms']['username'], 'pass' => $this->CONFIG['sms']['password'], 'type' => $type_sms, 'number' => $number, 'text' => $message, 'from' => $from);
             $encodedargs = array();
             foreach (array_keys($args) as $thiskey) {
                 array_push($encodedargs, urlencode($thiskey) . "=" . urlencode($args[$thiskey]));
             }
             $encodedargs = implode('&', $encodedargs);
             $curl = curl_init();
             curl_setopt($curl, CURLOPT_URL, 'http://api.statsms.net/send.php');
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($curl, CURLOPT_POST, 1);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $encodedargs);
             curl_setopt($curl, CURLOPT_TIMEOUT, 10);
             $page = curl_exec($curl);
             if (curl_error($curl)) {
                 return 'SMS communication error. ' . curl_error($curl);
             }
             $info = curl_getinfo($curl);
             if ($info['http_code'] != '200') {
                 return 'SMS communication error. Http code: ' . $info['http_code'];
             }
             curl_close($curl);
             $smsc = explode(', ', $page);
             $smsc_result = array();
             foreach ($smsc as $element) {
                 $tmp = explode(': ', $element);
                 array_push($smsc_result, $tmp[1]);
             }
             switch ($smsc_result[0]) {
                 case '002':
                 case '003':
                 case '004':
                 case '008':
                 case '011':
                     return MSG_SENT;
                 case '001':
                     return 'Smscenter error 001, Incorrect login or password';
                 case '009':
                     return 'Smscenter error 009, GSM network error (probably wrong prefix number)';
                 case '012':
                     return 'Smscenter error 012, System error please contact smscenter administrator';
                 case '104':
                     return 'Smscenter error 104, Incorrect sender field or field empty';
                 case '201':
                     return 'Smscenter error 201, System error please contact smscenter administrator';
                 case '202':
                     return 'Smscenter error 202, Unsufficient funds on account to send this text';
                 case '204':
                     return 'Smscenter error 204, Account blocked';
                 default:
                     return 'Smscenter error ' . $smsc_result[0] . '. Please contact smscenter administrator';
             }
             break;
         case 'smsapi':
             if (empty($this->CONFIG['sms']['username'])) {
                 return trans('SMSApi username not set!');
             }
             if (empty($this->CONFIG['sms']['password'])) {
                 return trans('SMSApi username not set!');
             }
             if (empty($this->CONFIG['sms']['from'])) {
                 return trans('SMS "from" not set!');
             } else {
                 $from = $this->CONFIG['sms']['from'];
             }
             if ($msg_len < 160) {
                 $type_sms = 'sms';
             } else {
                 if ($msg_len <= 459) {
                     $type_sms = 'concat';
                 } else {
                     return trans('SMS Message too long!');
                 }
             }
             $params = array('username' => $this->CONFIG['sms']['username'], 'password' => md5($this->CONFIG['sms']['password']), 'to' => $number, 'from' => $this->CONFIG['sms']['from'], 'eco' => get_conf('sms.smsapi_eco', 1), 'fast' => get_conf('sms.smsapi_fast', 0), 'nounicode' => get_conf('sms.smsapi_nounicode', 1), 'normalize' => get_conf('sms.smsapi_normalize', 1), 'max_parts' => get_conf('sms.$smsapi_max_parts', 3), 'skip_foreign' => get_conf('sms.smsapi_skip_foreign', 1), 'message' => $message);
             $data = '?' . http_build_query($params);
             $stream = fopen('http://api.smsapi.pl/sms.do' . $data, 'r');
             $ret = fread($stream, 1024);
             fclose($stream);
             $ret_status = explode(':', $ret);
             if (sizeof($ret_status) > 0 && $ret_status[0] == 'OK') {
                 return MSG_SENT;
             }
             return $ret;
             break;
         case 'serwersms':
             if ($msg_len < 160) {
                 $type_sms = 'sms';
             } else {
                 if ($msg_len <= 459) {
                     $type_sms = 'concat';
                 } else {
                     return trans('SMS Message too long!');
                 }
             }
             $param = array();
             if ($messageid) {
                 $param['unique_id'] = $messageid;
             }
             $result = SerwerSMS::sendSMS($number, $message, $param);
             if ($result) {
                 return MSG_SENT;
             } else {
                 return FALSE;
             }
             break;
         case 'mikrotik':
             $MT->debug = get_conf('sms.mt_debug', false) ? true : false;
             $MT->port = get_conf('sms.mt_port', 8728);
             $blad = false;
             if ($MT->connect(get_conf('sms.mt_host'), get_conf('sms.mt_username'), get_conf('sms.mt_password'))) {
                 $part = $this->share_news($message);
                 $cmd = "/tool/sms/send";
                 $usb = get_conf('sms.mt_usb', 'usb1');
                 if (count($part) > 0) {
                     if (get_conf('sms.mt_partreverse', false) && count($part) > 1) {
                         $part = array_reverse($part);
                     }
                     for ($p = 0; $p < count($part); $p++) {
                         $mess = $part[$p];
                         $vars = array("phone-number" => "{$number}", "port" => "{$usb}", "message" => "{$mess}");
                         if (!$MT->comm($cmd, $vars)) {
                             $blad = true;
                         }
                         if ($p < count($part)) {
                             usleep(1500);
                         }
                     }
                 }
                 $MT->disconnect();
             } else {
                 $blad = true;
             }
             if (!$blad) {
                 return MSG_SENT;
             } else {
                 return FALSE;
             }
             break;
         case 'smstools':
             $dir = !empty($this->CONFIG['sms']['smstools_outdir']) ? $this->CONFIG['sms']['smstools_outdir'] : '/var/spool/sms/outgoing';
             if (!file_exists($dir)) {
                 return trans('SMSTools outgoing directory not exists ($a)!', $dir);
             }
             if (!is_writable($dir)) {
                 return trans('Unable to write to SMSTools outgoing directory ($a)!', $dir);
             }
             $filename = $dir . '/lms-' . $messageid . '-' . $number;
             if (strtoupper(get_conf('sms.encoding', 'UTF8')) != 'UTF8') {
                 $latin1 = iconv('UTF-8', 'ISO-8859-15', $message);
                 $alphabet = '';
                 if (strlen($latin1) != mb_strlen($message, 'UTF-8')) {
                     $alphabet = "Alphabet: UCS2\n";
                     $message = iconv('UTF-8', 'UNICODEBIG', $message);
                 }
             }
             //$message = clear_utf($message);
             $file = sprintf("To: %s\n%s\n%s", $number, $alphabet, $message);
             if ($fp = fopen($filename, 'w')) {
                 fwrite($fp, $file);
                 fclose($fp);
             } else {
                 return trans('Unable to create file $a!', $filename);
             }
             return MSG_NEW;
             break;
         case 'asterisk_manager':
             $timeout = "10";
             $errno = 0;
             $errstr = 0;
             $wrets = '';
             $message = str_replace(" \n", "\r", $message);
             $message = str_replace("\n", "\r", $message);
             $sconn = fsockopen(get_conf('sms.asterisk_host'), get_conf('sms.asterisk_port'), $errno, $errstr, $timeout) or die("Connection to {$strhost}:{$strport} failed");
             if (!$sconn) {
                 echo "{$errstr} ({$errno})<br>\n";
                 return FALSE;
             } else {
                 fputs($sconn, "Action: login\r\n");
                 fputs($sconn, "Username: "******"\r\n");
                 fputs($sconn, "Secret: " . get_conf('sms.asterisk_passwd') . "\r\n\r\n");
                 $wrets = fread($sconn, 4096);
                 $wrets .= fread($sconn, 4096);
                 $wrets .= fread($sconn, 4096);
                 fputs($sconn, get_conf('sms.asterisk_action') . "\r\n");
                 fputs($sconn, get_conf('sms.asterisk_command') . " " . $number . " \"" . $message . "\"\r\n\r\n");
                 $wrets .= fread($sconn, 4096);
                 fputs($sconn, "Action: Logoff\r\n\r\n");
                 fclose($sconn);
             }
             print $wrets;
             if (strpos($wrets, 'Response: Follows') !== FALSE) {
                 return MSG_NEW;
             } else {
                 return FALSE;
             }
             break;
         default:
             return trans('Unknown SMS service!');
     }
 }