Skip to content

Commit

Permalink
Merge pull request #10 from jpmchia/main
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
jpmchia authored Oct 11, 2023
2 parents a7873fb + f8fbe28 commit 7c9f18d
Show file tree
Hide file tree
Showing 204 changed files with 14,436 additions and 1,206 deletions.
5 changes: 2 additions & 3 deletions backend/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"github.com/jpmchia/ip2location-pfsense/backend/config"
"github.com/jpmchia/ip2location-pfsense/backend/util"
"github.com/jpmchia/ip2location-pfsense/config"
"github.com/jpmchia/ip2location-pfsense/util"

"github.com/nitishm/go-rejson/v4"
"github.com/redis/go-redis/v9"
Expand All @@ -23,7 +23,6 @@ var instances map[string]RedisInstance

func init() {
util.LogDebug("[cache] Initialising cache service")

instances = make(map[string]RedisInstance)
}

Expand Down
4 changes: 2 additions & 2 deletions backend/cache/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cache

import (
"github.com/jpmchia/ip2location-pfsense/backend/config"
"github.com/jpmchia/ip2location-pfsense/backend/util"
"github.com/jpmchia/ip2location-pfsense/config"
"github.com/jpmchia/ip2location-pfsense/util"

"github.com/spf13/viper"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"log"

"github.com/jpmchia/ip2location-pfsense/backend/config"
"github.com/jpmchia/ip2location-pfsense/config"

"github.com/spf13/cobra"
)
Expand Down
4 changes: 2 additions & 2 deletions backend/cmd/counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cmd
import (
"log"

"github.com/jpmchia/ip2location-pfsense/backend/ip2location"
"github.com/jpmchia/ip2location-pfsense/backend/service"
"github.com/jpmchia/ip2location-pfsense/ip2location"
"github.com/jpmchia/ip2location-pfsense/service"

"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"log"

"github.com/jpmchia/ip2location-pfsense/backend/ip2location"
"github.com/jpmchia/ip2location-pfsense/ip2location"

"github.com/spf13/cobra"
)
Expand Down
25 changes: 8 additions & 17 deletions backend/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ package cmd
import (
"os"

"github.com/jpmchia/ip2location-pfsense/backend/config"
"github.com/jpmchia/ip2location-pfsense/backend/util"
"github.com/jpmchia/ip2location-pfsense/config"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var cfgFile string
var projectBase string

// var projectBase string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -69,21 +68,13 @@ func init() {

// Define global persistent flags
rootCmd.PersistentFlags().StringVarP(&config.CfgFile, "config", "c", cfgFile, "specifiy the filename and path of the configiration file")
rootCmd.PersistentFlags().StringVarP(&projectBase, "projectbase", "b", "https://github.com/jpmchia/IP2Location-pfSense", "base project directory")
rootCmd.PersistentFlags().BoolVarP(&util.Debug, "debug", "v", false, "output verbose debugging information")
// rootCmd.PersistentFlags().StringVarP(&projectBase, "projectbase", "b", "https://github.com/jpmchia/IP2Location-pfSense", "base project directory")

// Bind flags to viper
err := viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))
util.HandleError(err, "Unable to bind flag to viper")
err = viper.BindPFlag("projectbase", rootCmd.PersistentFlags().Lookup("projectbase"))
util.HandleError(err, "Unable to bind flag to viper")

//if util.Debug {
// util.LogDebug("Debugging verbose mode enabled")
//}

// // Load configuration
// config.LoadConfigProvider(cfgFile)
// err := viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))
// util.HandleError(err, "Unable to bind flag to viper")
// err = viper.BindPFlag("projectbase", rootCmd.PersistentFlags().Lookup("projectbase"))
// util.HandleError(err, "Unable to bind flag to viper")
}

func initConfig() {
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/serve.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/jpmchia/ip2location-pfsense/backend/service"
"github.com/jpmchia/ip2location-pfsense/service"

"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"fmt"

"github.com/jpmchia/ip2location-pfsense/backend/version"
"github.com/jpmchia/ip2location-pfsense/version"

"github.com/spf13/cobra"
)
Expand Down
12 changes: 4 additions & 8 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"github.com/jpmchia/ip2location-pfsense/backend/util"
"github.com/jpmchia/ip2location-pfsense/util"

