|
@@ -25,7 +25,24 @@
|
|
|
<div style="position: relative;">
|
|
|
<h2>Web SSH</h2>
|
|
|
<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;">
|
|
|
Copy from Terminal <code style="float: right;">Ctrl + Insert</code><br>
|
|
|
Paste to Terminal <code style="float: right;">Shift + Insert</code>
|
|
@@ -65,6 +82,66 @@
|
|
|
$('.tab.segment').removeClass('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>
|