Add self publishing scripts.

This commit is contained in:
2019-04-20 15:32:41 +02:00
parent 3990cd4b18
commit 7cf7582560
38 changed files with 285 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
Web/Deployer/priv/config.json

7
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#322D26",
"titleBar.activeBackground": "#463F35",
"titleBar.activeForeground": "#FCFBFA"
}
}

View File

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

62
Web/Deployer/index.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
require_once(__DIR__."/utils.php");
$klogRoot=__DIR__."/../";
$method=$_SERVER['REQUEST_METHOD'];
$input=json_decode(file_get_contents('php://input'), true);
$config=ReadJsonFile(__DIR__."/priv/config.json");
if ($config==null) {
EchoError("Config not found, use \"config.example.json\", as base to \"config.json\".");
echo json_encode(["Error"=>"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);

View File

@@ -0,0 +1,2 @@
# Denegar desde cualquier sitio, todo
deny from all

View File

@@ -0,0 +1 @@
{"Key": "12345678"}

128
Web/Deployer/utils.php Normal file
View File

@@ -0,0 +1,128 @@
<?php
function EchoError($text)
{
file_put_contents('php://stderr', "!!!!! ".$text."\n");
}
function EchoDebug($text)
{
file_put_contents('php://stderr', "***** ".$text."\n");
}
function EchoInfo($text)
{
file_put_contents('php://stderr', "..... ".$text."\n");
}
function GetDocRoot()
{
$localPath=$_SERVER["SCRIPT_NAME"];
$localName=basename($localPath);
$absolutePath=realpath($localName);
$absolutePath=str_replace("\\", "/", $absolutePath);
$docRoot=substr($absolutePath, 0, strpos($absolutePath, $localPath));
return($docRoot);
}
function pcre_fnmatch($pattern, $string)
{
$patternQuoted='#'.$pattern.'#';
$pattern2=strtr($patternQuoted, array('*' => '.*', '?' => '.', '.' => '\\.'));
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);
}

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 505 B

After

Width:  |  Height:  |  Size: 505 B

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

7
publish.cmd Normal file
View File

@@ -0,0 +1,7 @@
@echo off
title Publishing
php publish.php
pause

71
publish.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
require_once(__DIR__."/Web/Deployer/utils.php");
$klogDeployerEndpoint="https://varstudio.net/CandyFucker/Deployer/";
#$klogDeployerEndpoint="http://localhost:8080/Deployer/";
$klogRoot=__DIR__."/Web/";
$config=ReadJsonFile(__DIR__."/Web/Deployer/priv/config.json");
if ($config==null) {
EchoError("Config not found, use \"config.example.json\", as base to \"config.json\".");
return;
}
EchoInfo("Checking files...");
$ignores=[
"*.svg",
"*.xcf",
".php_cs.dist",
"setup.php",
"config.json",
"Deployer",
];
$files=array();
ScanFilesRecursive($klogRoot, $files, $ignores);
$filesWithChecksum=array();
foreach ($files as $file) {
$destPath=ReplacePrefix($file, $klogRoot);
$data=file_get_contents($file);
$sha1=sha1($data);
$filesWithChecksum[]=[
"DestPath"=>$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"]);
}
}

5
publish.sh Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
php publish.php
read -n1 -r -p "Press any key to continue..." key