Compare commits
No commits in common. "6e6c51a9eec127911dfce4907a38f05792643680" and "cf4dd2f07591e09b79921b74928f4c934d7f20ea" have entirely different histories.
6e6c51a9ee
...
cf4dd2f075
|
@ -11,8 +11,6 @@
|
||||||
|
|
||||||
namespace controllers\internals;
|
namespace controllers\internals;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class Received extends StandardController
|
class Received extends StandardController
|
||||||
{
|
{
|
||||||
protected $model;
|
protected $model;
|
||||||
|
@ -90,6 +88,14 @@ use Exception;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Check if the received message is a SMS STOP and we must register it
|
||||||
|
$internal_smsstop = new SmsStop($this->bdd);
|
||||||
|
$is_stop = $internal_smsstop->check_for_stop($received['text']);
|
||||||
|
if ($is_stop)
|
||||||
|
{
|
||||||
|
$internal_smsstop->create($id_user, $origin);
|
||||||
|
}
|
||||||
|
|
||||||
//Link medias
|
//Link medias
|
||||||
$internal_media = new Media($this->bdd);
|
$internal_media = new Media($this->bdd);
|
||||||
foreach ($media_ids as $media_id)
|
foreach ($media_ids as $media_id)
|
||||||
|
@ -110,32 +116,6 @@ use Exception;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if the received message is a SMS STOP and we must register it
|
|
||||||
$internal_smsstop = new SmsStop($this->bdd);
|
|
||||||
$is_stop = $internal_smsstop->check_for_stop($received['text']);
|
|
||||||
if ($is_stop)
|
|
||||||
{
|
|
||||||
$stop_exists = (bool) $internal_smsstop->get_by_number_for_user($id_user, $origin);
|
|
||||||
if ($stop_exists)
|
|
||||||
{
|
|
||||||
return $id_received;
|
|
||||||
}
|
|
||||||
|
|
||||||
$internal_smsstop->create($id_user, $origin);
|
|
||||||
|
|
||||||
//If stop response enabled, respond to user
|
|
||||||
//(this will happen only for first stop, any further stop will not trigger responses)
|
|
||||||
$internal_setting = new Setting($this->bdd);
|
|
||||||
$user_settings = $internal_setting->gets_for_user($id_user);
|
|
||||||
|
|
||||||
if ((int) ($user_settings['smsstop_respond'] ?? false))
|
|
||||||
{
|
|
||||||
$response = $user_settings['smsstop_response'];
|
|
||||||
$internal_scheduled = new Scheduled($this->bdd);
|
|
||||||
$internal_scheduled->create($id_user, (new \DateTime())->format('Y-m-d H:i:s'), $response, $id_phone, null, false, false, \models\SmsStop::SMS_STOP_TAG, [['number' => $origin, 'data' => '[]']]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $id_received;
|
return $id_received;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -602,8 +602,8 @@ use Monolog\Logger;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove messages to smsstops numbers if not with tag SMS_STOP
|
//Remove messages to smsstops numbers
|
||||||
if ($scheduled['tag'] != \models\SmsStop::SMS_STOP_TAG && ($users_smsstops[$id_user] ?? false) && in_array($target['number'], $users_smsstops[$id_user]))
|
if (($users_smsstops[$id_user] ?? false) && in_array($target['number'], $users_smsstops[$id_user]))
|
||||||
{
|
{
|
||||||
unset($targets[$key]);
|
unset($targets[$key]);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -73,8 +73,7 @@ namespace controllers\internals;
|
||||||
*/
|
*/
|
||||||
public function check_for_stop(string $str)
|
public function check_for_stop(string $str)
|
||||||
{
|
{
|
||||||
$str = trim(mb_strtolower($str));
|
return 'stop' == trim(mb_strtolower($str));
|
||||||
return 'stop' == $str || 'stop sms' == $str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -91,21 +91,21 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cette fonction permet de faire un retour sous forme de json
|
* Cette fonction permet de faire un retour sous forme de json
|
||||||
* @param array $datas : Les données à retourner sous forme de json
|
* @param array $data : Les données à retourner sous forme de json
|
||||||
* @param boolean $secure : Défini si l'affichage doit être sécurisé contre les XSS, par défaut true
|
* @param boolean $secure : Défini si l'affichage doit être sécurisé contre les XSS, par défaut true
|
||||||
* @return ApiController : On retourne l'API controlleur lui meme pour pouvoir chainer
|
* @return ApiController : On retourne l'API controlleur lui meme pour pouvoir chainer
|
||||||
*/
|
*/
|
||||||
public function json ($datas, $secure = true)
|
public function json ($data, $secure = true)
|
||||||
{
|
{
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
if ($secure)
|
if ($secure)
|
||||||
{
|
{
|
||||||
echo htmlspecialchars(json_encode($datas), ENT_NOQUOTES);
|
echo htmlspecialchars(json_encode($data), ENT_NOQUOTES);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo json_encode($datas);
|
echo json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
if (!is_readable($template_path))
|
if (!is_readable($template_path))
|
||||||
{
|
{
|
||||||
throw new exceptions\DescartesExceptionTemplateNotReadable('Template ' . $template_path . ' is not readable.');
|
throw new DescartesTemplateNotReadableException('Template ' . $template_path . ' is not readable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
require $template_path;
|
require $template_path;
|
||||||
|
|
|
@ -72,10 +72,6 @@
|
||||||
protected static function clean_url (string $url)
|
protected static function clean_url (string $url)
|
||||||
{
|
{
|
||||||
$to_remove = parse_url(HTTP_PWD, PHP_URL_PATH);
|
$to_remove = parse_url(HTTP_PWD, PHP_URL_PATH);
|
||||||
if ($to_remove === null)
|
|
||||||
{
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = mb_strcut($url, mb_strlen($to_remove));
|
$url = mb_strcut($url, mb_strlen($to_remove));
|
||||||
$url = parse_url($url, PHP_URL_PATH);
|
$url = parse_url($url, PHP_URL_PATH);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
/*
|
/*
|
||||||
* Define Descartes env
|
* Define Descartes env
|
||||||
*/
|
*/
|
||||||
$http_dir_path = ''; //Path we need to put after servername in url to access app
|
$http_dir_path = '/raspisms'; //Path we need to put after servername in url to access app
|
||||||
$https = $_SERVER['HTTPS'] ?? 0;
|
$https = $_SERVER['HTTPS'] ?? 0;
|
||||||
|
|
||||||
// Check for proxy forward
|
// Check for proxy forward
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
|
|
||||||
$pwd = substr(__DIR__, 0, strrpos(__DIR__, '/'));
|
$pwd = substr(__DIR__, 0, strrpos(__DIR__, '/'));
|
||||||
|
$http_pwd = $http_protocol . $http_server_name . $http_server_port . $http_dir_path;
|
||||||
|
|
||||||
|
|
||||||
$env = [
|
$env = [
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
'HTTP_SERVER_NAME' => $http_server_name,
|
'HTTP_SERVER_NAME' => $http_server_name,
|
||||||
'HTTP_SERVER_PORT' => $http_server_port,
|
'HTTP_SERVER_PORT' => $http_server_port,
|
||||||
'PWD' => $pwd,
|
'PWD' => $pwd,
|
||||||
|
'HTTP_PWD' => $http_pwd,
|
||||||
|
|
||||||
//path of back resources
|
//path of back resources
|
||||||
'PWD_CONTROLLER' => $pwd . '/controllers', //Controllers dir
|
'PWD_CONTROLLER' => $pwd . '/controllers', //Controllers dir
|
||||||
|
@ -46,17 +48,22 @@
|
||||||
|
|
||||||
//path of front resources
|
//path of front resources
|
||||||
'PWD_ASSETS' => $pwd . '/assets', //Assets dir
|
'PWD_ASSETS' => $pwd . '/assets', //Assets dir
|
||||||
|
'HTTP_PWD_ASSETS' => $http_pwd . '/assets', //HTTP path of asset dir
|
||||||
|
|
||||||
//images
|
//images
|
||||||
'PWD_IMG' => $pwd . '/assets' . '/img',
|
'PWD_IMG' => $pwd . '/assets' . '/img',
|
||||||
|
'HTTP_PWD_IMG' => $http_pwd . '/assets' . '/img',
|
||||||
|
|
||||||
//css
|
//css
|
||||||
'PWD_CSS' => $pwd . '/assets' . '/css',
|
'PWD_CSS' => $pwd . '/assets' . '/css',
|
||||||
|
'HTTP_PWD_CSS' => $http_pwd . '/assets' . '/css',
|
||||||
|
|
||||||
//javascript
|
//javascript
|
||||||
'PWD_JS' => $pwd . '/assets' . '/js',
|
'PWD_JS' => $pwd . '/assets' . '/js',
|
||||||
|
'HTTP_PWD_JS' => $http_pwd . '/assets' . '/js',
|
||||||
|
|
||||||
//fonts
|
//fonts
|
||||||
'PWD_FONT' => $pwd . '/assets' . '/font',
|
'PWD_FONT' => $pwd . '/assets' . '/font',
|
||||||
|
'HTTP_PWD_FONT' => $http_pwd . '/assets' . '/font',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
$environment = [];
|
$environment = [];
|
||||||
$env = [];
|
$env = [];
|
||||||
|
|
||||||
// Load descartes base env
|
|
||||||
require_once(__DIR__ . '/env.php');
|
require_once(__DIR__ . '/env.php');
|
||||||
$environment = array_merge($environment, $env);
|
$environment = array_merge($environment, $env);
|
||||||
|
|
||||||
|
@ -32,8 +31,11 @@
|
||||||
$environment = array_merge($environment, $env);
|
$environment = array_merge($environment, $env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Define all Descartes constants
|
||||||
|
define_array($environment);
|
||||||
|
|
||||||
### GLOBAL ENV ###
|
### GLOBAL ENV ###
|
||||||
//Load global app env
|
$environment = [];
|
||||||
$env = [];
|
$env = [];
|
||||||
if (file_exists(__DIR__ . '/../env.php'))
|
if (file_exists(__DIR__ . '/../env.php'))
|
||||||
{
|
{
|
||||||
|
@ -41,30 +43,19 @@
|
||||||
$environment = array_merge($environment, $env);
|
$environment = array_merge($environment, $env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define_array($environment);
|
||||||
|
|
||||||
|
|
||||||
### SPECIFIC ENV ###
|
### SPECIFIC ENV ###
|
||||||
// Load specific environment env
|
$environment = [];
|
||||||
$env = [];
|
$env = [];
|
||||||
if (isset($environment['ENV']) && file_exists(__DIR__ . '/../env.' . $environment['ENV'] . '.php'))
|
|
||||||
|
if (defined('ENV') && file_exists(__DIR__ . '/../env.' . ENV . '.php'))
|
||||||
{
|
{
|
||||||
require_once(__DIR__ . '/../env.' . $environment['ENV'] . '.php');
|
require_once(__DIR__ . '/../env.' . ENV . '.php');
|
||||||
$environment = array_merge($environment, $env);
|
$environment = array_merge($environment, $env);
|
||||||
}
|
}
|
||||||
|
|
||||||
### BUILD HTTP PWD CONSTS ###
|
|
||||||
// We compute http pwd at last minute to allow for simple overriding by user
|
|
||||||
// by simply defining custom HTTP_* (PROTOCOL, SERVER_NAME, SERVER_PORT, DIR_PATH)
|
|
||||||
$http_pwd = $environment['HTTP_PROTOCOL'] . $environment['HTTP_SERVER_NAME'] . $environment['HTTP_SERVER_PORT'] . $environment['HTTP_DIR_PATH'];
|
|
||||||
$env = [
|
|
||||||
"HTTP_PWD" => $http_pwd,
|
|
||||||
'HTTP_PWD_ASSETS' => $http_pwd . '/assets', //HTTP path of asset dir
|
|
||||||
'HTTP_PWD_IMG' => $http_pwd . '/assets' . '/img',
|
|
||||||
'HTTP_PWD_CSS' => $http_pwd . '/assets' . '/css',
|
|
||||||
'HTTP_PWD_JS' => $http_pwd . '/assets' . '/js',
|
|
||||||
'HTTP_PWD_FONT' => $http_pwd . '/assets' . '/font',
|
|
||||||
];
|
|
||||||
$environment = array_merge($environment, $env);
|
|
||||||
|
|
||||||
define_array($environment);
|
define_array($environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
env.php.dist
22
env.php.dist
|
@ -2,25 +2,23 @@
|
||||||
/*
|
/*
|
||||||
This file define constants and options for the app
|
This file define constants and options for the app
|
||||||
*/
|
*/
|
||||||
$dir_path = '/raspisms';
|
|
||||||
$http_pwd = $environment['HTTP_PROTOCOL'] . $dir_path . $environment['HTTP_SERVER_PORT'] . $environment['HTTP_DIR_PATH'];
|
|
||||||
$env = [
|
$env = [
|
||||||
'ENV' => '%APP_ENV%', #env name (probably 'dev' or 'prod'), this value is used to get the env.XXX.php.dist matching env file
|
'ENV' => '%APP_ENV%', #env name (probably 'dev' or 'prod'), this value is used to get the env.XXX.php.dist matching env file
|
||||||
'SESSION_NAME' => 'raspisms',
|
'SESSION_NAME' => 'raspisms',
|
||||||
'HTTP_DIR_PATH' => $dir_path, // Override default dir path
|
|
||||||
|
|
||||||
//RaspiSMS settings
|
//RaspiSMS settings
|
||||||
'WEBSITE_TITLE' => 'RaspiSMS',
|
'WEBSITE_TITLE' => 'RaspiSMS',
|
||||||
'WEBSITE_DESCRIPTION' => '',
|
'WEBSITE_DESCRIPTION' => '',
|
||||||
'WEBSITE_AUTHOR' => 'Raspberry Pi FR',
|
'WEBSITE_AUTHOR' => 'Raspberry Pi FR',
|
||||||
'PWD_SCRIPTS' => $environment['PWD'] . '/scripts',
|
'PWD_SCRIPTS' => PWD . '/scripts',
|
||||||
'PWD_RECEIVEDS' => $environment['PWD'] . '/receiveds',
|
'PWD_RECEIVEDS' => PWD . '/receiveds',
|
||||||
'HTTP_PWD_SOUND' => $http_pwd . '/assets' . '/sounds',
|
'HTTP_PWD_SOUND' => HTTP_PWD_ASSETS . '/sounds',
|
||||||
'PWD_ADAPTERS' => $environment['PWD'] . '/adapters',
|
'PWD_ADAPTERS' => PWD . '/adapters',
|
||||||
'PWD_DATA' => $environment['PWD'] . '/data',
|
'PWD_DATA' => PWD . '/data',
|
||||||
'HTTP_PWD_DATA' => $http_pwd . '/data',
|
'HTTP_PWD_DATA' => HTTP_PWD . '/data',
|
||||||
'PWD_DATA_PUBLIC' => $environment['PWD'] . '/data/public',
|
'PWD_DATA_PUBLIC' => PWD . '/data/public',
|
||||||
'HTTP_PWD_DATA_PUBLIC' => $http_pwd . '/data/public',
|
'HTTP_PWD_DATA_PUBLIC' => HTTP_PWD . '/data/public',
|
||||||
'PWD_LOGS' => '/var/log/raspisms',
|
'PWD_LOGS' => '/var/log/raspisms',
|
||||||
'PWD_PID' => '/var/run/raspisms',
|
'PWD_PID' => '/var/run/raspisms',
|
||||||
'APP_SECRET' => '%APP_SECRET%',
|
'APP_SECRET' => '%APP_SECRET%',
|
||||||
|
@ -89,8 +87,6 @@
|
||||||
'phone_limit' => 0,
|
'phone_limit' => 0,
|
||||||
'phone_priority' => 0,
|
'phone_priority' => 0,
|
||||||
'shorten_url' => 0,
|
'shorten_url' => 0,
|
||||||
'smsstop_respond' => 1,
|
|
||||||
'smsstop_response' => 'Demande prise en compte, vous ne recevrez plus de messages.',
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@ namespace models;
|
||||||
|
|
||||||
class SmsStop extends StandardModel
|
class SmsStop extends StandardModel
|
||||||
{
|
{
|
||||||
const SMS_STOP_TAG = 'SMS_STOP';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a smsstop by his number and user.
|
* Return a smsstop by his number and user.
|
||||||
*
|
*
|
||||||
|
|
|
@ -161,16 +161,6 @@
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
else if (field.type == 'textarea')
|
|
||||||
{
|
|
||||||
html += '<div class="form-group">' +
|
|
||||||
'<label>' + field.title + '</label>' +
|
|
||||||
'<p class="italic small help">' + field.description + '</p>' +
|
|
||||||
'<div class="form-group">' +
|
|
||||||
'<textarea name="adapter_data[' + field.name + ']" class="form-control" ' + (field.required ? 'required' : '') + ' >' + (field.default_value ? field.default_value : '') + '</textarea>' +
|
|
||||||
'</div>' +
|
|
||||||
'</div>';
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
html += '<div class="form-group">' +
|
html += '<div class="form-group">' +
|
||||||
|
|
|
@ -225,16 +225,6 @@
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
else if (field.type == 'textarea')
|
|
||||||
{
|
|
||||||
html += '<div class="form-group">' +
|
|
||||||
'<label>' + field.title + '</label>' +
|
|
||||||
'<p class="italic small help">' + field.description + '</p>' +
|
|
||||||
'<div class="form-group">' +
|
|
||||||
'<textarea name="adapter_data[' + field.name + ']" class="form-control" ' + (field.required ? 'required' : '') + ' >' + (value ? value : '') + '</textarea>' +
|
|
||||||
'</div>' +
|
|
||||||
'</div>';
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
html += '' +
|
html += '' +
|
||||||
|
|
|
@ -203,47 +203,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xs-12 col-md-6">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h4 class="panel-title"><i class="fa fa-ban fa-fw"></i> Activation des réponses automatiques aux SMS-STOP</h4>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<form action="<?php echo \descartes\Router::url('Setting', 'update', ['setting_name' => 'smsstop_respond', 'csrf' => $_SESSION['csrf']]); ?>" method="POST">
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Réponses automatiques aux SMS STOP activées : </label>
|
|
||||||
<select name="setting_value" class="form-control">
|
|
||||||
<option value="0">Non</option>
|
|
||||||
<option value="1" <?php echo $_SESSION['user']['settings']['smsstop_respond'] ? 'selected' : ''; ?>>Oui</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="text-center">
|
|
||||||
<button class="btn btn-success">Mettre à jour les données</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-xs-12 col-md-6">
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h4 class="panel-title"><i class="fa fa-comments-o fa-fw"></i> Texte de réponse aux SMS-STOP</h4>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<form action="<?php echo \descartes\Router::url('Setting', 'update', ['setting_name' => 'smsstop_response', 'csrf' => $_SESSION['csrf']]); ?>" method="POST">
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Texte des réponses automatiques aux SMS-STOP : </label>
|
|
||||||
<input name="setting_value" class="form-control" value="<?php $this->s($_SESSION['user']['settings']['smsstop_response'] ?? ''); ?>" />
|
|
||||||
</div>
|
|
||||||
<div class="text-center">
|
|
||||||
<button class="btn btn-success">Mettre à jour les données</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-xs-12 col-md-6">
|
<div class="col-xs-12 col-md-6">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
|
|
Loading…
Reference in New Issue