Added possibility for the client environment

canary
WolverinDEV 2018-10-05 16:37:14 +02:00
parent 13795e4fd1
commit d02983408c
6 changed files with 148 additions and 82 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ auth/js/auth.js.map
.idea/
web/*-environment/
client-api/environment

111
client-api/api.php Normal file
View File

@ -0,0 +1,111 @@
<?php
/**
* Created by PhpStorm.
* User: WolverinDEV
* Date: 04.10.18
* Time: 16:42
*/
$BASE_PATH = "files/";
if(!isset($_SERVER['REQUEST_METHOD'])) {
error_log("This is a web only script!");
exit(1);
}
function list_dir($base_dir, &$results = array(), $dir = "") {
$files = scandir($base_dir . $dir);
foreach($files as $key => $value){
$path = $base_dir.$dir.DIRECTORY_SEPARATOR.$value;
if(!is_dir($path)) {
$results[] = ($dir ? $dir.DIRECTORY_SEPARATOR : "").$value;
} else if($value != "." && $value != "..") {
list_dir($base_dir, $results, ($dir ? $dir.DIRECTORY_SEPARATOR : "").$value);
}
}
return $results;
}
function endsWith($haystack, $needle) {
// search forward starting from end minus needle length characters
if ($needle === '') {
return true;
}
$diff = \strlen($haystack) - \strlen($needle);
return $diff >= 0 && strpos($haystack, $needle, $diff) !== false;
}
function fdump($name) {
if(endsWith($name, ".php")) {
global $CLIENT;
$CLIENT = true;
include $name;
return;
}
$file = fopen($name, "r") or die(json_encode([
"success" => false,
"error" => "missing file (" . $name . ")"
]));
echo (fread($file, filesize($name)));
fclose($file);
}
function handle_develop_web_request() {
global $BASE_PATH;
if($_GET["type"] === "files") {
header("Content-Type: text/plain");
header("info-version: 1");
/* header("mode: develop"); */
echo ("type\thash\tpath\tname\n");
foreach (list_dir($BASE_PATH) as $file) {
$type_idx = strrpos($file, ".");
$type = substr($file, $type_idx + 1);
if($type == "php") $type = "html";
$name_idx = strrpos($file, "/");
$name = $name_idx > 0 ? substr($file, $name_idx + 1) : $file;
$path = $name_idx > 0 ? substr($file, 0, $name_idx) : ".";
$name_idx = strrpos($name, ".");
$name = substr($name, 0, $name_idx);
echo $type . "\t" . sha1_file($BASE_PATH . $file) . "\t" . $path . "\t" . $name . "." . $type . "\n";
}
die;
} else if($_GET["type"] === "file") {
header("Content-Type: text/plain");
$path = realpath($BASE_PATH . $_GET["path"]);
$name = $_GET["name"];
if($path === False || strpos($path, realpath(".")) === False || strpos($name, "/") !== False) die(json_encode([
"success" => false,
"error" => "invalid file!"
]));
if(!is_file( $path . DIRECTORY_SEPARATOR . $name)) {
if(endsWith($name, ".html")) {
$name = substr($name, 0, strlen($name) - 4);
$name .= "php";
}
}
if(!is_file( $path . DIRECTORY_SEPARATOR . $name))
die(json_encode([
"success" => false,
"error" => "missing file!"
]));
fdump( $path . DIRECTORY_SEPARATOR . $name);
die();
} else die(json_encode([
"success" => false,
"error" => "invalid action!"
]));
}
handle_develop_web_request();

View File

@ -1,54 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: WolverinDEV
* Date: 04.10.18
* Time: 16:42
*/
if(!isset($_SERVER['REQUEST_METHOD'])) {
error_log("This is a web only script!");
exit(1);
}
include "../files.php";
function handle_develop_web_request() {
if($_GET["type"] === "files") {
header("Content-Type: text/plain");
header("info-version: 1");
header("mode: develop");
echo ("type\thash\tpath\tname\n");
foreach (find_files(0b10, "../") as $file) {
echo $file->type . "\t" . $file->hash . "\t" . $file->path . "\t" . $file->name . "\n";
}
echo "html\t".sha1("main")."\t.\tindex.html\n";
die;
} else if($_GET["type"] === "file") {
header("Content-Type: text/plain");
$available_files = find_files(0b10, "../");
foreach ($available_files as $entry) {
if(($entry->path == $_GET["path"]) && ($entry->name == $_GET["name"])) {
fdump($entry->local_path);
die();
}
}
if($_GET["name"] == "index.html") {
global $CLIENT;
$CLIENT = true;
include "../index.php";
die();
}
die(json_encode([
"success" => false,
"error" => "missing file!"
]));
} else die(json_encode([
"success" => false,
"error" => "invalid action!"
]));
}
handle_develop_web_request();

View File

