diff --git a/common.js b/common.js new file mode 100644 index 0000000..325835d --- /dev/null +++ b/common.js @@ -0,0 +1,448 @@ +function check_deployments() { + var url = 'scan.php?op=check_deployments'; + jQuery.get(url, function(data) { + console.log('check_deployments: '+data); + if (data=="WAIT" || data=="") { + setTimeout(check_deployments, 1000); + } + else { + // manage2 + apps.length = 0; // reset + apps.push(...JSON.parse(data)); // push each element + console.log(apps); + + // manage + html_data = ''; + data = jQuery.parseJSON(data); + for (var k in data) { + console.log(data[k]); + service_name = data[k].name; + orig_service_name = data[k].orig_name; + content = data[k].content; + installed = data[k].installed; + if (installed=='true') { + html_data += '
'+orig_service_name+' - '+content+' - INSTALLED
'; + } + else { + html_data += '
'+orig_service_name+' - '+content+'
'; + } + html_data += '
'; + } + jQuery("#deployments").html(html_data); + + } + }); +} + +function get_deployments() { + var url = 'scan.php?op=deployments'; + jQuery.get(url, function(data) { + console.log('deployments: '+data); + if (data=="OK") { + setTimeout(check_deployments, 1000); + } + else jQuery("#deployments").html(data); + }); +} + +function check_system() { + var url = 'scan.php?op=check_system&services=1'; + jQuery.get(url, function(data) { + console.log('check_system: '+data); + if (data=="WAIT" || data=="") { + setTimeout(check_system, 1000); + } + else { + jQuery("#system").html(data); + } + }); +} + +function get_system() { + var url = 'scan.php?op=system'; + jQuery.get(url, function(data) { + console.log('system: '+data); + if (data=="OK") { + setTimeout(check_system, 1000); + } + else alert(data); + }); +} + +function check_repositories() { + var url = 'scan.php?op=check_repositories'; + jQuery.get(url, function(data) { + console.log('check_repositories: '+data); + if (data=="WAIT" || data=="") { + setTimeout(check_repositories, 500); + } + else { + jQuery("#repositories").html(data); + } + }); +} + +function get_repositories() { + var url = 'scan.php?op=repositories'; + jQuery.get(url, function(data) { + console.log('repositories: '+data); + if (data=="OK") { + setTimeout(check_repositories, 500); + get_deployments(); + } + else alert(data); + }); +} + +function add_repository() { + var url = 'scan.php?op=add_repository&repo='+jQuery('#repository').val(); + jQuery.get(url, function(data) { + console.log('add_repository: '+data); + if (data=="OK") { + } + get_repositories(); + }); +} + +function check_vpn() { + var url = 'scan.php?op=check_vpn'; + jQuery.get(url, function(data) { + console.log('check_vpn: '+data); + if (data=="2") { + $('#vpn_off').hide(); + $('#vpn_on').show(); + } + else { + $('#vpn_on').hide(); + $('#vpn_off').show(); + } + setTimeout(check_vpn, 10000); + }); +} + +function save_vpn() { + var url = 'scan.php?op=save_vpn&vpn_domain='+jQuery('#vpn_domain').val()+'&vpn_pass='+jQuery('#vpn_pass').val()+'&letsencrypt_mail='+jQuery('#letsencrypt_mail').val()+'&letsencrypt_servername='+jQuery('#letsencrypt_servername').val(); + + jQuery.get(url, function(data) { + console.log('save_vpn: '+data); + if (data=="OK") { + } + //get_vpn(); + }); +} + +function check_updates() { + var url = 'scan.php?op=check_updates'; + jQuery.get(url, function(data) { + console.log('check_updates: '+data); + if (data=="WAIT" || data=="") { + setTimeout(check_updates, 1000); + } + else { + jQuery("#updates").html(data); + } + }); +} + +function get_updates() { + var url = 'scan.php?op=updates'; + jQuery.get(url, function(data) { + console.log('updates: '+data); + if (data=="ERROR") { + jQuery("#updates").html('Searching for updates is in progress...'); + } + setTimeout(check_updates, 1000); + }); +} + +function check_upgrade() { + var url = 'scan.php?op=check_upgrade'; + jQuery.get(url, function(data) { + console.log('check_upgrade: '+data); + if (data=="WAIT" || data=="") { + setTimeout(check_upgrade, 1000); + } + else { + // TODO + } + }); +} + +function upgrade(service) { + var url = 'scan.php?op=upgrade&service='+service; + console.log('upgrade start: '+service); + jQuery.get(url, function(data) { + console.log('upgrade end: '+service); + if (data=="OK") { + setTimeout(check_upgrade, 1000); + } + }); +} + +function load_template(additional, block) { + + jQuery("div.deployment").each(function(index) { + $(this).html(''); + }); + jQuery("#"+block).html('Loading '+additional+' template...'); + var url = 'scan.php?op=deployment&additional='+additional; + jQuery.get(url, function(data) { + console.log('load_template: '+data); + if (data=="OK") { + setTimeout(check_deployment, 1000, additional); + } + }); +} + +function check_reinstall(additional) { + var url = 'scan.php?op=check_reinstall'; + jQuery.get(url, function(data) { + console.log('check_reinstall: '+data); + if (data!="") { + jQuery("#"+additional).html(data); + jQuery("#popupText").html(data); // manage2 + } + else setTimeout(check_reinstall, 1000, additional); + }); +} + +function reinstall(additional, block) { + jQuery("div.deployment").each(function(index) { + $(this).html(''); + }); + jQuery("#"+block).html('Loading '+additional+' template...'); + var url = 'scan.php?op=reinstall&additional='+additional; + jQuery.get(url, function(data) { + console.log('reinstall '+additional+': '+data); + if (data=="OK") { + setTimeout(check_reinstall, 1000, additional); + } + }); +} + +function check_uninstall(additional) { + var url = 'scan.php?op=check_uninstall&additional='+additional; + jQuery.get(url, function(data) { + console.log('check_uninstall '+additional+': '+data); + if (data!="") { + jQuery("#"+additional).html(data); + } + if (data!="OK") { + setTimeout(check_uninstall, 1000, additional); + } + else { + jQuery("#"+additional).html('Uninstall has finished'); + get_deployments(); + } + }); +} + +function uninstall(additional) { + + jQuery("div.deployment").each(function(index) { + $(this).html(''); + }); + data = '
YOU ARE GOING TO UNINSTALL '+additional.toUpperCase()+'.
ARE YOU SURE? IF YES, PLEASE CLICK ON THE BUTTON BELOW.

'; + jQuery("#"+additional).html(data); +} + +function confirm_uninstall(additional) { + jQuery("#"+additional).html('Loading...'); + var url = 'scan.php?op=uninstall&additional='+additional; + jQuery.get(url, function(data) { + console.log('uninstall '+additional+': '+data); + if (data!="") { + jQuery("#"+additional).html(data); + setTimeout(check_uninstall, 1000, additional); + } + }); +} + +function check_deployment(additional) { + var url = 'scan.php?op=check_deployment&additional='+additional; + jQuery.get(url, function(data) { + console.log('check_deployment '+additional); + //console.log('check_deployment data: '+data); + if (data!="") { + jQuery("#"+additional).html(data); + jQuery("#popupText").html(data); // manage2 + } + else setTimeout(check_deployment, 1000, additional); + }); +} + +function deploy(additional) { + pars = ''; + jQuery('input.additional_'+additional).each(function(index) { + console.log('Field ' + $(this).attr('name') + ': ' + $(this).val()); + //pars += '&'+$(this).attr('id') + '=' + $(this).val(); + pars += '&'+$(this).attr('name') + '=' + $(this).val(); + }); + //console.log(pars); + var url = 'scan.php?op=deploy&additional='+additional+pars; + jQuery.get(url, function(data) { + console.log('deploy '+additional+': '+data); + if (data!="") { + jQuery("#"+additional).html(data); + setTimeout(check_deployment, 1000, additional); + } + }); +} + +function redeploy(additional) { + pars = ''; + jQuery('input.additional_'+additional).each(function(index) { + console.log('Field ' + $(this).attr('name') + ': ' + $(this).val()); + //pars += '&'+$(this).attr('id') + '=' + $(this).val(); + pars += '&'+$(this).attr('name') + '=' + $(this).val(); + }); + //console.log(pars); + var url = 'scan.php?op=redeploy&additional='+additional+pars; + jQuery.get(url, function(data) { + console.log('redeploy '+additional+': '+data); + if (data!="") { + jQuery("#"+additional).html(data); + setTimeout(check_deployment, 1000, additional); + } + }); +} + +function check_services() { + var url = 'scan.php?op=check_services'; + jQuery.get(url, function(data) { + console.log('check_services: '+data); + if (data=="WAIT" || data=="") { + setTimeout(check_services, 1000); + } + else { + jQuery("#services").html(data); + } + }); +} + +function get_services() { + var url = 'scan.php?op=services'; + jQuery.get(url, function(data) { + console.log('services: '+data); + setTimeout(check_services, 1000); + }); +} + +function check_containers() { + var url = 'scan.php?op=check_containers'; + jQuery.get(url, function(data) { + console.log('check_containers: '+data); + if (data!="") { + jQuery("#containers").html(data); + } + else setTimeout(check_containers, 1000); + }); +} + +function get_containers() { + var url = 'scan.php?op=containers'; + jQuery.get(url, function(data) { + console.log('containers: '+data); + if (data=="OK") { + setTimeout(check_containers, 1000); + } + }); +} + +jQuery(document).ready(function(){ + + get_repositories(); + get_system(); + get_services(); + check_vpn(); + + jQuery('#deployments_btn').click(function() { + jQuery('#services').hide(); + jQuery('#deployments').toggle(); + }); + + jQuery('#services_btn').click(function() { + jQuery('#deployments').hide(); + jQuery('#services').toggle(); + }); + + jQuery('#settings_btn').click(function() { + jQuery('#settings').toggle(); + jQuery('#default').toggle(); + jQuery('#vpn').hide(); + }); + + jQuery('#vpn_btn').click(function() { + jQuery('#vpn').toggle(); + jQuery('#settings').hide(); + }); + + jQuery('#vpn_cancel_btn').click(function() { + jQuery('#vpn').hide(); + }); + + jQuery('#update_btn').click(function() { + jQuery('#updates').html('Looking for updates... Please wait...'); + get_updates(); + }); + + jQuery('#add_repo').submit(function() { + jQuery('#repositories').html('Loading...'); + add_repository(); + return false; + }); + + jQuery('#save_vpn').submit(function() { + save_vpn(); + jQuery('#vpn').html('Loading...'); + return false; + }); + + jQuery('select#smarthost').click(function() { + if (jQuery(this).val()=='yes') jQuery('#div_smarthost').show(); + else jQuery('#div_smarthost').hide(); + + if (jQuery("#smarthost").val()=='no' && jQuery("#localproxy").val()=='yes') { + alert("Warning! Local proxy will not work without smarthost proxy service."); + } + }); + jQuery('select#vpn').click(function() { + if (jQuery(this).val()=='yes') jQuery('#div_vpn').show(); + else jQuery('#div_vpn').hide(); + }); +/* + jQuery('select#discovery').click(function() { + if (jQuery(this).val()=='yes') jQuery('#div_discover').show(); + else jQuery('#div_discover').hide(); + }); + jQuery('select#additionals').click(function() { + if (jQuery(this).val()=='yes') jQuery('#div_additionals').show(); + else jQuery('#div_additionals').hide(); + }); + jQuery('select#nextcloud').click(function() { + if (jQuery(this).val()=='Y') jQuery('#div_nextcloud').show(); + else jQuery('#div_nextcloud').hide(); + }); + jQuery('select#bitwarden').click(function() { + if (jQuery(this).val()=='Y') jQuery('#div_bitwarden').show(); + else jQuery('#div_bitwarden').hide(); + }); + jQuery('select#bitwarden_smtp').click(function() { + if (jQuery(this).val()=='3') jQuery('#div_bitwarden_smtp').show(); + else jQuery('#div_bitwarden_smtp').hide(); + }); + jQuery('select#guacamole').click(function() { + if (jQuery(this).val()=='Y') jQuery('#div_guacamole').show(); + else jQuery('#div_guacamole').hide(); + }); + jQuery('select#smtp_server').click(function() { + if (jQuery(this).val()=='Y') jQuery('#div_smtp_server').show(); + else jQuery('#div_smtp_server').hide(); + }); + jQuery('select#roundcube').click(function() { + if (jQuery(this).val()=='Y') jQuery('#div_roundcube').show(); + else jQuery('#div_roundcube').hide(); + }); +*/ +}); + diff --git a/functions.php b/functions.php index 305b4f4..690472e 100644 --- a/functions.php +++ b/functions.php @@ -277,7 +277,8 @@ function set_output($op,$output) { redis_set($op,$output); } else { - file_put_contents($SHARED_DIR."/input/".$op.".json",$output); + if (file_exists($SHARED_DIR."/input/".$op.".json")) return false; + else file_put_contents($SHARED_DIR."/input/".$op.".json",$output); } return true; @@ -364,7 +365,7 @@ function remove_response($key) { } else { copy($SHARED_DIR."/output/".$key.".json",$SHARED_DIR."/".$key.".json"); // DEBUG - last json - unlink($SHARED_DIR."/output/".$key.".json"); + if (!unlink($SHARED_DIR."/output/".$key.".json")) echo "UNLINK ERROR"; } } diff --git a/image.png b/image.png new file mode 100644 index 0000000..1b980dc Binary files /dev/null and b/image.png differ diff --git a/manage.html b/manage.html index 1488d85..a944450 100644 --- a/manage.html +++ b/manage.html @@ -141,432 +141,15 @@

+ - + diff --git a/manage2.html b/manage2.html new file mode 100644 index 0000000..c649a45 --- /dev/null +++ b/manage2.html @@ -0,0 +1,567 @@ + + + + + + Control Panel + + + + + + + + +
+
+ Profilkép +
Pro
+
+ +
+
+ +
+ + + + + +
+ +
+ + + + + + + + + + + + + + + + + diff --git a/scan.php b/scan.php index 03da133..8e22f79 100644 --- a/scan.php +++ b/scan.php @@ -134,46 +134,33 @@ switch ($_GET["op"]) { else echo "ERROR"; break; case "check_deployments": + $deployments = ""; $arr = check_response("deployments"); if (!empty($arr)) { foreach ($arr as $key=>$data) { if ($key=="deployments") { if (count($data["DEPLOYMENTS"])) { - if ($data["DEPLOYMENTS"]["deployments"]=="NONE") echo "There are no deployments.
"; + if ($data["DEPLOYMENTS"]["deployments"]=="NONE") $deployments = "There are no deployments."; else { foreach ($data["DEPLOYMENTS"] as $service_name => $content) { $orig_service_name = $service_name; $service_name = strtolower($service_name); //echo base64_decode($content); - if (array_key_exists($service_name,$data["INSTALLED_SERVICES"])) { - echo '
'.$orig_service_name.' - '.$content.' - INSTALLED
'; - } - else echo '
'.$orig_service_name.' - '.$content.'
'; - echo '
'; + if (array_key_exists($service_name,$data["INSTALLED_SERVICES"])) $installed = "true"; + else $installed = "false"; + if (!empty($deployments)) $deployments .= ", "; + $deployments .= '{"name": "'.$service_name.'", "orig_name": "'.$orig_service_name.'", "image": "image.png", "content": "'.$content.'", "installed": "'.$installed.'"}'; } + if (!empty($deployments)) $deployments = "[{$deployments}]"; } } - else echo "There are no deployments."; - echo "
"; -/* - if (count($data["INSTALLED_SERVICES"])) { - echo "
Installed services:
"; - if ($data["INSTALLED_SERVICES"]["services"]=="NONE") echo "There are no installed services.
"; - else { - foreach ($data["INSTALLED_SERVICES"] as $service_name => $content) { - //echo base64_decode($content); - echo $service_name."
"; - } - echo "
"; - } - } - else echo "There are no installed services.
"; -*/ + else $deployments = "There are no deployments."; remove_response("$key"); } } } - else echo "WAIT"; + else $deployments = "WAIT"; + echo $deployments; break; case "deployment": $arr = array("NAME" => $_GET["additional"], "ACTION" => "ask"); @@ -245,6 +232,7 @@ switch ($_GET["op"]) { }); jQuery('#cancel_{$template->name}_btn').click(function() { $('div#{$template->name}').html(''); + document.getElementById('popup').classList.add('hidden'); // manage2 }); ";