PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/regsetup.php

http://awarenet.googlecode.com/
PHP | 188 lines | 118 code | 32 blank | 38 comment | 37 complexity | 18b0d3ef427b1afec7d4f1389e785d9c MD5 | raw file
Possible License(s): GPL-3.0
  1. <?
  2. require_once('core/kregistry.class.php');
  3. //--------------------------------------------------------------------------------------------------
  4. //* utility to create kapenta registry
  5. //--------------------------------------------------------------------------------------------------
  6. //+ NOTE: expects 'pass' value in GET, matching recovery password, will also accept 'reload' value
  7. //+ to reload setup.inc.php, and 'set' to set values.
  8. //+
  9. //+ Sending recovery password as a $_GET var is awful, TODO: fix this
  10. //----------------------------------------------------------------------------------------------
  11. // initialize registry and check password
  12. //----------------------------------------------------------------------------------------------
  13. session_start();
  14. $registry = new KRegistry();
  15. $auth = false;
  16. $recoveryPass = $registry->get('kapenta.recoverypassword');
  17. $userPass = '';
  18. if ((true == array_key_exists('action', $_POST)) && ('logout' == $_POST['action'])) {
  19. $_SESSION['regsetup_pass'] = '';
  20. }
  21. if ((true == array_key_exists('action', $_POST)) && ('login' == $_POST['action'])) {
  22. if (true == array_key_exists('pass', $_POST)) { $userPass = $_POST['pass']; }
  23. $_SESSION['regsetup_pass'] = $userPass;
  24. }
  25. if (true == array_key_exists('regsetup_pass', $_SESSION)) {
  26. $userPass = $_SESSION['regsetup_pass'];
  27. }
  28. //----------------------------------------------------------------------------------------------
  29. // show login form if not authorized
  30. //----------------------------------------------------------------------------------------------
  31. $header = "<html>
  32. <head>
  33. <link href='themes/clockface/css/default.css'
  34. rel='stylesheet' type='text/css' />
  35. </head>
  36. <body>
  37. <h1>Kapenta Registry Setup</h1>
  38. ";
  39. $footer = "</body></html>";
  40. echo $header;
  41. if (sha1($userPass) == $recoveryPass) { $auth = true; }
  42. if ('' == $recoveryPass) { $auth = true; }
  43. if (false == $auth) {
  44. $loginForm = "
  45. <h2>Please log in.</h2>
  46. <form name='pwForm' method='POST'>
  47. <input type='hidden' name='action' value='login' />
  48. <b>Kapenta Recovery Password:</b> <input type='password' name='pass' />
  49. <input type='submit' />
  50. </form><hr/><br/>
  51. ";
  52. die($loginForm . $footer);
  53. }
  54. //----------------------------------------------------------------------------------------------
  55. // load if setup.inc.php if requested and it exists - save values to the registry
  56. //----------------------------------------------------------------------------------------------
  57. if ((true == array_key_exists('action', $_POST)) && ('reload' == $_POST['action'])) {
  58. if (true == file_exists('setup.inc.php')) {
  59. require_once('setup.inc.php');
  60. echo "Reloading setup.inc.php...<br/>\n";
  61. $varMap = array(
  62. 'installPath' => 'kapenta.installpath',
  63. 'serverPath' => 'kapenta.serverpath',
  64. 'dbType' => 'kapenta.db.type',
  65. 'dbHost' => 'kapenta.db.host',
  66. 'dbName' => 'kapenta.db.name',
  67. 'dbUser' => 'kapenta.db.user',
  68. 'dbPass' => 'kapenta.db.password',
  69. 'defaultModule' => 'kapenta.modules.default',
  70. 'useBlockCache' => 'kapenta.blockcache.enabled',
  71. 'websiteName' => 'kapenta.sitename',
  72. 'defaultTheme' => 'kapenta.themes.default',
  73. 'logLevel' => 'kapenta.loglevel',
  74. 'cronInterval' => 'kapenta.cron.interval',
  75. 'hostInterface' => 'kapenta.network.interface',
  76. 'proxyEnabled' => 'kapenta.proxy.enabled',
  77. 'proxyAddress' => 'kapenta.proxy.address',
  78. 'proxyPort' => 'kapenta.proxy.port',
  79. 'proxyUser' => 'kapenta.proxy.user',
  80. 'proxyPass' => 'kapenta.proxy.pass',
  81. 'rsaKeySize' => 'kapenta.rsa.keysize',
  82. 'rsaPublicKey' => 'kapenta.rsa.publickey',
  83. 'rsaPrivateKey' => 'kapenta.rsa.privatekey'
  84. );
  85. foreach ($varMap as $varName => $regkey) {
  86. if (true == isset($$varName)) { $registry->set($regkey, $$varName); }
  87. echo "setting $regkey ...<br/>\n";
  88. }
  89. } else {
  90. echo "setup.inc.php not found.<br/>\n";
  91. }
  92. }
  93. //----------------------------------------------------------------------------------------------
  94. // set a key
  95. //----------------------------------------------------------------------------------------------
  96. if ((true == array_key_exists('action', $_POST)) && ('add' == $_POST['action'])) {
  97. $key = (array_key_exists('key', $_POST)) ? $_POST['key'] : '';
  98. $value = (array_key_exists('value', $_POST)) ? $_POST['value'] : '';
  99. //echo "setting $key to $value ...<br/>";
  100. if (('kapenta.recoverypassword' == $key) && ('' != $value)) { $value = sha1($value); }
  101. if ('' != $key) {
  102. $registry->set($key, $value);
  103. }
  104. }
  105. //----------------------------------------------------------------------------------------------
  106. // load all registry files
  107. //----------------------------------------------------------------------------------------------
  108. $prefixes = $registry->listFiles();
  109. echo "<b>Jump to:</b> ";
  110. foreach($prefixes as $prefix) { echo "<a href='#$prefix'>$prefix</a>, "; }
  111. echo "<br/><br/>";
  112. //----------------------------------------------------------------------------------------------
  113. // show 'add key' form
  114. //----------------------------------------------------------------------------------------------
  115. $addForm = "
  116. <form name='addForm' method='POST'>
  117. <input type='hidden' name='action' value='add' />
  118. <b>key:</b> <input type='text' name='key' />
  119. <b>value:</b> <input type='text' name='value' />
  120. <input type='submit' value='Add Key &gt;&gt;' />
  121. </form><br/>
  122. ";
  123. //----------------------------------------------------------------------------------------------
  124. // show 'reload' form
  125. //----------------------------------------------------------------------------------------------
  126. $reloadForm = "
  127. <form name='reloadForm' method='POST'>
  128. <input type='hidden' name='action' value='reload' />
  129. <input type='submit' value='Reload setup.inc.php &gt;&gt;' />
  130. </form><hr/><br/>
  131. ";
  132. //----------------------------------------------------------------------------------------------
  133. // show 'log out' form
  134. //----------------------------------------------------------------------------------------------
  135. $logOutForm = "
  136. <form name='logoutForm' method='POST'>
  137. <input type='hidden' name='action' value='logout' />
  138. <input type='submit' value='Log out &gt;&gt;' />
  139. </form><hr/><br/>
  140. ";
  141. echo $logOutForm;
  142. //----------------------------------------------------------------------------------------------
  143. // show keys and controls
  144. //----------------------------------------------------------------------------------------------
  145. foreach($prefixes as $prefix) {
  146. echo "<h2><a name='$prefix'>" . $prefix . "</a></h2>\n";
  147. echo $addForm;
  148. echo $registry->toHtml($prefix);
  149. echo $reloadForm;
  150. }
  151. echo $logOutForm;
  152. //----------------------------------------------------------------------------------------------
  153. // done
  154. //----------------------------------------------------------------------------------------------
  155. echo $footer;
  156. ?>