Exemplo n.º 1
0
 public virtual void Else(RequestArgs args)
 {
     if (args.Method == "CREATE")
     {
         this.Create(args);
     }
 }
Exemplo n.º 2
0
 protected RequestArgs(string method, Service service, JValue value, RequestArgs parent)
 {
     Url         = parent.Url;
     User        = parent.User;
     Server      = parent.Server;
     context     = parent.context;
     Path        = parent.Path;
     Service     = service;
     Method      = method.ToUpper();
     _bodyASJson = value;
     _jcontext   = parent._jcontext;
 }
Exemplo n.º 3
0
 protected virtual void OnTropCharche(IAsyncResult ar)
 {
     try
     {
         var x = Listener.EndGetContext(ar);
         RequestArgs.SendAlertError(x, "Wait ...", "Le serveur est trop charger");
     }
     catch (Exception e)
     {
         Ionsole.Write(e);
     }
 }
Exemplo n.º 4
0
 public virtual bool Options(RequestArgs args)
 {
     if (AllowCrossOrigin)
     {
         var response = args.context.Response;
         response.AddHeader("Access-Control-Allow-Headers", "*");
         response.AddHeader("Access-Control-Allow-Methods", "*");
         response.AddHeader("Access-Control-Max-Age", "1728000");
         response.AppendHeader("Access-Control-Allow-Origin", "*");
         return(true);
     }
     return(true);
 }
Exemplo n.º 5
0
        public virtual bool AnotherAccountIsStillOpened(HttpListenerContext context, User user)
        {
            if ((DateTime.Now - user.LastAccess).TotalMinutes > 15)
            {
                return(false);
            }

            var serviceArgs = RequestArgs.NewRequestArgs(context, this.server, user);
            var t           = new SecurityAccountRequest
            {
                OriginalIP = user.Address?.ToString(),
                YourIP     = context.Request.RemoteEndPoint.ToString(),
                Wait       = 300000,
                IsSuccess  = false
            };

            serviceArgs.Send(t);
            return(true);
        }
Exemplo n.º 6
0
        protected virtual bool OnRequest(HttpListenerContext context)
        {
            if (context.Request.HttpMethod == "OPTIONS")
            {
                ApisHandler.RespondOptions(context);
                return(true);
            }
            context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
            var user = ApiHandler.CheckAuth(context, out bool logged);

            if (user != null || logged)
            {
                var serviceArgs = RequestArgs.NewRequestArgs(context, this, user);

                if (serviceArgs.Service == null)
                {
                    serviceArgs.SendCode(HttpStatusCode.OK);
                }
                else if (serviceArgs.Service.CanbeDelayed(serviceArgs))
                {
                    CommandsQueue.Add(new CommandsParam(serviceArgs, ExecuteCommand, this));
                    return(false);
                }
                else
                {
                    using (serviceArgs)
                    {
                        Api(serviceArgs);
                        return(!serviceArgs.IsBusy);
                    }
                }
            }
            else
            {
                context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
            }
            return(true);
        }
Exemplo n.º 7
0
        public virtual bool GetUserFromIdentAndData(RequestArgs args, out User user)
        {
            var login = (ILogin)args.BodyAsJson;

            if (login != null)
            {
                var       identification = login.Identification;
                var       username       = login.Username;
                IPAddress ipaddress      = IPAddress.None;

                var pssword = login.Pwd;
deb:
                if (string.IsNullOrEmpty(username) == false)
                {
                    if (Users.TryGetValue(username, out user))
                    {
                        return(user.Password == pssword ? true : login.RegeneratePwd(user.Password));
                    }
                }

                if (!string.IsNullOrEmpty(identification))
                {
                    var ds = RequestArgs.aes.Decrypt(identification).Split('\0');
                    if (ds.Length == 3)
                    {
                        username = ds[1];
                        pssword  = ds[0];
                        if (IPAddress.TryParse(ds[2], out ipaddress))
                        {
                            identification = null;
                            goto deb;
                        }
                    }
                }
            }
            user = null;
            return(args.SendAlert("Authentication", "Le Compt soit est desactiver ou est n'est pas enregistrer<br><br>Contacter l'admin", "OK", false));
        }
Exemplo n.º 8
0
        public virtual bool GetUserFromCookie(RequestArgs args, out User user)
        {
            var cc = getId(args.context);

            if (cc != null)
            {
                if (_connectedUsers.TryGetValue(cc, out user) && user.AllowSigninById)
                {
                    if (cc == user.CurrentId)
                    {
                        return(true);
                    }
                    foreach (System.Net.Cookie ck in args.context.Request.Cookies)
                    {
                        ck.Expired = true;
                        args.context.Response.SetCookie(ck);
                    }
                    user.IsLogged = false;
                }
            }
            user = null;
            return(false);
        }
Exemplo n.º 9
0
 public bool Logout(IClient client, RequestArgs args)
 {
     return(_connectedUsers.Remove(args.User.UserName));
 }
