From 0a11e8b332aa07728582c19d7dfeaa03b2e80887 Mon Sep 17 00:00:00 2001 From: housamz Date: Mon, 1 Mar 2021 14:01:17 +0000 Subject: [PATCH 1/6] 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: - +

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 - - - - +