Changed some stuff

canary
WolverinDEV 2018-10-13 18:44:54 +02:00
parent 575a763079
commit 68ca5ad5ff
6 changed files with 185 additions and 76 deletions

View File

@ -242,7 +242,7 @@
var_dump($_GET);
var_dump($_POST);
if ($_GET["type"] == "login") {
die(checkLogin($_POST["user"], $_POST["pass"]));
die(json_encode(checkLogin($_POST["user"], $_POST["pass"])));
} else if ($_GET["type"] == "logout") {
logout();
global $localhost;
@ -253,7 +253,7 @@
setcookie($session->getCookieName(), '', time() - 3600, '/');
setcookie("session", '', time() - 3600, '/');
} else die("unknown type!");
} else if(isset($_POST)) {
} else if(isset($_POST["action"])) {
error_log("Got auth post request!");
if($_POST["action"] === "login") {
die(json_encode(checkLogin($_POST["user"], $_POST["pass"])));

View File

@ -7,6 +7,7 @@
*/
$UI_BASE_PATH = "ui-files/";
$CLIENT_BASE_PATH = "files/";
if(!isset($_SERVER['REQUEST_METHOD'])) {
error_log("This is a web only script!");
@ -54,80 +55,168 @@
fclose($file);
}
function error_exit($message) {
http_response_code(400);
die(json_encode([
"success" => false,
"msg" => $message
]));
}
function handle_develop_web_request() {
global $UI_BASE_PATH;
if($_GET["type"] === "files") {
header("Content-Type: text/plain");
header("info-version: 1");
/* header("mode: develop"); */
if(isset($_GET) && isset($_GET["type"])) {
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($UI_BASE_PATH) as $file) {
$type_idx = strrpos($file, ".");
$type = substr($file, $type_idx + 1);
if($type == "php") $type = "html";
echo ("type\thash\tpath\tname\n");
foreach (list_dir($UI_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($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);
$name_idx = strrpos($name, ".");
$name = substr($name, 0, $name_idx);
echo $type . "\t" . sha1_file($UI_BASE_PATH . $file) . "\t" . $path . "\t" . $name . "." . $type . "\n";
}
die;
} else if($_GET["type"] === "file") {
header("Content-Type: text/plain");
$path = realpath($UI_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";
echo $type . "\t" . sha1_file($UI_BASE_PATH . $file) . "\t" . $path . "\t" . $name . "." . $type . "\n";
}
}
if(!is_file( $path . DIRECTORY_SEPARATOR . $name))
die(json_encode([
"success" => false,
"error" => "missing file!"
]));
die;
} else if($_GET["type"] === "file") {
header("Content-Type: text/plain");
$path = realpath($UI_BASE_PATH . $_GET["path"]);
$name = $_GET["name"];
if($path === False || strpos($path, realpath(".")) === False || strpos($name, "/") !== False) error_exit("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)) error_exit("Missing file");
fdump( $path . DIRECTORY_SEPARATOR . $name);
die();
} else if ($_GET["type"] == "update-info") {
global $CLIENT_BASE_PATH;
$raw_versions = file_get_contents($CLIENT_BASE_PATH . "/version.json");
if($raw_versions === false) error_exit("Missing file!");
$versions = json_decode($raw_versions, true);
$versions["success"] = true;
die(json_encode($versions));
} else if ($_GET["type"] == "update-download") {
global $CLIENT_BASE_PATH;
$path = $CLIENT_BASE_PATH . $_GET["channel"] . DIRECTORY_SEPARATOR . $_GET["version"] . DIRECTORY_SEPARATOR;
$raw_release_info = file_get_contents($path . "info.json");
if($raw_release_info === false) error_exit("missing info file (version and/or channel missing. Path was " . $path . ")");
$release_info = json_decode($raw_release_info);
foreach($release_info as $platform) {
if($platform->platform != $_GET["platform"]) continue;
if($platform->arch != $_GET["arch"]) continue;
http_response_code(200);
header("Cache-Control: public"); // needed for internet explorer
header("Content-Type: application/binary");
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize($path . $platform->update));
header("Content-Disposition: attachment; filename=update.tar.gz");
readfile($path . $platform->update);
die();
}
error_exit("Missing platform, arch or file");
}
} else if($_POST["type"] == "deploy-build") {
global $CLIENT_BASE_PATH;
if(!isset($_POST["secret"]) || !isset($_POST["version"]) || !isset($_POST["platform"]) || !isset($_POST["arch"]) || !isset($_POST["update_suffix"]) || !isset($_POST["installer_suffix"]))
error_exit("Missing required information!");
{
$require_secret = file_get_contents(".deploy_secret");
if($require_secret === false || strlen($require_secret) == 0) error_exit("Server missing secret!");
if(!is_string($_POST["secret"])) error_exit("Invalid secret!");
if(strcmp(trim($require_secret), trim($_POST["secret"])) !== 0)
error_exit("Secret does not match!");
}
if(!isset($_FILES["update"])) error_exit("Missing update file");
if($_FILES["update"]["error"] !== UPLOAD_ERR_OK) error_exit("Upload for update failed!");
if(!isset($_FILES["installer"])) error_exit("Missing installer file");
if($_FILES["installer"]["error"] !== UPLOAD_ERR_OK) error_exit("Upload for installer failed!");
$json_version = json_decode($_POST["version"], true);
$version = $json_version["major"] . "." . $json_version["minor"] . "." . $json_version["patch"] . ($json_version["build"] > 0 ? $json_version["build"] : "");
$path = $CLIENT_BASE_PATH . DIRECTORY_SEPARATOR . $_POST["channel"] . DIRECTORY_SEPARATOR . $version . DIRECTORY_SEPARATOR;
exec("mkdir -p " . $path);
//mkdir($path, 777, true);
$filename_update = "TeaClient-" . $_POST["platform"] . "_" . $_POST["arch"] . "." . $_POST["update_suffix"];
$filename_install = "TeaClient-" . $_POST["platform"] . "_" . $_POST["arch"] . "." . $_POST["installer_suffix"];
{
$version_info = file_get_contents($path . "info.json");
if($version_info === false) $version_info = array();
else $version_info = json_decode($version_info, true);
for($index = 0; $index < count($version_info); $index++) {
if($version_info[$index]["platform"] == $_POST["platform"] && $version_info[$index]["arch"] == $_POST["arch"]) {
array_splice($version_info, $index, 1);
break;
}
}
$info = array();
$info["platform"] = $_POST["platform"];
$info["arch"] = $_POST["arch"];
$info["update"] = $filename_update;
$info["install"] = $filename_install;
array_push($version_info, $info);
file_put_contents($path . "info.json", json_encode($version_info));
}
{
$filename = $CLIENT_BASE_PATH . DIRECTORY_SEPARATOR . "version.json";
$indexes = file_get_contents($filename);
if($indexes === false) $indexes = array();
else $indexes = json_decode($indexes, true);
$index = &$indexes[$_POST["channel"]];
if(!isset($index))
$index = array();
for($idx = 0; $idx < count($index); $idx++) {
if($index[$idx]["platform"] == $_POST["platform"] && $index[$idx]["arch"] == $_POST["arch"]) {
array_splice($index, $idx, 1);
break;
}
}
$info = array();
$info["platform"] = $_POST["platform"];
$info["arch"] = $_POST["arch"];
$info["version"] = $json_version;
array_push($index, $info);
file_put_contents($filename, json_encode($indexes));
}
move_uploaded_file($_FILES["installer"]["tmp_name"],$path . $filename_install);
move_uploaded_file($_FILES["update"]["tmp_name"],$path . $filename_update);
fdump( $path . DIRECTORY_SEPARATOR . $name);
die();
} else if ($_GET["type"] == "update-info") {
//TODO read real data from update/info.txt
die(json_encode([
"versions" => [
[
"channel" => "beta",
"major" => 1,
"minor" => 0,
"patch" => 0,
"build" => 0
],
[
"channel" => "release",
"major" => 1,
"minor" => 0,
"patch" => 0,
"build" => 0
]
],
"updater" => [
"channel" => "release",
"major" => 1,
"minor" => 0,
"patch" => 0,
"build" => 0
],
"success" => true
]));
} else die(json_encode([
@ -136,4 +225,4 @@
]));
}
handle_develop_web_request();
handle_develop_web_request();

View File

@ -1,3 +1,4 @@
/* native functions declaration */
import * as updater from "updater/updater";
declare function displayCriticalError(message: string);

View File

@ -322,15 +322,17 @@ class HandshakeHandler {
} else if(this.identity.type() == IdentitifyType.NICKNAME) {
//FIXME handle error this should never happen!
}
this.connection.sendCommand("handshakeindentityproof", {proof: proof}).then(() => {
this.handshake_finished();
}).catch(error => {
this.connection.sendCommand("handshakeindentityproof", {proof: proof}).catch(error => {
console.error("Got login error");
console.log(error);
}); //TODO handle error
}).then(() => this.handshake_finished()); //TODO handle error
}
private handshake_finished() {
private async handshake_finished(version?: string) {
if(window.require && !version) {
version = "?.?.?"; //FIXME findout version!
}
let data = {
//TODO variables!
client_nickname: this.name ? this.name : this.identity.name(),
@ -342,9 +344,22 @@ class HandshakeHandler {
};
if(window.require) {
const os = require('os');
data.client_version = "TeaClient"; //FIXME get version
data.client_platform = os.platform() + " (" + os.arch() + ")";
data.client_version = "TeaClient ";
data.client_version += " " + version;
const os = require("os");
const arch_mapping = {
"x32": "32bit",
"x64": "64bit"
};
data.client_version += " " + (arch_mapping[os.arch()] || os.arch());
const os_mapping = {
"win32": "Windows",
"linux": "Linux"
};
data.client_platform = (os_mapping[os.platform()] || os.platform());
}
this.connection.sendCommand("clientinit", data).catch(error => {

View File

@ -239,6 +239,10 @@ function loadTemplates() {
});
}
interface Window {
$: JQuery;
}
//TODO release config!
function loadSide() {
if(window.require !== undefined) {

View File

@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "none",
"target": "es6",
"module": "none",
"sourceMap": true
},
"exclude": [