-
Name:
-
+
+
+
+
Compression:
+
+
+
+ bzip2
+ gzip
+ lzma
+ none
+ xz
+ zstd
+
@@ -1427,8 +1464,11 @@
About LXDWARE Dashboard
function createBackup(){
var backupName = $("#backupName").val();
+ var backupInstanceOnly = $("#backupInstanceOnly").val();
+ var backupOptimizedStorage = $("#backupOptimizedStorage").val();
+ var backupCompressionAlgorithm = $("#backupCompressionAlgorithm").val();
console.log("Info: backing up instance " + instanceName + " to " + backupName);
- $.get("./php/lxd/instances.php?remote=" + encodeURI(remoteName) + "&project=" + encodeURI(projectName) + "&instance=" + encodeURI(instanceName) + "&name=" + encodeURI(backupName) + "&action=createBackup", function (data) {
+ $.get("./php/lxd/instances.php?remote=" + encodeURI(remoteName) + "&project=" + encodeURI(projectName) + "&instance=" + encodeURI(instanceName) + "&name=" + encodeURI(backupName) + "&instance_only=" + encodeURI(backupInstanceOnly) + "&optimized_storage=" + encodeURI(backupOptimizedStorage) + "&compression_algorithm=" + encodeURI(backupCompressionAlgorithm) + "&action=createBackup", function (data) {
var operationData = JSON.parse(data);
console.log(operationData);
if (operationData.status_code == 100 && operationData.metadata.status_code < 400){
@@ -1441,11 +1481,15 @@
About LXDWARE Dashboard
});
}
- function downloadBackup(backupName){
- console.log("Info: downloading backup " + backupName + " from instance " + instanceName);
- $.get("./php/lxd/instances.php?remote=" + encodeURI(remoteName) + "&project=" + encodeURI(projectName) + "&instance=" + encodeURI(instanceName) + "&name=" + encodeURI(backupName) + "&action=downloadBackup", function (data) {
- console.log(data);
- window.location.href = data;
+ function exportBackup(backupName){
+ console.log("Info: exporting backup " + backupName + " from instance " + instanceName + " to a file");
+ $('#spinner').show();
+ $('#notificationArea').show();
+ $('#notification').text('Exporting ' + backupName + ' to local file');
+ $.get("./php/lxd/instances.php?remote=" + encodeURI(remoteName) + "&project=" + encodeURI(projectName) + "&instance=" + encodeURI(instanceName) + "&name=" + encodeURI(backupName) + "&action=exportBackupFile", function (data) {
+ $('#spinner').hide();
+ $('#notificationArea').hide();
+ $('#notification').text("");
});
}
diff --git a/admin/php/lxd/instance-list.php b/admin/php/lxd/instance-list.php
index 353963b..282d5af 100644
--- a/admin/php/lxd/instance-list.php
+++ b/admin/php/lxd/instance-list.php
@@ -19,115 +19,140 @@
$url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/instances?recursion=2&project=" . $project;
$instance_api_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$instance_api_data = json_decode($instance_api_data, true);
- $instance_api_data = $instance_api_data['metadata'];
-
- $i = 0;
- echo '{ "data": [';
-
- foreach ($instance_api_data as $instance_data){
-
- if ($instance_data['name'] == "")
- continue;
-
- if ($i > 0){
- echo ",";
- }
- $i++;
-
- echo "[ ";
- if ($instance_data['status'] == "Running"){
- echo '"';
- echo "
";
- echo '",';
+ if (isset($instance_api_data['metadata'])){
+ $instance_api_data = $instance_api_data['metadata'];
+
+ $i = 0;
+ echo '{ "data": [';
+
+ foreach ($instance_api_data as $instance_data){
+
+ if ($instance_data['name'] == "")
+ continue;
+
+ if ($i > 0){
+ echo ",";
+ }
+ $i++;
+
+ echo "[ ";
+ if ($instance_data['status'] == "Running"){
+ echo '"';
+ echo "
";
+ echo '",';
+
+ echo '"';
+ echo "
".htmlentities($instance_data['name'])." ";
+ echo '",';
+ }
+ else {
+ echo '"';
+ echo "
";
+ echo '",';
+
+ echo '"';
+ echo "
".htmlentities($instance_data['name'])." ";
+ echo '",';
+ }
+
echo '"';
- echo "
".$instance_data['name']." ";
+ if (isset($instance_data['config']['image.os']))
+ echo htmlentities($instance_data['config']['image.os']);
+ else
+ echo "";
echo '",';
- }
- else {
+
+ echo '"' . htmlentities($instance_data['location']) . '",';
+
+ //IPv4
echo '"';
- echo "
";
- echo '",';
- echo '"';
- echo "
".$instance_data['name']." ";
+ if (isset($instance_data['state']['network'])){
+ foreach ($instance_data['state']['network'] as $nic => $nic_properties){
+ foreach ($nic_properties['addresses'] as $nic_address){
+ if ($nic_address['family'] == "inet" && $nic_address['scope'] == "global"){
+ echo htmlentities($nic_address['address']) . " (" . htmlentities($nic) . ")
";
+ }
+ }
+ }
+ }
echo '",';
- }
-
- echo '"' . $instance_data['config']['image.os'] . '",';
- echo '"' . $instance_data['location'] . '",';
-
- //IPv4
- echo '"';
- foreach ($instance_data['state']['network'] as $nic=>$nic_properties){
- foreach ($nic_properties['addresses'] as $nic_address){
- if ($nic_address['family'] == "inet" && $nic_address['scope'] == "global"){
- echo $nic_address['address'] . " (" . $nic . ")
";
-
+
+ //IPv6
+ echo '"';
+
+ if (isset($instance_data['state']['network'])){
+ foreach ($instance_data['state']['network'] as $nic => $nic_properties){
+ foreach ($nic_properties['addresses'] as $nic_address){
+ if ($nic_address['family'] == "inet6" && $nic_address['scope'] == "global"){
+ echo htmlentities($nic_address['address']) . " (" . htmlentities($nic) . ")
";
+ }
+ }
}
}
- }
- echo '",';
-
- //IPv6
- echo '"';
- foreach ($instance_data['state']['network'] as $nic=>$nic_properties){
- foreach ($nic_properties['addresses'] as $nic_address){
- if ($nic_address['family'] == "inet6" && $nic_address['scope'] == "global"){
- echo $nic_address['address'] . " (" . $nic . ")
";
+ echo '",';
+
+ echo '"' . htmlentities($instance_data['type']) . '",';
+
+ //Convert the memory usage to an appropriate unit
+ if ($instance_data['state']['memory']['usage'] < 1073741824){
+ $memory = number_format($instance_data['state']['memory']['usage']/1024/1024, 2);
+ $memory_unit = "MB";
+ }
+ else {
+ $memory = number_format($instance_data['state']['memory']['usage']/1024/1024/1024, 2);
+ $memory_unit = "GB";
+ }
+
+ echo '"' . htmlentities($memory) . " " . $memory_unit . '",';
+
+ //When first created, the root disk usage is not set for brief second causing a PHP Notice in error log for Undefined index: root
+ if (isset($instance_data['state']['disk']['root']['usage'])){
+ //Convert the storage usage to an approprate unit
+ if ($instance_data['state']['disk']['root']['usage'] < 1073741824){
+ $disk_total = number_format($instance_data['state']['disk']['root']['usage']/1024/1024,2);
+ $disk_unit = "MB";
+ }
+ if ($instance_data['state']['disk']['root']['usage'] >= 1073741824 && $instance_data['state']['disk']['root']['usage'] < 1099511627776) {
+ $disk_total = number_format($instance_data['state']['disk']['root']['usage']/1024/1024/1024,2);
+ $disk_unit = "GB";
+ }
+ if ($instance_data['state']['disk']['root']['usage'] >= 1099511627776){
+ $disk_total = number_format($instance_data['state']['disk']['root']['usage']/1024/1024/1024/1024,2);
+ $disk_unit = "TB";
}
}
+ else {
+ $disk_total = 0.00;
+ $disk_unit = "MB";
+ }
+
+
+ echo '"' . htmlentities($disk_total) . " " . $disk_unit . '",';
+ echo '"' . htmlentities($instance_data['status']) . '",';
+
+ if ($instance_data['status'] == "Running"){
+ echo '"';
+ echo "
";
+ echo '"';
+ }
+ else{
+ echo '"';
+ echo "
";
+ echo '"';
+ }
+
+ echo " ]";
+
}
- echo '",';
-
- echo '"' . $instance_data['type'] . '",';
-
- //Convert the memory usage to an appropriate unit
- if ($instance_data['state']['memory']['usage'] < 1073741824){
- $memory = number_format($instance_data['state']['memory']['usage']/1024/1024, 2);
- $memory_unit = "MB";
- }
- else {
- $memory = number_format($instance_data['state']['memory']['usage']/1024/1024/1024, 2);
- $memory_unit = "GB";
- }
-
- echo '"' . $memory . " " . $memory_unit . '",';
-
- //Convert the storage usage to an approprate unit
- if ($instance_data['state']['disk']['root']['usage'] < 1073741824){
- $disk_total = number_format($instance_data['state']['disk']['root']['usage']/1024/1024,2);
- $disk_unit = "MB";
- }
- if ($instance_data['state']['disk']['root']['usage'] >= 1073741824 && $instance_data['state']['disk']['root']['usage'] < 1099511627776) {
- $disk_total = number_format($instance_data['state']['disk']['root']['usage']/1024/1024/1024,2);
- $disk_unit = "GB";
- }
- if ($instance_data['state']['disk']['root']['usage'] >= 1099511627776){
- $disk_total = number_format($instance_data['state']['disk']['root']['usage']/1024/1024/1024/1024,2);
- $disk_unit = "TB";
- }
-
- echo '"' . $disk_total . " " . $disk_unit . '",';
- echo '"' . $instance_data['status'] . '",';
-
- if ($instance_data['status'] == "Running"){
- echo '"';
- echo "
";
- echo '"';
- }
- else{
- echo '"';
- echo "
";
- echo '"';
- }
-
- echo " ]";
-
+
+ echo " ]}";
+ }
+ else {
+ echo '{ "data": [] }';
}
- echo " ]}";
-
}
}
diff --git a/admin/php/lxd/instance-single-backup-list.php b/admin/php/lxd/instance-single-backup-list.php
index cc50082..1a15ee4 100644
--- a/admin/php/lxd/instance-single-backup-list.php
+++ b/admin/php/lxd/instance-single-backup-list.php
@@ -15,14 +15,14 @@
echo "
";
echo "";
- echo " ";
+ echo " ";
echo "Name ";
echo "Created ";
echo "Expires ";
echo "Instance Only ";
- echo "Container Only ";
echo "Optimized Storage ";
- echo "Actions ";
+ echo "Local Export ";
+ echo "Actions ";
echo " ";
echo " ";
@@ -41,33 +41,62 @@
$url = $url . "/1.0/instances/" . $instance . "/backups?recursion=1&project=" . $project;
$instance_api_backups = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$instance_api_backups = json_decode($instance_api_backups, true);
- $instance_backups = $instance_api_backups['metadata'];
- foreach ($instance_backups as $instance_backup){
+ if (isset($instance_api_backups['metadata'])){
+ $instance_backups = $instance_api_backups['metadata'];
- $instance_only = ($instance_backup['instance_only'])?"true":"false";
- $container_only = ($instance_backup['container_only'])?"true":"false";
- $optimized_storage = ($instance_backup['optimized_storage'])?"true":"false";
+ foreach ($instance_backups as $instance_backup){
- echo "
";
-
- echo " ";
- echo "" . htmlentities($instance_backup['name']) . " ";
- echo "" . htmlentities($instance_backup['created_at']) . " ";
- echo "" . htmlentities($instance_backup['expires_at']) . " ";
- echo "" . htmlentities($instance_only) . " ";
- echo "" . htmlentities($container_only) . " ";
- echo "" . htmlentities($optimized_storage) . " ";
+ $instance_only = ($instance_backup['instance_only'])?"true":"false";
+ $container_only = ($instance_backup['container_only'])?"true":"false";
+ $optimized_storage = ($instance_backup['optimized_storage'])?"true":"false";
+ $file = '/var/lxdware/backups/' . $row['host'] . '/' . $project . '/' . $instance . '/' . $instance_backup['name'];
+
+ echo " ";
+
+ echo " ";
+ echo "" . htmlentities($instance_backup['name']) . " ";
+ echo "" . htmlentities($instance_backup['created_at']) . " ";
+ echo "" . htmlentities($instance_backup['expires_at']) . " ";
+ echo "" . htmlentities($instance_only) . " ";
+ echo "" . htmlentities($optimized_storage) . " ";
+ if (file_exists($file)){
+ $file_size = filesize($file);
+ $unit_size = "bytes";
+ if ($file_size >= 1024){
+ $file_size = $file_size / 1024;
+ $unit_size = "KB";
+ }
+ if ($file_size >= 1024){
+ $file_size = $file_size / 1024;
+ $unit_size = "MB";
+ }
+ if ($file_size >= 1024){
+ $file_size = $file_size / 1024;
+ $unit_size = "GB";
+ }
+ if ($file_size >= 1000){
+ $file_size = $file_size / 1024;
+ $unit_size = "TB";
+ }
+ echo ' '.htmlentities(basename($file)).' ('.number_format($file_size,0).' '.$unit_size.') ';
+ }
+ else{
+ echo " ";
+ }
+
+ echo "";
+ echo ' ';
+ echo '   ';
+ echo ' ';
+ echo " ";
+
+ echo " ";
+
+ }
+ }
- echo "
";
- echo ' ';
- echo '   ';
- echo ' ';
- echo " ";
-
- echo "";
- }
}
echo "";
diff --git a/admin/php/lxd/instance-single-disk-list.php b/admin/php/lxd/instance-single-disk-list.php
index 136cefe..069969a 100644
--- a/admin/php/lxd/instance-single-disk-list.php
+++ b/admin/php/lxd/instance-single-disk-list.php
@@ -35,35 +35,40 @@
$url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/instances/" . $instance . "/state?project=" . $project;
$remote_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$remote_data = json_decode($remote_data, true);
- $disk_names = $remote_data['metadata']['disk'];
- foreach ($disk_names as $disk_name => $disk_data){
- $url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/instances/" . $instance . "?project=" . $project;
- $remote_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
- $remote_data = json_decode($remote_data, true);
- $device_names = $remote_data['metadata']['expanded_devices'];
- foreach ($device_names as $device_name => $device_data){
- if ($device_name == $disk_name){
- $disk_path = $device_data['path'];
- $disk_type = $device_data['type'];
+ if (isset($remote_data['metadata']['disk'])){
+ $disk_names = $remote_data['metadata']['disk'];
+
+ foreach ($disk_names as $disk_name => $disk_data){
+
+ $url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/instances/" . $instance . "?project=" . $project;
+ $remote_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
+ $remote_data = json_decode($remote_data, true);
+ $device_names = $remote_data['metadata']['expanded_devices'];
+ foreach ($device_names as $device_name => $device_data){
+ if ($device_name == $disk_name){
+ $disk_path = $device_data['path'];
+ $disk_type = $device_data['type'];
+ }
}
+
+ echo "
";
+
+ echo " ";
+ echo "" . htmlentities($disk_name) . " ";
+ echo "" . htmlentities($disk_path) . " ";
+ echo "" . htmlentities(number_format($disk_data['usage']/1024/1024,2)) . " MB ";
+ echo "" . htmlentities($disk_type) . " ";
+
+ echo "";
+ //echo ' ';
+ echo " ";
+
+ echo " ";
+
}
-
- echo "
";
-
- echo " ";
- echo "" . htmlentities($disk_name) . " ";
- echo "" . htmlentities($disk_path) . " ";
- echo "" . htmlentities(number_format($disk_data['usage']/1024/1024,2)) . " MB ";
- echo "" . htmlentities($disk_type) . " ";
-
- echo "";
- //echo ' ';
- echo " ";
-
- echo " ";
-
}
+
}
echo "";
diff --git a/admin/php/lxd/instance-single-log-list.php b/admin/php/lxd/instance-single-log-list.php
index c261b92..052e6bb 100644
--- a/admin/php/lxd/instance-single-log-list.php
+++ b/admin/php/lxd/instance-single-log-list.php
@@ -36,24 +36,28 @@
$url = $url . "/1.0/instances/" . $instance . "/logs?project=" . $project;
$instance_api_logs = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$instance_api_logs = json_decode($instance_api_logs, true);
- $instance_logs = $instance_api_logs['metadata'];
-
- foreach ($instance_logs as $instance_log){
-
- echo "
";
-
- echo " ";
- echo "" . htmlentities($instance_log) . " ";
-
- echo "";
- echo ' ';
- echo '   ';
- echo ' ';
- echo " ";
+
+ if (isset($instance_api_logs['metadata'])){
+ $instance_logs = $instance_api_logs['metadata'];
- echo " ";
+ foreach ($instance_logs as $instance_log){
+ echo "
";
+
+ echo " ";
+ echo "" . htmlentities($instance_log) . " ";
+
+ echo "";
+ echo ' ';
+ echo '   ';
+ echo ' ';
+ echo " ";
+
+ echo " ";
+
+ }
}
+
}
echo "";
diff --git a/admin/php/lxd/instance-single-network-list.php b/admin/php/lxd/instance-single-network-list.php
index d0b82a6..4c74ca0 100644
--- a/admin/php/lxd/instance-single-network-list.php
+++ b/admin/php/lxd/instance-single-network-list.php
@@ -36,51 +36,55 @@
$url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/instances/" . $instance . "/state?recursion=1&project=" . $project;
$remote_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$remote_data = json_decode($remote_data, true);
- $networks = $remote_data['metadata']['network'];
- foreach ($networks as $network => $network_data){
-
- echo "
";
- if ($network_data['state'] == "up")
- echo " ";
- else
- echo " ";
- echo "" . htmlentities($network) . " ";
- echo "" . htmlentities($network_data['hwaddr']) . " ";
-
- echo "";
- $i = 0;
- foreach ($network_data['addresses'] as $address){
- if ($address['family'] == "inet"){
- if ($i > 0)
- echo " ";
- echo htmlentities($address['address']) . "/" . htmlentities($address['netmask']);
- $i++;
+ if (isset($remote_data['metadata']['network'])){
+ $networks = $remote_data['metadata']['network'];
+
+ foreach ($networks as $network => $network_data){
+
+ echo " ";
+ if ($network_data['state'] == "up")
+ echo " ";
+ else
+ echo " ";
+ echo "" . htmlentities($network) . " ";
+ echo "" . htmlentities($network_data['hwaddr']) . " ";
+
+ echo "";
+ $i = 0;
+ foreach ($network_data['addresses'] as $address){
+ if ($address['family'] == "inet"){
+ if ($i > 0)
+ echo " ";
+ echo htmlentities($address['address']) . "/" . htmlentities($address['netmask']);
+ $i++;
+ }
}
- }
- echo " ";
-
- echo "";
- $i = 0;
- foreach ($network_data['addresses'] as $address){
- if ($address['family'] == "inet6"){
- if ($i > 0)
- echo " ";
- echo htmlentities($address['address']);
- $i++;
+ echo " ";
+
+ echo "";
+ $i = 0;
+ foreach ($network_data['addresses'] as $address){
+ if ($address['family'] == "inet6"){
+ if ($i > 0)
+ echo " ";
+ echo htmlentities($address['address']);
+ $i++;
+ }
}
+ echo " ";
+
+ echo "" . htmlentities($network_data['state']) . " ";
+
+ echo "";
+ //echo ' ';
+ echo " ";
+
+ echo " ";
+
}
- echo "";
-
- echo "
" . htmlentities($network_data['state']) . " ";
-
- echo "
";
- //echo ' ';
- echo " ";
-
- echo "";
-
}
+
}
echo "";
diff --git a/admin/php/lxd/instance-single-profile-list.php b/admin/php/lxd/instance-single-profile-list.php
index 3e76e64..9e0082e 100644
--- a/admin/php/lxd/instance-single-profile-list.php
+++ b/admin/php/lxd/instance-single-profile-list.php
@@ -33,29 +33,34 @@
$url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/instances/" . $instance . "?project=" . $project;
$remote_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$remote_data = json_decode($remote_data, true);
- $profile_names = $remote_data['metadata']['profiles'];
- foreach ($profile_names as $profile_name){
- $url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/profiles/" . $profile_name . "?project=" . $project;
- $profile_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
- $profile_data = json_decode($profile_data, true);
- $profile_data = $profile_data['metadata'];
- if ($profile_data['name'] == "")
- continue;
-
- echo "
";
-
- echo " ";
- echo "" . htmlentities($profile_data['name']) . " ";
- echo "" . htmlentities($profile_data['description']) . " ";
-
- echo "";
- echo ' ';
- echo " ";
+ if (isset($remote_data['metadata']['profiles'])){
+ $profile_names = $remote_data['metadata']['profiles'];
- echo " ";
-
+ foreach ($profile_names as $profile_name){
+ $url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/profiles/" . $profile_name . "?project=" . $project;
+ $profile_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
+ $profile_data = json_decode($profile_data, true);
+ $profile_data = $profile_data['metadata'];
+ if ($profile_data['name'] == "")
+ continue;
+
+
+ echo "
";
+
+ echo " ";
+ echo "" . htmlentities($profile_data['name']) . " ";
+ echo "" . htmlentities($profile_data['description']) . " ";
+
+ echo "";
+ echo ' ';
+ echo " ";
+
+ echo " ";
+
+ }
}
+
}
echo "";
diff --git a/admin/php/lxd/instance-single-proxy-list.php b/admin/php/lxd/instance-single-proxy-list.php
index 87f591a..388ab7f 100644
--- a/admin/php/lxd/instance-single-proxy-list.php
+++ b/admin/php/lxd/instance-single-proxy-list.php
@@ -36,25 +36,29 @@
$url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/instances/" . $instance . "?project=" . $project;
$remote_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$remote_data = json_decode($remote_data, true);
- $device_names = $remote_data['metadata']['expanded_devices'];
- foreach ($device_names as $device_name => $device_data){
- if ($device_data['type'] == "proxy"){
- echo "
";
- echo " ";
- echo "" . htmlentities($device_name) . " ";
- echo "" . htmlentities($device_data['connect']) . " ";
- echo "" . htmlentities($device_data['listen']) . " ";
- echo "" . htmlentities($device_data['type']) . " ";
-
- echo "";
- //echo ' ';
- echo " ";
-
- echo " ";
- }
- else {
- continue;
+ if (isset($remote_data['metadata']['expanded_devices'])){
+ $device_names = $remote_data['metadata']['expanded_devices'];
+
+ foreach ($device_names as $device_name => $device_data){
+ if ($device_data['type'] == "proxy"){
+ echo "
";
+
+ echo " ";
+ echo "" . htmlentities($device_name) . " ";
+ echo "" . htmlentities($device_data['connect']) . " ";
+ echo "" . htmlentities($device_data['listen']) . " ";
+ echo "" . htmlentities($device_data['type']) . " ";
+
+ echo "";
+ //echo ' ';
+ echo " ";
+
+ echo " ";
+ }
+ else {
+ continue;
+ }
}
}
diff --git a/admin/php/lxd/instance-single-snapshot-list.php b/admin/php/lxd/instance-single-snapshot-list.php
index f94c193..e662edc 100644
--- a/admin/php/lxd/instance-single-snapshot-list.php
+++ b/admin/php/lxd/instance-single-snapshot-list.php
@@ -35,39 +35,43 @@
$url = "https://" . $row['host'] . ":" . $row['port'] . "/1.0/instances/" . $instance . "/snapshots?recursion=1&project=" . $project;
$remote_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$remote_data = json_decode($remote_data, true);
- $snapshots = $remote_data['metadata'];
-
- foreach ($snapshots as $snapshot){
-
- if ($snapshot['name'] == "")
- continue;
-
- if ($snapshot['stateful'])
- $state = "stateful";
- else
- $state = "stateless";
-
- echo "
";
-
- echo " ";
- echo "" . htmlentities($snapshot['name']) . " ";
- echo "" . htmlentities($state) . " ";
- echo "" . htmlentities(number_format($snapshot['size']/1024/1024,2)) . "MB ";
- echo "" . htmlentities($snapshot['created_at']) . " ";
-
- echo "";
- echo ' ';
- echo '   ';
- echo ' ';
- echo '   ';
- echo ' ';
- echo '   ';
- echo ' ';
- echo " ";
-
- echo " ";
+ if (isset($remote_data['metadata'])){
+ $snapshots = $remote_data['metadata'];
+
+ foreach ($snapshots as $snapshot){
+
+ if ($snapshot['name'] == "")
+ continue;
+
+ if ($snapshot['stateful'])
+ $state = "stateful";
+ else
+ $state = "stateless";
+
+ echo "
";
+
+ echo " ";
+ echo "" . htmlentities($snapshot['name']) . " ";
+ echo "" . htmlentities($state) . " ";
+ echo "" . htmlentities(number_format($snapshot['size']/1024/1024,2)) . "MB ";
+ echo "" . htmlentities($snapshot['created_at']) . " ";
+
+ echo "";
+ echo ' ';
+ echo '   ';
+ echo ' ';
+ echo '   ';
+ echo ' ';
+ echo '   ';
+ echo ' ';
+ echo " ";
+
+ echo " ";
+
+ }
}
+
}
echo "";
diff --git a/admin/php/lxd/instance-single-state.php b/admin/php/lxd/instance-single-state.php
index 5ff4755..aa3138c 100644
--- a/admin/php/lxd/instance-single-state.php
+++ b/admin/php/lxd/instance-single-state.php
@@ -27,59 +27,66 @@
$url = $url . "/1.0/instances/".$instance."/state?project=" . $project;
$instance_api_state = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$url'");
$instance_api_state = json_decode($instance_api_state, true);
- $instance_state = $instance_api_state['metadata'];
- $pid = $instance_state['pid']?: "N/A"; //process ID on the host
- $processes = $instance_state['processes']?: "N/A"; //number of process running in container
- $cpu = $instance_state['cpu']['usage']; //cpu usage in nanoseconds
+ if (isset($instance_api_state['metadata'])){
+ $instance_state = $instance_api_state['metadata'];
- if ($instance_state['memory']['usage'] < 1073741824){
- $memory = number_format($instance_state['memory']['usage']/1024/1024, 2);//total amount of memory used in MB
- $memory_unit = "MB";
- }
- else {
- $memory = number_format($instance_state['memory']['usage']/1024/1024/1024, 2);//total amount of memory used in GB
- $memory_unit = "GB";
- }
-
- $network_interfaces = $instance_state['network']; //array of networks
-
- //echo "
CPU Usage : " . htmlentities($cpu) . " nanoseconds
";
- echo "
Memory : " . htmlentities($memory) . " " . $memory_unit . "
";
- echo "
PID : " . htmlentities($pid) . "
";
- echo "
Processes : " . htmlentities($processes) . "
";
-
- echo "
IPv4 Addresses : ";
- $i = 0;
- if (!$network_interfaces)
- echo "N/A";
- foreach ($network_interfaces as $network_interface){
- foreach ($network_interface['addresses'] as $address){
- if ($address['family'] == "inet" && $address['scope'] == "global"){
- if ($i > 0)
- echo ", ";
- echo htmlentities($address['address']) . "/" . htmlentities($address['netmask']);
- $i++;
- }
+ $pid = $instance_state['pid']?: "N/A"; //process ID on the host
+ $processes = $instance_state['processes']?: "N/A"; //number of process running in container
+ $cpu = $instance_state['cpu']['usage']; //cpu usage in nanoseconds
+
+ if ($instance_state['memory']['usage'] < 1073741824){
+ $memory = number_format($instance_state['memory']['usage']/1024/1024, 2);//total amount of memory used in MB
+ $memory_unit = "MB";
}
- }
- echo "
";
-
- echo "
IPv6 Addresses : ";
- $i = 0;
- if (!$network_interfaces)
+ else {
+ $memory = number_format($instance_state['memory']['usage']/1024/1024/1024, 2);//total amount of memory used in GB
+ $memory_unit = "GB";
+ }
+
+ $network_interfaces = $instance_state['network']; //array of networks
+
+ //echo "
CPU Usage : " . htmlentities($cpu) . " nanoseconds
";
+ echo "
Memory : " . htmlentities($memory) . " " . $memory_unit . "
";
+ echo "
PID : " . htmlentities($pid) . "
";
+ echo "
Processes : " . htmlentities($processes) . "
";
+
+ echo "
IPv4 Addresses : ";
+ $i = 0;
+ if (!$network_interfaces)
echo "N/A";
- foreach ($network_interfaces as $network_interface){
- foreach ($network_interface['addresses'] as $address){
- if ($address['family'] == "inet6" && $address['scope'] == "global"){
- if ($i > 0)
- echo ", ";
- echo htmlentities($address['address']);
- $i++;
+ if (isset($network_interfaces)){
+ foreach ($network_interfaces as $network_interface){
+ foreach ($network_interface['addresses'] as $address){
+ if ($address['family'] == "inet" && $address['scope'] == "global"){
+ if ($i > 0)
+ echo ", ";
+ echo htmlentities($address['address']) . "/" . htmlentities($address['netmask']);
+ $i++;
+ }
+ }
+ }
+ }
+ echo "
";
+
+ echo "
IPv6 Addresses : ";
+ $i = 0;
+ if (!$network_interfaces)
+ echo "N/A";
+ if (isset($network_interfaces)){
+ foreach ($network_interfaces as $network_interface){
+ foreach ($network_interface['addresses'] as $address){
+ if ($address['family'] == "inet6" && $address['scope'] == "global"){
+ if ($i > 0)
+ echo ", ";
+ echo htmlentities($address['address']);
+ $i++;
+ }
+ }
}
}
+ echo "
";
}
- echo "
";
}
diff --git a/admin/php/lxd/instance-single.php b/admin/php/lxd/instance-single.php
index 1081401..d36972e 100644
--- a/admin/php/lxd/instance-single.php
+++ b/admin/php/lxd/instance-single.php
@@ -26,24 +26,33 @@
$data_url = $url . "/1.0/instances/".$instance."?project=" . $project;
$instance_api_data = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X GET '$data_url'");
$instance_api_data = json_decode($instance_api_data, true);
- $instance_data = $instance_api_data['metadata'];
-
- $name = $instance_data['name'];
- $created = $instance_data['created_at']?: "N/A";
- $description = $instance_data['description']?: "N/A";
- $type = $instance_data['type']?: "N/A"; //ex container, virtual-machine
- $location = $instance_data['location']?: "N/A"; //used with clusters,none for non-clustered host
- $image = $instance_data['config']['image.description']?: "N/A"; //ex Ubuntu focal amd64 (20200821_07:42)
- $status = $instance_data['status']?: "N/A"; //ex Running
-
-
- echo "
Name :
".htmlentities($name)." ";
- echo "
Description : " . htmlentities($description) . "
";
- echo "
Type : " . htmlentities($type) . "
";
- echo "
Status : " . htmlentities($status) . "
";
- echo "
Image : " . htmlentities($image) . "
";
- echo "
Location : " . htmlentities($location) . "
";
+ if (isset($instance_api_data['metadata'])){
+ $instance_data = $instance_api_data['metadata'];
+
+ $name = $instance_data['name'];
+ $created = $instance_data['created_at']?: "N/A";
+ $description = $instance_data['description']?: "N/A";
+ $type = $instance_data['type']?: "N/A"; //ex container, virtual-machine
+ $location = $instance_data['location']?: "N/A"; //used with clusters,none for non-clustered host
+
+ if (isset($instance_data['config']['image.description']))
+ $image = $instance_data['config']['image.description']?: "N/A"; //ex Ubuntu focal amd64 (20200821_07:42)
+ else
+ $image = "N/A";
+
+ $status = $instance_data['status']?: "N/A"; //ex Running
+
+
+ echo "
Name :
".htmlentities($name)." ";
+
+ echo "
Description : " . htmlentities($description) . "
";
+ echo "
Type : " . htmlentities($type) . "
";
+ echo "
Status : " . htmlentities($status) . "
";
+ echo "
Image : " . htmlentities($image) . "
";
+ echo "
Location : " . htmlentities($location) . "
";
+ }
+
}
diff --git a/admin/php/lxd/instances.php b/admin/php/lxd/instances.php
index 8501dc8..6b4830e 100644
--- a/admin/php/lxd/instances.php
+++ b/admin/php/lxd/instances.php
@@ -40,6 +40,12 @@
$release = filter_var(urldecode($_GET['release']), FILTER_SANITIZE_STRING);
if (isset($_GET['snapshot']))
$snapshot = filter_var(urldecode($_GET['snapshot']), FILTER_SANITIZE_STRING);
+ if (isset($_GET['instance_only']))
+ $instance_only = filter_var(urldecode($_GET['instance_only']), FILTER_SANITIZE_STRING);
+ if (isset($_GET['optimized_storage']))
+ $optimized_storage = filter_var(urldecode($_GET['optimized_storage']), FILTER_SANITIZE_STRING);
+ if (isset($_GET['compression_algorithm']))
+ $compression_algorithm = filter_var(urldecode($_GET['compression_algorithm']), FILTER_SANITIZE_STRING);
//Instantiate the POST variable
if (isset($_POST['json']))
@@ -212,17 +218,60 @@
$results = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X DELETE '$url'");
break;
case "createBackup":
+ //Determine file extension for backup file
+ switch ($compression_algorithm) {
+ case "bzip2":
+ $file_extension = ".tar.bz2";
+ break;
+ case "gzip":
+ $file_extension = ".tar.gz";
+ break;
+ case "lzma":
+ $file_extension = ".tar.lzma";
+ break;
+ case "xz":
+ $file_extension = ".tar.xz";
+ break;
+ case "zstd":
+ $file_extension = ".tar.zst";
+ break;
+ default:
+ $file_extension = ".tar";
+ }
$url = $url . "/1.0/instances/" . $instance . "/backups?project=" . $project;
- $data = escapeshellarg('{"name": "'. $name . '"}');
+ $data = escapeshellarg('{"name": "'. $name . $file_extension . '", "instance_only": '.$instance_only.', "optimized_storage": '.$optimized_storage.', "compression_algorithm": "'.$compression_algorithm.'"}');
$results = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X POST -d $data '$url'");
break;
- case "downloadBackup":
- mkdir('../../downloads');
- $url = $url . "/1.0/instances/" . $instance . "/backups/" . $name . "/export?project=" . $project;
- $results = shell_exec("sudo curl -k -L --connect-timeout 3 --output ../../downloads/".$name.".tar.gz --cert $cert --key $key -X GET '$url'");
- $results = "downloads/".$name.".tar.gz";
+ case "exportBackupFile":
+ $file = '/var/lxdware/backups/' . $row['host'] . '/' . $project . '/' . $instance . '/' . $name;
+ if (!file_exists($file)){
+ //If there is no directory yet for the host to store backups, create it
+ if (!file_exists('/var/lxdware/backup/' . $row['host'] . '/' . $project . '/' . $instance)){
+ mkdir('/var/lxdware/backups/'.$row['host'] . '/' . $project . '/' . $instance, 0777, true);
+ }
+ $url = $url . "/1.0/instances/" . $instance . "/backups/" . $name . "/export?project=" . $project;
+ $results = shell_exec("sudo curl -k -L --connect-timeout 3 --output $file --cert $cert --key $key -X GET '$url'");
+ }
+ break;
+ case "downloadExportFile":
+ $file = '/var/lxdware/backups/' . $row['host'] . '/' . $project . '/' . $instance . '/' . $name;
+ $file_name = basename($file);
+ $file_size = filesize($file);
+ if (file_exists($file)) {
+ header('Content-Description: File Transfer');
+ header('Content-Type: application/octet-stream');
+ header('Content-Disposition: attachment; filename="'.$file_name.'"');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate');
+ header('Pragma: public');
+ header('Content-Length: ' . $file_size);
+ readfile($file);
+ exit;
+ }
break;
case "deleteBackup":
+ $file = '/var/lxdware/backups/' . $row['host'] . '/' . $project . '/' . $instance . '/' . $name;
+ unlink($file);
$url = $url . "/1.0/instances/" . $instance . "/backups/" . $name . "?project=" . $project;
$results = shell_exec("sudo curl -k -L --connect-timeout 3 --cert $cert --key $key -X DELETE '$url'");
break;
diff --git a/admin/php/lxd/network-list.php b/admin/php/lxd/network-list.php
index 6587bd5..3e6bfba 100644
--- a/admin/php/lxd/network-list.php
+++ b/admin/php/lxd/network-list.php
@@ -31,6 +31,18 @@
$network_data_managed = ($network['managed'])?"true":"false";
+ //This array key is not availabe on unmanaged network devices
+ if (isset($network['config']['ipv4.address']))
+ $ipv4 = $network['config']['ipv4.address'];
+ else
+ $ipv4 = "";
+
+ //This array key is not available on unmanaged network devices
+ if (isset($network['config']['ipv6.address']))
+ $ipv6 = $network['config']['ipv6.address'];
+ else
+ $ipv6 = "";
+
if ($i > 0){
echo ",";
}
@@ -48,8 +60,8 @@
}
echo '"' . htmlentities($network['description']) . '",';
- echo '"' . htmlentities($network['config']['ipv4.address']) . '",';
- echo '"' . htmlentities($network['config']['ipv6.address']) . '",';
+ echo '"' . htmlentities($ipv4) . '",';
+ echo '"' . htmlentities($ipv6) . '",';
echo '"' . htmlentities($network['type']) . '",';
echo '"' . htmlentities($network_data_managed) . '",';
diff --git a/admin/php/lxd/operation-status.php b/admin/php/lxd/operation-status.php
index c8acbc2..c7d0e26 100644
--- a/admin/php/lxd/operation-status.php
+++ b/admin/php/lxd/operation-status.php
@@ -31,12 +31,19 @@
if (!empty($operations_data['running'])){
foreach ($operations_data['running'] as $running_task){
$results = $running_task['description'];
- $instance = basename($running_task['resources']['instances'][0]);
+
+ if (isset($running_task['resources']['instances'][0]))
+ $instance = basename($running_task['resources']['instances'][0]);
+ else
+ $instance = "";
switch($running_task['description']){
case "Backing up container":
$results .= " " . $instance;
break;
+ case "Backing up instance":
+ $results .= " " . $instance;
+ break;
case "Creating container":
$results .= " " . $instance;
break;
@@ -50,10 +57,12 @@
$results .= " " . $instance;
break;
case "Downloading image":
- $results .= " " . $running_task['metadata']['download_progress'];
+ if (isset($running_task['metadata']['download_progress']))
+ $results .= " " . htmlentities($running_task['metadata']['download_progress']);
break;
case "Executing command":
- $results = "Executing " . htmlentities($running_task['metadata']['command'][0]) . " command on " . htmlentities($instance);
+ if (isset($running_task['metadata']['command'][0]))
+ $results = "Executing " . htmlentities($running_task['metadata']['command'][0]) . " command on " . htmlentities($instance);
break;
case "Freezing instance":
$results .= " " . $instance;
@@ -85,7 +94,7 @@
if (!empty($operations_data['failure'])){
foreach ($operations_data['failure'] as $failed_task){
- $results = $failed_task['description'] . " Error: " . $failed_task['err'];
+ $results = htmlentities($failed_task['description']) . " Error: " . htmlentities($failed_task['err']);
}
}
diff --git a/admin/php/lxd/profile-list.php b/admin/php/lxd/profile-list.php
index f285ab2..636d641 100644
--- a/admin/php/lxd/profile-list.php
+++ b/admin/php/lxd/profile-list.php
@@ -44,7 +44,7 @@
foreach($profile['devices'] as $device=>$value){
if ($ii > 0)
echo ", ";
- echo $device;
+ echo htmlentities($device);
$ii++;
}
echo '",';
diff --git a/admin/php/lxd/remote-breadcrumb.php b/admin/php/lxd/remote-breadcrumb.php
index ebf0cb3..f02302e 100644
--- a/admin/php/lxd/remote-breadcrumb.php
+++ b/admin/php/lxd/remote-breadcrumb.php
@@ -12,9 +12,9 @@
while($row = $db_results->fetchArray()){
if ($row['alias'] != "")
- echo $row['alias'];
+ echo htmlentities($row['alias']);
else
- echo $row['host'];
+ echo htmlentities($row['host']);
}
}
diff --git a/admin/php/lxd/remote-list-nav.php b/admin/php/lxd/remote-list-nav.php
index f7cf048..11dbb66 100644
--- a/admin/php/lxd/remote-list-nav.php
+++ b/admin/php/lxd/remote-list-nav.php
@@ -24,8 +24,6 @@
$display_name = $row['host'];
-
- //echo '
';
echo '';
echo ' ';
echo 'Host: '. htmlentities($display_name) . ' ';
@@ -47,7 +45,6 @@
}
echo ' ';
- //echo '';
}
diff --git a/admin/php/lxd/storage-pool-list.php b/admin/php/lxd/storage-pool-list.php
index e057fa0..4685211 100644
--- a/admin/php/lxd/storage-pool-list.php
+++ b/admin/php/lxd/storage-pool-list.php
@@ -40,7 +40,7 @@
echo '",';
echo '"';
- echo "
";
echo '",';
echo '"' . htmlentities($storage_pool['description']) . '",';
diff --git a/startup.sh b/startup.sh
index 49bba8a..9d0492b 100644
--- a/startup.sh
+++ b/startup.sh
@@ -10,6 +10,12 @@ then
mkdir -p /var/lxdware/data/lxd
fi
+#Create backups directory if needed
+if [ ! -d /var/lxdware/backups ]
+then
+ mkdir -p /var/lxdware/backups
+fi
+
#Create LXC cert if necessary, because LXD dameon is not running we need to make a fake remote connection to create it
if [ ! -f /var/lxdware/data/lxd/client.crt ]
@@ -49,7 +55,7 @@ then
fi
chown -R www-data:www-data /var/lxdware/data/sqlite
-
+chown -R www-data:www-data /var/lxdware/backups
#Start PHP for NGINX
service php7.4-fpm start