Guest User

Untitled

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