all repos — honk @ 3762e5454acd3062b5c5d67e658143ac5f8be51e

my fork of honk

u
Anirudh Oppiliappan x@icyphox.sh
Wed, 15 Mar 2023 00:07:11 +0530
commit

3762e5454acd3062b5c5d67e658143ac5f8be51e

parent

c8a4ee4a52ec60147b2bac86ccca38020ba5bc5f

3 files changed, 36 insertions(+), 4 deletions(-)

jump to
M database.godatabase.go

@@ -1134,6 +1134,7 @@ var stmtDeliquentCheck, stmtDeliquentUpdate *sql.Stmt

var stmtGetUserCount *sql.Stmt var stmtGetActiveUserCount *sql.Stmt var stmtGetLocalHonkCount *sql.Stmt +var stmtSaveMastoApp *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)

@@ -1222,4 +1223,9 @@ stmtLoadChonks = preparetodie(db, "select chonkid, userid, xid, who, target, dt, noise, format from chonks where userid = ? and dt > ? order by chonkid asc")

stmtGetChatters = preparetodie(db, "select distinct(target) from chonks where userid = ?") stmtDeliquentCheck = preparetodie(db, "select dooverid, msg from doovers where userid = ? and rcpt = ?") stmtDeliquentUpdate = preparetodie(db, "update doovers set msg = ? where dooverid = ?") + stmtGetUserCount = preparetodie(db, "select count(*) from users where userid > 0") + stmtGetActiveUserCount = preparetodie(db, "select count(distinct honker) from honks where whofore = 2 and dt > ?") + stmtGetLocalHonkCount = preparetodie(db, "select count(*) from honks where whofore = 2") + + stmtSaveMastoApp = preparetodie(db, "insert into masto (clientname, redirecturis, scopes, clientid, clientsecret, vapidkey) values (?, ?, ?, ?, ?, ?)") }
M masto.gomasto.go

@@ -1,6 +1,7 @@

package main import ( + "crypto/rand" "fmt" "net/http"

@@ -15,15 +16,39 @@

// https://docs.joinmastodon.org/methods/apps/#create func apiapps(rw http.ResponseWriter, r *http.Request) { if err := r.ParseForm(); err != nil { - http.Error(rw, "invalid input", http.StatusBadRequest) + http.Error(rw, "invalid input", http.StatusUnprocessableEntity) return } clientName := r.Form.Get("client_name") - redirectUris := r.Form.Get("redirect_uris") + redirectUri := r.Form.Get("redirect_uris") scopes := r.Form.Get("scopes") - web := r.Form.Get("website") + clientID := tokengen() + clientSecret := tokengen() + vapidKey := tokengen() + + _, err := stmtSaveMastoApp.Exec(clientName, redirectUri, scopes, clientID, clientSecret, vapidKey) + if err != nil { + elog.Printf("error saving masto app: %v", err) + http.Error(rw, "error saving masto app", http.StatusUnprocessableEntity) + return + } + + j := junk.New() + j["id"] = 1 + j["name"] = clientName + j["redirect_uri"] = redirectUri + j["client_id"] = clientID + j["client_secret"] = clientSecret + j["vapid_key"] = vapidKey - dlog.Println(clientName, redirectUris, scopes, web) + rw.WriteHeader(http.StatusOK) + j.Write(rw) +} + +func tokengen() string { + b := make([]byte, 64) + rand.Read(b) + return fmt.Sprintf("%x", b) } // https://docs.joinmastodon.org/methods/oauth/#authorize
M schema.sqlschema.sql

@@ -11,6 +11,7 @@ create table onts (ontology text, honkid integer);

create table honkmeta (honkid integer, genus text, json text); create table hfcs (hfcsid integer primary key, userid integer, json text); create table tracks (xid text, fetches text); +create table masto (clientname text, redirecturis text, scopes text); create index idx_honksxid on honks(xid); create index idx_honksconvoy on honks(convoy);