Esempio n. 1
0
func main() {
	var err error

	// Define our commandline flags:
	fl_listen_uri := flag.String("l", "tcp://0.0.0.0:4444", "listen URI (schemes available are tcp, unix)")
	fl_ssh_uri := flag.String("ssh", "tcp://localhost:22", "forward ssh traffic to an sshd listening at this URI")
	fl_https_uri := flag.String("https", "tcp://localhost:443", "forward https traffic to an https service listening at this URI")
	flag.BoolVar(&verbose, "v", false, "verbose logging")
	flag.Parse()

	// Parse all the URIs:
	listen_addr, err = base.ParseListenable(*fl_listen_uri)
	base.PanicIf(err)
	ssh_addr, err = base.ParseDialable(*fl_ssh_uri)
	base.PanicIf(err)
	https_addr, err = base.ParseDialable(*fl_https_uri)
	base.PanicIf(err)

	// Start the server:
	var sig os.Signal
	sig, err = base.ServeMain(listen_addr, serveMux)
	if err != nil {
		log.Fatal(err)
	}
	if sig != nil {
		log.Printf("\ncaught signal %s\n", sig)
	}
}
Esempio n. 2
0
func main() {
	// Define our commandline flags:
	fs := flag.String("fs", ".", "Root directory of served files and templates")
	xrGifArg := flag.String("xrg", "", "X-Accel-Redirect header prefix for serving images or blank to disable")
	xrThumbArg := flag.String("xrt", "", "X-Accel-Redirect header prefix for serving thumbnails or blank to disable")

	fl_listen_uri := flag.String("l", "tcp://0.0.0.0:8080", "listen URI (schemes available are tcp, unix)")
	flag.Parse()

	// Parse all the URIs:
	listen_addr, err := base.ParseListenable(*fl_listen_uri)
	base.PanicIf(err)

	// Parse the flags and set values:
	flag.Parse()

	// Make directories we need:
	base_folder = base.CanonicalPath(path.Clean(*fs))
	os.MkdirAll(store_folder(), 0775)
	os.MkdirAll(thumb_folder(), 0775)
	os.MkdirAll(tmp_folder(), 0775)

	xrGif = *xrGifArg
	xrThumb = *xrThumbArg

	// Create/update the DB schema if needed:
	api, err := NewAPI()
	if err != nil {
		log.Fatal(err)
		return
	}
	api.Close()

	// Watch the html templates for changes and reload them:
	_, cleanup, err := web.WatchTemplates("ui", html_path(), "*.html", nil, &uiTmpl)
	if err != nil {
		log.Println(err)
		return
	}
	defer cleanup()

	// Start profiler:
	go func() {
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()

	// Start the server:
	_, err = base.ServeMain(listen_addr, func(l net.Listener) error {
		return http.Serve(l, web.ReportErrors(web.Log(web.DefaultErrorLog, web.ErrorHandlerFunc(requestHandler))))
	})
	if err != nil {
		log.Println(err)
		return
	}
}
Esempio n. 3
0
func main() {
	fl_listen_uri := flag.String("l", "tcp://0.0.0.0:8080", "listen URI (schemes available are tcp, unix)")
	flag.Parse()

	// Parse all the URIs:
	listen_addr, err := base.ParseListenable(*fl_listen_uri)
	base.PanicIf(err)

	// Open database:
	db, err = sql.Open("postgres", dbConnectionString)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Startup")
	base.ServeMain(listen_addr, func(l net.Listener) error {
		return http.Serve(l, web.ReportErrors(web.Log(web.DefaultErrorLog, web.ErrorHandlerFunc(requestHandler))))
	})
	fmt.Println("Shutdown")
}
Esempio n. 4
0
func main() {
	// Define our commandline flags:
	flag.StringVar(&html_folder, "html", "./html", "Directory of HTML template files")
	flag.StringVar(&staticHref, "static", "static", "HREF prefix to static files")
	fl_listen_uri := flag.String("l", "tcp://0.0.0.0:8080", "listen URI (schemes available are tcp, unix)")
	flag.BoolVar(&verbose, "v", false, "verbose logging")
	flag.BoolVar(&debug, "d", false, "debug logging")
	flag.BoolVar(&failsafe, "f", false, "failsafe mode - SQL errors return empty resultsets")
	// TODO: configurable DB connection string
	flag.StringVar(&dbConnectionString, "db", defaultDbConnectionString, "DB connection string")
	flag.Parse()

	// Parse all the URIs:
	listen_addr, err := base.ParseListenable(*fl_listen_uri)
	base.PanicIf(err)

	// Open database:
	db, err = sql.Open("postgres", dbConnectionString)
	if err != nil {
		log.Println(err)
		return
	}

	// Watch the html templates for changes and reload them:
	_, cleanup, err := web.WatchTemplates("ui", html_path(), "*.html", uiTemplatesPreParse, &uiTmpl)
	if err != nil {
		log.Println(err)
		return
	}
	defer cleanup()

	// Start the server:
	_, err = base.ServeMain(listen_addr, func(l net.Listener) error {
		return http.Serve(l, web.ReportErrors(web.Log(web.DefaultErrorLog, web.ErrorHandlerFunc(requestHandler))))
	})
	if err != nil {
		log.Println(err)
		return
	}
}
Esempio n. 5
0
func main() {
	flag.StringVar(&html_path, "html", "./html", "local path to html templates")
	flag.StringVar(&proxyRoot, "p", "/", "root of web requests to process")
	flag.StringVar(&jailRoot, "r", ".", "local filesystem path to bind to web request root path")
	flag.StringVar(&accelRedirect, "xa", "", "Root of X-Accel-Redirect paths to use)")
	flag.StringVar(&jplayerUrl, "jp-url", "", `Web path to jPlayer files (e.g. "/js")`)
	flag.StringVar(&jplayerPath, "jp-path", "", `Local filesystem path to jPlayer files`)

	fl_listen_uri := flag.String("l", "tcp://0.0.0.0:8080", "listen URI (schemes available are tcp, unix)")
	flag.Parse()

	if jplayerUrl != "" {
		useJPlayer = true
	}

	jailRoot = base.CanonicalPath(jailRoot)
	html_path = base.CanonicalPath(html_path)

	listen_addr, err := base.ParseListenable(*fl_listen_uri)
	base.PanicIf(err)

	// Watch the html templates for changes and reload them:
	_, cleanup, err := web.WatchTemplates("ui", html_path, "*.html", nil, &uiTmpl)
	if err != nil {
		log.Println(err)
		return
	}
	defer cleanup()

	// Start the server:
	_, err = base.ServeMain(listen_addr, func(l net.Listener) error {
		return http.Serve(l, web.ReportErrors(web.Log(web.DefaultErrorLog, web.ErrorHandlerFunc(processRequest))))
	})
	if err != nil {
		log.Println(err)
		return
	}
}
Esempio n. 6
0
func main() {
	fl_listen_uri := flag.String("l", "tcp://0.0.0.0:8080", "listen URI (schemes available: tcp, unix)")
	flag.StringVar(&proxyRoot, "p", "/", "root of web requests to process")
	flag.StringVar(&jailRoot, "r", ".", "local filesystem path to bind to web request root path")
	htmlPath := flag.String("html", ".", "local filesystem path to HTML templates")
	flag.StringVar(&accelRedirect, "xa", "", "Root of X-Accel-Redirect paths to use)")
	flag.StringVar(&jplayerUrl, "jp-url", "", `Web path to jPlayer files (e.g. "/js" or "//static.somesite.com/jp")`)
	flag.StringVar(&jplayerPath, "jp-path", "", `Local filesystem path to serve jPlayer files from (optional)`)
	flag.Parse()

	// Parse all the URIs:
	listen_addr, err := base.ParseListenable(*fl_listen_uri)
	base.PanicIf(err)

	jailRoot = base.CanonicalPath(jailRoot)

	if jplayerUrl != "" {
		useJPlayer = true
	}

	// Watch the html templates for changes and reload them:
	_, cleanup, err := web.WatchTemplates("ui", *htmlPath, "*.html", func(t *template.Template) *template.Template {
		return t.Funcs(map[string]interface{}{
			"isLast": func(i, count int) bool { return i == count-1 },
		})
	}, &uiTmpl)
	if err != nil {
		log.Fatal(err)
		return
	}
	defer cleanup()

	// Start the server:
	base.ServeMain(listen_addr, func(l net.Listener) error {
		return http.Serve(l, http.HandlerFunc(processRequest))
	})
}