3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 07:59:31 +01:00
ergo/ergonomadic.go

74 lines
1.4 KiB
Go
Raw Normal View History

2014-02-08 22:18:11 +01:00
package main
import (
2014-02-24 07:21:39 +01:00
"code.google.com/p/go.crypto/bcrypt"
"database/sql"
2014-02-24 07:21:39 +01:00
"encoding/base64"
"flag"
"fmt"
2014-02-08 22:18:11 +01:00
"github.com/jlatt/ergonomadic/irc"
_ "github.com/mattn/go-sqlite3"
2014-02-09 16:53:42 +01:00
"log"
"os"
2014-02-08 22:18:11 +01:00
)
2014-02-24 07:21:39 +01:00
func genPasswd(passwd string) {
2014-02-25 04:04:50 +01:00
crypted, err := bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.MinCost)
2014-02-24 07:21:39 +01:00
if err != nil {
log.Fatal(err)
}
encoded := base64.StdEncoding.EncodeToString(crypted)
fmt.Println(encoded)
}
func initDB(config *irc.Config) {
os.Remove(config.Database())
db, err := sql.Open("sqlite3", config.Database())
if err != nil {
log.Fatal(err)
}
defer db.Close()
_, err = db.Exec(`
CREATE TABLE channel (
name TEXT NOT NULL UNIQUE,
flags TEXT,
key TEXT,
topic TEXT,
user_limit INTEGER)`)
if err != nil {
log.Fatal(err)
}
}
2014-02-08 22:18:11 +01:00
func main() {
2014-02-24 07:21:39 +01:00
conf := flag.String("conf", "ergonomadic.json", "ergonomadic config file")
initdb := flag.Bool("initdb", false, "initialize database")
2014-02-24 07:21:39 +01:00
passwd := flag.String("genpasswd", "", "bcrypt a password")
flag.Parse()
if *passwd != "" {
genPasswd(*passwd)
return
}
config, err := irc.LoadConfig(*conf)
2014-02-09 16:53:42 +01:00
if err != nil {
log.Fatal(err)
}
if *initdb {
initDB(config)
2014-02-09 16:53:42 +01:00
return
}
// TODO move to data structures
2014-02-09 16:53:42 +01:00
irc.DEBUG_NET = config.Debug["net"]
irc.DEBUG_CLIENT = config.Debug["client"]
irc.DEBUG_CHANNEL = config.Debug["channel"]
irc.DEBUG_SERVER = config.Debug["server"]
2014-02-24 04:13:45 +01:00
irc.NewServer(config).Run()
2014-02-08 22:18:11 +01:00
}