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"
|
2014-02-25 20:11:34 +01:00
|
|
|
"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"
|
2014-02-25 20:11:34 +01:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2014-02-09 16:53:42 +01:00
|
|
|
"log"
|
2014-02-25 20:11:34 +01:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
2014-02-25 20:11:34 +01:00
|
|
|
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")
|
2014-02-25 20:11:34 +01:00
|
|
|
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)
|
2014-02-25 20:11:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if *initdb {
|
|
|
|
initDB(config)
|
2014-02-09 16:53:42 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-02-25 20:11:34 +01:00
|
|
|
// 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
|
|
|
}
|