PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/install.php

http://freshdns.googlecode.com/
PHP | 157 lines | 145 code | 10 blank | 2 comment | 0 complexity | 0c7360184f60ed82661a612c13920895 MD5 | raw file
  1<?
  2switch($_GET['p'])
  3{
  4	default:
  5		echo '<form method="post" action="install.php?p=do_install">
  6		<table>
  7		  <tr>
  8		    <td>Database type:</td>
  9			<td><select name="db_type">
 10			<option value="mysql">MySQL</option>
 11			<option value="postgresql">PostgreSQL</option>
 12			</select></td>
 13		  </tr>
 14		  <tr>
 15		    <td>Database host:</td>
 16			<td><input type="text" name="db_host" value="localhost"></td>
 17		  </tr>
 18		  <tr>
 19		    <td>Database username:</td>
 20			<td><input type="text" name="db_user" value="pdns"></td>
 21		  </tr>
 22		  <tr>
 23		    <td>Database password:</td>
 24			<td><input type="text" name="db_pass" value=""></td>
 25		  </tr>
 26		  <tr>
 27		    <td>Database database:</td>
 28			<td><input type="text" name="db_base" value="pdns"></td>
 29		  </tr>
 30		  <tr>
 31		    <td>&nbsp;</td>
 32			<td>&nbsp;</td>
 33		  </tr>
 34		  <tr>
 35		    <td>Nameserver 1:</td>
 36			<td><input type="text" name="ns0" value="ns0.example.com"></td>
 37		  </tr>
 38		  <tr>
 39		    <td>Nameserver 2:</td>
 40			<td><input type="text" name="ns1" value="ns1.example.com"></td>
 41		  </tr>
 42		  <tr>
 43		    <td>Nameserver 3:</td>
 44			<td><input type="text" name="ns2" value="ns2.example.com"></td>
 45		  </tr>
 46		  <tr>
 47		    <td>Hostmaster:</td>
 48			<td><input type="text" name="hostmaster" value="hostmaster@example.com"></td>
 49		  </tr>
 50		  <tr>
 51		    <td>&nbsp;</td>
 52			<td>&nbsp;</td>
 53		  </tr>
 54		  <tr>
 55		    <td><input type="submit" name="submit" value="Install"></td>
 56			<td>&nbsp;</td>
 57		  </tr>
 58		</table></form>';
 59	break;
 60	
 61	case "do_install":
 62		echo 'Copy the following <b>over</b> the original in config.inc.php<br /><br />
 63		
 64		<b>Database settings</b>
 65		
 66		<textarea name="configsettings" cols="150" rows="15">
 67$config[\''.$_POST['db_type'].'\'][\'use\']						= true;
 68$config[\''.$_POST['db_type'].'\'][\'username\']					= \''.$_POST['db_user'].'\';
 69$config[\''.$_POST['db_type'].'\'][\'password\']					= \''.$_POST['db_pass'].'\';	
 70$config[\''.$_POST['db_type'].'\'][\'database\']					= \''.$_POST['db_base'].'\';
 71$config[\''.$_POST['db_type'].'\'][\'master_host\']					= \''.$_POST['db_host'].'\';
 72$config[\''.$_POST['db_type'].'\'][\'slave_hosts\']					= array(\''.$_POST['db_host'].'\',\''.$_POST['db_host'].'\'); // DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING!
 73$config[\''.$_POST['db_type'].'\'][\'use_replication\']				= \'0\';	// DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING!
 74</textarea>
 75		
 76		<textarea name="configsettings2" cols="150" rows="10">
 77$config[\'DNS\'][\'ns0\']						= \''.$_POST['ns0'].'\';
 78$config[\'DNS\'][\'ns1\']						= \''.$_POST['ns1'].'\';
 79$config[\'DNS\'][\'ns2\']						= \''.$_POST['ns2'].'\';
 80$config[\'DNS\'][\'hostmaster\']					= \''.$_POST['hostmaster'].'\';
 81		</textarea>
 82		
 83		Done? Save and upload the editted file. <a href="install.php?p=install_db">Next step</a>';
 84	break;
 85	
 86	case "install_db":
 87		include_once("config.inc.php");
 88		include_once("./class/class.install.php");
 89		
 90		$install = new install ($config['database']);
 91		$install->pdns_sql();
 92		$install->padmin_sql();
 93		
 94		echo '<form method="post" action="install.php?p=do_add_admin">
 95		<table>
 96		  <tr>
 97		    <td>Username:</td>
 98			<td><input type="text" name="username" value=""></td>
 99		  </tr>
100		  <tr>
101		    <td>Password:</td>
102			<td><input type="password" name="password" value=""></td>
103		  </tr>
104		  <tr>
105		    <td>Name:</td>
106			<td><input type="text" name="fullname" value=""></td>
107		  </tr>
108		  <tr>
109		    <td>E-mail address:</td>
110			<td><input type="text" name="email" value=""></td>
111		  </tr>
112		  <tr>
113		    <td>Description:</td>
114			<td><input type="text" name="description" value=""></td>
115		  </tr>
116		  <tr>
117		    <td>&nbsp;</td>
118			<td>&nbsp;</td>
119		  </tr>
120		  <tr>
121		    <td><input type="submit" name="submit" value="Create admin account"></td>
122			<td>&nbsp;</td>
123		  </tr>
124		</table></form>';
125	break;
126	
127	case "do_add_admin":
128		include_once("config.inc.php");
129		include_once("./class/class.install.php");
130		
131		try
132		{
133			$_SESSION['level'] = 10;
134			
135			$manager = new manager ($config['database']);
136			$install = new install ($config['database']);
137			$userId = $manager->addUser ($_POST['username'], md5($_POST['password']), $_POST['fullname'], $_POST['email'], $_POST['description'], 10, 1);
138			
139			// LET'S FIND SOME ZONELESS DOMAINS!
140			$records = $install->zonelessdomains();
141			foreach($records AS $r)
142			{
143				// ADD A ZONE FOR THAT SILLY DOMAIN
144				$manager->addZone($r['id'], $userId, "");
145			}
146			
147			session_destroy();
148			
149			echo "Admin account added. <b><font color=\"red\">Please remove install.php and ./class/class.install.php from the webserver!</font></b><br /><br />
150			Installation done!";
151		}catch(Exception $ex)
152		{
153			echo $ex->getMessage();
154		}
155	break;
156}
157?>