From a81f3ef5cfe72b9edf345564fc31361650f15110 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Tue, 29 Jun 2021 14:04:13 -0700 Subject: added public instance tracking when instance is created --- README.md | 8 +++++ client.go | 2 ++ config-init | 4 ++- main.go | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ static/faq.html | 2 +- static/index.html | 14 +++++++++ static/ncatalog.html | 2 +- static/posts.html | 4 +-- 8 files changed, 119 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 721b836..5559a72 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ Any contributions or suggestions are appreciated. Best way to give immediate fee `dbpass:password` Database password for dbuser. `torproxy:127.0.0.1:9050` Tor proxy route and port, leave blank if you do not want to support + + `publicindex:true` Add instance to the public instance index at https://fchan.xyz if you do not want to be added set this value to `false` If you are on the public index and want to be removed get in contact with FChan dev to be removed. Currently e-mail is not implemented to do anything special, but the code is in place @@ -146,3 +148,9 @@ server { ### Docker `Please consider submitting a pull request if you set up a FChannel instance with Docker with instructions on how to do so` + +# Support + +Any support is appreciated all funds go to hosting and development of the project + +XMR - 85ma5KYR8Jk8zhGospQ8DeMNUrY74rQqEgiiPHvKHbowa37TAa5MLUD8RBaupw5oAxWmpFDrSAxsDbeXcfoAwiZF69mq4CE \ No newline at end of file diff --git a/client.go b/client.go index d91bbc7..97222d1 100644 --- a/client.go +++ b/client.go @@ -46,6 +46,7 @@ type PageData struct { Key string PostId string Instance Actor + InstanceIndex []ObjectBase } type AdminPage struct { @@ -88,6 +89,7 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { data.Board.Actor = actor data.Board.Post.Actor = actor.Id data.Board.Restricted = actor.Restricted + data.InstanceIndex = GetCollectionFromReq("https://fchan.xyz/followers").Items t.ExecuteTemplate(w, "layout", data) } diff --git a/config-init b/config-init index 6ca4aa9..c632102 100644 --- a/config-init +++ b/config-init @@ -15,4 +15,6 @@ emailport: emailaddress: emailpass: -torproxy: \ No newline at end of file +torproxy: + +publicindex:true \ No newline at end of file diff --git a/main.go b/main.go index 69bf337..59b1552 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,8 @@ var SiteEmailPort = GetConfigValue("emailport") //587 var TorProxy = GetConfigValue("torproxy") //127.0.0.1:9050 +var PublicIndexing = strings.ToLower(GetConfigValue("publicindex")) + var activitystreams = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" func main() { @@ -63,6 +65,9 @@ func main() { //name, prefname, summary, auth requirements, restricted if GetConfigValue("instancename") != "" { CreateNewBoardDB(db, *CreateNewActor("", GetConfigValue("instancename"), GetConfigValue("instancesummary"), authReq, false)) + if PublicIndexing == "true" { + AddInstanceToIndex(Domain) + } } // Allow access to public media folder @@ -1095,6 +1100,35 @@ func main() { }) + http.HandleFunc("/addtoindex", func(w http.ResponseWriter, r *http.Request) { + actor := r.URL.Query().Get("id") + + if Domain != "https://fchan.xyz" { + return + } + + if FingerActor(actor).Id != actor { + return + } + + followers := GetCollectionFromID("https://fchan.xyz/followers") + + var alreadyIndex = false + for _, e := range followers.Items { + if e.Id == actor { + alreadyIndex = true + } + } + + if !alreadyIndex { + query := `insert into follower (id, follower) values ($1, $2)` + + _, err := db.Exec(query, "https://fchan.xyz", actor) + + CheckError(err, "Error with add to index query") + } + }) + fmt.Println("Server for " + Domain + " running on port " + Port) fmt.Println("Mod key: " + *Key) @@ -2393,3 +2427,57 @@ func GetActorInstance(path string) (string, string) { return "", "" } + +func AddInstanceToIndex(actor string) { + + // if local testing enviroment do not add to index + re := regexp.MustCompile(`(.+)?(localhost|\d+\.\d+\.\d+\.\d+)(.+)?`) + if re.MatchString(actor) { + return + } + + followers := GetCollectionFromID("https://fchan.xyz/followers") + + var alreadyIndex = false + for _, e := range followers.Items { + if e.Id == actor { + alreadyIndex = true + } + } + + if !alreadyIndex { + req, err := http.NewRequest("GET", "https://fchan.xyz/addtoindex?id=" + actor, nil) + + CheckError(err, "error with add instance to actor index req") + + _, err = http.DefaultClient.Do(req) + + CheckError(err, "error with add instance to actor index resp") + } +} + +func GetCollectionFromReq(path string) Collection { + req, err := http.NewRequest("GET", path, nil) + + CheckError(err, "error with getting collection from req") + + req.Header.Set("Accept", activitystreams) + + resp, err := http.DefaultClient.Do(req) + + CheckError(err, "error getting resp from collection req") + + defer resp.Body.Close() + + body, _ := ioutil.ReadAll(resp.Body) + + var respCollection Collection + + err = json.Unmarshal(body, &respCollection) + + if err != nil { + panic(err) + } + + return respCollection +} diff --git a/static/faq.html b/static/faq.html index 2365c3e..c5f98d2 100644 --- a/static/faq.html +++ b/static/faq.html @@ -37,7 +37,7 @@

coming soon(tm).

Server Version

-

v0.0.3

+

v0.0.4

[Home][Rules][FAQ] diff --git a/static/index.html b/static/index.html index 1cd206b..502e527 100644 --- a/static/index.html +++ b/static/index.html @@ -21,6 +21,20 @@

{{ .Title }}

{{.Message}}

+ +
+ + Current known instances + + + {{ range .InstanceIndex }} + + + + {{ end }} +
+
{{ .Id }}
+
{{ end }} {{ define "bottom" }}{{ end }} diff --git a/static/ncatalog.html b/static/ncatalog.html index cbb3ae8..fc2dabf 100644 --- a/static/ncatalog.html +++ b/static/ncatalog.html @@ -52,7 +52,7 @@ media.style = "display: none;" } - if(isOnion("{{ .Id }}")) { + if(isOnion("{{ .Id }}") && !isOnion("{{ $board.Domain }}")) { sensitive = document.getElementById("sensitive-{{ .Id }}") document.getElementById("sensitive-img-{{ .Id }}").src = "/static/onion.png" document.getElementById("sensitive-text-{{ .Id }}").innerText = "Tor Instance" diff --git a/static/posts.html b/static/posts.html index cdefd14..f7ca3a7 100644 --- a/static/posts.html +++ b/static/posts.html @@ -32,7 +32,7 @@ media.style = "display: none;" } - if(isOnion("{{ .Id }}")) { + if(isOnion("{{ .Id }}") && !isOnion("{{ $board.Domain }}")) { sensitive = document.getElementById("sensitive-{{ .Id }}") document.getElementById("sensitive-img-{{ .Id }}").src = "/static/onion.png" document.getElementById("sensitive-text-{{ .Id }}").innerText = "Tor Instance" @@ -123,7 +123,7 @@ media.style = "display: none;" } - if(isOnion("{{ .Id }}")) { + if(isOnion("{{ .Id }}") && !isOnion("{{ $board.Domain }}") { sensitive = document.getElementById("sensitive-{{ .Id }}") document.getElementById("sensitive-img-{{ .Id }}").src = "/static/onion.png" document.getElementById("sensitive-text-{{ .Id }}").innerText = "Tor Instance" -- cgit v1.2.3