aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2021-06-29 14:04:13 -0700
committerFChannel <>2021-06-29 14:04:13 -0700
commita81f3ef5cfe72b9edf345564fc31361650f15110 (patch)
tree862ff930b44c62435c375f10cf54afb4053a6d02
parent9b67a65d76eb98a6e405b677a20c6215e1271753 (diff)
added public instance tracking when instance is created
-rw-r--r--README.md8
-rw-r--r--client.go2
-rw-r--r--config-init4
-rw-r--r--main.go88
-rw-r--r--static/faq.html2
-rw-r--r--static/index.html14
-rw-r--r--static/ncatalog.html2
-rw-r--r--static/posts.html4
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 @@
<p>coming soon(tm).</p>
<h4>Server Version</h4>
- <p>v0.0.3</p>
+ <p>v0.0.4</p>
</div>
<div style="width: 500px; margin:0 auto; margin-top: 50px; text-align: center;">
<a href="/">[Home]</a><a href="/static/rules.html">[Rules]</a><a href="/static/faq.html">[FAQ]</a>
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 @@
<div style="text-align: center; max-width: 800px; margin: 0 auto;">
<h1>{{ .Title }}</h1>
<p style="text-align: justify">{{.Message}}</p>
+
+ <div style="margin-top:50px;">
+ <table align="center" style="text-align: left;">
+ <th>
+ <tr>Current known instances</tr>
+ </th>
+
+ {{ range .InstanceIndex }}
+ <tr>
+ <td>{{ .Id }}</td>
+ </tr>
+ {{ end }}
+ </table>
+ </div>
</div>
{{ 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"