@ -107,7 +107,7 @@
"local-path" => "./web/html/"
],
[
"web-only" => true,
/* "web-only" => true, */ //Currently client as well
"type" => "html",
"search-pattern" => "/.*\.(php|html)/",
"search-exclude" => "/(files.php)/",
@ -202,16 +202,6 @@
return $result;
}
function fdump($name) {
$file = fopen($name, "r") or die(json_encode([
"success" => false,
"error" => "missing file (" . $name . ")"
]));
echo (fread($file, filesize($name)));
fclose($file);
}
if(isset($_SERVER["argv"])) { //Executed by command line
if(strpos(PHP_OS, "Linux") == -1) {
error_log("Invalid operating system! Help tool only available under linux!");
@ -251,7 +241,7 @@
$environment = "web/dev-environment";
} else if ($_SERVER["argv"][2] == "client") {
$flagset = 0b10;
$environment = "client/dev-environment";
$environment = "client-api/environment/files";
} else {
error_log("Invalid type!");
goto help;
@ -263,7 +253,7 @@
$environment = "web/rel-environment";
} else if ($_SERVER["argv"][2] == "client") {
$flagset = 0b10;
$environment = "client/rel-environment";
$environment = "client-api/environment/files";
} else {
error_log("Invalid type!");
goto help;
@ -275,9 +265,10 @@
{
exec($command = "rm -r " . $environment, $output, $state);
exec($command = "mkdir " . $environment, $output, $state); if($state) goto handle_error;
exec($command = "mkdir -p " . $environment, $output, $state); if($state) goto handle_error;
$files = find_files(0b01, "./", $type);
$files = find_files($flagset, "./", $type);
$original_path = realpath(".");
if(!chdir($environment)) {
error_log("Failed to enter directory " . $environment . "!");
exit(1);
@ -289,22 +280,35 @@
if($state) goto handle_error;
}
$parent = substr_count(realpath($file->path), DIRECTORY_SEPARATOR) - substr_count(realpath('.'), DIRECTORY_SEPARATOR);
$parent_base = substr_count(realpath($file->path), DIRECTORY_SEPARATOR) - substr_count(realpath('.'), DIRECTORY_SEPARATOR);
$parent_file = substr_count(realpath("."), DIRECTORY_SEPARATOR) - substr_count($original_path, DIRECTORY_SEPARATOR); //Current to parent
$parent = $parent_base + $parent_file;
$path = "../../";
$path = "";
for($index = 0; $index < $parent; $index++)
$path = $path . "../";
exec($command = "ln -s " . $path . $file->local_path . " " . $file->path, $output, $state);
if($state) goto handle_error;
echo $command . PHP_EOL;
}
if(!chdir($original_path)) {
error_log("Failed to reset directory!");
exit(1);
}
echo "Generated!" . PHP_EOL;
}
if ($_SERVER["argv"][2] == "client") {
if(!chdir("client-api/environment")) {
error_log("Failed to enter directory client-api/environment!");
exit(1);
}
exec($command = "ln -s ../api.php ./", $output, $state);
if($state) goto handle_error;
}
exit(0);
handle_error:
error_log("Failed to execute command '" . $command . "'!");
error_log("Command returned code " . $state . ". Output: " . PHP_EOL);

View File

@ -17,6 +17,10 @@
{
}
function logged_in() {
return false;
}
$localhost = true;
}
$localhost |= gethostname() == "WolverinDEV";
@ -88,6 +92,7 @@
</div>
</head>
<body>
<?php if(!$CLIENT) { ?>
<!-- No javascript error -->
<div style="display: block; position: fixed; top: 0px; bottom: 0px; left: 0px; right: 0px; background-color: gray; z-index: 1000; text-align: center;" class="no-js">
<div style="position: relative; display: inline-block; top: 30%">
@ -102,6 +107,7 @@
while (elements.length > 0) //Removing these elements (even self)
elements.item(0).remove();
</script>
<?php } ?>
<!-- Loading screen -->
<div class="loader">
@ -140,13 +146,11 @@
<div style="align-self: center;">TeaSpeak Web client by WolverinDEV</div>
<div style="align-self: center; position: fixed; right: 5px;">
<?php
/*
if(logged_in()) {
echo '<a href="' . authPath() . '"auth.php?type=logout>logout</a>';
} else {
echo '<a href="' . authPath() . '"login.php>Login</a> via the TeaSpeak forum.';
}
*/
?>
</div>
</div>

View File

@ -245,7 +245,7 @@ function loadSide() {
console.log("Loading node specific things");
const app = require('electron').remote.app;
module.paths.push(app.getAppPath());
window.$ = require("jquery");
window.$ = require("assets/jquery.min.js");
require("native/loader_adapter.js");
}
@ -264,12 +264,12 @@ function loadSide() {
return;
}
//Load the general scripts and required scripts
awaitLoad(loadScripts([
["vendor/jquery/jquery.min.js", /*"https://code.jquery.com/jquery-latest.min.js"*/],
(window.require !== undefined ? Promise.resolve(true) : awaitLoad(loadScripts([
["vendor/jquery/jquery.min.js"],
]))).then(() => awaitLoad(loadScripts([
["vendor/bbcode/xbbcode.js"],
["https://webrtc.github.io/adapter/adapter-latest.js"]
])).then(() => {
}).then(() => awaitLoad(loadScripts([
]))).then(() => awaitLoad(loadScripts([
//["https://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"]
["vendor/jsrender/jsrender.min.js"]
]))).then(() => {