shared directory init
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
root
2024-11-21 13:14:38 +01:00
parent 608f2afe9f
commit 8f48a99184
3 changed files with 80 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
<?php <?php
$REDIS_HOST='redis-server'; $REDIS_HOST='redis-server';
$SHARED_DIR = "shared";
$INTERFACE = "directory"; // redis OR directory
function ping_redis() { function ping_redis() {
@@ -117,7 +119,7 @@ function redis_set($key, $value) {
$redis->set($key, base64_encode($value)); $redis->set($key, base64_encode($value));
$redis->sAdd('web_in', $key); $redis->sAdd('web_in', $key);
} else { } else {
echo "Key already exist: $key"; //echo "Key already exist: $key";
} }
} }
} }
@@ -278,4 +280,27 @@ function put_install_envs() {
} }
} }
function set_output($op,$output) {
global $SHARED_DIR;
redis_set($op,$output);
file_put_contents($SHARED_DIR."/".$op,$output);
return true;
}
function check_response($key="") {
$arr = check_redis("web_out",$key);
//$arr = check_files("web_out",$key);
return $arr;
}
function remove_response($key) {
redis_remove("$key");
}
?> ?>

View File

@@ -51,6 +51,7 @@ function redirectToManage() {
function start_system() { function start_system() {
var url = 'scan.php?op=system'; var url = 'scan.php?op=system';
$.get(url, function(data){ $.get(url, function(data){
console.log('start_system: '+data);
if (data=='OK') { if (data=='OK') {
$("#previous").html('Scanning for previous install. Please wait...'); $("#previous").html('Scanning for previous install. Please wait...');
check_system(); check_system();
@@ -64,7 +65,7 @@ function start_system() {
function check_system() { function check_system() {
var url = 'scan.php?op=check_system'; var url = 'scan.php?op=check_system';
$.get(url, function(data){ $.get(url, function(data){
console.log(data); console.log('check_system: '+data);
if (data=='NEW') { if (data=='NEW') {
$("#previous").html('No previous install has found...'); $("#previous").html('No previous install has found...');
setTimeout(redirectToInstall, 3000); setTimeout(redirectToInstall, 3000);
@@ -86,7 +87,7 @@ function check_redis() {
var url = 'scan.php?op=redis'; var url = 'scan.php?op=redis';
$.get(url, function(data){ $.get(url, function(data){
console.log(data); console.log('check_redis: '+data);
if (data=='OK') { if (data=='OK') {
$("#redis").html('Redis server - OK'); $("#redis").html('Redis server - OK');
start_system(); start_system();
@@ -98,7 +99,39 @@ function check_redis() {
}); });
} }
function check_directory() {
var url = 'scan.php?op=directory';
$.get(url, function(data){
console.log('check_directory: '+data);
if (data=='OK') {
$("#redis").html('Connection is ready - OK');
start_system();
}
else {
$("#redis").html('Shared directory is not available...');
}
});
}
function check_interface() {
var url = 'scan.php?op=get_interface';
$.get(url, function(data){
console.log('check_interface: '+data);
if (data=='redis') {
check_redis(); check_redis();
}
else if (data=='directory') {
check_directory();
}
else {
$("#redis").html('Invalid interface definition...');
}
});
}
check_interface();
//setTimeout(redirectToManage, 10000); //setTimeout(redirectToManage, 10000);

View File

@@ -3,6 +3,21 @@ include "functions.php";
sleep(1); sleep(1);
switch ($_GET["op"]) { switch ($_GET["op"]) {
case "get_interface":
echo $INTERFACE;
break;
case "directory":
if (file_exists($SHARED_DIR)) {
$test_file = $SHARED_DIR."/test";
file_put_contents($test_file,"TEST");
if (file_exists($test_file)) {
echo "OK";
unlink($test_file);
}
else echo "WRITE ERROR";
}
else echo "DIRECTORY DOESN'T EXISTS";
break;
case "redis": case "redis":
try { try {
$ret = ping_redis(); $ret = ping_redis();
@@ -33,12 +48,10 @@ switch ($_GET["op"]) {
$arr = array("STATUS" => 0); $arr = array("STATUS" => 0);
$json = json_encode($arr, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT); $json = json_encode($arr, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
$op = "system"; //"init:".date("YmdHis"); if (set_output("system",$json)) echo "OK"; // TODO?
redis_set($op,$json);
echo "OK"; // TODO?
break; break;
case "check_system": case "check_system":
$arr = check_redis("web_out","system"); $arr = check_response("system");
if (!empty($arr)) { if (!empty($arr)) {
foreach ($arr as $key=>$data) { foreach ($arr as $key=>$data) {
if ($key=="system") { if ($key=="system") {
@@ -54,7 +67,7 @@ switch ($_GET["op"]) {
} }
else echo "EXISTS"; else echo "EXISTS";
} }
redis_remove("$key"); remove_response("$key");
} }
} }
} }