-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
369 lines (324 loc) · 12.3 KB
/
index.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
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
<?
session_start();
require("lib.php");
require("api.php");
header("Content-Type: application/json");
//Server API
$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'POST':
switch ($_POST['command']) {
/* To facilitate the activity log and bugs, it is desirable to be inserted at the end
* of the new features and is assigned a unique identifier functions, consistent with
* the registered database.
* Is very important that you do not modify the identifiers lightly.
* -----------------------------------------------------------------------
* para facilitar el registro de actividad y bugs, es conveniente que se inserten
* al final las nuevas funciones y se le asigne un identificador unico de funcion,
* que concuerde con el registrado en la base de datos.
* Es muy importante que no se modifique los identificadores a la ligera.
* */
//1
case "login":
login($_POST['username'], $_POST['password']);
//**grant a user access to the aplication
// ::> returns a message | return JSON configuration
break;
//1
case "login2":
login2($_POST['username'], $_POST['password']);
//**grant a user access to the aplication
// ::> returns a message | return JSON configuration
break;
//1
case "login3":
login3($_POST['username'], $_POST['password'],$_POST['regid'], $_POST['os']);
//**grant a user access to the aplication registration the mobile ID to send them messages
// ::> returns a message | return JSON configuration
break;
//40
case "logout":
logout($_POST['username'],$_POST['regid']);
//**delete the mobile ID registration
// ::> returns a message
break;
//2
case "lostpass":
lostpass($_POST['username']);
//**send an email to the email of the username
// ::> returns a message | send an email to the user with the new password
break;
//-------------------------------------------------------------------------------------------------
//3
case "createuser":
createuser($_POST['username'],$_POST['password'],$_POST['email'],$_POST['hint']);
//**create a new user account
// ::> returns a message
break;
//3
case "createuser2":
createuser2($_POST['username'],$_POST['password'],$_POST['email'],$_POST['hint']);
//**create a new user account
// ::> returns a message | send a confirm email to the user
break;
//4
case "deleteuser":
deleteuser($_POST['username'],$_POST['password']);
//**delete a existing user
// ::> returns a message
break;
//4
case "deleteuser2":
deleteuser2($_POST['username'],$_POST['password']);
//**delete a existing user
// ::> returns a message | send a good bye email to the user
break;
//5
case "modifyuser":
modifyuser($_POST['username'],$_POST['password'],$_POST['n_username'],$_POST['n_password'],$_POST['n_email'],$_POST['n_hint']);
//**modify all fields
// ::> returns a message
break;
//5
case "modifyuser2":
modifyuser2($_POST['username'],$_POST['password'],$_POST['n_username'],$_POST['n_password'],$_POST['n_email'],$_POST['n_hint'],$_POST['image']);
//**modify all fields
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//6
case "doaction":
doaction($_POST['username'],$_POST['housename'],$_POST['roomname'],$_POST['servicename'],$_POST['actionname'],$_POST['data']);
//**send an action to the arduino to be done
// ::> returns a message
break;
//8
case "ipcheck":
ipcheck();
//**ask for the IP address of a host conection
// ::> returns real client IP
break;
//10
case "getweather":
getweather($_POST['city'],$_POST['country'],$_POST['language']);
//**ask the weather of a city, country, in a lenguage
// ::> returns the weather of a specific city and country
break;
//-------------------------------------------------------------------------------------------------
//7
case "createhouse":
createhouse($_POST['username'],$_POST['housename'],$_POST['city'],$_POST['country']);
//**create a new house with an existing user
// ::> returns a message
break;
//9
case "deletehouse":
deletehouse($_POST['username'],$_POST['password'],$_POST['housename']);
//**delete a existing house by an administrator user
// ::> returns a message
break;
//20
case "modifyhouse":
modifyhouse($_POST['username'],$_POST['housename'],$_POST['n_housename'],$_POST['image'],$_POST['city'],$_POST['country']);
//**update informacion of the house, used to modify the house image
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//14
case "createprogramaction":
createprogramaction( $_POST['programname'],$_POST['username'],$_POST['housename'],$_POST['roomname'],$_POST['servicename'],$_POST['actionname'],$_POST['data'],$_POST['start']);
//**create an event, programaction == event
// ::> returns a message
break;
//15
case "deleteprogramaction":
deleteprogramaction( $_POST['username'],$_POST['programname']);
//**delete an event
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//11
case "createtask":
createtask( $_POST['username'],$_POST['taskname'],$_POST['description'],$_POST['frequency']);
//**create a task, a task agroup programactions
// ::> returns a message
break;
//12
case "deletetask":
deletetask( $_POST['username'],$_POST['taskname']);
//**delete the task but not the programactions inside
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//21
case "addtaskprogram":
addtaskprogram( $_POST['username'],$_POST['taskname'],$_POST['idaction']);
//**add a programaction to the task
// ::> returns a message
break;
//22
case "removetaskprogram":
removetaskprogram( $_POST['username'],$_POST['taskname'],$_POST['idaction']);
//**remove a program action from a task
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//28
case "addcommandprogram":
addcommandprogram( $_POST['username'],$_POST['commandname'],$_POST['idaction'], $_POST['number']);
//**
// ::>
break;
//29
case "removecommandprogram":
removecommandprogram( $_POST['username'],$_POST['commandname'],$_POST['idaction'], $_POST['number']);
//**
// ::>
break;
//-------------------------------------------------------------------------------------------------
//26
case "createcommand":
createcommand( $_POST['username'],$_POST['commandname']);
//**
// ::>
break;
//27
case "deletecommand":
deletecommand( $_POST['username'],$_POST['commandname']);
//**
// ::>
break;
//-------------------------------------------------------------------------------------------------
//23
case "schedulehouse":
schedulehouse( $_POST['housename']);
//**
// ::>
break;
//-------------------------------------------------------------------------------------------------
//17
case "createroom":
createroom($_POST['username'],$_POST['housename'],$_POST['roomname']);
//**create a new room with an existing user
// ::> returns a message
break;
//18
case "deleteroom":
deleteroom($_POST['username'],$_POST['password'],$_POST['housename'],$_POST['roomname']);
//**delete a existing room by an administrator user
// ::> returns a message
break;
//not implemented
/*case "modifyroom":
modifyroom($_POST['username'],$_POST['password'],$_POST['roomname']);
//**modify setings of an existing the room
// ::> returns a message
break;*/
//-------------------------------------------------------------------------------------------------
//24
case "createaccesshouse":
createaccesshouse($_POST['username'],$_POST['housename'],$_POST['n_username'],$_POST['number']);
//**grant a user access to a house
// ::> returns a message
break;
//36
case "deleteaccesshouse":
deleteaccesshouse($_POST['username'],$_POST['housename'],$_POST['n_username']);
//**delete a user access to a house
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//37
case "image":
image($_POST['idimage']);
//**look an updated image in the browser
// ::> watch image on browser
break;
//38
case "subir":
subir2();
//**update an image to the server
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//31
case "linkserviceroom":
linkserviceroom($_POST['idservice'],$_POST['idroom']);
//**assign a service to a room
// ::> returns a message
break;
//32
case "unlinkserviceroom":
unlinkserviceroom($_POST['idservice']);
//**delete the service on the room
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//33
case "modifyservicetype":
modifyservicetype($_POST['username'], $_POST['iddevice'],$_POST['servicename'], $_POST['type']);
//**modify the type of service instanced
// ::> returns a message
break;
//34
case "createpermissionservice":
createpermissionservice($_POST['username'],$_POST['housename'],$_POST['roomname'],$_POST['servicename'],$_POST['n_username'],$_POST['number']);
//**create permission to a user for a service
// ::> returns a message
break;
//35
case "deletepermissionservice":
deletepermissionservice($_POST['username'],$_POST['housename'],$_POST['roomname'],$_POST['servicename'],$_POST['n_username']);
//**delete permission to a user for a service
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//25
case "createdevice":
createdevice($_POST['username'],$_POST['ipaddress'],$_POST['serial'],$_POST['devicename']);
//**create a suported device
// ::> returns a message
break;
//30
case "deletedevice":
deletedevice($_POST['username'],$_POST['password'],$_POST['iddevice']);
//**delete an existing device created by this user
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
//39
case "UPDATE":
updateservicestate($_POST['idservice'],$_POST['data']);
//**raspberry pi connect to update the state of the service
// ::> returns a message
break;
//-------------------------------------------------------------------------------------------------
default:
$message = query("SELECT ERRORCODE AS ERROR, ENGLISH, SPANISH
FROM ERRORS
WHERE ERRORCODE= 38 LIMIT 1 ");
$json['error'] = $message['result'][0];
print json_encode($json);
}
break;
case 'GET':
switch ($_GET['command']) {
//39
case "UPDATE":
updateservicestate($_GET['idservice'],$_GET['data']);
//**raspberry pi connect to update the state of the service
// ::> returns a message
break;
default:
$message = query( "SELECT ERRORCODE AS ERROR, ENGLISH, SPANISH
FROM ERRORS
WHERE ERRORCODE= 38 LIMIT 1 ");
$json['error'] = $message['result'][0];
print json_encode($json);
}
break;
default:
break;
}
exit();
?>