Fix gammu adapter, first version of gammu sms parser
This commit is contained in:
parent
d252f88595
commit
fcc438af3c
|
@ -84,15 +84,7 @@
|
|||
public function __construct (string $number, string $datas)
|
||||
{
|
||||
$this->number = $number;
|
||||
$this->formatted_number = str_replace('+', '00', $number);
|
||||
$this->datas = json_decode($datas, true);
|
||||
|
||||
$this->api = new Api(
|
||||
$this->datas['app_key'],
|
||||
$this->datas['app_secret'],
|
||||
$this->datas['endpoint'],
|
||||
$this->datas['consumer_key']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,14 +128,14 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
$find_ok = $this->search_for_string('ok', $command_parts['output']);
|
||||
$find_ok = $this->search_for_string($result['output'], 'ok');
|
||||
if (!$find_ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$uid = false;
|
||||
foreach ($output as $line)
|
||||
foreach ($result['output'] as $line)
|
||||
{
|
||||
$matches = [];
|
||||
preg_match('#reference=([0-9]+)#u', $line, $matches);
|
||||
|
@ -184,17 +176,7 @@
|
|||
*/
|
||||
public function test () : bool
|
||||
{
|
||||
if (!file_exists($this->datas['config_file']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->exec_command($command_parts);
|
||||
if ($result['return'] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Always return true as we cannot test because we would be needing a root account
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -258,12 +240,18 @@
|
|||
*/
|
||||
private function exec_command (array $command_parts) : array
|
||||
{
|
||||
//Add redirect of error to stdout
|
||||
$command_parts[] = '2>&1';
|
||||
|
||||
|
||||
$command = implode(' ', $command_parts);
|
||||
|
||||
$output = [];
|
||||
$return_var = null;
|
||||
exec($command, $output, $return_var);
|
||||
|
||||
var_dump($output);
|
||||
|
||||
return ['return' => (int) $return_var, 'output' => $output];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,30 @@
|
|||
#!/bin/sh
|
||||
date=$(date +%Y%m%d%H%M%S%N)
|
||||
first_time=1
|
||||
|
||||
RECEPTION_DIR='/opt/raspisms/datas/gammu'
|
||||
|
||||
if [ ! -d $RECEPTION_DIR ]
|
||||
then
|
||||
mkdir "$RECEPTION_DIR"
|
||||
fi
|
||||
|
||||
for i in `seq $SMS_MESSAGES` ; do
|
||||
eval "sms_number=\"\${SMS_${i}_NUMBER}\""
|
||||
eval "sms_text=\"\${SMS_${i}_TEXT}\""
|
||||
|
||||
if [ $first_time -eq 1 ]
|
||||
then
|
||||
sms="$sms_number:"
|
||||
first_time=0
|
||||
fi
|
||||
|
||||
sms="$sms$sms_text"
|
||||
done
|
||||
echo "$sms" >> /var/www/RaspiSMS/receiveds/"$date".txt
|
||||
|
||||
if [ -z "$SMS_MESSAGES" ]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "$sms" >> "$RECEPTION_DIR/$PHONE_ID-${date}.txt"
|
|
@ -60,4 +60,37 @@ namespace controllers\internals;
|
|||
|
||||
new \daemons\Phone($phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne la fenetre de connexion.
|
||||
*/
|
||||
public function test($id_phone)
|
||||
{
|
||||
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
||||
$internal_phone = new \controllers\internals\Phone($bdd);
|
||||
$phone = $internal_phone->get($id_phone);
|
||||
if (!$phone)
|
||||
{
|
||||
echo "No phone for id : $id_phone\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
echo "Found phone for id : $id_phone\n";
|
||||
|
||||
$adapter_classname = $phone['adapter'];
|
||||
$adapter = new $adapter_classname($phone['number'], $phone['adapter_datas']);
|
||||
|
||||
//Try send a message
|
||||
$destination = '+33669529042';
|
||||
$text = "Coucou c'est pour un test !";
|
||||
$flash = false;
|
||||
$uid = $adapter->send($destination, $text, $flash);
|
||||
|
||||
if (!$uid)
|
||||
{
|
||||
echo "Cannot send message to $destination\n";
|
||||
}
|
||||
|
||||
echo "Send a message to $destination with uid $uid \n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace controllers\publics;
|
|||
/**
|
||||
* Page de connexion.
|
||||
*/
|
||||
class Connect extends \descartes\Controller
|
||||
class Test extends \descartes\Controller
|
||||
{
|
||||
private $internal_user;
|
||||
private $internal_setting;
|
||||
|
@ -33,35 +33,5 @@ namespace controllers\publics;
|
|||
$this->internal_phone = new \controllers\internals\Phone($bdd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette fonction retourne la fenetre de connexion.
|
||||
*/
|
||||
public function test($id_phone)
|
||||
{
|
||||
$phone = $this->internal_phone->get($id_phone);
|
||||
if (!$phone)
|
||||
{
|
||||
echo "No phone for id : $id_phone\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
echo "Found phone for id : $id_phone\n";
|
||||
|
||||
$adapter_classname = $phone['adapter'];
|
||||
$adapter = new $adapter_classname($phone['number'], $phone['adapter_datas']);
|
||||
|
||||
//Try send a message
|
||||
$destination = '+33669529042';
|
||||
$text = "Coucou c'est pour un test !";
|
||||
$flash = false;
|
||||
$uid = $adapter->send($destination, $text, $flash);
|
||||
|
||||
if (!$uid)
|
||||
{
|
||||
echo "Cannot send message to $destination\n";
|
||||
}
|
||||
|
||||
echo "Send a message to $destination with uid $uid \n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue