index.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. session_start();
  6. $TAB = 'IP';
  7. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  8. // Header
  9. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  10. // Panel
  11. top_panel($user,$TAB);
  12. // Are you admin?
  13. if ($_SESSION['user'] == 'admin') {
  14. if (!empty($_POST['ok'])) {
  15. // Check input
  16. if (empty($_POST['v_ip'])) $errors[] = 'ip address';
  17. if (empty($_POST['v_netmask'])) $errors[] = 'netmask';
  18. if (empty($_POST['v_interface'])) $errors[] = 'interface';
  19. if (empty($_POST['v_owner'])) $errors[] = 'assigned used';
  20. if (empty($_POST['v_interface'])) $errors[] = 'interface';
  21. // Protect input
  22. $v_ip = escapeshellarg($_POST['v_ip']);
  23. $v_netmask = escapeshellarg($_POST['v_netmask']);
  24. $v_name = escapeshellarg($_POST['v_name']);
  25. $v_interface = $_POST['v_interface'];
  26. $v_shared = $_POST['v_shared'];
  27. if ($v_shared == 'on') {
  28. $ip_status = 'shared';
  29. } else {
  30. $ip_status = 'dedicated';
  31. $v_dedicated = 'yes';
  32. }
  33. $v_owner = $_POST['v_owner'];
  34. // Check for errors
  35. if (!empty($errors[0])) {
  36. foreach ($errors as $i => $error) {
  37. if ( $i == 0 ) {
  38. $error_msg = $error;
  39. } else {
  40. $error_msg = $error_msg.", ".$error;
  41. }
  42. }
  43. $_SESSION['error_msg'] = "Error: field ".$error_msg." can not be blank.";
  44. } else {
  45. // Add IP
  46. $v_interface = escapeshellarg($_POST['v_interface']);
  47. $v_owner = $_POST['v_owner'];
  48. exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name, $output, $return_var);
  49. $v_owner = $_POST['v_owner'];
  50. $v_interface = $_POST['v_interface'];
  51. if ($return_var != 0) {
  52. $error = implode('<br>', $output);
  53. if (empty($error)) $error = 'Error: vesta did not return any output.';
  54. $_SESSION['error_msg'] = $error;
  55. unset($v_password);
  56. unset($output);
  57. } else {
  58. $_SESSION['ok_msg'] = "OK: ip <a href='/edit/ip/?ip=".$_POST['v_ip']."'><b>".$_POST['v_ip']."</b></a> has been created successfully.";
  59. unset($v_ip);
  60. unset($v_netmask);
  61. unset($v_name);
  62. unset($output);
  63. }
  64. }
  65. }
  66. exec (VESTA_CMD."v-list-sys-interfaces 'json'", $output, $return_var);
  67. $interfaces = json_decode(implode('', $output), true);
  68. unset($output);
  69. exec (VESTA_CMD."v-list-sys-users 'json'", $output, $return_var);
  70. $users = json_decode(implode('', $output), true);
  71. unset($output);
  72. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_ip.html');
  73. unset($_SESSION['error_msg']);
  74. unset($_SESSION['ok_msg']);
  75. }
  76. // Footer
  77. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');