Revize 675
Přidáno uživatelem Roman Ševčík před více než 14 roky(ů)
freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'november' => 'Listopad',
|
||
'number' => 'Číslo',
|
||
'number of the recipient' => 'Číslo příjemce',
|
||
'phone number of the sim card' => 'Telefonní číslo SIM karty',
|
||
'number of the sender' => 'Číslo odesilatele',
|
||
'numbers' => 'Čísla',
|
||
'number interval' => 'Rozsah čísel',
|
freenetis/trunk/kohana/application/controllers/web_interface.php | ||
---|---|---|
$view->render(true);
|
||
}
|
||
|
||
|
||
|
||
|
||
/**
|
||
* Function is used for VoIP callback.
|
||
* @param <type> $user
|
||
* @param <type> $pass
|
||
* @param <type> $number
|
||
*/
|
||
function callback($user = null, $pass = null, $number = null)
|
||
{
|
||
|
freenetis/trunk/kohana/application/controllers/settings.php | ||
---|---|---|
|
||
$this->form->group('')->label(Sms::get_driver_name(Sms::$SOUNDWINV100).' - '.url_lang::lang('texts.Settings'));
|
||
$this->form->dropdown('sms_driver_state'.Sms::$SOUNDWINV100)->label(url_lang::lang('texts.Driver state').':')->options(array( Sms::$DRIVER_INACTIVE => url_lang::lang('texts.Inactive'), Sms::$DRIVER_ACTIVE => url_lang::lang('texts.Active')))->selected($this->settings->get('sms_driver_state'.Sms::$SOUNDWINV100));
|
||
$this->form->input('sms_sim_card_number'.Sms::$SOUNDWINV100)->label(url_lang::lang('texts.Phone number of the SIM card').':')->rules('length[12,12]|valid_phone_cs_CZ')->value($this->settings->get('sms_sim_card_number'.Sms::$SOUNDWINV100));
|
||
$this->form->input('sms_user'.Sms::$SOUNDWINV100)->label(url_lang::lang('texts.User').':')->rules('length[1,50]')->value($this->settings->get('sms_user'.Sms::$SOUNDWINV100));
|
||
$this->form->input('sms_password'.Sms::$SOUNDWINV100)->label(url_lang::lang('texts.Password').':')->rules('length[1,50]')->value($this->settings->get('sms_password'.Sms::$SOUNDWINV100));
|
||
$this->form->input('sms_hostname'.Sms::$SOUNDWINV100)->label(url_lang::lang('texts.Hostname').':')->rules('length[1,50]')->value($this->settings->get('sms_hostname'.Sms::$SOUNDWINV100));
|
||
... | ... | |
}
|
||
}
|
||
|
||
if ($this->settings->get('sms_driver_state'.Sms::$SOUNDWINV100) == Sms::$DRIVER_ACTIVE)
|
||
{
|
||
$sms = new Sms_Soudvinv100();
|
||
$sms->user($this->settings->get('sms_user'.Sms::$SOUNDWINV100));
|
||
$sms->password($this->settings->get('sms_password'.Sms::$SOUNDWINV100));
|
||
$sms->hostname($this->settings->get('sms_hostname'.Sms::$SOUNDWINV100));
|
||
|
||
if($sms->test_conn())
|
||
{
|
||
$aditional_info[] = url_lang::lang('texts.Testing driver').' : '.Sms::get_driver_name(Sms::$SOUNDWINV100).'......<span style="color:green">OK</span>';
|
||
}
|
||
else
|
||
{
|
||
$aditional_info[] = url_lang::lang('texts.Testing driver').' : '.Sms::get_driver_name(Sms::$SOUNDWINV100).'......<span style="color:red">'.url_lang::lang('texts.Failed').'</span>';
|
||
}
|
||
}
|
||
|
||
$view->content->aditional_info = $aditional_info;
|
||
$view->render(TRUE);
|
||
|
freenetis/trunk/kohana/application/controllers/scheduler.php | ||
---|---|---|
//send quened SMS
|
||
self::send_quened_sms();
|
||
|
||
//receive SMS
|
||
self::receive_sms();
|
||
|
||
}
|
||
|
||
/**
|
||
... | ... | |
}
|
||
$message->save();
|
||
case Sms::$SOUNDWINV100:
|
||
//TODO
|
||
$user = $this->settings->get('sms_user'.Sms::$SOUNDWINV100);
|
||
$password = $this->settings->get('sms_password'.Sms::$SOUNDWINV100);
|
||
$hostname = $this->settings->get('sms_hostname'.Sms::$SOUNDWINV100);
|
||
|
||
|
||
$sms = new Sms_Soudvinv100();
|
||
$sms->user($user);
|
||
$sms->password($password);
|
||
$sms->hostname($hostname);
|
||
$sms->recipient('00'.$message->receiver);
|
||
$sms->text(htmlspecialchars_decode($message->text));
|
||
if ($sms->send())
|
||
{
|
||
$message->state = Sms_Controller::$SENT_OK;
|
||
$message->message = $sms->get_status();
|
||
}
|
||
else
|
||
{
|
||
$message->state = Sms_Controller::$SENT_FAILED;
|
||
$message->message = $sms->get_error();
|
||
}
|
||
$message->save();
|
||
break;
|
||
case Sms::$INACTIVE:
|
||
default:
|
||
... | ... | |
$message->save();
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Function receive SMS messages from GSM gw.
|
||
* @author Roman Sevcik
|
||
*/
|
||
private function receive_sms()
|
||
{
|
||
if ($this->settings->get('sms_driver_state'.Sms::$SOUNDWINV100) == Sms::$DRIVER_ACTIVE)
|
||
{
|
||
$user = $this->settings->get('sms_user'.Sms::$SOUNDWINV100);
|
||
$password = $this->settings->get('sms_password'.Sms::$SOUNDWINV100);
|
||
$hostname = $this->settings->get('sms_hostname'.Sms::$SOUNDWINV100);
|
||
|
||
$sms = new Sms_Soudvinv100();
|
||
$sms->user($user);
|
||
$sms->password($password);
|
||
$sms->hostname($hostname);
|
||
|
||
if ($sms->receive())
|
||
{
|
||
$messages = $sms->get_messages();
|
||
|
||
print '<pre>';
|
||
print_r ($messages);
|
||
print '</pre>';
|
||
|
||
for($i = 0; $i < count($messages); $i++)
|
||
{
|
||
if (strtolower($messages[$i]->text) === 'klima')
|
||
{
|
||
print 'Sending answer to '.$messages[$i]->sender;
|
||
$sms = new Sms_Soudvinv100();
|
||
$sms->user($user);
|
||
$sms->password($password);
|
||
$sms->hostname($hostname);
|
||
$sms->recipient('00'.$messages[$i]->sender);
|
||
$sms->text(htmlspecialchars_decode('Klima je nejlepsi, Klima je super, Klima je nej...! S pozdravem FreeNetIS'));
|
||
$sms->send();
|
||
}elseif (strtolower($messages[$i]->text) === 'freenetis stav')
|
||
{
|
||
|
||
print 'Sending answer to '.$messages[$i]->sender;
|
||
$sms = new Sms_Soudvinv100();
|
||
$sms->user($user);
|
||
$sms->password($password);
|
||
$sms->hostname($hostname);
|
||
$sms->recipient('00'.$messages[$i]->sender);
|
||
$sms->text(htmlspecialchars_decode('Vas aktualni kredit je 1240 CZK. S pozdravem FreeNetIS'));
|
||
$sms->send();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
//$sms = new Sms_message_Model();
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
freenetis/trunk/kohana/application/libraries/Sms.php | ||
---|---|---|
|
||
protected $user;
|
||
protected $password;
|
||
protected $hostname;
|
||
protected $text;
|
||
protected $error;
|
||
protected $status;
|
||
... | ... | |
$this->password = $password;
|
||
}
|
||
|
||
public function hostname($hostname)
|
||
{
|
||
$this->hostname = $hostname;
|
||
}
|
||
|
||
public function text($text)
|
||
{
|
||
$this->text = $text;
|
freenetis/trunk/kohana/application/libraries/Sms_Soudvinv100.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
|
||
require_once('Sms.php');
|
||
|
||
class Sms_Soudvinv100 extends Sms
|
||
{
|
||
protected $hostname;
|
||
|
||
protected $messages;
|
||
|
||
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
$this->driver = self::$SOUNDWINV100;
|
||
}
|
||
|
||
public function test_conn()
|
||
{
|
||
$curl = curl_init();
|
||
curl_setopt ($curl, CURLOPT_URL, 'http://'.$this->hostname);
|
||
curl_setopt($curl, CURLOPT_USERPWD, $this->user.':'.$this->password);
|
||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||
|
||
$result = curl_exec ($curl);
|
||
curl_close ($curl);
|
||
|
||
if ($result == '' || $result === null)
|
||
{
|
||
$this->error = 0;
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
$this->status = 0;
|
||
return true;
|
||
}
|
||
}
|
||
|
||
public function hostname($hostname)
|
||
{
|
||
$this->hostname = $hostname;
|
||
}
|
||
|
||
public function get_messages()
|
||
{
|
||
return $this->messages;
|
||
}
|
||
|
||
final public function send()
|
||
{
|
||
if (!$this->test_conn())
|
||
return false;
|
||
|
||
$vars = array(
|
||
'sms_number' => $this->recipient,
|
||
'max_digit' => $this->text
|
||
);
|
||
|
||
$data = http_build_query($vars);
|
||
|
||
$curl = curl_init();
|
||
curl_setopt($curl, CURLOPT_URL, 'http://'.$this->hostname.'/do_gsm_sms.cgi');
|
||
curl_setopt($curl, CURLOPT_USERPWD, $this->user.':'.$this->password);
|
||
curl_setopt($curl, CURLOPT_POST, 1);
|
||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||
|
||
$result = curl_exec ($curl);
|
||
curl_close ($curl);
|
||
|
||
if ($result == '' || $result === null)
|
||
{
|
||
$this->error = 1;
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
$this->status = 0;
|
||
return true;
|
||
}
|
||
}
|
||
|
||
final public function receive()
|
||
{
|
||
if (!$this->test_conn())
|
||
return false;
|
||
|
||
$curl = curl_init();
|
||
curl_setopt ($curl, CURLOPT_URL, 'http://'.$this->hostname.'/sms.message');
|
||
curl_setopt($curl, CURLOPT_USERPWD, $this->user.':'.$this->password);
|
||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||
|
||
$result = curl_exec ($curl);
|
||
curl_close ($curl);
|
||
|
||
if ($result == '' || $result === null)
|
||
{
|
||
$this->error = 1;
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
$messages = explode("\n", $result);
|
||
|
||
$sms = array();
|
||
$c = 0;
|
||
|
||
foreach ($messages as $m)
|
||
{
|
||
$message = substr($m, strpos($m, 'From:'));
|
||
|
||
if (stristr($message, 'From:') != FALSE && stristr($message, 'Date:') != FALSE && stristr($message, 'Message:') != FALSE)
|
||
{
|
||
$sub_message = explode('Date:', $message);
|
||
|
||
$from = trim($sub_message[0]);
|
||
$sender = substr($from, 5);
|
||
$date = substr($sub_message[1], 0, 17);
|
||
$text = substr(substr($sub_message[1], 26), 0, strlen(substr($sub_message[1], 26)) - 2);
|
||
|
||
$sms[$c]->sender = $sender;
|
||
$sms[$c]->date = $date;
|
||
$sms[$c]->text = $text;
|
||
$c++;
|
||
}
|
||
}
|
||
|
||
$this->messages = $sms;
|
||
|
||
$this->status = 1;
|
||
return true;
|
||
}
|
||
}
|
||
|
||
public function get_error()
|
||
{
|
||
switch ($this->error)
|
||
{
|
||
case '0':
|
||
return 'Nesprávné přihlašovací údaje nebo hostname.';
|
||
default:
|
||
return 'Neznámá chyba';
|
||
}
|
||
}
|
||
|
||
public function get_status()
|
||
{
|
||
switch ($this->status)
|
||
{
|
||
case '0':
|
||
return 'SMS zpráva odeslána';
|
||
case '1':
|
||
return 'SMS zpráva přijata';
|
||
default:
|
||
return 'Neznámá chyba';
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
?>
|
Také k dispozici: Unified diff
Přidán ovladač pro SMS brámu GSM Soundvin V 100