public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { Console.WriteLine("POST request: {0}", p.http_url); string data = inputData.ReadToEnd(); Console.WriteLine(data); try { var log = ToLog(data); var ok_msg = "{\"code\":\"0\",\"msg\":\"ok\"}"; var msg_len = Encoding.UTF8.GetByteCount(ok_msg); ProcessLog(log); p.outputStream.Write("HTTP/1.0 200 OK\r\n"); p.outputStream.Write("Cache-Control: private, max-age=0\r\n"); p.outputStream.Write("Content-Type: text/html\r\n"); p.outputStream.Write(string.Format("Content-Length:{0}\r\n", msg_len)); p.outputStream.Write("Vary: Accept-Encoding\r\n"); p.outputStream.Write("Server: Microsoft-IIS/8.5\r\n\r\n"); p.outputStream.Write(ok_msg); } catch { p.outputStream.Write("HTTP/1.0 404 NOT FOUND\r\n"); p.outputStream.Write("Content-Length:0\r\n"); p.outputStream.Write("Content-Type: text/html\r\n"); p.outputStream.Write("Server: Microsoft-IIS/8.5\r\n\r\n"); } }
private void WriteForm(HttpProcessor p) { string source = "PROGRAM test."; try { StreamReader stream = new StreamReader ("Test.abap"); source = stream.ReadToEnd (); stream.Close (); } catch (Exception e) { } p.writeSuccess (); p.outputStream.WriteLine ("<html>"); p.outputStream.WriteLine ("<head>"); p.outputStream.WriteLine ("<script src=\"client.js\" type=\"text/javascript\"></script>"); p.outputStream.WriteLine ("</head>"); p.outputStream.WriteLine ("<body>"); p.outputStream.WriteLine ("<h1>openABAP</h1>"); p.outputStream.WriteLine ("<form name=screen method=get action=\"\">"); p.outputStream.WriteLine ("<textarea name=source cols=120 rows=30>"); p.outputStream.WriteLine (source); p.outputStream.WriteLine ("</textarea>"); p.outputStream.WriteLine ("<input type=submit name=sy-ucomm value=OK onclick=\"return send();\">"); p.outputStream.WriteLine ("<br/><textarea name=result cols=120 rows=10 readonly></textarea>"); p.outputStream.WriteLine ("</form></body></html>"); }
public override void handleGETRequest(HttpProcessor p) { Console.WriteLine("request: {0}", p.http_url); p.writeSuccess(); //p.outputStream.WriteLine("<html><body><h1>test server</h1>"); //p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString()); //p.outputStream.WriteLine("url : {0}", p.http_url); //p.outputStream.WriteLine("<form method=post action=/form>"); //p.outputStream.WriteLine("<input type=text name=foo value=foovalue>"); //p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>"); //p.outputStream.WriteLine("</form>"); if (p.http_url.Contains("www")) { string appPath = Path.GetDirectoryName(Application.ExecutablePath); string fileName = appPath + "/" + p.http_url.Substring(p.http_url.IndexOf("www")); FileInfo fi = new FileInfo(fileName); using (StreamReader sr = new StreamReader(fi.OpenRead())) { p.outputStream.Write(sr.ReadToEnd()); } } else { System.Web.Script.Serialization.JavaScriptSerializer j = new System.Web.Script.Serialization.JavaScriptSerializer(); p.outputStream.WriteLine(j.Serialize(Temps)); } }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { if (p.http_url.ToLower().Contains("setalarm")) { string args = inputData.ReadToEnd(); System.Web.Script.Serialization.JavaScriptSerializer j = new System.Web.Script.Serialization.JavaScriptSerializer(); SetAlarmArgs saa = j.Deserialize<SetAlarmArgs>(args); if (NewAlarm != null) { if(saa.temp.Length == 0){ NewAlarm(saa.index, null); }else{ double dbl = 0; if(double.TryParse(saa.temp, out dbl)){ NewAlarm(saa.index, dbl); }else{ NewAlarm(saa.index, null); } } } //NewAlarm(p.httpHeaders["temp"]); p.outputStream.WriteLine( "ok"); } else { Console.WriteLine("POST request: {0}", p.http_url); string data = inputData.ReadToEnd(); p.outputStream.WriteLine("<html><body><h1>test server</h1>"); p.outputStream.WriteLine("<a href=/test>return</a><p>"); p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data); } }
public override void handleGETRequest(HttpProcessor processor) { Console.WriteLine("--GET REQUEST BEGIN--"); Console.WriteLine("Request:\n\t" + processor.http_url); Console.WriteLine("Parameter:"); Console.WriteLine("\nSearching Handler.."); foreach (ITaskReciverPlugin cmd in pluginLoader.LoadedPlugins) { if (processor.http_url.StartsWith(cmd.CommandTrigger)) { Console.Write(" Found!"); List<Tuple<string, string>> param = new List<Tuple<string,string>>(); param = GetParams(processor.http_url, cmd.CommandTrigger); param.ForEach(x => Console.WriteLine("\t" + x.Item1 + " = " + ((x.Item2 == "") ? "no value" : x.Item2))); Console.WriteLine("Executing!"); Console.WriteLine("--GET REQUEST END--\n"); cmd.Execute(param); processor.writeSuccess(); return; } } processor.writeFailure(); Console.Write(" Non Found :("); Console.WriteLine("--GET REQUEST END--\n"); }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { Console.WriteLine("--POST REQUEST BEGIN--"); Console.WriteLine("Request:\n\t" + p.http_url); Console.WriteLine("Answer:\n\tPost request not supported."); Console.WriteLine("--POST REQUEST END--\n"); }
private void CopyHeaders(HttpProcessor p, Recipe engine) { foreach (string key in p.HttpHeaders.Keys) { engine.SetMacro("q_" + key, p.HttpHeaders[key]); } int i = p.HttpUrl.IndexOf('?'); string path; if (i == -1) { path = Unescape(p.HttpUrl); } else { path = Unescape(p.HttpUrl.Substring(0, i)); var query = p.HttpUrl.Substring(i + 1); // skip '?' string[] pairs = query.Split('&'); foreach (string s in pairs) { string u = Unescape(s); string[] t = u.Split('='); string key = t[0]; string value = t.Length == 1 ? "" : t[1]; engine.SetMacro("q_" + key, value); // try to avoid clashing with existing macros by prefixing with q_ } } engine.SetMacro("query", path); }
private void Deal(HttpProcessor p,string url, string data,bool isGet){ if(url==null){ return; } if(url=="/"||url.StartsWith("/room.php")||url.StartsWith("/room.json")){ //房间列表 p.writeSuccess(); p.outputStream.Write(GetContent(url, data)); }else if(url.StartsWith("/deck.php")){ //卡片列表 if(data.IndexOf("pwd=caicai")<0){ p.writeFailure(); return; } p.writeSuccess(); string[] args = data.Split('&'); foreach(string a in args){ if(a != null && a.StartsWith("name=")){ int i = a.IndexOf("="); if(i>=0 && i< a.Length-1){ string name = a.Substring(i+1); List<int> cards = GameManager.GameCards(name); foreach(int id in cards){ p.outputStream.WriteLine(""+id); } } } } } else{ p.writeFailure(); } }
public override void HandlePOSTRequest(HttpProcessor p, StreamReader inputData) { //Console.WriteLine("POST request: {0}", p.HttpUrl); var engine = (Recipe)_Engine.Clone(); CopyHeaders(p, engine); engine.SetMacro(Response, inputData.ReadToEnd()); engine.Run(new LineReader(_Script, "POST")); WriteResponse(p, engine); }
public override void HandleGETRequest(HttpProcessor p) { //Console.WriteLine("request: {0}", p.HttpUrl); var engine = (Recipe)_Engine.Clone(); CopyHeaders(p, engine); engine.SetMacro(Response, ""); engine.Run(new LineReader(_Script, "GET")); WriteResponse(p, engine); }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { Console.WriteLine("POST request: {0}", p.http_url); string data = inputData.ReadToEnd(); p.outputStream.WriteLine("<html><body><h1>test server</h1>"); p.outputStream.WriteLine("<a href=/test>return</a><p>"); p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data); }
public override void handleGETRequest(HttpProcessor p) { string urlText = p.http_url; int pos = urlText.IndexOf("&"); if (pos != -1) { urlText = urlText.Substring(0, pos); } if (urlText.EndsWith("/getSnapshot") == true) { p.writeSuccess("application/json"); p.outputStream.Write(_document.SnapshotText); } else if (urlText.Contains("/setSlide/") == true) { string txt = urlText.Substring(urlText.LastIndexOf('/') + 1); int slide; if (Int32.TryParse(txt, out slide) == true) { _document.SetCurrentSlide(slide); } p.writeSuccess("text/html"); p.outputStream.Write("OK"); } else if (urlText.Contains("/startShow/") == true) { string txt = urlText.Substring(urlText.LastIndexOf('/') + 1); int slide; if (Int32.TryParse(txt, out slide) == true) { _document.StartShow(slide); } p.writeSuccess("text/html"); p.outputStream.Write("OK"); } else if (urlText.Contains("/startShow") == true) { _document.StartShow(1); p.writeSuccess("text/html"); p.outputStream.Write("OK"); } else if (urlText.Contains("/nextAnimation") == true) { _document.NextAnimation(); p.writeSuccess("text/html"); p.outputStream.Write("OK"); } }
public void listen() { listener = new TcpListener(server, port); listener.Start(); while (is_active) { TcpClient s = listener.AcceptTcpClient(); HttpProcessor processor = new HttpProcessor(s, this); Thread thread = new Thread(new ThreadStart(processor.process)); thread.Start(); Thread.Sleep(1); } }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { Console.WriteLine("POST request: {0}", p.http_url); var stopWatch = new Stopwatch(); stopWatch.Start(); string data = inputData.ReadToEnd(); var board = JsonConvert.DeserializeObject<DynaShipBoard>(data); var response = new DynaShipAI(board).Process(); p.writeSuccess("application/json"); p.outputStream.Write(String.Format("{{\"x\": {0}, \"y\": {1}}}", response.X, response.Y)); stopWatch.Stop(); Console.WriteLine("Time taken: " + stopWatch.Elapsed); }
public override void handleGETRequest(HttpProcessor p) { Console.WriteLine("request: {0}", p.http_url); p.writeSuccess(); string callback = String.Empty; this.setData(ParseParameters(p.http_url, out callback)); try { p.outputStream.WriteLine(callback + "(\"OK\")"); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); } }
public override void handleGETRequest(HttpProcessor p) { //Console.WriteLine("request: {0}", p.http_url); if(p.http_url==null){ p.writeFailure(); return; } int index=p.http_url.IndexOf("?"); string url=p.http_url; string arg=""; if(index>0){ url=p.http_url.Substring(0, index); if(index+1<p.http_url.Length){ arg=p.http_url.Substring(index+1); } } Deal(p, url, arg, true); }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { Console.WriteLine("POST request: {0}", p.http_url); // write source in post body to server file StreamWriter file = new StreamWriter("temp.abap"); inputData.BaseStream.CopyTo(file.BaseStream); file.Close(); // compile openABAP.Compiler.Compiler compiler = new openABAP.Compiler.Compiler("temp.abap"); try { compiler.Compile(); compiler.Run (); p.outputStream.WriteLine(openABAP.Runtime.Runtime.Output); } catch (openABAP.Compiler.CompilerError ex) { p.outputStream.WriteLine(ex.Message); p.outputStream.WriteLine(compiler.GetErrors()); } // ready //p.writeSuccess(); }
public override void listen() { base.listener = new TcpListener(IPAddress.Any, port); // moualem changed listener.Start(); while (is_active) { TcpClient s = null; try { s = listener.AcceptTcpClient(); } catch { return; } HttpProcessor processor = new HttpProcessor(s, this); Thread thread = new Thread(new ThreadStart(processor.process)); thread.Start(); Thread.Sleep(1); } }
public override void handleGETRequest(HttpProcessor p) { Console.WriteLine ("request: {0}", p.http_url); if (p.http_url.Equals ("/")) { // return form WriteForm (p); } else { //return static file try { FileInfo f = new FileInfo(p.http_url.TrimStart('/')); if (f.Exists) { StreamReader s = new StreamReader(f.FullName); p.writeSuccess(); p.outputStream.Write(s.ReadToEnd()); } else { p.writeFailure(); } } catch(Exception e) { p.writeFailure(); } } }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { Console.WriteLine("POST request: {0}", p.http_url); string data = inputData.ReadToEnd(); p.writeSuccess(); String[] args = data.Split('&'); Dictionary<String, String> act_args = new Dictionary<string, string>(); foreach (String s in args) { String[] arg_pair = s.Split('='); act_args[arg_pair[0]] = arg_pair[1]; } bool success = false; if (p.http_url.Equals("/vote/index.csh")) { String user = act_args["user"]; String pass = act_args["pw"]; String md5pass = Util.getMD5Hash(pass); int uid = Convert.ToInt32(act_args["uid"]); success = pl.vote(uid, um.getUser(user, md5pass)); p.outputStream.WriteLine("<h1>Vote aftersite</h1>"); p.outputStream.WriteLine("<a href=/vote/vote.csh>Vote was {0}</a><p>", (success) ? "successfull" : "not successfull"); } else if (p.http_url.Equals("/vote/pass.csh")) { Dictionary<String, String> vars_to_pass = new Dictionary<string,string>(); vars_to_pass["UID"] = act_args["uid"]; openFile("/vote/pass.csh", p.outputStream, vars_to_pass); } //p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data); }
public override void handleGETRequest(HttpProcessor p) { if (p.http_url.Equals("/Test.png")) { Stream fs = File.Open("../../Test.png", FileMode.Open); p.writeSuccess("image/png"); fs.CopyTo(p.outputStream.BaseStream); p.outputStream.BaseStream.Flush(); } MoaLog.Debug(String.Format("request: {0}", p.http_url)); p.writeSuccess(); p.outputStream.WriteLine("<html><body><h1>test server</h1>"); p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString()); p.outputStream.WriteLine("url : {0}", p.http_url); p.outputStream.WriteLine("<form method=post action=/form>"); p.outputStream.WriteLine("<input type=text name=foo value=foovalue>"); p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>"); p.outputStream.WriteLine("</form>"); }
public override void handleGETRequest(HttpProcessor p) { var reader = new StreamReader("index.html"); var content = reader.ReadToEnd(); var length = Encoding.UTF8.GetByteCount(content); p.outputStream.Write("HTTP/1.0 200 OK\r\n"); p.outputStream.Write("Cache-Control: private, max-age=0\r\n"); p.outputStream.Write("Content-Type: text/html\r\n"); p.outputStream.Write(string.Format("Content-Length:{0}\r\n", length)); p.outputStream.Write("Vary: Accept-Encoding\r\n"); p.outputStream.Write("Server: Microsoft-IIS/8.5\r\n\r\n"); p.outputStream.Write(content); reader.Close(); if (p.http_url.Equals("/Test.png")) { } Console.WriteLine("request: {0}", p.http_url); }
public abstract void handlePOSTRequest(HttpProcessor p, StreamReader inputData);
public override void handleGETRequest(HttpProcessor p) { if (p.http_url.Equals ("/Test.png")) { Stream fs = File.Open("../../Test.png",FileMode.Open); p.writeSuccess("image/png",fs.Length); p.outputStream.Flush(); fs.CopyTo (p.outputStream.BaseStream); p.outputStream.BaseStream.Flush (); fs.Close(); return; } if (p.http_url.StartsWith ("/m3u8")) { string path = "http://scgd-m3u8.joyseetv.com:10009"; path += p.http_url; path += GenKey(); if (p.http_url == pid && DateTime.Now.Subtract(lastQueryTime).TotalSeconds < 10) { p.writeSuccess("application/vnd.apple.mpegurl", length); p.outputStream.Flush(); Stream fs2= new MemoryStream(copyfsbytes, 0, (int)length); fs2.CopyTo(p.outputStream.BaseStream); p.outputStream.BaseStream.Flush(); fs2.Close(); Console.WriteLine("1:"+lastQueryTime + DateTime.Now); return; } else { copyfsbytes = new byte[5000]; } pid = p.http_url; lastQueryTime = DateTime.Now; Console.WriteLine("2:" + lastQueryTime + DateTime.Now); // The downloaded resource ends up in the variable named content. // Initialize an HttpWebRequest for the current URL. var webReq = (HttpWebRequest)WebRequest.Create(path); webReq.UserAgent = "Android/TVPlayerSDK/1.0"; WebResponse response = webReq.GetResponse(); Stream fs = webReq.GetResponse().GetResponseStream(); fs.Read(copyfsbytes, 0, (int)response.ContentLength); fs = new MemoryStream(copyfsbytes,0, (int)response.ContentLength); length = response.ContentLength; p.writeSuccess("application/vnd.apple.mpegurl", response.ContentLength); p.outputStream.Flush(); fs.CopyTo (p.outputStream.BaseStream); p.outputStream.BaseStream.Flush (); fs.Close(); return; } Console.WriteLine("request: {0}", p.http_url); p.writeSuccess(); p.outputStream.WriteLine("<html><body><h1>test server</h1>"); p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString()); p.outputStream.WriteLine("url : {0}", p.http_url); p.outputStream.WriteLine("<form method=post action=/form>"); p.outputStream.WriteLine("<input type=text name=foo value=foovalue>"); p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>"); p.outputStream.WriteLine("</form>"); }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { //Console.WriteLine("POST request: {0}", p.http_url.Substring(1)); string data = inputData.ReadToEnd(); lastrequest = HttpUtility.UrlDecode(data).Substring(data.IndexOf("=")+1); NotifyPostRequest(p.http_url.Substring(1), lastrequest); LandingPage(p); }
public abstract void handleGETRequest(HttpProcessor p);
private void LandingPage(HttpProcessor p) { p.writeSuccess(); Stream fs = File.Open("../../../html/index.html", FileMode.Open); StreamReader reader = new StreamReader(fs); string html = reader.ReadToEnd(); fs.Close(); html = html.Replace("#UTTERANCE#", lastrequest); string addString; addString = ""; foreach (string s in Targets) addString += htmlListElement(s); html = html.Replace("#TARGETS#", addString); addString = ""; foreach (string s in Instructions) addString += htmlListElement(s); html = html.Replace("#INSTRUCTIONS#", addString); /*p.outputStream.WriteLine("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"); p.outputStream.WriteLine("<html xmlns=/'http://www.w3.org/1999/xhtml'>"); p.outputStream.WriteLine("<head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /><title>EMOTE Utterance Tester</title></head><body>"); p.outputStream.WriteLine("<form name='input' action='performUtterance' method='post'><textarea type='text' name='utterance' rows='10' cols='150'>" + lastrequest + "</textarea><br><input type='submit' value='Perform'></form><br>"); p.outputStream.WriteLine("Available Targets:<br>"); foreach (string s in Targets) p.outputStream.WriteLine(s + "<br>"); p.outputStream.WriteLine("</body></html>");*/ p.outputStream.WriteLine(html); p.outputStream.BaseStream.Flush(); }
public override void handleGETRequest (HttpProcessor p) { LandingPage(p); }
private void auth_reg_radius(HttpProcessor p) { string pass; do { pass = Simbol(8); } while (formvalidation.is_unique(pass, "radcheck.Value")); connect.insert_update("INSERT INTO `users` (`login`, `e-mail`, `fio`, `name_s_net`, `rules`) VALUES(@0, @1, @2, @3, '001');", new string[] { }); }
public void registration(HttpProcessor p, string[] route) { //Здесь мы видим как применяеться проверка данных //Способ : p.InputPOST("Password") != "null" & p.InputPOST("Username") != "null" //показывает нам как он много занимет места в коде и какой не практичный //способ formvalidation.add(p.InputPOST("Password"), "num|required"); //показывает нам как можно выполнить любую проверку текста просто указывая их //здесь мы задали чтобы данные не были пустыми и содержали целочисленный тип formvalidation.add("Password", "required|num"); //здесь мы задали чтобы данные не были пустыми и содержали буквы англ и русс //также добавил проверку на уникальность в БД is_unique[users.login] users ->БД login -> поле где проверить, //ответ false если в БД уже такое есть. formvalidation.add("Username", "required|alpha|is_unique[users.login]"); //здесь мы запускаем его и узнаем можно продолжать работать или просто пустить клиента на страницу registration if (formvalidation.Start(p)) { //старый способ проверки кода просто на существование строк if (p.InputPOST("Password") != "null" & p.InputPOST("Username") != "null") if (connect.insert_update("INSERT INTO `users` (`login`, `pass`, `rules`) VALUES(@0, @1, '001');", new string[] { p.InputPOST("Username"), p.InputPOST("Password") })) p.redirect("http://localhost:8080/login"); } }
public override void handleGETRequest(HttpProcessor p) { Console.WriteLine("GET request: {0}", p.http_url); p.writeSuccess(); p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString()); }