-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.php
More file actions
497 lines (432 loc) · 22.9 KB
/
index.php
File metadata and controls
497 lines (432 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="Central SMS">
<meta name="author" content="Renato Siqueira">
<title>Enviar SMS</title>
</head>
<body>
<?php
/* Nome .ini Default */
$nameArquivo = 'sms.ini';
/* Lendo dongles.conf */
$lines = file ('/etc/asterisk/dongle.conf');
/* Comando Padrão Asterisk */
$command="asterisk -rx ";
//////////////////////////////////////////////////////////////////////
/** https://github.com/uzi88/PHP_INI_Read_Write */
class INI
{
/** INI file path
* @var String
*/
var $file = NULL;
/** INI data
* @var Array
*/
var $data = array();
/** Process sections
* @var Boolean
*/
var $sections = TRUE;
/** Parse INI file
* @param String $file - INI file path
* @param Boolean $sections - Process sections
*/
function INI() {
if (func_num_args()) {
$args = func_get_args();
call_user_func_array(array($this, 'read'), $args);
}
}
/** Parse INI file
* @param String $file - INI file path
* @param Boolean $sections - Process sections
*/
function read($file = NULL, $sections = TRUE) {
$this->file = ($file) ? $file : $this->file;
$this->sections = $sections;
$this->data = parse_ini_file(realpath($this->file), $this->sections);
return $this->data;
}
/** Write INI file
* @param String $file - INI file path
* @param Array $data - Data (Associative Array)
* @param Boolean $sections - Process sections
*/
function write($file = NULL, $data = array(), $sections = TRUE) {
$this->data = (!empty($data)) ? $data : $this->data;
$this->file = ($file) ? $file : $this->file;
$this->sections = $sections;
$content = NULL;
if ($this->sections) {
foreach ($this->data as $section => $data) {
$content .= '[' . $section . ']' . PHP_EOL;
foreach ($data as $key => $val) {
if (is_array($val)) {
foreach ($val as $v) {
$content .= $key . '[] = ' . (is_numeric($v) ? $v : '"' . $v . '"') . PHP_EOL;
}
} elseif (empty($val)) {
$content .= $key . ' = ' . PHP_EOL;
} else {
$content .= $key . ' = ' . (is_numeric($val) ? $val : '"' . $val . '"') . PHP_EOL;
}
}
$content .= PHP_EOL;
}
} else {
foreach ($this->data as $key => $val) {
if (is_array($val)) {
foreach ($val as $v) {
$content .= $key . '[] = ' . (is_numeric($v) ? $v : '"' . $v . '"') . PHP_EOL;
}
} elseif (empty($val)) {
$content .= $key . ' = ' . PHP_EOL;
} else {
$content .= $key . ' = ' . (is_numeric($val) ? $val : '"' . $val . '"') . PHP_EOL;
}
}
}
return (($handle = fopen($this->file, 'w')) && fwrite($handle, trim($content)) && fclose($handle)) ? TRUE : FALSE;
}
}
/* Instanciando Classe */
$ini = new INI($nameArquivo);
//////////////////////////////////////////////////////////////////////
/* SE: Criando Nova Mensagem */
$identificacaoMsg = $_POST[identificacaoMsg];
if($identificacaoMsg) {
$novaMensagem = str_replace(array("\n","\r"," "), " ", $_POST[novaMensagem]);
$ini->data['mensagens'][$identificacaoMsg] = $novaMensagem;
$ini->write();
}
/* Lendo INI file */
$smsIni = parse_ini_file($nameArquivo, true);
if(!$smsIni) {
print "Nao Existe. Criar sms.ini com permissões 777. ";
exit;
}
/* Recebendo/Tratando SMS para Enviar */
$destino = $_POST[destino];
// $mensagem = str_replace(array("\n","\r"," "), " ", $_POST[mensagem]);
$mensagem = $_POST[mensagem];
$canal = $_POST[canal];
if($destino && $mensagem && $canal){
$output = shell_exec("$command \"dongle sms $canal $destino $mensagem \" ");
}
function msgAlert($tipo, $mensagemRetorno, $destino, $mensagem) {
return '
<div class="form-group col-md-12">
<div class="alert alert-' . $tipo . '">
<h4 class="alert-heading">' . $destino . '</h4>
<p>' . $mensagem . '</p>
<hr>
<p class="mb-0"><strong>' . $mensagemRetorno . '</strong></p>
</div>
</div>
';
}
/* Retorno do Envio (resposta do modem) */
$posDisabled = strpos( $output, 'disabled' );
$posError = strpos( $output, 'error' );
$posQueued = strpos( $output, 'queued' );
if($posDisabled)
$retorno = msgAlert('warning', 'Erro:<br/> Modem Desativado/Desligado. ' . nl2br($output), $destino, $mensagem);
if($posError)
$retorno = msgAlert('warning', 'Erro:<br/> Não Foi Possível Enviar. ' . nl2br($output), $destino, $mensagem);
if($posQueued) {
$retorno = msgAlert('success', 'Mensagem encaminhada para Enviar.', $destino, $mensagem);
/* Update qtde Msg Enviadas */
$ini->data['qtdeSms'][$canal] = intval($smsIni['qtdeSms'][$canal]) + 1;
$ini->write();
}
/** Atualizando Informações. */
$smsIni = parse_ini_file($nameArquivo, true);
?>
<!-- MENU -->
<div class="cover-container d-flex w-100 h-100 p-3 mx-auto flex-column">
<header class="masthead mb-auto">
<div class="inner">
<h3 class="masthead-brand">SMS Center</h3>
<nav class="nav nav-masthead justify-content-center">
<a class="nav-link" href="#void" onclick="changeOption('individual')">Individual</a>
<!-- <a class="nav-link" href="#void" onclick="changeOption('emMassa')">Em Série</a> -->
<a class="nav-link" href="#void" onclick="changeOption('gerenciamentoMsg')">Mensagens</a>
</nav>
</div>
</header>
<!-- SMS Individual -->
<main role="main" class="inner cover" id="SMSIndividual">
<h1 class="cover-heading">Envio de SMS</h1>
<p class="lead">
<form class="form-horizontal" method="POST">
<fieldset>
<?php if($retorno) { echo $retorno; } ?>
<!-- Select Chip -->
<div class="form-group">
<label class="col-md-12 control-label" for="selectChip">Selecione o Chip</label>
<div class="col-md-12">
<select id="selectChip" name="canal" class="form-control">
<?php
foreach ($lines as $line_num => $line) {
if ( preg_match("/^\[.+\]/", $line, $matches) ) {
if ( $matches[0] != '[general]' && $matches[0] != '[defaults]' && $matches[0] != '[device]' ) {
$nomeDongle = substr($matches[0], 0, -1);
$nomeDongle = substr($nomeDongle, 1);
$qtdeSmsModem = $smsIni['qtdeSms'][$nomeDongle];
if($qtdeSmsModem) {
$qtdeSmsModem = " - " . $qtdeSmsModem . " Mensagen(s) Enviada(s)";
}
echo "<option value='" . $nomeDongle . "'>" . $nomeDongle . $qtdeSmsModem . "</option>";
}
}
}
?>
</select>
</div>
</div>
<!-- Client Number -->
<div class="form-group">
<label class="col-md-12 control-label" for="textinput">Nº Cliente?</label>
<div class="col-md-12">
<input
id="textinput" name="destino" type="number"
placeholder="91983730000" class="form-control input-md"
required title="Digite somente o DDD+Número. Sem pontuações e/ou traços."/>
<span class="help-block"><small>Preencher apenas DDD+Nº (Apenas Números)</small></span>
</div>
</div>
<!-- Message to Send -->
<div class="form-group">
<label class="col-md-12 control-label" for="textarea">Mensagem</label>
<div class="col-md-12">
<select id="selectMsg" class="form-control" onChange="changeMsgs(this.value);">
<?php
foreach($smsIni['mensagens'] as $indice => $valor)
{
echo "<option value='" . $indice . "'>" . $indice . "</option>";
}
?>
</select>
<br/>
<input class="form-control" id="TxtObservacoes" name="mensagem" value="Olá! Sua Ordem de Serviço é XXXX. Sua instalação está pré-agendado para o dia __/__/__.">
<span class="help-block"><span data-js="restantes">140</span> Restantes</span>
</div>
</div>
<!-- Send! -->
<div class="form-group">
<div class="col-md-12">
<button type="submit" class="btn btn-primary btn-lg btn-block">Enviar</button>
</div>
</div>
</fieldset>
</form>
</p>
</main>
<!-- SMS Em Massa -->
<main role="main" class="inner cover" id="SMSEmMassa" style="display: none;">
<h1 class="cover-heading">Envio de SMS em Massa</h1>
<p class="lead">
<form class="form-horizontal" method="POST">
<fieldset>
<?php if($retorno) { ?>
<div class="form-group col-md-12" style="display:none;">
<div class="alert alert-info">
<h4 class="alert-heading"><?php echo "$destino"; ?></h4>
<p><?php echo "$mensagem"; ?></p>
<hr>
<p class="mb-0"><?php echo "$retorno"; ?></p>
</div>
</div>
<?php } ?>
<!-- Select Chip -->
<div class="form-group">
<label class="col-md-12 control-label" for="selectChip">Selecione os Chips</label>
<div class="col-md-12">
<?php
foreach ($lines as $line_num => $line) {
if ( preg_match("/^\[.+\]/", $line, $matches) ) {
if ( $matches[0] != '[general]' && $matches[0] != '[defaults]' && $matches[0] != '[device]' ) {
$nomeDongle = substr($matches[0], 0, -1);
$nomeDongle = substr($nomeDongle, 1);
echo "
<div class='form-check form-check-inline'>
<input class='form-check-input' type='checkbox' value='' id='" . $nomeDongle . "'>
<label class='form-check-label' for='" . $nomeDongle . "'>
" . $nomeDongle . "
</label>
</div>
";
}
}
}
?>
</div>
</div>
<!-- Client Number -->
<div class="form-group">
<label class="col-md-12 control-label" for="textinput">Selecione o Arquivo:</label>
<div class="col-md-12">
<input type="file" name="uploadFile" id="" class="form-control-file">
<span class="help-block"><small>O Arquivo deve ter números separados por vírgula (Ex. 9430000000,92980000000)</small></span>
</div>
</div>
<!-- Message to Send -->
<div class="form-group">
<label class="col-md-12 control-label" for="textarea">Mensagem</label>
<div class="col-md-12">
<textarea class="form-control" id="TxtObservacoes1" name="mensagem" rows="5">Olá! Sua Ordem de Serviço é XXXX. Sua instalação está pré-agendado para o dia __/__/__.</textarea>
<span class="help-block"><span data-js="restantes1">140</span> Restantes</span>
</div>
</div>
<!-- Send! -->
<div class="form-group" style="display: none;">
<div class="col-md-12">
<button type="submit" class="btn btn-primary btn-lg btn-block">Enviar</button>
</div>
</div>
</fieldset>
</form>
</p>
</main>
<!-- Gerenciamento de Mensagens -->
<main role="main" class="inner cover" id="gerenciamentoMsg" style="display: none;">
<h1 class="cover-heading">Cadastrar Mensagens</h1>
<p class="lead">
<form class="form-horizontal" method="POST">
<fieldset>
<div class="form-group">
<label class="col-md-12 control-label" for="textarea">Nova Mensagem</label>
<div class="col-md-12">
<input type="text" placeholder="Mensagem de Agradecimento" name="identificacaoMsg" class="form-control" required>
</div>
<br />
<div class="col-md-12">
<textarea class="form-control" id="novaMensagem" rows="5" name="novaMensagem" placeholder="Qual mensagem deseja cadastrar?" required></textarea>
<span class="help-block"><span data-js="restantesNovaMensagem">140</span> Restantes</span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
</div>
</div>
</fieldset>
</form>
</p>
</main>
<footer class="mastfoot mt-auto">
<div class="inner">
<p>SMS Center 2018.</p>
</div>
</footer>
</div>
<?php
/* Reset */
$destino = "";
$mensagem = "";
$canal = "";
?>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style>
* { margin: 0; padding: 0; font-family:Tahoma; font-size:12pt; }
/* Body */
html, body {
height: 100%;
background-color: #333;
}
body {
display: -ms-flexbox;
display: flex;
color: #fff;
}
/* Container */
.cover-container { max-width: 42em; }
/* Header */
.masthead { margin-bottom: 2rem; }
.masthead-brand { margin-bottom: 0; }
.nav-masthead .nav-link {
padding: .25rem 0;
color: rgba(255, 255, 255, .5);
background-color: transparent;
border-bottom: .25rem solid transparent;
}
.nav-masthead .nav-link:hover,.nav-masthead .nav-link:focus { border-bottom-color: rgba(255, 255, 255, .25); }
.nav-masthead .nav-link + .nav-link { margin-left: 1rem; }
.nav-masthead .active { color: #fff; border-bottom-color: #fff; }
@media (min-width: 48em) {
.masthead-brand { float: left; }
.nav-masthead { float: right; }
}
/* Heading */
.cover-heading { text-align: center; }
/* Footer */
.mastfoot { color: rgba(255, 255, 255, .5); }
/* Remove Arrows from input:number */
input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
cursor:pointer;
display:block;
width:8px;
color: #333;
position:relative;
}
input[type=number] {
-moz-appearance: textfield;
appearance: textfield;
margin: 0;
}
</style>
<script>
function changeOption(option) {
event.preventDefault();
if(option === 'individual') {
document.getElementById('SMSIndividual').style.display = 'block';
document.getElementById('SMSEmMassa').style.display = 'none';
document.getElementById('gerenciamentoMsg').style.display = 'none';
}
if(option === 'emMassa') {
document.getElementById('SMSIndividual').style.display = 'none';
document.getElementById('SMSEmMassa').style.display = 'block';
document.getElementById('gerenciamentoMsg').style.display = 'none';
}
if(option === 'gerenciamentoMsg') {
document.getElementById('SMSIndividual').style.display = 'none';
document.getElementById('SMSEmMassa').style.display = 'none';
document.getElementById('gerenciamentoMsg').style.display = 'block';
}
}
function changeMsgs(option) {
<?php
foreach($smsIni['mensagens'] as $indice => $valor) {
echo "
if('" . $indice . "' == option) {
document.querySelector('#TxtObservacoes').value = '" . $smsIni['mensagens'][$indice] . "';
}
";
}
?>
}
(function(doc){
var limite = 140;
var $txtObservacoes = doc.querySelector("#TxtObservacoes");
var $restantes = doc.querySelector("[data-js='restantes']");
var $selectMsg = doc.querySelector("[data-js='selectMsg']");
var $novaMensagem = doc.querySelector("#novaMensagem");
var $restantesNovaMensagem = doc.querySelector("[data-js='restantesNovaMensagem']");
$txtObservacoes.addEventListener("input", function() {
var caracteresDigitados = $txtObservacoes.value.length;
$restantes.innerHTML= limite - caracteresDigitados;
}, false);
$novaMensagem.addEventListener("input", function() {
var caracteresDigitados = $novaMensagem.value.length;
$restantesNovaMensagem.innerHTML= limite - caracteresDigitados;
}, false);
})(document)
</script>
</body>
</html>