formatting and linting

This commit is contained in:
farhan 2020-12-17 04:23:25 +00:00
parent 8d56747f1c
commit 726ac7e0bd
11 changed files with 232 additions and 231 deletions

View File

@ -1,56 +1,61 @@
package main
import (
"io/ioutil"
"encoding/json"
"muzzammil.xyz/jsonc"
"io/ioutil"
"log"
"muzzammil.xyz/jsonc"
)
// Database - Database configuration used by config.go
type Database struct {
Host string `"json:host"`
Port int `"json:port"`
Username string `"json:username"`
Password string `"json:password"`
Workers int `"json:workers"`
Host string `"json:host"`
Port int `"json:port"`
Username string `"json:username"`
Password string `"json:password"`
Workers int `"json:workers"`
}
// 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"`
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"`
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"`
Host string `"json:host"`
Port int `"json:port"`
Username string `"json:username'`
Password string `"json:password"`
}
// Settings - Configuration file structure
type Settings struct {
Autostart []string `"json:autostart"`
Crawl bool `"json:crawl"`
Banned []string `"json:banned"`
Alwaysbot []string `"json:alwaysbot"`
Proxies []Proxy `"json:proxies"`
Externalaccounts []ExtAccount `"json:externalaccounts"`
MassFollowers []MassFollower `"json:massfollowers"`
Database Database `"json:database"`
Autostart []string `"json:autostart"`
Crawl bool `"json:crawl"`
Banned []string `"json:banned"`
Alwaysbot []string `"json:alwaysbot"`
Proxies []Proxy `"json:proxies"`
Externalaccounts []ExtAccount `"json:externalaccounts"`
MassFollowers []MassFollower `"json:massfollowers"`
Database Database `"json:database"`
}
var settings Settings
func StringExists(needle string, haystack []string) (bool) {
func stringexists(needle string, haystack []string) bool {
for _, check := range haystack {
if check == needle {
return true
@ -61,7 +66,7 @@ func StringExists(needle string, haystack []string) (bool) {
func getSettings() {
c, err := ioutil.ReadFile("config.jsonc")
if (err != nil) {
if err != nil {
log.Fatal("Unable to open config.jsonc, exiting: ", err)
}
jsoncbin := jsonc.ToJSON(c) // Calling jsonc.ToJSON() to convert JSONC to JSON

7
ctl.go
View File

@ -4,9 +4,9 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"net"
"log"
"io"
"log"
"net"
"os"
)
@ -31,7 +31,7 @@ func startctl(reportPostChan chan ReportPost) {
}(l)
for {
c := <-commandClient // New client connection
c := <-commandClient // New client connection
go handleClient(c, reportPostChan)
}
@ -90,7 +90,6 @@ func handleClient(commandClient net.Conn, reportPostChan chan ReportPost) {
fmt.Println("Something else")
}
responseback.Type = "status"
responseback.RunningInstances = runninginstances

10
db.go
View File

@ -1,10 +1,10 @@
package main
import (
"github.com/jackc/pgx/pgxpool"
"context"
"log"
"fmt"
"github.com/jackc/pgx/pgxpool"
"log"
)
func postHandler(reportPostChan chan ReportPost, pool *pgxpool.Pool) {
@ -57,10 +57,10 @@ func writePost(pool *pgxpool.Pool, reportpost ReportPost) {
}
}
func get_db_pool() (*pgxpool.Pool) {
func getDbPool() *pgxpool.Pool {
// Setup Database
db_uri := fmt.Sprintf("postgres://%s:%s@%s:%d/fedilogue", settings.Database.Username, settings.Database.Password, settings.Database.Host, settings.Database.Port)
pool, err := pgxpool.Connect(context.Background(), db_uri)
dbURI := fmt.Sprintf("postgres://%s:%s@%s:%d/fedilogue", settings.Database.Username, settings.Database.Password, settings.Database.Host, settings.Database.Port)
pool, err := pgxpool.Connect(context.Background(), dbURI)
if err != nil {
log.Fatal("Unable to connect to database:", err)
}

View File

@ -5,9 +5,9 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"net"
"os"
"io"
)
func main() {

View File

@ -1,13 +1,13 @@
package main
import (
_ "net/http/pprof"
"net/http"
"sync"
"regexp"
"log"
"github.com/microcosm-cc/bluemonday"
"log"
"net/http"
_ "net/http/pprof"
"regexp"
"runtime"
"sync"
)
// Current instances
@ -27,7 +27,7 @@ func main() {
getSettings()
go startpprof()
pool := get_db_pool()
pool := getDbPool()
for i := 0; i < settings.Database.Workers; i++ {
go postHandler(reportPostChan, pool)

View File

@ -5,89 +5,88 @@ import (
)
const (
NEW_INSTANCE = 0
RUNNING = 200
UNAUTHORIZED = 401
FORBIDDEN = 403
NOT_FOUND = 404
UNPROCESSABLE_ENTITY = 422
TOOMANYREQUESTS = 429
INTERNAL_ERROR = 500
CLIENT_ISSUE = 600
ONION_PROTOCOL = 601
BAD_RESPONSE = 602
BAD_NODEINFO = 604
UNSUPPORTED_INSTANCE = 605
STREAM_ENDED = 606
KEEPALIVE = 607
NEW_INSTANCE = 0
RUNNING = 200
UNAUTHORIZED = 401
FORBIDDEN = 403
NOT_FOUND = 404
UNPROCESSABLE_ENTITY = 422
TOOMANYREQUESTS = 429
INTERNAL_ERROR = 500
CLIENT_ISSUE = 600
ONION_PROTOCOL = 601
BAD_RESPONSE = 602
BAD_NODEINFO = 604
UNSUPPORTED_INSTANCE = 605
STREAM_ENDED = 606
KEEPALIVE = 607
)
// Parsing Unmarshal JSON type
type ReportPost struct {
// Retrieved values
Id string `json:"id"`
Uri string `json:"uri"`
Account AccountType
Content string `json:"content"`
Created_at string `json:"created_at"`
Id string `json:"id"`
Uri string `json:"uri"`
Account AccountType
Content string `json:"content"`
Created_at string `json:"created_at"`
// Derived values
normalized string
posthash []byte
normalized string
posthash []byte
}
type AccountType struct {
Acct string `json:"acct"`
Avatar string `json:"avatar"`
Bot bool `json:"bot"`
Created_at string `json:"created_at"`
Display_name string `json:"display_name"`
Url string `json:"url"`
Acct string `json:"acct"`
Avatar string `json:"avatar"`
Bot bool `json:"bot"`
Created_at string `json:"created_at"`
Display_name string `json:"display_name"`
Url string `json:"url"`
}
// Instance's new min_id value
type RunningInstance struct {
Software string `json:"software"`
Status int `json:"status"`
LastRun string `json:"lastrun"`
CaptureType string `json:"capturetype"`
client http.Client
Software string `json:"software"`
Status int `json:"status"`
LastRun string `json:"lastrun"`
CaptureType string `json:"capturetype"`
client http.Client
}
type NodeInfoSoftware struct {
Name string `json:"name"`
Version string `json:"version"`
Name string `json:"name"`
Version string `json:"version"`
}
type NodeInfo struct {
Software NodeInfoSoftware `json:"software"`
Software NodeInfoSoftware `json:"software"`
}
type CommandMap struct {
Type string `json:"Type"`
Endpoint string `json:"Endpoint"`
Type string `json:"Type"`
Endpoint string `json:"Endpoint"`
}
type ResponseBack struct {
Type string `json:"Type"`
Message string `json:"Message"`
RunningInstances map[string]RunningInstance `json:"RunningInstances"`
Type string `json:"Type"`
Message string `json:"Message"`
RunningInstances map[string]RunningInstance `json:"RunningInstances"`
}
type Userinfo struct {
Id string `"json:id"`
Type string `"json:type"`
Following string `"json:following"`
Followers string `"json:followers"`
Inbox string `"json:inbox"`
Outbox string `"json:outbox"`
Featured string `"json:featured"`
PreferredUsername string `"json:preferredUsername"`
Name string `"json:name"`
Summary string `"json:summary"`
Url string `"json:Url"`
ManuallyApprovesFollowers string `"json:manuallyApprovesFollowers"`
Discoverable string `"json:discoverable"`
Id string `"json:id"`
Type string `"json:type"`
Following string `"json:following"`
Followers string `"json:followers"`
Inbox string `"json:inbox"`
Outbox string `"json:outbox"`
Featured string `"json:featured"`
PreferredUsername string `"json:preferredUsername"`
Name string `"json:name"`
Summary string `"json:summary"`
Url string `"json:Url"`
ManuallyApprovesFollowers string `"json:manuallyApprovesFollowers"`
Discoverable string `"json:discoverable"`
}

View File

@ -1,14 +1,14 @@
package main
import (
"github.com/microcosm-cc/bluemonday"
"encoding/json"
"github.com/microcosm-cc/bluemonday"
"io/ioutil"
"net/http"
"strings"
"regexp"
"time"
"log"
"net/http"
"regexp"
"strings"
"time"
)
var p *bluemonday.Policy
@ -19,7 +19,7 @@ func GetNodeInfo(endpoint string) (http.Client, NodeInfo) {
/* Checking order
* Mastodon/Pleroma
* Um..nothing else yet
*/
*/
pleromastodon_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.0.json"
http_client := http.Client{}
pleromastodon_api_resp, err := http_client.Get(pleromastodon_nodeinfo_uri)

View File

@ -1,25 +1,25 @@
package main
import (
"net/http"
"encoding/json"
"bytes"
"bufio"
"log"
"io/ioutil"
"bytes"
"encoding/json"
"io"
"io/ioutil"
"log"
"net/http"
"os"
)
type OAuth struct {
Access_token string `"json:access_token"`
Created_at int `"json:created_at"`
Expires_in int64 `"json:Expires_in"`
Refresh_token string `"json:refresh_token"`
Access_token string `"json:access_token"`
Created_at int `"json:created_at"`
Expires_in int64 `"json:Expires_in"`
Refresh_token string `"json:refresh_token"`
}
type authError struct {
msg string
msg string
}
func (e *authError) Error() string {
@ -38,7 +38,7 @@ func register_client(endpoint string, http_client *http.Client) (string, string,
resp, err := http_client.Post(api_base_apps, "application/json", requestBodybytes)
if err != nil {
log.Fatal("Unable to connect to " + api_base_apps + " ", err)
log.Fatal("Unable to connect to "+api_base_apps+" ", err)
}
body, err := ioutil.ReadAll(resp.Body)
@ -59,17 +59,17 @@ func register_client(endpoint string, http_client *http.Client) (string, string,
f, err := os.Create("clients/" + endpoint)
if err != nil {
log.Print("Unable to create " + client_file + ": ", err)
log.Print("Unable to create "+client_file+": ", err)
return bodymap["client_id"], bodymap["client_secret"], nil
}
defer f.Close()
_, err = io.WriteString(f, bodymap["client_id"] + "\n")
_, err = io.WriteString(f, bodymap["client_id"]+"\n")
if err != nil {
log.Print("Unable to write client_id line: ", err)
return bodymap["client_id"], bodymap["client_secret"], nil
}
_, err = io.WriteString(f, bodymap["client_secret"] + "\n")
_, err = io.WriteString(f, bodymap["client_secret"]+"\n")
if err != nil {
log.Print("Unable to write client_secret line: ", err)
return bodymap["client_id"], bodymap["client_secret"], nil
@ -110,13 +110,13 @@ func get_client(endpoint string, http_client *http.Client) (string, string, erro
func oauth_login(endpoint string, username string, password string, client_id string, client_secret string) (OAuth, error) {
authMap, err := json.Marshal(map[string]string{
"username": username,
"password": password,
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
"grant_type": "password",
"client_name": "Tusky",
"scope": "read write follow push",
"client_id": client_id,
"username": username,
"password": password,
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
"grant_type": "password",
"client_name": "Tusky",
"scope": "read write follow push",
"client_id": client_id,
"client_secret": client_secret,
})
@ -127,9 +127,9 @@ func oauth_login(endpoint string, username string, password string, client_id st
authMapbytes := bytes.NewBuffer(authMap)
resp, err := http.Post("https://" + endpoint + "/oauth/token", "application/json", authMapbytes)
resp, err := http.Post("https://"+endpoint+"/oauth/token", "application/json", authMapbytes)
if err != nil {
log.Print("Cannot connect to " + endpoint + ": ", err)
log.Print("Cannot connect to "+endpoint+": ", err)
return OAuth{}, err
}
@ -157,19 +157,19 @@ func oauth_login(endpoint string, username string, password string, client_id st
func oauth_refresh(endpoint string, client_id string, client_secret string, refresh_token string) (OAuth, error) {
authMap, err := json.Marshal(map[string]string{
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
"grant_type": "refresh_token",
"scope": "read write follow push",
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
"grant_type": "refresh_token",
"scope": "read write follow push",
"refresh_token": refresh_token,
"client_id": client_id,
"client_id": client_id,
"client_secret": client_secret,
})
authMapbytes := bytes.NewBuffer(authMap)
resp, err := http.Post("https://" + endpoint + "/oauth/token", "application/json", authMapbytes)
resp, err := http.Post("https://"+endpoint+"/oauth/token", "application/json", authMapbytes)
if err != nil {
log.Print("Cannot connect to " + endpoint + ": ", err)
log.Print("Cannot connect to "+endpoint+": ", err)
return OAuth{}, err
}

74
poll.go
View File

@ -1,59 +1,58 @@
package main
import (
"encoding/json"
"crypto/sha1"
"encoding/json"
"fmt"
"html"
"io/ioutil"
"log"
"net/http"
"strings"
"html"
"time"
"fmt"
"log"
)
type ImageData struct {
Type string `"json:type"`
Url string `"json:url"`
Type string `"json:type"`
Url string `"json:url"`
}
type PublicKeyData struct {
Id string `"json:id"`
Owner string `"json:owner"`
PublicKeyPem string `"json:publicKeyPem"`
Id string `"json:id"`
Owner string `"json:owner"`
PublicKeyPem string `"json:publicKeyPem"`
}
type UserInfo struct {
Id string `"json:id"`
Type string `"json:type"`
Following string `"json:following"`
Followers string `"json:followers"`
Inbox string `"json:inbox"`
Outbox string `"json:outbox"`
Featured string `"json:featured"`
PreferredUsername string `"json:preferredUsername"`
PublicKey PublicKeyData `"json:publicKeyPem"`
Name string `"json:name"`
Summary string `"json:summary"`
Url string `"json:Url"`
Id string `"json:id"`
Type string `"json:type"`
Following string `"json:following"`
Followers string `"json:followers"`
Inbox string `"json:inbox"`
Outbox string `"json:outbox"`
Featured string `"json:featured"`
PreferredUsername string `"json:preferredUsername"`
PublicKey PublicKeyData `"json:publicKeyPem"`
Name string `"json:name"`
Summary string `"json:summary"`
Url string `"json:Url"`
// ManuallyApprovesFollowers string `"json:manuallyApprovesFollowers"`
// Discoverable bool `"json:discoverable"`
// ManuallyApprovesFollowers string `"json:manuallyApprovesFollowers"`
// Discoverable bool `"json:discoverable"`
}
type PostInfo struct {
Id string `"json:id"`
Type string `"json:type"`
Published string `"json:published"`
Url string `"json:Url"`
Content string `"json:content"`
Id string `"json:id"`
Type string `"json:type"`
Published string `"json:published"`
Url string `"json:Url"`
Content string `"json:content"`
}
func fetch_user_info(http_client http.Client, uri string) (UserInfo, error) {
var userinfo UserInfo
// http_client := http.Client{}
// http_client := http.Client{}
req, err := http.NewRequest(http.MethodGet, uri, nil)
if err != nil {
return UserInfo{}, err
@ -75,7 +74,6 @@ func fetch_user_info(http_client http.Client, uri string) (UserInfo, error) {
return userinfo, nil
}
func fetch_post(http_client http.Client, uri string) (PostInfo, error) {
var postinfo PostInfo
@ -118,7 +116,7 @@ func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_c
for _, extaccount := range settings.Externalaccounts {
if extaccount.Endpoint == endpoint {
use_auth = true
client_id, client_secret, err = get_client(endpoint, &http_client);
client_id, client_secret, err = get_client(endpoint, &http_client)
if err != nil {
log.Fatal("Unable to register client: ", err)
}
@ -146,7 +144,7 @@ func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_c
}
if use_auth == true {
if time.Now().Unix() > last_refresh + oauthData.Expires_in {
if time.Now().Unix() > last_refresh+oauthData.Expires_in {
oauthData, err = oauth_refresh(endpoint, client_id, client_secret, oauthData.Refresh_token)
if err != nil {
log.Print("Unable to refresh: ", err)
@ -169,7 +167,7 @@ func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_c
}
if resp.StatusCode == TOOMANYREQUESTS { // Short Delay, 30 seconds
log.Print("Delaying " + endpoint + ", gave status ", resp.StatusCode, ", 1 hour delay")
log.Print("Delaying "+endpoint+", gave status ", resp.StatusCode, ", 1 hour delay")
_, _ = ioutil.ReadAll(resp.Body)
resp.Body.Close() // Release as soon as done
m.Status = resp.StatusCode
@ -183,7 +181,7 @@ func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_c
time.Sleep(time.Second * 30)
continue
} else if resp.StatusCode == INTERNAL_ERROR { // Longer delay, 1 hour
log.Print("Suspending " + endpoint + ", gave status ", resp.StatusCode, ", 1 hour delay")
log.Print("Suspending "+endpoint+", gave status ", resp.StatusCode, ", 1 hour delay")
_, _ = ioutil.ReadAll(resp.Body)
resp.Body.Close() // Release as soon as done
m.Status = 765
@ -193,7 +191,7 @@ func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_c
time.Sleep(time.Second * 3600)
continue
} else if resp.StatusCode != 200 { // Crash
log.Print("Terminating " + endpoint + ", gave status ", resp.StatusCode)
log.Print("Terminating "+endpoint+", gave status ", resp.StatusCode)
_, _ = ioutil.ReadAll(resp.Body)
resp.Body.Close() // Release as soon as done
m.Status = resp.StatusCode
@ -303,14 +301,14 @@ func PollMastodonPleroma(endpoint string, reportPostChan chan ReportPost, http_c
}
// Only done if we are crawling
if settings.Crawl == true && StringExists(endpoint, settings.Banned) == false {
if settings.Crawl == true && stringexists(endpoint, settings.Banned) == false {
// 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 {
if exists == false || o.Status == KEEPALIVE {
m := RunningInstance{}
runninginstances[newinstance] = m
go StartInstance(newinstance, reportPostChan)

View File

@ -1,15 +1,15 @@
package main
import (
"net/http"
"encoding/json"
"crypto/sha1"
"strings"
"bufio"
"time"
"crypto/sha1"
"encoding/json"
"fmt"
"html"
"log"
"fmt"
"net/http"
"strings"
"time"
)
func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
@ -29,10 +29,10 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
for _, extaccount := range settings.Externalaccounts {
if extaccount.Endpoint == endpoint {
// use_auth = true
// use_auth = true
get_client(endpoint, &http_client)
client_id, client_secret, err = get_client(endpoint, &http_client);
client_id, client_secret, err = get_client(endpoint, &http_client)
if err != nil {
log.Fatal("Unable to register client: ", err)
}
@ -43,10 +43,9 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
return
}
// This needs to updated with the time
// last_refresh := time.Now().Unix()
// last_refresh := time.Now().Unix()
_ = time.Now().Unix()
req.Header.Add("Authorization", oauthData.Access_token)
}
@ -168,16 +167,16 @@ func StreamMastodon(endpoint string, reportPostChan chan ReportPost) {
// Reporting post
reportPostChan <- newpost
if settings.Crawl == true && StringExists(endpoint, settings.Banned) == false {
ri_mutex.Lock()
o, exists := runninginstances[newinstance]
if exists == false || o.Status == KEEPALIVE {
m := RunningInstance{}
runninginstances[newinstance] = m
go StartInstance(newinstance, reportPostChan)
}
if settings.Crawl == true && stringexists(endpoint, settings.Banned) == false {
ri_mutex.Lock()
o, exists := runninginstances[newinstance]
if exists == false || o.Status == KEEPALIVE {
m := RunningInstance{}
runninginstances[newinstance] = m
go StartInstance(newinstance, reportPostChan)
}
ri_mutex.Unlock()
ri_mutex.Unlock()
}
}

77
web.go
View File

@ -1,35 +1,37 @@
package main
import (
"crypto/sha1"
"encoding/json"
"fmt"
"html"
"io/ioutil"
"log"
"net/http"
"encoding/json"
"io/ioutil"
"html"
"time"
"strings"
"crypto/sha1"
"os"
"strings"
"time"
)
// CreateObject - Used by post web receiver
type CreateObject struct {
Actor string `json:"actor"`
Cc []string `json:"cc"`
Content string `json:"content"`
To []string `json:"to"`
Type string `json:"type"`
Actor string `json:"actor"`
Cc []string `json:"cc"`
Content string `json:"content"`
To []string `json:"to"`
Type string `json:"type"`
}
// CreateObject - Used by post web receiver
type FindType struct {
Actor string `json:"actor"`
Cc []string `json:"cc"`
Actor string `json:"actor"`
Cc []string `json:"cc"`
//Object interface{} `json:"Object"`
Object json.RawMessage `json:"Object"`
Id string `json:"id"`
Published string `json:"published"`
To []string `json:"to"`
Type string `json:"type"`
Object json.RawMessage `json:"Object"`
ID string `json:"id"`
Published string `json:"published"`
To []string `json:"to"`
Type string `json:"type"`
}
func hostmeta(w http.ResponseWriter, r *http.Request) {
@ -79,7 +81,7 @@ func webfinger(w http.ResponseWriter, r *http.Request) {
if exists {
resource := resourceRaw[0]
if resource != "acct:fedilogue@" + host {
if resource != "acct:fedilogue@"+host {
fmt.Println("Writes properly but wrong acct")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, webfingerstr)
@ -98,7 +100,6 @@ func webfinger(w http.ResponseWriter, r *http.Request) {
func inboxHandler(reportPostChan chan ReportPost) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fmt.Println("PATH --> ", r.URL.Path)
body, err := ioutil.ReadAll(r.Body)
@ -122,19 +123,19 @@ func inboxHandler(reportPostChan chan ReportPost) http.HandlerFunc {
return
}
newpost.Uri = findtype.Id
newpost.Uri = findtype.ID
start_slashes := strings.Index(createobject.Actor, "//") + 2
end_slashes := strings.Index(createobject.Actor[start_slashes:], "/")
newinstance := createobject.Actor[start_slashes:start_slashes+end_slashes]
startSlashes := strings.Index(createobject.Actor, "//") + 2
endSlashes := strings.Index(createobject.Actor[startSlashes:], "/")
newinstance := createobject.Actor[startSlashes : startSlashes+endSlashes]
// For now we are just verifying the user
ri_mutex.Lock()
o, exist := runninginstances[newinstance]
if exist == false {
o := RunningInstance{}
new_client := http.Client{}
o.client = new_client
newClient := http.Client{}
o.client = newClient
o.Status = KEEPALIVE
runninginstances[newinstance] = o
}
@ -176,12 +177,12 @@ func inboxHandler(reportPostChan chan ReportPost) http.HandlerFunc {
}
}
func users_fedilogue_followers(w http.ResponseWriter, r *http.Request) {
func usersFedilogueFollowers(w http.ResponseWriter, r *http.Request) {
fmt.Println("PATH --> ", r.URL.Path)
host := r.Host
contextlist := map[string]string {"@language":"und"}
contextlist := map[string]string{"@language": "und"}
context := []interface{} {"https://www.w3.org/ns/activitystreams", "https://" + host + "/schemas/litepub-0.1.jsonld", contextlist}
context := []interface{}{"https://www.w3.org/ns/activitystreams", "https://" + host + "/schemas/litepub-0.1.jsonld", contextlist}
followersmap := make(map[string]interface{})
followersmap["@context"] = context
@ -192,7 +193,7 @@ func users_fedilogue_followers(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, staticjson)
}
func users_fedilogue_following(w http.ResponseWriter, r *http.Request) {
func usersFedilogueFollowing(w http.ResponseWriter, r *http.Request) {
host := r.Host
fmt.Println("PATH --> ", r.URL.Path)
staticjson := "{\"@context\": [\"https://www.w3.org/ns/activitystreams\", \"https://" + host + "/schemas/litepub-0.1.jsonld\", {\"@language\": \"und\"}], \"first\": {\"id\": \"https://" + host + "/users/fedilogue/following?page=1\", \"orderedItems\": [], \"partOf\": \"https://" + host + "/users/fedilogue/following\", \"totalItems\": 0, \"type\": \"OrderedCollectionPage\"}, \"id\": \"https://" + host + "/users/fedilogue/following\", \"totalItems\": 0, \"type\": \"OrderedCollection\"}"
@ -200,7 +201,7 @@ func users_fedilogue_following(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, staticjson)
}
func users_fedilogue(w http.ResponseWriter, r *http.Request) {
func usersFedilogue(w http.ResponseWriter, r *http.Request) {
fmt.Println("PATH --> ", r.URL.Path)
host := r.Host
@ -215,15 +216,15 @@ func users_fedilogue(w http.ResponseWriter, r *http.Request) {
publickeypemstr := string(publickeybin)
publicKey := map[string]string {"id":"https://" + host + "/users/fedilogue#main-key", "owner": "https://" + host + "/users/fedilogue", "publicKeyPem": publickeypemstr}
publicKey := map[string]string{"id": "https://" + host + "/users/fedilogue#main-key", "owner": "https://" + host + "/users/fedilogue", "publicKeyPem": publickeypemstr}
capabilities := map[string]bool{}
tag := []string{}
contextlist := map[string]string {"@language":"und"}
contextlist := map[string]string{"@language": "und"}
attachment := []string{}
endpoints := map[string]string {"oauthAuthorizationEndpoint":"https://" + host+ "/oauth/authorize", "oauthRegistrationEndpoint": "https://" + host + "/api/v1/apps", "oauthTokenEndpoint": "https://" + host + "/oauth/token", "sharedInbox": "https://" + host + "/inbox", "uploadMedia": "https://" + host + "/api/ap/upload_media"}
endpoints := map[string]string{"oauthAuthorizationEndpoint": "https://" + host + "/oauth/authorize", "oauthRegistrationEndpoint": "https://" + host + "/api/v1/apps", "oauthTokenEndpoint": "https://" + host + "/oauth/token", "sharedInbox": "https://" + host + "/inbox", "uploadMedia": "https://" + host + "/api/ap/upload_media"}
context := []interface{} {"https://www.w3.org/ns/activitystreams", "https://" + host + "/schemas/litepub-0.1.jsonld", contextlist}
context := []interface{}{"https://www.w3.org/ns/activitystreams", "https://" + host + "/schemas/litepub-0.1.jsonld", contextlist}
userjsonmap := make(map[string]interface{})
userjsonmap["@context"] = context
userjsonmap["attachment"] = attachment
@ -263,9 +264,9 @@ func webmain(reportPostChan chan ReportPost) {
http.HandleFunc("/.well-known/webfinger", webfinger)
http.HandleFunc("/.well-known/host-meta", hostmeta)
http.HandleFunc("/inbox", inboxHandler(reportPostChan))
http.HandleFunc("/users/fedilogue", users_fedilogue)
http.HandleFunc("/users/fedilogue/followers", users_fedilogue_followers)
http.HandleFunc("/users/fedilogue/following", users_fedilogue_following)
http.HandleFunc("/users/fedilogue", usersFedilogue)
http.HandleFunc("/users/fedilogue/followers", usersFedilogueFollowers)
http.HandleFunc("/users/fedilogue/following", usersFedilogueFollowing)
http.HandleFunc("/", errorHandler)
log.Print("Starting HTTP inbox on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))