Upgrade LBCAlerte to version 3.3

Add upgrade script
This commit is contained in:
Jimmy Monin
2016-11-26 19:19:16 +01:00
parent a7c054b535
commit 58ffd500e6
89 changed files with 6436 additions and 758 deletions

View File

@ -0,0 +1,33 @@
<?php
if (empty($_GET["s"])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
switch ($_GET["s"]) {
case "sms-free-mobile":
$key = "freeMobile";
break;
case "sms-ovh":
$key = "ovh";
break;
default:
$key = $_GET["s"];
}
$notifications = $userAuthed->getOption("notification");
if (!isset($notifications[$key])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
$notifications[$key]["active"] = false;
$userAuthed->mergeOptions(array(
"notification" => $notifications
));
$userStorage->save($userAuthed);
header("LOCATION: ./?mod=user&a=settings");
exit;

View File

@ -0,0 +1,66 @@
<?php
$form_values = array(
"user" => "",
"key" => "",
);
$data_user = $userAuthed->getOption("notification.freeMobile");
if ($data_user && is_array($data_user)) {
$form_values = array_merge($form_values, $data_user);
}
$errors = array();
$errorsTest = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["cancel-config"])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
if (!empty($_POST["delete-config"])) {
$userAuthed->mergeOptions(array(
"notification" => array(
"freeMobile" => false,
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
$form_values = array_intersect_key($_POST, $form_values);
// Validation des champs
foreach ($form_values AS $name => $value) {
if (empty($value)) {
$errors[$name] = "Ce champ doit être renseigné.";
}
}
if (empty($errors)) {
if (!empty($_POST["test-config"])) {
$sms = \Message\AdapterFactory::factory("freeMobile", $form_values);
try {
$sms->send("La notification SMS est fonctionnelle.");
} catch (Exception $e) {
$errorsTest = "Erreur lors de l'envoi du SMS : (".$e->getCode().") ".$e->getMessage();
}
} else {
$userAuthed->mergeOptions(array(
"notification" => array(
"freeMobile" => array(
"user" => $form_values["user"],
"key" => $form_values["key"],
"active" => true,
),
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
}
}

View File

@ -0,0 +1,67 @@
<?php
$form_values = array(
"device_ids" => "group.all",
"token" => "",
);
$data_user = $userAuthed->getOption("notification.joaoappsjoin");
if ($data_user && is_array($data_user)) {
$form_values = array_merge($form_values, $data_user);
}
$errors = array();
$errorsTest = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["cancel-config"])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
if (!empty($_POST["delete-config"])) {
$userAuthed->mergeOptions(array(
"notification" => array(
"joaoappsjoin" => false,
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
$form_values = array_intersect_key($_POST, $form_values);
// Validation des champs
foreach ($form_values AS $name => $value) {
if (empty($value)) {
$errors[$name] = "Ce champ doit être renseigné.";
}
}
if (empty($errors)) {
if (!empty($_POST["test-config"])) {
$sender = \Message\AdapterFactory::factory("joaoappsjoin", $form_values);
try {
$sender->send("La notification Joaoapps / Join est fonctionnelle");
} catch (Exception $e) {
$errorsTest = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
} else {
$userAuthed->mergeOptions(array(
"notification" => array(
"joaoappsjoin" => array(
"device_ids" => $form_values["device_ids"],
"token" => $form_values["token"],
"active" => true,
),
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
}
}

View File

@ -0,0 +1,67 @@
<?php
$form_values = array(
"token" => "",
);
$data_user = $userAuthed->getOption("notification.notifymyandroid");
if ($data_user && is_array($data_user)) {
$form_values = array_merge($form_values, $data_user);
}
$errors = array();
$errorsTest = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["cancel-config"])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
if (!empty($_POST["delete-config"])) {
$userAuthed->mergeOptions(array(
"notification" => array(
"notifymyandroid" => false,
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
$form_values = array_intersect_key($_POST, $form_values);
// Validation des champs
foreach ($form_values AS $name => $value) {
if (empty($value)) {
$errors[$name] = "Ce champ doit être renseigné.";
}
}
if (empty($errors)) {
if (!empty($_POST["test-config"])) {
$sender = \Message\AdapterFactory::factory("notifymyandroid", $form_values);
try {
$sender->send("La notification NotifyMyAndroid est fonctionnelle", array(
"title" => "Test alerte"
));
} catch (Exception $e) {
$errorsTest = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
} else {
$userAuthed->mergeOptions(array(
"notification" => array(
"notifymyandroid" => array(
"token" => $form_values["token"],
"active" => true,
),
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
}
}

View File

@ -0,0 +1,73 @@
<?php
$form_values = array(
"account" => "",
"login" => "",
"password" => "",
"from" => "",
"to" => "",
);
$data_user = $userAuthed->getOption("notification.ovh");
if ($data_user && is_array($data_user)) {
$form_values = array_merge($form_values, $data_user);
}
$errors = array();
$errorsTest = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["cancel-config"])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
if (!empty($_POST["delete-config"])) {
$userAuthed->mergeOptions(array(
"notification" => array(
"ovh" => false,
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
$form_values = array_intersect_key($_POST, $form_values);
// Validation des champs
foreach ($form_values AS $name => $value) {
if (empty($value)) {
$errors[$name] = "Ce champ doit être renseigné.";
}
}
if (empty($errors)) {
if (!empty($_POST["test-config"])) {
$sender = \Message\AdapterFactory::factory("SmsOvh", $form_values);
try {
$sender->send("La notification SMS est fonctionnelle.");
} catch (Exception $e) {
$errorsTest = "Erreur lors de l'envoi du SMS : (".$e->getCode().") ".$e->getMessage();
}
} else {
$userAuthed->mergeOptions(array(
"notification" => array(
"ovh" => array(
"account" => $form_values["account"],
"login" => $form_values["login"],
"password" => $form_values["password"],
"from" => $form_values["from"],
"to" => $form_values["to"],
"active" => true,
),
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
}
}

View File

@ -0,0 +1,65 @@
<?php
$form_values = array(
"token" => "",
);
$data_user = $userAuthed->getOption("notification.pushbullet");
if ($data_user && is_array($data_user)) {
$form_values = array_merge($form_values, $data_user);
}
$errors = array();
$errorsTest = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["cancel-config"])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
if (!empty($_POST["delete-config"])) {
$userAuthed->mergeOptions(array(
"notification" => array(
"pushbullet" => false,
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
$form_values = array_intersect_key($_POST, $form_values);
// Validation des champs
foreach ($form_values AS $name => $value) {
if (empty($value)) {
$errors[$name] = "Ce champ doit être renseigné.";
}
}
if (empty($errors)) {
if (!empty($_POST["test-config"])) {
$sender = \Message\AdapterFactory::factory("pushbullet", $form_values);
try {
$sender->send("La notification Pushbullet est fonctionnelle");
} catch (Exception $e) {
$errorsTest = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
} else {
$userAuthed->mergeOptions(array(
"notification" => array(
"pushbullet" => array(
"token" => $form_values["token"],
"active" => true,
),
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
}
}

View File

@ -0,0 +1,67 @@
<?php
$form_values = array(
"token" => "",
"user_key" => "",
);
$data_user = $userAuthed->getOption("notification.pushover");
if ($data_user && is_array($data_user)) {
$form_values = array_merge($form_values, $data_user);
}
$errors = array();
$errorsTest = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["cancel-config"])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
if (!empty($_POST["delete-config"])) {
$userAuthed->mergeOptions(array(
"notification" => array(
"pushover" => false,
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
$form_values = array_intersect_key($_POST, $form_values);
// Validation des champs
foreach ($form_values AS $name => $value) {
if (empty($value)) {
$errors[$name] = "Ce champ doit être renseigné.";
}
}
if (empty($errors)) {
if (!empty($_POST["test-config"])) {
$sender = \Message\AdapterFactory::factory("pushover", $form_values);
try {
$sender->send("La notification Pushover est fonctionnelle");
} catch (Exception $e) {
$errorsTest = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
} else {
$userAuthed->mergeOptions(array(
"notification" => array(
"pushover" => array(
"token" => $form_values["token"],
"user_key" => $form_values["user_key"],
"active" => true,
),
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
}
}

View File

@ -0,0 +1,65 @@
<?php
$form_values = array(
"hookurl" => "",
);
$data_user = $userAuthed->getOption("notification.slack");
if ($data_user && is_array($data_user)) {
$form_values = array_merge($form_values, $data_user);
}
$errors = array();
$errorsTest = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["cancel-config"])) {
header("LOCATION: ./?mod=user&a=settings");
exit;
}
if (!empty($_POST["delete-config"])) {
$userAuthed->mergeOptions(array(
"notification" => array(
"slack" => false,
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
$form_values = array_intersect_key($_POST, $form_values);
// Validation des champs
foreach ($form_values AS $name => $value) {
if (empty($value)) {
$errors[$name] = "Ce champ doit être renseigné.";
}
}
if (empty($errors)) {
if (!empty($_POST["test-config"])) {
$sender = \Message\AdapterFactory::factory("slack", $form_values);
try {
$sender->send("La notification Slack est fonctionnelle");
} catch (Exception $e) {
$errorsTest = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
} else {
$userAuthed->mergeOptions(array(
"notification" => array(
"slack" => array(
"hookurl" => trim($form_values["hookurl"]),
"active" => true,
),
),
));
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings");
exit;
}
}
}

View File

@ -1,122 +1,49 @@
<?php
if (!$userAuthed->getApiKey()) {
$userAuthed->setApiKey(
sha1(
str_repeat(
uniqid($_SERVER["HTTP_HOST"], true),
rand(10, 100)
)
)
);
$userStorage->save($userAuthed);
}
$params = array(
"notification" => $userAuthed->getOption("notification"),
"unique_ads" => $userAuthed->getOption("unique_ads", false)
"unique_ads" => $userAuthed->getOption("unique_ads", false),
"api_key" => $userAuthed->getApiKey(),
"addresses_mails" => $userAuthed->getOption("addresses_mails"),
);
if (!is_array($params["notification"])) {
$params["notification"] = array();
}
$form_values["notification"] = array_replace_recursive(array(
"freeMobile" => array(
"user" => "",
"key" => "",
),
"notifymyandroid" => array(
"token" => "",
),
"pushbullet" => array(
"token" => "",
),
"ovh" => array(
"account" => "",
"login" => "",
"password" => "",
"from" => "",
"to" => "",
),
"pushover" => array(
"token" => "",
"user_key" => "",
),
), $params["notification"]);
$errors = array();
$errorsTest = array();
require DOCUMENT_ROOT."/app/data/notifications.php";
$form_values = array(
"api_key" => $params["api_key"],
"unique_ads" => $params["unique_ads"],
"addresses_mails" => $params["addresses_mails"],
);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$params = array_merge($params, $_POST);
$form_values = array_intersect_key($_POST, $form_values);
// test config Free Mobile
foreach ($params["notification"] AS $section => $options) {
if (is_array($options)) {
$hasValue = false;
foreach ($options AS $name => $value) {
if (empty($value)) {
$errors["notification"][$section][$name] = "Ce champ doit être renseigné.";
} else {
$hasValue = true;
}
}
if (!$hasValue) {
unset($errors["notification"][$section]);
$params["notification"][$section] = false;
}
}
}
if (empty($errors["notification"])) {
unset($errors["notification"]);
}
if (empty($errors)) {
if (!empty($_POST["testFreeMobile"])) {
$sms = \Message\AdapterFactory::factory("freeMobile", $params["notification"]["freeMobile"]);
try {
$sms->send("La notification SMS est fonctionnelle.");
} catch (Exception $e) {
$errorsTest["freeMobile"] = "Erreur lors de l'envoi du SMS : (".$e->getCode().") ".$e->getMessage();
}
} elseif (!empty($_POST["testPushbullet"])) {
if (empty($_POST["notification"]["pushbullet"]["token"])) {
$errors["notification"]["pushbullet"]["token"] = "Veuillez renseigner la clé d'identification. ";
} else {
$sender = \Message\AdapterFactory::factory("pushbullet", $_POST["notification"]["pushbullet"]);
try {
$sender->send("La notification Pushbullet est fonctionnelle");
} catch (Exception $e) {
$errorsTest["pushbullet"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
}
} elseif (!empty($_POST["testOvh"])) {
$sender = \Message\AdapterFactory::factory("SmsOvh", $params["notification"]["ovh"]);
try {
$sender->send("La notification SMS est fonctionnelle.");
} catch (Exception $e) {
$errorsTest["ovh"] = "Erreur lors de l'envoi du SMS : (".$e->getCode().") ".$e->getMessage();
}
} elseif (!empty($_POST["testNotifyMyAndroid"])) {
if (empty($_POST["notification"]["notifymyandroid"]["token"])) {
$errors["notification"]["notifymyandroid"]["token"] = "Veuillez renseigner la clé d'identification.";
} else {
$sender = \Message\AdapterFactory::factory("notifymyandroid", $_POST["notification"]["notifymyandroid"]);
try {
$sender->send("La notification NotifyMyAndroid est fonctionnelle", array(
"title" => "Test alerte"
));
} catch (Exception $e) {
$errorsTest["notifymyandroid"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
}
} elseif (!empty($_POST["testPushover"])) {
if (empty($_POST["notification"]["pushover"]["token"])) {
$errors["notification"]["pushover"]["token"] = "Veuillez renseigner la clé application.";
} elseif (empty($_POST["notification"]["pushover"]["user_key"])) {
$errors["notification"]["pushover"]["user_key"] = "Veuillez renseigner la clé utilisateur.";
} else {
$sender = \Message\AdapterFactory::factory("pushover", $_POST["notification"]["pushover"]);
try {
$sender->send("La notification Pushover est fonctionnelle");
} catch (Exception $e) {
$errorsTest["pushover"] = "Erreur lors de l'envoi de la notification : (".$e->getCode().") ".$e->getMessage();
}
}
} else {
$userAuthed->mergeOptions($params);
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings"); exit;
}
if (!empty($_POST["regenerate-apikey"])) {
$userAuthed->setApiKey(
sha1(
str_repeat(
uniqid($_SERVER["HTTP_HOST"], true),
rand(10, 100)
)
)
);
}
$userAuthed->mergeOptions($form_values);
$userStorage->save($userAuthed);
$_SESSION["userSettingsSaved"] = true;
header("LOCATION: ./?mod=user&a=settings"); exit;
}
$userSettingsSaved = isset($_SESSION["userSettingsSaved"]) && true === $_SESSION["userSettingsSaved"];