-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsend.php
37 lines (30 loc) · 1.18 KB
/
send.php
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
<?php
$log = date('Y-m-d H:i:s') . PHP_EOL;
$file = 'data/sms.log';
if (php_sapi_name() == "cli") {
if (!$argv[1] || !$argv[2]) exit("[ERR] Usage: php send.php <phone number> \"<text>\"\n");
$text = $argv[2];
$rec = filter_var($argv[1], FILTER_SANITIZE_NUMBER_INT);
} else {
$text = trim($_REQUEST['text']);
$rec = filter_var($_REQUEST['phone'], FILTER_SANITIZE_NUMBER_INT);
if(!$text && !$rec)
{
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE); //convert JSON into array
$text = $input['text'];
$rec = filter_var($input['phone'], FILTER_SANITIZE_NUMBER_INT);
}
if (!$text || !$rec)
exit(json_encode(['status' => 'err', 'reason' => 'Phone number and text required']));
}
ob_start();
$cmd = sprintf('gammu-smsd-inject TEXT %s -unicode -len '.(strlen($text)+1).' -text %s', $rec, escapeshellarg($text));
$log .= $cmd . PHP_EOL;
$log .= shell_exec($cmd) . PHP_EOL . PHP_EOL;
file_put_contents($file, $log, FILE_APPEND | LOCK_EX);
echo $log;
$cont= ob_get_contents();
ob_end_clean();
header('Content-Type: application/json; charset=utf-8');
exit(json_encode(['status' => 'ok', 'log' => $log]));