Issues (2963)

LibreNMS/Alert/Transport/Playsms.php (1 issue)

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
 * PlaySMS API Transport
18
 *
19
 * @author f0o <[email protected]>
20
 * @copyright 2015 f0o, LibreNMS
21
 * @license GPL
22
 */
23
24
namespace LibreNMS\Alert\Transport;
25
26
use LibreNMS\Alert\Transport;
27
28
class Playsms extends Transport
29
{
30
    public function deliverAlert($obj, $opts)
31
    {
32
        $playsms_opts['url'] = $this->config['playsms-url'];
33
        $playsms_opts['user'] = $this->config['playsms-user'];
34
        $playsms_opts['token'] = $this->config['playsms-token'];
35
        $playsms_opts['from'] = $this->config['playsms-from'];
36
        $playsms_opts['to'] = preg_split('/([,\r\n]+)/', $this->config['playsms-mobiles']);
37
38
        return $this->contactPlaysms($obj, $playsms_opts);
39
    }
40
41
    public static function contactPlaysms($obj, $opts)
42
    {
43
        $data = ['u' => $opts['user'], 'h' => $opts['token'], 'to' => implode(',', $opts['to']), 'msg' => $obj['title']];
44
        if (! empty($opts['from'])) {
45
            $data['from'] = $opts['from'];
46
        }
47
        $url = $opts['url'] . '&op=pv&' . http_build_query($data);
48
        $curl = curl_init($url);
49
50
        set_curl_proxy($curl);
51
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
52
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
53
54
        $ret = curl_exec($curl);
55
        $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
56
        if ($code > 202) {
57
            var_dump($ret);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($ret) looks like debug code. Are you sure you do not want to remove it?
Loading history...
58
59
            return;
60
        }
61
62
        return true;
63
    }
64
65
    public static function configTemplate()
66
    {
67
        return [
68
            'config' => [
69
                [
70
                    'title' => 'PlaySMS URL',
71
                    'name' => 'playsms-url',
72
                    'descr' => 'PlaySMS URL',
73
                    'type' => 'text',
74
                ],
75
                [
76
                    'title' => 'User',
77
                    'name' => 'playsms-user',
78
                    'descr' => 'PlaySMS User',
79
                    'type' => 'text',
80
                ],
81
                [
82
                    'title' => 'Token',
83
                    'name' => 'playsms-token',
84
                    'descr' => 'PlaySMS Token',
85
                    'type' => 'text',
86
                ],
87
                [
88
                    'title' => 'From',
89
                    'name' => 'playsms-from',
90
                    'descr' => 'PlaySMS From',
91
                    'type' => 'text',
92
                ],
93
                [
94
                    'title' => 'Mobiles',
95
                    'name' => 'playsms-mobiles',
96
                    'descr' => 'PlaySMS Mobiles, can be new line or comma separated',
97
                    'type' => 'textarea',
98
                ],
99
            ],
100
            'validation' => [
101
                'playsms-url'     => 'required|url',
102
                'playsms-user'    => 'required|string',
103
                'playsms-token'   => 'required|string',
104
                'playsms-mobiles' => 'required',
105
            ],
106
        ];
107
    }
108
}
109