"github.com/spf13/viper"
)
Expand All @@ -32,6 +32,7 @@ type Provider interface {
var Config Options

const appName string = "github.com/jpmchia/ip2location-pfsense/backend"
const appNamePrefix string = "ip2location-pfsense"

var CfgFile string = "config.yaml"
var defaultConfig *viper.Viper
Expand All @@ -45,7 +46,7 @@ func init() {

func Configure() {
// Load the default configuration
defaultConfig = initViperConfig(appName)
defaultConfig = initViperConfig(appNamePrefix)

// Set and load additional configuration locations
setConfigLocations(CfgFile)
Expand Down Expand Up @@ -90,32 +91,28 @@ func initViperConfig(appName string) *viper.Viper {
// global defaults
v.SetDefault("jsonlogs", false)
v.SetDefault("loglevel", "debug")
v.SetDefault("installation_path", "/usr/local/ip2location")
v.SetDefault("use_redis", true)
v.SetDefault("installation_path", "/opt/ip2location-pfsense")
v.SetDefault("redis.ip2location.host", "127.0.0.1")
v.SetDefault("redis.ip2location.port", "6379")
v.SetDefault("redis.ip2location.db", 1)
v.SetDefault("redis.ip2location.auth", "ip2location")
v.SetDefault("redis.ip2location.pass", "password")

v.SetDefault("redis.pfsense.host", "127.0.0.1")
v.SetDefault("redis.pfsense.port", "6379")
v.SetDefault("redis.pfsense.db", 2)
v.SetDefault("redis.pfsense.auth", "ip2location")
v.SetDefault("redis.pfsense.pass", "password")

v.SetDefault("redis.watchlist.host", "127.0.0.1")
v.SetDefault("redis.watchlist.port", "6379")
v.SetDefault("redis.watchlist.db", 3)
v.SetDefault("redis.watchlist.auth", "ip2location")
v.SetDefault("redis.watchlist.pass", "password")

v.SetDefault("ip2api.url", "https://api.ip2location.io/")
v.SetDefault("ip2api.key", "")
v.SetDefault("ip2api.plan", "Free")
v.SetDefault("ip2api.max_errors", 5)
v.SetDefault("ip2api.source", "IP2Location-pfSense")

v.SetDefault("service.bind_host", "127.0.0.1")
v.SetDefault("service.bind_port", "9999")
v.SetDefault("service.allow_hosts", "*")
Expand All @@ -127,7 +124,6 @@ func initViperConfig(appName string) *viper.Viper {
v.SetDefault("service.ip2geomap", "/index.html")
v.SetDefault("service.healthcheck", "/health")
v.SetDefault("service.ip_requests", "/api/ip2location")

v.SetDefault("use_cache", true)
v.SetDefault("debug", false)

Expand Down
25 changes: 25 additions & 0 deletions backend/counters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
counters:
apimisses: 0
cachehits: 0
cachemisses: 0
daily:
count: 0
max: 900
nextreset: "2023-10-11T23:47:17Z"
startdate: "2023-10-10T23:47:17Z"
enabled: true
hourly:
count: 0
max: 900
nextreset: 2023-10-11T00:47:17.215480477Z
startdate: 2023-10-10T23:47:17.215480287Z
lifetime:
count: 0
max: 0
nextreset: 2023-10-10T23:47:17.215481197Z
startdate: 2023-10-10T23:47:17.215480987Z
monthly:
count: 0
max: 30000
nextreset: "2023-11-10T23:47:17Z"
startdate: "2023-10-10T23:47:17Z"
23 changes: 14 additions & 9 deletions backend/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/jpmchia/ip2location-pfsense/backend
module github.com/jpmchia/ip2location-pfsense

go 1.21

require (
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5
github.com/redis/go-redis/v9 v9.2.1
github.com/spf13/viper v1.16.0
github.com/spf13/viper v1.17.0
)

require (
Expand All @@ -16,10 +16,16 @@ require (
github.com/labstack/gommon v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/time v0.3.0 // indirect
)

Expand All @@ -31,15 +37,14 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nitishm/go-rejson/v4 v4.1.1-0.20230331060235-d2aa875760e4
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 7c9f18d

Please sign in to comment.