public static string invalidAuthTok(string main,ServerConfig s ) { if (s.InstalledHostFound(s,s.GET_InstalledHost_Dirname(main))) main = "http://"+main+":"+s.Port; else main = "http://"+s.GetHostAndPort(); return "Your Broswer sent outdated parameters <a href='"+WebServer.EncodeHtmlChars(main)+"/' >Go To Main Page</a>"; }
internal bool InstalledHostFound(ServerConfig s,string hn) { string k = s.RootDirectory + "\\" + hn; k = k.Replace("\\\\", "\\"); return AppHelper.ExistedDir(k); }
private void LoadServerConfiguration() { string ServerConfigPath = Application.StartupPath + "\\Req\\httpd.conf".Replace("\\\\", "\\"); this.Servconf = new ServerConfig(ServerConfigPath); cp_private.Checked = !Servconf.IsPublicServer; txbxServerPass.Text = Servconf.ServerAutPass; TxbxServerId.Text = Servconf.ServerAuthId; TxbxServerId.Text = Servconf.ServerAuthId; txbxServerPass.Text = Servconf.ServerAutPass; txbx_pass_Control.Text = Servconf.ControlPassword; txbx_pass_Listen.Text = Servconf.ListenPassword; txbx_pass_Stream.Text = Servconf.StreamPassword; txbx_pass_Upload.Text = Servconf.UploadPassword; txbx_pass_video.Text = Servconf.VideoPassword; cb_secure_control.Checked = Servconf.SecureControl; cb_secure_listen.Checked = Servconf.SecureListen; cb_secure_stream.Checked = Servconf.SecureStream; cb_secure_upload.Checked = Servconf.SecureUpload; cb_secure_video.Checked = Servconf.SecureVideo; videoToolStripMenuItem.Checked =videoonToolStripMenuItem1.Checked= Servconf.EnableVideo; offvideoToolStripMenuItem1.Checked = !Servconf.EnableVideo; listenToolStripMenuItem.Checked = onlistenToolStripMenuItem.Checked = Servconf.EnableListen; offlistenToolStripMenuItem.Checked = !Servconf.EnableListen; int port = this.Servconf.Port; if (port > 0 && port <= 65353) this.NumPort.Value = port; string v= Servconf.GetMainApp(); gpxmainapp.Text = v; comboBoxmainapp.SelectedItem = v; labelmainapp.Text = v + " url"; }
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)); }
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; }
private static string PoweredBy(ServerConfig Config) { return PoweredByConstant.Replace("YasserGersy", Config.PoweredByEnd); }
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 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))); }
private static string PoweredBy(ServerConfig Config) { return(PoweredByConstant.Replace("YasserGersy", Config.PoweredByEnd)); }
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); } }
public static void executeController(ref ServerConfig Servconf, ref RykonProcess cp, ref bool valid_CSRF_tok, ref bool isValidsession, IntPtr handle , FormMain frm ) { if (cp.LocalPath.EndsWith("/Control/thumb.png")) { cp.Requesting_Binary_data = true; cp.OutPutData = AppHelper.ReadFileBts(cp.RequestPage); return; } else if (!Servconf.EnableControler) // disabled { cp.Output_document = WebDesigner.BuiltInDisabled("controller"); cp.LoadMaster = true; } 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_token_name, 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.SetResponseCooke(WebServer.Control_auth_token_name , 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_token_name + "=" + Servconf.controlsession); } }