Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1.  
  2. #/user/local/vesta/web/login/index.php
  3. `<?php
  4.  
  5. define('NO_AUTH_REQUIRED',true);
  6.  
  7. // Main include
  8. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  9.  
  10. //echo $_SESSION['request_uri'];
  11.  
  12. $TAB = 'LOGIN';
  13.  
  14. // Logout
  15. if (isset($_GET['logout'])) {
  16. session_destroy();
  17. }
  18.  
  19. // Login as someone else
  20. if (isset($_SESSION['user'])) {
  21. if ($_SESSION['user'] == 'admin' && !empty($_GET['loginas'])) {
  22. exec (VESTA_CMD . "v-list-user ".escapeshellarg($_GET['loginas'])." json", $output, $return_var);
  23. if ( $return_var == 0 ) {
  24. $data = json_decode(implode('', $output), true);
  25. reset($data);
  26. $_SESSION['look'] = key($data);
  27. $_SESSION['look_alert'] = 'yes';
  28. }
  29. }
  30. header("Location: /");
  31. exit;
  32. }
  33.  
  34. /************************************/
  35. $sec_key=false;
  36. if ( isset($_POST['security_code'])) {
  37. if ( $_SESSION['security_code']!=$_POST['security_code'] ) {
  38. $ERROR = "Invalid code";
  39. $sec_key=false;
  40. } else {
  41. $sec_key=true;
  42. }
  43. }
  44. /**********************************/
  45.  
  46. // Basic auth
  47. if (isset($_POST['user']) && isset($_POST['password'])) {
  48. $v_user = escapeshellarg($_POST['user']);
  49.  
  50. // Send password via tmp file
  51. $v_password = exec('mktemp -p /tmp');
  52. $fp = fopen($v_password, "w");
  53. fwrite($fp, $_POST['password']."\n");
  54. fclose($fp);
  55.  
  56. // Check user & password
  57. exec(VESTA_CMD ."v-check-user-password ".$v_user." ".$v_password." ".escapeshellarg($_SERVER['REMOTE_ADDR']), $output, $return_var);
  58. unset($output);
  59.  
  60. // Remove tmp file
  61. unlink($v_password);
  62.  
  63. // Check API answer
  64. if ( $return_var > 0 ) {
  65. $ERROR = "<a class=\"error\">".__('Invalid username or password')."</a>";
  66.  
  67. } else {
  68. if ( $sec_key ) {//captcha control
  69. // Make root admin user
  70. if ($_POST['user'] == 'root') $v_user = 'admin';
  71.  
  72. // Get user speciefic parameters
  73. exec (VESTA_CMD . "v-list-user ".$v_user." json", $output, $return_var);
  74. $data = json_decode(implode('', $output), true);
  75.  
  76. // Define session user
  77. $_SESSION['user'] = key($data);
  78. $v_user = $_SESSION['user'];
  79.  
  80. // Get user favorites
  81. get_favourites();
  82.  
  83. // Define language
  84. if (!empty($data[$v_user]['LANGUAGE'])) $_SESSION['language'] = $data[$v_user]['LANGUAGE'];
  85.  
  86. // Redirect request to control panel interface
  87. if (!empty($_SESSION['request_uri'])) {
  88. header("Location: ".$_SESSION['request_uri']);
  89. unset($_SESSION['request_uri']);
  90. exit;
  91. } else {
  92. header("Location: /");
  93. exit;
  94. }
  95. }//sec_key
  96. }
  97. }
  98.  
  99. // Check system configuration
  100. exec (VESTA_CMD . "v-list-sys-config json", $output, $return_var);
  101. $data = json_decode(implode('', $output), true);
  102. $sys_arr = $data['config'];
  103. foreach ($sys_arr as $key => $value) {
  104. $_SESSION[$key] = $value;
  105. }
  106.  
  107. // Detect language
  108. if (empty($_SESSION['language'])) {
  109. $output = '';
  110. exec (VESTA_CMD."v-list-sys-config json", $output, $return_var);
  111. $config = json_decode(implode('', $output), true);
  112. $lang = $config['config']['LANGUAGE'];
  113.  
  114. $output = '';
  115. exec (VESTA_CMD."v-list-sys-languages json", $output, $return_var);
  116. $languages = json_decode(implode('', $output), true);
  117. if(in_array($lang, $languages)){
  118. $_SESSION['language'] = $lang;
  119. }
  120. }
  121.  
  122. require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.$_SESSION['language'].'.php');
  123. require_once('../templates/header.html');
  124. require_once('../templates/login.html');
  125. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement