go.talks/present: add -play flag
R=r
CC=gobot, golang-dev
https://golang.org/cl/6677046
diff --git a/present/appengine.go b/present/appengine.go
new file mode 100644
index 0000000..8292f0b
--- /dev/null
+++ b/present/appengine.go
@@ -0,0 +1,9 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build appengine
+
+package main
+
+const socketPresent = false // no websockets or compilation on app engine (yet)
diff --git a/present/code.go b/present/code.go
index c322f96..c60aedf 100644
--- a/present/code.go
+++ b/present/code.go
@@ -17,7 +17,7 @@
"unicode"
)
-var playEnabled = false // switched on when socket.go is included (not on App Engine)
+var playEnabled = false // to be enabled by a flag in main.go
func init() {
Register("code", parseCode, code)
diff --git a/present/main.go b/present/main.go
index b181ab3..18e4e32 100644
--- a/present/main.go
+++ b/present/main.go
@@ -21,8 +21,13 @@
func main() {
httpListen := flag.String("http", "127.0.0.1:3999", "host:port to listen on")
flag.StringVar(&basePath, "base", "", "base path for slide template and static resources")
+ flag.BoolVar(&playEnabled, "play", true, "enable playground (permit execution of arbitrary user code)")
flag.Parse()
+ if !socketPresent {
+ playEnabled = false
+ }
+
if basePath == "" {
p, err := build.Default.Import(basePkg, "", build.FindOnly)
if err != nil {
@@ -36,7 +41,8 @@
http.Handle("/static/", http.FileServer(http.Dir(basePath)))
if !strings.HasPrefix(*httpListen, "127.0.0.1") &&
- !strings.HasPrefix(*httpListen, "localhost") {
+ !strings.HasPrefix(*httpListen, "localhost") &&
+ playEnabled {
log.Print(localhostWarning)
}
@@ -59,6 +65,8 @@
Anyone with access to this address and port will have access to this machine as
the user running present.
+To avoid this message, listen on localhost or run with -play=false.
+
If you don't understand this message, hit Control-C to terminate this process.
WARNING! WARNING! WARNING!
diff --git a/present/socket.go b/present/socket.go
index cc573ed..be79dd0 100644
--- a/present/socket.go
+++ b/present/socket.go
@@ -23,19 +23,21 @@
"code.google.com/p/go.net/websocket"
)
+const socketPresent = true
+
const msgLimit = 1000 // max number of messages to send per session
var uniq = make(chan int) // a source of numbers for naming temporary files
func init() {
- playEnabled = true // instruct code.go to include "Run" buttons
-
go func() {
for i := 0; ; i++ {
uniq <- i
}
}()
+}
+func HandleSocket() {
http.Handle("/socket", websocket.Handler(socketHandler))
}