Work:MySQL Database Manager

From Zoelife4U Wiki
Jump to: navigation, search

This is gonna do it all !!!

<?php
/*
Repairs and Optimizes All MySQL Databases belonging to said user.
Copyright (C) 2008  John D Jones III ampvbmVzX0FUX2JsdWVob3N0LmNvbQ==
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
*/
// Get a session and some settings
session_start();
header("Cache-control: private"); //IE 6 Fix
//Let's try to set some session vars ??
$passwd = $_SESSION['passwd'];
eval(base64_decode('aW5pX3NldCgicmVnaXN0ZXJfZ2xvYmFscyIsICJPZmYiKTsNCmluaV9zZXQoIm1heF9leGVjdXRpb25fdGltZSIsICI2MDAiKTsNCmluaV9zZXQoIm1heF9pbnB1dF90aW1lIiwgIjYwMCIpOw0KaW5pX3NldCgibWVtb3J5X2xpbWl0IiwgIjI2ME0iKTsNCmluaV9zZXQoInVwbG9hZF9tYXhfZmlsZXNpemUiLCAiMjU2TSIpOw0KaW5pX3NldCgicG9zdF9tYXhfc2l6ZSIsICIyNTdNIik7'));
//error_reporting(0);
//A constant or two..
define("HOST", "localhost");
define("MAXUPLOAD", "268435456"); //256M as L3 says 50MB is a high average.
//Set up the Variables
$task=$_GET['task'];
$db=$_POST['db'];
$uid=$_POST['uid'];
$pass=base64_decode($_POST['pass']);
 
//Ok, let's get the meat and potatoes done
//Gotta love functions ;-)
function version() {
    $version = "0.1-Alpha";
    return $version;
}
function getHome(){
    $home_array = $_SERVER['SCRIPT_FILENAME'];
    $home_split = split ('/', $home_array);
    $home = "/".$home_split['1']."/".$home_split['2'];
    return $home;
}
function doHeader() {
    echo '<?xml version="1.0" encoding="utf-8"?>';
    echo "\n";
    //$user = getUser();
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head profile="http://www.w3.org/2000/08/w3c-synd/#">
<?php
if($log) { //Honestly, I forget why this is here?? o_O
    ?>
<title> <?php echo $log;?></title>
<?php }else{ ?>
<title>MySQL Database Manager <?php echo version();?></title>
<?php } ?>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<meta name="generator" content="Vim 7.2" />
<script type="text/javascript">
<!--
var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function encode64(A){var B="";var C,D,E;var F,G,H,I;var J=0;do {C=A.charCodeAt(J++);D=A.charCodeAt(J++);E=A.charCodeAt(J++);F=C>>2;G=((C&3)<<4)|(D>>4);H=((D&15)<<2)|(E>>6);I=E&63;if(isNaN(D)){H=I=64;}else if(isNaN(E)){I=64;}B=B+keyStr.charAt(F)+keyStr.charAt(G)+keyStr.charAt(H)+keyStr.charAt(I);}while(J<A.length);return B;}function encryptData(){var A=document.getElementById("p");var B=encode64(A.value);document.forms['auth'].p.value=B;document.forms['auth'].submit();}
//-->
</script>
<style type="text/css">
*{padding:0;margin:0}
body{font:9333%/1.2 arial,helvetica,sans-serif;font-size:14px}
#wrapper{margin:0 auto;width:922px}
#leftcolumn{color:#333;border:1px solid #ccc;background:#CCEDDD;margin:10px 5px 10px 0px;padding:10px;min-height:500px;width:436px;float:left}
#rightcolumn{float:right;color:#333;border:1px solid #ccc;background:#DDDEEE;margin:10px 0px 10px 0px;padding:10px;min-height:500px;width:436px;display:inline;position:relative}
#wholecolumn{color:#333;border:1px solid #ccc;background:#DDDEEE;margin:10px 0px 10px 0px;padding:10px;min-height:500px;width:900px}
#footer{width:900px;clear:both;color:#333;border:1px solid #ccc;background:#CDEEFC;margin:0px 0px 10px 0px;padding:10px}
.center{text-align:center}
</style>
</head>
<body>
<div id="wrapper">
    <div id="wholecolumn">
        <h2>MySQL Repair and Optimizer</h2>
        <h4> Version: <?php echo version();?> </h4>
        <strong> Domain: </strong><em><?php echo $_SERVER['HTTP_HOST'];?></em> | <strong>User: </strong><em><?php echo $user;?></em>
        <hr />
<?php
} //End doHeader()
function copyright() {
    $fw = base64_decode('MjAwOA==');
    $ty = date('Y');
    if($fw == $ty) {
        $y = $ty;
    }else{
    $y = $fw."-".$ty;
    }
    return $y;
}
function doFooter() {
    $copyright=copyright();
    $GPL='<a href="http://www.gnu.org/licenses/gpl-3.0.html" title="GPL 3.0">GPL 3.0</a>';
    $version=version();
    $usage=memory_get_usage(); //Please leave this for debug purposes.
    echo "</div>"; //End of WholeColumn DIV tag
    echo "
    <div id='footer'>
        <div class='center'>
            <p>
                <small>
                    <span>Version $version &copy; $copyright $GPL I used $usage bytes of memory.</span>
                </small>
            </p>
        </div>
    </div>
    ";
?>
</div>
</body>
</html>
<?php
}//End doFooter();
 
function showUploadForm() {
    ?>
<form enctype="multipart/form-data" action="upload.php" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    Choose a file to upload: <input name="uploaded_file" type="file" />
    <input type="submit" value="Upload" />
</form>
    <?php
}
function doUpload() {
    if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
        //Check if the file is SQL file and it's size is less than MAXUPLOAD
        $filename = basename($_FILES['uploaded_file']['name']);
        $ext = substr($filename, strrpos($filename, '.') + 1);
            if (($ext == "sql") && ($_FILES["uploaded_file"]["type"] == "text/plain") && 
            ($_FILES["uploaded_file"]["size"] < MAXUPLOAD)) {
            //Determine the path to which we want to save this file
                $newname = dirname(__FILE__).'/upload/'.$filename;
                //Check if the file with the same name is already exists on the server
                if (!file_exists($newname)) {
                    //Attempt to move the uploaded file to it's new place
                    if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
                        echo "It's done! The file has been saved as: ".$newname;
                    } else {
                        echo "Error: A problem occurred during file upload!";
                    }
                } else {
                    echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
                }
            } else {
                echo "Error: Only .sql files under 256MB are accepted for upload";
            }
    } else {
        echo "Error: No file uploaded";
    }
}
function showDatabases() {
    //Gonna do this pure PHP baby
    $host = HOST; //Added the CONSTANT later..
    $user = get_current_user();
    //$pass = askPass();
    $link = mysql_connect($host, $user, $password);
    $db_list = mysql_list_dbs($link);
 
    while ($row = mysql_fetch_object($db_list)) {
        echo $row->Database . "\n";
        // We'll actually want to do a SELECT form tag here, to reuse this over
    }
}
function import() {
 
}
function export() {
 
}
function changeEncoding($old,$new) {
 
}
function askPass() {
 
}
function doLogin($p) {
 
}
?>
Personal tools
Online Users
Zoelife4U: