PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/ railoapacheportable/security/htdocs/securefunctions.php

http://railoapacheportable.googlecode.com/
PHP | 220 lines | 201 code | 19 blank | 0 comment | 36 complexity | 55ce5530d90811019520f404b3104e7c MD5 | raw file
Possible License(s): BSD-2-Clause, Apache-2.0, EPL-1.0, LGPL-3.0, GPL-3.0, AGPL-1.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-2.1, BSD-3-Clause, AGPL-3.0, CC-BY-SA-3.0
  1. <?php
  2. function mysqlrootupdate($currentpass, $newpass, $renewpass) {
  3. list($partwampp, $directorwampp) = preg_split('|\\\security\\\htdocs|', dirname(__FILE__));
  4. $mypasswdtxt = "mysqlrootpasswd.txt";
  5. $mypasswdtxtdir = $partwampp."\security\\".$mypasswdtxt;
  6. $dir = $partwampp."\security\\";
  7. global $rootpasswdupdate;
  8. global $update;
  9. global $mysqlpfile;
  10. if (false !== @mysql_connect("localhost", "root", $currentpass)) {
  11. mysql_select_db("mysql");
  12. mysql_query("SET PASSWORD = PASSWORD('".mysql_real_escape_string($newpass)."')"); //Fix by Wiedmann
  13. mysql_query("FLUSH PRIVILEGES");
  14. mysql_close();
  15. if (!file_exists($dir)) { // Fix by Wiedmann
  16. mkdir($dir);
  17. }
  18. if ($mysqlpfile=="yes")
  19. {
  20. $datei = fopen($mypasswdtxtdir, 'w');
  21. $put = "mysql user = root\r\nmysql password = $newpass\r\n";
  22. fputs($datei, $put);
  23. fclose($datei);
  24. }
  25. $rootpasswdupdate = "yes";
  26. } else {
  27. $rootpasswdupdate = "no";
  28. }
  29. }
  30. function mysqlpmaupdate() {
  31. list($partwampp, $directorwampp) = preg_split('|\\\security\\\htdocs|', dirname(__FILE__));
  32. $mypasswdtxt = "mysqlrootpasswd.txt";
  33. $mypasswdtxtdir = $partwampp."\security\\".$mypasswdtxt;
  34. $dir = $partwampp."\security\\";
  35. global $pmapasswdupdate;
  36. global $update;
  37. global $mysqlpfile;
  38. global $pmanewpass;
  39. global $mypasswd;
  40. $pmanewpass = uniqid();
  41. if (false !== @mysql_connect("localhost", "root", $mypasswd)) {
  42. mysql_select_db("mysql");
  43. mysql_query("SET PASSWORD for 'pma'@'localhost' = PASSWORD('".mysql_real_escape_string($pmanewpass)."')"); //Fix by Wiedmann
  44. mysql_query("FLUSH PRIVILEGES");
  45. mysql_close();
  46. if (!file_exists($dir)) { // Fix by Wiedmann
  47. mkdir($dir);
  48. }
  49. if ($mysqlpfile=="yes")
  50. {
  51. $datei = fopen($mypasswdtxtdir, 'a');
  52. $put = "\r\nphpmyadmin user = pma\r\nmysql password = $pmanewpass\r\n";
  53. fputs($datei, $put);
  54. fclose($datei);
  55. }
  56. $pmapasswdupdate = "yes";
  57. } else {
  58. $pmapasswdupdate = "no";
  59. }
  60. }
  61. function phpmyadminstatus() {
  62. global $currentstatus;
  63. global $authzeile;
  64. global $notfind;
  65. list($partwampp, $directorwampp) = preg_split('|\\\htdocs|', dirname(__FILE__));
  66. $configinc = "config.inc.php";
  67. $phpmyadminconf = $partwampp."\phpmyadmin\\".$configinc;
  68. if (file_exists($phpmyadminconf)) {
  69. $datei = fopen($phpmyadminconf, 'r');
  70. $i = 0;
  71. while (!feof($datei)) {
  72. $zeile = fgets($datei, 255);
  73. $oldzeile[] = $zeile;
  74. @list($left, $right) = split('=', $zeile);
  75. if (preg_match("/'auth_type'/i", $left)) {
  76. if (preg_match("/'http'/i", $right)) {
  77. $currentstatus[] = "http";
  78. $authzeile[] = $i;
  79. } elseif (preg_match("/'cookie'/i", $right)) {
  80. $currentstatus[] = "cookie";
  81. $authzeile[] = $i;
  82. } else {
  83. $currentstatus[] = "null";
  84. $authzeile[] = $i;
  85. }
  86. }
  87. $i++;
  88. }
  89. fclose($datei);
  90. } else {
  91. $notfind = 1;
  92. }
  93. }
  94. function changephpadminauth($phpmyadminauth, $myupdate) {
  95. global $phpmyadminconfsafe;
  96. list($partwampp, $directorwampp) = preg_split('|\\\security\\\htdocs|', dirname(__FILE__));
  97. $configinc = "config.inc.php";
  98. $phpmyadminconf = $partwampp."\phpmyadmin\\".$configinc;
  99. if (file_exists($phpmyadminconf)) {
  100. $datei = fopen($phpmyadminconf, 'r');
  101. $i = 0;
  102. while (!feof($datei)) {
  103. $zeile = fgets($datei, 255);
  104. $oldzeile[] = $zeile;
  105. @list($left, $right) = split('=', $zeile);
  106. if (preg_match("/'auth_type'/i", $left)) {
  107. if (preg_match("/'http'/i", $right)) {
  108. $currentstatus[] = "http";
  109. $authzeile[] = $i;
  110. } elseif (preg_match("/'cookie'/i", $right)) {
  111. $currentstatus[] = "cookie";
  112. $authzeile[] = $i;
  113. } else {
  114. $currentstatus[] = "null";
  115. $authzeile[] = $i;
  116. }
  117. }
  118. $i++;
  119. }
  120. fclose($datei);
  121. } else {
  122. $notfind = 1;
  123. }
  124. $mynewzeile = "\$cfg['Servers'][\$i]['auth_type'] = '$phpmyadminauth'; /* Authentication method (config, http or cookie based) */\r\n";
  125. if (file_exists($phpmyadminconf)) {
  126. if (($currentstatus[0] == "null") || ($myupdate == "1")) {
  127. copy($phpmyadminconf, $phpmyadminconf.'.safe');
  128. $phpmyadminconfsafe = $partwampp."\phpmyadmin\\".$configinc.".safe";
  129. $phpmyadminauth = "http";
  130. $datei = fopen($phpmyadminconf, 'w');
  131. if ($datei) {
  132. for ($z = 0; $z < $i + 1; $z++) {
  133. if ($authzeile[0] == $z) {
  134. fputs($datei, $mynewzeile);
  135. } else {
  136. fputs($datei, $oldzeile[$z]);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. function changephpadminpma() {
  144. global $pmanewpass;
  145. list($partwampp, $directorwampp) = preg_split('|\\\security\\\htdocs|', dirname(__FILE__));
  146. $configinc = "config.inc.php";
  147. $phpmyadminconf = $partwampp."\phpmyadmin\\".$configinc;
  148. if (file_exists($phpmyadminconf)) {
  149. $datei = file_get_contents($phpmyadminconf);
  150. $datei = preg_replace('/(\$cfg\[\'Servers\'\]\[\$i\]\[\'controlpass\'\]\h*?=\h*?\').*?(\';)/i', '${1}'.$pmanewpass.'${2}', $datei);
  151. file_put_contents($phpmyadminconf, $datei);
  152. } else {
  153. $notfind = 1;
  154. }
  155. }
  156. function htaccess($xauser, $xapasswd) {
  157. global $xamppdirconfig;
  158. global $xapasswdtxtdir;
  159. global $htpasswddir;
  160. global $htpasswddirectory;
  161. global $htxampp;
  162. global $xapfile;
  163. list($partwampp, $directorwampp) = preg_split('|\\\security\\\htdocs|', dirname(__FILE__));
  164. $htaccess = ".htaccess";
  165. $xapasswdtxt = "xamppdirpasswd.txt";
  166. $htpasswd = "xampp.users";
  167. $xapasswdtxtdir = $partwampp."\security\\".$xapasswdtxt;
  168. $curspcript = $_SERVER["SCRIPT_FILENAME"];
  169. $htxampp = $partwampp."\htdocs\\xampp\\".$htaccess;
  170. $htpasswdexe = $partwampp."\apache\\bin\\htpasswd.exe";
  171. if (file_exists($htpasswdexe)) {
  172. $htpasswddir = "\"".$partwampp."\security\\".$htpasswd."\"";
  173. $htpasswddirectory = $partwampp."\security\\".$htpasswd;
  174. $dir = $partwampp."\security\\";
  175. if (!file_exists($dir)) {
  176. mkdir($dir);
  177. }
  178. $datei = fopen($htxampp, 'w+');
  179. $insert = "AuthName \"xampp user\"\r\nAuthType Basic\r\nAuthUserFile $htpasswddir\r\nrequire valid-user";
  180. fputs($datei,$insert);
  181. fclose($datei);
  182. chdir($partwampp."\security"); // Fix by Wiedmann
  183. $htpassrealm = "start /b \"\" \"$htpasswdexe\" -c -m -b .\\xampp.users $xauser $xapasswd";
  184. $handle = popen($htpassrealm, 'w');
  185. pclose($handle);
  186. chdir($curdir);
  187. if ($xapfile=="yes")
  188. {
  189. $datei = fopen($xapasswdtxtdir, 'w+');
  190. $put = "XAMPP user = $xauser\r\nXAMPP password = $xapasswd";
  191. fputs($datei, $put);
  192. fclose($datei);
  193. }
  194. $hdir = $dir.'htdocs\\';
  195. copy($htxampp, $dir.'htdocs\\.htaccess');
  196. $xamppdirconfig = "ok";
  197. } else {
  198. $xamppdirconfig = "notok";
  199. }
  200. }
  201. ?>