-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
141 lines (132 loc) · 4.89 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
<?php
session_start();
if (!file_exists('include/configData.json')) {
file_put_contents('include/configData.json', '{"Town":"","IP":"","Port":"","ListeAppareils":[{"idx":"","type":""}]}');
header('Location: index.php?page=configIp');
}
require('include/fonctions/controles.php');
require('include/actions/switchActions.php');
try {
if (isset($_GET['page'])) {
$page = htmlentities($_GET['page']);
switch ($page) {
case 'about':
about();
break;
case 'accueil':
accueil();
break;
case 'plan':
if (isset($_GET['id'])) {
$idplan = htmlentities($_GET['id']);
if (preg_match('/\d{1,}/', $idplan)) {
plan($idplan);
}
else {
throw new Exception('id au mauvais format');
}
}
else {
throw new Exception('id du plan manquant');
}
break;
case 'meteo':
if (isset($_GET['id'])) {
$townid = htmlentities($_GET['id']);
if (preg_match('/\d{1,}/', $townid)) {
weatherDetail($townid);
}
else {
throw new Exception('id au mauvait format');
}
}
else {
throw new Exception('id de la ville manquant');
}
break;
case 'configMenu':
configurationMenu();
break;
case 'configIp':
configurationIp();
break;
case 'configTown':
configurationTown();
break;
case 'configListe':
configurationListe();
break;
case 'configSave':
if (isset($_POST['id'])) {
$listeID = htmlentities($_POST['id']);
configurationSave($listeID);
}
else {
throw new Exception("Action non permise !");
}
break;
case 'configSaveIp':
if (isset($_POST['IP']) && isset($_POST['Port'])) {
$IP = htmlentities($_POST['IP']);
$Port = htmlentities($_POST['Port']);
configurationSaveIp($IP,$Port);
}
else {
throw new Exception("Action non permise !");
}
break;
case 'configSaveTown':
if (isset($_POST['Town'])) {
$Town = htmlentities($_POST['Town']);
configurationSaveTown($Town);
}
else {
throw new Exception("Action non permise !");
}
break;
case 'switch':
if (isset($_GET['action'])) {
$action = htmlentities($_GET["action"]);
$data = htmlentities($_GET["data"]);
$idx = htmlentities($_GET["idx"]);
if ( $data != "" && $idx !="" ) {
switch ($action) {
case 'On':
$switched = switchOn($idx);
break;
case 'Off':
$switched = switchOff($idx);
break;
case 'Toggle':
$switched = switchToggle($data,$idx);
break;
default:
throw new Exception("Action non définie");
break;
}
$parsedJSON = json_decode($switched, true);
if ($parsedJSON['status'] == "OK") {
header('Location: index.php');
}
}
else {
throw new Exception("Data ou Idx manquant");
}
}
else {
throw new Exception("Action manquante");
}
break;
//Si inconnue, on affiche une erreur
default:
throw new Exception("Page inconnue");
break;
}
}
else {
accueil(); // page par défaut
}
}
catch (Exception $e) {
afficherErreur($e->getMessage());
}