fixing up the "is setup" check in the installer
[gwvp.git] / gwvplib / gwvpsetup.php
1 <?php
2 $CALL_ME_FUNCTIONS["setup"] = "gwvp_SetupCall";
3
4
5 function gwvp_SetupCall()
6 {
7         if(isset($_REQUEST["q"])) {
8                 $query = $_REQUEST["q"];
9                 if($query == "postsetup") return "gwvp_PostSetup";
10                 else return false;
11         }
12         
13         return false;
14         
15 }
16
17 function gwvp_PostSetup()
18 {
19         gwvp_goMainPage("gwvp_PostSetupPageBody");
20 }
21
22 function gwvp_PostSetupPageBody()
23 {
24         echo "GWVP Is now setup, login at the top of the page and you should be in control!";
25 }
26
27 // TODO: need to do this bit
28 function gwvp_issetup()
29 {
30         // check for the config file
31         if(!file_exists("config.php")) return false;
32          
33         return gwvp_isDBSetup();
34 }
35
36
37 function gwvp_goSetup()
38 {
39         global $BASE_URL;
40         
41         if(isset($_REQUEST["install"])) {
42                 switch($_REQUEST["install"]) {
43                         case "tryinstall":
44                                 gwvp_goSetupDoInstall();
45                                 break;
46                         default:
47                                 gwvp_goSetupGoMain();
48                                 break;
49                                 
50                 }
51         } else {
52                 header("Location: $BASE_URL/?install=begin");
53         }
54 }
55
56 function gwvp_goSetupGoMain()
57 {
58         
59         // interesting, TODO: need a non-unix dependant way of doing this
60         $webusername = exec("whoami");
61         
62         $defrepoloc = "/var/lib/gwvp/gitrepos";
63         $defdataloc = "/var/lib/gwvp/data";
64         
65         $repodata = "$defrepoloc";
66         if(file_exists("$defrepoloc")) {
67                 $repodata .= " exists";
68                 if(is_writable("$defrepoloc")) {
69                         $repodata .= " and is wriable - this is ok as it is";
70                 } else {
71                         $repodata .= " but is not writable - needs permissions for the web user";
72                 }
73         } else $repodata .= " does not exist (needs to be created)";
74
75         $datadata = "$defdataloc";
76         if(file_exists("$defdataloc")) {
77                 $datadata .= " exists";
78                 if(is_writable("$defdataloc")) {
79                         $datadata .= " and is wriable - this is ok as it is";
80                 } else {
81                         $datadata .= " but is not writable - needs permissions for the web user";
82                 }
83         } else $datadata .= " does not exist (needs to be created)";
84         
85         echo "<html><body><h1>Welcome to the GWVP setup Page</h1>";
86         echo "Fill out the form below and lets get started<br>";
87         
88         echo "<form method=\"post\"><table>";
89         echo "<input type=\"hidden\" name=\"install\" value=\"tryinstall\">";
90         echo "<tr><td>Site Name</td><td><input type=\"text\" name=\"sitename\"></td><td>Some Name for your site</td></tr>";
91         echo "<tr><td>First User Full Name</td><td><input type=\"text\" name=\"firstuserfullname\"></td><td>The name of the admin of your site</td></tr>";
92         echo "<tr><td>First User email address</td><td><input type=\"text\" name=\"firstuseremail\"></td><td>The email address of the admin of your site (login)</td></tr>";
93         echo "<tr><td>First User Username</td><td><input type=\"text\" name=\"firstuserusername\"></td><td>The name used to idenity the user on the site</td></tr>";
94         echo "<tr><td>First User Password</td><td><input type=\"text\" name=\"pass1\"></td><td>Password for the user</td></tr>";
95         echo "<tr><td>First User Password (confirm)</td><td><input type=\"text\" name=\"pass2\"></td><td>and confirm it...</td></tr>";
96         echo "<tr><td>Database Type</td><td><select name=\"dbtype\"><option value=\"sqlite\">SQLite</option></select></td><td>SQLite only at this point</td></tr>";
97         echo "<tr><td>Database name</td><td><input type=\"text\" name=\"dbname\" value=\"gvwp\"></td><td>For SQLite, this is simple the file on disk</td></tr>";
98         echo "<tr><td>GIT repository storage Location</td><td><input type=\"text\" name=\"repoloc\" value=\"$defrepoloc\"></td><td>The location (on disk) of the repos - you need to create this (see below)</td><td><i><b>Note: $repodata</b></i></td></tr>";
99         echo "<tr><td>Data storage Location</td><td><input type=\"text\" name=\"dataloc\" value=\"$defdataloc\"></td><td>The location (on disk) where the database for this site is stored - you need to create this (see below)</td><td><i><b>Note: $datadata</b></i></td></tr>";
100         echo "<tr><td><input type=\"submit\" value=\"Install\" name=\"Install\"></td></tr>";
101         echo "</table></form>";
102         
103         echo "<hr><h2>GIT Repo Storage Location Creation</h2>";
104         echo "<b>GIT Repo Storage Location</b> - A location (accessible by the web user, $webusername) must be created on disk for this application to store git repositories (and only repositories) in.";
105         echo "To do this, do the following (as root or via sudo):<br>";
106         echo "<li>Create a directory - sudo mkdir -p $defrepoloc<br>";
107         echo "<li>Change ownership of the directory to the web user - sudo chown $webusername $defrepoloc<br>";
108         echo "And, your done<br>";
109         
110         
111         echo "<hr><h2>Data Storage Location Creation</h2>";
112         echo "<b>Data Storage Location</b> - A location (accessible by the web user, $webusername) must be created on disk for this application to store data (such as database information) in.";
113         echo "To do this, do the following (as root or via sudo):<br>";
114         echo "<li>Create a directory - sudo mkdir -p $defdataloc<br>";
115         echo "<li>Change ownership of the directory to the web user - sudo chown $webusername $defdataloc<br>";
116         echo "And, your done<br>";
117         echo "</body></html>";
118 }
119
120 function gwvp_goSetupDoInstall()
121 {
122         $sitename = $_REQUEST["sitename"];
123         $fufn = $_REQUEST["firstuserfullname"];
124         $fwem = $_REQUEST["firstuseremail"];
125         $fwusername = $_REQUEST["firstuserusername"];
126         $fwpass = $_REQUEST["pass1"];
127         $fwpassconf = $_REQUEST["pass2"];
128         $dbtype = $_REQUEST["dbtype"];
129         $dbname = $_REQUEST["dbname"];
130         $repoloc = $_REQUEST["repoloc"];
131         $dataloc = $_REQUEST["dataloc"];
132         
133         echo "<html><body>";
134         echo "<table>";
135         echo "<tr><td>Sitename</td><td>$sitename</td></tr>";
136         echo "<tr><td>fullname</td><td>$fufn</td></tr>";
137         echo "<tr><td>email</td><td>$fwem</td></tr>";
138         echo "<tr><td>username</td><td>$fwusername</td></tr>";
139         echo "<tr><td>pass</td><td>$fwpass</td></tr>";
140         echo "<tr><td>passconfirm</td><td>$fwpassconf</td></tr>";
141         echo "<tr><td>dbtype</td><td>$dbtype</td></tr>";
142         echo "<tr><td>dbname</td><td>$dbname</td></tr>";
143         echo "<tr><td>repoloc</td><td>$repoloc</td></tr>";
144         echo "<tr><td>dataloc</td><td>$dataloc</td></tr>";
145         echo "</table>";
146         echo "</body></html>";
147
148 }
149
150
151 ?>