forked from abhishekdelta/twemote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwemoteManager.php
More file actions
executable file
·88 lines (78 loc) · 1.87 KB
/
TwemoteManager.php
File metadata and controls
executable file
·88 lines (78 loc) · 1.87 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
<?php
/**
* @package Twemote
* @copyright Hackersquad (Refer README for details)
* @author Abhishek Shrivastava <i.abhi27[at]gmail.com>
* @description TwemoteManager takes the sms from the reader script, parse it, call the appropriate
* handler for the sms command and return the output to the user's mobile via the sender script.
*/
require_once(__DIR__.'/common.php');
class TwemoteManager
{
private $app;
private $sms;
private $result;
private $params;
function __construct($sms)
{
$this->sms = $sms;
}
public function run()
{
$this->parse();
$this->execute();
$this->sendsms();
}
public function parse()
{
$parts = explode(' ',$this->sms);
switch($parts[0])
{
case '#route' :
$this->app = 'TwemoteMaps';
break;
case '#stocks' :
$this->app='TwemoteStocks';
break;
case '#dictionary' :
case '#dict' :
$this->app='TwemoteDict';
break;
case '#email' :
case '#em' :
$this->app = 'TwemoteEmail';
break;
case '#browse' :
case '#br' :
$this->app = 'TwemoteBrowser';
break;
case '#cricket' :
case '#cric' :
$this->app = 'TwemoteCricket';
break;
}
array_shift($parts);
$this->params = $parts;
}
public function execute()
{
require_once(__DIR__.'/'.$this->app.'.php');
$object = new $this->app();
$object->input($this->params);
$this->result = $object->output();
//var_dump(str_replace('\n','<br/>',$this->result));
}
public function sendsms()
{
echo "Trying to send the result, which is :";
if(!file_exists(__DIR__.'/'.SENDSMS_AUTHFILE))
{
exec(PYTHONCMD." ".__DIR__."/".SENDSMS_SCRIPT." --setup ".SMS_USERNAME." ".SMS_PASSWORD);
}
$this->result = addslashes($this->result);
var_dump($this->result);
$out = array();
exec(PYTHONCMD." ".__DIR__."/".SENDSMS_SCRIPT." ".USER_MOBILE." \"".$this->result."\"",$out);
}
}
?>