Exemplo n.º 1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU() * 4)

	flag.BoolVar(&printf, "printf", false, "print replies")
	flag.BoolVar(&compress, "compress", false, "compress replies")
	flag.StringVar(&tsig, "tsig", "", "use MD5 hmac tsig: keyname:base64")
	flag.StringVar(&config, "config", "", "alternative configuration file")
	flag.StringVar(&bind_addr, "bind_addr", "127.0.0.1:53", "bind HTTP to HOST and PORT")
	flag.StringVar(&dnsfwd_addr, "dnsfwd_addr", "8.8.8.8:53", "DNS server to forward request to")
	flag.StringVar(&redis_addr, "redis_addr", "127.0.0.1:6379", "address of Redis instance")
	flag.StringVar(&portal_addr, "portal_addr", "127.0.0.1:80", "address of portal")
	flag.StringVar(&log_file, "log_file", "", "path to log file")

	var name, secret string
	flag.Usage = func() {
		flag.PrintDefaults()
	}
	flag.Parse()

	// Setup Log file
	if len(log_file) > 0 {
		f, err := os.OpenFile(log_file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0640)
		defer f.Close()
		if err != nil {
			log.Fatalf("Error opening file: %v", err)
		}
		log.SetOutput(f)
	}

	// Tsig
	if tsig != "" {
		a := strings.SplitN(tsig, ":", 2)
		name, secret = dns.Fqdn(a[0]), a[1] // fqdn the name, which everybody forgets...
	}

	// DNS
	dns.HandleFunc(".", handleAll)

	go serve("tcp", name, secret)
	go serve("udp", name, secret)
	log.Printf("* Running on %s\n", bind_addr)
	sig := make(chan os.Signal)
	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
