diff --git a/fedilogger/config.go b/fedilogger/config.go index 53d5538..9d1a3d5 100644 --- a/fedilogger/config.go +++ b/fedilogger/config.go @@ -1,45 +1,14 @@ package main import ( - "encoding/json" - "io/ioutil" - - "muzzammil.xyz/jsonc" + "flag" ) -// MassFollower - Mass follower configuration used by config.go -type MassFollower struct { - Acct string `"json:acct"` - Name string `"json:name"` - Summary string `"json:summary"` - FollowingCount int `"json:followingcount"` - FollowLimit int `"json:followlimit"` -} - -// ExtAccount - External account configuration used by config.go -type ExtAccount struct { - Username string `"json:username"` - Password string `"json:password"` - Endpoint string `"json:endpoint"` - Followlimit int `"json:followlimit"` -} - -// Proxy - Configuration file proxy settings -type Proxy struct { - Host string `"json:host"` - Port int `"json:port"` - Username string `"json:username'` - Password string `"json:password"` -} - // Settings - Configuration file structure type Settings struct { - Crawl bool `"json:crawl"` - Proxies []Proxy `"json:proxies"` - Externalaccounts []ExtAccount `"json:externalaccounts"` - MassFollowers []MassFollower `"json:massfollowers"` - LogLevel int `"json:loglevel"` - Hostname string `"json:hostname"` + Crawl bool + LogLevel int + Hostname string } var settings Settings @@ -55,17 +24,8 @@ func stringexists(needle string, haystack []string) bool { } func getSettings() { - c, err := ioutil.ReadFile("config.jsonc") - if err != nil { - logFatal("Unable to open config.jsonc, exiting: ", err) - } - jsoncbin := jsonc.ToJSON(c) // Calling jsonc.ToJSON() to convert JSONC to JSON - if jsonc.Valid(jsoncbin) == false { - logFatal("Invalid jsonc, exiting.") - } - - err = json.Unmarshal(jsoncbin, &settings) - if err != nil { - logFatal("Unable to parse config.jsonc, exiting: ", err) - } + flag.BoolVar(&settings.Crawl, "c", true, "Crawl mode (default is yes)") + flag.StringVar(&settings.Hostname, "h", "myhostname", "Set your hostname") + flag.IntVar(&settings.LogLevel, "l", 1, "Logging Level:\n 0) No logs\n 1) Reports every 30 seconds\n 2) Errors\n 3) Warnings\n 4) New Connections\n 5) Debugging\n") + flag.Parse() } diff --git a/fedilogger/config.jsonc.sample b/fedilogger/config.jsonc.sample deleted file mode 100644 index 4e39c1d..0000000 --- a/fedilogger/config.jsonc.sample +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This is a jsonc file, NOT a json file. - * If you are using vim, I recommend this add-on: - * https://github.com/neoclide/jsonc.vim - */ -{ - // Should pollers automatically crawl - "crawl": true, - - /* - * Should pollers crawl .onion instances - * Requires a local tor proxy on 127.0.0.1:9050 - */ - "crawlonion": false, - - // Connect through the following proxies - "proxies": [ -// { -// "host": "127.0.0.1", -// "port": 9050, -// "username": "", -// "password": "" -// } - ], - - // External accounts to follow blindspots - "externalaccounts": [ - { - "username": "", - "password": "", - "endpoint": "", - "followlimit": 0 - } - ], - - /* - * Mass follower configurations - * All mass followers specified here will have their - * keys generated in the poll/keys directory - */ - "massfollowers": [ - { - "acct": "fedilogue@example.com", - "name": "Fedilogue Mass Follower", - "summary": "Profile description here", - "followingCount": 200, - "followlimit": -1 - }, - { - "acct": "fedilogue@example.xyz", - "name": "Fedilogue Mass Follower", - "summary": "Profile description here", - "followingCount": 200, - "followlimit": -1 - } - ], - - "hostname": "myhostname", - - /* - Log Level: - * 0 = No logs - * 1 = Reports every 30 seconds - * 2 = Errors - * 3 = Warnings - * 4 = New Connections - * 5 = Debugging - */ - "loglevel": 1 -} diff --git a/fedilogger/fedilogger.go b/fedilogger/fedilogger.go index 816cd44..9c3af89 100644 --- a/fedilogger/fedilogger.go +++ b/fedilogger/fedilogger.go @@ -73,11 +73,6 @@ func main() { runninginstances = make(map[string]shared.RunningInstance) getSettings() - if len(settings.Proxies) > 0 { - for i := 0; i < len(settings.Proxies); i++ { - logInfo("Using proxy: ", settings.Proxies[i].Host, ":", settings.Proxies[i].Port) - } - } go startpprof() pool = getDbPool() diff --git a/fedilogger/instance.go b/fedilogger/instance.go index 369cfbb..cb6a504 100644 --- a/fedilogger/instance.go +++ b/fedilogger/instance.go @@ -3,11 +3,8 @@ package main import ( "context" "encoding/json" - "fmt" - "math/rand" "net" "net/http" - "net/url" "time" "gitlab.com/khanzf/fedilogue/shared" @@ -47,17 +44,6 @@ func BuildClient(endpoint string) http.Client { } client := http.Client{Transport: tr} - if len(settings.Proxies) >= 1 { - rand.Seed(time.Now().Unix()) - ridx := rand.Intn(len(settings.Proxies)) - proxyuri := fmt.Sprintf("socks5://%s:%d", settings.Proxies[ridx].Host, settings.Proxies[ridx].Port) - proxy, err := url.Parse(proxyuri) - if err != nil { - logFatal("Error: ", err) - } - tr.Proxy = http.ProxyURL(proxy) - } - return client } @@ -152,6 +138,32 @@ func GetInstanceInfo(endpoint string, o shared.RunningInstance) shared.RunningIn } } + // Check for Lemmy (With Json) + lemmy_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.1" + req, _ = http.NewRequest("GET", lemmy_nodeinfo_uri, nil) + req.Header.Set("User-Agent", "Tusky") + + lemmy_api_resp, err := DoTries(&o, req) + if err != nil { + o.Software = "Unsupported" + return o + } else { + defer lemmy_api_resp.Body.Close() + } + + if lemmy_api_resp.StatusCode == 200 { + err = json.NewDecoder(lemmy_api_resp.Body).Decode(&nodeinfo) + if err == nil { + 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 + } + } + + // Unsupported Software o.Software = "Unsupported" o.Version = "Unknown" diff --git a/fedilogger/poll.go b/fedilogger/poll.go index 446dd31..29a0fea 100644 --- a/fedilogger/poll.go +++ b/fedilogger/poll.go @@ -57,30 +57,6 @@ func PollMastodonPleroma(endpoint string, o *shared.RunningInstance) { var client_id string var client_secret string var oauthData OAuth - var err error - - for _, extaccount := range settings.Externalaccounts { - if extaccount.Endpoint == endpoint { - use_auth = true - o, _ := GetRunner(endpoint) - if o.Banned == true { - return // banned endpoint - } - err = get_client(endpoint, &o) - if err != nil { - logErr("Unable to register client for "+endpoint+": ", err) - return - } - - oauthData, err = oauth_login(endpoint, &o, extaccount.Username, extaccount.Password) - if err != nil { - logErr("Unable to login to "+endpoint+": ", err) - return - } - last_refresh = time.Now().Unix() - - } - } for { ri_mutex.Lock() diff --git a/fedilogger/stream.go b/fedilogger/stream.go index 76c440f..14e67de 100644 --- a/fedilogger/stream.go +++ b/fedilogger/stream.go @@ -30,8 +30,6 @@ type MisskeyNoteBody struct { Id string `json:"id"` // Local note } -////////////////////////////// - type MisskeyRequest struct { Type string `json:"type"` Body MisskeyRequestBody `json:"body"` @@ -204,7 +202,6 @@ func StreamPleroma(endpoint string) { func StreamMastodon(endpoint string, o *shared.RunningInstance) { stream_client := BuildClient(endpoint) - var oauthData OAuth var retry bool api_timeline := "https://" + endpoint + "/api/v1/streaming/public" @@ -217,26 +214,6 @@ func StreamMastodon(endpoint string, o *shared.RunningInstance) { return } - for _, extaccount := range settings.Externalaccounts { - if extaccount.Endpoint == endpoint { - get_client(endpoint, o) - - err = get_client(endpoint, o) - if err != nil { - logWarn("Unable to register client: ", err) - } - - oauthData, err = oauth_login(endpoint, o, extaccount.Username, extaccount.Password) - if err != nil { - logWarn("Unable to login: ", err) - return - } - - req.Header.Add("Authorization", oauthData.Access_token) - - } - } - var resp *http.Response for tries := 0; tries < 10; tries++ {