Exemplo n.º 10
0
        public virtual void Exec(RequestArgs args)
        {
            //if (AllowCrossOrigin) args.context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
            if (!CheckAccess(args))
            {
                return;
            }
            switch (args.Method)
            {
            case "GET":
                Get(args);
                break;

            case "POST":
                Post(args);
                break;

            case "PUT":
                Put(args);
                break;

            case "DELETE":
                Delete(args);
                break;

            case "CREATE":
                Create(args);
                return;

            case "UPDATE":
                Update(args);
                break;

            case "SUPDATE":
                SUpdate(args);
                break;

            case "OPTIONS":
                Options(args);
                return;

            case "PRINT":
                Print(args);
                return;

            case "SET":
                Set(args);
                return;

            case "HEAD":
                Head(args);
                return;

            case "OPEN":
                Open(args);
                return;

            default:
                Else(args);
                return;
            }
        }
Exemplo n.º 11
0
 public virtual bool SUpdate(RequestArgs args)
 {
     return(false);
 }
Exemplo n.º 12
0
 public abstract void BlockUser(RequestArgs args);
Exemplo n.º 13
0
 public virtual bool Post(RequestArgs args)
 {
     return(false);
 }
Exemplo n.º 14
0
 public virtual void Head(RequestArgs args)
 {
 }
Exemplo n.º 15
0
 protected virtual bool Set(RequestArgs args) => true;
Exemplo n.º 16
0
 protected virtual bool Open(RequestArgs args)
 {
     return(true);
 }
Exemplo n.º 17
0
 public abstract bool LockUser(RequestArgs args, ILogin e);
Exemplo n.º 18
0
 public virtual bool CanbeDelayed(RequestArgs args) => false;
Exemplo n.º 19
0
 public virtual bool CheckAccess(RequestArgs args)
 {
     return(true);
 }
Exemplo n.º 20
0
 public virtual bool Print(RequestArgs args) => true;
Exemplo n.º 21
0
 public abstract bool ValidateUser(RequestArgs args, ILogin e);
Exemplo n.º 22
0
 public virtual void Api(RequestArgs args) => args.Service?.Exec(args);
Exemplo n.º 23
0
 public abstract bool DeleteUser(RequestArgs args, ILogin e);
Exemplo n.º 24
0
 protected virtual bool Close(RequestArgs args)
 {
     return(true);
 }
Exemplo n.º 25
0
 public abstract bool SignupAgent(RequestArgs args, out User user);
Exemplo n.º 26
0
 public virtual bool Update(RequestArgs args) => false;
Exemplo n.º 27
0
 public virtual bool Delete(RequestArgs args) => false;
Exemplo n.º 28
0
 public virtual void Put(RequestArgs args)
 {
 }
Exemplo n.º 29
0
        public virtual bool PublicApi(HttpListenerContext context, string raw)
        {
            switch (context.Request.Url.LocalPath.ToLower())
            {
            case "/~checklogging":
                IsLoged(context);
                break;

            case "/~login":
                Login(context);
                break;

            case "/~signup":
                Signup(context);
                break;

            case "/~signout":
                Signout(context);
                break;

            case "/~newGuid":
                Server.Send(context, (context.Response.ContentEncoding ?? context.Request.ContentEncoding ?? Encoding.UTF8).GetBytes(Guid.NewGuid().ToString()));
                break;

            case "/~guid":
                var r = string.Format(Server.SGuidService, GuidService.GetGuid());
                Server.Send(context, (context.Response.ContentEncoding ?? context.Request.ContentEncoding ?? Encoding.UTF8).GetBytes(r));
                break;

            case "/~issecured":
                Server.Send(context, RequestArgs.https ? Server.True : Server.False);
                break;

            case "/~sessionid":
                Server.Send(context, (context.Response.ContentEncoding ?? context.Request.ContentEncoding ?? Encoding.UTF8).GetBytes(SessionIdService.SessionId));
                break;

            case "/~isadmin":
                var  cc   = getId(context);
                User user = null;
                if (cc != null && (_connectedUsers.TryGetValue(cc, out user)))
                {
                    if (user.IsBlocked)
                    {
                        _connectedUsers.Remove(cc);
                        context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                        break;
                    }
                    if (context.Request.RemoteEndPoint.Address.GetHashCode() != user.Address.GetHashCode())
                    {
                        if (AnotherAccountIsStillOpened(context, user))
                        {
                            context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                        }

                        user.Address = context.Request.RemoteEndPoint.Address;
                    }
                    using (var rr = RequestArgs.NewRequestArgs(context, this.server, user))
                        if (user.IsAgent)
                        {
                            rr.SendSuccess();
                        }
                        else
                        {
                            rr.SendFail();
                        }
                }
                break;

            default:
                if (raw.StartsWith("/~$?id") || raw.StartsWith("/~%24?"))
                {
                    Downloader.Send(context);
                }
                else
                {
                    return(false);
                }
                break;
            }
            context.Response.Close();
            return(true);
        }
Exemplo n.º 30
0
 public CommandsParam(RequestArgs args, CommandCallback callback, object param)
 {
     Args     = args;
     Parms    = param;
     Callback = callback;
 }