public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // It's a POST, so we need to read the data on the stream, the lines after the blank line StreamReader sr = new StreamReader(requestData); string body = sr.ReadToEnd(); sr.Close(); body = body.Trim(); httpResponse.ContentType = "text/html"; string resource = GetParam(path); //m_log.DebugFormat("[XXX]: query String: {0}; resource: {1}", body, resource); try { // Here the data on the stream is transformed into a nice dictionary of keys & values Dictionary <string, object> postdata = ServerUtils.ParseQueryString(body); Request req = RequestFactory.CreateRequest(resource, httpRequest, Localization.GetLanguageInfo(httpRequest.Headers.Get("accept-language"))); Environment env = new Environment(req); string result = string.Empty; if (resource.Equals("/") || resource.Equals(string.Empty)) { // The client invoked /wifi/admin/users/ string terms = String.Empty; if (postdata.ContainsKey("terms")) { terms = postdata["terms"].ToString(); } result = m_WebApp.Services.UserSearchPostRequest(env, terms); } else if (resource.StartsWith("/edit")) { // The client invoked /wifi/admin/groups/edit, possibly with the UUID parameter after UUID groupID = UUID.Zero; string[] pars = SplitParams(path); if ((pars.Length >= 2) && UUID.TryParse(pars[1], out groupID)) { // Indeed the client invoked /wifi/admin/groups/edit/<uuid>, and we got it already in userID (above) string name = string.Empty, charter = string.Empty; if (postdata.ContainsKey("name")) { name = postdata["name"].ToString(); } if (postdata.ContainsKey("charter")) { charter = postdata["charter"].ToString(); } result = m_WebApp.Services.GroupsEditPostRequest(env, groupID, name, charter); } } else if (resource.StartsWith("/delete")) { // The client invoked /wifi/admin/groups/edit, possibly with the UUID parameter after UUID groupID = UUID.Zero; string[] pars = SplitParams(path); if ((pars.Length >= 2) && UUID.TryParse(pars[1], out groupID)) { // Indeed the client invoked /wifi/admin/groups/edit/<uuid>, and we got it already in userID (above) string form = string.Empty; result = m_WebApp.Services.GroupsDeletePostRequest(env, groupID); } } return(WebAppUtils.StringToBytes(result)); } catch (Exception e) { m_log.DebugFormat("[USER ACCOUNT POST HANDLER]: Exception {0}", e); } return(WebAppUtils.FailureResult()); }
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // It's a POST, so we need to read the data on the stream, the lines after the blank line StreamReader sr = new StreamReader(requestData); string body = sr.ReadToEnd(); sr.Close(); body = body.Trim(); httpResponse.ContentType = "text/html"; string resource = GetParam(path); //m_log.DebugFormat("[HYPERLINK POST HANDLER]: query String: {0}; resource: {1}", body, resource); try { // Here the data on the stream is transformed into a nice dictionary of keys & values Dictionary <string, object> postdata = ServerUtils.ParseQueryString(body); Request request = RequestFactory.CreateRequest(resource, httpRequest); Diva.Wifi.Environment env = new Diva.Wifi.Environment(request); string result = string.Empty; if (resource.StartsWith("/add")) { // The client invoked /wifi/linkregion/add string address = string.Empty; uint xloc = 0, yloc = 0; if (postdata.ContainsKey("address")) { address = postdata["address"].ToString(); } if (postdata.ContainsKey("xloc")) { UInt32.TryParse(postdata["xloc"].ToString(), out xloc); } if (postdata.ContainsKey("yloc")) { UInt32.TryParse(postdata["yloc"].ToString(), out yloc); } result = m_WebApp.Services.HyperlinkAddRequest(env, address, xloc, yloc); } else if (resource.StartsWith("/delete")) { // The client invoked /wifi/linkregion/delete, possibly with the UUID parameter after UUID regionID = UUID.Zero; string[] pars = SplitParams(path); if ((pars.Length >= 2) && UUID.TryParse(pars[1], out regionID)) { // Indeed the client invoked /wifi/linkregion/delete/<uuid>, and we got it already in regionID (above) result = m_WebApp.Services.HyperlinkDeletePostRequest(env, regionID); } } return(WebAppUtils.StringToBytes(result)); } catch (Exception e) { m_log.DebugFormat("[HYPERLINK POST HANDLER]: Exception {0}", e); } return(WebAppUtils.FailureResult()); }
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // path = /wifi/... //m_log.DebugFormat("[Wifi]: path = {0}", path); //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint); //foreach (object o in httpRequest.Query.Keys) // m_log.DebugFormat(" >> {0}={1}", o, httpRequest.Query[o]); httpResponse.ContentType = "text/html"; string resource = GetParam(path); //m_log.DebugFormat("[INVENTORY HANDLER POST]: resource {0}", resource); Request request = RequestFactory.CreateRequest(string.Empty, httpRequest, Localization.GetLanguageInfo(httpRequest.Headers.Get("accept-language"))); Environment env = new Environment(request); string result = string.Empty; if (resource.Equals("/") || resource.Equals(string.Empty)) { StreamReader sr = new StreamReader(requestData); string body = sr.ReadToEnd(); sr.Close(); body = body.Trim(); Dictionary <string, object> postdata = ServerUtils.ParseQueryString(body); string action = postdata.Keys.FirstOrDefault(key => key.StartsWith("action-")); if (action == null) { action = string.Empty; } else { action = action.Substring("action-".Length); } string folder = string.Empty; string newFolderName = string.Empty; List <string> nodes = new List <string>(); List <string> types = new List <string>(); if (postdata.ContainsKey("folder")) { folder = postdata["folder"].ToString(); } if (postdata.ContainsKey("newFolderName")) { newFolderName = postdata["newFolderName"].ToString(); } foreach (KeyValuePair <string, object> kvp in postdata) { if (kvp.Key.StartsWith("inv-")) { nodes.Add(kvp.Key.Substring(4)); types.Add(kvp.Value.ToString()); } } result = m_WebApp.Services.InventoryPostRequest(env, action, folder, newFolderName, nodes, types); } else if (resource.StartsWith("/upload")) { HttpMultipartParser parser = new HttpMultipartParser(requestData, "datafile"); if (parser.Success) { //string user = HttpUtility.UrlDecode(parser.Parameters["user"]); if (!Directory.Exists(WebAppUtils.UploadPath)) { Directory.CreateDirectory(WebAppUtils.UploadPath); } string filename = new Guid().ToString().Substring(0, 8) + ".iar"; string pathToFile = System.IO.Path.Combine(WebAppUtils.UploadPath, filename); if (File.Exists(pathToFile)) { File.Delete(pathToFile); } using (FileStream w = new FileStream(pathToFile, FileMode.CreateNew)) { w.Write(parser.FileContents, 0, parser.FileContents.Length); } result = m_WebApp.Services.InventoryUploadRequest(env, pathToFile); File.Delete(pathToFile); } } return(WebAppUtils.StringToBytes(result)); }
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // path = /wifi/... //m_log.DebugFormat("[Wifi]: path = {0}", path); //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint); //foreach (object o in httpRequest.Query.Keys) // m_log.DebugFormat(" >> {0}={1}", o, httpRequest.Query[o]); string resource = GetParam(path); resource = Uri.UnescapeDataString(resource).Trim(WebAppUtils.DirectorySeparatorChars); //m_log.DebugFormat("[Wifi]: resource {0}", resource); Request request = RequestFactory.CreateRequest(resource, httpRequest, Localization.GetLanguageInfo(httpRequest.Headers.Get("accept-language"))); Environment env = new Environment(request); if (resource == string.Empty || resource.StartsWith("index.")) { if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero) { m_WebApp.Services.ComputeStatistics(); } httpResponse.ContentType = "text/html"; return(WebAppUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env))); } else { string resourcePath = WebApp.GetPath(resource); string[] resourcePaths = WebApp.GetPaths(resource); string type = WebAppUtils.GetContentType(resource); httpResponse.ContentType = type; //m_log.DebugFormat("[Wifi]: ContentType {0}", type); //m_log.DebugFormat("[XXX]: path {0}", resourcePath); if (type.StartsWith("image")) { return(WebAppUtils.ReadBinaryResource(resourcePaths)); } if (type.StartsWith("application")) { string res = WebAppUtils.ReadTextResource(resourcePaths, WebApp.MissingPage, true); return(WebAppUtils.StringToBytes(res)); } if (type.StartsWith("text")) { if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero) { m_WebApp.Services.ComputeStatistics(); } resourcePath = Localization.LocalizePath(env, resource); Processor p = new Processor(m_WebApp.WifiScriptFace, env); string res = p.Process(WebAppUtils.ReadTextResource(resourcePaths, WebApp.MissingPage)); if (res == string.Empty) { res = m_WebApp.Services.DefaultRequest(env); } return(WebAppUtils.StringToBytes(res)); } } httpResponse.ContentType = "text/plain"; string result = "Boo!"; return(WebAppUtils.StringToBytes(result)); }