install.php
changeset 82 c255196bc447
parent 81 c72d6d51f3d3
child 83 90fbb34b3d97
equal deleted inserted replaced
81:c72d6d51f3d3 82:c255196bc447
     1 <?php
       
     2 
       
     3 /*  PowerAdmin, a friendly web-based admin tool for PowerDNS.
       
     4  *  See <https://rejo.zenger.nl/poweradmin> for more details.
       
     5  *
       
     6  *  Copyright 2007, 2008  Rejo Zenger <rejo@zenger.nl>
       
     7  *
       
     8  *  This program is free software: you can redistribute it and/or modify
       
     9  *  it under the terms of the GNU General Public License as published by
       
    10  *  the Free Software Foundation, either version 3 of the License, or
       
    11  *  (at your option) any later version.
       
    12  *
       
    13  *  This program is distributed in the hope that it will be useful,
       
    14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16  *  GNU General Public License for more details.
       
    17  *
       
    18  *  You should have received a copy of the GNU General Public License
       
    19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    20  */
       
    21 
       
    22 // addslashes to vars if magic_quotes_gpc is off
       
    23 function slash_input_data(&$data)
       
    24 {
       
    25 	if ( is_array($data) )
       
    26 	{
       
    27 		foreach ( $data as $k => $v )
       
    28 		{
       
    29 			$data[$k] = ( is_array($v) ) ? slash_input_data($v) : addslashes($v);
       
    30 		}
       
    31 	}
       
    32 	return $data;
       
    33 }
       
    34 
       
    35 set_magic_quotes_runtime(0);
       
    36 
       
    37 // If magic quotes is off, addslashes
       
    38 if ( !get_magic_quotes_gpc() )
       
    39 {
       
    40 	$_GET = slash_input_data($_GET);
       
    41 	$_POST = slash_input_data($_POST);
       
    42 	$_COOKIE = slash_input_data($_COOKIE);
       
    43 }
       
    44 
       
    45 
       
    46 error_reporting(E_ALL);
       
    47 if(!@require_once("inc/config.inc.php"))
       
    48 {
       
    49 	error("You have to create a config.inc.php!");
       
    50 }
       
    51 include_once("inc/header.inc.php");
       
    52 
       
    53 $sup_types = array('mysql');
       
    54 
       
    55 function error($msg=false)
       
    56 {
       
    57        	// General function for printing critical errors.
       
    58         if ($msg)
       
    59 	    {
       
    60 		?>
       
    61                 <P><TABLE CLASS="error"><TR><TD CLASS="error"><H2><?php echo _('Oops! An error occured!'); ?></H2>
       
    62        	        <BR>
       
    63                	<FONT STYLE="font-weight: Bold"><?php nl2br($msg) ?><BR><BR><a href="javascript:history.go(-1)">&lt;&lt; back</a></FONT><BR></TABLE>
       
    64                 <?php
       
    65       	        die();
       
    66         }
       
    67 	    else
       
    68 	    {
       
    69        	        die("No error specified!");
       
    70         }
       
    71 }
       
    72 
       
    73 if(isset($_POST["submit"]))
       
    74 {
       
    75 	//$dbtype = $_POST["dbtype"];
       
    76 	require_once("inc/database.inc.php");
       
    77 
       
    78 	if($dbdsntype == "mysql")
       
    79 	{
       
    80 		$sqlusers =	"CREATE TABLE users (
       
    81 				  id int(11) NOT NULL auto_increment,
       
    82 				  username varchar(16) NOT NULL default '',
       
    83 				  password varchar(34) NOT NULL default '',
       
    84 				  fullname varchar(255) NOT NULL default '',
       
    85 				  email varchar(255) NOT NULL default '',
       
    86 				  description text NOT NULL,
       
    87 				  level tinyint(3) NOT NULL default '0',
       
    88 				  active tinyint(1) NOT NULL default '0',
       
    89 				  PRIMARY KEY  (id)
       
    90 				) TYPE=InnoDB";
       
    91 		$sqlzones =	"CREATE TABLE zones (
       
    92   				  id int(11) NOT NULL auto_increment,
       
    93 				  domain_id int(11) NOT NULL default '0',
       
    94 				  owner int(11) NOT NULL default '0',
       
    95 				  comment text,
       
    96 				  PRIMARY KEY  (id)
       
    97 				) TYPE=InnoDB";
       
    98                 $sqlrecowns =   "CREATE TABLE record_owners (
       
    99                                   id int(11) NOT NULL auto_increment,
       
   100                                   user_id int(11) NOT NULL default '0',
       
   101                                   record_id int(11) NOT NULL default '0',
       
   102                                   PRIMARY KEY  (id)
       
   103                                 ) TYPE=InnoDB";
       
   104 	}
       
   105 
       
   106 	// PGSQL Is trivial still, the relations are different.
       
   107 	if($dbdsntype == "pgsql")
       
   108 	{
       
   109 		$sqlusers =	"CREATE TABLE users (
       
   110 				id SERIAL PRIMARY KEY,
       
   111 				username varchar(16) NOT NULL,
       
   112 				password varchar(34) NOT NULL,
       
   113 				fullname varchar(255) NOT NULL,
       
   114 				email varchar(255) NOT NULL,
       
   115 				description text NOT NULL,
       
   116 				level smallint DEFAULT 0,
       
   117 				active smallint DEFAULT 0
       
   118 				)";
       
   119 		$sqlzones =	"CREATE TABLE zones (
       
   120 				id SERIAL PRIMARY KEY,
       
   121 				domain_id integer NOT NULL,
       
   122 				owner integer NOT NULL,
       
   123 				comment text NULL
       
   124 				)";
       
   125                 $sqlrecowns =   "CREATE TABLE record_owners (
       
   126                                 id SERIAL PRIMARY KEY,
       
   127                                 user_id integer NOT NULL,
       
   128                                 record_id integer NOT NULL
       
   129                                 )";
       
   130 	}
       
   131 
       
   132 	if(!empty($_POST['login']) && !empty($_POST['password']) && !empty($_POST['fullname']) && !empty($_POST['email']))
       
   133 	{
       
   134 		// Declare default tables.
       
   135 
       
   136 
       
   137 
       
   138 		// It just tries to rough create. If it flunks.. bad a user exists or the dbase exists.
       
   139 
       
   140 		$resusers = $db->query($sqlusers);
       
   141 
       
   142 		if($db->isError($resusers))
       
   143 		{
       
   144 			error("Can not create table users in $dbdatabase");
       
   145 		}
       
   146 
       
   147 		$reszones = $db->query($sqlzones);
       
   148 
       
   149 		if($db->isError($reszones))
       
   150 		{
       
   151 			error("Can not create zones table in $dbdatabase");
       
   152 		}
       
   153                 $reszones = $db->query($sqlrecowns);
       
   154 
       
   155                 if($db->isError($reszones))
       
   156                 {
       
   157                         error("Can not create record_owners table in $dbdatabase");
       
   158                 }
       
   159 		
       
   160 		$sqlinsert =	"INSERT INTO 
       
   161 					users 
       
   162 					(username, password, fullname, email, description, level, active)
       
   163 				VALUES (
       
   164 					'". $_POST['login'] ."', 
       
   165 					'". md5(stripslashes($_POST['password'])) ."',
       
   166 					'". $_POST["fullname"] ."',
       
   167 					'". $_POST["email"] ."',
       
   168 					'". $_POST["description"] ."',
       
   169 					10,
       
   170 					1)";
       
   171 
       
   172 		$resadmin = $db->query($sqlinsert);
       
   173 
       
   174 		if($db->isError($resadmin))
       
   175 		{
       
   176 
       
   177 			error("Can not add the admin to database $dbdatabase.users");
       
   178 		}
       
   179 		else
       
   180 		{
       
   181 
       
   182 			?>
       
   183 <h2><?php echo _('PowerAdmin has succesfully been installed.'); ?></h2>
       
   184 <br />
       
   185 <?php echo _('Remove this file (install.php) from your webdir.'); ?><br />
       
   186 <b><?php echo _('WARNING'); ?>:</b> <?php echo _('PowerAdmin will not work until you delete install.php'); ?><br />
       
   187 <br />
       
   188 <?php echo _('You can click'); ?> <a href="index.php">here</a> <?php echo _('to start using PowerAdmin'); ?>
       
   189 </BODY></HTML>
       
   190 <?php
       
   191 			die();
       
   192 		}
       
   193 
       
   194 	}
       
   195 	else
       
   196 	{
       
   197 		echo "<DIV CLASS=\"warning\">" . _('You didnt fill in one of the required fields!') . "</DIV>";
       
   198 	}
       
   199 }
       
   200 
       
   201 else
       
   202 {
       
   203 ?>
       
   204 
       
   205 <H2><?php echo _('PowerAdmin for PowerDNS'); ?></H2>
       
   206 <BR>
       
   207 <B><?php echo _('This config file will setup your database to be ready for PowerAdmin. Please fill in the next fields which will create an
       
   208 administrator login.'); ?><BR>
       
   209 <?php echo _('Fields marked with a'); ?> <FONT COLOR="#FF0000">*</FONT> <?php echo _('are required.'); ?>
       
   210 </B><BR><BR>
       
   211 
       
   212 <FORM METHOD="post">
       
   213 <TABLE BORDER="0" CELLSPACING="4">
       
   214 <TR><TD CLASS="tdbg"><?php echo _('Login Name'); ?>:</TD><TD WIDTH="510" CLASS="tdbg"><INPUT TYPE="text" CLASS="input" NAME="login" VALUE=""> <FONT COLOR="#FF0000">*</FONT> </TD></TR>
       
   215 <TR><TD CLASS="tdbg"><?php echo _('Password'); ?>:</TD><TD WIDTH="510" CLASS="tdbg"><INPUT TYPE="password" CLASS="input" NAME="password" VALUE=""> <FONT COLOR="#FF0000">*</FONT> </TD></TR>
       
   216 <TR><TD CLASS="tdbg"><?php echo _('Full name'); ?>:</TD><TD WIDTH="510" CLASS="tdbg"><INPUT TYPE="text" CLASS="input" NAME="fullname" VALUE=""> <FONT COLOR="#FF0000">*</FONT> </TD></TR>
       
   217 <TR><TD CLASS="tdbg"><?php echo _('Email'); ?>:</TD><TD CLASS="tdbg"><INPUT TYPE="text" CLASS="input" NAME="email" VALUE=""> <FONT COLOR="#FF0000">*</FONT> </TD></TR>
       
   218 <TR><TD CLASS="tdbg"><?php echo _('Description'); ?>:</TD><TD CLASS="tdbg"><TEXTAREA ROWS="6" COLS="30" CLASS="inputarea" NAME="description"></TEXTAREA></TD></TR>
       
   219 <TR><TD CLASS="tdbg">&nbsp;</TD><TD CLASS="tdbg"><INPUT TYPE="submit" CLASS="button" NAME="submit" VALUE="<?php echo _('Make Account'); ?>"></TD></TR>
       
   220 </TABLE>
       
   221 </FORM>
       
   222 <?php
       
   223 }
       
   224 include_once('inc/footer.inc.php');
       
   225 ?>