Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. require_once('../inc/error.inc.php');
  3. require_once('../inc/i18n.inc.php');
  4. if (isset($_POST['language'])) {
  5. $language = $_POST['language'];
  6. } else {
  7. $language = "en_EN";
  8. }
  9. # FIXME: setlocale can fail if locale package is not installed ion the systme for that language
  10. setlocale(LC_ALL, $language, $language . '.UTF-8');
  11. $gettext_domain = 'messages';
  12. if (!function_exists('bindtextdomain')) {
  13. die(error('You have to install PHP gettext extension!'));
  14. }
  15. bindtextdomain($gettext_domain, "./../locale");
  16. textdomain($gettext_domain);
  17. @putenv('LANG=' . $language);
  18. @putenv('LANGUAGE=' . $language);
  19. $local_config_file = "../inc/config.inc.php";
  20. function get_random_key() {
  21. $key = '';
  22. $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_+=-][{}';
  23. $length = 46;
  24. $size = strlen($chars);
  25. for ($i = 0; $i < $length; $i++) {
  26. $key .= $chars[mt_rand(0, $size - 1)];
  27. }
  28. return $key;
  29. }
  30. echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
  31. echo "<html>\n";
  32. echo " <head>\n";
  33. echo " <title>Poweradmin</title>\n";
  34. echo " <link rel=stylesheet href=\"../style/example.css\" type=\"text/css\">\n";
  35. echo " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
  36. echo " <script type=\"text/javascript\" src=\"../inc/helper.js\"></script>";
  37. echo " </head>\n";
  38. echo " <body>\n";
  39. if (!isset($_POST['step']) || !is_numeric($_POST['step'])) {
  40. $step = 1;
  41. } else {
  42. $step = $_POST['step'];
  43. }
  44. echo " <h1>Poweradmin</h1>\n";
  45. echo " <h2>" . _('Installation step') . " " . $step . "</h2>\n";
  46. switch ($step) {
  47. case 1:
  48. $step++;
  49. echo " <form method=\"post\" action=\"\">\n";
  50. echo " <input type=\"radio\" name=\"language\" value=\"en_EN\" checked> I prefer to proceed in english.<br>\n";
  51. echo " <input type=\"radio\" name=\"language\" value=\"nl_NL\"> Ik ga graag verder in het Nederlands.<br>\n";
  52. echo " <input type=\"radio\" name=\"language\" value=\"de_DE\"> Ich mache in Deutsch weiter.<br>\n";
  53. echo " <input type=\"radio\" name=\"language\" value=\"ja_JP\"> 日本語で続ける<br>\n";
  54. echo " <input type=\"radio\" name=\"language\" value=\"pl_PL\"> Chcę kontynuować po polsku.<br>\n";
  55. echo " <input type=\"radio\" name=\"language\" value=\"fr_FR\"> Je préfère continuer en français.<br>\n";
  56. echo " <input type=\"radio\" name=\"language\" value=\"nb_NO\"> Jeg ønsker å forsette på norsk.<br>\n";
  57. echo " <input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
  58. echo " <input type=\"submit\" name=\"submit\" value=\"" . _('Go to step') . " " . $step . "\">";
  59. echo " </form>\n";
  60. break;
  61. case 2:
  62. $step++;
  63. 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: perm_items, perm_templ, perm_templ_items, users and zones. This installer will, of course, not touch the data in the PowerDNS tables of the database. However, it is recommended that you create a backup of your database before proceeding.') . "</p>\n";
  64. echo "<p>" . _('The alternative for this installer is a manual installation. Refer to the poweradmin.org website if you want to go down that road.') . "</p>\n";
  65. echo "<p>" . _('Finally, if you see any errors during the installation process, a problem report would be appreciated. You can report problems (and ask for help) on the <a href="http://groups.google.com/group/poweradmin" target=\"blank\">poweradmin</a> mailinglist.') . "</p>";
  66. echo "<p>" . _('Do you want to proceed now?') . "</p>\n";
  67. echo "<form method=\"post\">";
  68. echo "<input type=\"hidden\" name=\"language\" value=\"" . $language . "\">";
  69. echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
  70. echo "<input type=\"submit\" name=\"submit\" value=\"" . _('Go to step') . " " . $step . "\">";
  71. echo "</form>";
  72. break;
  73. case 3:
  74. $step++;
  75. echo "<p>" . _('To prepare the database for using Poweradmin, the installer needs to modify the PowerDNS database. It will add a number of tables and it will fill these tables with some data. If the tables are already present, the installer will drop them first.') . "</p>";
  76. 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>";
  77. echo "<form method=\"post\">";
  78. echo " <table>\n";
  79. echo " <tr id=\"username_row\">\n";
  80. echo " <td>" . _('Username') . "</td>\n";
  81. echo " <td><input type=\"text\" name=\"user\" value=\"\"></td>\n";
  82. echo " <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 (the installer wants to drop, create and fill tables to the database).') . "</td>\n";
  83. echo " </tr>\n";
  84. echo " <tr id=\"password_row\">\n";
  85. echo " <td>" . _('Password') . "</td>\n";
  86. echo " <td><input type=\"password\" name=\"pass\" value=\"\" autocomplete=\"off\"></td>\n";
  87. echo " <td>" . _('The password for this username.') . "</td>\n";
  88. echo " </tr>\n";
  89. echo " <tr>\n";
  90. echo " <td width=\"210\">" . _('Database type') . "</td>\n";
  91. echo " <td>" .
  92. "<select name=\"type\" onChange=\"changePort(this.value)\">" .
  93. "<option value=\"mysql\">MySQL</option>" .
  94. "<option value=\"pgsql\">PostgreSQL</option>" .
  95. "<option value=\"sqlite\">SQLite</option>" .
  96. "</td>\n";
  97. echo " <td>" . _('The type of the PowerDNS database.') . "</td>\n";
  98. echo " </tr>\n";
  99. echo " <tr id=\"hostname_row\">\n";
  100. echo " <td>" . _('Hostname') . "</td>\n";
  101. echo " <td><input type=\"text\" id=\"host\" name=\"host\" value=\"localhost\"></td>\n";
  102. echo " <td>" . _('The hostname on which the PowerDNS database resides. Frequently, this will be "localhost".') . "</td>\n";
  103. echo " </tr>\n";
  104. echo " <tr id=\"dbport_row\">\n";
  105. echo " <td>" . _('DB Port') . "</td>\n";
  106. echo " <td><input type=\"text\" id=\"dbport\" name=\"dbport\" value=\"3306\"></td>\n";
  107. echo " <td>" . _('The port the database server is listening on.') . "</td>\n";
  108. echo " </tr>\n";
  109. echo " <tr>\n";
  110. echo " <td>" . _('Database') . "</td>\n";
  111. echo " <td><input type=\"text\" name=\"name\" value=\"\"></td>\n";
  112. echo " <td><span id=\"db_name_title\">" . _('The name of the PowerDNS database.') . "</span>"
  113. . "<span id=\"db_path_title\" style=\"display: none;\">" . _('The path and filename to the PowerDNS SQLite database.') . "</span></td>\n";
  114. echo " </tr>\n";
  115. echo " <tr>\n";
  116. echo " <td>" . _('Poweradmin administrator password') . "</td>\n";
  117. echo " <td><input type=\"text\" name=\"pa_pass\" value=\"\" autocomplete=\"off\"></td>\n";
  118. echo " <td>" . _('The password of the Poweradmin administrator. This administrator has full rights to Poweradmin using the web interface.') . "</td>\n";
  119. echo " </tr>\n";
  120. echo "</table>\n";
  121. echo "<br>\n";
  122. echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
  123. echo "<input type=\"hidden\" name=\"language\" value=\"" . $language . "\">";
  124. echo "<input type=\"submit\" name=\"submit\" value=\"" . _('Go to step') . " " . $step . "\">";
  125. echo "</form>";
  126. break;
  127. case 4:
  128. $step++;
  129. echo "<p>" . _('Updating database...') . " ";
  130. include_once("../inc/config-me.inc.php");
  131. $db_user = $_POST['user'];
  132. $db_pass = $_POST['pass'];
  133. $db_host = $_POST['host'];
  134. $db_port = $_POST['dbport'];
  135. $db_name = $_POST['name'];
  136. $db_type = $_POST['type'];
  137. if ($db_type == 'sqlite') {
  138. $db_file = $db_name;
  139. }
  140. $pa_pass = $_POST['pa_pass'];
  141. require_once("../inc/database.inc.php");
  142. $db = dbConnect();
  143. $db->loadModule('Manager');
  144. $db->loadModule('Extended');
  145. include_once("database-structure.inc.php");
  146. $current_tables = $db->listTables();
  147. foreach ($def_tables as $table) {
  148. if (in_array($table['table_name'], $current_tables))
  149. $db->dropTable($table['table_name']);
  150. $db->createTable($table['table_name'], $table['fields'], $table['options']);
  151. }
  152. $fill_perm_items = $db->prepare('INSERT INTO perm_items VALUES (?, ?, ?)');
  153. $db->extended->executeMultiple($fill_perm_items, $def_permissions);
  154. if (method_exists($fill_perm_items, 'free')) {
  155. $fill_perm_items->free();
  156. }
  157. foreach ($def_remaining_queries as $user_query) {
  158. $db->query($user_query);
  159. }
  160. echo _('done!') . "</p>";
  161. echo "<p>" . _('Now we will gather all details for the configuration itself.') . "</p>\n";
  162. echo "<form method=\"post\">";
  163. echo " <table>";
  164. echo " <tr>";
  165. if ($db_type != 'sqlite') {
  166. echo " <td>" . _('Username') . "</td>\n";
  167. echo " <td><input type=\"text\" name=\"pa_db_user\" value=\"\"></td>\n";
  168. echo " <td>" . _('The username for Poweradmin. This new user will have limited rights only.') . "</td>\n";
  169. echo " </tr>\n";
  170. echo " <tr>\n";
  171. echo " <td>" . _('Password') . "</td>\n";
  172. echo " <td><input type=\"text\" name=\"pa_db_pass\" value=\"\" autocomplete=\"off\"></td>\n";
  173. echo " <td>" . _('The password for this username.') . "</td>\n";
  174. echo " </tr>\n";
  175. }
  176. echo " <tr>\n";
  177. echo " <td>" . _('Hostmaster') . "</td>\n";
  178. echo " <td><input type=\"text\" name=\"dns_hostmaster\" value=\"\"></td>\n";
  179. echo " <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>\n";
  180. echo " </tr>\n";
  181. echo " <tr>\n";
  182. echo " <td>" . _('Primary nameserver') . "</td>\n";
  183. echo " <td><input type=\"text\" name=\"dns_ns1\" value=\"\"></td>\n";
  184. echo " <td>" . _('When creating new zones using the template, this value will be used as primary nameserver. Should be like "ns1.example.net".') . "</td>\n";
  185. echo " </tr>\n";
  186. echo " <tr>\n";
  187. echo " <td>" . _('Secondary nameserver') . "</td>\n";
  188. ;
  189. echo " <td><input type=\"text\" name=\"dns_ns2\" value=\"\"></td>\n";
  190. echo " <td>" . _('When creating new zones using the template, this value will be used as secondary nameserver. Should be like "ns2.example.net".') . "</td>\n";
  191. echo " </tr>\n";
  192. echo "</table>";
  193. echo "<br>\n";
  194. echo "<input type=\"hidden\" name=\"db_user\" value=\"" . $db_user . "\">";
  195. echo "<input type=\"hidden\" name=\"db_pass\" value=\"" . $db_pass . "\">";
  196. echo "<input type=\"hidden\" name=\"db_host\" value=\"" . $db_host . "\">";
  197. echo "<input type=\"hidden\" name=\"db_port\" value=\"" . $db_port . "\">";
  198. echo "<input type=\"hidden\" name=\"db_name\" value=\"" . $db_name . "\">";
  199. echo "<input type=\"hidden\" name=\"db_type\" value=\"" . $db_type . "\">";
  200. echo "<input type=\"hidden\" name=\"pa_pass\" value=\"" . $pa_pass . "\">";
  201. echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
  202. echo "<input type=\"hidden\" name=\"language\" value=\"" . $language . "\">";
  203. echo "<input type=\"submit\" name=\"submit\" value=\"" . _('Go to step') . " " . $step . "\">";
  204. echo "</form>";
  205. break;
  206. case 5:
  207. $step++;
  208. $db_user = $_POST['db_user'];
  209. $db_pass = $_POST['db_pass'];
  210. $db_host = $_POST['db_host'];
  211. $db_port = $_POST['db_port'];
  212. $db_name = $_POST['db_name'];
  213. $db_type = $_POST['db_type'];
  214. if ($db_type == 'sqlite') {
  215. $db_file = $db_name;
  216. } else {
  217. $pa_db_user = $_POST['pa_db_user'];
  218. $pa_db_pass = $_POST['pa_db_pass'];
  219. }
  220. $pa_pass = $_POST['pa_pass'];
  221. $dns_hostmaster = $_POST['dns_hostmaster'];
  222. $dns_ns1 = $_POST['dns_ns1'];
  223. $dns_ns2 = $_POST['dns_ns2'];
  224. $db_layer = 'PDO';
  225. require_once("../inc/database.inc.php");
  226. $db = dbConnect();
  227. include_once("database-structure.inc.php");
  228. echo "<p>" . _('You now want to give limited rights to Poweradmin 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.') . " ";
  229. if ($db_type == 'mysql') {
  230. $pa_db_host = $db_host;
  231. $sql = 'SELECT USER()';
  232. $result = $db->queryRow($sql);
  233. if (isset($result['user()'])) {
  234. $current_db_user = $result['user()'];
  235. $pa_db_host = substr($current_db_user, strpos($current_db_user, '@') + 1);
  236. }
  237. echo _('In MySQL you should now perform the following command:') . "</p>";
  238. echo "<p><tt>GRANT SELECT, INSERT, UPDATE, DELETE<BR>ON " . $db_name . ".*<br>TO '" . $pa_db_user . "'@'" . $pa_db_host . "'<br>IDENTIFIED BY '" . $pa_db_pass . "';</tt></p>";
  239. } elseif ($db_type == 'pgsql') {
  240. echo _('On PgSQL you would use:') . "</p>";
  241. echo "<p><tt>$ createuser -E -P " . $pa_db_user . "<br>" .
  242. "Enter password for new role: " . $pa_db_pass . "<br>" .
  243. "Enter it again: " . $pa_db_pass . "<br>" .
  244. "Shall the new role be a superuser? (y/n) n<br>" .
  245. "Shall the new user be allowed to create databases? (y/n) n<br>" .
  246. "Shall the new user be allowed to create more new users? (y/n) n<br>" .
  247. "CREATE USER<br>" .
  248. "$ psql " . $db_name . "<br>";
  249. echo "psql> ";
  250. foreach ($grantTables as $tableName) {
  251. echo "GRANT SELECT, INSERT, DELETE, UPDATE ON " . $tableName . " TO " . $pa_db_user . ";<br />";
  252. }
  253. foreach ($grantSequences as $sequenceName) {
  254. echo "GRANT USAGE, SELECT ON SEQUENCE " . $sequenceName . " TO " . $pa_db_user . ";<br />";
  255. }
  256. echo "</tt></p>\n";
  257. }
  258. echo "<p>" . _('After you have added the new user, proceed with this installation procedure.') . "</p>\n";
  259. echo "<form method=\"post\">";
  260. echo "<input type=\"hidden\" name=\"db_host\" value=\"" . $db_host . "\">";
  261. echo "<input type=\"hidden\" name=\"db_name\" value=\"" . $db_name . "\">";
  262. echo "<input type=\"hidden\" name=\"db_port\" value=\"" . $db_port . "\">";
  263. echo "<input type=\"hidden\" name=\"db_type\" value=\"" . $db_type . "\">";
  264. echo "<input type=\"hidden\" name=\"db_user\" value=\"" . $db_user . "\">";
  265. echo "<input type=\"hidden\" name=\"db_pass\" value=\"" . $db_pass . "\">";
  266. if ($db_type != 'sqlite') {
  267. echo "<input type=\"hidden\" name=\"pa_db_user\" value=\"" . $pa_db_user . "\">";
  268. echo "<input type=\"hidden\" name=\"pa_db_pass\" value=\"" . $pa_db_pass . "\">";
  269. }
  270. echo "<input type=\"hidden\" name=\"pa_pass\" value=\"" . $pa_pass . "\">";
  271. echo "<input type=\"hidden\" name=\"dns_hostmaster\" value=\"" . $dns_hostmaster . "\">";
  272. echo "<input type=\"hidden\" name=\"dns_ns1\" value=\"" . $dns_ns1 . "\">";
  273. echo "<input type=\"hidden\" name=\"dns_ns2\" value=\"" . $dns_ns2 . "\">";
  274. echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
  275. echo "<input type=\"hidden\" name=\"language\" value=\"" . $language . "\">";
  276. echo "<input type=\"submit\" name=\"submit\" value=\"" . _('Go to step') . " " . $step . "\">";
  277. echo "</form>";
  278. break;
  279. case 6:
  280. $step++;
  281. require_once("../inc/database.inc.php");
  282. global $db_layer;
  283. $db_type = $_POST['db_type'];
  284. $pa_pass = $_POST['pa_pass'];
  285. $db_port = $_POST['db_port'];
  286. $config = "<?php\n\n" .
  287. ( $db_type == 'sqlite' ? "\$db_file\t\t= '" . $_POST['db_name'] . "';\n" :
  288. "\$db_host\t\t= '" . $_POST['db_host'] . "';\n" .
  289. "\$db_user\t\t= '" . $_POST['pa_db_user'] . "';\n" .
  290. "\$db_pass\t\t= '" . $_POST['pa_db_pass'] . "';\n" .
  291. "\$db_name\t\t= '" . $_POST['db_name'] . "';\n" .
  292. (($db_type == 'mysql' && $db_port != 3306) || ($db_type == 'pgsql' && $db_port != 5432) ? "\$db_port\t\t= '" . $db_port . "';\n" : '')) .
  293. "\$db_type\t\t= '" . $_POST['db_type'] . "';\n" .
  294. "\$db_layer\t\t= 'PDO';\n" .
  295. "\n" .
  296. "\$session_key\t\t= '" . get_random_key() . "';\n" .
  297. "\n" .
  298. "\$iface_lang\t\t= '" . $_POST['language'] . "';\n" .
  299. "\n" .
  300. "\$dns_hostmaster\t\t= '" . $_POST['dns_hostmaster'] . "';\n" .
  301. "\$dns_ns1\t\t= '" . $_POST['dns_ns1'] . "';\n" .
  302. "\$dns_ns2\t\t= '" . $_POST['dns_ns2'] . "';\n";
  303. if (is_writeable($local_config_file)) {
  304. $h_config = fopen($local_config_file, "w");
  305. fwrite($h_config, $config);
  306. fclose($h_config);
  307. echo "<p>" . _('The installer was able to write to the file "') . $local_config_file . _('". A basic configuration, based on the details you have given, has been created.') . "</p>\n";
  308. } else {
  309. echo "<p>" . _('The installer is unable to write to the file "') . $local_config_file . _('" (which is in itself good). 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>\n";
  310. echo "<pre>";
  311. echo htmlentities($config);
  312. echo "</pre>";
  313. }
  314. echo "<form method=\"post\">";
  315. echo "<input type=\"hidden\" name=\"pa_pass\" value=\"" . $pa_pass . "\">";
  316. echo "<input type=\"hidden\" name=\"step\" value=\"" . $step . "\">";
  317. echo "<input type=\"hidden\" name=\"language\" value=\"" . $language . "\">";
  318. echo "<input type=\"submit\" name=\"submit\" value=\"" . _('Go to step') . " " . $step . "\">";
  319. echo "</form>";
  320. break;
  321. case 7:
  322. $step++;
  323. echo "<p>" . _('Now we have finished the configuration.') . "</p>";
  324. echo "<p>" . _('If you want support for the URLs used by other dynamic DNS providers, run "cp install/htaccess.dist .htaccess" and enable mod_rewrite in Apache.') . "</p>";
  325. echo "<p>" . _('You should (must!) remove the directory "install/" from the Poweradmin root directory. You will not be able to use Poweradmin if it exists. Do it now.') . "</p>";
  326. echo "<p>" . _('After you have removed the directory, you can login to <a href="../index.php">Poweradmin</a> with username "admin" and password "') . $_POST['pa_pass'] . _('". You are highly encouraged to change these as soon as you are logged in.') . "</p>";
  327. break;
  328. default:
  329. break;
  330. }
  331. include_once('../inc/version.inc.php');
  332. echo "<div class=\"footer\">";
  333. echo "<a href=\"http://www.poweradmin.org/\">a complete(r) <strong>poweradmin</strong> v$VERSION</a> - <a href=\"http://www.poweradmin.org/credits.html\">credits</a>";
  334. echo "</div></body></html>";