Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // PHP Monitor v.0.1 (C)Hannu Balk 2013 http://twitter.com/hannub
- // Horrible code, comment on twitter.
- // Some features missing, might or might not be implemented later.
- session_start();
- if(!isset($_SESSION['curdir']))
- {
- $_SESSION['curdir'] = pathinfo(PHP_SELF, PATHINFO_DIRNAME);//dirname($_SERVER[PHP_SELF]);
- }
- if(isset($_GET['folder']))
- {
- $_SESSION['curdir'] = $_GET['folder'];
- }
- if(isset($_GET['select']))
- {
- if(is_dir($_GET['select']))
- {
- $_SESSION['curdir'] = $_GET['select'];
- }
- }
- if($_SESSION['curdir'] != "/")
- $dir = $_SESSION['curdir'] . "/";
- else
- $dir = $_SESSION['curdir'];
- if($_GET['download']=="true")
- {
- $file = $_GET['select'];
- header('Content-Description: File Transfer');
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename='.basename($file));
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate');
- header('Pragma: public');
- header('Content-Length: ' . filesize($file));
- ob_clean();
- flush();
- readfile($file);
- $_GET['download'] = "false";
- exit;
- }
- if($_GET['dbdlcsv']=="true")
- {
- $conn = mysql_connect($_GET['sqlserver'], $_GET['sqlusername'], $_GET['sqlpassword']);
- mysql_select_db($_GET['db']);
- $str = $str . mysql_error();
- $columns = mysql_query("SHOW COLUMNS FROM " . $_GET['table']);
- $str = $str . mysql_error();
- $data = mysql_query("SELECT * FROM " . $_GET['table']);
- $str = $str . mysql_error();
- $f = true;
- while($row = mysql_fetch_array($columns))
- {
- if($f == false)
- {
- $str = $str . ";";
- }
- else
- $f = false;
- $str = $str . "\"".$row[0]."\"";
- }
- $str = $str . "\r\n";
- while($row = mysql_fetch_array($data, MYSQL_NUM))
- {
- $f = true;
- foreach($row as $r)
- {
- if($f ==false)
- $str = $str . ";";
- else
- $f = false;
- $str = $str . "\"".$r."\"";
- }
- $str= $str ."\r\n";
- }
- header('Content-Description: File Transfer');
- header('Content-Type: text/csv');
- header('Content-Disposition: attachment; filename='.$_GET['table'].".csv");
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate');
- header('Pragma: public');
- header('Content-Length: ' . strlen($str));
- ob_clean();
- flush();
- print($str);
- $_GET['download'] = "false";
- exit;
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta content="fi" http-equiv="Content-Language"/>
- <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
- <title>PHP Monitor</title>
- <link href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" rel="stylesheet" />
- <style type="text/css">
- .BG {
- background-color: #383225;
- }
- .Main {
- background-color: #2E3E3F;
- border: thin solid #C0C0C0;
- border-radius: 5px;
- margin: 10px 20px 30px 20px;
- box-shadow: 10px 10px 3px 2px #000000;
- color: #FFFFCC;
- padding: 10px;
- font-size: x-small;
- font-family: "Courier New", Courier, monospace;
- }
- .FormInput {
- background-color: #121F21;
- color: #A4B6BF;
- font-size: x-small;
- font-family: "Courier New", Courier, monospace;
- }
- .InputButton {
- width: 16px;
- height: 16px;
- vertical-align: middle;
- text-align: center;
- }
- .MenuMargins {
- margin-right: 20px;
- margin-left: 20px;
- }
- .sqltable table{
- border: 1.0px #FFFF66 outset;
- empty-cells: show;
- border-spacing: 2px;
- }
- .sqltable th{
- border: 1.0px #FFFF66 outset;
- empty-cells: show;
- border-spacing: 2px;
- }
- .sqltable td{
- border: 0.5px #FFFF66 ridge;
- empty-cells: show;
- border-spacing: 2px;
- }
- a:link {color:#FFFFCC; text-decoration:none;} /* unvisited link */
- a:visited {color:#FFFFCC; text-decoration:none;} /* visited link */
- a:hover {color:#FFFFCC; text-decoration:underline;} /* mouse over link */
- a:active {color:#FFFFCC;} /* selected link */
- .Terminal {
- font-family: "Courier New", Courier, monospace;
- font-size: small;
- font-weight: normal;
- font-style: normal;
- font-variant: normal;
- text-transform: none;
- color: #00FF00;
- line-height: normal;
- vertical-align: top;
- text-align: left;
- white-space: normal;
- word-spacing: normal;
- letter-spacing: normal;
- background-color: #000000;
- border: 0.5px solid #C0C0C0;
- }
- </style>
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
- <script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
- <script type="text/javascript">
- var fsvisible;
- fsvisible = <?php if(!empty($_GET['fs']))echo $_GET['fs'].";\n";else echo "true;\n";?>
- var sbvisible;
- sbvisible = <?php if(!empty($_GET['sb']))echo $_GET['sb'].";\n";else echo "true;\n";?>
- var fcvisible;
- fcvisible = <?php if(!empty($_GET['fc']))echo $_GET['fc'].";\n";else echo "true;\n";?>
- checkfs();
- checksb();
- checkfc();
- function checkfs()
- {
- if(fsvisible)
- show("#filesystem");
- else
- hide("#filesystem");
- }
- function checksb()
- {
- if(sbvisible)
- show("#sqlbrowser");
- else
- hide("#sqlbrowser");
- }
- function checkfc()
- {
- if(fcvisible)
- show("#filecontent");
- else
- hide("#filecontent");
- }
- function fs()
- {
- if(fsvisible)
- hide("#filesystem");
- else
- show("#filesystem");
- fsvisible = !fsvisible;
- insertParamReload("fs", fsvisible, true);
- }
- function sb()
- {
- if(sbvisible)
- hide("#sqlbrowser");
- else
- show("#sqlbrowser");
- sbvisible = !sbvisible;
- insertParamReload("sb", sbvisible, true);
- }
- function filecontent()
- {
- if(fcvisible)
- hide("#filecontent");
- else
- show("#filecontent");
- fcvisible = !fcvisible;
- insertParamReload("fc", fcvisible, true);
- }
- function hide(obj)
- {
- $(obj).hide("Drop", null, 500, null);
- }
- function show(obj)
- {
- $(obj).show("Drop", null, 500, null);
- }
- function insertParam(key, value)
- {
- insertParamReload(key, value, true);
- }
- function insertParamReload(key, value, reload)
- {
- key = escape(key); value = escape(value);
- var kvp = document.location.search.substr(1).split('&');
- var i=kvp.length; var x; while(i--)
- {
- x = kvp[i].split('=');
- if (x[0]==key)
- {
- x[1] = value;
- kvp[i] = x.join('=');
- break;
- }
- }
- if(i<0) {kvp[kvp.length] = [key,value].join('=');}
- if(reload)
- {
- //this will reload the page, it's likely better to store this until finished
- document.location.search = kvp.join('&');
- }
- }
- function onmouse(who)
- {
- who.style.textDecoration='underline';
- }
- function offmouse(who)
- {
- who.style.textDecoration='none';
- }
- function rowcount(who)
- {
- var x = who.options[who.selectedIndex].value;
- insertParam("rowcount", x);
- }
- function dl()
- {
- insertParam("download", "true");
- }
- function dbdlcsv()
- {
- insertParam("dbdlcsv", "true");
- }
- function exec()
- {
- var params = prompt("Command paramters:", "");
- if(params == null)
- return;
- insertParam("exec", params);
- }
- </script>
- </head>
- <body class="BG">
- <div class="Main">
- <div>
- PHP Monitor 0.1 - (C)2013 <a href="http://twitter.com/hannub" target="_blank">http://twitter.com/hannub</a><br/>
- <a onclick="fs();" onmouseover="onmouse(this);" onmouseout="offmouse(this);;" class="MenuMargins">File System</a>
- <a onclick="sb();" onmouseover="onmouse(this);" onmouseout="offmouse(this);" class="MenuMargins">MySQL Browser</a>
- </div>
- <div id="filesystem" style="display: <?php if(!empty($_GET['fs']))
- {if($_GET['fs']=="true")
- echo "inherit;";
- else
- echo "none;";
- }
- else
- echo "inherit";
- ?>">
- <form name="folderselect" method="get">
- <input type="text" name="folder" style="width:80%" class="FormInput" value="<?php echo $_SESSION['curdir'] ?>"/>
- <input type="submit" value="Go"/>
- </form>
- <div id="filesystem" style="display: <?php if(!empty($_GET['fs']))
- {if($_GET['fs']=="true")
- echo "inherit;";
- else
- echo "none;";
- }
- else
- echo "inherit";
- ?>">
- <b>Files and folders:</b><br/>
- <?php
- //$df = scandir($_SESSION['curdir']);
- $df = scandir($dir);
- if($df == FALSE)
- {
- echo "<b>Failure to open directory [" . $dir . "]</b>";
- }
- else
- {
- $count = count($df);
- $index = 0;
- $cols = 6;
- echo $count . " files or directories in current directory<br/>";
- echo "<table style=\"width:100%\">";
- for($y=0;$y<$count/$cols;$y++)
- {
- echo "<tr>";
- for($i = 0;$i<$cols;$i++)
- {
- echo "<td onclick='insertParam(\"select\", \"" .$dir . $df[$index] ."\");' onmouseover=\"this.style.textDecoration='underline'\" onmouseout=\"this.style.textDecoration='none'\">" . $df[$index] . "</td>\n";
- $index++;
- }
- echo "</tr>\n";
- }
- echo "</table>";
- }
- ?>
- </div>
- <div>
- <?php
- if(isset($_GET['select']))
- {
- echo "<br/><hr/><b><a onclick=\"filecontent();\" onmouseover=\"onmouse(this);\" onmouseout=\"offmouse(this);\">" . $_GET['select'] . ":</a></b><br/>\n";
- echo "<div id=\"filecontent\" style=\"display: ";
- if(!empty($_GET['fc']))
- {if($_GET['fc']=="true")
- echo "inherit;";
- else
- echo "none;";
- }
- else
- echo "inherit";
- echo "\"";
- echo "><table name=\"filecontent\" style=\"width:100%;\">";
- //readfile($_GET['select']);
- $lines = file($_GET['select']);
- foreach($lines as $line_num => $line)
- {
- echo "<tr><td style=\"text-align:right;width:4ex;\"><b>" . $line_num . "</b>:</td><td>". htmlspecialchars($line) . "</td></tr>\n";
- }
- echo "</table></div>";
- echo "<br/>\n";
- echo "<a onclick=\"dl();\" onmouseover=\"onmouse(this);\" onmouseout=\"offmouse(this);\" style=\"margin-right: 25px;\">Download</a>";
- echo "<a onclick=\"exec();\" onmouseover=\"onmouse(this);\" onmouseout=\"offmouse(this);\" style=\"margin-right: 25px;\">Execute</a>";
- echo "<br/>";
- if(isset($_GET['exec']))
- {
- echo "<hr/>";
- echo "<b>Output:</b><br/>";
- //$buffer = shell_exec($_GET['select'] . " ". $_GET['exec']);
- /*exec($_GET['select']. " ".$_GET['exec'], $buffer = array());
- echo "<pre>\n";
- foreach($buffer as $b)
- echo $b . "\r\n";
- echo "\n</pre>\n";*/
- echo "<div class=\"Terminal\">";
- echo "<pre>\n>" .$_GET['select'] . " " . $_GET['exec'] ."\r\n" . shell_exec($_GET['select']. " " . $_GET['exec']) . "\n</pre>\n";
- echo "</div>";
- }
- }
- ?>
- </div>
- </div>
- <div id="sqlbrowser" style="display: <?php if(!empty($_GET['sb']))
- {if($_GET['sb']=="true")
- echo "inherit;";
- else
- echo "none;";
- }
- else
- echo "inherit";
- ?>">
- <hr/>
- <form method="get" name="sqlbrowser">
- <b>SQL Server: </b><input type="text" name="sqlserver" class="FormInput" value="<?php echo $_GET['sqlserver'];?>"/>
- <b>Username: </b><input type="text" name="sqlusername" class="FormInput" value="<?php echo $_GET['sqlusername'];?>"/>
- <b>Password: </b><input type="password" name="sqlpassword" class="FormInput" value="<?php echo $_GET['sqlpassword'];?>"/>
- <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"/>
- </form>
- <br/>
- <?php
- if(isset($_GET['SQLBrowser']))
- {
- if($_GET['sqlservertype']=="mysql")
- {
- $conn = mysql_connect($_GET['sqlserver'], $_GET['sqlusername'], $_GET['sqlpassword']);
- if($conn == false)
- {
- echo "<b>SQL Server connect error: " . mysql_error() . "</b><br/>";
- }
- else
- {
- echo "<hr/>";
- echo "<b>SQL Server connected.</b><br/>";
- $dbs = mysql_list_dbs($conn);
- $count = mysql_num_rows($dbs);
- echo "<b>Server has " . $count . " database(s).</b><br/>";
- echo "<b>Databases:</b><br/><table style=\"width:100%\">\n";
- $cols = 4;
- $index = 0;
- for($i=0;$i<$count/$cols;$i++)
- {
- echo "<tr>";
- for($y=0;$y<$cols;$y++)
- {
- if($index<$count)
- {
- $row = mysql_fetch_object($dbs);
- echo "<td style=\"width:25%;\" onclick='insertParam(\"db\",\"". $row->Database . "\");' onmouseover='onmouse(this);' onmouseout='offmouse(this);'>[". $row->Database . "]</td>\n";
- $index++;
- }
- else
- echo "<td></td>";
- }
- echo "</tr>\n";
- }
- echo "</table><br/>\n";
- if(!empty($_GET['db']))
- {
- mysql_select_db($_GET['db']);
- $tables = mysql_query("SHOW TABLES FROM " . $_GET['db']);
- if($tables==FALSE)
- {
- echo "<b>SQL Error: " . mysql_error()."<b><br/>\n";
- }
- else
- {
- echo "<hr/>";
- $count = mysql_num_rows($tables);
- echo "<b>Database has " . $count . " table(s).</b><br/>\n";
- echo "<b>Tables:</b><br/><table style=\"width:100%\">\n";
- $cols = 4;
- $index = 0;
- for($i=0;$i<$count/$cols;$i++)
- {
- echo "<tr>";
- for($y=0;$y<$cols;$y++)
- {
- if($index<$count)
- {
- $row = mysql_fetch_row($tables);
- echo "<td style=\"width:25%;\" onclick='insertParam(\"table\",\"". $row[0]. "\");' onmouseover='onmouse(this);' onmouseout='offmouse(this);'>[". $row[0] . "]</td>\n";
- $index++;
- }
- else
- echo "<td></td>";
- }
- echo "</tr>\n";
- }
- echo "</table><br/>\n";
- }
- if(!empty($_GET['table']))
- {
- echo "<hr/>";
- $columns = mysql_query("SHOW COLUMNS FROM " . $_GET['table']);
- if(!isset($_GET['rowcount']))
- $_GET['rowcount']=25;
- $data = mysql_query("SELECT * FROM " . $_GET['table'] . " LIMIT " . $_GET['rowcount']);
- if($columns ==FALSE)
- {
- echo "<b>SQL Error: " . mysql_error() . "<b><br/>\n";
- }
- else
- {
- $count = mysql_num_rows($columns);
- echo "<b>Table has " . $count . " column(s).</b><br/>\n";
- echo "<b>Columns:</b><br/><b>Row count:</b> <select name=\"rowcount\" onchange=\"rowcount(this)\">\n";
- 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>";
- echo "<a onclick=\"dbdlcsv();\" onmouseover='onmouse(this);' onmouseout='offmouse(this);'>CSV</a>";
- echo "<br/>";
- echo "<table style=\"width:100%\" class=\"sqltable\">\n";
- echo "<tr>";
- while($row = mysql_fetch_array($columns))
- {
- echo "<th class=\"sqltable\">".$row[0]."</th>\n";
- }
- echo "</tr>";
- while($row = mysql_fetch_array($data, MYSQL_NUM))
- {
- echo "<tr>";
- foreach($row as $r)
- {
- echo "<td class=\"sqltable\">".$r."</td>\n";
- }
- echo "</tr>\n";
- }
- }
- }
- }
- }
- }
- }
- ?>
- </div>
- </div>
- </body>
- </html>
- <?php
- session_write_close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement