1 | <?php |
||
2 | /* Copyright (C) 2015 Daniel Preussker <[email protected]> |
||
3 | * This program is free software: you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation, either version 3 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
||
15 | |||
16 | /** |
||
17 | * SMSEagle API Transport |
||
18 | * |
||
19 | * @author Barry O'Donovan <[email protected]> |
||
20 | * @copyright 2017 Barry O'Donovan, LibreNMS |
||
21 | * @license GPL |
||
22 | */ |
||
23 | |||
24 | namespace LibreNMS\Alert\Transport; |
||
25 | |||
26 | use Illuminate\Support\Str; |
||
27 | use LibreNMS\Alert\Transport; |
||
28 | |||
29 | class Smseagle extends Transport |
||
30 | { |
||
31 | public function deliverAlert($obj, $opts) |
||
32 | { |
||
33 | $smseagle_opts['url'] = $this->config['smseagle-url']; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
34 | $smseagle_opts['user'] = $this->config['smseagle-user']; |
||
35 | $smseagle_opts['token'] = $this->config['smseagle-pass']; |
||
36 | $smseagle_opts['to'] = preg_split('/([,\r\n]+)/', $this->config['smseagle-mobiles']); |
||
37 | |||
38 | return $this->contactSmseagle($obj, $smseagle_opts); |
||
39 | } |
||
40 | |||
41 | public static function contactSmseagle($obj, $opts) |
||
42 | { |
||
43 | $params = [ |
||
44 | 'login' => $opts['user'], |
||
45 | 'pass' => $opts['token'], |
||
46 | 'to' => implode(',', $opts['to']), |
||
47 | 'message' => $obj['title'], |
||
48 | ]; |
||
49 | $url = Str::startsWith($opts['url'], 'http') ? '' : 'http://'; |
||
50 | $url .= $opts['url'] . '/index.php/http_api/send_sms?' . http_build_query($params); |
||
51 | $curl = curl_init($url); |
||
52 | |||
53 | set_curl_proxy($curl); |
||
54 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); |
||
55 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
56 | |||
57 | $ret = curl_exec($curl); |
||
58 | if (substr($ret, 0, 2) == 'OK') { |
||
59 | return true; |
||
60 | } else { |
||
61 | return false; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | public static function configTemplate() |
||
66 | { |
||
67 | return [ |
||
68 | 'config' => [ |
||
69 | [ |
||
70 | 'title' => 'SMSEagle Base URL', |
||
71 | 'name' => 'smseagle-url', |
||
72 | 'descr' => 'SMSEagle Host', |
||
73 | 'type' => 'text', |
||
74 | ], |
||
75 | [ |
||
76 | 'title' => 'User', |
||
77 | 'name' => 'smseagle-user', |
||
78 | 'descr' => 'SMSEagle User', |
||
79 | 'type' => 'text', |
||
80 | ], |
||
81 | [ |
||
82 | 'title' => 'Password', |
||
83 | 'name' => 'smseagle-pass', |
||
84 | 'descr' => 'SMSEagle Password', |
||
85 | 'type' => 'text', |
||
86 | ], |
||
87 | [ |
||
88 | 'title' => 'Mobiles', |
||
89 | 'name' => 'smseagle-mobiles', |
||
90 | 'descr' => 'SMSEagle Mobiles, can be new line or comma separated', |
||
91 | 'type' => 'textarea', |
||
92 | ], |
||
93 | ], |
||
94 | 'validation' => [ |
||
95 | 'smseagle-url' => 'required|url', |
||
96 | 'smseagle-user' => 'required|string', |
||
97 | 'smseagle-pass' => 'required|string', |
||
98 | 'smseagle-mobiles' => 'required', |
||
99 | ], |
||
100 | ]; |
||
101 | } |
||
102 | } |
||
103 |