)
type Configuration struct {
+ // The path to which all file operations are restricted.
JailRoot string
+
+ // The port on which the server back end runs.
Port int
+
+ // An array of URLs that the /proxy service will for which the back-end will
+ // forward GET requests and return the result.
ProxyURLs []string
+
+ // A map of usernames to MD5-encoded passwords that will be allowed to log in
+ // via a .htaccess style realm.
Users map [string] string
}
)
func main() {
+ // Set up the basic flags.
var configPath *string = flag.String("config", "~/.armadillo", "Path to the configuration file")
- flag.StringVar(&paths.JailRoot, "jail", "/", "Restrict file operations to this directory root")
- var port *int = flag.Int("port", 8080, "Port to run the server on")
+ var jailRoot *string = flag.String("jail", "", "Restrict file operations to this directory root")
+ var port *int = flag.Int("port", 0, "Port to run the server on")
flag.Parse()
+ // Load the configuration file, if it is present.
var configuration = new(config.Configuration)
fmt.Printf("Reading configuration from %v\n", *configPath)
if len(*configPath) > 0 {
}
}
- configuration.JailRoot = paths.JailRoot
- configuration.Port = *port
+ // Override configuration values with command line arguments.
+ if *jailRoot != "" {
+ configuration.JailRoot = *jailRoot
+ }
+ if *port != 0 {
+ configuration.Port = *port
+ }
- fmt.Printf("Starting Armadillo on port %d with root:\n %v\n", *port, paths.JailRoot)
+ // Run the server.
+ fmt.Printf("Starting Armadillo on port %d with root:\n %v\n",
+ configuration.Port, configuration.JailRoot)
+ paths.SetConfig(configuration)
server.RunBackEnd(configuration)
}
"os"
"path"
"strings"
+ "./config"
)
-var JailRoot string;
+var gJailRoot string;
+
+func SetConfig(aConfig *config.Configuration) {
+ gJailRoot = aConfig.JailRoot
+}
func canonicalizePath(raw_path string) string {
- raw_path = path.Join(JailRoot, raw_path)
+ raw_path = path.Join(gJailRoot, raw_path)
return path.Clean(raw_path)
}
func checkInJail(the_path string) bool {
- if len(the_path) < len(JailRoot) {
+ if len(the_path) < len(gJailRoot) {
return false
}
- if the_path[0:len(JailRoot)] != JailRoot {
+ if the_path[0:len(gJailRoot)] != gJailRoot {
return false
}
if strings.Index(the_path, "../") != -1 {
}
func errorResponse(connection *http.Conn, message string) {
- message = strings.Replace(message, paths.JailRoot, "/", -1)
+ message = strings.Replace(message, gConfig.JailRoot, "/", -1)
response := map[string] string {
"error" : "-1",
"message" : message,