Example #1
0
        public JobViewModel GetEdit(ApiCall call)
        {
            var id = call.GetValue <long>("id");

            if (id > 0)
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Job can not edit, you may delete and create a new one"));

                var isrepeat = call.GetBoolValue("IsRepeat");

                if (isrepeat)
                {
                    var item = GlobalDb.RepeatingJob().Get(id);
                    if (item != null)
                    {
                        return(new JobViewModel(item));
                    }
                }
                else
                {
                    // var item = GlobalDb.ScheduleJob().
                }
            }

            return(new JobViewModel());
        }
Example #2
0
 public void AddJobLog(string JobName, bool isSuccess, DateTime ExecutionTime, Guid WebSiteId, string message)
 {
     GlobalDb.JobLog().Add(new JobLog()
     {
         JobName       = JobName,
         Success       = isSuccess,
         ExecutionTime = ExecutionTime,
         WebSiteId     = WebSiteId,
         Message       = message
     });
 }
Example #3
0
        /// <summary>
        /// Gets login records for the past 2 months for the session's logged-in user, ordered by Date descending.  Does not require admin privilege.
        /// </summary>
        /// <returns></returns>
        public ActionResult GetLoginRecordsForSelf()
        {
            long startDate = TimeUtil.GetTimeInMsSinceEpoch(DateTime.Now.AddMonths(-2));
            long endDate   = TimeUtil.GetTimeInMsSinceEpoch(DateTime.Now.AddMonths(1));

            using (GlobalDb db = new GlobalDb())
                return(Json(new LoginRecordsResponse()
                {
                    records = db.GetLoginRecordsByUserName(session.userName, startDate, endDate)
                }));
        }
Example #4
0
File: Job.cs Project: xhute/Kooboo
 private void _delete(JobDeleteViewModel model)
 {
     if (model.IsRepeat)
     {
         GlobalDb.RepeatingJob().Del(model.Id);
     }
     else
     {
         GlobalDb.ScheduleJob().Delete(model.DayInt, model.SecondOfDay, model.BlockPosition);
     }
 }
Example #5
0
        public List <JobLog> Logs(ApiCall call)
        {
            string success   = call.GetValue("success");
            bool   IsSuccess = false;

            if (!string.IsNullOrEmpty(success) && success.ToLower() == "true" || success.ToLower() == "yes")
            {
                IsSuccess = true;
            }

            return(GlobalDb.JobLog().GetByWebSiteId(call.Context.WebSite.Id, IsSuccess, 100));
        }
Example #6
0
 private static void AddJobLog(string JobName, string Description, bool isSuccess, DateTime ExecutionTime, Guid WebSiteId, string message)
 {
     GlobalDb.JobLog().Add(new JobLog()
     {
         JobName       = JobName,
         Description   = Description,
         Success       = isSuccess,
         ExecutionTime = ExecutionTime,
         WebSiteId     = WebSiteId,
         Message       = message
     });
 }
Example #7
0
        /// <summary>
        /// Gets all login records within a time range, ordered by Date descending.  Session must have admin privilege.
        /// </summary>
        /// <returns></returns>
        public ActionResult GetLoginRecordsGlobal()
        {
            if (!session.IsAdminValid)
            {
                return(ApiError("Not Authorized"));
            }

            LoginRecordsGlobalRequest request = ApiRequestBase.ParseRequest <LoginRecordsGlobalRequest>(this);

            using (GlobalDb db = new GlobalDb())
                return(Json(new LoginRecordsResponse()
                {
                    records = db.GetLoginRecordsGlobal(request.startDate, request.endDate)
                }));
        }
Example #8
0
        /// <summary>
        /// Gets all login records for the specified user, ordered by Date descending.  Session must have admin privilege.
        /// </summary>
        /// <returns></returns>
        public ActionResult GetLoginRecordsForUser()
        {
            if (!session.IsAdminValid)
            {
                return(ApiError("Not Authorized"));
            }

            LoginRecordsByUserNameRequest request = ApiRequestBase.ParseRequest <LoginRecordsByUserNameRequest>(this);

            using (GlobalDb db = new GlobalDb())
                return(Json(new LoginRecordsResponse()
                {
                    records = db.GetLoginRecordsByUserName(request.userName)
                }));
        }
Example #9
0
        public List <JobViewModel> List(ApiCall call)
        {
            var jobs = new List <JobViewModel>();

            foreach (var item in GlobalDb.ScheduleJob().GetByWebSiteId(call.Context.WebSite.Id))
            {
                jobs.Add(new JobViewModel(item));
            }

            foreach (var item in GlobalDb.RepeatingJob().GetByWebSiteId(call.Context.WebSite.Id))
            {
                jobs.Add(new JobViewModel(item));
            }

            SetCodeName(jobs, call.WebSite.SiteDb());

            return(jobs);
        }
Example #10
0
        public void Execute()
        {
            var scheduleJob = GlobalDb.ScheduleJob().DeQueue();

            while (scheduleJob != null)
            {
                ExecuteScheduleJob(scheduleJob);
                scheduleJob = GlobalDb.ScheduleJob().DeQueue();
            }

            var repeatingJob = GlobalDb.RepeatingJob().DequeueItem();

            while (repeatingJob != null)
            {
                ExecuteRepeatingJob(repeatingJob);
                repeatingJob = GlobalDb.RepeatingJob().DequeueItem();
            }
        }
