PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/logs/index.php

https://gitlab.com/tutaalexandr/bot_local
PHP | 138 lines | 121 code | 7 blank | 10 comment | 13 complexity | 5680cd27116d856d3cc89bec712d7ac0 MD5 | raw file
  1. <?php
  2. /***************************************
  3. * http://www.program-o.com
  4. * PROGRAM O
  5. * Version: 2.4.8
  6. * FILE: index.php
  7. * AUTHOR: Elizabeth Perreau and Dave Morton
  8. * DATE: 02-15-2013
  9. * DETAILS: Program O Log File Reader
  10. ***************************************/
  11. if (!file_exists('../config/global_config.php'))
  12. {
  13. header('location: ../install/install_programo.php');
  14. }
  15. else
  16. {
  17. $thisFile = __FILE__;
  18. require_once('../config/global_config.php');
  19. if (!defined('SCRIPT_INSTALLED')) header('location: ' . _INSTALL_PATH_ . 'install_programo.php');
  20. require_once(_LIB_PATH_ . 'PDO_functions.php');
  21. include_once (_LIB_PATH_ . "error_functions.php");
  22. ini_set('error_log', _LOG_PATH_ . 'log.reader.error.log');
  23. }
  24. $now_playing = '';
  25. $server_name = filter_input(INPUT_SERVER,'SERVER_NAME', FILTER_SANITIZE_STRING);
  26. $session_cookie_path = str_replace("http://$server_name", '', _LOG_URL_);
  27. session_set_cookie_params($session_lifetime, $session_cookie_path);
  28. $session_name = 'PGO_LOG';
  29. session_name($session_name);
  30. session_start();
  31. $iframeURL = 'about:blank';
  32. $options = array(
  33. 'file' => FILTER_SANITIZE_STRING,
  34. 'name' => FILTER_SANITIZE_STRING,
  35. 'pass' => FILTER_SANITIZE_STRING,
  36. 'logout' => FILTER_SANITIZE_STRING,
  37. );
  38. $post_vars = filter_input_array(INPUT_POST, $options);
  39. if (isset($post_vars['logout']))
  40. {
  41. $_SESSION['isLoggedIn'] = false;
  42. header('Location: ' . _LOG_URL_);
  43. }
  44. if (isset($post_vars['name']))
  45. {
  46. $name = $post_vars['name'];
  47. $pass = md5($post_vars['pass']);
  48. $dbConn = db_open();
  49. $sql = "select `password` from `myprogramo` where `user_name` = '$name' limit 1;";
  50. $sth = $dbConn->prepare($sql);
  51. $sth->execute();
  52. $row = $sth->fetch();
  53. if ($row !== false)
  54. {
  55. $verify = $row['password'];
  56. if ($pass == $verify)
  57. {
  58. $_SESSION['isLoggedIn'] = true;
  59. header('Location: ' . _LOG_URL_);
  60. }
  61. else $iframeURL = _LIB_URL_ . 'accessdenied.htm';
  62. }
  63. else echo 'No results found!';
  64. }
  65. if (!isset($_SESSION['isLoggedIn']) or $_SESSION['isLoggedIn'] === false)
  66. {
  67. $sel_msg = 'Log in to continue';
  68. $options = '';
  69. $login_form = '
  70. Admin Name: <input name="name" />
  71. Password: <input name="pass" type="password" />
  72. <input type="submit" value="Log In" />';
  73. }
  74. else {
  75. $sel_msg = 'Empty Selection';
  76. $login_form = '
  77. <input type="submit" name="logout" value="Log Out" onclick="document.forms[0].submit();" />
  78. ';
  79. $iframeURL = (!empty($post_vars['file'])) ? $post_vars['file'] : 'about:blank';
  80. $now_playing = ($iframeURL == 'about:blank') ? 'Viewer is empty' : "<strong>Viewing Log File: $iframeURL</strong>";
  81. $optionTemplate = ' <option[fileSelected] value="[file]">[file]</option>' . "\n";
  82. $fileList = glob(_LOG_PATH_ . '*.log');
  83. usort(
  84. $fileList,
  85. create_function('$b,$a', 'return filemtime($a) - filemtime($b);')
  86. );
  87. $options = '';
  88. $postedFile = $post_vars['file'];
  89. foreach ($fileList as $file) {
  90. $file = str_replace(_LOG_PATH_, '', $file);
  91. $file = trim($file);
  92. $fileSelected = ($file == $postedFile) ? ' selected="selected"' : '';
  93. $row = str_replace('[file]', trim($file), $optionTemplate);
  94. $row = str_replace('[fileSelected]', $fileSelected, $row);
  95. $options .= $row;
  96. }
  97. }
  98. ?>
  99. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  100. <html xmlns="http://www.w3.org/1999/xhtml">
  101. <head>
  102. <title>Log File Reader</title>
  103. <style type="text/css">
  104. body, html {
  105. min-width: 800px;
  106. }
  107. #viewer {
  108. position: absolute;
  109. left: 5px;
  110. top: 75px;
  111. right: 5px;
  112. bottom: 5px;
  113. }
  114. </style>
  115. </head>
  116. <body>
  117. <form name="fileChoice" action="<?php echo _LOG_URL_ ?>" method="POST">
  118. Select a Log File to view: <select name="file" id="file" size="1" onchange="document.forms[0].submit();">
  119. <option value="about:blank"><?php echo $sel_msg ?></option>
  120. <?php echo rtrim($options) . PHP_EOL; ?>
  121. </select> &nbsp; &nbsp;
  122. <?php echo $login_form ?> &nbsp; &nbsp;
  123. <a href="<?php echo _LOG_URL_ ?>">Reload the Page</a>
  124. </form>
  125. <br />
  126. <div id="now_playing"><?php echo $now_playing ?></div>
  127. <div id="viewer">
  128. <iframe width="99%" height="99%" src="<?php echo $iframeURL ?>"><h1>Access Denied!</h1></iframe>
  129. </div>
  130. </body>
  131. </html>