123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="apple-mobile-web-app-capable" content="yes" />
- <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
- <meta charset="UTF-8">
- <meta name="theme-color" content="#4b75ff">
- <link rel="icon" type="image/png" href="./favicon.png" />
- <title>Web SSH | Zoraxy</title>
- <link rel="stylesheet" href="../script/semantic/semantic.min.css">
- <script src="../script/jquery-3.6.0.min.js"></script>
- <script src="../../script/ao_module.js"></script>
- <script src="../script/semantic/semantic.min.js"></script>
- <script src="../script/tablesort.js"></script>
- <link rel="stylesheet" href="../main.css">
- <style>
- #loadingUI{
- width: 100%;
- height: 100%;
- background-color: black;
- position: fixed;
- top: 0;
- left: 0;
- display:none;
- }
- #loadingUI div{
- color: white;
- font-family: monospace;
- }
- </style>
- </head>
- <body>
- <div id="loadingUI">
- <div style="margin-top: 2em; margin-left: 2em; color: white;">
- <i class="ui loading spinner icon"></i> <b>Creating virtual terminal session</b><br>
- <div id="counter" style="color: white; margin-left: 1.9em;">Setting Up Environment</div>
- </div>
- </div>
- <div id="connectionSettings">
- <div class="ui container">
- <br>
- <div class="ui form">
- <div class="two fields">
- <div class="field">
- <label>Server Name or IP Address</label>
- <input type="text" name="server" placeholder="e.g. example.com or 192.168.1.1">
- </div>
- <div class="field">
- <label>Port Number</label>
- <input type="number" name="port" placeholder="e.g. 22 or 2022">
- </div>
- <div class="field">
- <label>Username</label>
- <input type="text" name="username" placeholder="root">
- </div>
- </div>
- </div>
- <div id="ui error message">
- </div>
- <div style="float: right;">
- <button class="ui basic button" onclick="connectSSH()"><i class="ui blue exchange icon"></i> Connect</button>
- <button class="ui basic button" onclick="window.open('', '_self', ''); window.close();"><i class="ui red remove icon"></i> Close</button>
- </div>
- </div>
- <br><br><br>
- </div>
- <script>
-
- 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")
- }
- }
-
- function connectSSH() {
- const serverValue = $('input[name="server"]').val().trim();
- var portString = $('input[name="port"]').val().trim();
- if (portString.trim() == ""){
- portString = "22";
- }
- const portValue = parseInt(portString, 10);
- const username = $('input[name="username"]').val().trim();
- if (username == ""){
- username = "root";
- }
-
- const validServer = isValidServerNameOrIPAddress(serverValue);
-
-
- const validPort = (portValue >= 1 && portValue <= 65535);
-
- if (validServer && validPort) {
-
- createSSHProxy(serverValue, portValue, username);
- } else {
-
- const errorLabel = $('<div>').addClass('ui red basic label');
- if (!validServer) {
- $('input[name="server"]').parent().addClass('error');
- } else{
- $('input[name="server"]').parent().removeClass('error');
- }
-
- if (!validPort) {
- $('input[name="port"]').parent().addClass('error');
- }else{
- $('input[name="port"]').parent().removeClass('error');
- }
- }
- }
- function redirectWithCountdown(url) {
- $("#loadingUI").show();
- $("#connectionSettings").hide();
- var count = 3;
- var interval = setInterval(function() {
- $("#counter").html("ETA " + count + " seconds");
- count--;
- if (count === 0) {
- clearInterval(interval);
- window.location.href = url;
- }
- }, 1000);
- }
-
-
- function createSSHProxy(remoteAddr, remotePort, username){
-
- $.ajax({
- url: "/api/tools/webssh",
- data: {ipaddr: remoteAddr, port: remotePort, username:username},
- method: "POST",
- success: function(sessionToken){
- if (sessionToken.error != undefined){
- alert(sessionToken.error);
- }else{
-
- redirectWithCountdown("/web.ssh/" + sessionToken + "/");
- }
- },
- error: function(){
- }
- })
- }
- function isValidServerNameOrIPAddress(str) {
-
- if (str == "localhost"){
- return true;
- }
-
- const ipAddressRegex = /^(\d{1,3}\.){3}\d{1,3}$/;
- if (ipAddressRegex.test(str)) {
- return true;
- }
-
- const serverNameRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$/;
- if (serverNameRegex.test(str)) {
- return true;
- }
-
-
- return false;
- }
- </script>
- </body>
- </html>
|