Преглед изворни кода

auto update script executed

Toby Chui пре 1 година
родитељ
комит
63c8a2133d
4 измењених фајлова са 139 додато и 24 уклоњено
  1. 3 0
      api.go
  2. 1 0
      main.go
  3. 101 19
      web/components/utils.html
  4. 34 5
      wrappers.go

+ 3 - 0
api.go

@@ -136,6 +136,9 @@ func initAPIs() {
 	http.HandleFunc("/api/account/reset", HandleAdminAccountResetEmail)
 	http.HandleFunc("/api/account/new", HandleNewPasswordSetup)
 
+	//Others
+	http.HandleFunc("/api/info/x", HandleZoraxyInfo)
+
 	//If you got APIs to add, append them here
 }
 

+ 1 - 0
main.go

@@ -41,6 +41,7 @@ var (
 	version     = "2.6.1"
 	nodeUUID    = "generic"
 	development = true //Set this to false to use embedded web fs
+	bootTime    = time.Now().Unix()
 
 	/*
 		Binary Embedding File System

+ 101 - 19
web/components/utils.html

@@ -4,6 +4,8 @@
         <p>You might find these tools or information helpful when setting up your gateway server</p>
     </div>
     <div class="ui divider"></div>
+  
+    
     <div class="selfauthOnly">
         <h3>Account Management</h3>
         <p>Functions to help management the current account</p>
@@ -34,6 +36,11 @@
         <p>The following SMTP settings help you to reset your password in case you have lost your management account.</p>
         <form id="email-form" class="ui form">
             <div class="field">
+                <label>Sender Address</label>
+                <input type="text" name="senderAddr" placeholder="E.g. [email protected]">
+            </div>
+            <div class="field">
+                <p><i class="caret down icon"></i> Connection setup for email service provider</p>
                 <div class="fields">
                     <div class="twelve wide field">
                         <label>SMTP Provider Hostname</label>
@@ -46,36 +53,35 @@
                     </div>
                 </div>
             </div>
-          
-            <div class="field">
-                <label>Sender Domain</label>
-                <input type="text" name="domain" min="1" max="65534" placeholder="E.g. arozos.com">
-            </div>
-        
-            <div class="field">
-                <label>Sender Address</label>
-                <input type="text" name="senderAddr" placeholder="E.g. [email protected]">
-            </div>
 
             <div class="field">
+                <p><i class="caret down icon"></i> Credentials for SMTP server authentications</p>
                 <div class="two fields">
                     <div class="field">
                         <label>Sender Username</label>
-                        <input type="text" name="username" placeholder="Username of the email account">
+                        <input type="text" name="username" placeholder="E.g. admin">
                     </div>
                 
                     <div class="field">
-                        <label>Sender Password</label>
-                        <input type="password" name="password" placeholder="Password of the email account">
-                        <small>Leave empty to use the old password</small>
+                        <label>Sender Domain</label>
+                        <div class="ui labeled input">
+                            <div class="ui basic label">
+                              @
+                            </div>
+                            <input type="text" name="domain" min="1" max="65534" placeholder="E.g. arozos.com">
+                        </div>
                     </div>
                 </div>
             </div>
+            <div class="field">
+                <label>Sender Password</label>
+                <input type="password" name="password" placeholder="Password of the email account">
+                <small>Leave empty to use the old password</small>
+            </div>
            
-            <div class="ui divider"></div>
-            <p> Email for sending account reset link</p>
+            <p> <i class="caret down icon"></i> Email for sending account reset link</p>
             <div class="field">
-                <label>Admin Address</label>
+                <label>Admin / Receiver Address</label>
                 <input type="text" name="recvAddr" placeholder="E.g. [email protected]">
             </div>
             
@@ -83,7 +89,7 @@
             <button class="ui basic button" onclick="event.preventDefault(); sendTestEmail(this);"><i class="teal mail icon"></i> Send Test Email</button>
         </form>
     </div>
-
+    <div class="ui divider"></div>
     <h3> IP Address to CIDR</h3>
     <p>No experience with CIDR notations? Here are some tools you can use to make setting up easier.</p>
     <div class="ui basic segment">
@@ -110,6 +116,45 @@
         </div>
         <p>Results: <div id="ipRangeOutput">N/A</div></p>
     </div>
+
+    <div class="ui divider"></div>
+    <div id="zoraxyinfo">
+        <h3 class="ui header">
+            System Information
+        </h3>
+        <p>Basic information about this zoraxy host</p>
+        <table class="ui very basic collapsing celled table">
+            <tbody>
+                <tr>
+                    <td>Host UUID</td>
+                    <td class="uuid"></td>
+                </tr>
+                <tr>
+                    <td>Version</td>
+                    <td class="version"></td>
+                </tr>
+                <tr>
+                    <td>Build</td>
+                    <td class="development"></td>
+                </tr>
+                <tr>
+                    <td>Running Since</td>
+                    <td class="boottime"></td>
+                </tr>
+                
+                <tr>
+                    <td>ZeroTier Linked</td>
+                    <td class="zt"></td>
+                </tr>
+                <tr>
+                    <td>Enable SSH Loopback</td>
+                    <td class="sshlb"></td>
+                </tr>
+            </tbody>
+          </table>
+          <p>Zoraxy is developed by tobychui for <a href="//imuslab.com" target="_blank">imuslab</a> and open source under <a href="https://www.gnu.org/licenses/agpl-3.0.txt">AGPL</a></p>
+    </div>
+    <br>
 </div>
 <script>
 
@@ -122,7 +167,44 @@
             //Using external auth manager. Hide options
             $(".selfauthOnly").hide();
         }
-    })
+    });
+
+    $.get("/api/info/x", function(data){
+        function timeConverter(UNIX_timestamp){
+            var a = new Date(UNIX_timestamp * 1000);
+            var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
+            var year = a.getFullYear();
+            var month = months[a.getMonth()];
+            var date = a.getDate();
+            var hour = a.getHours();
+            var min = a.getMinutes();
+            var sec = a.getSeconds();
+            var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
+            return time;
+        }
+
+        function secondsToDhms(seconds) {
+            seconds = Number(seconds);
+            var d = Math.floor(seconds / (3600*24));
+            var h = Math.floor(seconds % (3600*24) / 3600);
+            var m = Math.floor(seconds % 3600 / 60);
+            var s = Math.floor(seconds % 60);
+
+            var dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
+            var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
+            var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
+            var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
+            return dDisplay + hDisplay + mDisplay + sDisplay;
+        }
+
+        console.log(data);
+        $("#zoraxyinfo .uuid").text(data.NodeUUID);
+        $("#zoraxyinfo .development").text(data.Development?"Development":"Release");
+        $("#zoraxyinfo .version").text(data.Version);
+        $("#zoraxyinfo .boottime").text(timeConverter(data.BootTime) + ` ( ${secondsToDhms(parseInt(Date.now()/1000) - data.BootTime)} ago)`);
+        $("#zoraxyinfo .zt").html(data.ZerotierConnected?`<i class="ui green check icon"></i> Connected`:`<i class="ui red times icon"></i> Link Error`);
+        $("#zoraxyinfo .sshlb").html(data.EnableSshLoopback?`<i class="ui yellow exclamation triangle icon"></i> Enabled`:`Disabled`);
+    });
 
     function changePassword() {
         const oldPassword = document.getElementsByName('oldPassword')[0].value;

+ 34 - 5
wrappers.go

@@ -69,7 +69,7 @@ func HandleCheckSiteSupportTLS(w http.ResponseWriter, r *http.Request) {
 	Statistic Summary
 */
 
-//Handle conversion of statistic daily summary to country summary
+// Handle conversion of statistic daily summary to country summary
 func HandleCountryDistrSummary(w http.ResponseWriter, r *http.Request) {
 	requestClientCountry := map[string]int{}
 	statisticCollector.DailySummary.RequestClientIp.Range(func(key, value interface{}) bool {
@@ -143,7 +143,7 @@ func GetUptimeTargetsFromReverseProxyRules(dp *dynamicproxy.Router) []*uptime.Ta
 	return UptimeTargets
 }
 
-//Handle rendering up time monitor data
+// Handle rendering up time monitor data
 func HandleUptimeMonitorListing(w http.ResponseWriter, r *http.Request) {
 	if uptimeMonitor != nil {
 		uptimeMonitor.HandleUptimeLogRead(w, r)
@@ -153,7 +153,7 @@ func HandleUptimeMonitorListing(w http.ResponseWriter, r *http.Request) {
 	}
 }
 
-//Handle listing current registered mdns nodes
+// Handle listing current registered mdns nodes
 func HandleMdnsListing(w http.ResponseWriter, r *http.Request) {
 	js, _ := json.Marshal(previousmdnsScanResults)
 	utils.SendJSONResponse(w, string(js))
@@ -175,7 +175,7 @@ func HandleMdnsScanning(w http.ResponseWriter, r *http.Request) {
 	utils.SendJSONResponse(w, string(js))
 }
 
-//handle ip scanning
+// handle ip scanning
 func HandleIpScan(w http.ResponseWriter, r *http.Request) {
 	cidr, err := utils.PostPara(r, "cidr")
 	if err != nil {
@@ -214,14 +214,16 @@ func HandleIpScan(w http.ResponseWriter, r *http.Request) {
 }
 
 /*
+	WAKE ON LAN
+
 	Handle wake on LAN
 	Support following methods
 	/?set=xxx&name=xxx Record a new MAC address into the database
 	/?wake=xxx Wake a server given its MAC address
 	/?del=xxx Delete a server given its MAC address
 	/ Default: list all recorded WoL MAC address
-
 */
+
 func HandleWakeOnLan(w http.ResponseWriter, r *http.Request) {
 	set, _ := utils.PostPara(r, "set")
 	del, _ := utils.PostPara(r, "del")
@@ -297,3 +299,30 @@ func HandleWakeOnLan(w http.ResponseWriter, r *http.Request) {
 		utils.SendJSONResponse(w, string(js))
 	}
 }
+
+/*
+	Zoraxy Host Info
+*/
+
+func HandleZoraxyInfo(w http.ResponseWriter, r *http.Request) {
+	type ZoraxyInfo struct {
+		Version           string
+		NodeUUID          string
+		Development       bool
+		BootTime          int64
+		EnableSshLoopback bool
+		ZerotierConnected bool
+	}
+
+	info := ZoraxyInfo{
+		Version:           version,
+		NodeUUID:          nodeUUID,
+		Development:       development,
+		BootTime:          bootTime,
+		EnableSshLoopback: *allowSshLoopback,
+		ZerotierConnected: ganManager.ControllerID != "",
+	}
+
+	js, _ := json.MarshalIndent(info, "", " ")
+	utils.SendJSONResponse(w, string(js))
+}