Nuestro burocrata preferido: Sam Lowry https://lowry.sindominio.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
lowry/main.go

84 lines
1.9 KiB

package main
import (
"bufio"
"log"
"os"
"sort"
"strings"
"time"
"0xacab.org/sindominio/lowry/db"
"0xacab.org/sindominio/lowry/ldap"
"0xacab.org/sindominio/lowry/server"
"github.com/namsral/flag"
)
var (
inviteExpireDuration = time.Hour * 24 * 30
)
func main() {
var (
ldapaddr = flag.String("ldapaddr", "localhost:389", "LDAP server address and port")
domain = flag.String("domain", "", "LDAP domain components")
ldappass = flag.String("ldappass", "", "Password of the LDAP `admin' user")
homepath = flag.String("homepath", "/home/", "Path to the user homes")
httpaddr = flag.String("httpaddr", ":8080", "Web server address and port")
dbpath = flag.String("dbpath", "bolt.db", "The path to store the lowry status database")
ro = flag.Bool("ro", false, "Read-Only mode")
askRolePath = flag.String("ask-role-list", "", "List of usernames to ask if want to be sindominantes")
)
flag.String(flag.DefaultConfigFlagname, "/etc/lowry.conf", "Path to configuration file")
flag.Parse()
l := ldap.Ldap{
Addr: *ldapaddr,
Domain: *domain,
Pass: *ldappass,
HomePath: *homepath,
RO: *ro,
}
err := l.Init()
if err != nil {
log.Fatal(err)
}
ldb, err := db.Init(*dbpath)
if err != nil {
log.Fatal(err)
}
defer ldb.Close()
go cleanInvites(ldb)
usersAskRole := []string{}
if *askRolePath != "" {
usersAskRole = readUserList(*askRolePath)
}
log.Fatal(server.Serve(*httpaddr, &l, ldb, usersAskRole))
}
func cleanInvites(ldb *db.DB) {
for {
ldb.ExpireInvites(inviteExpireDuration)
time.Sleep(time.Minute * 60)
}
}
func readUserList(listPath string) []string {
f, err := os.Open(listPath)
if err != nil {
log.Fatal(err)
}
defer f.Close()
list := []string{}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
user := strings.TrimSpace(scanner.Text())
list = append(list, user)
}
sort.Strings(list)
return list
}