Example #11
0
        public void Execute()
        {
            var scheduleJob = GlobalDb.ScheduleJob().DeQueue();

            while (scheduleJob != null)
            {
                ExecuteScheduleJob(scheduleJob);
                scheduleJob = GlobalDb.ScheduleJob().DeQueue();
            }

            var repeatingJobs = GlobalDb.RepeatingJob().DequeueItems();

            if (repeatingJobs != null && repeatingJobs.Any())
            {
                foreach (var item in repeatingJobs)
                {
                    ExecuteRepeatingJob(item);
                }
            }
        }
Example #12
0
        public void Deletes(ApiCall call)
        {
            try
            {
                string body = call.GetValue("ids");
                if (string.IsNullOrEmpty(body))
                {
                    body = call.Context.Request.Body;
                }

                var ids = Lib.Helper.JsonHelper.Deserialize <List <Guid> >(body);

                if (ids != null)
                {
                    var schedulejobs = GlobalDb.ScheduleJob().GetByWebSiteId(call.Context.WebSite.Id);
                    var repeatjobs   = GlobalDb.RepeatingJob().GetByWebSiteId(call.Context.WebSite.Id);

                    foreach (var item in ids)
                    {
                        var findschedule = schedulejobs.Find(o => o.Item.Id == item);
                        if (findschedule != null)
                        {
                            GlobalDb.ScheduleJob().Delete(findschedule.DayInt, findschedule.SecondOfDay, findschedule.BlockPosition);
                        }
                        else
                        {
                            var findrepeat = repeatjobs.Find(o => o.Item.Id == item);
                            if (findrepeat != null)
                            {
                                GlobalDb.RepeatingJob().Del(findrepeat);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Example #13
0
        public void Post(JobEditViewModel model, ApiCall call)
        {
            //JobEditViewModel model = call.Context.Request.Model as JobEditViewModel;

            Job newjob = new Job();

            newjob.Description = model.Description;
            newjob.JobName     = model.Name;
            newjob.WebSiteId   = call.Context.WebSite.Id;
            newjob.Script      = model.Script;
            newjob.CodeId      = model.CodeId;

            // add a new job.
            if (model.IsRepeat)
            {
                RepeatItem <Job> repeatjob = new RepeatItem <Job>();
                repeatjob.Item          = newjob;
                repeatjob.StartTime     = model.StartTime;
                repeatjob.FrequenceUnit = model.FrequenceUnit;

                switch (model.Frequence.ToLower())
                {
                case "month":
                {
                    repeatjob.Frequence = RepeatFrequence.Month;
                    break;
                }

                case "day":
                {
                    repeatjob.Frequence = RepeatFrequence.Day;
                    break;
                }

                case "minutes":
                {
                    repeatjob.Frequence = RepeatFrequence.Minutes;
                    break;
                }

                case "minute":
                {
                    repeatjob.Frequence = RepeatFrequence.Minutes;
                    break;
                }

                case "second":
                {
                    repeatjob.Frequence = RepeatFrequence.Second;
                    break;
                }

                case "week":
                {
                    repeatjob.Frequence = RepeatFrequence.Week;
                    break;
                }

                case "hour":
                {
                    repeatjob.Frequence = RepeatFrequence.Hour;
                    break;
                }

                default:
                    break;
                }

                GlobalDb.RepeatingJob().Add(repeatjob);
                GlobalDb.RepeatingJob().Close();
            }
            else
            {
                GlobalDb.ScheduleJob().Add(newjob, model.StartTime);
                GlobalDb.ScheduleJob().Close();
            }
        }
Example #14
0
        public ActionResult Login()
        {
            LoginRequest args = ApiRequestBase.ParseRequest <LoginRequest>(this);

            ServerSession session = args.GetSession();

            bool isNewSession = false;

            if (session == null)
            {
                isNewSession = true;
                session      = ServerSession.CreateUnauthenticated();
                SessionManager.AddSession(session);
            }

            // Initialize challenge data
            if (session.authChallenge == null || session.authChallenge.Length == 0)
            {
                session.authChallenge = ByteUtil.GenerateRandomBytes(32);
            }

            // Get user
            if (string.IsNullOrEmpty(args.user))
            {
                return(ApiError("missing parameter: \"user\""));
            }
            User user = Settings.data.GetUser(args.user);

            string salt;

            if (user != null)
            {
                salt = user.Salt;
            }
            else
            {
                salt = Util.GenerateFakeUserSalt(args.user);
                Logger.Info("Fake salt \"" + salt + "\" created for user name \"" + args.user + "\". Remote IP: " + Context.httpProcessor.RemoteIPAddressStr);
            }

            if (string.IsNullOrEmpty(args.token))
            {
                // No response token was provided, so we are on step 1 of authentication, where the client requests information necessary to build the response token.
                return(Json(new LoginChallengeResponse(session, salt, null)));
            }
            else
            {
                // A response token was provided. This token can be used to authenticate the user.
                if (user != null)
                {
                    if (user.AuthenticateUser(args.token, session.authChallenge))
                    {
                        // Delete challenge data -- it is no longer needed and should not be reused.
                        session.authChallenge = null;
                        session.userName      = user.Name;
                        using (GlobalDb db = new GlobalDb())
                            db.AddLoginRecord(user.Name, Context.httpProcessor.RemoteIPAddressStr, session.sid);
                        return(Json(new LoginSuccessResponse(session)));
                    }
                }
                if (isNewSession)
                {
                    return(Json(new LoginFailedResponse(session, "Authentication protocol timed out. Please try again.")));
                }
                return(Json(new LoginFailedResponse(session, "Authentication failed. Please check inputs.")));
            }
        }