forked from kevinowino869/mitrobill
Change to devices
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PEAR2\Net\RouterOS;
|
||||
|
||||
require $root_path . 'system/autoload/mail/Exception.php';
|
||||
require $root_path . 'system/autoload/mail/PHPMailer.php';
|
||||
require $root_path . 'system/autoload/mail/SMTP.php';
|
||||
@ -37,10 +39,8 @@ class Message
|
||||
if (strlen($txt) > 160) {
|
||||
$txts = str_split($txt, 160);
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($config['sms_url']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
foreach ($txts as $txt) {
|
||||
Mikrotik::sendSMS($client, $phone, $txt);
|
||||
self::sendSMS($config['sms_url'], $phone, $txt);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// ignore, add to logs
|
||||
@ -48,9 +48,7 @@ class Message
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($config['sms_url']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::sendSMS($client, $phone, $txt);
|
||||
self::sendSMS($config['sms_url'], $phone, $txt);
|
||||
} catch (Exception $e) {
|
||||
// ignore, add to logs
|
||||
_log("Failed to send SMS using Mikrotik.\n" . $e->getMessage(), 'SMS', 0);
|
||||
@ -64,6 +62,24 @@ class Message
|
||||
}
|
||||
}
|
||||
|
||||
public static function MikrotikSendSMS($router_name, $to, $message)
|
||||
{
|
||||
global $_app_stage, $client_m;
|
||||
if ($_app_stage == 'demo') {
|
||||
return null;
|
||||
}
|
||||
if(!isset($client_m)){
|
||||
$mikrotik = ORM::for_table('tbl_routers')->where('name', $router_name)->find_one();
|
||||
$iport = explode(":", $mikrotik['ip_address']);
|
||||
$client_m = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
|
||||
}
|
||||
$smsRequest = new RouterOS\Request('/tool sms send');
|
||||
$smsRequest
|
||||
->setArgument('phone-number', $to)
|
||||
->setArgument('message', $message);
|
||||
$client_m->sendSync($smsRequest);
|
||||
}
|
||||
|
||||
public static function sendWhatsapp($phone, $txt)
|
||||
{
|
||||
global $config;
|
||||
|
Reference in New Issue
Block a user