Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- set_time_limit(0);
- if(strstr(PHP_OS, "WIN"))
- {
- $OS = "Windows";
- $SIDE = "Client";
- }
- else
- {
- $OS = "Linux";
- $SIDE = "Server";
- }
- $PASSWORD_HASH_USER = "\$2y\$10\$8sJZ.feUSOn/CqXjHsO2hO1owQKYutGfazkdj7f.rCcv7lw9aiXzK";
- $PATH_CODE = folder("/usr", "dev", "Code");
- $FOLDER_BUILD = folder("/dev", "Builds");
- if($SIDE == "Client")
- $FOLDER_ONLINE = folder("C:", "Users", "loiso", "Desktop", "Online");
- else
- $FOLDER_SCRIPT = folder("/home", "altiscraft", "DEV", "C++", "Server");
- // For Server side: folder where you want the exec file to be, example: /home/altiscraft/DEV/C++/Server/Exec/
- $FOLDER_COMPILED = folder($FOLDER_SCRIPT, "Exec");
- $EXEC_NAME = "Compiled";
- $EXEC = $EXEC_NAME;
- if($OS == "Windows")
- $EXEC .= ".exe";
- $FILE_ACCESS = array("main", "config.h", "language.h", "logger", "server", "string_plus.h", "file_plus");
- // END OF BASIC CONFIG
- $FILE_EXT_FOR_PANEL = array("h", "cpp", "res");
- $FOLDER_COMPILED_CODES_NAME = "Obj";
- $FOLDER_COMPILED_CODES = folder($PATH_CODE . $FOLDER_COMPILED_CODES_NAME);
- if($OS == "Windows")
- $INSTRUCTION_MOVE = "move ";
- else
- $INSTRUCTION_MOVE = "mv ";
- if($OS == "Windows")
- $INSTRUCTION_COPY = "copy ";
- else
- $INSTRUCTION_COPY = "cp ";
- if($OS == "Windows")
- $INSTRUCTION_MAKE = "mingw32-make ";
- else
- $INSTRUCTION_MAKE = "make ";
- $PASSWORD_ID = "password" . $SIDE;
- $COMPILE_FILE = "compile.php";
- $MAKEFILE = "makefile.mak";
- $UNDER_MAKEFILE = "makefile-sous.mak";
- // For Server side
- $FOLDER_LOGS = $FOLDER_COMPILED . folder('Extensions', 'Logger', 'Logs');
- $WEBSITE_FOLDER_STYLES = folder("Styles");
- // END OF ADVANCED CONFIG
- $PASSWORD_HASH_ROOT = "\$2y\$10\$v4sjDy2c/.2zEuemcwhxQuS5SnJOtsPzC/AR/Dy4TqihFHXeO/alu";
- $USER_AGENT_ROOT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";
- $HOST_ROOT = "LFbn-1-12506-125.w90-91.abo.wanadoo.fr";
- $COOKIE_ROOT = "root" . $SIDE;
- $COOKIE_HASH_ROOT = "\$2y\$10\$U4GFFBeTv2/Fauopx5rOiOMGQ.RA2QLPYQUDoX77OxES0VnQklNVe";
- $ROOT = false;
- $COMPILATOR = folder("COMPILATOR");
- ?>
- <html>
- <head>
- <title>Compilation panel for <?php echo $OS ?> (<?php echo $SIDE ?>)</title>
- <link rel="stylesheet" href="<?php echo $WEBSITE_FOLDER_STYLES; ?>style.css" />
- <script src="<?php echo $WEBSITE_FOLDER_STYLES; ?>spoiler.js"></script>
- </head>
- <body>
- <form method="post">
- <?php
- setup();
- $error = false;
- if(!isset($_POST[$PASSWORD_ID]) && !isset($_COOKIE[$PASSWORD_ID]))
- connectBtn(false);
- else
- {
- connectBtn(true);
- $files = "";
- $filesModified = array();
- /* echo '<link rel="stylesheet" href="Styles/styles/';
- $style = "default";
- if(isset($_GET["style"]))
- $style = $_GET["style"];
- echo $style;
- echo '.css">
- <script src="Styles/highlight.pack.js"></script>
- <script>hljs.initHighlightingOnLoad();</script>
- <script src="Styles/highlight.min.js"></script>
- <script src="Styles/highlightjs-line-numbers.min.js"></script>
- <script>hljs.initLineNumbersOnLoad();</script>'; */
- function listFolderFiles($dir)
- {
- global $files, $FOLDER_COMPILED_CODES_NAME;
- $ffs = scandir($dir);
- unset($ffs[array_search('.', $ffs, true)]);
- unset($ffs[array_search('..', $ffs, true)]);
- if(count($ffs) < 1)
- return;
- foreach($ffs as $ff)
- {
- if(!is_dir(folder($dir) . $ff) && isFileForPanel($ff)) $files .= folder($dir) . $ff . ' ';
- if(is_dir(folder($dir) . $ff) && $ff != $FOLDER_COMPILED_CODES_NAME) listFolderFiles(folder($dir) . $ff);
- }
- }
- function endsWith($haystack, $needle)
- {
- $length = strlen($needle);
- if($length == 0) return true;
- return (substr($haystack, -$length) === $needle);
- }
- function content($file)
- {
- $fh = fopen($file, 'r');
- return fread($fh, 25000);
- }
- function nameOf($file)
- {
- $slashPos = strrpos($file, DIRECTORY_SEPARATOR);
- return $name = substr($file, $slashPos + 1);
- }
- function edit($file)
- {
- global $PATH_CODE, $filesModified, $COMPILATOR;
- $name = nameOf($file);
- $id = str_replace(".", "_", $name);
- if(isset($_POST[$id]))
- {
- if($_POST[$id] != file_get_contents($file))
- {
- array_push($filesModified, $file);
- file_put_contents($file, $_POST[$id]);
- }
- }
- echo '<h3>' . str_replace($PATH_CODE, $COMPILATOR, $file) . '<a onclick="show(\'' . $name . '\')"><img src="Styles/show.png" width=1.2% class="show' . $name . '"></a><a onclick="hide(\'' . $name . '\')"><img src="Styles/hide.png" width=1.2% class="hide' . $name . '" id="hideID"></a></h3>';
- echo '<textarea name="' . $id . '" class="hide' . $name . '" id="hideID" spellcheck="false">' . content($file) . '</textarea>';
- /* TODO:
- Key input highlighted AND line numbers
- <script>
- document.getElementById("' . $id . '").addEventListener("input", function()
- {
- alert("input event fired");
- }, false);
- </script>*/
- }
- function access($file)
- {
- global $FILE_ACCESS, $ROOT;
- if($ROOT)
- return true;
- for($i = 0; $i < count($FILE_ACCESS); $i++)
- if(strstr($file, $FILE_ACCESS[$i]))
- return true;
- return false;
- }
- listFolderFiles($PATH_CODE);
- $filesTable = explode(" ", $files);
- for($i = 0; $i < count($filesTable); $i++)
- if($filesTable[$i] == "")
- unset($filesTable[$i]);
- foreach($filesTable as $file)
- {
- $file = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $file);
- if(access($file))
- edit($file);
- }
- function recurse_copy($src, $dst, $fileForPanel = false)
- {
- global $COMPILE_FILE, $FOLDER_COMPILED_CODES_NAME;
- $dir = opendir($src);
- @mkdir($dst, 0777); // DO NOT PRINT "COPIED"
- while(false !== ($file = readdir($dir)))
- if(($file != '.') && ($file != '..') && ($file != $FOLDER_COMPILED_CODES_NAME))
- if(is_dir(folder($src) . $file))
- recurse_copy(folder($src) . $file, folder($dst) . $file, $fileForPanel);
- else
- {
- if($fileForPanel)
- if(!isFileForPanel($file))
- continue;
- if($file != $COMPILE_FILE)
- if(file_exists(folder($dst) . $file))
- {
- if(filemtime(folder($src) . $file) > filemtime(folder($dst) . $file))
- copy(folder($src) . $file, folder($dst) . $file);
- }
- else
- copy(folder($src) . $file, folder($dst) . $file);
- }
- closedir($dir);
- }
- echo '<div id="styles">';
- if(isset($_POST['compile']))
- {
- if($_POST['compile'] == "Rebuild")
- $REBUILD = true;
- else
- $REBUILD = false;
- if(count($filesModified) == 0 && !$REBUILD)
- {
- echo '<p id="compiled">No modified files detected ! Compilation aborted !</p>';
- endOfPage();
- }
- function generateRandomString($length = 10)
- {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charactersLength = strlen($characters);
- $randomString = '';
- for($i = 0; $i < $length; $i++)
- $randomString .= $characters[rand(0, $charactersLength - 1)];
- return $randomString;
- }
- $generated = str_replace("/", DIRECTORY_SEPARATOR, date("y/m/d/H/i/s/")) . generateRandomString();
- $FOLDER_BUILD .= folder($generated);
- if($SIDE == "Client")
- $FOLDER_COMPILED .= folder($generated);
- mkdir($FOLDER_BUILD, 0777, true);
- mkdir($FOLDER_COMPILED, 0777, true);
- recurse_copy($PATH_CODE, $FOLDER_BUILD, true);
- $time = time();
- include $PATH_CODE . "compile.php";
- compile();
- echo 'Compilation done in ' . (time() - $time) . ' seconds.
- <p id="compiled">';
- exec($INSTRUCTION_MOVE . $FOLDER_COMPILED_CODES . $EXEC . " " . $FOLDER_COMPILED);
- if($error)
- echo 'Can\'t compile if there are errors.';
- else
- {
- if($SIDE == "Client")
- echo '<a target="_blank" href="' . str_replace($FOLDER_ONLINE, "", $FOLDER_COMPILED . $EXEC) . '">Your client program is available here.</a>';
- else
- echo 'Compilation done and new server program applied !';
- }
- echo '</p>';
- }
- endOfPage();
- }
- ?>
- </form>
- </body>
- </html>
- <?php
- function setup()
- {
- global $time;
- $time = time();
- global $FILE_EXT_FOR_PANEL;
- for($i = 0; $i < count($FILE_EXT_FOR_PANEL); $i++)
- $FILE_EXT_FOR_PANEL[$i] = '.' . $FILE_EXT_FOR_PANEL[$i];
- function checkPw($pw)
- {
- global $PASSWORD_HASH_USER, $PASSWORD_HASH_ROOT, $USER_AGENT_ROOT, $COOKIE_ROOT, $COOKIE_HASH_ROOT, $HOST_ROOT, $PASSWORD_ID, $ROOT;
- if(password_verify($pw, $PASSWORD_HASH_ROOT) && gethostbyaddr($_SERVER["REMOTE_ADDR"]) === $HOST_ROOT && $USER_AGENT_ROOT === $_SERVER["HTTP_USER_AGENT"])
- {
- //setcookie($COOKIE_ROOT, "pw", 2147483647);
- if(isset($_COOKIE[$COOKIE_ROOT]))
- if(password_verify($_COOKIE[$COOKIE_ROOT], $COOKIE_HASH_ROOT))
- $ROOT = true;
- else
- die();
- else
- die();
- }
- else if(!password_verify($pw, $PASSWORD_HASH_USER))
- {
- setcookie($PASSWORD_ID, " ", 2147483647);
- die("<h3>Wrong password !</h3>");
- }
- }
- function connectBtn($login)
- {
- global $PASSWORD_ID;
- if($login)
- if(isset($_POST[$PASSWORD_ID]))
- {
- setcookie($PASSWORD_ID, $_POST[$PASSWORD_ID], 2147483647);
- checkPw($_POST[$PASSWORD_ID]);
- }
- else
- checkPw($_COOKIE[$PASSWORD_ID]);
- else
- echo '<h3>Password: </h3><input type="password" name="' . $PASSWORD_ID . '"> <input type="submit" value="Login">';
- }
- function endOfPage()
- {
- global $time, $SIDE, $FOLDER_COMPILED, $FOLDER_LOGS, $FOLDER_SCRIPT, $WEBSITE_FOLDER_STYLES;
- echo '<br/><input type="submit" name="compile" value="Compile"><br/><br/>';
- echo '<input type="image" name="compile" value="Rebuild" src="' . $WEBSITE_FOLDER_STYLES . 'rebuild.jpg"> Rebuild<br/>';
- if($SIDE == "Server")
- {
- function action($action)
- {
- echo '<input type="radio" name="action" value="' . $action . '"> ' . ucfirst($action) . '<br/>';
- }
- echo '<h4>Action to perform on the server:</h4>';
- action("restart");
- action("stop");
- action("start");
- echo '<br/><input type="submit" value="Execute"><br/>';
- if(isset($_POST['action']))
- {
- $action = $_POST['action'];
- echo '<br/>Result of the execution: <strong>'; system("sh " . $FOLDER_SCRIPT . "script.sh " . $action);
- echo '</strong><br>Action: <strong>' . $action . '</strong> performed on the server !';
- }
- echo '<br/><br/><h4>Available logs:</h3>';
- $logs = scandir($FOLDER_LOGS);
- for($i = 0; $i < count($logs); $i++)
- {
- if(endsWith($logs[$i], ".log"))
- {
- $log = str_replace(".log", "", $logs[$i]);
- echo '<a href="/?log=' . str_replace("#", "%23", $log) . '">' . $log . '</a> ';
- }
- }
- if(isset($_GET["log"]))
- {
- $log = $_GET["log"];
- $logFile = $log . '.log';
- echo '<br/><h4>Content of ' . $logFile . ':</h4>';
- echo str_replace("\n", "<br/>", file_get_contents($FOLDER_LOGS . $logFile));
- }
- /*
- $files = scandir("Styles/styles/");
- for($i = 0; $i < count($files); $i++)
- {
- if(endsWith($files[$i], ".css"))
- {
- $css = str_replace(".css", "", $files[$i]);
- echo '<a href="/?style=' . $css . '">' . $css . '</a> ';
- }
- }
- */
- }
- echo 'Global time: ' . (time() - $time);
- echo '</div>';
- die();
- }
- }
- function isFileForPanel($ff)
- {
- global $FILE_EXT_FOR_PANEL;
- for($i = 0; $i < count($FILE_EXT_FOR_PANEL); $i++)
- if(endsWith($ff, $FILE_EXT_FOR_PANEL[$i]))
- return true;
- return false;
- }
- function path(array $segments)
- {
- return join(DIRECTORY_SEPARATOR, $segments);
- }
- function folder(...$segments)
- {
- return path($segments) . DIRECTORY_SEPARATOR;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement