No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setpwd.php 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. <title>密码修改工具 - 易优CMS</title>
  6. </head>
  7. <body>
  8. <?php
  9. error_reporting(E_ALL & ~E_NOTICE);
  10. header('Content-Type: text/html; charset=UTF-8');
  11. $database = include_once "application/database.php";
  12. $dbHost = trim($database['hostname']);
  13. $dbport = $database['hostport'] ? $database['hostport'] : '3306';
  14. $dbName = trim($database['database']);
  15. $dbUser = trim($database['username']);
  16. $dbPwd = trim($database['password']);
  17. $dbPrefix = empty($database['prefix']) ? 'ey_' : trim($database['prefix']);
  18. $charset = trim($database['charset']);
  19. $conn = @mysqli_connect($dbHost, $dbUser, $dbPwd,$dbName,$dbport);
  20. if (mysqli_connect_errno($conn)){
  21. $msg = "连接数据库失败!".mysqli_connect_error($conn);
  22. tips($msg);
  23. }
  24. mysqli_set_charset($conn, $charset);
  25. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  26. $type = $_POST['type'];
  27. if (1 == $type) { // 修改后台登录密码
  28. $user_name = $_POST['user_name'];
  29. $password = $_POST['password'];
  30. if (empty($password)) {
  31. tips("新密码不能为空!");
  32. }
  33. $config = include_once "application/config.php";
  34. $auth_code = $config['AUTH_CODE'];
  35. $sql = "SELECT value FROM `{$dbPrefix}config` WHERE name='system_auth_code' AND inc_type='system' LIMIT 1";
  36. $ret = mysqli_query($conn,$sql);
  37. while($row = mysqli_fetch_array($ret))
  38. {
  39. if (!empty($row['value'])) {
  40. $auth_code = $row['value'];
  41. }
  42. }
  43. $password = md5($auth_code.$password);
  44. $sql = "UPDATE `{$dbPrefix}admin` SET `password`='{$password}' WHERE `user_name`='{$user_name}'";
  45. $ret = mysqli_query($conn,$sql);
  46. if ($ret) {
  47. $msg = "修改成功";
  48. } else {
  49. $msg = "修改失败,请联系技术!";
  50. }
  51. tips($msg);
  52. }
  53. else if (2 == $type) // 修改插件安装密码
  54. {
  55. $password = $_POST['password'];
  56. if (empty($password)) {
  57. tips("新密码不能为空!");
  58. }
  59. $config = include_once "application/config.php";
  60. $auth_code = $config['AUTH_CODE'];
  61. $sql = "SELECT value FROM `{$dbPrefix}config` WHERE name='system_auth_code' AND inc_type='system' LIMIT 1";
  62. $ret = mysqli_query($conn,$sql);
  63. while($row = mysqli_fetch_array($ret))
  64. {
  65. if (!empty($row['value'])) {
  66. $auth_code = $row['value'];
  67. }
  68. }
  69. $password = md5($auth_code.$password);
  70. $t = time();
  71. $sql = "UPDATE `{$dbPrefix}config` SET `value`='{$password}', `update_time`='{$t}' WHERE `name`='weapp_installpwd' AND `inc_type`='weapp'";
  72. $ret = mysqli_query($conn,$sql);
  73. if ($ret) {
  74. delFile('./data/runtime/cache', true);
  75. $msg = "修改成功";
  76. } else {
  77. $msg = "修改失败,请联系技术!";
  78. }
  79. tips($msg);
  80. }
  81. else if (3 == $type) // 修改插件问题与答案
  82. {
  83. $ask = $_POST['ask'];
  84. if (empty($ask)) {
  85. tips("新问题不能为空!");
  86. }
  87. $answer = $_POST['answer'];
  88. if (empty($answer)) {
  89. tips("新答案不能为空!");
  90. }
  91. $config = include_once "application/config.php";
  92. $auth_code = $config['AUTH_CODE'];
  93. $sql = "SELECT value FROM `{$dbPrefix}config` WHERE name='system_auth_code' AND inc_type='system' LIMIT 1";
  94. $ret = mysqli_query($conn,$sql);
  95. while($row = mysqli_fetch_array($ret))
  96. {
  97. if (!empty($row['value'])) {
  98. $auth_code = $row['value'];
  99. }
  100. }
  101. $answer = md5($auth_code.$answer);
  102. $t = time();
  103. $sql = "UPDATE `{$dbPrefix}setting` SET `value`='{$ask}', `update_time`='{$t}' WHERE `name`='weapp_install_ask' AND `inc_type`='weapp'";
  104. $sql2 = "UPDATE `{$dbPrefix}setting` SET `value`='{$answer}', `update_time`='{$t}' WHERE `name`='weapp_install_answer' AND `inc_type`='weapp'";
  105. if (@mysqli_query($conn,$sql) && @mysqli_query($conn,$sql2)) {
  106. delFile('./data/runtime/cache', true);
  107. $msg = "修改成功";
  108. } else {
  109. $msg = "修改失败,请联系技术!";
  110. }
  111. tips($msg);
  112. }
  113. } else {
  114. /*系统版本号*/
  115. $version = 'v1.0.0';
  116. $version_txt_path = './data/conf/version.txt';
  117. if(file_exists($version_txt_path)) {
  118. $fp = fopen($version_txt_path, 'r');
  119. $content = fread($fp, filesize($version_txt_path));
  120. fclose($fp);
  121. $version = $content ? $content : $version;
  122. }
  123. /*end*/
  124. /*管理员列表*/
  125. $sql = "SELECT * FROM `{$dbPrefix}admin`";
  126. $ret = mysqli_query($conn,$sql);
  127. $select_html = "";
  128. while($row = mysqli_fetch_array($ret))
  129. {
  130. $select_html .= "<option value='{$row['user_name']}'>{$row['user_name']}</option>";
  131. }
  132. /*end*/
  133. /*插件问题列表*/
  134. $weapp_askanswer_list = [];
  135. $sql = "SELECT value FROM `{$dbPrefix}setting` WHERE name='weapp_askanswer_list' AND inc_type='weapp' LIMIT 1";
  136. $ret = mysqli_query($conn,$sql);
  137. while($row = mysqli_fetch_array($ret))
  138. {
  139. if (!empty($row['value'])) {
  140. $weapp_askanswer_list = json_decode($row['value'], true);
  141. }
  142. }
  143. $ask_select_html = "";
  144. foreach ($weapp_askanswer_list as $key => $value) {
  145. $ask_select_html .= "<option value='{$key}'>{$value}</option>";
  146. }
  147. /*end*/
  148. }
  149. mysqli_close($conn);
  150. function tips($msg)
  151. {
  152. die('<script type="text/javascript">alert("'.$msg.'");window.location.href = "setpwd.php";</script>');
  153. }
  154. /**
  155. * 递归删除文件夹
  156. *
  157. * @param string $path 目录路径
  158. * @param boolean $delDir 是否删除空目录
  159. * @return boolean
  160. */
  161. function delFile($path, $delDir = FALSE) {
  162. if(!is_dir($path))
  163. return FALSE;
  164. $handle = @opendir($path);
  165. if ($handle) {
  166. while (false !== ( $item = readdir($handle) )) {
  167. if ($item != "." && $item != "..")
  168. is_dir("$path/$item") ? delFile("$path/$item", $delDir) : @unlink("$path/$item");
  169. }
  170. closedir($handle);
  171. if ($delDir) {
  172. return @rmdir($path);
  173. }
  174. }else {
  175. if (file_exists($path)) {
  176. return @unlink($path);
  177. } else {
  178. return FALSE;
  179. }
  180. }
  181. }
  182. ?>
  183. 易优CMS - 修改后台登录密码<br/><br/>
  184. <form action="setpwd.php" method="post">
  185. 用户名:
  186. <select name="user_name">
  187. <?php echo $select_html;?>
  188. </select><br/><br/>
  189. 新密码:<input type="password" name="password" value=""><br/><br/>
  190. <input type="hidden" name="type" value="1">
  191. <input type="submit" name="submit" value="确认修改">
  192. </form>
  193. <?php if (version_compare($version,'v1.4.2','>')) { ?>
  194. <br/>
  195. <hr/>
  196. <br/>
  197. 易优CMS - 修改插件问题与答案<br/><br/>
  198. <form action="setpwd.php" method="post">
  199. 新问题:
  200. <select name="ask">
  201. <?php echo $ask_select_html;?>
  202. </select><br/><br/>
  203. 新答案:<input type="text" name="answer" value=""><br/><br/>
  204. <input type="hidden" name="type" value="3">
  205. <input type="submit" name="submit" value="确认修改">
  206. </form>
  207. <?php } else { ?>
  208. <br/>
  209. <hr/>
  210. <br/>
  211. 易优CMS - 修改插件安装密码<br/><br/>
  212. <form action="setpwd.php" method="post">
  213. 新密码:<input type="password" name="password" value=""><br/><br/>
  214. <input type="hidden" name="type" value="2">
  215. <input type="submit" name="submit" value="确认修改">
  216. </form>
  217. <?php } ?>
  218. </body>
  219. </html>