2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of PHP CS Fixer.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
namespace controllers\internals;
|
2019-10-29 18:36:25 +01:00
|
|
|
|
|
|
|
class Console extends \descartes\InternalController
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-11-04 18:23:11 +01:00
|
|
|
private $model_command;
|
2019-11-07 16:17:18 +01:00
|
|
|
private $model_sended;
|
2019-11-04 18:23:11 +01:00
|
|
|
private $model_smsstop;
|
|
|
|
private $model_received;
|
2019-11-06 20:34:26 +01:00
|
|
|
private $model_scheduled;
|
2019-11-04 18:23:11 +01:00
|
|
|
private $model_user;
|
2019-11-07 16:17:18 +01:00
|
|
|
private $internal_contact;
|
|
|
|
private $internal_command;
|
|
|
|
private $internal_database;
|
|
|
|
private $internal_sended;
|
|
|
|
private $internal_sms_stop;
|
|
|
|
private $internal_received;
|
2019-11-06 20:34:26 +01:00
|
|
|
private $internal_scheduled;
|
2019-11-07 16:17:18 +01:00
|
|
|
private $internal_user;
|
|
|
|
private $internal_transfer;
|
2019-11-04 18:23:11 +01:00
|
|
|
|
|
|
|
private $internal_event;
|
|
|
|
|
2019-11-04 18:33:04 +01:00
|
|
|
public function __construct()
|
2019-11-04 18:23:11 +01:00
|
|
|
{
|
2019-11-06 20:34:26 +01:00
|
|
|
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
2019-11-04 18:33:04 +01:00
|
|
|
|
2019-11-04 18:23:11 +01:00
|
|
|
$this->model_command = new \models\Command($bdd);
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->model_sended = new \models\Sended($bdd);
|
2019-11-04 18:23:11 +01:00
|
|
|
$this->model_smsstop = new \models\SmsStop($bdd);
|
|
|
|
$this->model_received = new \models\Received($bdd);
|
|
|
|
$this->model_user = new \models\User($bdd);
|
|
|
|
|
|
|
|
$this->internal_event = new \controllers\internals\Event($bdd);
|
|
|
|
}
|
2019-11-06 20:34:26 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction envoie tous les Sms programmés qui doivent l'être.
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
|
|
|
public function sendScheduled()
|
|
|
|
{
|
|
|
|
//On créé l'objet de base de données
|
2019-10-30 00:30:39 +01:00
|
|
|
for ($i = 0; $i < 30; ++$i)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$now = new \DateTime();
|
|
|
|
$now = $now->format('Y-m-d H:i:s');
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
echo "Début de l'envoi des Sms programmés\n";
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-06 18:32:07 +01:00
|
|
|
$scheduleds = $this->model_scheduled->get_scheduleds_not_in_progress_before($now);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
$ids_scheduleds = [];
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On passe en cours de progression tous les Sms
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($scheduleds as $scheduled)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$ids_scheduleds[] = $scheduled['id'];
|
|
|
|
}
|
|
|
|
|
2019-11-07 19:31:49 +01:00
|
|
|
if (!count($ids_scheduleds))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
echo \count($ids_scheduleds)." Sms à envoyer ont été trouvés et ajoutés à la liste des Sms en cours d'envoi.\n";
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-06 20:27:16 +01:00
|
|
|
foreach ($ids_scheduleds as $ids_scheduled)
|
|
|
|
{
|
|
|
|
$this->internal_scheduled->update_progress($id_scheduled, true);
|
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//Pour chaque Sms à envoyer
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($scheduleds as $scheduled)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$id_scheduled = $scheduled['id'];
|
|
|
|
$text_sms = escapeshellarg($scheduled['content']);
|
|
|
|
$flash = $scheduled['flash'];
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On initialise les numéros auxquelles envoyer le Sms
|
2019-10-30 00:30:39 +01:00
|
|
|
$numbers = [];
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On récupère les numéros pour le Sms et on les ajoute
|
2019-11-07 16:17:18 +01:00
|
|
|
$target_numbers = $this->internal_scheduled->get_numbers($id_scheduled);
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($target_numbers as $target_number)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$numbers[] = $target_number['number'];
|
|
|
|
}
|
|
|
|
|
|
|
|
//On récupère les contacts, et on ajoute les numéros
|
2019-11-07 16:17:18 +01:00
|
|
|
$contacts = $this->internal_scheduled->get_contacts($id_scheduled);
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($contacts as $contact)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$numbers[] = $contact['number'];
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On récupère les groups
|
2019-11-07 16:17:18 +01:00
|
|
|
$groups = $this->internal_scheduled->get_groups($id_scheduled);
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($groups as $group)
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
//On récupère les contacts du group et on les ajoute aux numéros
|
2019-11-07 16:17:18 +01:00
|
|
|
$contacts = $this->internal_contact->get_by_group($group['id']);
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($contacts as $contact)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$numbers[] = $contact['number'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
$smsStops = $this->internal_sms_stop->get_all();
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
foreach ($numbers as $number)
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
//Si les Sms STOP sont activés, on passe au numéro suivant si le numéro actuelle fait parti des Sms STOP
|
2019-11-10 00:27:42 +01:00
|
|
|
if (RASPISMS_SETTINGS_SMSSTOP)
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
|
|
|
foreach ($smsStops as $smsStop)
|
|
|
|
{
|
|
|
|
if (!($number === $smsStop['number']))
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
echo 'Un Sms destiné au '.$number." a été bloqué par Sms STOP\n";
|
|
|
|
|
|
|
|
continue 2; //On passe au numéro suivant !
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
echo " Envoi d'un Sms au ".$number."\n";
|
2019-10-30 00:17:10 +01:00
|
|
|
//On ajoute le Sms aux Sms envoyés
|
2019-10-29 14:57:13 +01:00
|
|
|
//Pour plus de précision, on remet la date à jour en réinstanciant l'objet \DateTime (et on reformatte la date, bien entendu)
|
|
|
|
$now = new \DateTime();
|
|
|
|
$now = $now->format('Y-m-d H:i:s');
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On peut maintenant ajouter le Sms
|
2019-11-07 16:17:18 +01:00
|
|
|
if (!$id_sended = $this->model_sended->insert(['at' => $now, 'target' => $number, 'content' => $scheduled['content'], 'before_delivered' => ceil(mb_strlen($scheduled['content']) / 160)]))
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
|
|
|
echo 'Impossible d\'inserer le sms pour le numero '.$number."\n";
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//Commande qui envoie le Sms
|
2019-10-30 00:30:39 +01:00
|
|
|
$commande_send_sms = 'gammu-smsd-inject TEXT '.escapeshellarg($number).' -report -len '.mb_strlen($text_sms).' -text '.$text_sms;
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 01:22:09 +01:00
|
|
|
if (RASPISMS_SETTINGS_SMS_FLASH && $flash)
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$commande_send_sms .= ' -flash';
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//Commande qui s'assure de passer le Sms dans ceux envoyés, et de lui donner le bon statut
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On va liée les deux commandes pour envoyer le Sms puis le passer en echec
|
2019-10-30 00:30:39 +01:00
|
|
|
$commande = '('.$commande_send_sms.') >/dev/null 2>/dev/null &';
|
2019-10-30 00:17:10 +01:00
|
|
|
exec($commande); //On execute la commande d'envoie d'un Sms
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
echo "Tous les Sms sont en cours d'envoi.\n";
|
|
|
|
//Tous les Sms ont été envoyés.
|
2019-11-06 18:32:07 +01:00
|
|
|
foreach ($ids_scheduleds as $id_scheduled)
|
|
|
|
{
|
|
|
|
$this->model_scheduled->delete($id_scheduled);
|
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
//On dors 2 secondes
|
|
|
|
sleep(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:17:10 +01:00
|
|
|
* Cette fonction reçoit un Sms, et l'enregistre, en essayant dde trouver une commande au passage.
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
2019-10-30 00:17:10 +01:00
|
|
|
public function parseReceivedSms()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
//On créer l'objet de base de données
|
2019-10-30 00:30:39 +01:00
|
|
|
for ($i = 0; $i < 30; ++$i)
|
|
|
|
{
|
|
|
|
foreach (scandir(PWD_RECEIVEDS) as $dir)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
//Si le fichier est un fichier système, on passe à l'itération suivante
|
2019-11-07 19:29:11 +01:00
|
|
|
if (mb_substr($dir, 0, 1) == '.')
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
2019-10-29 18:36:25 +01:00
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-07 19:29:11 +01:00
|
|
|
echo 'Analyse du Sms ' . $dir . "\n";
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On récupère la date du Sms à la seconde près grâce au nom du fichier (Cf. parseSms.sh)
|
2019-10-29 14:57:13 +01:00
|
|
|
//Il faut mettre la date au format Y-m-d H:i:s
|
2019-10-30 00:30:39 +01:00
|
|
|
$date = mb_substr($dir, 0, 4).'-'.mb_substr($dir, 4, 2).'-'.mb_substr($dir, 6, 2).' '.mb_substr($dir, 8, 2).':'.mb_substr($dir, 10, 2).':'.mb_substr($dir, 12, 2);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
//On récupère le fichier, et on récupère la chaine jusqu'au premier ':' pour le numéro de téléphone source, et la fin pour le message
|
2019-10-30 00:30:39 +01:00
|
|
|
$content_file = file_get_contents(PWD_RECEIVEDS.$dir);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
//Si on peux pas ouvrir le fichier, on quitte en logant une erreur
|
2019-10-30 00:30:39 +01:00
|
|
|
if (false === $content_file)
|
|
|
|
{
|
|
|
|
error_log('Unable to read file "'.$dir);
|
2019-10-29 14:57:13 +01:00
|
|
|
die(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
//On supprime le fichier. Si on n'y arrive pas, alors on log
|
2019-10-30 00:30:39 +01:00
|
|
|
if (!unlink(PWD_RECEIVEDS.$dir))
|
|
|
|
{
|
|
|
|
error_log('Unable to delete file "'.$dir);
|
2019-10-29 14:57:13 +01:00
|
|
|
die(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
$content_file = explode(':', $content_file, 2);
|
|
|
|
|
|
|
|
//Si on a pas passé de numéro ou de message, alors on lève une erreur
|
2019-10-30 00:30:39 +01:00
|
|
|
if (!isset($content_file[0], $content_file[1]))
|
|
|
|
{
|
|
|
|
error_log('Missing params in file "'.$dir);
|
2019-10-29 14:57:13 +01:00
|
|
|
die(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
$number = $content_file[0];
|
2019-10-30 00:17:10 +01:00
|
|
|
$number = \controllers\internals\Tool::parse_phone($number);
|
2019-10-29 14:57:13 +01:00
|
|
|
$text = $content_file[1];
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On gère les Sms STOP
|
2019-10-30 00:30:39 +01:00
|
|
|
if ('STOP' === trim($text))
|
|
|
|
{
|
|
|
|
echo 'STOP Sms detected '.$number."\n";
|
|
|
|
error_log('STOP Sms detected '.$number);
|
2019-11-04 18:23:11 +01:00
|
|
|
$this->model_smsstop->insert(['number' => $number]);
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//On gère les accusés de reception
|
2019-10-30 00:30:39 +01:00
|
|
|
if ('Delivered' === trim($text) || 'Failed' === trim($text))
|
|
|
|
{
|
|
|
|
echo 'Delivered or Failed Sms for '.$number."\n";
|
|
|
|
error_log('Delivered or Failed Sms for '.$number);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On récupère les Sms pas encore validé, uniquement sur les dernières 12h
|
2019-10-29 14:57:13 +01:00
|
|
|
$now = new \DateTime();
|
|
|
|
$interval = new \DateInterval('PT12H');
|
|
|
|
$sinceDate = $now->sub($interval)->format('Y-m-d H:i:s');
|
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
if (!$sendeds = $this->model_sended->_select('sendeds', ['target' => $number, 'delivered' => false, 'failed' => false, '>at' => $sinceDate], 'at', false, 1))
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sended = $sendeds[0];
|
|
|
|
|
|
|
|
//On gère les echecs
|
2019-10-30 00:30:39 +01:00
|
|
|
if ('Failed' === trim($text))
|
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->model_sended->update($sended['id'], ['before_delivered' => 0, 'failed' => true]);
|
|
|
|
echo 'Sended Sms id '.$sended['id']." pass to failed status\n";
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//On gère le cas des messages de plus de 160 caractères, lesquels impliquent plusieurs accusés
|
2019-10-30 00:30:39 +01:00
|
|
|
if ($sended['before_delivered'] > 1)
|
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->internal_sended->decrement_before_delivered($sended['id']);
|
|
|
|
echo 'Sended Sms id '.$sended['id']." before_delivered decrement\n";
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Si tout est bon, que nous avons assez d'accusés, nous validons !
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->internal_sended->set_delivered($sended['id']);
|
|
|
|
echo 'Sended Sms id '.$sended['id']." to delivered status\n";
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
continue;
|
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
if (!$number)
|
|
|
|
{
|
|
|
|
error_log('Invalid phone number in file "'.$dir);
|
2019-10-29 14:57:13 +01:00
|
|
|
die(6);
|
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
//On va vérifier si on a reçu une commande, et des identifiants
|
2019-10-30 00:17:10 +01:00
|
|
|
$flags = \controllers\internals\Tool::parse_for_flag($text);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
//On créer le tableau qui permettra de stocker les commandes trouvées
|
2019-10-30 00:30:39 +01:00
|
|
|
$found_commands = [];
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
//Si on reçu des identifiants
|
2019-10-30 00:30:39 +01:00
|
|
|
if (\array_key_exists('LOGIN', $flags) && \array_key_exists('PASSWORD', $flags))
|
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
$user = $this->internal_user->check_credentials($flags['LOGIN'], $flags['PASSWORD']);
|
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
error_log('We found '.\count($user).' users');
|
2019-11-07 16:17:18 +01:00
|
|
|
if ($user)
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
error_log('Password is valid');
|
2019-11-07 16:17:18 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
//On va passer en revue toutes les commandes, pour voir si on en trouve dans ce message
|
2019-11-07 16:17:18 +01:00
|
|
|
$commands = $this->internal_command->get_all();
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
error_log('We found '.\count($commands).' commands');
|
|
|
|
foreach ($commands as $command)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$command_name = mb_strtoupper($command['name']);
|
2019-10-30 00:30:39 +01:00
|
|
|
if (\array_key_exists($command_name, $flags))
|
|
|
|
{
|
|
|
|
error_log('We found command '.$command_name);
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
//Si la commande ne nécessite pas d'être admin, ou si on est admin
|
2019-10-30 00:30:39 +01:00
|
|
|
if (!$command['admin'] || $user['admin'])
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
error_log('And the count is ok');
|
2019-10-30 00:30:39 +01:00
|
|
|
$found_commands[$command_name] = PWD_SCRIPTS.$command['script'].escapeshellcmd($flags[$command_name]);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On va supprimer le mot de passe du Sms pour pouvoir l'enregistrer sans danger
|
2019-10-30 00:30:39 +01:00
|
|
|
if (isset($flags['PASSWORD']))
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$text = str_replace($flags['PASSWORD'], '*****', $text);
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On map les données et on créer le Sms reçu
|
2019-11-10 17:00:21 +01:00
|
|
|
$origin = $number;
|
2019-10-29 14:57:13 +01:00
|
|
|
$content = $text;
|
2019-10-30 00:30:39 +01:00
|
|
|
$is_command = \count($found_commands);
|
2019-11-10 17:00:21 +01:00
|
|
|
if ($id_received = $this->internal_received->create($date, $origin, $content, $is_command))
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
echo "Erreur lors de l'enregistrement du Sms\n";
|
2019-10-30 00:30:39 +01:00
|
|
|
error_log('Unable to process the Sms in file "'.$dir);
|
2019-10-29 14:57:13 +01:00
|
|
|
die(7);
|
|
|
|
}
|
|
|
|
|
2019-10-30 00:17:10 +01:00
|
|
|
//On insert le Sms dans le tableau des sms à envoyer par mail
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->internal_transfer->create($id_received);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
//Chaque commande sera executée.
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($found_commands as $command_name => $command)
|
|
|
|
{
|
|
|
|
echo 'Execution de la commande : '.$command_name.' :: '.$command."\n";
|
2019-10-29 14:57:13 +01:00
|
|
|
exec($command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//On attend 2 secondes
|
|
|
|
sleep(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-30 00:30:39 +01:00
|
|
|
* Cette fonction permet d'envoyer par mail les sms à transférer.
|
2019-10-29 14:57:13 +01:00
|
|
|
*/
|
2019-10-29 18:36:25 +01:00
|
|
|
public function sendTransfers()
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-30 01:22:09 +01:00
|
|
|
if (!RASPISMS_SETTINGS_TRANSFER)
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
echo "Le transfer de Sms est désactivé ! \n";
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
$users = $this->internal_user->gets_by_transfer(true);
|
|
|
|
$transfers = $this->internal_transfer->get_not_in_progress();
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($transfers as $transfer)
|
|
|
|
{
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->internal_transfer->update($transfer['id'], $transfer['id_received'], true);
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
$received = $this->internal_received->get($transfer['id_received']);
|
|
|
|
if (!$received)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
foreach ($users as $user)
|
2019-10-30 00:30:39 +01:00
|
|
|
{
|
2019-11-10 17:00:21 +01:00
|
|
|
echo "Transfer d'un Sms du ".$received['origin']." à l'email ".$user['email'];
|
2019-11-07 16:17:18 +01:00
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
$to = $user['email'];
|
2019-11-10 17:00:21 +01:00
|
|
|
$subject = '[RaspiSms] - Transfert d\'un Sms du '.$received['origin'];
|
|
|
|
$message = 'Le numéro '.$received['origin']." vous a envoyé un Sms : \n".$received['content'];
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
$success = mail($to, $subject, $message);
|
|
|
|
echo ' ... '.($success ? 'ok' : 'ko')."\n";
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-11-07 16:17:18 +01:00
|
|
|
$this->internal_transfer->delete($transfer['id']);
|
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
}
|