1
0
Эх сурвалжийг харах

auto update script executed

Toby Chui 1 жил өмнө
parent
commit
6524a7965b

+ 78 - 1
web/components/networktools.html

@@ -25,7 +25,24 @@
         <div style="position: relative;">
         <div style="position: relative;">
             <h2>Web SSH</h2>
             <h2>Web SSH</h2>
             <p>Connect to a network node within the local area network of the gateway</p>
             <p>Connect to a network node within the local area network of the gateway</p>
-            <button class="ui basic larger circular button" onclick="launchToolWithSize('./tools/sshconn.html',1000, 640);">Connect via SSH</button>
+            <div class="ui small form">
+                <div class="three fields">
+                    <div class="field">
+                        <label>Server Name or IP Address</label>
+                        <input type="text" id="ssh_server" placeholder="e.g. example.com or 192.168.1.1">
+                    </div>
+                    <div class="field">
+                        <label>Port Number</label>
+                        <input type="number" id="ssh_port" placeholder="e.g. 22 or 2022">
+                    </div>
+                        <div class="field">
+                            <label>Username</label>
+                            <input type="text" id="ssh_username" placeholder="root">
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <button class="ui basic larger orange circular button" onclick="connectSSH();">Connect using SSH</button>
             <div class="ui inverted message" style="display: block;">
             <div class="ui inverted message" style="display: block;">
                 Copy from Terminal <code style="float: right;">Ctrl + Insert</code><br>
                 Copy from Terminal <code style="float: right;">Ctrl + Insert</code><br>
                 Paste to Terminal <code style="float: right;">Shift + Insert</code>
                 Paste to Terminal <code style="float: right;">Shift + Insert</code>
@@ -65,6 +82,66 @@
         $('.tab.segment').removeClass('active');
         $('.tab.segment').removeClass('active');
         $('div[data-tab="' + tab + '"]').addClass('active');
         $('div[data-tab="' + tab + '"]').addClass('active');
     });
     });
+
+    function connectSSH(){
+        function validateForm() {
+            var serverInput = document.getElementById("ssh_server");
+            var portInput = document.getElementById("ssh_port");
+            var usernameInput = document.getElementById("ssh_username");
+
+            var server = serverInput.value.trim();
+            var port = parseInt(portInput.value.trim() || "22");
+            var username = usernameInput.value.trim() || "root";
+
+            var isValid = true;
+
+            // Validate server input
+            if (server === "") {
+                msgbox("Server Name or IP Address is required", false, 5000);
+                serverInput.focus();
+                isValid = false;
+            } else if (!isIpAddress(server) && !isDomainName(server)) {
+                msgbox("Invalid Server Name or IP Address", false, 5000);
+                serverInput.focus();
+                isValid = false;
+            }
+
+            // Validate port input
+            if (isNaN(port) || port < 2 || port > 65533) {
+                msgbox("Port Number must be a number between 2 and 65533", false, 5000);
+                portInput.focus();
+                isValid = false;
+            }
+
+            if (isValid){
+                //OK! Launch SSH terminal
+                let settingPayload = {
+                    server: server,
+                    port: port,
+                    username: username
+                }
+
+                let settings = encodeURIComponent(JSON.stringify(settingPayload));
+                launchToolWithSize('./tools/sshconn.html#' + settings,1000, 640);
+            }else{
+
+            }
+        }
+
+        // Returns true if the given string is a valid IP address
+        function isIpAddress(str) {
+            var pattern = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
+            return pattern.test(str);
+        }
+
+        // Returns true if the given string is a valid domain name
+        function isDomainName(str) {
+            var pattern = /^[a-z\d\-]{1,63}(\.[a-z\d\-]{1,63})*$/i;
+            return pattern.test(str);
+        }
+
+        validateForm();
+    }
     
     
 </script>
 </script>
 <script>
 <script>

+ 1 - 1
web/main.css

@@ -226,7 +226,7 @@ body{
 }
 }
 
 
 .bluefont{
 .bluefont{
-    color: #a9d1f3 !important;
+    color: #417ac1 !important;
 }
 }
 
 
 
 

+ 28 - 0
web/tools/sshconn.html

@@ -66,6 +66,34 @@
             <br><br><br>
             <br><br><br>
         </div>
         </div>
         <script>
         <script>
+            /*
+                SSHCONN
+
+                This interface is designed to start a ssh connection instance
+                and brige the virtual terminal to the web front-end
+
+                Example Usage: 
+                let settingPayload = {
+                    server: "192.168.1.100",
+                    port: 2022,
+                    username: "pi"
+                }
+
+                let settings = encodeURIComponent(JSON.stringify(settingPayload));
+                window.open("sshconn.html#" + settings)
+            */
+
+            if (window.location.hash.length > 1){
+                try{
+                    var c = JSON.parse(decodeURIComponent((window.location.hash.substr(1))));
+                    $('input[name="server"]').val(c.server);
+                    $('input[name="port"]').val(c.port);
+                    $('input[name="username"]').val(c.username);
+                    connectSSH();
+                }catch(ex){
+                    alert("invalid usage")
+                }
+            }
 
 
             //Start the SSH connection process
             //Start the SSH connection process
             function connectSSH() {
             function connectSSH() {