3 /* Copyright (c) 2007-08 Kyle Osborn, Alec Henriksen
4 * phpns is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public Licence (GPL) as published by the Free
6 * Software Foundation; either version 2 of the Licence, or (at your option) any
8 * Please see the GPL at http://www.gnu.org/copyleft/gpl.html for a complete
9 * understanding of what this license means and how to abide by it.
12 //check to see if it's installed already
13 include("../inc/config.php");
14 if ($globalvars['installed'] == "yes") {
15 die("Phpns seems to have been installed already. Switch the <code>\$globalvars['installed']</code> to \"no\" in <code>../inc/config.php</code>.");
18 //unset for include above, don't want any conflicts!
22 //constant proclaiming installation in progress
23 define("INSTALLING",1);
27 function db_form($data=NULL) {
28 global $error_message;
30 if (!$data['db_tableprefix']) {
31 $data['db_tableprefix'] = 'phpns_';
33 if (!$data['db_host']) {
34 $data['db_host'] = 'localhost';
39 <form action="index.php?step=2" method="post">
41 <h3>Database information</h3>
43 <label for="type">Database type</label>
44 <select id="type" style="width: 400px">
45 <optgroup label="Select a database type...">
46 <option>mySQL database</option>
50 <label for="db_host">Database host*</label>
51 <input type="text" name="db_host" value="'.$data['db_host'].'" /> (Usually "localhost")
54 <label for="db_user">Database user*</label>
55 <input type="text" name="db_user" value="'.$data['db_user'].'" />
58 <label for="db_password">DB user password</label>
59 <input type="password" name="db_password" value="'.$data['db_password'].'" />
62 <label for="db_name">Database name*</label>
63 <input type="text" name="db_name" value="'.$data['db_name'].'" />
66 <label for="db_tableprefix">Table prefix</label>
67 <input type="text" name="db_tableprefix" value="'.$data['db_tableprefix'].'" />
69 <h3>Admin information</h3>
71 <label for="username">Admin username*</label>
72 <input type="text" name="username" value="'.$data['username'].'" />
74 <label for="username">Admin email*</label>
75 <input type="text" name="email" value="'.$data['email'].'" />
78 <label for="password">Admin password*</label>
79 <input type="password" name="password" value="'.$data['password'].'" />
82 <label for="c_password">Confirm password*</label>
83 <input type="password" name="c_password" value="'.$data['c_password'].'" />
86 <h4>Advanced (<a href="javascript:expand(\'adv\');">expand/collapse</a>)</h4>
87 <div id="adv" class="advanced" style="display: none;">
89 <label for="create">Create DB</label><input type="checkbox" name="create" id="create" value="create" /> Phpns will attempt to create the database from scratch.<br /><br />
90 <label for="existing">Existing DB</label><input type="checkbox" name="existing" id="existing" value="existing" /> This is an existing phpns database. Check so phpns will not erase/overwrite/append data to database.<br /><br />
91 <label for="overwrite">Overwrite DB</label><input type="checkbox" name="overwrite" id="overwrite" value="overwrite" /> Overwrite and destroy existing data in phpns database.<br />
96 <input type="submit" id="submit" value="Continue" />
105 $step = $_GET['step'];
109 $license_txt = file_get_contents("../docs/LICENSE");
111 <form action="index.php?step=1" method="post">
112 <textarea style="width: 100%; height: 200px;" readonly="readonly">
117 <input type="submit" id="submit" value="Continue" />
121 } elseif ($step == 1) { //step 1
122 //If upgrade is selected, then go directly to upgrade
123 if($_POST[upgrade
] == TRUE){
124 header("location: upgrade.php");
127 $content = db_form();
129 } elseif ($step == 2) { //step 2 : check data.
130 //get data from post, now we'll verify...
132 //set continue to TRUE, then we'll make sure everything is ok
134 foreach ($data as $key=>$value) {
135 if ($value == NULL && $key != 'db_tableprefix' && $key != 'db_password' && $key != 'existing') {
138 $error_message = '<div class="warning">You need to fill out all the required fields.</div>';
142 if ($data['password'] && ($data['password'] != $data['c_password'])) {
143 $error_message .= '<div class="warning">Your passwords do not match.</div>';
145 } elseif ($data['password']) {
146 $data['password'] = sha1($data['password']);
149 if ($continue == TRUE) { //if all fields are full, we move on to verification. First, we'll do the db stuff.
150 if (!$connection = @mysql_connect
($data['db_host'], $data['db_user'], $data['db_password'])) {
151 $error_message .= '<div class="warning">We could not connect to the database ('.$data['db_host'].') with the information you provided. This is most likely due to a misspelled username or password. If you are sure you provided correct information, the user you are using probably doesn\'t exist on the server you specified.</div>';
155 if ($continue == TRUE && $_POST['create'] != NULL) {
156 if (!mysql_query('CREATE DATABASE '.$data['db_name'].'', $connection)) {
157 $error_message .= '<div class="warning">Phpns tried to create a database named "'.$data['db_name'].'", but was unsuccessful. Mysql said: "'.mysql_error().'".</div>';
161 if (!@mysql_select_db
($data['db_name'], $connection) && $continue == TRUE) {
162 $error_message .= '<div class="warning">We could not find the database ('.$data['db_name'].') you specified. You might have spelled the database wrong, or, you are not connected to a database (you would recieve a previous error if this was the case).</div>';
166 //if connection is active, insert data
167 if ($continue == TRUE && $_POST['existing'] == NULL) {
168 include_once("install.inc.php");
174 if ($continue == FALSE) {
175 //if there were errors, we're going to redisplay the form with errors (inside the function)
176 $content = db_form($data);
178 } elseif ($continue == TRUE) {
179 //else if we have no errors, we serialize the $data, and head over to ?step=3
180 $data = serialize($data);
181 $data = str_replace('"',"'", $data); //replace all "s with 's as to be xhtml compliant in hidden form
182 $url = str_replace('install/index.php','',$_SERVER['PHP_SELF']);
184 <h3>Configuration finished</h3>
185 <p>You have filled in all the fields in the previous step successfully. Now, we need to write the configuration to the phpns config.php file, so it can be used globally across the whole system. But, before we can do this, we need you to give this script proper permissions. Please do the following:
187 <li>Using your favorite FTP application, login to your website directory, and navigate to where you uploaded the phpns system ('.$url.').</li>
188 <li>Now, you need to navigate to: /inc</li>
189 <li>Select the config.php file</li>
190 <li>Change the permissions of the file so phpns can write to the file. Right click the file, and navigate to the file permissions tab/section. You should "tick" the boxes next to "read", and "write". If the server allows you to supply a numeric value, use 0777, or 777. Note, this may be unnessary; phpns might already have the correct permissions.
192 <li>If you are using an FTP client, right click the config.php file and search for an option named "CHMOD". Give a value of 0777.</li>
195 <li>Return to this installation guide, and press continue.</li>
197 <form action="index.php?step=3" method="post">
198 <input type="hidden" name="config" value="'.$data.'" />
200 <input type="submit" id="submit" value="Continue" />
206 } elseif ($step == 3) { //else if step 3
208 //unserialize string passed through form, get back array
209 $data = unserialize(str_replace("'",'"',stripslashes($_POST['config'])));
214 /* Copyright (c) 2007-08 Alec Henriksen
215 * phpns is free software; you can redistribute it and/or modify it under the
216 * terms of the GNU General Public Licence (GPL) as published by the Free
217 * Software Foundation; either version 2 of the Licence, or (at your option) any
219 * Please see the GPL at http://www.gnu.org/copyleft/gpl.html for a complete
220 * understanding of what this license means and how to abide by it.
223 //This is the file generated by the installation. Copy and paste this into the /inc/config.php file. If neceessary, you should edit anything needed below.
225 //The host is where the mySQL database is stored. Usually localhost.
226 $databaseinfo[\'host\'] = "'.$data['db_host'].'";
229 //The user your database is assigned to.
230 $databaseinfo[\'user\'] = "'.$data['db_user'].'";
233 //The password of your mysql user.
234 $databaseinfo[\'password\'] = "'.$data['db_password'].'";
237 //The database name that phpns will use.
238 $databaseinfo[\'dbname\'] = "'.$data['db_name'].'";
241 //The table prefix defined for each table in the database.
242 $databaseinfo[\'prefix\'] = "'.$data['db_tableprefix'].'";
245 //This should be "yes" if you have completed the phpns installation.
246 $globalvars[\'installed\'] = "yes";
249 //Activates the global debugging system for phpns. Change to "yes" to activate
250 $globalvars[\'debug\'] = "no";
254 if ($filec = @fopen
("../inc/config.php",'w')) { //if we can open
255 //if we can open the file for reading...
256 if (!@fwrite
($filec, $fcontent)) {
257 $error_message .= '<div class="warning">We opened the config.php file, but we could not write to it. This is probably because you did not set the file permissions correctly.</div>';
261 $error_message .= '<div class="warning">We could not open the config.php file to edit with your configuration options. The file permissions probably are not set correctly.</div>';
265 //if problems with writing to file, give them the code to edit the file themselves.
266 if ($continue == FALSE) {
268 <h3>Error writing to "inc/config.php"</h3>
269 <p>We could not edit the file with your configuration. This is probably due to wrong file permissions. You can try to set the permissions again (to 0777), and refresh this page. However, if you do not know how to set file permissions, you can open the file on the server, and replace everything in the file with the following:</p>
270 <textarea style="" readonly="readonly">'.$fcontent.'</textarea>
276 <p>We have successully edited the config.php file with your configuration, and created the database structure. Installation is complete, here is what you do:</p>
278 <li>Open your FTP or File browser on the server</li>
279 <li>Navigate to the phpns directory, and <strong>DELETE</strong> the /install directory</li>
280 <li>Navigate to the <a href="../login.php">login page</a>, and login with your recently created admin account</li>
282 <p>A copy of the config.php file is attached below for your reference.</p>
283 <textarea readonly="readonly">'.$fcontent.'</textarea>
288 include("install.tmp.php");