From a6254341feb77ac09845aa7eba859b3b66154703 Mon Sep 17 00:00:00 2001 From: Housam Ziad Date: Sun, 9 Feb 2020 02:39:05 +0000 Subject: [PATCH 01/11] Update handler.php --- handler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handler.php b/handler.php index 598d3ef..b4e3cc6 100755 --- a/handler.php +++ b/handler.php @@ -442,7 +442,7 @@ function navConfirm(loc) {

Created using MAGE ♥

- Visit Project + Visit Project
@@ -491,4 +491,4 @@ function navConfirm(loc) { echo json_encode(array('status' => 'error','message'=> 'Unknown error occured')); } -?> \ No newline at end of file +?> From e2015261a387f46e9d47b565e6dc6036a2caed2c Mon Sep 17 00:00:00 2001 From: Housam Ziad Date: Mon, 17 Feb 2020 02:34:57 +0000 Subject: [PATCH 02/11] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7ac92c5..a4e6fb3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # MAGE :: PHP MySQL Admin Panel Generator +For Python version visit: [Python Mage](https://github.com/housamz/python-mysql-admin-panel-generator) PHP MySQL Admin Panel Generator (MAGE), a PHP tool that helps you create a PHP Admin Panel for any MySQL database in seconds. Mage is not PHPMyAdmin; it doesn't contain all your databases. It physically creates an admin panel for a database. From f6a557a9d2d521f962dca88b2dd4ba65b4021eec Mon Sep 17 00:00:00 2001 From: Housam Ziad Date: Mon, 17 Feb 2020 02:35:10 +0000 Subject: [PATCH 03/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4e6fb3..9f3ac13 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # MAGE :: PHP MySQL Admin Panel Generator -For Python version visit: [Python Mage](https://github.com/housamz/python-mysql-admin-panel-generator) +For Python version visit: [Python Mage](https://github.com/housamz/python-mysql-admin-panel-generator) . PHP MySQL Admin Panel Generator (MAGE), a PHP tool that helps you create a PHP Admin Panel for any MySQL database in seconds. Mage is not PHPMyAdmin; it doesn't contain all your databases. It physically creates an admin panel for a database. From dac7f514a978cb1297867628dd5ace5a94fc6b3b Mon Sep 17 00:00:00 2001 From: Housam Ziad Date: Mon, 17 Feb 2020 02:35:34 +0000 Subject: [PATCH 04/11] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f3ac13..f6b86f8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # MAGE :: PHP MySQL Admin Panel Generator -For Python version visit: [Python Mage](https://github.com/housamz/python-mysql-admin-panel-generator) . +For Python version visit: [Python Mage](https://github.com/housamz/python-mysql-admin-panel-generator) + PHP MySQL Admin Panel Generator (MAGE), a PHP tool that helps you create a PHP Admin Panel for any MySQL database in seconds. Mage is not PHPMyAdmin; it doesn't contain all your databases. It physically creates an admin panel for a database. From 8cbb2e087318a1442a7e4f8af3e3115b15ccd586 Mon Sep 17 00:00:00 2001 From: Housam Ziad Date: Mon, 17 Feb 2020 02:56:20 +0000 Subject: [PATCH 05/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6b86f8..d79de98 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # MAGE :: PHP MySQL Admin Panel Generator -For Python version visit: [Python Mage](https://github.com/housamz/python-mysql-admin-panel-generator) +Available for Python also: [Python Mage](https://github.com/housamz/python-mysql-admin-panel-generator) PHP MySQL Admin Panel Generator (MAGE), a PHP tool that helps you create a PHP Admin Panel for any MySQL database in seconds. From 0a11e8b332aa07728582c19d7dfeaa03b2e80887 Mon Sep 17 00:00:00 2001 From: housamz Date: Mon, 1 Mar 2021 14:01:17 +0000 Subject: [PATCH 06/11] Minor fixes and adding Debugging section to README --- README.md | 24 +++++++++-- handler.php | 103 +++++++++++++++++++-------------------------- index.php | 39 ++++++++++------- library/data.php | 36 ++++++++-------- library/index.php | 5 ++- library/login.php | 14 +++--- library/logout.php | 4 +- 7 files changed, 117 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index d79de98..7e64740 100644 --- a/README.md +++ b/README.md @@ -16,16 +16,17 @@ Mage (meɪdʒ): a magician or learned person. ### Disclaimer: Always backup your database. ## Instructions: -1- Start by providing your MySQL Server Info, then click Next Step button. +***Note: You need to make sure that you have `php-mysql` package that connects PHP with MySQL, and that you change the `generated` directory permissions to be 777.*** +1- Start by providing your MySQL Server Info, then click Next Step button. ![Server info](images/1.png) -2- The tool will scan the server for available databases and list them in a dropdown menu, select the database that you want and then click "Generate Admin Panel" button +2- The tool will scan the server for available databases and list them in a dropdown menu, select the database that you want and then click "Generate Admin Panel" button ![Second Step](images/2.png) -3- After a few seconds, you'll get a success message, with a link to the newly created admin panel, and a report of all the operations that were done. +3- After a few seconds, you'll get a success message, with a link to the newly created admin panel, and a report of all the operations that were done. ![Success Message](images/3.png) -4- Click the link to the admin panel. You have to sign in using "admin" as an email and a password. +4- Click the link to the admin panel. You have to sign in using "admin" as an email and a password. ![Sign in](images/4.png) --- @@ -37,3 +38,18 @@ You'll get a clean bootstrap interface to control the website, check below scree ![Admin Panel 2](images/6.png) --- ![Admin Panel 3](images/7.png) + + +## Debugging: +#### Nothing happens when you provide credentials on home page +You need to install `php-mysql` package, the following installs the latest version. +```bash +sudo apt install php-mysql +service apache2 restart +``` + +#### Nothing happens when I click Generate button +Change the `generated` directory permission to 777 +```bash +chmod 777 generated +``` \ No newline at end of file diff --git a/handler.php b/handler.php index b4e3cc6..e1745cb 100755 --- a/handler.php +++ b/handler.php @@ -4,17 +4,15 @@ header('Content-Type: application/json'); // function for removing last colon -function removeLastChar($string){ +function removeLastChar($string) { $string = substr($string, 0, -1); return $string; } // function to create files -function createFile($database, $myFile, $stringData){ +function createFile($database, $myFile, $stringData) { $path = "generated/".$database.date("Y-m-d_H-i"); - if (file_exists($path)) { - - } else { + if (!file_exists($path)) { mkdir($path, 0777); } if (file_exists($path."/includes")) { @@ -27,12 +25,12 @@ function createFile($database, $myFile, $stringData){ fclose($fh); } -// function to return a random glyphicon to be used in the side bar links -function random_glyphicon(){ - $glyphicons = array("asterisk", "plus", "euro", "eur", "minus", "cloud", "envelope", "pencil", "glass", "music", "search", "heart", "star", "star-empty", "user", "film", "th-large", "th", "th-list", "ok", "remove", "zoom-in", "zoom-out", "off", "signal", "cog", "file", "time", "road", "download-alt", "download", "upload", "inbox", "play-circle", "repeat", "refresh", "list-alt", "lock", "flag", "headphones", "volume-off", "volume-down", "volume-up", "qrcode", "barcode", "tag", "tags", "book", "bookmark", "print", "camera", "font", "bold", "italic", "text-height", "text-width", "align-left", "align-center", "align-right", "align-justify", "list", "indent-left", "indent-right", "facetime-video", "picture", "map-marker", "adjust", "tint", "share", "check", "move", "step-backward", "fast-backward", "backward", "play", "pause", "stop", "forward", "fast-forward", "step-forward", "eject", "chevron-left", "chevron-right", "plus-sign", "minus-sign", "remove-sign", "ok-sign", "question-sign", "info-sign", "screenshot", "remove-circle", "ok-circle", "ban-circle", "arrow-left", "arrow-right", "arrow-up", "arrow-down", "share-alt", "resize-full", "resize-small", "exclamation-sign", "gift", "leaf", "fire", "eye-open", "eye-close", "warning-sign", "plane", "calendar", "random", "comment", "magnet", "chevron-up", "chevron-down", "retweet", "shopping-cart", "folder-close", "folder-open", "resize-vertical", "resize-horizontal", "hdd", "bullhorn", "bell", "certificate", "thumbs-up", "thumbs-down", "hand-right", "hand-left", "hand-up", "hand-down", "circle-arrow-right", "circle-arrow-left", "circle-arrow-up", "circle-arrow-down", "globe", "wrench", "tasks", "filter", "briefcase", "fullscreen", "dashboard", "paperclip", "heart-empty", "link", "phone", "pushpin", "usd", "gbp", "sort", "sort-by-alphabet", "sort-by-alphabet-alt", "sort-by-order", "sort-by-order-alt", "sort-by-attributes", "sort-by-attributes-alt", "unchecked", "expand", "collapse-down", "collapse-up", "log-in", "flash", "new-window", "record", "save", "open", "saved", "import", "export", "send", "floppy-disk", "floppy-saved", "floppy-remove", "floppy-save", "floppy-open", "credit-card", "transfer", "cutlery", "header", "compressed", "earphone", "phone-alt", "tower", "stats", "sd-video", "hd-video", "subtitles", "sound-stereo", "sound-dolby", "sound-5-1", "sound-6-1", "sound-7-1", "copyright-mark", "registration-mark", "cloud-download", "cloud-upload", "tree-conifer", "tree-deciduous", "cd", "save-file", "open-file", "level-up", "copy", "paste", "alert", "equalizer", "king", "queen", "pawn", "bishop", "knight", "baby-formula", "tent", "blackboard", "bed", "apple", "erase", "hourglass", "lamp", "duplicate", "piggy-bank", "scissors", "bitcoin", "btc", "xbt", "yen", "jpy", "ruble", "rub", "scale", "ice-lolly", "ice-lolly-tasted", "education", "option-horizontal", "option-vertical", "menu-hamburger", "modal-window", "oil", "grain", "sunglasses", "text-size", "text-color", "text-background", "object-align-top", "object-align-bottom", "object-align-horizontal", "object-align-left", "object-align-vertical", "object-align-right", "triangle-right", "triangle-left", "triangle-bottom", "triangle-top", "console", "superscript", "subscript", "menu-left", "menu-right", "menu-down", "menu-up"); +// function to return a random glyph icon to be used in the side bar links +function random_glyphicon() { + $glyph_icons = array("asterisk", "plus", "euro", "eur", "minus", "cloud", "envelope", "pencil", "glass", "music", "search", "heart", "star", "star-empty", "user", "film", "th-large", "th", "th-list", "ok", "remove", "zoom-in", "zoom-out", "off", "signal", "cog", "file", "time", "road", "download-alt", "download", "upload", "inbox", "play-circle", "repeat", "refresh", "list-alt", "lock", "flag", "headphones", "volume-off", "volume-down", "volume-up", "qrcode", "barcode", "tag", "tags", "book", "bookmark", "print", "camera", "font", "bold", "italic", "text-height", "text-width", "align-left", "align-center", "align-right", "align-justify", "list", "indent-left", "indent-right", "facetime-video", "picture", "map-marker", "adjust", "tint", "share", "check", "move", "step-backward", "fast-backward", "backward", "play", "pause", "stop", "forward", "fast-forward", "step-forward", "eject", "chevron-left", "chevron-right", "plus-sign", "minus-sign", "remove-sign", "ok-sign", "question-sign", "info-sign", "screenshot", "remove-circle", "ok-circle", "ban-circle", "arrow-left", "arrow-right", "arrow-up", "arrow-down", "share-alt", "resize-full", "resize-small", "exclamation-sign", "gift", "leaf", "fire", "eye-open", "eye-close", "warning-sign", "plane", "calendar", "random", "comment", "magnet", "chevron-up", "chevron-down", "retweet", "shopping-cart", "folder-close", "folder-open", "resize-vertical", "resize-horizontal", "hdd", "bullhorn", "bell", "certificate", "thumbs-up", "thumbs-down", "hand-right", "hand-left", "hand-up", "hand-down", "circle-arrow-right", "circle-arrow-left", "circle-arrow-up", "circle-arrow-down", "globe", "wrench", "tasks", "filter", "briefcase", "fullscreen", "dashboard", "paperclip", "heart-empty", "link", "phone", "pushpin", "usd", "gbp", "sort", "sort-by-alphabet", "sort-by-alphabet-alt", "sort-by-order", "sort-by-order-alt", "sort-by-attributes", "sort-by-attributes-alt", "unchecked", "expand", "collapse-down", "collapse-up", "log-in", "flash", "new-window", "record", "save", "open", "saved", "import", "export", "send", "floppy-disk", "floppy-saved", "floppy-remove", "floppy-save", "floppy-open", "credit-card", "transfer", "cutlery", "header", "compressed", "earphone", "phone-alt", "tower", "stats", "sd-video", "hd-video", "subtitles", "sound-stereo", "sound-dolby", "sound-5-1", "sound-6-1", "sound-7-1", "copyright-mark", "registration-mark", "cloud-download", "cloud-upload", "tree-conifer", "tree-deciduous", "cd", "save-file", "open-file", "level-up", "copy", "paste", "alert", "equalizer", "king", "queen", "pawn", "bishop", "knight", "baby-formula", "tent", "blackboard", "bed", "apple", "erase", "hourglass", "lamp", "duplicate", "piggy-bank", "scissors", "bitcoin", "btc", "xbt", "yen", "jpy", "ruble", "rub", "scale", "ice-lolly", "ice-lolly-tasted", "education", "option-horizontal", "option-vertical", "menu-hamburger", "modal-window", "oil", "grain", "sunglasses", "text-size", "text-color", "text-background", "object-align-top", "object-align-bottom", "object-align-horizontal", "object-align-left", "object-align-vertical", "object-align-right", "triangle-right", "triangle-left", "triangle-bottom", "triangle-top", "console", "superscript", "subscript", "menu-left", "menu-right", "menu-down", "menu-up"); - $rand = array_rand($glyphicons, 1); - return $glyphicons[$rand]; + $rand = array_rand($glyph_icons, 1); + return $glyph_icons[$rand]; } @@ -46,12 +44,13 @@ function random_glyphicon(){ // connecting to the host $link = mysqli_connect($host, $username, $password); + if (!$link) { die(json_encode(array('status' => 'error','message'=> 'Could not connect: ' . mysqli_error($link)))); } // if the action is to connect, we request all databases - if($action == "connect"){ + if($action == "connect") { $result = ''; $res = mysqli_query($link, "SHOW DATABASES"); if (!$res) { @@ -61,7 +60,7 @@ function random_glyphicon(){ $result .= ""; } - if(!$result){ + if(!$result) { echo json_encode(array('status' => 'error','message'=> 'Error in data collection')); } else { echo json_encode(array('status' => 'success','result'=> $result)); @@ -70,17 +69,17 @@ function random_glyphicon(){ } // process starts if the action is to generate the admin panel - else if($action == "generate") { + else if ($action == "generate") { // get the database name $database = $_POST["database"]; // gather success info and display to user at the end $message = "The operations that were performed are:
    "; - + // select the database - $linkdb = mysqli_select_db($link, $database); - if (!$linkdb) { + $db_link = mysqli_select_db($link, $database); + if (!$db_link) { die(json_encode(array('status' => 'error','message'=> 'Couldn\'t select database: ' . mysqli_error($link)))); } @@ -97,7 +96,7 @@ function random_glyphicon(){ // loop to show all the tables and fields $loop = mysqli_query($link, "SHOW tables FROM $database"); - + if (!$loop) { die(json_encode(array('status' => 'error','message'=> 'Couldn\'t select table: ' . mysqli_error($link)))); } @@ -106,7 +105,7 @@ function random_glyphicon(){ // collecting DB connection info to generate includes/connect.php file $connection = " "; @@ -139,7 +138,7 @@ function random_glyphicon(){ $header = ' @@ -153,12 +152,8 @@ function random_glyphicon(){ ' .ucfirst($database). ' Admin Panel - - - - - + @@ -169,7 +164,6 @@ function random_glyphicon(){ - @@ -186,7 +180,6 @@ function random_glyphicon(){ ' .ucfirst($database). '
    - @@ -200,7 +193,7 @@ function random_glyphicon(){ '; // looping all the database tables - while($table = mysqli_fetch_array($loop)){ + while($table = mysqli_fetch_array($loop)) { // having a name for the table in two cases, all small caps and capitalised $capital = ucfirst($table[0]); @@ -227,7 +220,7 @@ function random_glyphicon(){ \$data=[]; $"."act = $"."_GET['act']; - if($"."act == \"edit\"){ + if($"."act == \"edit\") { $"."id = $"."_GET['id']; $".$small." = getById(\"".$small."\", $"."id); } @@ -243,7 +236,7 @@ function random_glyphicon(){ // continue the save page $save .= " - if($"."cat == \"".$small."\" || $"."cat_get == \"".$small."\"){ + if($"."cat == \"".$small."\" || $"."cat_get == \"".$small."\") { "; // continue the home page @@ -270,13 +263,13 @@ function random_glyphicon(){ or die ('cannot select table fields'); // looping in the columns - while ($col = mysqli_fetch_array($row)){ - // data for the table in the show page tableName.php + while ($col = mysqli_fetch_array($row)) { + // data for the table in the show page tableName.php $head .= " \t" . ucfirst(str_replace("_", " ", $col[0])) . "\n"; $body .= " \t\n"; - if($col[3] != "PRI"){ - if($col[1] == "text"){ + if($col[3] != "PRI") { + if($col[1] == "text") { // continue the edit page with a text area for a type text column $edit .= " @@ -293,13 +286,13 @@ function random_glyphicon(){ } // check if the column is not the ID to create the corresponding save and insert data - if ($col[0] != 'id'){ + if ($col[0] != 'id') { $save .= "$" . $col[0] . " = mysqli_real_escape_string(\$link,$"."_POST[\"" . $col[0] . "\"]);\n"; $insert .= " `" . $col[0] . "` ,"; - if($col[0] == "password"){ + if($col[0] == "password") { $attach_password = 1; $values .= " '\".md5($" . $col[0] . ").\"',"; @@ -327,7 +320,6 @@ function random_glyphicon(){ ?> "; - // build the whole page $show .= $head."\n"; $show .= $mid."\n"; @@ -341,7 +333,6 @@ function random_glyphicon(){ "; - $edit .= "
    @@ -350,21 +341,21 @@ function random_glyphicon(){ $save .= " - if($"."act == \"add\"){ + if($"."act == \"add\") { mysqli_query(\$link, \"INSERT INTO `".$small."` ( ".removeLastChar($insert).") VALUES (".removeLastChar($values).") \"); - }elseif ($"."act == \"edit\"){ + }elseif ($"."act == \"edit\") { mysqli_query(\$link, \"UPDATE `".$small."` SET ".removeLastChar($update)." WHERE `id` = '\".$"."id.\"' \"); "; - if($attach_password == 1){ + if($attach_password == 1) { $save .= " - if($"."_POST[\"password\"] && $"."_POST[\"password\"] != \"\"){ + if($"."_POST[\"password\"] && $"."_POST[\"password\"] != \"\") { mysqli_query(\$link, \"UPDATE `".$small."` SET `password` = '\".md5($"."password).\"' WHERE `id` = '\".$"."id.\"' \"); } "; } - $save .= " - }elseif ($"."act_get == \"delete\"){ + $save .= " + }elseif ($"."act_get == \"delete\") { mysqli_query(\$link, \"DELETE FROM `".$small."` WHERE id = '\".$"."id_get.\"' \"); } header(\"location:\".\"".$small.".php\"); @@ -395,7 +386,6 @@ function random_glyphicon(){ - @@ -407,9 +397,8 @@ function random_glyphicon(){ - - '; @@ -439,7 +426,7 @@ function navConfirm(loc) { $header .= "
  • Logout
- +

Created using MAGE ♥

Visit Project @@ -486,9 +473,7 @@ function navConfirm(loc) { } - } else { - - echo json_encode(array('status' => 'error','message'=> 'Unknown error occured')); + echo json_encode(array('status' => 'error','message'=> 'Unknown error occurred')); } ?> diff --git a/index.php b/index.php index bf17b6c..7c77907 100644 --- a/index.php +++ b/index.php @@ -8,12 +8,9 @@ MAGE :: MySQL Admin Generator - - - - +