internal static string DefaultIndex(string rootdir, string hotsandport_slashed) { string html = WebServer.masterPagePre; //AppHelper.ReadFileText(rootdir + "\\index.html"); int sep = 0; List <Rykonpath> paths = WebServer.getDirectoryPaths(rootdir, rootdir, out sep); string res = ""; int i = -1; foreach (Rykonpath p in paths) { i++; if (p.path.EndsWith("\\index.html")) { continue; } res += ((p.type == Rykonpathtype.directory) ?WebDesigner.DirectoryTagAnchorWithImage(p.webpath) : WebDesigner.FileTagAnchor(p.webpath) + "\r\n"); if (i == sep) { res += "<br />"; } } // html= html.Replace(WebServer.anchorsTagsReplacor,res); html += res; html = html.Replace(WebServer.pagenamereplacor, "Main Page"); html = html.Replace(WebServer.appvernameReplacor, Program._AppverName); html += WebServer.masterPageAfter; return(html); }
internal static string ListDirectory(string requestdir, Classes.RykonFile[] f, ServerConfig Config) { string indexofdire = requestdir; if (Config.ShowFullPaths) { indexofdire = indexofdire.Remove(0, Config.RootDirectory.Length); } string doc = "<h2>\r\n"; doc += " Index of \r\n"; doc += " </h2><h4>\r\n"; doc += WebServer.EncodeHtmlChars(requestdir) + "\r\n"; doc += "</h4>\r\n"; doc += "<hr/><table>\r\n"; if (f == null || f.Length < 1) // empty { return("Empty Dir"); } string folderic = ""; string fileicon = ""; if (Config.ShowDirIcon) { folderic = WebDesigner.FileIcoTag; fileicon = WebDesigner.FileIcoTag; } int i = -1; string endtable = "</table><hr />" + WebDesigner.PoweredBy(Config) + " "; foreach (var p in f) { i++; if (p == null) { continue; } string tr = "<span style=\"text-decoration:underline\">"; tr += "<tr>\r\n"; tr += "<td>" + ((p.IsDir) ? folderic : fileicon) + "\r\n"; tr += "<a style='text-decoration: underline;' draggable='true' href ='" + (p.Webpath) + "' >\r\n"; tr += ((i == 0) ? "Parent Directory" : (i.ToString() + " " + p.Name)); tr += "</a>\r\n"; tr += "</td>\r\n"; tr += "</tr></span>\r\n"; doc += tr; } //} doc += endtable; return(doc); }
public static void executeUploader(System.Net.HttpListenerContext ctx, RykonProcess cp, ServerConfig Servconf) { if (cp.Method == "POST") { HttpNameValueCollection o = new HttpNameValueCollection(ref ctx); //WebServer.SaveFile(ctx.Request.ContentEncoding, WebServer.GetBoundary(ctx.Request.ContentType), ctx.Request.InputStream); } else { if (cp.LocalPath.EndsWith("/Upload/thumb.png")) { cp.OutPutData = AppHelper.ReadFileBts(Servconf.RootDirectory + "\\" + cp.LocalPath); cp.Requesting_Binary_data = true; return; } cp.Output_document = WebDesigner.getUpload_PostPage(cp.MainUrl(), Servconf.UploadPassword, Servconf.CSRF); cp.OutPutData = Encoding.UTF8.GetBytes(cp.Output_document); } }
internal static string ListDirectory(string Dir, string[] f, ServerConfig Config) { int i = 0; string doc = "<h2>\r\n"; doc += " Index of \r\n"; doc += " </h2><h4>\r\n"; doc += WebServer.EncodeHtmlChars(Dir) + "\r\n"; doc += "</h4>\r\n"; doc += "<hr/><table>\r\n"; if (f == null || f.Length < 1) // empty { return("Empty Dir"); } string fic = (Config.ShowDirIcon?WebDesigner.FolderIcoTag:""); foreach (string p in f) { string tr = "<span style=\"text-decoration:underline\">"; tr += "<tr>\r\n"; tr += "<td>" + fic + "\r\n"; tr += "<a style='text-decoration: underline;' draggable='true' href ='" + (p) + "/' >\r\n"; string name = WebServer.EncodeHtmlChars(" ") + WebServer.EncodeHtmlChars(AppHelper.LastPeice(p, "/")); tr += ((i == 0)?"Parent Directory":(i.ToString() + name)); tr += "</a>\r\n"; tr += "</td>\r\n"; tr += "</tr></span>\r\n"; i++; if (p == "") { continue; } doc += tr; } //} doc += "</table><hr />" + WebDesigner.PoweredBy(Config) + " "; return(doc); }
public static void executeController(ref ServerConfig Servconf, ref RykonProcess cp, ref bool valid_CSRF_tok, ref bool isValidsession, IntPtr handle, FormMain frm) { if (!Servconf.EnableControler) // disabled { cp.Output_document = WebDesigner.BuiltInDisabled("controller"); cp.Output_code = 302; } else // working { cp.LoadMaster = true; valid_CSRF_tok = cp.UrlOriginalString.Contains(Servconf.CSRF) || cp.POSTParEqual("CSRF", Servconf.CSRF); isValidsession = cp.Reqcuest_cookie_equal(WebServer.Control_auth_tokenname, Servconf.controlsession); /* ||cp.UrlOriginalString.Contains(Servconf.ControlPassword) */ if (Servconf.SecureControl) { cp.AllowedTocontrol = isValidsession; } else { cp.AllowedTocontrol = true; } string[] pcs = new string[] { }; if (cp.LocalPath.EndsWith("Control/logout")) { cp.SetResponseHeader("Set-Cookie", WebServer.Control_auth_tokenname + "=" + WebServer.CookieDeletedvalue); cp.Output_document = "Logged out"; return; } else if (!cp.LocalPath.StartsWith("/Control/exec")) { cp.RedirectTo("http://" + cp.Url.Authority + "/Control/exec.rk"); return; } else if (!cp.AllowedTocontrol) // login page { bool validformcsrf = cp.POSTParEqual("CSRF", Servconf.CSRF); bool validformpassword = cp.POSTParEqual("pass", Servconf.ControlPassword); if (validformcsrf && validformpassword) { cp.RedirectTo(cp.Url.ToString()); } else { //ControlLoginPage; cp.Output_document = (!valid_CSRF_tok && isValidsession && cp.UrlOriginalString.Contains("CSRF")) ? WebDesigner.invalidAuthTok(cp.Requesting_Host, Servconf) : WebDesigner.ControlNotAllowedIndex(Servconf.CSRF); cp.OutPutData = Encoding.UTF8.GetBytes(cp.Output_document); cp.Output_code = 405; cp.Processing_Type = ProcessingResult.unAuthorized; return; } } else if (cp.UrlOriginalString.Contains("exec") && cp.UrlOriginalString.Contains("com=") && valid_CSRF_tok)//&& !cp.UrlOriginalString.EndsWith(this.AuthToke)) { // sending commands //"http://192.168.1.100:9090/Control/exec?jex&com=msgbx&title=hello+It" if (cp.UrlOriginalString.Contains("?")) { pcs = cp.UrlOriginalString.Split('?'); } else if (cp.UrlOriginalString.Contains("/")) { pcs = cp.UrlOriginalString.Split('/'); } } if (pcs.Length > 0) // receive comands { // "http://192.168.1.100:9090/Control/exec jex&com=msgbx&title=hello+It" string main = pcs[pcs.Length - 1]; if (main.StartsWith(Servconf.CSRF)) { main = main.Substring(Servconf.CSRF.Length); } RemoteCommandExecuter r = new RemoteCommandExecuter(main); r.HandlePointer = handle; r.proceeed(); if (r.RequireUnpreved) { if (frm != null) { if (r.hideOrShowclient()) { frm.Visible = r.formvisible; frm.notifyIcon1.Visible = r.ComType == RemoteCommandType.ShowClient; r.Result = "Form = " + (frm.Visible ? "visible" : "hidden"); r.Result += WebServer.NewLineReplacor; r.Result += "icon = " + (frm.notifyIcon1.Visible ? "visible" : "hidden"); } } } if (r.HasBinaryResult) { cp.OutPutData = r.bytes; cp.Processing_Type = ProcessingResult.Binary; cp.Requesting_Binary_data = true; cp.Request_extn = r.extn; } else { cp.Output_document = (r.Result); } } else if (cp.AllowedTocontrol)// List Command index { cp.Output_document = AppHelper.ReadFileText(Servconf.RootDirectory + "/Control/index.html"); cp.OutPutData = Encoding.UTF8.GetBytes(cp.Output_document); } if (Servconf.SecureControl) { cp.SetResponseHeader("Set-Cookie", WebServer.Control_auth_tokenname + "=" + Servconf.controlsession); } } }
internal static string FileNotFoundTitle_Traditional(string p1, string p2) { return(string.Format("<center><h1>404</h1><h2>Not Found</h2><h4>The Request URL was not found on this Server </h4><hr /><a href='{2}'>Rykon</a> 2.0 (Windows) Server at Host {0} Port {1} </center> </br>{3}", p1, p2, Program.GithUbURl, WebDesigner.TradeMark(" "))); }
public static string _501InternalServerError(string host, string port, ServerConfig s) { return(string.Format( "<center><h1>501</h1><h2>Server Error</h2><h4>Internal Server Error Occured while proccessing your request </br> on this Server </h4><hr /><a href='{2}'>Rykon</a> 2.0 (Windows) Server at Host {0} Port {1} </center> </br>{3}", host, port, Program.GithUbURl, WebDesigner.TradeMark(s.PoweredByEnd))); }