diff --git a/functions.php b/functions.php index 2fd051a..7472b0c 100644 --- a/functions.php +++ b/functions.php @@ -1,6 +1,8 @@ set($key, base64_encode($value)); $redis->sAdd('web_in', $key); } 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"); +} + ?> diff --git a/index.html b/index.html index 65f1e94..e5cbe26 100644 --- a/index.html +++ b/index.html @@ -51,6 +51,7 @@ function redirectToManage() { function start_system() { var url = 'scan.php?op=system'; $.get(url, function(data){ + console.log('start_system: '+data); if (data=='OK') { $("#previous").html('Scanning for previous install. Please wait...'); check_system(); @@ -64,7 +65,7 @@ function start_system() { function check_system() { var url = 'scan.php?op=check_system'; $.get(url, function(data){ - console.log(data); + console.log('check_system: '+data); if (data=='NEW') { $("#previous").html('No previous install has found...'); setTimeout(redirectToInstall, 3000); @@ -86,7 +87,7 @@ function check_redis() { var url = 'scan.php?op=redis'; $.get(url, function(data){ - console.log(data); + console.log('check_redis: '+data); if (data=='OK') { $("#redis").html('Redis server - OK'); start_system(); @@ -98,7 +99,39 @@ function check_redis() { }); } - 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(); + } + else if (data=='directory') { + check_directory(); + } + else { + $("#redis").html('Invalid interface definition...'); + } + }); +} + + check_interface(); //setTimeout(redirectToManage, 10000); diff --git a/scan.php b/scan.php index d5891b8..1edfd90 100644 --- a/scan.php +++ b/scan.php @@ -3,6 +3,21 @@ include "functions.php"; sleep(1); 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": try { $ret = ping_redis(); @@ -33,12 +48,10 @@ switch ($_GET["op"]) { $arr = array("STATUS" => 0); $json = json_encode($arr, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT); - $op = "system"; //"init:".date("YmdHis"); - redis_set($op,$json); - echo "OK"; // TODO? + if (set_output("system",$json)) echo "OK"; // TODO? break; case "check_system": - $arr = check_redis("web_out","system"); + $arr = check_response("system"); if (!empty($arr)) { foreach ($arr as $key=>$data) { if ($key=="system") { @@ -54,7 +67,7 @@ switch ($_GET["op"]) { } else echo "EXISTS"; } - redis_remove("$key"); + remove_response("$key"); } } }