PhpLabWare version 0.3 
/ -> setup.php

1  <?php
2 
3  // setup.php - Initiates and updates database, manages system wide prefs
4  // setup.php - author: Nico Stuurman <nicost@sourceforge.net>
5 
6    /***************************************************************************
7    * Copyright (c) 2001,2002,2003 by Nico Stuurman *
8    * ------------------------------------------------------------------------ *
9    * This program is free software; you can redistribute it and/or modify it *
10    * under the terms of the GNU General Public License as published by the *
11    * Free Software Foundation; either version 2 of the License, or (at your *
12    * option) any later version. *
13    \**************************************************************************/
14 
15  $version_code=0.3;
16  $localdir=exec("pwd");
17  include ('includes/functions_inc.php');
18  if (!file_exists("includes/config_inc.php")) {
19     printheader("Not ready yet");
20     echo "<h3 align='center'>Please edit the file <i>$localdir/includes/config_inc.exp</i> and save it as <i>$localdir/includes/config_inc.php</i>. Then come back to this page.</h3>";
21     printfooter();
22     exit();
23  }
24  include ('includes/config_inc.php');
25  include ("includes/defines_inc.php");
26  include ('adodb/adodb.inc.php');
27  $adodb_version=(float)substr($ADODB_vers,1);
28  $adodb_version_required=3.50;
29  if ($adodb_version<$adodb_version_required) {
30     echo "The adodb version you are using ($adodb_version) is too old. Please download version $adodb_version_required or greater from <a href='http://php.weblogs.com'>php.weblogs.com</a>.";
31     exit();
32  }
33 
34  $post_vars="access,action,authmethod,baseURL,homeURL,checkpwd,convert,dateformat,filedir,thumbnaildir,templatedir,gs,pwd,protocols_file,pdfs_file,pdfget,secure_server_new,smallthumbsize,submit,tmpdir,tmpdirpsql,word2html";
35  globalize_vars($post_vars, $HTTP_POST_VARS);
36 
37  if ($set_local) {
38     // only allow connections from localhost
39     $host=getenv("HTTP_HOST");
40     if (! ($host=="localhost" ||$host=="127.0.0.1") ) {
41        printheader("Phplabware setup. Localhost only");
42        echo "<table align='center' border=0><caption><h3>This script can only be reached from the localhost.</h3></caption></table>\n";
43        printfooter();
44        exit();
45     }
46  }
47 
48  // we want associative arrays from the database
49  $ADODB_FETCH_MODE=ADODB_FETCH_DEFAULT;
50 
51  // test whether the database exists
52  $db=NewADOConnection($db_type);
53  if (!@$db->Connect($db_host, $db_user, $db_pwd, $db_name)) {
54     printheader("PhpLabware: Database connection failed");
55     echo "<h3>Connection to database <i>$db_name</i> on host <i>$db_host</i>";
56     echo " failed.<br> Please make sure that the variables in file ";
57     echo "<i>phplabware/includes/config_inc.php</i> are correct, your database ";
58     echo "server is functioning, and you created a database named <i>$db_name";
59     echo "</i>.</h3>";
60     printfooter();
61     exit ();
62  }
63 
64  // if table settings does not exist, we'll need to create the initial tables
65  $version=get_cell($db, "settings", "version", "id", 1);
66 
67  if (! ($version || $pwd) ) {
68     // This must be the first time, ask for a sysadmin password
69     printheader("Ready to install the database");
70  ?>
71  <form enctype='multipart/form-data' method='post' action='<?php echo $PHP_SELF?>'>
72  <?php
73     echo "<h3>After submitting the following form the phplabware database will ";
74     echo "be created and you will be asked to login.<br>";
75     echo "Login as <i>sysadmin</i> using the password you enter here.<br>\n";
76     echo "The database tables will be created. This may take a while.<br>\n";
77     echo "After logging in, examine the system settings, and press the submit button.</h3>\n";
78     echo "<table border=0>\n";
79     echo "<tr>\n";
80     echo "<td><h3>Please provide a password for <i>sysadmin</i>:</td>\n";
81     echo "<td><input type='text' name='pwd'></td>\n";
82     echo "</tr>\n";
83     echo "<tr>\n";
84     echo "<td colspan=2 align='center'><input type='submit' name='submit' ";
85     echo "value='submit'></td>\n";
86     echo "</tr>\n";
87     echo "</table>\n";
88     printfooter();
89  }
90 
91  if (!$version && $pwd) {
92     // we connected to an empty database and have the password
93     // now create the initial tables
94     // $db->debug = true;
95     include ("dd/0_001_inc.php");
96  }
97 
98  // $version is known, so we have a working database and must now authenticate
99  if ($version) {
100     $system_settings=unserialize(get_cell($db, "settings", "settings", "id", 1));
101     include ("includes/auth_inc.php");
102     allowonly($SUPER, $USER["permissions"]);
103     printheader("Settings");
104     navbar($USER["permissions"]);
105 
106     // insert database updates here
107     if ($version<$version_code) {
108        $test=true;
109        if ($version<0.0021)
110           include ("dd/0_0021_inc.php");
111        if ($version<0.0022)
112           include ("dd/0_0022_inc.php");
113        if ($version<0.0023)
114           include ("dd/0_0023_inc.php");
115        if ($version<0.0024)
116           include ("dd/0_0024_inc.php");
117        if ($version<0.0026)
118           include ("dd/0_0026_inc.php");
119        if ($version<0.0027)
120           include ("dd/0_0027_inc.php");
121        if ($version<0.0028)
122           include ("dd/0_0028_inc.php");
123        if ($version<0.0029)
124           include ("dd/0_0029_inc.php");
125        if ($version<0.0030)
126           include ("dd/0_0030_inc.php");
127        if ($version<0.0031)
128           include ("dd/0_0031_inc.php");
129        if ($version<0.0032)
130           include ("dd/0_0032_inc.php");
131        if ($version<0.0033)
132           include ("dd/0_0033_inc.php");
133        if ($version<0.0034)
134           include ("dd/0_0034_inc.php");
135        if ($version<0.0035)
136           include ("dd/0_0035_inc.php");
137        if ($version<0.0036)
138           include ("dd/0_0036_inc.php");
139        if ($version<0.0041) {
140           include ("dd/0_0037_inc.php");
141           include ("dd/0_0038_inc.php");
142           include ("dd/0_0039_inc.php");
143           include ("dd/0_0040_inc.php");
144           include ("dd/0_0041_inc.php");
145        }
146        if ($version<0.1001) {
147           // add table words for indexing of uploaded files
148           $db->Execute("CREATE TABLE words (id int PRIMARY KEY, word text)");
149           $db->Execute("CREATE INDEX words_word_index ON words (word)");
150           $db->Execute("CREATE INDEX words_word_index ON words (word(10))");
151        }
152        if ($version<0.1002) {
153           // add field indexed to table files
154           // add associated tables to all known columns of type file
155           include ("dd/0_1002_inc.php");
156        }
157        if ($version<0.1003) {
158           // Changes ownerid, date, lastmoddate, lastmodby into viewable/editable fields
159           // Introduces datatype user and date
160           include ("dd/0_1003_inc.php");
161        }
162        if ($version<0.1004) {
163           // Creates table images
164           $rs=$db->Execute("CREATE TABLE images (id int UNIQUE NOT NULL, x_size int, y_size int, xbt_size int, ybt_size int, xst_size int, yst_size int, xnmperpixel int, ynmperpixel int, rotation int, seq int, type text) ");
165           // Create index
166           $db->Execute("CREATE INDEX images_id ON images(id)");
167        }
168        if ($version<0.1005) {
169           // Creates table reports
170           $rs=$db->Execute("CREATE TABLE reports (id int UNIQUE NOT NULL, label text, tableid int, sortkey int, type text, filesize int) ");
171          // Create indices
172          $db->Execute("CREATE INDEX reports_id ON reports(id)");
173          $db->Execute("CREATE INDEX reports_tableid ON reports(tableid)");
174          $db->Execute("CREATE INDEX reports_sortkey ON reports(sortkey)");
175        }
176        if ($version<0.1006) {
177           // Adjust table dateformat, such that generated dates are interpretated right by the function strtotime
178           $db->Execute("UPDATE dateformats SET dateformat='n/d/Y' WHERE id=1");
179           $db->Execute("UPDATE dateformats SET dateformat='M d Y' WHERE id=2");
180           $db->Execute("UPDATE dateformats SET dateformat='d M Y' WHERE id=3");
181           $db->Execute("UPDATE dateformats SET dateformat='d M Y' WHERE id=4");
182        }
183        if ($version<0.2001) {
184           // add columns gw,gr,ew,er (to replace column access) to each table
185           include ("dd/0_2001_inc.php");
186        }
187        if ($version<0.2002) {
188           // fill columns gw,gr,ew,er with values from column access
189           // Moves column access to columns gw,gr,ew,er
190           include ("dd/0_2002_inc.php");
191        }
192        if ($version<0.2003) {
193           // Adds column key_table to description tables
194           include ("dd/0_2003_inc.php");
195        }
196        if ($version<0.2004) {
197           // adds Ethan's ordering table
198           include ("dd/ordertable.php");
199        }
200 
201        $query="UPDATE settings SET version='$version_code' WHERE id=1";
202        if (!$db->Execute($query)) $test=false;
203 
204 
205        if ($test)
206            echo "<h3 align='center'>Succesfully updated the database to version $version_code.</h3>\n";
207         else
208            echo "<h3 align='center'>Failed to update the database to version $version_code.</h3>\n";
209     }
210 
211     if ($action) {
212        if ($access)
213           if (strlen($access)==9 && strlen(count_chars($access,3))<4)
214              $system_settings["access"]=$access;
215        if ((int)$smallthumbsize)
216           $system_settings["smallthumbsize"]=(int)$smallthumbsize;
217        else
218           $system_settings["smallthumbsize"]=72;
219        if ($dateformat)
220           $system_settings["dateformat"]=$dateformat;
221        if ($filedir)
222           if (is_writable($filedir))
223              $system_settings["filedir"]=$filedir;
224           else
225           echo "<h4 align='center'>Directory $filedir is not writeable</h4>";
226        if ($thumbnaildir) {
227           if (is_writable("$thumbnaildir/small") && is_writable("$thumbnaildir/big"))
228              $system_settings["thumbnaildir"]=$thumbnaildir;
229           else
230           echo "<h4 align='center'>Directory $thumbnaildir/small and/or $thumbnaildir/big is not writeable</h4>";
231        }
232        if ($templatedir)
233           if (is_writable($templatedir))
234              $system_settings["templatedir"]=$templatedir;
235           else
236           echo "<h4 align='center'>Directory $templatedir is not writeable</h4>";
237        if ($tmpdir)
238           if (is_writeable($tmpdir))
239              $system_settings["tmpdir"]=$tmpdir;
240           else {
241           echo "<h4 align='center'>Directory $tmpdir is not writeable</h4>";
242              if (!isset ($system_settings["tmpdir"]))
243                 $system_settings["tmpdir"]=session_save_path();
244           }
245        if ($tmpdirpsql) {
246           if (is_writeable($tmpdirpsql))
247              $system_settings["tmpdirpsql"]=$tmpdirpsql;
248           else {
249           echo "<h4 align='center'>Directory $tmpdirpsql is not writeable</h4>";
250              if (!isset ($system_settings["tmpdirpsql"]))
251                 $system_settings["tmpdirpsql"]="/tmp";
252           }
253        }
254   
255        // wvHtml
256        if (isset($word2html) && @is_readable($word2html)) {
257           $system_settings["word2html"]=$word2html;
258           // attempt to discover version of wvWare used
259           $wvWare=str_replace("Html","Ware",$word2html);
260           $wvresult=exec("$wvWare -v");
261           //last attempt to get something
262           if (!$wvresult)
263              $wvresult=exec("$word2html -v");
264           $wvresult=explode(" ",$wvresult);
265           if ($wvresult)
266              $system_settings["wvHtml_version"]=$wvresult[1];
267           else
268              $system_settings["wvHtml_version"]=0.6;
269        }
270        else {
271           unset($system_settings["word2html"]);
272           unset($system_settings["wvHtml_version"]);
273           if (isset($word2html) && $word2html)
274           echo "<h3 align='center'>wvHtml was not found at '$word2html'.</h3>";
275        }
276 
277        // ghostscript
278        $gs=trim($gs);
279        if (isset($gs) && @is_readable($gs)) {
280           $system_settings["gs"]=$gs;
281        }
282        else {
283           unset($system_settings["gs"]);
284           if (isset($gs))
285           echo "<h3 align='center'>Ghostscript was not found at '$gs'.</h3>";
286        }
287 
288        // Imagemagick convert
289        $convert=trim($convert);
290        if (isset($convert) && @is_readable($convert)) {
291           $system_settings["convert"]=$convert;
292        }
293        else {
294           unset($system_settings["convert"]);
295           if (isset($convert))
296           echo "<h3 align='center'>Imagemagick's convert was not found at '$convert'.</h3>";
297        }
298 
299        if ($baseURL)
300           $system_settings["baseURL"]=$baseURL;
301        $system_settings["homeURL"]=$homeURL;
302        if ($protocols_file) {
303           if (!is_readable($protocols_file)) {
304           $fid=fopen($protocols_file,w);
305           if ($fid)
306           fclose ($fid);
307           }
308           if (is_writeable($protocols_file))
309              $system_settings["protocols_file"]=$protocols_file;
310           else
311           echo "<h4 align='center'>Protocols additions file $protocols_file is not writeable</h4>";
312        }
313        else
314           unset ($system_settings["protocols_file"]);
315        if ($pdfs_file) {
316           if (!is_readable($pdfs_file)) {
317           $fid=fopen($pdfs_file,w);
318           if ($fid)
319           fclose ($fid);
320           }
321           if (is_writeable($pdfs_file))
322              $system_settings["pdfs_file"]=$pdfs_file;
323           else
324           echo "<h4 align='center'>Pdfs additions file $pdfs_file is not writeable</h4>";
325        }
326        else
327           unset ($system_settings["pdfs_file"]);
328        if ($secure_server_new=="Yes")
329           $system_settings["secure_server"]=true;
330        else
331           $system_settings["secure_server"]=false;
332        if ($authmethod)
333           $system_settings["authmethod"]=$authmethod;
334        $system_settings["checkpwd"]=$checkpwd;
335        $system_settings["pdfget"]=$pdfget;
336        
337        $settings_ser=serialize($system_settings);
338        $query="UPDATE settings SET settings='$settings_ser' WHERE id=1";
339        $result=$db->Execute($query);
340        if ($result)
341           echo "<h3 align='center'>Succesfully updated the database settings.</h3>\n";
342        else
343           echo "<h3 align='center'>Failed to update settings!</h3>\n";
344     }
345 
346     // display form with current settings
347  ?>
348  <form enctype='multipart/form-data' method='post' name='globals-form' action='<?php echo $PHP_SELF ?>?<?=SID?>'>
349  <?php
350     echo "<table border=1 align='center' width='70%'>\n";
351     echo "<tr><th width='50%'>Description</th><th width='50%'>Setting</th></tr>\n";
352 
353     echo "<tr><td colspan='2' align='center'><i>Defaults</i></th></tr>\n";
354     echo "<tr><td>Default access rights. A 9 character string using the UNIX access method:</td>\n";
355     if (!$system_settings["access"])
356        $system_settings["access"]="rw-r-----";
357     echo "<td><input type='text' size='9' name='access' value='".$system_settings["access"]."'></td></tr>\n";
358 
359     echo "<tr><td>Default size of thumbnail in table view (in pixels):</td>\n";
360     if (!$system_settings['smallthumbsize'])
361        $system_settings['smallthumbsize']='72';
362     echo "<td><input type='text' size='4' name='smallthumbsize' value='".$system_settings["smallthumbsize"]."'></td></tr>\n";
363 
364     echo "<tr><td colspan='2' align='center'><i>Directories and URLs</i></th></tr>\n";
365     $dirsizestring="size='50'";
366 
367     echo "<tr><td>Directory <i>files</i>. The webdaemon should ";
368     echo "have read and write priveleges, but the directory should not be directly ";
369     echo "accessible through the web.";
370     if (!$system_settings["filedir"]) {
371        $dir=getenv("SCRIPT_FILENAME");
372        $dir=substr($dir,0,strrpos($dir,"/")+1)."files";
373        $system_settings["filedir"]=$dir;
374     }
375     $filedir=$system_settings["filedir"];
376     echo "<td><input type='text' $dirsizestring name='filedir' value='$filedir'></td></tr>\n";
377 
378     echo "<tr><td>Directory <i>thumbnails</i>. The webdaemon should ";
379     echo "have read and write priveleges, but the directory should not be directly ";
380     echo "accessible through the web. ";
381     if (!$system_settings["thumbnaildir"]) {
382        $dir=getenv("SCRIPT_FILENAME");
383        $dir=substr($dir,0,strrpos($dir,"/")+1)."thumbnails";
384        $system_settings["thumbnaildir"]=$dir;
385     }
386     $thumbnaildir=$system_settings["thumbnaildir"];
387     echo "<td><input type='text' $dirsizestring name='thumbnaildir' value='$thumbnaildir'></td></tr>\n";
388 
389     echo "<tr><td>Directory <i>templates</i>. The webdaemon should ";
390     echo "have read and write priveleges, but the directory should not be directly ";
391     echo "accessible through the web. ";
392     if (!$system_settings["templates"]) {
393        $dir=getenv("SCRIPT_FILENAME");
394        $dir=substr($dir,0,strrpos($dir,"/")+1)."templates";
395        $system_settings["templatedir"]=$dir;
396     }
397     $templatedir=$system_settings["templatedir"];
398     echo "<td><input type='text' $dirsizestring name='templatedir' value='$templatedir'></td></tr>\n";
399 
400     echo "<tr><td>Directory for <i>temporary</i> files. For security reasons, only the webdaemon should be able to read (and write) files here. Usually, this is <b>not</b> the case for directory <i>/tmp</i>. </td>";
401     if (!$system_settings["tmpdir"])
402        $system_settings["tmpdir"]="/tmp";
403     echo "<td><input type='text' name='tmpdir' value='".$system_settings["tmpdir"]."'></td></tr>\n";
404     
405     if ($db_type=="postgres7") {
406        echo "<tr><td>Directory for exchange of files between the webdaemon and the postgres daemon. Both should be able to read and write here. </td>";
407        if (!$system_settings["tmpdirpsql"])
408           $system_settings["tmpdirpsql"]="/tmp";
409        echo "<td><input type='text' $dirsizestring name='tmpdirpsql' value='".$system_settings["tmpdirpsql"]."'></td></tr>\n";
410     }
411     
412     echo "<tr><td>Server URL.</td>\n ";
413     if (!$system_settings["baseURL"]) {
414        $system_settings["baseURL"]="http://".getenv("SERVER_NAME");
415     }
416     echo "<td><input type='text' $dirsizestring name='baseURL' value='".$system_settings["baseURL"]."'></td></tr>\n";
417        
418     echo "<tr><td>URL to return to after logging out.\n ";
419     echo "(Try: http://".getenv("SERVER_NAME").")</td>\n";
420     echo "<td><input type='text' $dirsizestring name='homeURL' value='".$system_settings["homeURL"]."'></td></tr>\n";
421 
422     echo "<tr><td colspan='2' align='center'><i>Files with new additions</i>\n";
423     echo "<br>Certain modules can write a file with information about the last added record. You could show this information on a webpage. If you don't use this, leave blank.</th></tr>\n";
424     echo "<tr><td>New addition file for protocols.</td>\n ";
425     echo "<td><input type='text' $dirsizestring name='protocols_file' value='".$system_settings["protocols_file"]."'></td></tr>\n";
426     echo "<tr><td>New addition file for pdfs.</td>\n ";
427     echo "<td><input type='text' $dirsizestring name='pdfs_file' value='".$system_settings["pdfs_file"]."'></td></tr>\n";
428     
429     echo "<tr><td colspan='2' align='center'><i>Helper Applications</i></th></tr>\n";
430     echo "<tr><td>wvHtml (used to convert MSWord files into HTML):</td>\n";
431     if (!$system_settings["word2html"]) {
432        $temp=`which wvHtml`;
433        $tok=strtok($temp," ");
434        if (!strtok(" "))
435           $system_settings["word2html"]=$tok;
436     }
437     echo "<td><input type='text' $dirsizestring name='word2html' value='".$system_settings["word2html"]."'></td></tr>\n";
438 
439     echo "<tr><td>Ghostscript (gs, needed to index pdf files):</td>\n";
440     if (!$system_settings["gs"]) {
441        $temp=`which gs`;
442        $tok=strtok($temp," ");
443        if (!strtok(" "))
444           $system_settings["gs"]=$tok;
445     }
446     echo "<td><input type='text' $dirsizestring name='gs' value='".$system_settings["gs"]."'></td></tr>\n";
447 
448     echo "<tr><td>Imagemagick's convert (convert, needed for images):</td>\n";
449     if (!$system_settings["convert"]) {
450        $temp=`which convert`;
451        $tok=strtok($temp," ");
452        if (!strtok(" "))
453           $system_settings["convert"]=$tok;
454     }
455     echo "<td><input type='text' $dirsizestring name='convert' value='".$system_settings["convert"]."'></td></tr>\n";
456 
457 
458     echo "<tr><td colspan='2' align='center'><i>Localization</i></th></tr>\n";
459     echo "<tr><td>Date Format:</td>\n";
460     $query="SELECT dateformat,id FROM dateformats ORDER BY sortkey";
461     $r=$db->Execute($query);
462     echo "\n<td>";
463     echo $r->GetMenu2('dateformat',$system_settings['dateformat'],false);
464     echo "</td></tr>\n";
465 
466     echo "<tr><td colspan='2' align='center'><i>Login Options</i></th></tr>\n";
467     echo "<tr><td>Is PhpLabWare accessible through a secure server? ";
468     echo "If so, passwords will be encrypted while in transit.\n";
469     echo "Do <b>not</b> enter yes if you don't have a secure server.</td>\n";
470     echo "<td>";
471     if ($system_settings['secure_server'])
472        echo "Yes <input type='radio' name='secure_server_new' checked value='Yes'>
473              &nbsp&nbsp No<input type='radio' name='secure_server_new' value='No'>
474              \n";
475     else
476        echo "Yes <input type='radio' name='secure_server_new' value='Yes'>
477              &nbsp&nbsp No<input type='radio' name='secure_server_new' checked
478              value='No'>\n";
479     echo "</td></tr>\n";
480     echo "<tr><td>Authentification method. For PAM you will need the utility 'testpwd' available <a href='http://sourceforge.net/project/showfiles.php?group_id=17393'>here</a>. </td>";
481     $query="SELECT method,id FROM authmethods";
482     $r=$db->Execute($query);
483     echo "\n<td>";
484     echo $r->GetMenu2('authmethod',$system_settings['authmethod'],false);
485     echo "</td></tr>\n";
486     echo "<tr><td>(When using PAM:) Location of check_pwd. ";
487     echo "Please use this only in conjunction with the sudo command</td>\n";
488     echo "<td>\n";
489     $checkpwd=$system_settings['checkpwd'];
490     echo "<input type='text' name='checkpwd' value='$checkpwd'></td></tr>\n";
491 
492     echo "<tr><td colspan='2' align='center'><i>Pdfs</i></th></tr>\n";
493     echo "<tr><td>GET variable to add to Pubmed request (for instance: 'holding=ucsflib')</td>";
494     $pdfget=$system_settings['pdfget'];
495     echo "<td><input type='text' $dirsizestring name='pdfget' value='$pdfget'></td></tr>\n";
496 
497     echo "<tr><td colspan=2 align='center'><input align=center type=submit
498           name=action value=submit></td></tr>\n";
499 
500     echo "</table>\n</form>\n";
501     printfooter();
502  }
503 
504  ?>


Generated: Sun Oct 5 21:17:35 2003 SourceForge Logo Generated by PHPXref 0.2