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;
|
|
|
|
private $model_database;
|
|
|
|
private $model_sended;
|
|
|
|
private $model_smsstop;
|
|
|
|
private $model_received;
|
|
|
|
private $model_user;
|
|
|
|
|
|
|
|
private $internal_event;
|
|
|
|
|
2019-11-04 18:33:04 +01:00
|
|
|
public function __construct()
|
2019-11-04 18:23:11 +01:00
|
|
|
{
|
2019-11-04 18:33:04 +01:00
|
|
|
$bdd = descartes\Model::connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
|
|
|
|
|
2019-11-04 18:23:11 +01:00
|
|
|
$this->model_command = new \models\Command($bdd);
|
|
|
|
$this->model_database = new \models\DataBase($bdd);
|
2019-11-06 17:46:28 +01:00
|
|
|
$this->model_sended = new \models\Sent($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-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:08:22 +01:00
|
|
|
$scheduleds = $this->model_database->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-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 18:08:22 +01:00
|
|
|
$this->model_database->update_progress_scheduleds_in($ids_scheduleds, 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-06 18:08:22 +01:00
|
|
|
$target_numbers = $this->model_database->get_numbers_for_scheduled($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-04 18:23:11 +01:00
|
|
|
$contacts = $this->model_database->getContactForScheduled($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-06 18:08:22 +01:00
|
|
|
$groups = $this->model_database->get_groups_for_scheduled($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-06 18:08:22 +01:00
|
|
|
$contacts = $this->model_database->get_contacts_for_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-04 18:23:11 +01:00
|
|
|
$smsStops = $this->model_smsstop->_select('smsstop');
|
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-10-30 01:22:09 +01:00
|
|
|
if (RASPISMS_SETTINGS_SMSSTOPS)
|
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-04 18:23:11 +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:08:22 +01:00
|
|
|
$this->model_database->delete_scheduleds_in($ids_scheduleds);
|
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-10-30 00:30:39 +01:00
|
|
|
if ('.' === $dir || '..' === $dir || '.tokeep' === $dir)
|
|
|
|
{
|
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-10-30 00:30:39 +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-04 18:23:11 +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-04 18:23:11 +01:00
|
|
|
$this->model_sended->update($sended['id'], ['before_delivered' => 0, 'failed' => true]);
|
2019-11-06 17:46:28 +01:00
|
|
|
echo 'Sent 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-04 18:23:11 +01:00
|
|
|
$this->model_database->update($sended['id'], ['before_delivered' => $sended['before_delivered'] - 1]);
|
2019-11-06 17:46:28 +01:00
|
|
|
echo 'Sent 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-04 18:23:11 +01:00
|
|
|
$this->model_database->update($sended['id'], ['before_delivered' => 0, 'delivered' => true]);
|
2019-11-06 17:46:28 +01:00
|
|
|
echo 'Sent 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-10-29 14:57:13 +01:00
|
|
|
//Si on a bien un utilisateur avec les identifiants reçus
|
2019-11-06 18:08:22 +01:00
|
|
|
$user = $this->model_database->get_user_from_email($flags['LOGIN']);
|
2019-10-30 00:30:39 +01:00
|
|
|
error_log('We found '.\count($user).' users');
|
|
|
|
if ($user && $user['password'] === sha1($flags['PASSWORD']))
|
|
|
|
{
|
2019-10-30 00:17:10 +01:00
|
|
|
error_log('Password is valid');
|
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-04 18:23:11 +01:00
|
|
|
$commands = $this->model_database->_select('commands');
|
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-10-29 14:57:13 +01:00
|
|
|
$send_by = $number;
|
|
|
|
$content = $text;
|
2019-10-30 00:30:39 +01:00
|
|
|
$is_command = \count($found_commands);
|
2019-11-04 18:23:11 +01:00
|
|
|
if (!$this->model_received->insert(['at' => $date, 'send_by' => $send_by, 'content' => $content, 'is_command' => $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-04 18:23:11 +01:00
|
|
|
$this->model_database->_insert('transfers', ['id_received' => $this->model_database->lastId(), 'progress' => false]);
|
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-04 18:23:11 +01:00
|
|
|
global $this->model_database;
|
|
|
|
$transfers = $this->model_database->_select('transfers', ['progress' => false]);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
$ids_transfers = [];
|
|
|
|
$ids_receiveds = [];
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($transfers as $transfer)
|
|
|
|
{
|
2019-10-29 14:57:13 +01:00
|
|
|
$ids_transfers[] = $transfer['id'];
|
|
|
|
$ids_receiveds[] = $transfer['id_received'];
|
|
|
|
}
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-06 18:08:22 +01:00
|
|
|
$this->model_database->update_progress_transfers_in($ids_transfers, true);
|
2019-10-30 00:30:39 +01:00
|
|
|
|
2019-11-06 18:08:22 +01:00
|
|
|
$receiveds = $this->model_database->get_receiveds_in($ids_receiveds);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-11-04 18:23:11 +01:00
|
|
|
$users = $this->model_user->_select('users', ['transfer' => true]);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-30 00:30:39 +01:00
|
|
|
foreach ($users as $user)
|
|
|
|
{
|
|
|
|
foreach ($receiveds as $received)
|
|
|
|
{
|
|
|
|
echo "Transfer d'un Sms du ".$received['send_by']." à l'email ".$user['email'];
|
2019-10-29 14:57:13 +01:00
|
|
|
$to = $user['email'];
|
2019-10-30 00:30:39 +01:00
|
|
|
$subject = '[RaspiSms] - Transfert d\'un Sms du '.$received['send_by'];
|
|
|
|
$message = 'Le numéro '.$received['send_by']." vous a envoyé un Sms : \n".$received['content'];
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
$ok = mail($to, $subject, $message);
|
2019-10-30 00:30:39 +01:00
|
|
|
|
|
|
|
echo ' ... '.($ok ? 'OK' : 'KO')."\n";
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 18:08:22 +01:00
|
|
|
$this->model_database->delete_transfers_in($ids_transfers);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
}
|