88 "math/rand"
99 "net/http"
1010 "os/exec"
11+ "regexp"
1112 "strconv"
1213 "time"
1314
@@ -55,7 +56,7 @@ func init() {
5556 return nil
5657 })
5758 db .Update (func (tx * bolt.Tx ) error {
58- _ , err := tx .CreateBucketIfNotExists ([]byte ("UserToBlog" )) // random string -> email
59+ _ , err := tx .CreateBucketIfNotExists ([]byte ("UserToBlog" )) // user -> blogdetails
5960 if err != nil {
6061 return fmt .Errorf ("Error with UserToBlog: %s" , err )
6162 }
@@ -114,6 +115,17 @@ func MainPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
114115 })
115116}
116117
118+ func ErrorPage (w http.ResponseWriter , r * http.Request , pm httprouter.Params ) {
119+ baseT := template .Must (template .New ("base" ).Parse (base ))
120+ baseT = template .Must (baseT .Parse (errorPage ))
121+
122+ baseT .ExecuteTemplate (w , "base" , map [string ]string {
123+ "PageName" : "error" ,
124+ "User" : getUser (w , r ),
125+ "Error" : pm .ByName ("errorcode" ),
126+ })
127+ }
128+
117129func SignupPage (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
118130 baseT := template .Must (template .New ("base" ).Parse (base ))
119131 baseT = template .Must (baseT .Parse (signup ))
@@ -180,6 +192,10 @@ func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
180192 blogname := r .FormValue ("blogname" )
181193 website := r .FormValue ("website" )
182194 port := rand .Intn (63000 ) + 2000
195+
196+ re := regexp .MustCompile ("[^A-Za-z]" )
197+ blogname = re .ReplaceAllString (blogname , "" )
198+
183199 blogcheck := []byte ("" )
184200
185201 username := getUser (w , r )
@@ -194,6 +210,7 @@ func AdminHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
194210 blogcheck = b .Get ([]byte (blogname ))
195211 return nil
196212 })
213+
197214 if blogcheck == nil {
198215 create , err := exec .Command ("./create.sh" , blogname , website , strconv .Itoa (port )).Output ()
199216 if err != nil && ! DEBUG {
@@ -376,5 +393,6 @@ func main() {
376393 router .GET ("/admin/" , AdminPage )
377394 router .POST ("/admin/" , AdminHandler )
378395 router .GET ("/logout/" , LogoutHandler )
396+ router .GET ("/error/:errorcode/" , ErrorPage )
379397 log .Fatal (http .ListenAndServe (":1337" , router ))
380398}
0 commit comments