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