Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
checklist.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Verify several point for the integrity of the system
9  *
10  * @author Anakeen 2007
11  * @version $Id: checklist.php,v 1.8 2008/12/31 14:37:26 jerome Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage CORE
15  */
16 /**
17  */
18 ?>
19 <html><head>
20 <LINK REL="stylesheet" type="text/css" HREF="Layout/wg.css" >
21 <style>
22 a.context {
23  border:solid 1px black;
24  margin:0px;
25  width:100px;
26  display:block;
27  float:left;
28  cursor:pointer;
29  -moz-border-radius:0px 10px 0px 0px;
30 }
31 a.context:hover {
32  background-color:yellow;
33 }
34 </style>
35 <title>Check List</title>
36 </head>
37 <body>
38 <?php
39 define("OK", "green");
40 define("KO", "red");
41 define("BOF", "orange");
42 
43 include ("../WHAT/Lib.Common.php");
44 
45 function globalparam($conn)
46 {
47  $result = pg_query($conn, "SELECT * FROM paramv where type='G'");
48  if (!$result) {
49  }
50  $pout = array();
51  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
52  $pout[$row["name"]] = $row["val"];
53  }
54  return $pout;
55 }
56 //---------------------------------------------------
57 //------------------- MAIN -------------------------
58 $wcontext = $_GET["context"];
59 if (!$wcontext) $wcontext = "default";
60 print "<H1>Check List : <i>$wcontext</i> </H1>";
61 // detect Contexts
62 if ($handle = @opendir(DEFAULT_PUBDIR . "/context")) {
63  /* Ceci est la façon correcte de traverser un dossier. */
64  while (false !== ($file = readdir($handle))) {
65  if ($file[0] != ".") {
66  if (file_exists(DEFAULT_PUBDIR . "/context/" . $file . "/dbaccess.php")) {
67  $contexts[] = $file;
68  if ($file == $wcontext) include (DEFAULT_PUBDIR . "/context/" . $file . "/dbaccess.php");
69  }
70  }
71  }
72 
73  closedir($handle);
74 }
75 
76 foreach ($contexts as $k => $v) {
77  if ($v == $wcontext) $sty = 'style="background-color:lightblue";';
78  else $sty = "";
79  print "<a href=\"?context=$v\" $sty class=\"context\">$v</a>";
80 }
81 print "<hr style=\"clear:both\">";
82 
83 $r = @pg_connect("service='$pgservice_core'");
84 if ($r) $dbr_anakeen = true;
85 else $dbr_anakeen = false;
86 
87 $tout["main connection db"] = array(
88  "status" => $dbr_anakeen ? OK : KO,
89  "msg" => $pgservice_core
90 );
91 
92 if ($dbr_anakeen) {
93  $GP = globalparam($r);
94  // print_r2($GP);
95  // TEST groups coherence
96  $appNameList = array();
97  $result = pg_query($r, "SELECT name FROM application;");
98  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
99  $appNameList[] = $row['name'];
100  }
101 
102  $result = pg_query($r, "SELECT * from groups where iduser not in (select id from users);");
103  $pout = array();
104  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
105  $pout[$row["iduser"]][] = $row["idgroup"];
106  }
107  if (count($pout) > 0) $msg = sprintf("%d unreference users<pre>%s</pre>", count($pout) , print_r($pout, true));
108  else $msg = "";
109  $tout["unreference user in group"] = array(
110  "status" => (count($pout) == 0) ? OK : BOF,
111  "msg" => $msg
112  );
113 
114  $result = pg_query($r, "SELECT distinct(idgroup) from groups where idgroup not in (select id from users where isgroup='Y');");
115  $pout = array();
116  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
117  $pout[] = $row["idgroup"];
118  }
119  if (count($pout) > 0) $msg = sprintf("%d users detected as group<br><kbd>%s</kbd>", count($pout) , implode(", ", $pout));
120  else $msg = "";
121  $tout["user as group"] = array(
122  "status" => (count($pout) == 0) ? OK : KO,
123  "msg" => $msg
124  );
125 
126  $result = pg_query($r, "SELECT * from action where id_application not in (select id from application);");
127  $pout = array();
128  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
129  $pout[] = $row["name"];
130  }
131  if (count($pout) > 0) $msg = sprintf("%d unreference actions<br><kbd>%s</kbd>", count($pout) , implode(", ", $pout));
132  else $msg = "";
133  $tout["unreference actions"] = array(
134  "status" => (count($pout) == 0) ? OK : BOF,
135  "msg" => $msg
136  );
137 
138  $result = pg_query($r, "SELECT * from paramdef where appid not in (select id from application);");
139  $pout = array();
140  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
141  $pout[] = $row["name"];
142  }
143  $result = pg_query($r, "SELECT * from paramv where appid not in (select id from application);");
144  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
145  $pout[] = $row["name"];
146  }
147  if (count($pout) > 0) $msg = sprintf("%d unreference parameters<br><kbd>%s</kbd>", count($pout) , implode(", ", $pout));
148  else $msg = "";
149  $tout["unreference parameters"] = array(
150  "status" => (count($pout) == 0) ? OK : BOF,
151  "msg" => $msg
152  );
153 
154  $result = pg_query($r, "SELECT * from acl where id_application not in (select id from application);");
155  $pout = array();
156  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
157  $pout[] = $row["name"];
158  }
159  if (count($pout) > 0) $msg = sprintf("%d unreference acl<br><kbd>%s</kbd>", count($pout) , implode(", ", $pout));
160  else $msg = "";
161  $tout["unreference acl"] = array(
162  "status" => (count($pout) == 0) ? OK : BOF,
163  "msg" => $msg
164  );
165 
166  $result = pg_query($r, "SELECT * from permission where id_acl not in (select id from acl);");
167  $nb = pg_num_rows($result);
168  $result = pg_query($r, "SELECT * from permission where id_user not in (select id from users);");
169  $nb+= pg_num_rows($result);
170  $result = pg_query($r, "SELECT * from permission where id_application not in (select id from application);");
171  $nb+= pg_num_rows($result);
172 
173  if ($nb > 0) $msg = sprintf("%d unreference permission", ($nb));
174  $tout["unreference permission"] = array(
175  "status" => ($nb == 0) ? OK : BOF,
176  "msg" => $msg
177  );
178  // Test FREEDOM DB Connection
179  $fdb = $GP["FREEDOM_DB"];
180  $dbr_freedom = false;
181  if ($fdb) {
182  $rf = @pg_connect($fdb);
183  if ($rf) $dbr_freedom = true;
184  }
185 
186  $tout["connection db dynacase"] = array(
187  "status" => $dbr_freedom ? OK : KO,
188  "msg" => $fdb
189  );
190 
191  if ($rf) {
192  // test double in docfrom
193  $result = pg_query($rf, "SELECT * from (SELECT id, count(id) as c from doc group by id) as Z where Z.c > 1;");
194  $pout = array();
195  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
196  $pout[$row["id"]] = $row["c"];
197  }
198  if (count($pout) > 0) $msg = sprintf("%d double id detected<pre>%s</pre>", count($pout) , print_r($pout, true));
199  else $msg = "";
200  $tout["double doc id"] = array(
201  "status" => (count($pout) == 0) ? OK : KO,
202  "msg" => $msg
203  );
204  // test double in docname
205  $result = pg_query($rf, "select * from (select name, count(name) as c from doc where name is not null and name != '' and locked != -1 group by name) as Z where Z.c >1");
206  $pout = array();
207  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
208  $pout[$row["name"]] = $row["c"];
209  }
210  if (count($pout) > 0) $msg = sprintf("%d double detected<pre>%s</pre>", count($pout) , print_r($pout, true));
211  else $msg = "";
212  $tout["double doc name"] = array(
213  "status" => (count($pout) == 0) ? OK : KO,
214  "msg" => $msg
215  );
216  // test multiple alive
217  $result = pg_query($rf, "select id, title from docread where id in (SELECT m AS id FROM (SELECT min(id) AS m, initid, count(initid) AS c FROM docread WHERE locked != -1 AND doctype != 'T' GROUP BY docread.initid) AS z where z.c > 1);");
218  $pout = array();
219  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
220  $pout[$row["id"]] = $row["title"];
221  }
222  if (count($pout) > 0) $msg = sprintf("%d multiple alive<pre>%s</pre>", count($pout) , print_r($pout, true));
223  else $msg = "";
224  $tout["multiple alive"] = array(
225  "status" => (count($pout) == 0) ? OK : KO,
226  "msg" => $msg
227  );
228  // test inheritance
229  $result = pg_query($rf, "select * from docfam");
230  $pout = array();
231  while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
232  $fromid = intval($row["fromid"]);
233  if ($fromid == 0) $fromid = "";
234  $fid = intval($row["id"]);
235  $test = pg_query($rf, sprintf("SELECT relname from pg_class where oid in (SELECT inhparent from pg_inherits where inhrelid =(SELECT oid FROM pg_class where relname='doc%d'));", $fid));
236  $dbfrom = pg_fetch_array($test, NULL, PGSQL_ASSOC);
237  if ($dbfrom["relname"] != "doc$fromid") {
238  $pout[] = sprintf("Family %s [%d]: fromid = %d, pg inherit=%s", $row["name"], $row["id"], $row["fromid"], $dbfrom["relname"]);
239  }
240  }
241  $tout["family inheritance"] = array(
242  "status" => (count($pout) == 0) ? OK : KO,
243  "msg" => implode("<br/>", $pout)
244  );
245  // test groups
246  $result = pg_query($rf, "select * from groups");
247  $result2 = pg_query($r, "select * from groups");
248  if (pg_num_rows($result) != pg_num_rows($result2)) $msg = "tables group are differents between <b>$dbaccess</b> <br>and <b>$fdb</b>";
249  else $msg = "";
250  $tout["user group synchro"] = array(
251  "status" => ($msg == "") ? OK : KO,
252  "msg" => $msg
253  );
254  }
255  // Test WEBDAV DB Connection
256  $fdb = $GP["WEBDAV_DB"];
257  if ($fdb) {
258  $dbr_webdav = false;
259  if ($fdb) {
260  $rw = @pg_connect($fdb);
261  if ($rw) $dbr_webdav = true;
262  }
263 
264  $tout["connection db webdav"] = array(
265  "status" => $dbr_webdav ? OK : KO,
266  "msg" => $fdb
267  );
268  }
269  // Test User LDAP (NetworkUser Module)
270  $nuAppExists = (array_search('NU', $appNameList) === false) ? false : true;
271  $ldaphost = $GP["NU_LDAP_HOST"];
272  $ldapport = $GP["NU_LDAP_PORT"];
273  $ldapmode = $GP["NU_LDAP_MODE"];
274  if ($nuAppExists && $ldaphost) {
275  include_once ('../NU/Lib.NU.php');
276 
277  $ldapBindDn = $GP['NU_LDAP_BINDDN'];
278  $ldapPassword = $GP['NU_LDAP_PASSWORD'];
279 
280  $baseList = array();
281  array_push($baseList, array(
282  'dn' => $GP['NU_LDAP_USER_BASE_DN'],
283  'filter' => $GP['NU_LDAP_USER_FILTER']
284  ));
285  array_push($baseList, array(
286  'dn' => $GP['NU_LDAP_GROUP_BASE_DN'],
287  'filter' => $GP['NU_LDAP_GROUP_FILTER']
288  ));
289 
290  foreach ($baseList as $base) {
291  $testName = sprintf("connection to '%s'", $base['dn']);
292  $tout[$testName] = array();
293 
294  $uri = getLDAPUri($ldapmode, $ldaphost, $ldapport);
295  $conn = ldap_connect($uri);
296  if ($conn === false) {
297  $tout[$testName]['status'] = KO;
298  $tout[$testName]['msg'] = sprintf("Could not connect to LDAP server '%s': %s", $uri, $php_errormsg);
299  continue;
300  }
301 
302  ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
303  ldap_set_option($conn, LDAP_OPT_REFERRALS, 0);
304 
305  if ($ldapmode == 'tls') {
306  $ret = ldap_start_tls($conn);
307  if ($ret === false) {
308  $tout[$testName]['status'] = KO;
309  $tout[$testName]['msg'] = sprintf("Could not negotiate TLS with server '%s': %s", $uri, ldap_error($conn));
310  continue;
311  }
312  }
313 
314  $bind = ldap_bind($conn, $ldapBindDn, $ldapPassword);
315  if ($bind === false) {
316  $tout[$testName]['status'] = KO;
317  $tout[$testName]['msg'] = sprintf("Could not bind with bind DN '%s' on server '%s': %s", $ldapBindDn, $uri, ldap_error($conn));
318  ldap_close($conn);
319  continue;
320  }
321 
322  $res = ldap_search($conn, $base['dn'], sprintf("(&(objectClass=*)%s)", $base['filter']));
323  if ($res === false) {
324  $tout[$testName]['status'] = KO;
325  $tout[$testName]['msg'] = sprintf("LDAP search on base '%s' with filter '%s' failed: %s", $base['dn'], $base['filter'], ldap_error($conn));
326  ldap_close($conn);
327  continue;
328  }
329 
330  $count = ldap_count_entries($conn, $res);
331  if ($count === false) {
332  $tout[$testName]['status'] = KO;
333  $tout[$testName]['msg'] = sprintf("Error counting result entries: %s", ldap_error($conn));
334  ldap_close($conn);
335  continue;
336  }
337  if ($count <= 0) {
338  $tout[$testName]['status'] = BOF;
339  $tout[$testName]['msg'] = sprintf("Search returned 0 entries...");
340  ldap_close($conn);
341  continue;
342  }
343 
344  $tout[$testName]['status'] = OK;
345  $tout[$testName]['msg'] = sprintf("Search returned %s entries.", $count);
346  ldap_close($conn);
347  }
348  }
349 }
350 
351 print "<table border=1>";
352 foreach ($tout as $k => $v) {
353  print sprintf("<tr><td><span style=\"background-color:%s;margin:3px;border:inset 2px %s\">&nbsp;&nbsp;&nbsp;</span></td><td>%s</td><td>%s</td></tr>", $v["status"], $v["status"], $k, $v["msg"]);
354 }
355 print "</table>";
356 ?>
357 </body>
358 </html>
← centre documentaire © anakeen - published under CC License - Dynacase