Entirely redoing instance identification process
This commit is contained in:
parent
b783f21ccd
commit
12cf21c33a
@ -7,6 +7,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"os"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.farhan.codes/farhan/fedilogue/shared"
|
"git.farhan.codes/farhan/fedilogue/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,90 +85,77 @@ func UpdateRunner(endpoint string, o shared.RunningInstance) {
|
|||||||
ri_mutex.Unlock()
|
ri_mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func GetInstanceInfo(endpoint string, o shared.RunningInstance) shared.RunningInstance {
|
func GetInstanceInfo(endpoint string, o shared.RunningInstance) shared.RunningInstance {
|
||||||
/* Checking order
|
|
||||||
* Mastodon/Pleroma/Misskey
|
|
||||||
* Um..nothing else yet
|
|
||||||
*/
|
|
||||||
logDebug("GetInstanceInfo for ", endpoint)
|
logDebug("GetInstanceInfo for ", endpoint)
|
||||||
var nodeinfo shared.NodeInfo
|
wellknown_nodeinfo_uri := "https://" + endpoint + "/.well-known/nodeinfo"
|
||||||
pleromastodon_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.0.json"
|
|
||||||
|
|
||||||
// Checking Mastodon and Pleroma (with .json)
|
req, _ := http.NewRequest("GET", wellknown_nodeinfo_uri, nil)
|
||||||
reqjson, _ := http.NewRequest("GET", pleromastodon_nodeinfo_uri, nil)
|
|
||||||
reqjson.Header.Set("User-Agent", "Tusky")
|
|
||||||
|
|
||||||
pleromastodon_api_resp, err := DoTries(&o, reqjson)
|
|
||||||
if err != nil {
|
|
||||||
o.Software = "Unsupported"
|
|
||||||
return o
|
|
||||||
} else {
|
|
||||||
defer pleromastodon_api_resp.Body.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
if pleromastodon_api_resp.StatusCode == 200 {
|
|
||||||
err = json.NewDecoder(pleromastodon_api_resp.Body).Decode(&nodeinfo)
|
|
||||||
if err == nil {
|
|
||||||
o.Software = nodeinfo.Software.Name
|
|
||||||
o.Version = nodeinfo.Software.Version
|
|
||||||
o.LastRun = time.Now().Format(time.RFC3339)
|
|
||||||
defer pleromastodon_api_resp.Body.Close()
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking for Misskey (without .json)
|
|
||||||
misskey_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.0"
|
|
||||||
req, _ := http.NewRequest("GET", misskey_nodeinfo_uri, nil)
|
|
||||||
req.Header.Set("User-Agent", "Tusky")
|
req.Header.Set("User-Agent", "Tusky")
|
||||||
|
|
||||||
misskey_api_resp, err := DoTries(&o, req)
|
resp, err := DoTries(&o, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Exit 1")
|
||||||
o.Software = "Unsupported"
|
o.Software = "Unsupported"
|
||||||
return o
|
return o
|
||||||
} else {
|
} else {
|
||||||
defer misskey_api_resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if misskey_api_resp.StatusCode == 200 {
|
if resp.StatusCode != 200 {
|
||||||
err = json.NewDecoder(misskey_api_resp.Body).Decode(&nodeinfo)
|
fmt.Println("Exit 2")
|
||||||
if err == nil {
|
o.Software = "Unsupported"
|
||||||
o.Software = nodeinfo.Software.Name
|
|
||||||
o.Version = nodeinfo.Software.Version
|
|
||||||
o.LastRun = time.Now().Format(time.RFC3339)
|
|
||||||
defer misskey_api_resp.Body.Close()
|
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var wellknownnodeinfo shared.WellKnownNodeInfo
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&wellknownnodeinfo)
|
||||||
|
if (err != nil) {
|
||||||
|
fmt.Println("Exit 3")
|
||||||
|
o.Software = "Unsupported"
|
||||||
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for Lemmy (With Json)
|
// There can be multiple entries of /.well-known/nodeinfo entries, we want the last
|
||||||
lemmy_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.1"
|
length := len(wellknownnodeinfo.Links)
|
||||||
req, _ = http.NewRequest("GET", lemmy_nodeinfo_uri, nil)
|
if length == 0 {
|
||||||
|
fmt.Println("Exit 4")
|
||||||
|
o.Software = "Unsupported"
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
actual_nodeinfo_uri := wellknownnodeinfo.Links[length-1].Href
|
||||||
|
|
||||||
|
req, _ = http.NewRequest("GET", actual_nodeinfo_uri, nil)
|
||||||
req.Header.Set("User-Agent", "Tusky")
|
req.Header.Set("User-Agent", "Tusky")
|
||||||
|
|
||||||
lemmy_api_resp, err := DoTries(&o, req)
|
respActual, err := DoTries(&o, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Exit 5")
|
||||||
o.Software = "Unsupported"
|
o.Software = "Unsupported"
|
||||||
return o
|
return o
|
||||||
} else {
|
} else {
|
||||||
defer lemmy_api_resp.Body.Close()
|
defer respActual.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if lemmy_api_resp.StatusCode == 200 {
|
if respActual.StatusCode != 200 {
|
||||||
err = json.NewDecoder(lemmy_api_resp.Body).Decode(&nodeinfo)
|
fmt.Println("Exit 6")
|
||||||
if err == nil {
|
o.Software = "Unsupported"
|
||||||
logDebug("Found a new Lemmy instance: " + endpoint)
|
|
||||||
o.Software = nodeinfo.Software.Name
|
|
||||||
o.Version = nodeinfo.Software.Version
|
|
||||||
o.LastRun = time.Now().Format(time.RFC3339)
|
|
||||||
defer lemmy_api_resp.Body.Close()
|
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var actualnodeinfo shared.ActualNodeInfo
|
||||||
|
err = json.NewDecoder(respActual.Body).Decode(&actualnodeinfo)
|
||||||
|
if (err != nil) {
|
||||||
|
fmt.Println("Exit 7")
|
||||||
|
fmt.Println(err)
|
||||||
|
o.Software = "Unsupported"
|
||||||
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unsupported Software
|
fmt.Println(actualnodeinfo)
|
||||||
o.Software = "Unsupported"
|
fmt.Println("Final exit")
|
||||||
o.Version = "Unknown"
|
os.Exit(1)
|
||||||
|
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
@ -70,21 +70,6 @@ type RunningInstance struct {
|
|||||||
Recentactors *UniqueFifo `json:"-"`
|
Recentactors *UniqueFifo `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeInfoSoftware struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NodeInfo struct {
|
|
||||||
Software NodeInfoSoftware `json:"software"`
|
|
||||||
}
|
|
||||||
|
|
||||||
//type ResponseBack struct {
|
|
||||||
///Type string `json:"Type"`
|
|
||||||
//Message string `json:"Message"`
|
|
||||||
// RunningInstances map[string]RunningInstance `json:"RunningInstances"`
|
|
||||||
///}
|
|
||||||
|
|
||||||
type Userinfo struct {
|
type Userinfo struct {
|
||||||
Id string `"json:id"`
|
Id string `"json:id"`
|
||||||
Type string `"json:type"`
|
Type string `"json:type"`
|
||||||
@ -100,3 +85,21 @@ type Userinfo struct {
|
|||||||
ManuallyApprovesFollowers string `"json:manuallyApprovesFollowers"`
|
ManuallyApprovesFollowers string `"json:manuallyApprovesFollowers"`
|
||||||
Discoverable string `"json:discoverable"`
|
Discoverable string `"json:discoverable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SoftwareActualNodeInfo struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ActualNodeInfo struct {
|
||||||
|
Software SoftwareActualNodeInfo `json:"software"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WellKnownNodeInfoLinks struct {
|
||||||
|
Rel string `json:"rel"`
|
||||||
|
Href string `json:"href"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WellKnownNodeInfo struct {
|
||||||
|
Links []WellKnownNodeInfoLinks `json:"links"`
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user