2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
22 var dir, file = path.Split(path.Clean(os.Getenv("_")))
23 var kFrontEndFiles string = path.Join(dir, "fe")
25 func indexHandler(connection *http.Conn, request *http.Request) {
26 fd, err := os.Open(path.Join(kFrontEndFiles, "index.html"), os.O_RDONLY, 0)
28 fmt.Print("Error opening file ", err.String(), "\n")
31 io.Copy(connection, fd)
34 func serviceHandler(connection *http.Conn, request *http.Request) {
35 if request.Method != "POST" {
36 io.WriteString(connection, "Error: Not a POST request")
40 switch request.FormValue("action") {
42 files, err := paths.List(request.FormValue("path"))
44 errorResponse(connection, err.String())
46 okResponse(connection, files)
51 errorResponse(connection, "Unhandled action")
54 func errorResponse(connection *http.Conn, message string) {
55 response := map[string] string {
59 json_data, err := json.Marshal(response)
61 connection.SetHeader("Content-Type", "text/json")
63 io.WriteString(connection, "{\"error\":\"-9\",\"message\":\"Internal encoding error\"}")
65 connection.Write(json_data)
69 func okResponse(connection *http.Conn, data interface{}) {
70 connection.SetHeader("Content-Type", "text/json")
71 json_data, err := json.Marshal(data)
73 errorResponse(connection, "Internal encoding error")
75 connection.Write(json_data)
80 mux := http.NewServeMux()
81 mux.HandleFunc("/", indexHandler)
82 mux.Handle("/fe/", http.FileServer(kFrontEndFiles, "/fe/"))
83 mux.HandleFunc("/service", serviceHandler)
85 error := http.ListenAndServe(":8084", mux)
86 fmt.Printf("error %v", error)