Passed
Push — master ( 0baeb0...d4017c )
by Tony
19:18 queued 08:55
created

LibreNMS/Alert/Transport/Smsfeedback.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 <http://www.gnu.org/licenses/>. */
15
16
/**
17
 * SMSEagle API Transport
18
 * @author Barry O'Donovan <[email protected]>
19
 * @copyright 2017 Barry O'Donovan, LibreNMS
20
 * @license GPL
21
 * @package LibreNMS
22
 * @subpackage Alerts
23
 */
24
namespace LibreNMS\Alert\Transport;
25
26
use LibreNMS\Alert\Transport;
27
28
class Smsfeedback extends Transport
29
{
30
    public function deliverAlert($obj, $opts)
31
    {
32
        $smsfeedback_opts['user']  = $this->config['smsfeedback-user'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$smsfeedback_opts was never initialized. Although not strictly required by PHP, it is generally a good practice to add $smsfeedback_opts = array(); before regardless.
Loading history...
33
        $smsfeedback_opts['token'] = $this->config['smsfeedback-pass'];
34
        $smsfeedback_opts['sender'] = $this->config['smsfeedback-sender'];
35
        $smsfeedback_opts['to']    = $this->config['smsfeedback-mobiles'];
36
        return $this->contactsmsfeedback($obj, $smsfeedback_opts);
37
    }
38
39
    public static function contactsmsfeedback($obj, $opts)
40
    {
41
        $params = [
42
            'login' => $opts['user'],
43
            'pass' => md5($opts['token']),
44
            'phone' => $opts['to'],
45
            'text' => $obj['title'],
46
            'sender' => $opts['sender'],
47
        ];
48
        $url    = 'http://' . $opts['user'] . ':' . $opts['token'] . '@' . 'api.smsfeedback.ru/messages/v2/send/?' . http_build_query($params);
49
        $curl   = curl_init($url);
50
51
        set_curl_proxy($curl);
52
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
53
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
54
55
        $ret = curl_exec($curl);
56
        if (substr($ret, 0, 8) == "accepted") {
57
            return true;
58
        }
59
    }
60
61
    public static function configTemplate()
62
    {
63
        return [
64
            'config' => [
65
                [
66
                    'title' => 'User',
67
                    'name' => 'smsfeedback-user',
68
                    'descr' => 'smsfeedback User',
69
                    'type' => 'text',
70
                ],
71
                [
72
                    'title' => 'Password',
73
                    'name' => 'smsfeedback-pass',
74
                    'descr' => 'smsfeedback Password',
75
                    'type' => 'text',
76
                ],
77
                [
78
                    'title' => 'Mobiles',
79
                    'name' => 'smsfeedback-mobiles',
80
                    'descr' => 'smsfeedback Mobile number',
81
                    'type' => 'textarea',
82
                ],
83
                [
84
                    'title' => 'Sender',
85
                    'name' => 'smsfeedback-sender',
86
                    'descr' => 'smsfeedback sender name',
87
                    'type' => 'textarea',
88
                ],
89
            ],
90
            'validation' => [
91
                'smsfeedback-user'    => 'required|string',
92
                'smsfeedback-pass'    => 'required|string',
93
                'smsfeedback-mobiles' => 'required',
94
                'smsfeedback-sender' => 'required|string',
95
            ]
96
        ];
97
    }
98
}
99