Exemple #1
0
func init() {
	confFile := flag.String("f", "wiki.conf", "config file")
	flag.Parse()

	var err error
	cfg, err = config.ParseFile(*confFile)
	if err != nil {
		fmt.Printf("[!] could not load %s: %s\n",
			*confFile, err.Error())
		fmt.Println("[+] using defaults")
	}
	initSecurity(cfg["security"])
	initWiki(cfg["wiki"])
	initDefaultPaths()
	initServer(cfg["server"])
}
Exemple #2
0
func config(filename string) {
	cfg, err := goconfig.ParseFile(filename)
	if err != nil {
		log.Fatalf("failed to parse config file (%v), shutting down.",
			err)
	}

	var ok bool
	serverConfig.Address, _ = cfg.GetValue("server", "address")
	serverConfig.Port, ok = cfg.GetValue("server", "port")
	if !ok {
		serverConfig.Port = defaultPort
	}

	serverConfig.Key, ok = cfg.GetValue("tls", "key")
	if !ok {
		log.Fatalf("no TLS key specified, shutting down.")
	}
	serverConfig.Cert, ok = cfg.GetValue("tls", "cert")
	if !ok {
		log.Fatalf("no TLS certificate specified, shutting down.")
	}

	var saltFile string
	if saltFile, ok = cfg.GetValue("keys", "salt"); ok {
		checkSaltFile(saltFile)
	} else {
		log.Fatal("no salt file option in configuration")
	}

	if spec, ok := cfg.GetValue("db", "spec"); !ok {
		log.Fatal("fatal error: no database spec in config")
	} else {
		err = db.Init(spec)
		if err != nil {
			log.Fatalf("fatal error setting up database: %v", err)
		}
		log.Println("database configured successfully")
	}
	log.Println("successfully loaded config")
}
Exemple #3
0
func main() {
	var cfile = flag.String("config", "config.ini", "Full path to config file.")
	var debug = flag.Bool("v", false, "show logging info.")
	flag.Parse()
	conf, err := goconfig.ParseFile(*cfile)
	if err != nil {
		log.Fatalf("Can't parse config file! - %v", err)
	}

	url := conf["global"]["url"]
	dfile_name := conf["global"]["destination"]
	params := "?"

	os.Remove(dfile_name)

	for key, val := range conf["params"] {
		params = params + key + "=" + val + "&"
	}

	if *debug {
		log.Printf("Getting lists from: %s", url)
	}

	for key, val := range conf["list"] {
		full_url := url + params + "list=" + val

		if *debug {
			log.Printf("downloading %s", key)
		}
		_, err := get(full_url, dfile_name)
		if err != nil {
			if *debug {
				log.Fatalf("Can't write file! - %v", err)
			}
		}
	}
}
Exemple #4
0
func main() {
	var host, port string
	conf, err := config.ParseFile(config_file)
	if err != nil {
		fmt.Printf("[!] couldn't parse config file: %s\n", err.Error())
		os.Exit(1)
	}

	if conf["server"] == nil {
		host = DEFAULT_HOST
		port = DEFAULT_PORT
	} else {
		if conf["server"]["port"] != "" {
			port = conf["server"]["port"]
		} else {
			port = DEFAULT_PORT
		}

		if conf["server"]["host"] != "" {
			host = conf["server"]["host"]
		} else {
			port = DEFAULT_HOST
		}

		if conf["server"]["development"] == "false" {
			server_dev = false
			server_secure = true
		}

		if conf["server"]["dbfile"] != "" {
			dbFile = conf["server"]["dbfile"]
		}

		if conf["server"]["authenticate"] == "false" {
			check_auth = false
		} else {
			init_auth()
		}

		if conf["server"]["admin_user"] != "" {
			admin_user = conf["server"]["admin_user"]
			ok, err := userExists(admin_user)
			if err != nil {
				panic(err)
			} else if !ok {
				panic("User does not exists.")
			}
		}

		if conf["server"]["access_log"] != "" {
			access_logfile = conf["server"]["access_log"]
		}
		error_logfile = access_logfile

		if conf["server"]["error_log"] != "" {
			error_logfile = conf["server"]["error_log"]
		}
	}

	if conf["page"] == nil {
		page_title = DEFAULT_TITLE
		server_host = "localhost"
	} else {
		if conf["page"]["title"] != "" {
			page_title = conf["page"]["title"]
		} else {
			page_title = DEFAULT_TITLE
		}

		if conf["page"]["host"] != "" {
			server_host = conf["page"]["title"]
		} else {
			server_host = "localhost"
		}
	}

	if server_dev {
		server_host = fmt.Sprintf("%s:%s", server_host, port)
	}

	NotFound, err = webshell.GenerateTemplateErrorHandler(http.StatusNotFound,
		"templates/404.html")
	if err != nil {
		panic(err.Error())
	}
	app := webshell.NewApp("urlshorten-ng", host, port)
	err = assetcache.BackgroundAttachAssetCache(app, "/assets/", "assets/")
	if err != nil {
		log.Fatal("[!] ", err.Error())
	}
	app.AddConditionalRoute(check_auth, "/add", addUser)
	app.AddConditionalRoute(check_auth, "/change", changePass)
	app.AddRoute("/views/", getViews)
	app.AddRoute("/", topRoute)
	log.Printf("[+] listening on %s:%s\n", host, port)
	log.Fatal(app.Serve())
}