install/index.php
author rejo
Mon, 28 Apr 2008 19:12:51 +0000
changeset 145 6190c9a5f48b
parent 142 edd0c3ee3e1d
child 146 0756319df2d0
permissions -rw-r--r--
[feladat @ 251] Fixed a small problem in the database scheme that is created by the install procedure.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
142
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     1
<?php
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     2
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     3
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     4
echo "<html>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     5
echo " <head>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     6
echo "  <title>Poweradmin</title>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     7
echo "  <link rel=stylesheet href=\"../style/example.inc.php\" type=\"text/css\">\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     8
echo " </head>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
     9
echo " <body>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    10
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    11
if (!isset($_POST['step']) || !is_numeric($_POST['step'])) {
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    12
	$step = 1;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    13
} else {
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    14
	$step = $_POST['step'];
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    15
}
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    16
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    17
echo "  <h1>Poweradmin</h1>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    18
echo "  <h2>Installation step " . $step . "</h2>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    19
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    20
switch($step) {
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    21
	case 1:
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    22
		$step++;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    23
		echo "<p>This installer expects you to have a PowerDNS database accessable from this server. This installer also expects you to have never ran Poweradmin before, or that you want to overwrite the Poweradmin part of the database. If you have had Poweradmin running before, any data in the following tables will be destroyed:</p>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    24
		echo "<ul><li>perm_items</li><li>perm_templ</li><li>perm_templ_items</li><li>users</li><li>zones</li></ul>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    25
		echo "<p>This installer will, of course, not touch the data in the PowerDNS tables of the database. However, it is, of course, recommended you create a backup of your database before proceeding.</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    26
		echo "<p>Finaly, if you see any errors during the installation process, a problem report would be. You can report problems (and ask for help) on the <a href=\"https://www.poweradmin.org/trac/wiki/Mailinglists\">poweradmin-users</a> mailinglist or you can create <a href=\"https://www.poweradmin.org/trac/newticket\">a ticket</a> in the ticketsystem.</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    27
		echo "<p>Do you want to proceed now?</p>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    28
		echo "<form method=\"post\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    29
		echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    30
		echo "<input type=\"submit\" name=\"submit\" value=\"Go to step " . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    31
		echo "</form>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    32
		break;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    33
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    34
	case 2:	
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    35
		$step++;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    36
		echo "<p>To prepare the database for using Poweradmin, the installer needs to modify the PowerDNS database. It'll add a number of tables and it'll fill these tables with some data. If the tables are already present, the installer will drop them first.</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    37
		echo "<p>To do all of this, the installer needs to access the database with an account which has sufficient rights. If you trust the installer, you may give it the username and password of the database user root. Otherwise, make sure the user has enough rights, before actually proceeding.</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    38
		echo "<form method=\"post\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    39
		echo "<table>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    40
		echo "<tr><td>Username</td><td><input type=\"text\" name=\"user\" value=\"\"></td><td>The username to use to connect to the database, make sure the username has sufficient rights to perform administrative task to the PowerDNS database (e.g. \"root\").</td></tr>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    41
		echo "<tr><td>Password</td><td><input type=\"password\" name=\"pass\" value=\"\"></td><td>The password for this username.</td></tr>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    42
		echo "<tr><td>Hostname</td><td><input type=\"text\" name=\"host\" value=\"\"></td><td>The hostname on which the PowerDNS database resides. Frequently, this will be \"localhost\".</td></tr>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    43
		echo "<tr><td>Database</td><td><input type=\"text\" name=\"name\" value=\"\"></td><td>The name of the PowerDNS database.</td></tr>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    44
		echo "</table>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    45
		echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    46
		echo "<input type=\"submit\" name=\"submit\" value=\"Go to step " . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    47
		echo "</form>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    48
		break;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    49
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    50
	case 3:
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    51
		$step++;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    52
		echo "<p>Updating database... ";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    53
		include_once("../inc/config-me.inc.php");
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    54
		include_once("database-structure.inc.php");
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    55
		$db_user = $_POST['user'];
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    56
		$db_pass = $_POST['pass'];
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    57
		$db_host = $_POST['host'];
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    58
		$db_name = $_POST['name'];
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    59
		$db_type = "mysql";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    60
		require_once("../inc/database.inc.php");
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    61
		$db = dbConnect();
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    62
		$db->loadModule('Manager');
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    63
		$db->loadModule('Extended');
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    64
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    65
		$current_tables = $db->listTables();
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    66
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    67
		foreach ($def_tables as $table) {
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    68
			if (in_array($table['table_name'], $current_tables)) $db->dropTable($table['table_name']);
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    69
			$db->createTable($table['table_name'], $table['fields']);
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    70
		}
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    71
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    72
		$fill_perm_items = $db->prepare('INSERT INTO perm_items VALUES (?, ?, ?)');
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    73
		$db->extended->executeMultiple($fill_perm_items, $def_permissions);
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    74
		$fill_perm_items->free();
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    75
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    76
		foreach ($def_remaining_queries as $query) {
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    77
			$db->query($query);
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    78
		}
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    79
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    80
		echo "done!</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    81
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    82
		echo "<p>We have now updated the PowerDNS database to work with Poweradmin. You now want to give limited rights to Poweraadmin so it can update the data in the tables. To do this, you should create a new user and give it rights to select, delete, insert and update records in the PowerDNS database. In MySQL should now perform the following command:</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    83
		echo "<p><tt>GRANT SELECT, INSERT, UPDATE, DELETE<BR>ON powerdns-database.*<br>TO 'poweradmin-user'@'localhost'<br>IDENTIFIED BY 'poweradmin-password';</tt></p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    84
		echo "<p>On PgSQL you would use:</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    85
		echo "<p><tt>$ createuser poweradmin-user<br>Shall the new role be a superuser? (y/n) n<br>Shall the new user be allowed to create databases? (y/n) n<br>Shall the new user be allowed to create more new users? (y/n) n<br>CREATE USER<br>$ psql powerdns-database<br>psql> GRANT  SELECT, INSERT, DELETE, UPDATE<br>ON powerdns-database<br>TO poweradmin-user;</tt></p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    86
		echo "<p>After you have added the new user, proceed with this installation procedure.</p>\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    87
		echo "<form method=\"post\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    88
		echo "<input type=\"hidden\" name=\"host\" value=\"" . $db_host . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    89
		echo "<input type=\"hidden\" name=\"name\" value=\"" . $db_name . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    90
		echo "<input type=\"hidden\" name=\"type\" value=\"" . $db_type . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    91
		echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    92
		echo "<input type=\"submit\" name=\"submit\" value=\"Go to step " . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    93
		echo "</form>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    94
		break;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    95
	
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    96
	case 4:
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    97
		$step++;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    98
		$db_host = $_POST['host'];
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
    99
		$db_name = $_POST['name'];
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   100
		$db_type = $_POST['type'];
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   101
		echo "<p>Now we will put together the configuration. To do so, I need some details:</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   102
		echo "<form method=\"post\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   103
		echo "<table>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   104
		echo "<tr><td>Username</td><td><input type=\"text\" name=\"db_user\" value=\"\"></td><td>The username as created in the previous step.</td></tr>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   105
		echo "<tr><td>Password</td><td><input type=\"text\" name=\"db_pass\" value=\"\"></td><td>The password for this username.</td></tr>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   106
		echo "<tr><td>Hostmaster</td><td><input type=\"text\" name=\"dns_hostmaster\" value=\"\"></td><td>When creating SOA records and no hostmaster is provided, this value here will be used. Should be in the form \"hostmaster.example.net\".</td></tr>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   107
		echo "<tr><td>Primary nameserver</td><td><input type=\"text\" name=\"dns_ns1\" value=\"\"></td><td>When creating new zones using the template, this value will be used as primary nameserver. Should be like \"ns1.example.net\".</td></tr>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   108
		echo "<tr><td>Secondary nameserver</td><td><input type=\"text\" name=\"dns_ns2\" value=\"\"></td><td>When creating new zones using the template, this value will be used as secondary nameserver. Should be like \"ns2.example.net\".</td></tr>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   109
		echo "</table>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   110
		echo "<input type=\"hidden\" name=\"db_host\" value=\"" . $db_host . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   111
		echo "<input type=\"hidden\" name=\"db_name\" value=\"" . $db_name . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   112
		echo "<input type=\"hidden\" name=\"db_type\" value=\"" . $db_type . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   113
		echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   114
		echo "<input type=\"submit\" name=\"submit\" value=\"Go to step " . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   115
		echo "</form>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   116
		break;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   117
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   118
	case 5:
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   119
		$step++;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   120
		echo "<p>The configuration is printed here. You should now create the file " . $local_config_file . " in the Poweradmin root directory yourself. It should contain the following few lines:</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   121
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   122
		echo "<pre>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   123
		echo "\$db_host\t\t= \"" . $_POST['db_host'] . "\";\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   124
			"\$db_user\t\t= \"" . $_POST['db_user'] . "\";\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   125
			"\$db_pass\t\t= \"" . $_POST['db_pass'] . "\";\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   126
			"\$db_name\t\t= \"" . $_POST['db_name'] . "\";\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   127
			"\$db_type\t\t= \"" . $_POST['db_type'] . "\";\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   128
			"\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   129
			"\$dns_hostmaster\t\t= \"" . $_POST['dns_hostmaster'] . "\";\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   130
			"\$dns_ns1\t\t= \"" . $_POST['dns_ns1'] . "\";\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   131
			"\$dns_ns2\t\t= \"" . $_POST['dns_ns2'] . "\";\n" .
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   132
			"\n";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   133
		echo "</pre>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   134
		echo "<form method=\"post\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   135
		echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   136
		echo "<input type=\"submit\" name=\"submit\" value=\"Go to step " . $step . "\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   137
		echo "</form>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   138
		break;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   139
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   140
	case 6:
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   141
		$step++;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   142
		echo "<p>Now we have finished the configuration, you should remove the directory \"install/\" from the Poweradmin root directory. You will not be able to use the file if it exists. Do it now.</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   143
		echo "<p>After you have removed the file, you can login to <a href=\"index.php\">Poweradmin</a> with username \"admin\" and password \"admin\". You are highly encouraged to change these as soon as you are logged in.</p>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   144
		break;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   145
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   146
	default:
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   147
		break;
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   148
}
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   149
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   150
echo "<div class=\"footer\">";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   151
echo "<a href=\"https://www.poweradmin.org/\">a complete(r) <strong>poweradmin</strong></a> - <a href=\"https://www.poweradmin.org/trac/wiki/Credits\">credits</a>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   152
echo "</div></body></html>";
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   153
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   154
?>
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   155
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   156
edd0c3ee3e1d [feladat @ 248]
rejo
parents:
diff changeset
   157