validating hostname before starting instance
changed hostname identification from account to URI
This commit is contained in:
parent
48acaa5b0b
commit
ec1743905a
19
ctl.go
19
ctl.go
@ -7,7 +7,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func startctl() {
|
func startctl() {
|
||||||
@ -44,12 +43,10 @@ func handleClient(commandClient net.Conn) {
|
|||||||
var responseback ResponseBack
|
var responseback ResponseBack
|
||||||
n, err := io.ReadFull(commandClient, sizebyte)
|
n, err := io.ReadFull(commandClient, sizebyte)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Read error", err)
|
log.Fatal("Read error: ", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
if n != 4 {
|
if n != 4 {
|
||||||
fmt.Println("Did not read 4 bytes, failure.")
|
log.Fatal("Did not read 4 bytes, failure.")
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
jsonsize := int(binary.LittleEndian.Uint32(sizebyte))
|
jsonsize := int(binary.LittleEndian.Uint32(sizebyte))
|
||||||
jsonbyte := make([]byte, jsonsize)
|
jsonbyte := make([]byte, jsonsize)
|
||||||
@ -95,8 +92,7 @@ func handleClient(commandClient net.Conn) {
|
|||||||
|
|
||||||
responsebytes, err := json.Marshal(responseback)
|
responsebytes, err := json.Marshal(responseback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error: ", err)
|
log.Fatal("Error: ", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = len(responsebytes)
|
n = len(responsebytes)
|
||||||
@ -104,20 +100,17 @@ func handleClient(commandClient net.Conn) {
|
|||||||
|
|
||||||
_, err = commandClient.Write(sizebyte)
|
_, err = commandClient.Write(sizebyte)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error on write:", err)
|
log.Fatal("Error on write:", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responsebyte, err := json.Marshal(responseback)
|
responsebyte, err := json.Marshal(responseback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error response back: ", err)
|
log.Fatal("Error response back: ", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = commandClient.Write(responsebyte)
|
_, err = commandClient.Write(responsebyte)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error on write:", err)
|
log.Fatal("Error on write:", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
commandClient.Close()
|
commandClient.Close()
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ func main() {
|
|||||||
|
|
||||||
p = bluemonday.NewPolicy()
|
p = bluemonday.NewPolicy()
|
||||||
spaceReg = regexp.MustCompile(`\s+`)
|
spaceReg = regexp.MustCompile(`\s+`)
|
||||||
|
// re = regexp.MustCompile("^https?://(.*)/.*$")
|
||||||
|
re = regexp.MustCompile("^https?://([^/]*)/(.*)$")
|
||||||
|
|
||||||
for _, endpoint := range settings.Autostart {
|
for _, endpoint := range settings.Autostart {
|
||||||
log.Print("Autostarting " + endpoint)
|
log.Print("Autostarting " + endpoint)
|
||||||
|
25
instance.go
25
instance.go
@ -9,10 +9,12 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
var p *bluemonday.Policy
|
var p *bluemonday.Policy
|
||||||
var spaceReg *regexp.Regexp
|
var spaceReg *regexp.Regexp
|
||||||
|
var re *regexp.Regexp
|
||||||
|
|
||||||
func GetRunner(endpoint string) RunningInstance {
|
func GetRunner(endpoint string) RunningInstance {
|
||||||
ri_mutex.Lock()
|
ri_mutex.Lock()
|
||||||
@ -101,6 +103,29 @@ func GetNodeInfo(endpoint string, o RunningInstance) RunningInstance {
|
|||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckInstance(newinstance string, callerEndpoint string) {
|
||||||
|
if settings.Crawl == true && stringexists(newinstance, settings.Banned) == false {
|
||||||
|
_, err := net.LookupHost(newinstance)
|
||||||
|
if err != nil { // Bad hostname
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Skip over this if its the same as the endpoint
|
||||||
|
if newinstance == callerEndpoint {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ri_mutex.Lock()
|
||||||
|
o, exists := runninginstances[newinstance]
|
||||||
|
if exists == false || o.Status == KEEPALIVE {
|
||||||
|
m := RunningInstance{}
|
||||||
|
runninginstances[newinstance] = m
|
||||||
|
go StartInstance(newinstance)
|
||||||
|
}
|
||||||
|
|
||||||
|
ri_mutex.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func StartInstance(endpoint string) {
|
func StartInstance(endpoint string) {
|
||||||
// Check if exists. If so, get the object. If not, create it
|
// Check if exists. If so, get the object. If not, create it
|
||||||
o := GetRunner(endpoint)
|
o := GetRunner(endpoint)
|
||||||
|
25
poll.go
25
poll.go
@ -1,13 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"crypto/sha1"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
//"html"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -177,8 +174,10 @@ func PollMastodonPleroma(endpoint string, o *RunningInstance) {
|
|||||||
|
|
||||||
for _, newpost := range newposts {
|
for _, newpost := range newposts {
|
||||||
go check_post(newpost.Uri)
|
go check_post(newpost.Uri)
|
||||||
at_sign := strings.Index(newpost.Account.Acct, "@")
|
matchset := re.FindStringSubmatch(newpost.Uri)
|
||||||
newinstance := newpost.Account.Acct[at_sign+1:]
|
newinstance := matchset[1]
|
||||||
|
|
||||||
|
log.Print(newinstance + " reported by " + endpoint)
|
||||||
|
|
||||||
// Check min_id
|
// Check min_id
|
||||||
if newpost.Id > min_id {
|
if newpost.Id > min_id {
|
||||||
@ -186,21 +185,7 @@ func PollMastodonPleroma(endpoint string, o *RunningInstance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only done if we are crawling
|
// Only done if we are crawling
|
||||||
if settings.Crawl == true && stringexists(newinstance, settings.Banned) == false {
|
go CheckInstance(newinstance, endpoint)
|
||||||
// Skip over this if its the same as the endpoint
|
|
||||||
if newinstance == endpoint {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
ri_mutex.Lock()
|
|
||||||
o, exists := runninginstances[newinstance]
|
|
||||||
if exists == false || o.Status == KEEPALIVE {
|
|
||||||
m := RunningInstance{}
|
|
||||||
runninginstances[newinstance] = m
|
|
||||||
go StartInstance(newinstance)
|
|
||||||
}
|
|
||||||
|
|
||||||
ri_mutex.Unlock()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * 10)
|
||||||
}
|
}
|
||||||
|
23
stream.go
23
stream.go
@ -91,20 +91,10 @@ func StreamMastodon(endpoint string, o *RunningInstance) {
|
|||||||
|
|
||||||
go check_post(newpost.Uri)
|
go check_post(newpost.Uri)
|
||||||
|
|
||||||
at_sign := strings.Index(newpost.Account.Acct, "@")
|
matchset := re.FindStringSubmatch(newpost.Uri)
|
||||||
newinstance := newpost.Account.Acct[at_sign+1:]
|
newinstance := matchset[1]
|
||||||
|
|
||||||
if settings.Crawl == true && stringexists(newinstance, settings.Banned) == false {
|
go CheckInstance(newinstance, endpoint)
|
||||||
ri_mutex.Lock()
|
|
||||||
o, exists := runninginstances[newinstance]
|
|
||||||
if exists == false || o.Status == KEEPALIVE {
|
|
||||||
m := RunningInstance{}
|
|
||||||
runninginstances[newinstance] = m
|
|
||||||
go StartInstance(newinstance)
|
|
||||||
}
|
|
||||||
|
|
||||||
ri_mutex.Unlock()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if retry == true {
|
if retry == true {
|
||||||
time.Sleep(time.Minute * 30)
|
time.Sleep(time.Minute * 30)
|
||||||
@ -112,11 +102,4 @@ func StreamMastodon(endpoint string, o *RunningInstance) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ri_mutex.Lock()
|
|
||||||
// m = runninginstances[endpoint]
|
|
||||||
// m.LastRun = time.Now().Format(time.RFC3339)
|
|
||||||
// m.Status = STREAM_ENDED
|
|
||||||
// runninginstances[endpoint] = m
|
|
||||||
// ri_mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
15
web.go
15
web.go
@ -125,20 +125,7 @@ func inboxHandler() http.HandlerFunc {
|
|||||||
newinstance := createobject.ID[8 : 8+slashend]
|
newinstance := createobject.ID[8 : 8+slashend]
|
||||||
log.Print("The at sign is: ", newinstance)
|
log.Print("The at sign is: ", newinstance)
|
||||||
|
|
||||||
// Only done if we are crawling
|
go CheckInstance(newinstance, "")
|
||||||
if settings.Crawl == true && stringexists(newinstance, settings.Banned) == false {
|
|
||||||
// Skip over this if its the same as the endpoint
|
|
||||||
ri_mutex.Lock()
|
|
||||||
o, exists := runninginstances[newinstance]
|
|
||||||
if exists == false || o.Status == KEEPALIVE {
|
|
||||||
m := RunningInstance{}
|
|
||||||
runninginstances[newinstance] = m
|
|
||||||
go StartInstance(newinstance)
|
|
||||||
}
|
|
||||||
|
|
||||||
ri_mutex.Unlock()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
case "Like":
|
case "Like":
|
||||||
case "Announcement":
|
case "Announcement":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user