edit_alias.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
  3. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
  4. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
  5. $msg_error = "";
  6. $sSQL = "SELECT * FROM user_auth WHERE id=$id";
  7. $auth_info = get_record_sql($db_link, $sSQL);
  8. if (empty($auth_info['dns_name']) or $auth_info['deleted']) {
  9. header("Location: /admin/users/editauth.php?id=".$id);
  10. exit;
  11. }
  12. run_sql($db_link,"DELETE FROM user_auth_alias WHERE auth_id in (SELECT id FROM user_auth WHERE deleted=1)");
  13. if (isset($_POST["s_remove"])) {
  14. $s_id = $_POST["s_id"];
  15. foreach ($s_id as $key => $val) {
  16. if (isset($val)) {
  17. LOG_INFO($db_link, "Remove alias id: $val ".dump_record($db_link,'user_auth_alias','id='.$val));
  18. delete_record($db_link, "user_auth_alias", "id=" . $val);
  19. }
  20. }
  21. header("Location: " . $page_url);
  22. exit;
  23. }
  24. if (isset($_POST['s_save'])) {
  25. $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
  26. $domain_zone = get_option($db_link, 33);
  27. $domain_zone = ltrim($domain_zone, '.');
  28. for ($i = 0; $i < $len; $i ++) {
  29. $save_id = intval($_POST['s_save'][$i]);
  30. $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
  31. for ($j = 0; $j < $len_all; $j ++) {
  32. if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
  33. $f_dnsname = trim($_POST['s_alias'][$j]);
  34. if (!empty($f_dnsname)) {
  35. $f_dnsname = preg_replace('/\.' . str_replace('.', '\.', $domain_zone) . '$/', '', $f_dnsname);
  36. // $f_dnsname = preg_replace('/\.$/','',$f_dnsname);
  37. $f_dnsname = preg_replace('/\s+/','-',$f_dnsname);
  38. // $f_dnsname = preg_replace('/\./','-',$f_dnsname);
  39. }
  40. if (empty($f_dnsname) or !checkValidHostname($f_dnsname) or !checkUniqHostname($db_link,$id,$f_dnsname)) { continue; }
  41. $new['alias'] = $f_dnsname;
  42. $new['description'] = trim($_POST['s_description'][$j]);
  43. update_record($db_link, "user_auth_alias", "id='{$save_id}'", $new);
  44. }
  45. }
  46. header("Location: " . $page_url);
  47. exit;
  48. }
  49. if (isset($_POST["s_create"])) {
  50. $new_alias = $_POST["s_create_alias"];
  51. if (isset($new_alias)) {
  52. $f_dnsname = trim($new_alias);
  53. if (!empty($f_dnsname)) {
  54. $domain_zone = get_option($db_link, 33);
  55. $domain_zone = ltrim($domain_zone, '.');
  56. $f_dnsname = preg_replace('/\.' . str_replace('.', '\.', $domain_zone) . '$/', '', $f_dnsname);
  57. // $f_dnsname = preg_replace('/\.$/','',$f_dnsname);
  58. $f_dnsname = preg_replace('/\s+/','-',$f_dnsname);
  59. // $f_dnsname = preg_replace('/\./','-',$f_dnsname);
  60. }
  61. if (empty($f_dnsname) or !checkValidHostname($f_dnsname) or !checkUniqHostname($db_link,$id,$f_dnsname)) {
  62. $msg_error = "DNS $f_dnsname already exists at: ".searchHostname($db_link,$id,$f_dnsname)." Discard changes!";
  63. $_SESSION[$page_url]['msg'] = $msg_error;
  64. LOG_ERROR($db_link, $msg_error);
  65. header("Location: " . $_SERVER["REQUEST_URI"]);
  66. exit;
  67. }
  68. if (empty($f_dnsname)) { $f_dnsname = ''; }
  69. $new_rec['alias'] = $f_dnsname;
  70. $new_rec['auth_id'] = $id;
  71. LOG_INFO($db_link, "Create new alias $new_alias");
  72. insert_record($db_link, "user_auth_alias", $new_rec);
  73. }
  74. header("Location: " . $page_url);
  75. exit;
  76. }
  77. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
  78. ?>
  79. <div id="cont">
  80. <?php
  81. if (!empty($_SESSION[$page_url]['msg'])) {
  82. print '<div id="msg">' . $_SESSION[$page_url]['msg'] . '</div>';
  83. unset($_SESSION[$page_url]['msg']);
  84. }
  85. ?>
  86. <br>
  87. <form name="def" action="edit_alias.php?id=<?php echo $id; ?>" method="post">
  88. <b><?php print WEB_user_alias_for."&nbsp"; print_url($auth_info['ip'],"/admin/users/editauth.php?id=$id"); ?></b> <br>
  89. <table class="data">
  90. <tr align="center">
  91. <td></td>
  92. <td width=30><b>id</b></td>
  93. <td><b><?php echo WEB_cell_name; ?></b></td>
  94. <td><b><?php echo WEB_cell_description; ?></b></td>
  95. <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="s_remove" value="<?php echo WEB_btn_delete; ?>"></td>
  96. </tr>
  97. <?php
  98. $t_user_auth_alias = get_records($db_link,'user_auth_alias',"auth_id=$id ORDER BY alias");
  99. if (!empty($t_user_auth_alias)) {
  100. foreach ( $t_user_auth_alias as $row ) {
  101. print "<tr align=center>\n";
  102. print "<td class=\"data\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
  103. print "<td class=\"data\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
  104. print "<td class=\"data\"><input type=\"text\" name='s_alias[]' value='{$row['alias']}' pattern=\"^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$\"></td>\n";
  105. print "<td class=\"data\"><input type=\"text\" name='s_description[]' value='{$row['description']}'></td>\n";
  106. print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
  107. print "</tr>\n";
  108. }
  109. }
  110. ?>
  111. </table>
  112. <div>
  113. <?php echo WEB_user_dns_add_alias; ?>:
  114. <input type="text" name='s_create_alias' value='' pattern="^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$">
  115. <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
  116. </div>
  117. </form>
  118. <?php
  119. require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
  120. ?>