This commit is contained in:
parent
762e801fd5
commit
18c86edd42
@ -13,12 +13,14 @@ func (config *Config) GetConfig() error {
|
||||
var configfile string
|
||||
var nofeed bool
|
||||
var debug bool
|
||||
var host string
|
||||
var port int
|
||||
|
||||
flag.Usage = utils.Usage
|
||||
|
||||
flag.StringVar(&configfile, "configfile", "qrz.ini", "config file to use with qrz section")
|
||||
flag.IntVar(&port, "port", 8080, "http port to use")
|
||||
flag.StringVar(&host, "host", "[::]", "http host to bind to")
|
||||
flag.IntVar(&port, "port", 8087, "http port to use")
|
||||
flag.BoolVar(&nofeed, "nofeed", false, "do not feed table with entries at first launch")
|
||||
flag.BoolVar(&debug, "debug", false, "enable debug")
|
||||
flag.Parse()
|
||||
@ -30,6 +32,7 @@ func (config *Config) GetConfig() error {
|
||||
|
||||
qrzsection := cfg.Section("qrz")
|
||||
|
||||
config.Host = host
|
||||
config.Port = port
|
||||
config.NoFeed = nofeed
|
||||
config.Debug = debug
|
||||
@ -60,6 +63,7 @@ type Config struct {
|
||||
URLBaseForGroups string
|
||||
QrzGroups []string
|
||||
Cron string
|
||||
Host string
|
||||
Port int
|
||||
NoFeed bool
|
||||
Debug bool
|
||||
|
@ -14,6 +14,12 @@ import (
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
const gxpath = "//center/form/select/*"
|
||||
|
||||
var frsre = regexp.MustCompile(`^ [0-9]{1,4}\s[A-Z]{1,5}\s[0-9]{1,5}`)
|
||||
var gre1 = regexp.MustCompile(`.*document.write\('(.*)'\).*`)
|
||||
var gre2 = regexp.MustCompile(`.*_(\d{1,3})\.php$`)
|
||||
|
||||
// InitCronConfig create task schedules
|
||||
func InitCronConfig(config config.Config) (err error) {
|
||||
cr := cron.New()
|
||||
@ -72,10 +78,6 @@ func Run(config config.Config) (err error) {
|
||||
}
|
||||
|
||||
func getGroups(urlbase string) (groups []string, err error) {
|
||||
re1 := regexp.MustCompile(`.*document.write\('(.*)'\).*`)
|
||||
re2 := regexp.MustCompile(`.*_(\d{1,3})\.php$`)
|
||||
xpath := `//center/form/select/*`
|
||||
|
||||
clt := &http.Client{}
|
||||
resp, err := clt.Get(urlbase)
|
||||
if err != nil {
|
||||
@ -87,7 +89,7 @@ func getGroups(urlbase string) (groups []string, err error) {
|
||||
}
|
||||
retstr := string(pagebody)
|
||||
|
||||
b := re1.FindStringSubmatch(retstr)
|
||||
b := gre1.FindStringSubmatch(retstr)
|
||||
body := b[1]
|
||||
|
||||
htmlpage, err := htmlquery.Parse(strings.NewReader(body))
|
||||
@ -95,10 +97,10 @@ func getGroups(urlbase string) (groups []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
query := htmlquery.Find(htmlpage, xpath)
|
||||
query := htmlquery.Find(htmlpage, gxpath)
|
||||
|
||||
for _, opt := range query {
|
||||
rematch := re2.FindStringSubmatch(opt.Attr[0].Val)
|
||||
rematch := gre2.FindStringSubmatch(opt.Attr[0].Val)
|
||||
if len(rematch) > 1 {
|
||||
groups = append(groups, rematch[1])
|
||||
}
|
||||
@ -133,7 +135,6 @@ func getBody(url string) (string, error) {
|
||||
// getFrsEntries get FRS entries from html body
|
||||
func getFrsEntries(config config.Config, body string) (frsentries map[string]Qrz, err error) {
|
||||
frsentries = make(map[string]Qrz)
|
||||
re := regexp.MustCompile(`^ [0-9]{1,4}\s[A-Z]{1,5}\s[0-9]{1,5}`)
|
||||
|
||||
htmlpage, err := htmlquery.Parse(strings.NewReader(body))
|
||||
if err != nil {
|
||||
@ -144,7 +145,7 @@ func getFrsEntries(config config.Config, body string) (frsentries map[string]Qrz
|
||||
td := htmlquery.Find(n, "//td")
|
||||
|
||||
if len(td) >= 6 {
|
||||
if re.MatchString(htmlquery.InnerText(td[1])) {
|
||||
if frsre.MatchString(htmlquery.InnerText(td[1])) {
|
||||
frs := Qrz{
|
||||
DMRID: getColumn(td[0]),
|
||||
QRZ: getColumn(td[1]),
|
||||
@ -153,7 +154,7 @@ func getFrsEntries(config config.Config, body string) (frsentries map[string]Qrz
|
||||
Dept: getColumn(td[4]),
|
||||
Country: getColumn(td[5])}
|
||||
frsentries[frs.QRZ] = frs
|
||||
} else if re.MatchString(htmlquery.InnerText(td[0])) {
|
||||
} else if frsre.MatchString(htmlquery.InnerText(td[0])) {
|
||||
frs := Qrz{
|
||||
QRZ: getColumn(td[0]),
|
||||
Name: getColumn(td[1]),
|
||||
|
@ -19,6 +19,10 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
var colre = regexp.MustCompile(`^[A-Za-z0-9]+$`)
|
||||
var orderre = regexp.MustCompile(`^(ASC|asc|DESC|desc)$`)
|
||||
var intre = regexp.MustCompile(`^[0-9]+$`)
|
||||
|
||||
// RunServer runs the main echo server
|
||||
func RunServer(config config.Config) (err error) {
|
||||
var p page.Page
|
||||
@ -59,7 +63,7 @@ func RunServer(config config.Config) (err error) {
|
||||
if !config.NoFeed {
|
||||
go qrz.Run(config)
|
||||
}
|
||||
e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", config.Port)))
|
||||
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", config.Host, config.Port)))
|
||||
return
|
||||
}
|
||||
|
||||
@ -141,6 +145,9 @@ func BuildQuery(config config.Config, qrzdt *QrzDatatableInput) (qrz []qrz.Qrz,
|
||||
// BuildQCntFil builds query for counting filtered
|
||||
func BuildQCntFil(config config.Config, qrzdt *QrzDatatableInput) (cnt int64, err error) {
|
||||
searchstatement, err := SetSearchLike(config, qrzdt)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
cnt, err = config.Db.SQL(
|
||||
fmt.Sprintf("SELECT COUNT(*) FROM qrz WHERE %s",
|
||||
searchstatement)).Count()
|
||||
@ -159,7 +166,6 @@ func BuildQCntTot(config config.Config, qrzdt *QrzDatatableInput) (cnt int64, er
|
||||
// SetSelect build the sql select statement part
|
||||
func SetSelect(config config.Config, qrzdt *QrzDatatableInput) (selectstatement string, err error) {
|
||||
var cols []string
|
||||
colre := regexp.MustCompile(`^[A-Za-z0-9]+$`)
|
||||
|
||||
if len(qrzdt.Columns) > 0 {
|
||||
for _, col := range qrzdt.Columns {
|
||||
@ -167,7 +173,7 @@ func SetSelect(config config.Config, qrzdt *QrzDatatableInput) (selectstatement
|
||||
if valid {
|
||||
cols = append(cols, col.Name)
|
||||
} else {
|
||||
err = fmt.Errorf("String does not match prerequisites")
|
||||
err = fmt.Errorf("string does not match prerequisites")
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -181,17 +187,13 @@ func SetSelect(config config.Config, qrzdt *QrzDatatableInput) (selectstatement
|
||||
|
||||
// SetOrder build the sql order statement part
|
||||
func SetOrder(config config.Config, qrzdt *QrzDatatableInput) (orderdir string, ordercols []string, err error) {
|
||||
colre := regexp.MustCompile(`^[A-Za-z0-9]+$`)
|
||||
orderre := regexp.MustCompile(`^(ASC|asc|DESC|desc)$`)
|
||||
|
||||
for _, col := range qrzdt.Order {
|
||||
if colre.MatchString(qrzdt.Columns[col.Column].Name) &&
|
||||
orderre.MatchString(col.Dir) {
|
||||
ordercols = append(ordercols,
|
||||
fmt.Sprintf("%s", qrzdt.Columns[col.Column].Name))
|
||||
ordercols = append(ordercols, qrzdt.Columns[col.Column].Name)
|
||||
orderdir = col.Dir
|
||||
} else {
|
||||
err = fmt.Errorf("Order statements does not match prerequisites")
|
||||
err = fmt.Errorf("order statements does not match prerequisites")
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -201,7 +203,6 @@ func SetOrder(config config.Config, qrzdt *QrzDatatableInput) (orderdir string,
|
||||
|
||||
// SetLimit build the sql limit
|
||||
func SetLimit(config config.Config, qrzdt *QrzDatatableInput) (limit int, offset int, err error) {
|
||||
intre := regexp.MustCompile(`^[0-9]+$`)
|
||||
|
||||
if qrzdt.Length < 1 {
|
||||
qrzdt.Length = 50
|
||||
@ -213,7 +214,7 @@ func SetLimit(config config.Config, qrzdt *QrzDatatableInput) (limit int, offset
|
||||
limit = qrzdt.Length
|
||||
offset = qrzdt.Start
|
||||
} else {
|
||||
err = fmt.Errorf("Limit statements does not match prerequisites")
|
||||
err = fmt.Errorf("limit statements does not match prerequisites")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -8,5 +8,5 @@ import (
|
||||
// Usage displays possible arguments
|
||||
func Usage() {
|
||||
flag.PrintDefaults()
|
||||
os.Exit(1)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user