2020-11-10 21:53:46 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-29 20:20:02 +00:00
|
|
|
"github.com/jackc/pgx/pgxpool"
|
2020-12-17 04:23:25 +00:00
|
|
|
"github.com/microcosm-cc/bluemonday"
|
2020-11-10 21:53:46 -05:00
|
|
|
"net/http"
|
2020-12-17 04:23:25 +00:00
|
|
|
_ "net/http/pprof"
|
2020-12-06 18:05:17 -05:00
|
|
|
"regexp"
|
2020-12-14 23:09:51 +00:00
|
|
|
"runtime"
|
2020-12-17 04:23:25 +00:00
|
|
|
"sync"
|
2020-11-10 21:53:46 -05:00
|
|
|
)
|
|
|
|
|
2020-11-17 18:28:59 -05:00
|
|
|
// Current instances
|
|
|
|
var runninginstances map[string]RunningInstance
|
|
|
|
var ri_mutex = &sync.Mutex{}
|
2020-12-18 06:06:32 +00:00
|
|
|
var pool *pgxpool.Pool
|
2020-11-10 21:53:46 -05:00
|
|
|
|
2020-11-24 20:36:47 -05:00
|
|
|
func startpprof() {
|
2021-01-14 19:51:42 +00:00
|
|
|
logInfo.Print("Starting http/pprof on :7777")
|
|
|
|
logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
|
2020-11-24 20:36:47 -05:00
|
|
|
}
|
2020-11-10 21:53:46 -05:00
|
|
|
|
2020-11-24 20:36:47 -05:00
|
|
|
func main() {
|
2020-11-10 21:53:46 -05:00
|
|
|
// Initial Setup
|
2021-01-14 19:51:42 +00:00
|
|
|
logInit()
|
2020-11-24 20:36:47 -05:00
|
|
|
runninginstances = make(map[string]RunningInstance)
|
2020-11-10 21:53:46 -05:00
|
|
|
|
2020-12-03 17:26:38 -05:00
|
|
|
getSettings()
|
2021-01-30 07:12:37 +00:00
|
|
|
if len(settings.Proxies) > 0 {
|
|
|
|
for i := 0; i < len(settings.Proxies); i++ {
|
|
|
|
logInfo.Printf("Using proxy: %s:%d", settings.Proxies[i].Host, settings.Proxies[i].Port)
|
|
|
|
}
|
|
|
|
}
|
2020-11-24 20:36:47 -05:00
|
|
|
go startpprof()
|
2020-11-16 00:10:33 -05:00
|
|
|
|
2020-12-18 06:06:32 +00:00
|
|
|
pool = getDbPool()
|
2020-12-03 17:26:38 -05:00
|
|
|
|
2020-12-06 18:05:17 -05:00
|
|
|
p = bluemonday.NewPolicy()
|
2021-01-14 19:51:42 +00:00
|
|
|
spaceReg = regexp.MustCompile(`[\s\t\.]+`)
|
2021-01-14 20:43:20 +00:00
|
|
|
removeHTMLReg = regexp.MustCompile(`<\/?\s*br\s*>`)
|
2021-01-10 05:31:51 +00:00
|
|
|
re = regexp.MustCompile("^https?://([^/]*)/(.*)$")
|
2021-01-25 20:28:13 -05:00
|
|
|
matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*")
|
2020-12-03 17:26:38 -05:00
|
|
|
|
|
|
|
for _, endpoint := range settings.Autostart {
|
2021-01-14 19:51:42 +00:00
|
|
|
logInfo.Print("Autostarting " + endpoint)
|
2021-02-01 00:28:20 +00:00
|
|
|
_, exists := GetRunner(endpoint)
|
2020-12-17 18:26:55 +00:00
|
|
|
if exists == false {
|
2020-12-22 20:36:37 +00:00
|
|
|
go StartInstance(endpoint)
|
2020-12-03 17:26:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-22 20:36:37 +00:00
|
|
|
go startctl()
|
|
|
|
go webmain()
|
2020-12-14 23:09:51 +00:00
|
|
|
|
|
|
|
runtime.Goexit()
|
2020-11-10 21:53:46 -05:00
|
|
|
}
|