all repos — flounder @ a8444973aece69a635505a6f022743ce0bf84d68

A small site builder for the Gemini protocol

admin.go (view raw)

 1package main
 2
 3// Commands for administering your instance
 4// reset user password -> generate link
 5// delete user
 6
 7// Run some scripts to setup your instance
 8
 9import (
10	"fmt"
11	"io/ioutil"
12	"log"
13	"os"
14	"path"
15)
16
17// TODO improve cli
18func runAdminCommand() {
19	if len(os.Args) < 4 {
20		fmt.Println("expected subcommand with parameter")
21		os.Exit(1)
22	}
23	switch os.Args[2] {
24	case "activate-user":
25		username := os.Args[3]
26		activateUser(username)
27		// reset password
28		// delete user (with are you sure?)
29	}
30}
31
32func activateUser(username string) {
33	_, err := DB.Exec("UPDATE user SET active = true WHERE username = $1", username)
34	if err != nil {
35		log.Fatal(err)
36	}
37	log.Println("Activated user", username)
38	baseIndex := `# Welcome to Flounder!
39## About
40Welcome to an ultra-lightweight platform for making and sharing small websites. You can get started by editing this page -- remove this content and replace it with whatever you like! It will be live at <your-name>.flounder.online. You can go there right now to see what this page currently looks like. Here is a link to a page which will give you more information about using flounder:
41=> //admin.flounder.online
42
43And here's a guide to the text format that Flounder uses to create pages, Gemini. These pages are converted into HTML so they can be displayed in a web browser.
44=> //admin.flounder.online/gemini_text_guide.gmi
45
46Have fun!`
47	os.Mkdir(path.Join(c.FilesDirectory, username), os.ModePerm)
48	ioutil.WriteFile(path.Join(c.FilesDirectory, username, "index.gmi"), []byte(baseIndex), 0644)
49	os.Mkdir(path.Join(c.FilesDirectory, username), os.ModePerm)
50}