forever:
	for {
		select {
		case s := <-sig:
			fmt.Printf("Signal (%d) received, stopping\n", s)
			break forever
		}
	}
}
Exemplo n.º 2
0
func NewSettings(version, home string, locations []string) (*Settings, error) {
	location := searchConfig(locations)
	if location == "" {
		msg := "Unable to find mediagui.conf\nIt should be placed at any these locations:\n$HOME/.mediagui/\n/usr/local/etc\n<app directory>"
		return nil, errors.New(msg)
	}

	var config, dataDir, webDir, logDir, mediaFolders, ginMode, cpuprofile, unraidHosts string
	var logtostderr, unraidMode bool
	flag.BoolVar(&logtostderr, "logtostderr", true, "true/false log to stderr")
	flag.StringVar(&config, "config", "", "config location")
	flag.StringVar(&dataDir, "datadir", filepath.Join(home, ".mediagui/db"), "folder containing the database files")
	flag.StringVar(&webDir, "webdir", filepath.Join(home, ".mediagui/web"), "folder where web app will be read from")
	flag.StringVar(&logDir, "logdir", "", "folder where log file will be written to")
	flag.StringVar(&mediaFolders, "mediafolders", "/mnt/user/films", "folders that will be scanned for media")
	flag.StringVar(&ginMode, "gin_mode", "release", "gin mode")
	flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to file")
	flag.BoolVar(&unraidMode, "unraid_mode", true, "if true the app will work distributed with a service running on the unraid host")
	flag.StringVar(&unraidHosts, unraidHosts, "wopr|hal", "specify which unraid hosts will be scanned for movies. the service agent must be running in that host")

	flag.Set("config", location)
	flag.Parse()

	// fmt.Printf("mediaFolders: %s\n", mediaFolders)

	s := &Settings{}
	if mediaFolders == "" {
		s.MediaFolders = make([]string, 0)
	} else {
		s.MediaFolders = strings.Split(mediaFolders, "|")
	}
	s.Version = version
	s.DataDir = dataDir
	s.WebDir = webDir
	s.LogDir = logDir
	s.Location = location
	s.GinMode = ginMode
	s.CpuProfile = cpuprofile
	s.UnraidMode = unraidMode
	if unraidHosts == "" {
		s.UnraidHosts = make([]string, 0)
	} else {
		s.UnraidHosts = strings.Split(unraidHosts, "|")
	}

	return s, nil
}
func init() {
	flag.IntVar(&WebPort, "web-port", 8080, "Port to bind to")
	flag.StringVar(&EndPointURL, "endpoint", "http://*****:*****@getfishtank.ca", "SMTP username")
	flag.StringVar(&SmtpPassword, "smtp-password", "", "SMTP password")

	flag.StringVar(&DatabaseStore, "database", "mongodb://127.0.0.1:27017/model", "database")

	flag.StringVar(&GplusKey, "gplus-key", "1049113770955-agedcvcoi68qlbc9mm321odb5qdqlgrg.apps.googleusercontent.com", "Google+ OAuth Key")
	flag.StringVar(&GplusSecret, "gplus-secret", "TjdRDltddkFtlx9dyStuaa5w", "Google+ OAuth Secret")
	flag.StringVar(&FacebookKey, "facebook-key", "1667094910175363", "facebook key")
	flag.StringVar(&FacebookSecret, "facebook-secret", "63472dc2deb3269d298f529cc727b9f2", "facebook secret")
	flag.StringVar(&TwitterKey, "twitter-key", "QVO8QAPqpvnfX6CY3291GkauQ", "twitter key")
	flag.StringVar(&TwitterSecret, "twitter-secret", "YpaY8TsSR2aLOJh4o9XIqXSgtRubhACmRI2oWTPJs608hdJYv9", "twitter secret")

	flag.Parse()
	log.Printf("Config file						%s", config)
	log.Printf("Web folder						%s", StaticAssets)
	log.Printf("Web host						%s", WebHost)
	log.Printf("Web port						%s", WebPort)
	log.Printf("End point						%s", EndPointURL)
	log.Printf("Use SSL							%s", UseSSL)
	log.Printf("certification file				%s", CertFile)
	log.Printf("key file						%s", KeyFile)
	log.Printf("run folder						%s", RunFolder)
	log.Printf("template folder					%s", TemplateFolder)
	log.Printf("end point						%s", EndPointURL)
	log.Printf("SMTP host						%s", SmtpHost)
	log.Printf("SMTP port 						%s", SmtpPort)
	log.Printf("SMTP username					%s", SmtpUsername)
	log.Printf("SMTP password					%s", SmtpPassword)
	log.Printf("Database						%s", DatabaseStore)
	log.Printf("JWT File						%s", JwtFile)
	log.Printf("Google plus						%s", GplusKey)
	log.Printf("Google Secret					%s", GplusSecret)
	log.Printf("facebook						%s", FacebookKey)
	log.Printf("facebook secret					%s", FacebookSecret)
	log.Printf("twitter							%s", TwitterKey)
	log.Printf("twitter secret					%s", TwitterSecret)

}
Exemplo n.º 4
0
func main() {
	var (
		config string
		length float64
		age    int
		name   string
		female bool
	)

	flag.StringVar(&config, "config", "", "help message")
	flag.StringVar(&name, "name", "", "help message")
	flag.IntVar(&age, "age", 0, "help message")
	flag.Float64Var(&length, "length", 0, "help message")
	flag.BoolVar(&female, "female", false, "help message")

	flag.Parse()

	fmt.Println("length:", length)
	fmt.Println("age:", age)
	fmt.Println("name:", name)
	fmt.Println("female:", female)
}
Exemplo n.º 5
0
func main() {
	var (
		port          = 3001
		redisDatabase = 0
		redisPoolSize = 10
		clientID      = ""
		clientSecret  = ""
		hashKey       = "randomishstringthatsi32charslong"
		blockKey      = "randomishstringthatsi32charslong"
		deferPanicKey = ""
	)
	flag.IntVar(&port, "port", port, "Port to start the server on")
	flag.IntVar(&procs, "procs", 1, "Number of CPU processors (0 to use max)")
	flag.BoolVar(&debug, "debug", false, "Debug mode")
	flag.StringVar(
		&redisURL, "redisURL", redisURL,
		"Redis URL to tcp connect to")
	flag.StringVar(
		&staticPrefix, "staticPrefix", staticPrefix,
		"Prefix in front of static assets in HTML")
	flag.IntVar(&redisDatabase, "redisDatabase", redisDatabase,
		"Redis database number to connect to")
	flag.StringVar(
		&clientID, "clientID", clientID,
		"OAuth Client ID")
	flag.StringVar(
		&clientSecret, "clientSecret", clientSecret,
		"OAuth Client Secret")
	flag.BoolVar(&usingHTTPS, "usingHTTPS", usingHTTPS,
		"Whether requests are made under HTTPS")
	flag.StringVar(
		&hashKey, "hashKey", hashKey,
		"HMAC hash key to use for encoding cookies")
	flag.StringVar(
		&blockKey, "blockKey", blockKey,
		"Block key to encrypt cookie values")
	flag.StringVar(
		&deferPanicKey, "deferPanicKey", deferPanicKey,
		"Auth key for deferpanic.com")
	flag.Parse()

	dfs := deferstats.NewClient(deferPanicKey)
	if deferPanicKey == "" {
		dfs.SetnoPost(true)
	}
	go dfs.CaptureStats()

	oauthConf.ClientID = clientID
	oauthConf.ClientSecret = clientSecret

	sCookie = securecookie.New([]byte(hashKey), []byte(blockKey))

	log.Println("REDIS DATABASE:", redisDatabase)
	log.Println("DEBUG MODE:", debug)
	log.Println("STATIC PREFIX:", staticPrefix)

	if !debug {
		redisPoolSize = 100
	}

	// Figuring out how many processors to use.
	maxProcs := runtime.NumCPU()
	if procs == 0 {
		procs = maxProcs
	} else if procs < 0 {
		panic("PROCS < 0")
	} else if procs > maxProcs {
		panic(fmt.Sprintf("PROCS > max (%v)", maxProcs))
	}
	log.Println("PROCS:", procs)
	runtime.GOMAXPROCS(procs)

	renderer = render.New(render.Options{
		IndentJSON:    debug,
		IsDevelopment: debug,
	})

	df := func(network, addr string) (*redis.Client, error) {
		client, err := redis.Dial(network, addr)
		if err != nil {
			return nil, err
		}
		err = client.Cmd("SELECT", redisDatabase).Err
		if err != nil {
			return nil, err
		}
		// if err = client.Cmd("AUTH", "SUPERSECRET").Err; err != nil {
		// 	client.Close()
		// 	return nil, err
		// }
		return client, nil
	}

	var err error
	redisPool, err = pool.NewCustomPool("tcp", redisURL, redisPoolSize, df)
	errorHandler(err)

	mux := mux.NewRouter()
	mux.HandleFunc("/", dfs.HTTPHandler(indexHandler)).Methods("GET", "HEAD")
	mux.HandleFunc("/v1/ping", dfs.HTTPHandler(pingHandler)).Methods("GET", "HEAD")
	mux.HandleFunc("/v1", dfs.HTTPHandler(fetchHandler)).Methods("GET", "HEAD")
	mux.HandleFunc("/v1", dfs.HTTPHandler(updateHandler)).Methods("POST", "PUT")
	mux.HandleFunc("/v1", dfs.HTTPHandler(deleteHandler)).Methods("DELETE")
	mux.HandleFunc("/v1/stats", dfs.HTTPHandler(privateStatsHandler)).Methods("GET")
	mux.HandleFunc("/v1/flush", dfs.HTTPHandler(flushHandler)).Methods("DELETE")
	mux.HandleFunc("/v1/bulk", dfs.HTTPHandler(bulkHandler)).Methods("POST", "PUT")
	mux.HandleFunc("/login", dfs.HTTPHandler(handleGitHubLogin)).Methods("GET")
	mux.HandleFunc("/logout", dfs.HTTPHandler(logoutHandler)).Methods("GET", "POST")
	mux.HandleFunc("/github_oauth_cb", dfs.HTTPHandler(handleGitHubCallback)).Methods("GET")
	mux.HandleFunc("/domainkeys/new", domainkeyNewHandler).Methods("POST")
	mux.HandleFunc("/domainkeys/delete", domainkeyDeleteHandler).Methods("POST")

	n := negroni.Classic()

	n.UseHandler(mux)
	n.Run(fmt.Sprintf(":%d", port))
}
Exemplo n.º 6
0
func main() {
	var listen string
	var dockerHost string
	var dockerTLSVerify bool
	var dockerCertPath string
	var debugMode bool
	var debugListen string
	var registryURL string
	var cachePath string
	var dsn string
	var sqlAdapter string

	flag.StringVar(&listen, "listen", ":3000", "host:port to listen on")
	flag.StringVar(&dockerHost, "docker-host", "unix:///var/run/docker.sock", "address of Docker host")
	flag.BoolVar(&dockerTLSVerify, "docker-tls-verify", false, "use TLS client for Docker")
	flag.StringVar(&dockerCertPath, "docker-cert-path", "", "path to the cert.pem, key.pem, and ca.pem for authenticating to Docker")
	flag.BoolVar(&debugMode, "debug", false, "enable /debug endpoints on DEBUG_LISTEN")
	flag.StringVar(&debugListen, "debug-listen", ":3001", "host:port to listen on for debug requests")
	flag.StringVar(&registryURL, "registry-url", "192.168.59.103:5000", "host:port of the registry for pushing images")
	flag.StringVar(&cachePath, "cache-path", "cache/", "path to the directory where cached repos will be stored")
	flag.StringVar(&dsn, "dsn", "file::memory:?cache=shared", "DSN string for connecting to the database")
	flag.StringVar(&sqlAdapter, "sql-adapter", "sqlite3", "adapter to use for the DSN string (currently only supports sqlite3)")
	flag.Parse()

	gin.DisableBindValidation()
	router := gin.Default()
	router.StaticFile("/", "static/index.html")
	router.Use(static.Serve("/", static.LocalFile("static", false)))

	client := dockerClient(dockerHost, dockerTLSVerify, dockerCertPath)
	db, err := sql.Open(sqlAdapter, dsn)
	if err != nil {
		panic(err)
	}
	buildRepo := builds.NewRepository(sqlAdapter, db)
	buildRepo.Migrate()
	logRepo := builds.NewLogRepository(sqlAdapter, db)
	logRepo.Migrate()
	streamRepo := streams.NewRepository()
	builder := builds.NewBuilder(registryURL, client, cachePath)
	buildQueue := builds.NewQueue(buildRepo, streamRepo, logRepo, builder)

	webhookHandler := api.NewWebhookHandler(buildRepo, buildQueue)
	router.POST("/webhooks/github", webhookHandler.Github)

	buildsResource := api.NewBuildsResource(buildRepo, buildQueue)
	router.GET("/builds", buildsResource.Index)
	router.POST("/builds", buildsResource.Create)
	router.GET("/builds/:id", buildsResource.Show)

	streamsResource := api.NewStreamsResource(buildRepo, streamRepo)
	router.GET("/builds/:id/streams/:type", streamsResource.Show)

	logsResource := api.NewLogsResource(buildRepo, logRepo)
	router.GET("/builds/:id/logs/:type", logsResource.Show)

	go buildQueue.Run()

	if debugMode {
		log.Println("Starting debug server on :3001")
		go http.ListenAndServe(debugListen, http.DefaultServeMux)
	}

	router.Run(listen)
}