Example #1
0
 public override void handleGETRequest(RequestHandler p, string url)
 {
     try
     {
         string path = router.CheckRoutes(url, p);
         if (path != null)
         {
             // check if it has parameters from get post
             if (path.Contains('?'))
             {
                 // parses the get values
                 Header header = new ResponseHeader();
                 Dictionary<string, string> data = ParseGetData(url);
                 byte[] bytes = WritePost(data, path.Split('?')[0], p.stream);
                 string extension = GetFileExtensionFromString(path);
                 header.SetHeader("ContentLength", bytes.Length.ToString());
                 header.SetHeader("ContentType", ext.extensions.Where(x => x.ext == extension).FirstOrDefault().content + "; charset=UTF-8 ");
                 SendContentHandler.SendHeader(header, p.stream);
                 SendContentHandler.SendContent(bytes, p.stream);
             }
             else
                 WritePost(p.stream, path);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("File not Found");
         errorHandler.SendErrorPage(p.stream, 404);
     }
     m_ServerSemaphore.Release();
 }
Example #2
0
 /// <param name="inputData">User en Password van form</param>
 public void Authenticate(RequestHandler r, StreamReader inputData)
 {
     Dictionary<string, string> data = ParsePostData(inputData);
     string user = data.ElementAt(0).Value;
     if (UserAuthentication.Authenticate(user, data.ElementAt(1).Value))
     {
         SessionManager.addSession(user,r.http_clientIp);
         GetLoginAuthentication(r.stream, true, user);
     }
     else
         GetLoginAuthentication(r.stream, false, user);
 }
Example #3
0
 public override void handlePOSTRequest(RequestHandler p, StreamReader inputData, string url)
 {
     // parses the post data form the request
     Header header = new ResponseHeader();
     string path = router.CheckRoutes(url, p);
     Dictionary<string, string> data = ParsePostData(inputData);
     byte[] bytes = WritePost(data, path, p.stream);
     string extension = GetFileExtensionFromString(url);
     header.SetHeader("ContentLength", bytes.Length.ToString());
     header.SetHeader("ContentType", ext.extensions.Where(x => x.ext == extension).FirstOrDefault().content + "; charset=UTF-8 ");
     SendContentHandler.SendHeader(header, p.stream);
     SendContentHandler.SendContent(bytes, p.stream);
     m_ServerSemaphore.Release();
 }
Example #4
0
        /// <summary>
        /// Listens for incoming connections
        /// </summary>
        public void Listen()
        {
            listener = new TcpListener(IPAddress.Parse("127.0.0.1"), port);
            listener.Start();
            while (is_active)
            {
                Console.WriteLine("Waiting for connection...");
                TcpClient client = listener.AcceptTcpClient();

                m_ServerSemaphore.WaitOne();
                Stream stream = GetStream(client);

                String ip = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
                RequestHandler newRequest = new RequestHandler(ip, this, stream);
                Thread Thread = new Thread(new ThreadStart(newRequest.Process));
                Thread.Name = "HTTP Request";
                Thread.Start();
            }
        }
Example #5
0
 public abstract void handlePOSTRequest(RequestHandler p, StreamReader inputData, string url);
Example #6
0
 public abstract void handleGETRequest(RequestHandler p, string url);
Example #7
0
 /// <summary>
 /// Handles the Get Request  and releases thread when done
 /// </summary>
 /// <param name="p">The current RequestHandler</param>
 /// <param name="url">Given Get url</param>
 public override void handleGETRequest(RequestHandler p, string url)
 {
     try
     {
         string route = router.CheckRoutes(url, p);
         if (route != null)
             WritePost(p.stream, route);
     }
     catch (IOException ex)
     {
         Console.WriteLine("File not Found");
     }
     m_ServerSemaphore.Release();
 }
Example #8
0
 public void PostControlForm(RequestHandler r, StreamReader inputData, string url)
 {
     //Console.WriteLine("POST request: {0}", p.http_url);
     Dictionary<string, string> data = ParsePostData(inputData);
     UpdateSettingsModel(data);
     string route = router.CheckRoutes(url, r);
     WritePost(r.stream, route);
 }
Example #9
0
 /// <summary>
 /// Handles the post request
 /// </summary>
 /// <param name="p">Current RequestHandler</param>
 /// <param name="inputData"></param>
 /// <param name="url"></param>
 public override void handlePOSTRequest(RequestHandler p, StreamReader inputData, string url)
 {
     string bs = "";
     p.requestHeader.Headers.TryGetValue("Cookie", out bs);
     // handle ajax calls
     if (router.CheckAjaxRoutes(url) != null)
     {
         switch (router.CheckAjaxRoutes(url))
         {
             case "FormValues":
                 if (SessionManager.SessionExists(bs,p.http_clientIp))
                     GetFormValues(p.stream, url);
                 break;
             case "LogFiles":
                 if (SessionManager.SessionExists(bs,p.http_clientIp)&&SessionManager.isAdmin(bs))
                     OpenLogFile(p.stream);
                 break;
             case "LoginValues":
                 Authenticate(p, inputData);
                 break;
             case "LogoutValues":
                 doLogout(p.stream,inputData);
                 break;
         }
     }
     else
     {
         if (SessionManager.SessionExists(bs,p.http_clientIp) && SessionManager.isAdmin(bs))
         {
             PostControlForm(p, inputData, url);
         }
         else
         {
             string route = router.CheckRoutes(url, p);
             WritePost(p.stream, route);
         }
         // handle form post
     }
     m_ServerSemaphore.Release();
 }