-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
236 lines (169 loc) · 5.54 KB
/
function.php
File metadata and controls
236 lines (169 loc) · 5.54 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
<?php
$office_server="140.118.34.204";
$db_host = "127.0.0.1";
$db_user = ""; // this will overwrite by function_secret.php
$db_pass = "";// this will overwrite by function_secret.php
$db_name = "";// this will overwrite by function_secret.php
$appId="";// this will overwrite by function_secret.php
$secret="";// this will overwrite by function_secret.php
include(dirname(__FILE__)."/function_secret.php")
$dorm=1; //1=only dorm , 2=all 118
$crlf = '
';
$test="";//"test".ntust-bomb.org or null
if (!empty($_SERVER['HTTP_CLIENT_IP']))
$ip=$_SERVER['HTTP_CLIENT_IP'];
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
else if (!empty($_SERVER['REMOTE_ADDR']))
$ip=$_SERVER['REMOTE_ADDR'];
//讓自己得到118ip
//$ip="140.118.232.171";
//讓自己得到118ip
include(dirname(__FILE__)."/converter.class.php");
include(dirname(__FILE__)."/NexmoMessage.php");
function fbid_to_uid($fbid){
global $db_host, $db_name, $db_user, $db_pass;
$Wormdb = @mysql_connect($db_host, $db_user, $db_pass) or die ('錯誤:數據庫連接失敗');
mysql_select_db ($db_name);
$fbid=mysql_real_escape_string($fbid);
$result = mysql_query("SELECT `uid` from `account` WHERE fbid='".$fbid."' ORDER BY `uid` DESC LIMIT 1");
$uid='';
while($row = mysql_fetch_array($result))
{
$uid=$row['uid'];
}
if($uid==''){
return 0;
}else{
return $uid;
}
}
function log_do ($uid=0 , $log , $kind){
global $db_host, $db_name, $db_user, $db_pass;
$Wormdb = @mysql_connect($db_host, $db_user, $db_pass) or die ('錯誤:數據庫連接失敗');
mysql_select_db ($db_name);
$log=mysql_real_escape_string($log);
$d = mysql_query('INSERT INTO `log` (`time`,`uid`,`log`,`kind`)VALUES ("'.date('U').'","'.$uid.'","'.$log.'","'.$kind.'")');
}
function nexmo_conv( $string )
{
$conv = new converter;
$string = $conv->convert('UTF','BIG', $string);
$string = $conv->convert('BIG','GB', $string);
$string = iconv('GBK', 'UTF-8//IGNORE', $string);
$string = urlencode($string);
return $string;
}
function sendvoice($to , $text , $uid=0){
$to=phone_regex($to);
$text=nexmo_conv($text);
$url="https://rest.nexmo.com/tts/json?api_key=641a3794&api_secret=cba9477f&to=".$to."&text=".$text."&lg=zh-cn";
$log=print_r(file_get_contents($url),true);
log_do($uid,print_r($log,true),"call");
return ($log);
}
//return object
function sendmessage($to , $text , $uid=0){
$nexmo_sms = new NexmoMessage('641a3794' ,'cba9477f');
$to=phone_regex($to);
$log= $nexmo_sms->sendText( $to ,"ntustbomb" ,$text );
log_do($uid,print_r($log,true),"sms");
return print_r($log,true);
}
function phone_regex($to){
if(preg_match("/0([0-9]{9})/", $to, $matches)){
$to="+886".$matches[1];
}
if(preg_match("/(\+886[0-9]{9})/", $to, $matches)){
$to=$matches[1];
}
if(preg_match("/^([0-9]{9})/", $to, $matches)){
$to="+886".$matches[1];
}
return $to;
}
function Check118($ip){
$value=(int) preg_match("/140.118.[0-9]{1,3}[.][0-9]{1,3}/",$ip);
return $value;
}
function Check118dorm($ip){
global $office_server;
//----------cheat----------
if($office_server==$ip){
$value=(int) preg_match("/[dD]([1-4])-([0-9]{4})-([1-6]).dorm.ntust.edu.tw/", gethostbyaddr("140.118.232.171"));
return $value;
}else{
$value=(int) preg_match("/[dD]([1-4])-([0-9]{4})-([1-6]).dorm.ntust.edu.tw/", gethostbyaddr($ip));
return $value;
}
//----------cheat----------
}
function GetDormStr($ip){ //第X宿舍X房X床
global $office_server;
//----------cheat----------
if($office_server==$ip){
preg_match("/[dD]([1-4])-([0-9]{4})-([1-6]).dorm.ntust.edu.tw/", gethostbyaddr("140.118.232.171"), $matches);
return "第".$matches[1]."宿舍".$matches[2]."房".$matches[3]."床\n";
}else{
if((int)Check118dorm($ip)==0){
return 0;
}else{
preg_match("/[dD]([1-4])-([0-9]{4})-([1-6]).dorm.ntust.edu.tw/", gethostbyaddr($ip), $matches);
if($matches[1]==4){$matches[1]=3;}
return "第".$matches[1]."宿舍".$matches[2]."房".$matches[3]."床\n";
}
}
}
function Getflow($ip){
//大招
//return 1000;
if($ip=="140.118.238.186"){
//return 4666;
}
global $office_server;
if(!Check118($ip)){
return 0;
}else{
$flow=file_get_contents("http://".$office_server."/getflow.php?ip=".$ip);
return $flow;
}
}
function Getflow_toDB($ip){
global $db_host, $db_name, $db_user, $db_pass;
$Wormdb = @mysql_connect($db_host, $db_user, $db_pass) or die ('錯誤:數據庫連接失敗');
mysql_select_db ($db_name);
$flow=Getflow($ip);
$a=mysql_query("UPDATE `dormiptable` SET `flow`='".$flow."',time='".@date('U')."' where `ip`='".$ip."'");
return $flow;
}
//input ip array , output flow array
function Getflow_many($iparray){
$getdata="";
while(count($iparray)>1){
$getdata.=array_pop($iparray).",";
}
if(count($iparray)==1){
$getdata.=array_pop($iparray);
}
$flow=file_get_contents("http://".$office_server."/getflow.php?ip=".$getdata);
$flow=json_decode($flow);
return $flow;
}
function getAddrByHost($host, $timeout = 5) {
$returnString = '';
$query = `nslookup -timeout=$timeout -retry=1 $host`;
if (preg_match('/\nAddress: (.*)\n/', $query, $matches)){
$returnString = trim($matches[1]);
}
return $returnString;
}
function get2digit($num){
if($num<10){
return '0'.$num;
}else{
return $num;
}
}
//echo getAddrByHost("D1-0117-1.dorm.ntust.edu.tw");
?>