public string loginstatus(ClientWebRequest request)
        {
            if (request.QueryString.ContainsKey("sessionID"))
            {
                string sesid = request.QueryString["sessionID"];
                if (!sessions.ContainsKey(request.QueryString["sessionID"]))
                {
                    sessions.Add(sesid, new SessionInformation());
                }
                SessionInformation session = sessions[sesid];

                if(request.Method == "POST") {
                Dictionary<string,string> formdata = request.Form;

                    Stream fstr = File.Open(formdata["username"],FileMode.OpenOrCreate);
                try {
                    session.fs = new IndexedFS(new Filesystem(fstr,formdata["pswd"],1024*1024,1024*1024*512));
                    //return "Authorization success!";
                    session.UserName = formdata["username"];
                        bool dirsetup = false;
                        foreach(string et in session.fs.Directories) {
                        if(et == formdata["username"]) {
                            dirsetup = true;
                            }
                        }
                        if(!dirsetup) {
                        session.fs.CreateDirectory(formdata["username"]);
                        }
                    session.fs.Commit();

                    }catch(Exception er) {
                    fstr.Close();
                        return "Invalid password";
                    }
                }
                if(session.fs !=null) {
                ClientHttpResponse response = new ClientHttpResponse();
                    request.ContinueProcessing = false;
                    response.Redirect("profile.html?sessionID="+request.QueryString["sessionID"],false,request.stream);

                }
                return sesid;
            }
            else
            {
                return "";
            }
        }
        public string loginstatus(ClientWebRequest request)
        {
            if (request.QueryString.ContainsKey("sessionID"))
            {
                string sesid = request.QueryString["sessionID"];
                if (!sessions.ContainsKey(request.QueryString["sessionID"]))
                {
                    sessions.Add(sesid, new SessionInformation());
                }
                SessionInformation session = sessions[sesid];

                if(request.Method == "POST") {
                Dictionary<string,string> formdata = request.Form;
                try {
                        using(Stream fstr = File.Open(Environment.CurrentDirectory+"\\admin",FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.ReadWrite)) {
                        Filesystem msys = new Filesystem(fstr,formdata["pswd"],16384,1024*1024*5);
                            msys.Dispose();
                        session.isAdminAuthenticated = true;
                        }

                    }catch(Exception er) {
                        return "Login failure";
                    }
                }
                if(session.isAdminAuthenticated) {
                ClientHttpResponse response = new ClientHttpResponse();
                response.Redirect("serverAdmin.htm?sessionID="+request.QueryString["sessionID"],false,request.stream);
                request.ContinueProcessing = false;
                }
                return "";
            }
            else
            {
                return "";
            }
        }
 public string securePage(ClientWebRequest request)
 {
     SessionInformation session = sessions[sessionKey(request)];
     if(!session.isAdminAuthenticated) {
     ClientHttpResponse response = new ClientHttpResponse();
         response.Redirect("index.htm?sessionID="+sessionKey(request),false,request.stream);
         request.ContinueProcessing = false;
     }
     return "";
 }
Exemple #4
0
        public void NtfyConnection(ClientWebRequest request)
        {
            string appname;
                if(request.UnsanitizedRelativeURI.Length>5) {
                int el;
                if(request.UnsanitizedRelativeURI.IndexOf("/",request.UnsanitizedRelativeURI.IndexOf("/")+1) <0) {
                el = request.UnsanitizedRelativeURI.Length-(request.UnsanitizedRelativeURI.IndexOf("/")+1);
                }else {
                el = request.UnsanitizedRelativeURI.IndexOf("/",request.UnsanitizedRelativeURI.IndexOf("/")+1)-1;
                }
                appname = request.UnsanitizedRelativeURI.Substring(request.UnsanitizedRelativeURI.IndexOf("/")+1,el);
                }else {
            ClientHttpResponse response = new ClientHttpResponse();
                response.Redirect(startupApplication,true,request.stream);
                request.ContinueProcessing = false;
                return;
            }
                doRequest:
                if(request.ProxyConnection) {
            OpenNetProxySvc.ProxyHandler.ProcessRequest(request);
            }else {
                if(instances.ContainsKey(appname)) {
                try {
                    instances[appname].ntfyRequest(request);
                    if(request.UnmanagedConnection) {
                        Console.WriteLine("Unmanaged connection found");
                    return;
                    }
                }catch(RemotingException er) {
                Console.WriteLine("Remoting instance for "+appname+" has died. Respawning application....");
                    lock(instances) {
                    AppDomain.Unload(domains[appname]);
                        instances.Remove(appname);
                        domains.Remove(appname);
                    }
                    goto doRequest;
                }
                    }else {
                //Search for application
                    bool isfound = false;
                    foreach(string et in Directory.GetDirectories(Environment.CurrentDirectory)) {
                    string it = et.Replace("\\","/");
                    string ix = it.Substring(it.LastIndexOf("/")+1);

                    if(ix == appname) {
                        isfound = true;
                        }
                    }
                    if(!isfound) {
                    StreamWriter mwriter = new StreamWriter(request.stream);
                        mwriter.WriteLine("<html>");
                        mwriter.WriteLine("<head>");
                        mwriter.WriteLine("<title>Application not found</title>");
                        mwriter.WriteLine("</head>");
                        mwriter.WriteLine("<body>");
                        mwriter.WriteLine("<h1>Unable to locate application "+appname+"</h1><hr />The application you are looking for does not exist on this server.");
                        mwriter.WriteLine("</body>");
                        mwriter.WriteLine("</html>");
                        mwriter.Flush();
                    }else {
                    Stream mstr = File.Open(Environment.CurrentDirectory+"\\"+appname+"\\"+appname+".dll",FileMode.Open);
                        byte[] buffer = new byte[mstr.Length];
                        mstr.Read(buffer,0,buffer.Length);
                    mstr.Close();
                        LoadApplication(buffer,appname);
                        goto doRequest;
                    }
                }
                }
            byte[] mbuffer = new byte[16384];
            int total = 0;
            try {
            if(request.ExpectedContentLength>0) {
            while(true) {
            int count = request.stream.Read(mbuffer,0,mbuffer.Length);

                        total+=count;
                if(count <=0 || total>=request.ExpectedContentLength) {
                break;
                }

            }
            }
            }catch(Exception er) {
            }

                request.stream.Dispose();
        }