Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
ef6e3bac79
4 changed files with 89 additions and 9 deletions
  1. 9 2
      main.go
  2. 47 0
      mod/geodb/geodb.go
  3. 15 7
      web/components/status.html
  4. 18 0
      web/index.html

+ 9 - 2
main.go

@@ -14,6 +14,7 @@ import (
 	"imuslab.com/arozos/ReverseProxy/mod/auth"
 	"imuslab.com/arozos/ReverseProxy/mod/database"
 	"imuslab.com/arozos/ReverseProxy/mod/dynamicproxy/redirection"
+	"imuslab.com/arozos/ReverseProxy/mod/geodb"
 	"imuslab.com/arozos/ReverseProxy/mod/tlscert"
 )
 
@@ -23,13 +24,14 @@ var showver = flag.Bool("version", false, "Show version of this server")
 
 var (
 	name    = "Zoraxy"
-	version = "2.0"
+	version = "2.1"
 
 	handler        *aroz.ArozHandler
 	sysdb          *database.Database
 	authAgent      *auth.AuthAgent
 	tlsCertManager *tlscert.Manager
 	redirectTable  *redirection.RuleTable
+	geodbStore     *geodb.Store
 )
 
 // Kill signal handler. Do something before the system the core terminate.
@@ -82,7 +84,6 @@ func main() {
 	if err != nil {
 		log.Fatal(err)
 	}
-
 	authAgent = auth.NewAuthenticationAgent(name, []byte(sessionKey), sysdb, true, func(w http.ResponseWriter, r *http.Request) {
 		//Not logged in. Redirecting to login page
 		http.Redirect(w, r, "/login.html", http.StatusTemporaryRedirect)
@@ -100,6 +101,12 @@ func main() {
 		panic(err)
 	}
 
+	//Create a geodb store
+	geodbStore, err = geodb.NewGeoDb(sysdb, "./system/GeoLite2-Country.mmdb")
+	if err != nil {
+		panic(err)
+	}
+
 	//Initiate management interface APIs
 	initAPIs()
 

+ 47 - 0
mod/geodb/geodb.go

@@ -0,0 +1,47 @@
+package geodb
+
+import (
+	"net"
+
+	"github.com/oschwald/geoip2-golang"
+	"imuslab.com/arozos/ReverseProxy/mod/database"
+)
+
+type Store struct {
+	geodb *geoip2.Reader
+	sysdb *database.Database
+}
+
+type CountryInfo struct {
+	CountryIsoCode string
+	ContinetCode   string
+}
+
+func NewGeoDb(sysdb *database.Database, dbfile string) (*Store, error) {
+	db, err := geoip2.Open(dbfile)
+	if err != nil {
+		return nil, err
+	}
+
+	return &Store{
+		geodb: db,
+		sysdb: sysdb,
+	}, nil
+}
+
+func (s *Store) ResolveCountryCodeFromIP(ipstring string) (*CountryInfo, error) {
+	// If you are using strings that may be invalid, check that ip is not nil
+	ip := net.ParseIP(ipstring)
+	record, err := s.geodb.City(ip)
+	if err != nil {
+		return nil, err
+	}
+	return &CountryInfo{
+		record.Country.IsoCode,
+		record.Continent.Code,
+	}, nil
+}
+
+func (s *Store) Close() {
+	s.geodb.Close()
+}

+ 15 - 7
web/components/status.html

@@ -1,12 +1,20 @@
-<div id="serverstatus" class="ui message">
-    <h3 class="ui header">
-        <i class="exchange icon"></i>
-        <div class="content">
-          <span id="statusTitle">Offline</span>
-          <div class="sub header" id="statusText">Reverse proxy server is offline</div>
+<div class="ui stackable four column grid">
+        <div class="column">
+            <div id="serverstatus" class="ui green inverted segment">
+                <h3 class="ui header">
+                    <i class="exchange icon"></i>
+                    <div class="content">
+                      <span id="statusTitle">Offline</span>
+                      <div class="sub header" id="statusText">Reverse proxy server is offline</div>
+                    </div>
+                </h3>
+            </div>
         </div>
-    </h3>
+        <div class="column">Column 2</div>
+        <div class="column">Column 3</div>
+        <div class="column">Column 4</div>
 </div>
+
 <div class="ui divider"></div>
 <p>Inbound Port (Port to be proxied)</p>
 <div class="ui action fluid input">

+ 18 - 0
web/index.html

@@ -52,6 +52,24 @@
                 padding: 1em;
                 flex: 1;
             }
+
+            @media screen and (max-width: 530px) {
+                .toolbar {
+                    display: inline-block;
+                    width: 100%;
+                    margin-bottom: 1em;
+                }
+
+                #mainmenu{
+                    width: calc(100% - 1em);
+                }
+
+                .contentWindow{
+                    display: inline-block;
+                    width: 100%;
+                }
+            }
+
         </style>
     </head>
     <body>