Advertisement
Guest User

Untitled

a guest
Oct 11th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. <?php
  2. session_start();
  3. session_destroy();
  4. session_start();
  5.  
  6. include_once "./password.php";
  7.  
  8. // AudioStreamer, www.audiostreamer.org
  9. // Copyright (C) <2013> <Lieven Rottiers>
  10. //
  11. // This program is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published by
  13. // the Free Software Foundation, either version 3 of the License, or
  14. // (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23.  
  24.  
  25. //database connection and AudioStreamer version
  26. //also change this in audiostreamerlib.php
  27. $version = "3.0";
  28. $sdb = "../sqlite/audiostreamer.db";
  29. $dbh = new PDO("sqlite:".$sdb);
  30. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  31. $error = '';
  32. $output = '';
  33.  
  34. //check for new version of AudioStreamer
  35. $new_version = file_get_contents("http://www.audiostreamer.org/version/version.txt");
  36. if (($new_version) && ($new_version != $version)) {
  37. $new_version = 'Current version '.$version.
  38. '<br/>Version '.$new_version.' available'.
  39. '<br/><a href="http://www.audiostreamer.org" target="_blank">http://www.audiostreamer.org</a>';
  40. } else {
  41. $new_version = '';
  42. }
  43.  
  44. if (!empty($_GET) || !empty($_POST)) {
  45. if (!empty($_POST["username"])) {
  46. $_SESSION["username"] = $_POST["username"];
  47. } else if (!empty($_GET["username"])) {
  48. $_SESSION["username"] = $_GET["username"];
  49. } else {
  50. $_SESSION["username"] = '';
  51. }
  52. if (!empty($_POST["password"])) {
  53. $_SESSION["password"] = $_POST["password"];
  54. } else if (!empty($_GET["password"])) {
  55. $_SESSION["password"] = $_GET["password"];
  56. } else {
  57. $_SESSION["password"] = '';
  58. }
  59. //
  60. //check if working with the password file
  61. //and thus checking username and password
  62. //
  63. if (!empty($start_password)) {
  64. $username = $start_username;
  65. $password = $start_password;
  66. $_SESSION["userid"] = "";
  67. $_SESSION["ind_admin"] = "1";
  68. }
  69. else {
  70. $username="";
  71. $password="";
  72. $sql = "select id, name, password, ind_admin, ind_desktop from user where name='".$_SESSION["username"]."'";
  73. foreach ($dbh->query($sql) as $row) {
  74. $username = $row["name"];
  75. $password = $row["password"];
  76. $_SESSION["userid"] = $row["id"];
  77. $_SESSION["ind_admin"] = $row["ind_admin"];
  78. $_SESSION["ind_desktop"] = $row["ind_desktop"];
  79. }
  80. }
  81.  
  82. if (empty($_SESSION["username"])) {
  83. $error = 'User must be specified. Try again.';
  84. session_destroy();
  85. }
  86. else if (empty($_SESSION["password"])) {
  87. $error = 'Password must be specified. Try again.';
  88. session_destroy();
  89. }
  90. else if ($_SESSION["username"]!=$username) {
  91. $error = 'Wrong user. Login Failed. Try again.';
  92. session_destroy();
  93. }
  94. else if ($_SESSION["password"]!=$password) {
  95. $error = 'Wrong password. Login Failed. Try again.';
  96. session_destroy();
  97. }
  98. else {
  99. //fetching current desktop
  100. $sql = "select a.id, b.folder from desktop a, theme b where a.ind_current = 1 and a.user='".$_SESSION["userid"]."' and a.theme = b.id";
  101. foreach ($dbh->query($sql) as $row) {
  102. $_SESSION["desktopid"] = $row["id"];
  103. $_SESSION["desktopcss"] = './app/themes/'.$row["folder"].'/theme.css';
  104. }
  105. //fetching setting parameters
  106. $sql = "select param, value from param";
  107. foreach ($dbh->query($sql) as $row) {
  108. $_SESSION[$row["param"]] = $row["value"];
  109. }
  110. header("Location: ./index.php");
  111. header('Content-Length: 0');
  112. exit;
  113. }
  114. }
  115. //close connection
  116. $dbh = null;
  117.  
  118. //
  119. $output = '
  120. <!doctype html>
  121. <html>
  122. <head>
  123. <title>AudioStreamer Login</title>
  124.  
  125. <link rel="stylesheet" type="text/css" href="./app/css/login.css" />
  126. <link rel="shortcut icon" href="./favicon.ico" />
  127. <!-- for ios 7 style, multi-resolution icon of 152x152 -->
  128. <meta name="apple-mobile-web-app-capable" content="yes">
  129. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  130. <link rel="apple-touch-icon" sizes="152x152" href="./apple-touch-icon-152x152.png">
  131. <!-- for Chrome on Android, multi-resolution icon of 196x196 and manifest file -->
  132. <link rel="shortcut icon" sizes="196x196" href="./icon196.png">
  133. <link rel="manifest" href="./manifest.json">
  134.  
  135. <script type="text/javascript" src="./app/js/jquery-1.11.0.min.js"></script>
  136. <script type="text/javascript" src="./app/js/jquery-ui-1.10.4.custom.min.js"></script>
  137.  
  138. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  139.  
  140. </head>
  141. <body>
  142. <div id="content">
  143. <div id="login">
  144. ';
  145.  
  146. $output = $output.'
  147. <div class="title">AudioStreamer</div>
  148. <form method=post action="login.php" id="formlogin">
  149. <div class="username">Username</div>
  150. <div><input name=username type="text" autofocus></div>
  151. <div class="password">Password</div>
  152. <div><input name=password type=password></div>
  153. <div class="logindiv" onclick="$(\'#formlogin\').submit()">Login</div>
  154. </form>
  155. <div class="messages">';
  156. //
  157. if ($error) {
  158. $output = $output.'
  159. <div class="error"><span>'.$error.'</span></div>';
  160. }
  161. if ($new_version) {
  162. $output = $output.'
  163. <div class="version"><span>'.$new_version.'</span></div>';
  164. }
  165. //
  166. $output = $output.'
  167. </div>
  168. </div>
  169. </div>
  170. <script type="text/javascript">
  171. $(document).ready(function(){
  172. $("#formlogin").keyup(function(event){
  173. if(event.keyCode == 13) {
  174. //Enter keypress event.
  175. $("#formlogin").submit();
  176. }
  177. });
  178. });
  179. </script>
  180. </body>
  181. </html>
  182. ';
  183.  
  184. echo $output;
  185. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement