diff --git a/src/zutil/net/ws/openapi/OpenAPIHttpPage.java b/src/zutil/net/ws/openapi/OpenAPIHttpPage.java
index 83a6a5c..c8f6319 100644
--- a/src/zutil/net/ws/openapi/OpenAPIHttpPage.java
+++ b/src/zutil/net/ws/openapi/OpenAPIHttpPage.java
@@ -58,7 +58,7 @@ public class OpenAPIHttpPage implements HttpPage {
out.setHeader(HttpHeader.HEADER_CONTENT_TYPE, "application/json");
wsdl.write(out);
} else {
- // Output human readable interface
+ // Output human-readable interface
out.println("");
out.println("");
diff --git a/src/zutil/osal/linux/app/Btrfs.java b/src/zutil/osal/linux/app/Btrfs.java
new file mode 100644
index 0000000..9edbad6
--- /dev/null
+++ b/src/zutil/osal/linux/app/Btrfs.java
@@ -0,0 +1,78 @@
+package zutil.osal.linux.app;
+
+import zutil.osal.MultiCommandExecutor;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Wrapper for the linux Btrfs command to query and modify btrfs based filesystems.
+ */
+public class Btrfs {
+ private static String BTRFS_CMD = "btrfs";
+ private static SimpleDateFormat DATE_PARSER = new SimpleDateFormat("dow mon dd hh:mm:ss zzz yyyy");
+
+ // The disk used as an id to btrfs
+ private String path;
+ // Terminal where all commands will be executed.
+ private MultiCommandExecutor terminal;
+
+
+ public Btrfs(String path) {
+ this(path, new MultiCommandExecutor());
+ }
+ public Btrfs(String path, MultiCommandExecutor terminal) {
+ this.path = path;
+ this.terminal = terminal;
+ }
+
+
+ // ****************************************************
+ // Balance functions
+ // ****************************************************
+
+ public void startBalance() throws IOException {
+ execBtrfsCommand("balance start", path);
+ }
+
+ public void cancelBalance() throws IOException {
+ execBtrfsCommand("balance cancel", path);
+ }
+
+ public void getBalanceProgress() throws IOException {
+ execBtrfsCommand("balance status", path);
+ }
+
+ // ****************************************************
+ // Scrub functions
+ // ****************************************************
+
+ public void startScrub() throws IOException {
+ execBtrfsCommand("scrub start", path);
+ }
+
+ public void cancelScrub() throws IOException {
+ execBtrfsCommand("scrub cancel", path);
+ }
+
+ public void getScrubProgress() throws IOException {
+ execBtrfsCommand("scrub status", path);
+ }
+
+ public Date getLastScrubDate() throws IOException {
+ String log = execBtrfsCommand("scrub status", path);
+
+ return null;
+ }
+
+ // ****************************************************
+ // Utility functions
+ // ****************************************************
+
+ public String execBtrfsCommand(String params, String path) throws IOException {
+ terminal.exec(BTRFS_CMD + " " + params + " " + path);
+
+ return terminal.readAll();
+ }
+}
diff --git a/src/zutil/ui/conf/configurator.dynamic.tmpl b/src/zutil/ui/conf/configurator.dynamic.tmpl
index 2abd0b8..089bf09 100644
--- a/src/zutil/ui/conf/configurator.dynamic.tmpl
+++ b/src/zutil/ui/conf/configurator.dynamic.tmpl
@@ -28,26 +28,36 @@
if (formTemplateId != null)
modal.find("#" + formTemplateId).empty(); // clear form div
- // select dynamic form
- var selector = modal.find("select[name=type]");
- selector.val(button.data("type"));
- selector.change(); // Update dynamic inputs
// set dynamic form data
$.each(button.attr(), function(fieldName, value) {
- if (fieldName.startsWith("data-")) {
- fieldName = fieldName.substring(5);
+ if(fieldName.startsWith("data-")) {
+ fieldName = fieldName.substring(5); // remove prefix data-
+
// case insensitive search
- input = modal.find("input").filter(function() {
- return this.name.toLowerCase() == fieldName;
+ var input = modal.find("input, select").filter(function() {
+ if (this.name.toLowerCase() == fieldName) {
+ if (this.type == "hidden" && modal.find("input[type=checkbox][name=" + fieldName + "]") != null)
+ return false; // Workaround for the default(false) boolean input
+ return true;
+ }
+ return false;
});
- if (input.attr("type") == "checkbox") { // special handling for checkboxes
- input.attr("value", "true");
- if (value=="true") input.attr("checked", "true");
- else input.removeAttr("checked");
- // Add default false value as a unchecked checkbox is not included in the post
- input.parent().prepend("");
- } else {
- input.val(value);
+
+ if (input != null) {
+ if (input.prop("type") == "checkbox") { // special handling for checkboxes
+ input.prop("value", "true");
+ input.prop("checked", value == "true");
+
+ if (modal.find("input[type=hidden][name=" + fieldName + "]") == null) {
+ // Add default false value as a unchecked checkbox is not included in the post
+ input.parent().prepend("");
+ }
+ } else {
+ input.val(value);
+
+ if (input.prop("tagName") == "SELECT")
+ input.change(); // required for select elements to update properly
+ }
}
}
});
diff --git a/test/zutil/osal/linux/app/BtrfsTest.java b/test/zutil/osal/linux/app/BtrfsTest.java
new file mode 100644
index 0000000..4680ccf
--- /dev/null
+++ b/test/zutil/osal/linux/app/BtrfsTest.java
@@ -0,0 +1,41 @@
+package zutil.osal.linux.app;
+
+import junit.framework.TestCase;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class BtrfsTest {
+
+ @Test
+ public void testGetScrubProgress() {
+ }
+
+ //@Test
+ public void testGetLastScrubDate() throws IOException, ParseException {
+ final String[] cmd = {null};
+
+ Btrfs btrfs = new Btrfs("/dev/sda1") {
+ public String execBtrfsCommand(String params, String path) throws IOException {
+ cmd[0] = params + " " + path;
+
+ return "scrub status for 3a6b2a74-05a9-464d-bbbd-15710c548f76\n" +
+ " scrub started at Fri Feb 4 00:29:54 2022 and finished after 58380 seconds\n" +
+ " total bytes scrubbed: 15.74TiB with 0 errors\n";
+ }
+ };
+
+ Date actualDate = btrfs.getLastScrubDate();
+ Date expectedDate = new SimpleDateFormat("dow mon dd hh:mm:ss zzz yyyy").parse("Fri Feb 4 00:29:54 2022");
+
+ assertEquals("scrub status /dev/sda1", cmd[0]);
+ assertTrue("Dates are not close enough to each other!",
+ Math.abs(expectedDate.getTime() - actualDate.getTime()) < 1000);
+ }
+}
\ No newline at end of file