1
0

sshconn.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="apple-mobile-web-app-capable" content="yes" />
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  6. <meta charset="UTF-8">
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="icon" type="image/png" href="./favicon.png" />
  9. <title>Web SSH | Zoraxy</title>
  10. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  11. <script src="../script/jquery-3.6.0.min.js"></script>
  12. <script src="../../script/ao_module.js"></script>
  13. <script src="../script/semantic/semantic.min.js"></script>
  14. <script src="../script/tablesort.js"></script>
  15. <link rel="stylesheet" href="../main.css">
  16. <style>
  17. </style>
  18. </head>
  19. <body>
  20. <br>
  21. <div class="ui container">
  22. <div class="ui form">
  23. <div class="two fields">
  24. <div class="field">
  25. <label>Server Name or IP Address</label>
  26. <input type="text" name="server" placeholder="e.g. example.com or 192.168.1.1">
  27. </div>
  28. <div class="field">
  29. <label>Port Number</label>
  30. <input type="number" name="port" placeholder="e.g. 22 or 2022">
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <div style="float: right;">
  36. <button class="ui basic button" onclick="connectSSH()"><i class="ui blue exchange icon"></i> Connect</button>
  37. <button class="ui basic button" style="margin-right: 1em;" onclick="window.open('', '_self', ''); window.close();"><i class="ui red remove icon"></i> Close</button>
  38. </div>
  39. <br><br><br>
  40. <script>
  41. //Start the SSH connection process
  42. function connectSSH() {
  43. const serverValue = $('input[name="server"]').val().trim();
  44. const portValue = parseInt($('input[name="port"]').val().trim(), 10);
  45. // Validate server name or IP address
  46. const validServer = isValidServerNameOrIPAddress(serverValue);
  47. // Validate port number
  48. const validPort = (portValue >= 1 && portValue <= 65535);
  49. if (validServer && validPort) {
  50. // Call doSomething function if both inputs are valid
  51. createSSHProxy(serverValue, portValue);
  52. } else {
  53. // Display an error message if either input is invalid
  54. const errorLabel = $('<div>').addClass('ui red basic label');
  55. if (!validServer) {
  56. errorLabel.text('Invalid server name or IP address');
  57. $('input[name="server"]').addClass('error');
  58. } else if (!validPort) {
  59. errorLabel.text('Invalid port number');
  60. $('input[name="port"]').addClass('error');
  61. }
  62. const field = $('input[name="server"]').closest('.field');
  63. field.append(errorLabel);
  64. }
  65. }
  66. //Try to ask the server side to create a ssh proxy object
  67. function createSSHProxy(){
  68. }
  69. function isValidServerNameOrIPAddress(str) {
  70. // First, check if the string is a valid IP address
  71. const ipAddressRegex = /^(\d{1,3}\.){3}\d{1,3}$/;
  72. if (ipAddressRegex.test(str)) {
  73. return true;
  74. }
  75. // If the string is not an IP address, check if it is a valid domain name or server name
  76. const serverNameRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$/;
  77. if (serverNameRegex.test(str)) {
  78. return true;
  79. }
  80. // If the string is neither an IP address nor a server name, return false
  81. return false;
  82. }
  83. </script>
  84. </body>
  85. </html>