Issues (2963)

LibreNMS/Alert/Transport/Clickatell.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
 * Clickatell REST-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 Clickatell extends Transport
29
{
30
    public function deliverAlert($obj, $opts)
31
    {
32
        $clickatell_opts['token'] = $this->config['clickatell-token'];
33
        $clickatell_opts['to'] = preg_split('/([,\r\n]+)/', $this->config['clickatell-numbers']);
34
35
        return $this->contactClickatell($obj, $clickatell_opts);
36
    }
37
38
    public static function contactClickatell($obj, $opts)
39
    {
40
        $url = 'https://platform.clickatell.com/messages/http/send?apiKey=' . $opts['token'] . '&to=' . implode(',', $opts['to']) . '&content=' . urlencode($obj['title']);
41
42
        $curl = curl_init($url);
43
        set_curl_proxy($curl);
44
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
45
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
46
47
        $ret = curl_exec($curl);
48
        $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
49
        if ($code > 200) {
50
            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...
51
52
            return;
53
        }
54
55
        return true;
56
    }
57
58
    public static function configTemplate()
59
    {
60
        return [
61
            'config' => [
62
                [
63
                    'title' => 'Token',
64
                    'name'  => 'clickatell-token',
65
                    'descr' => 'Clickatell Token',
66
                    'type'  => 'text',
67
                ],
68
                [
69
                    'title' => 'Mobile Numbers',
70
                    'name'  => 'clickatell-numbers',
71
                    'descr' => 'Enter mobile numbers, can be new line or comma separated',
72
                    'type'  => 'textarea',
73
                ],
74
            ],
75
            'validation' => [
76
                'clickatell-token'   => 'required|string',
77
                'clickatell-numbers' => 'required|string',
78
            ],
79
        ];
80
    }
81
}
82