From 7cf75825603f000c095ff626e7ca18bfc11e9255 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Sat, 20 Apr 2019 15:32:41 +0200 Subject: [PATCH] Add self publishing scripts. --- .gitignore | 1 + .vscode/settings.json | 7 ++ LICENSE.txt | 2 +- Web/Deployer/index.php | 62 +++++++++++++ Web/Deployer/priv/.htaccess | 2 + Web/Deployer/priv/config.example.json | 1 + Web/Deployer/utils.php | 128 ++++++++++++++++++++++++++ {code => Web/code}/CandyFucker.js | 0 {code => Web/code}/GameLib.js | 0 {gfx => Web/gfx}/BallsBlue.png | Bin {gfx => Web/gfx}/BallsBlue.svg | 0 {gfx => Web/gfx}/BallsCyan.png | Bin {gfx => Web/gfx}/BallsCyan.svg | 0 {gfx => Web/gfx}/BallsGreen.png | Bin {gfx => Web/gfx}/BallsRed.png | Bin {gfx => Web/gfx}/BallsRed.svg | 0 {gfx => Web/gfx}/BallsYellow.png | Bin {gfx => Web/gfx}/BallsYellow.svg | 0 {gfx => Web/gfx}/Frags.xcf | Bin {gfx => Web/gfx}/FragsBlue.png | Bin {gfx => Web/gfx}/FragsCyan.png | Bin {gfx => Web/gfx}/FragsGreen.png | Bin {gfx => Web/gfx}/FragsRed.png | Bin {gfx => Web/gfx}/FragsYellow.png | Bin {gfx => Web/gfx}/favicon.ico | Bin {gfx => Web/gfx}/favicon.png | Bin {gfx => Web/gfx}/favicon.svg | 0 {gfx => Web/gfx}/icon.svg | 0 {gfx => Web/gfx}/logo.png | Bin {gfx => Web/gfx}/logo.svg | 0 index.html => Web/index.html | 0 {sfx => Web/sfx}/explosion1.wav | Bin {sfx => Web/sfx}/pickcandy.wav | Bin {sfx => Web/sfx}/swapinvalid.wav | Bin style.css => Web/style.css | 0 publish.cmd | 7 ++ publish.php | 71 ++++++++++++++ publish.sh | 5 + 38 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 Web/Deployer/index.php create mode 100644 Web/Deployer/priv/.htaccess create mode 100644 Web/Deployer/priv/config.example.json create mode 100644 Web/Deployer/utils.php rename {code => Web/code}/CandyFucker.js (100%) rename {code => Web/code}/GameLib.js (100%) rename {gfx => Web/gfx}/BallsBlue.png (100%) rename {gfx => Web/gfx}/BallsBlue.svg (100%) rename {gfx => Web/gfx}/BallsCyan.png (100%) rename {gfx => Web/gfx}/BallsCyan.svg (100%) rename {gfx => Web/gfx}/BallsGreen.png (100%) rename {gfx => Web/gfx}/BallsRed.png (100%) rename {gfx => Web/gfx}/BallsRed.svg (100%) rename {gfx => Web/gfx}/BallsYellow.png (100%) rename {gfx => Web/gfx}/BallsYellow.svg (100%) rename {gfx => Web/gfx}/Frags.xcf (100%) rename {gfx => Web/gfx}/FragsBlue.png (100%) rename {gfx => Web/gfx}/FragsCyan.png (100%) rename {gfx => Web/gfx}/FragsGreen.png (100%) rename {gfx => Web/gfx}/FragsRed.png (100%) rename {gfx => Web/gfx}/FragsYellow.png (100%) rename {gfx => Web/gfx}/favicon.ico (100%) rename {gfx => Web/gfx}/favicon.png (100%) rename {gfx => Web/gfx}/favicon.svg (100%) rename {gfx => Web/gfx}/icon.svg (100%) rename {gfx => Web/gfx}/logo.png (100%) rename {gfx => Web/gfx}/logo.svg (100%) rename index.html => Web/index.html (100%) rename {sfx => Web/sfx}/explosion1.wav (100%) rename {sfx => Web/sfx}/pickcandy.wav (100%) rename {sfx => Web/sfx}/swapinvalid.wav (100%) rename style.css => Web/style.css (100%) create mode 100644 publish.cmd create mode 100644 publish.php create mode 100644 publish.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c8bf05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Web/Deployer/priv/config.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..03eeba6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "workbench.colorCustomizations": { + "activityBar.background": "#322D26", + "titleBar.activeBackground": "#463F35", + "titleBar.activeForeground": "#FCFBFA" + } +} \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt index 1d39482..8971c4a 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Valeriano Alfonso Rodriguez +Copyright (c) 2015-2019 Valeriano Alfonso Rodriguez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Web/Deployer/index.php b/Web/Deployer/index.php new file mode 100644 index 0000000..dd59552 --- /dev/null +++ b/Web/Deployer/index.php @@ -0,0 +1,62 @@ +"NotConfigured", "Message"=>"Config not found, use \"config.example.json\", as base to \"config.json\"."]); + return; +} + +if (isset($input["Key"])===false || $input["Key"]!==$config["Key"]) { + EchoError("AccessDenied"); + echo json_encode(["Error"=>"AccessDenied"]); + return; +} + +if (isset($input["Action"])===false) { + EchoError("ActionNotSpecified"); + echo json_encode(["Error"=>"ActionNotSpecified"]); + return; +} + +if ($input["Action"]==="CheckFiles") { + $filesChecked=array(); + $files=$input["Files"]; + foreach ($files as $file) { + $destPath=$file["DestPath"]; + $checksum=$file["Checksum"]; + + $filePath=$klogRoot.$destPath; + $data=file_get_contents($filePath); + $sha1=sha1($data); + + $filesChecked[]=[ + "DestPath"=>$destPath, + "ChecksumDifferent"=>($checksum!==$sha1), + ]; + } + echo json_encode($filesChecked); + return; +} + +if ($input["Action"]==="UploadFile") { + $destPath=$input["DestPath"]; + $data=base64_decode($input["Data"]); + EchoDebug("UploadFile: ".$destPath); + $destPathDir=dirname($klogRoot.$destPath."/"); + mkdir($destPathDir, 0777, true); + file_put_contents($klogRoot.$destPath, $data); + if (isset($input["Timestamp"])) { + touch($klogRoot.$destPath, $input["Timestamp"]); + } + echo json_encode(true); + return; +} + + +echo json_encode(null); diff --git a/Web/Deployer/priv/.htaccess b/Web/Deployer/priv/.htaccess new file mode 100644 index 0000000..c7f013a --- /dev/null +++ b/Web/Deployer/priv/.htaccess @@ -0,0 +1,2 @@ +# Denegar desde cualquier sitio, todo +deny from all diff --git a/Web/Deployer/priv/config.example.json b/Web/Deployer/priv/config.example.json new file mode 100644 index 0000000..a705933 --- /dev/null +++ b/Web/Deployer/priv/config.example.json @@ -0,0 +1 @@ +{"Key": "12345678"} \ No newline at end of file diff --git a/Web/Deployer/utils.php b/Web/Deployer/utils.php new file mode 100644 index 0000000..45628a0 --- /dev/null +++ b/Web/Deployer/utils.php @@ -0,0 +1,128 @@ + '.*', '?' => '.', '.' => '\\.')); + return (boolean)preg_match($pattern2, $string); +} + +function ScanFilesRecursive($path, &$files, $ignores) +{ + if (file_exists($path)===false) { + return; + } + $dirObj=@opendir($path); + if ($dirObj===false) { + return; + } + while (1) { + $file=readdir($dirObj); + if ($file===false) { + break; + } + $filePath=$path.$file; + + if ($file==='.' || $file==='..') { + continue; + } + $ignoreThis=false; + foreach ($ignores as $ignore) { + if ($file===$ignore) { + $ignoreThis=true; + break; + } + if (pcre_fnmatch($ignore, $filePath)) { + $ignoreThis=true; + break; + } + } + if ($ignoreThis) { + continue; + } + + if (is_dir($path.$file)) { + ScanFilesRecursive($path.$file."/", $files, $ignores); + } else { + if (is_file($path.$file)) { + $files[]=$path.$file; + } + } + } + closedir($dirObj); +} + +function ReplacePrefix($text, $prefix) +{ + if (substr($text, 0, strlen($prefix)) == $prefix) { + $text = substr($text, strlen($prefix)); + } + return $text; +} + +function PostRequest($url, $object) +{ + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json")); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($object)); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20); + + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + + curl_setopt($curl, CURLOPT_NOBODY, false); + curl_setopt($curl, CURLOPT_HTTPGET, false); + + curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0"); + curl_setopt($curl, CURLOPT_AUTOREFERER, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + + #curl_setopt($curl, CURLOPT_VERBOSE, true); + + $json_response = curl_exec($curl); + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + if ($status!=200) { + EchoDebug($json_response); + EchoError("PostRequest.Code: ".$status." ".curl_error($curl)); + return null; + } + curl_close($curl); + + $response = json_decode($json_response, true); + return $response; +} + +function ReadJsonFile($file) +{ + $data=@file_get_contents($file); + return json_decode($data, true); +} diff --git a/code/CandyFucker.js b/Web/code/CandyFucker.js similarity index 100% rename from code/CandyFucker.js rename to Web/code/CandyFucker.js diff --git a/code/GameLib.js b/Web/code/GameLib.js similarity index 100% rename from code/GameLib.js rename to Web/code/GameLib.js diff --git a/gfx/BallsBlue.png b/Web/gfx/BallsBlue.png similarity index 100% rename from gfx/BallsBlue.png rename to Web/gfx/BallsBlue.png diff --git a/gfx/BallsBlue.svg b/Web/gfx/BallsBlue.svg similarity index 100% rename from gfx/BallsBlue.svg rename to Web/gfx/BallsBlue.svg diff --git a/gfx/BallsCyan.png b/Web/gfx/BallsCyan.png similarity index 100% rename from gfx/BallsCyan.png rename to Web/gfx/BallsCyan.png diff --git a/gfx/BallsCyan.svg b/Web/gfx/BallsCyan.svg similarity index 100% rename from gfx/BallsCyan.svg rename to Web/gfx/BallsCyan.svg diff --git a/gfx/BallsGreen.png b/Web/gfx/BallsGreen.png similarity index 100% rename from gfx/BallsGreen.png rename to Web/gfx/BallsGreen.png diff --git a/gfx/BallsRed.png b/Web/gfx/BallsRed.png similarity index 100% rename from gfx/BallsRed.png rename to Web/gfx/BallsRed.png diff --git a/gfx/BallsRed.svg b/Web/gfx/BallsRed.svg similarity index 100% rename from gfx/BallsRed.svg rename to Web/gfx/BallsRed.svg diff --git a/gfx/BallsYellow.png b/Web/gfx/BallsYellow.png similarity index 100% rename from gfx/BallsYellow.png rename to Web/gfx/BallsYellow.png diff --git a/gfx/BallsYellow.svg b/Web/gfx/BallsYellow.svg similarity index 100% rename from gfx/BallsYellow.svg rename to Web/gfx/BallsYellow.svg diff --git a/gfx/Frags.xcf b/Web/gfx/Frags.xcf similarity index 100% rename from gfx/Frags.xcf rename to Web/gfx/Frags.xcf diff --git a/gfx/FragsBlue.png b/Web/gfx/FragsBlue.png similarity index 100% rename from gfx/FragsBlue.png rename to Web/gfx/FragsBlue.png diff --git a/gfx/FragsCyan.png b/Web/gfx/FragsCyan.png similarity index 100% rename from gfx/FragsCyan.png rename to Web/gfx/FragsCyan.png diff --git a/gfx/FragsGreen.png b/Web/gfx/FragsGreen.png similarity index 100% rename from gfx/FragsGreen.png rename to Web/gfx/FragsGreen.png diff --git a/gfx/FragsRed.png b/Web/gfx/FragsRed.png similarity index 100% rename from gfx/FragsRed.png rename to Web/gfx/FragsRed.png diff --git a/gfx/FragsYellow.png b/Web/gfx/FragsYellow.png similarity index 100% rename from gfx/FragsYellow.png rename to Web/gfx/FragsYellow.png diff --git a/gfx/favicon.ico b/Web/gfx/favicon.ico similarity index 100% rename from gfx/favicon.ico rename to Web/gfx/favicon.ico diff --git a/gfx/favicon.png b/Web/gfx/favicon.png similarity index 100% rename from gfx/favicon.png rename to Web/gfx/favicon.png diff --git a/gfx/favicon.svg b/Web/gfx/favicon.svg similarity index 100% rename from gfx/favicon.svg rename to Web/gfx/favicon.svg diff --git a/gfx/icon.svg b/Web/gfx/icon.svg similarity index 100% rename from gfx/icon.svg rename to Web/gfx/icon.svg diff --git a/gfx/logo.png b/Web/gfx/logo.png similarity index 100% rename from gfx/logo.png rename to Web/gfx/logo.png diff --git a/gfx/logo.svg b/Web/gfx/logo.svg similarity index 100% rename from gfx/logo.svg rename to Web/gfx/logo.svg diff --git a/index.html b/Web/index.html similarity index 100% rename from index.html rename to Web/index.html diff --git a/sfx/explosion1.wav b/Web/sfx/explosion1.wav similarity index 100% rename from sfx/explosion1.wav rename to Web/sfx/explosion1.wav diff --git a/sfx/pickcandy.wav b/Web/sfx/pickcandy.wav similarity index 100% rename from sfx/pickcandy.wav rename to Web/sfx/pickcandy.wav diff --git a/sfx/swapinvalid.wav b/Web/sfx/swapinvalid.wav similarity index 100% rename from sfx/swapinvalid.wav rename to Web/sfx/swapinvalid.wav diff --git a/style.css b/Web/style.css similarity index 100% rename from style.css rename to Web/style.css diff --git a/publish.cmd b/publish.cmd new file mode 100644 index 0000000..33eb445 --- /dev/null +++ b/publish.cmd @@ -0,0 +1,7 @@ +@echo off + +title Publishing + +php publish.php + +pause diff --git a/publish.php b/publish.php new file mode 100644 index 0000000..3e843e0 --- /dev/null +++ b/publish.php @@ -0,0 +1,71 @@ +$destPath, + "Checksum"=>$sha1, + ]; +} +$filesChecked=PostRequest($klogDeployerEndpoint, [ + "Action"=>"CheckFiles", + "Key"=>$config["Key"], + "Files"=>$filesWithChecksum, +]); +if ($filesChecked===null) { + EchoError("Failure in comms"); + return; +} +if (isset($filesChecked["Error"])) { + EchoError("Server error: ".$filesChecked["Error"]); + return; +} +foreach ($filesChecked as $file) { + $destPath=$file["DestPath"]; + $filePath=$klogRoot.$destPath; + if ($file["ChecksumDifferent"]===false) { + EchoInfo("--- ".$destPath); + continue; + } + EchoInfo("+++ ".$destPath); + $data=file_get_contents($filePath); + $timestamp=filemtime($filePath); + $result=PostRequest($klogDeployerEndpoint, [ + "Action"=>"UploadFile", + "Key"=>$config["Key"], + "DestPath"=>$destPath, + "Data"=>base64_encode($data), + "Timestamp"=>$timestamp, + ]); + if ($result!==true) { + EchoError("Failure uploading ".$destPath); + } + if (isset($result["Error"])) { + EchoError("Server error: ".$result["Error"]); + } +} diff --git a/publish.sh b/publish.sh new file mode 100644 index 0000000..e5dc3f1 --- /dev/null +++ b/publish.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +php publish.php + +read -n1 -r -p "Press any key to continue..." key