feature: Add Smseagle transport support (#5989)

* added alert transport for SMSEagle hardware gateway (smseagle.eu)

* added newline

* schema file update + small code refactor

* added docs
This commit is contained in:
barryodonovan
2017-02-24 11:55:53 +00:00
committed by Neil Lathwood
parent 20ae9e2ecd
commit 0f663b3a82
6 changed files with 154 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ $config_token = mres($_POST['config_token']);
$status = 'error';
$message = 'Error with config';
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocket' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell' || $action == 'remove-playsms') {
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocket' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell' || $action == 'remove-playsms' || $action == 'remove-smseagle') {
$config_id = mres($_POST['config_id']);
if (empty($config_id)) {
$message = 'No config id passed';
@@ -57,6 +57,8 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocke
dbDelete('config', "`config_name` LIKE 'alert.transports.clickatell.$config_id.%'");
} elseif ($action == 'remove-playsms') {
dbDelete('config', "`config_name` LIKE 'alert.transports.playsms.$config_id.%'");
} elseif ($action == 'remove-smseagle') {
dbDelete('config', "`config_name` LIKE 'alert.transports.smseagle.$config_id.%'");
}
$status = 'ok';
$message = 'Config item removed';
@@ -218,6 +220,33 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocke
$message = 'Could not create config item';
}
}
} elseif ($action == 'add-smseagle') {
if (empty($config_value)) {
$message = 'No SMSEagle URL provided';
} elseif (empty($config_user)) {
$message = 'No SMSEagle User provided';
} elseif (empty($config_to)) {
$message = 'No mobile numbers provided';
} else {
$config_id = dbInsert(array('config_name' => 'alert.transports.smseagle.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'SMSEagle Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.smseagle.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id));
$additional_id['user'] = dbInsert(array('config_name' => 'alert.transports.smseagle.'.$config_id.'.user', 'config_value' => $config_user, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_user, 'config_descr' => 'SMSEagle User'), 'config');
$additional_id['token'] = dbInsert(array('config_name' => 'alert.transports.smseagle.'.$config_id.'.token', 'config_value' => $config_token, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_token, 'config_descr' => 'SMSEagle Token'), 'config');
$status = 'ok';
$message = 'Config item created';
$mobiles = explode('\n', $config_to);
$x=0;
foreach ($mobiles as $mobile) {
if (!empty($mobile)) {
dbInsert(array('config_name' => 'alert.transports.smseagle.'.$config_id.'.to.'.$x, 'config_value' => $mobile, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'SMSEagle mobile'), 'config');
$x++;
}
}
} else {
$message = 'Could not create config item';
}
}
} else {
if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) {
$message = 'Missing config name or value';

View File

@@ -47,6 +47,9 @@ if (!is_numeric($config_id)) {
} elseif ($config_type == 'playsms') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.playsms.to.'.$x, 'config_value' => $k, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'PlaySMS Transport'), 'config');
$x++;
} elseif ($config_type == 'smseagle') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.smseagle.to.'.$x, 'config_value' => $k, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'SMSEagle Transport'), 'config');
$x++;
}
}
}
@@ -71,6 +74,8 @@ if (!is_numeric($config_id)) {
dbDelete('config', "(`config_name` LIKE 'alert.transports.clickatell.to.%' AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'playsms') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.playsms.to.%' AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'smseagle') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.smseagle.to.%' AND `config_id` NOT IN ($db_inserts))");
}
}