forked from jeedom/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sick.php
173 lines (161 loc) · 4.97 KB
/
sick.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
<?php
if (php_sapi_name() != 'cli' || isset($_SERVER['REQUEST_METHOD']) || !isset($_SERVER['argc'])) {
header("Statut: 404 Page non trouvée");
header('HTTP/1.0 404 Not Found');
$_SERVER['REDIRECT_STATUS'] = 404;
echo "<h1>404 Non trouvé</h1>";
echo "La page que vous demandez ne peut être trouvée.";
exit();
}
echo "==================================================\n";
echo "| JEEDOM SICK SCRIPT " . date('Y-m-d H:i:s') . " |";
echo "\n==================================================\n";
echo "\n**************************************************\n";
echo "* VARIABLES *";
echo "\n**************************************************\n";
$install_dir = __DIR__;
$processUser = posix_getpwuid(posix_geteuid());
echo "Dossier d'installation : " . $install_dir . "\n";
echo "User : " . $processUser['name'] . "\n";
if (trim(exec('sudo cat /etc/sudoers')) != "") {
echo "Sudo : OUI\n";
} else {
echo "Sudo : NON\n";
}
echo "\n**************************************************\n";
echo "* DOSSIERS *";
echo "\n**************************************************\n";
echo "Charge l'environnement de Jeedom...";
try {
require_once __DIR__ . "/core/php/core.inc.php";
echo "OK\n";
} catch (Exeption $e) {
echo "ERREUR\n";
echo "Impossible de charger l'environnement de Jeedom : " . $e->getMessage();
echo "\n";
die();
}
/* Check log dir */
echo "Vérifie si les log sont en écriture...";
if (!file_exists($install_dir . '/log')) {
echo "introuvable\n";
echo "Faites : mkdir " . $install_dir . "/log\n";
die();
}
if (!is_writable($install_dir . '/log')) {
echo "Impossible d'écrire\n";
echo "Faites : chown -R " . $processUser['name'] . ' ' . $install_dir . "/log\n";
die();
}
echo "OK\n";
echo "\n**************************************************\n";
echo "* UTILISATEURS *";
echo "\n**************************************************\n";
try {
$foundAdmin = false;
foreach (user::all() as $user) {
echo $user->getLogin();
echo " => ";
if ($user->getProfils() == 'admin') {
$foundAdmin = true;
echo " Admin\n";
} else {
echo " Regular\n";
}
}
if (!$foundAdmin) {
echo "Aucun utilisateur admin trouvé, veuillez en créer un...";
$user = (new \user())
->setLogin('admin')
->setPassword(sha512('admin'))
->setProfils('admin', 1);
$user->save();
echo "OK (admin/admin)\n";
}
} catch (Exeption $e) {
echo "ERREUR\n";
echo "Description : " . $e->getMessage();
echo "\n";
die();
}
echo "\n**************************************************\n";
echo "* CRON *";
echo "\n**************************************************\n";
echo "Vérifie si cron est actif...";
if (config::byKey('enableCron', 'core', 1, true) == 0) {
echo "NOK\n";
} else {
echo "OK\n";
}
echo "Vérifie si scenario est actif...";
if (config::byKey('enableScenario') == 0) {
echo "NOK\n";
} else {
echo "OK\n";
}
echo "\n";
echo "NAME | STATE | SCHEDULE | DEAMON | ONCE | LAST RUN\n";
foreach (cron::all() as $cron) {
echo $cron->getName();
echo " | ";
echo $cron->getState();
echo " | ";
echo $cron->getSchedule();
echo " | ";
echo $cron->getDeamon();
echo " | ";
echo $cron->getOnce();
echo " | ";
echo $cron->getLastRun();
echo "\n";
}
echo "\n**************************************************\n";
echo "* DATE *";
echo "\n**************************************************\n";
echo "Vérifie si la date de Jeedom est bonne...";
if (jeedom::isDateOk()) {
echo "OK";
} else {
echo "NOK";
}
$cache = cache::byKey('jeedom::lastDate');
echo " (" . $cache->getValue() . ")\n";
echo "\n**************************************************\n";
echo "* MESSAGE *";
echo "\n**************************************************\n";
echo "DATE | PLUGIN | LOGICALID | MESSAGE\n";
foreach (message::all() as $message) {
echo $message->getDate();
echo " | ";
echo $message->getPlugin();
echo " | ";
echo $message->getLogicalId();
echo " | ";
echo $message->getMessage();
echo "\n";
}
echo "\n**************************************************\n";
echo "* PLUGIN *";
echo "\n**************************************************\n";
echo "ID | NAME | STATE\n";
foreach (plugin::listPlugin() as $plugin) {
echo $plugin->getId();
echo " | ";
echo $plugin->getName();
echo " | ";
echo $plugin->isActive();
echo "\n";
}
foreach (plugin::listPlugin() as $plugin) {
if (method_exists($plugin->getId(), 'sick')) {
echo "\n**************************************************\n";
echo "* SICK " . $plugin->getId() . " *";
echo "\n**************************************************\n";
$plugin_id = $plugin->getId();
$plugin_id::sick();
}
}
echo "\n\n";
echo "\n==================================================\n";
echo "| TOUTES LES VERIFICATIONS SONT FAITES |";
echo "\n==================================================\n";