예제 #1
0
        /**
         * Constructor
         * parse filename
         * @param path
         */
        public MyFile(string path)
        {
            fullPath = path;
            if (!Path.HasExtension(fullPath))
            {
                string   orginalPath  = fullPath;
                string[] defaultPages = AppConfigProcessor.Get().DefaultPages.Split(new string[] { ";" }, StringSplitOptions.None);
                Boolean  result       = false;
                foreach (string i in defaultPages)
                {
                    fullPath = orginalPath + i;
                    result   = this.checkIfIndexPageExists(fullPath);
                    if (result == true)
                    {
                        break;
                    }
                }
            }
            else
            {
                indexPage = false;
            }

            pathParts = fullPath.Split('/');
            if (pathParts.Length > 0)
            {
                name = pathParts[pathParts.Length - 1];
            }
            else
            {
                name = "";
            }
        }
예제 #2
0
        public void HandlePost(Request request, string requestedFile)
        {
            /*@ todo Logfile leeg maken */
            System.IO.File.WriteAllText(ConfigurationManager.AppSettings.Get("log"), string.Empty);

            string path = "http://" + ConfigurationManager.AppSettings.Get("ipadress") + ":"
                          + AppConfigProcessor.Get().WebPort + "/admin/settings.html";

            throw new RedirectException(path);
        }
        public void HandlePost(Request request, string requestedFile)
        {
            AppConfigProcessor.Get().WebRoot           = request.formData["webroot"];
            AppConfigProcessor.Get().DefaultPages      = request.formData["defaultpage"];
            AppConfigProcessor.Get().DirectoryBrowsing = Convert.ToBoolean(request.formData["directoryBrowsing"]);
            AppConfigProcessor.Save();

            string path = "http://" + ConfigurationManager.AppSettings.Get("ipadress") + ":"
                          + AppConfigProcessor.Get().WebPort + "/admin/settings.html";

            throw new RedirectException(path);
        }
예제 #4
0
        public Server()
        {
            Int32      port      = AppConfigProcessor.Get().WebPort;
            IPAddress  localAddr = IPAddress.Parse(ConfigurationManager.AppSettings.Get("ipadress"));
            IPEndPoint endPoint  = new IPEndPoint(localAddr, port);

            listenSocket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            listenSocket.Bind(endPoint);
            Thread listenerThread = new Thread(Start);

            listenerThread.Start();
        }
예제 #5
0
        public void HandlePost(Request request, string requestedFile)
        {
            string username = request.formData["Username"];
            string password = request.formData["Password"];

            if (_authentication.AuthenticateUser(username, password))
            {
                string path = "http://" + ConfigurationManager.AppSettings.Get("ipadress") + ":"
                              + AppConfigProcessor.Get().WebPort + "/admin/settings.html";

                throw new RedirectException(path);
            }
            else
            {
                string path = "http://" + ConfigurationManager.AppSettings.Get("ipadress") + ":"
                              + AppConfigProcessor.Get().WebPort + "/admin/index.html";

                throw new RedirectException(path);
            }
        }
 protected void createForm()
 {
     content += "<form METHOD=\"POST\" ACTION=\"/admin/settings.html\">";
     content += "    <H3>Superserver!</H3>";
     content += "    <p>";
     content += "        <table>";
     content += "            <tr>";
     content += "                <td>Webport:</td>";
     content += "                <td><INPUT TYPE=\"TEXT\" NAME=\"webport\" VALUE=\"" + AppConfigProcessor.Get().WebPort + "\" SIZE=\"25\" MAXLENGTH=\"150\" disabled></td>";
     content += "            </tr>";
     content += "            <tr>";
     content += "                <td>Webroot:</td>";
     content += "                <td><INPUT TYPE=\"TEXT\" NAME=\"webroot\" VALUE=\"" + encodeText(AppConfigProcessor.Get().WebRoot) + "\" SIZE=\"25\" MAXLENGTH=\"150\"></td>";
     content += "            </tr>";
     content += "            <tr>";
     content += "                <td>Default page:</td>";
     content += "                <td><INPUT TYPE=\"TEXT\" NAME=\"defaultpage\" VALUE=\"" + encodeText(AppConfigProcessor.Get().DefaultPages) + "\" SIZE=\"25\" MAXLENGTH=\"150\"></td>";
     content += "            </tr>";
     content += "            <tr>";
     content += "                <td>Directory browsing:</td>";
     if (AppConfigProcessor.Get().DirectoryBrowsing)
     {
         content += "                <td><input type='radio' name='directoryBrowsing' value='true' checked> Ja ";
         content += "                <input type='radio' name='directoryBrowsing' value='false' > Nee <br></td>";
     }
     else
     {
         content += "                <td><input type='radio' name='directoryBrowsing' value='true' > Ja ";
         content += "                <input type='radio' name='directoryBrowsing' value='false' checked> Nee <br></td>";
     }
     content += "            </tr>";
     content += "        </table>";
     content += "    </p>";
     content += "    <p>";
     content += "        <a href='/admin/log.html'>Show log</a>";
     content += "        <INPUT TYPE=\"submit\" VALUE=\"Save\">";
     content += "        <INPUT TYPE=\"submit\" VALUE=\"Cancel\">";
     content += "    </p>";
     content += "</form>";
 }
예제 #7
0
        public void Run()
        {
            MyFile myfile   = null;
            String HtmlPage = null;

            try
            {
                socket_in  = socket;
                socket_out = socket;

                request = new Request(socket_in, remoteIpEndPoint.ToString());

                string       actualPath   = request.path;
                IPageHandler _pageHandler = _pageHandlerFactory.Create(actualPath);

                if (_pageHandler != null)
                {
                    // Map and parse the relative path to get the actual file info
                    string requestedFile = ConfigurationManager.AppSettings.Get("configpath") + actualPath;

                    switch (request.command)
                    {
                    case "GET":
                        HtmlPage = _pageHandler.HandleGet(request, requestedFile);
                        break;

                    case "POST":
                        _pageHandler.HandlePost(request, requestedFile);
                        break;
                    }
                }
                else
                {
                    myfile = new MyFile(AppConfigProcessor.Get().WebRoot + request.getPath());
                }

                //System.Console.WriteLine(myfile.indexPageExists());

                if (AppConfigProcessor.Get().DirectoryBrowsing == true && (myfile != null && myfile.indexPageExists() == true))
                {
                    HtmlPage directoryList = new DirectoryList(AppConfigProcessor.Get().WebRoot,
                                                               request.getPath().Substring(0, request.getPath().LastIndexOf('/')));
                    writeString(directoryList.getHtmlPage());
                }
                else
                {
                    if (HtmlPage is string)
                    {
                        writeString(HtmlPage);
                    }
                    else
                    {
                        writeFile(myfile);
                    }
                }
            }
            catch (RedirectException e)
            {
                Console.WriteLine(e);
                writeRedirectString(e.getPath(), 302);
            }
            catch (BadRequestException e)
            {
                Console.WriteLine(e);
                myfile = new MyFile((new Error(400)).getHtmlPath(ConfigurationManager.AppSettings.Get("configpath")));
                writeFile(myfile, 400);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e);
                myfile = new MyFile((new Error(404)).getHtmlPath(ConfigurationManager.AppSettings.Get("configpath")));
                writeFile(myfile, 404);
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
                myfile = new MyFile((new Error(500)).getHtmlPath(ConfigurationManager.AppSettings.Get("configpath")));
                writeFile(myfile, 500);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            if (myfile != null)
            {
                myfile.Close();
            }
        }