Merge branch 'devbyspi' into 'master'
Devices-Übersicht/DeviceApicontroller/SmsNotification See merge request fronk/thetool!56
This commit is contained in:
@@ -6,6 +6,7 @@ class DeviceApicontroller extends mfBaseApicontroller
|
||||
{
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$this->addRoute("/device/getDevices", "getDevices", "GET");
|
||||
$this->addRoute("/device/updateDevices", "updateDevices", "POST");
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +19,7 @@ class DeviceApicontroller extends mfBaseApicontroller
|
||||
$deviceReturn[$key]['ip'] = $device->ip;
|
||||
$deviceReturn[$key]['snmp_version'] = $device->snmp_version;
|
||||
$deviceReturn[$key]['serial'] = $device->serial;
|
||||
$deviceReturn[$key]['last_config_backup'] = $device->last_config_backup;
|
||||
$deviceReturn[$key]['manufactor'] = $device->devicetype->devicemanufactor->name;
|
||||
|
||||
}
|
||||
@@ -25,4 +27,40 @@ class DeviceApicontroller extends mfBaseApicontroller
|
||||
return mfResponse::Ok($deviceReturn);
|
||||
|
||||
}
|
||||
|
||||
protected function updateDevices()
|
||||
{
|
||||
$id = $this->post['id'];
|
||||
$changeArray[] = 'last_config_backup';
|
||||
if ($id) {
|
||||
$device = new Device($id);
|
||||
if (!$device->id) {
|
||||
return mfResponse::BadRequest(['message' => "Device not found"]);
|
||||
}
|
||||
$data = [];
|
||||
foreach ($this->post as $keychanges => $changes) {
|
||||
if (in_array($keychanges, $changeArray)) {
|
||||
if ($changes == "null" || empty($changes)) {
|
||||
$data[$keychanges] = NULL;
|
||||
} else {
|
||||
$data[$keychanges] = $changes;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($data)) {
|
||||
$device->update($data);
|
||||
$device->save();
|
||||
$result['message'] = 'Device update success';
|
||||
$result['updates'] = implode(",", array_keys($data));
|
||||
return mfResponse::Ok($result);
|
||||
} else {
|
||||
return mfResponse::BadRequest(['message' => "Keine Update Felder angegeben"]);
|
||||
}
|
||||
|
||||
} else {
|
||||
return mfResponse::BadRequest(['message' => "Device id nicht angegeben"]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
class SmsNotification
|
||||
{
|
||||
private $ApiKey;
|
||||
private $ApiUrl;
|
||||
private $body;
|
||||
private $recipient;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->ApiKey = TT_OUTGOING_SMS_API_KEY;
|
||||
$this->ApiUrl = TT_OUTGOING_SMS_API_URL;
|
||||
}
|
||||
|
||||
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->body = $body;
|
||||
}
|
||||
|
||||
public function setRecipient($recipient)
|
||||
{
|
||||
if (is_array($recipient)) {
|
||||
$this->recipient = implode(",", $recipient);
|
||||
} else {
|
||||
$this->recipient = $recipient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function send()
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $this->ApiUrl . '/smsmessaging/simple',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS => array('messageContent' => $this->body, 'recipientAddressList' => $this->recipient),
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Authorization: Bearer ' . $this->ApiKey
|
||||
),
|
||||
));
|
||||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
echo $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user