Issues (2963)

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 <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 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
37
        return $this->contactsmsfeedback($obj, $smsfeedback_opts);
38
    }
39
40
    public static function contactsmsfeedback($obj, $opts)
41
    {
42
        $params = [
43
            'login' => $opts['user'],
44
            'pass' => md5($opts['token']),
45
            'phone' => $opts['to'],
46
            'text' => $obj['title'],
47
            'sender' => $opts['sender'],
48
        ];
49
        $url = 'http://' . $opts['user'] . ':' . $opts['token'] . '@' . 'api.smsfeedback.ru/messages/v2/send/?' . http_build_query($params);
50
        $curl = curl_init($url);
51
52
        set_curl_proxy($curl);
53
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
54
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
55
56
        $ret = curl_exec($curl);
57
        if (substr($ret, 0, 8) == 'accepted') {
58
            return true;
59
        }
60
    }
61
62
    public static function configTemplate()
63
    {
64
        return [
65
            'config' => [
66
                [
67
                    'title' => 'User',
68
                    'name' => 'smsfeedback-user',
69
                    'descr' => 'smsfeedback User',
70
                    'type' => 'text',
71
                ],
72
                [
73
                    'title' => 'Password',
74
                    'name' => 'smsfeedback-pass',
75
                    'descr' => 'smsfeedback Password',
76
                    'type' => 'text',
77
                ],
78
                [
79
                    'title' => 'Mobiles',
80
                    'name' => 'smsfeedback-mobiles',
81
                    'descr' => 'smsfeedback Mobile number',
82
                    'type' => 'textarea',
83
                ],
84
                [
85
                    'title' => 'Sender',
86
                    'name' => 'smsfeedback-sender',
87
                    'descr' => 'smsfeedback sender name',
88
                    'type' => 'textarea',
89
                ],
90
            ],
91
            'validation' => [
92
                'smsfeedback-user'    => 'required|string',
93
                'smsfeedback-pass'    => 'required|string',
94
                'smsfeedback-mobiles' => 'required',
95
                'smsfeedback-sender' => 'required|string',
96
            ],
97
        ];
98
    }
99
}
100