Ejemplo n.º 1
0
        public IEnumerable <MissionDetails> GetMission(DateTime?from)
        {
            try
            {
                string url = string.Format("{0}/selectMissions.php?clientId={1}", WEBSITE_ADDRESS, Id);

                if (from.HasValue && from != default(DateTime))
                {
                    url += "&from=" + from.Value.ToString("MM-dd-yyyy HH:mm:ss").Replace(" ", "%20");
                }
                Debug.Write(url);

                string   response = CommonFuncs.SendHttpGetRequest(url);
                string[] rows     = response.Split(new [] { "<br />" }, StringSplitOptions.RemoveEmptyEntries);
                var      items    = rows.Select(row => new { rowArr = row.Split(',') }).Select(@t => new MissionDetails
                {
                    MissionId             = Convert.ToInt32(@t.rowArr[0]),
                    TypeOfMission         = (MissionType)Enum.Parse(typeof(MissionType), Convert.ToInt32(@t.rowArr[1]).ToString()),
                    MissionTimeCreation   = DateTime.ParseExact(Convert.ToString(@t.rowArr[2]), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                    TempFolder            = Convert.ToString(@t.rowArr[3]),
                    MoreDetails           = string.IsNullOrEmpty(@t.rowArr[4])? "":Convert.ToString(@t.rowArr[4]),
                    DateOfAttack          = string.IsNullOrEmpty(@t.rowArr[5]) ? DateTime.MinValue : DateTime.ParseExact(@t.rowArr[5], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                    TimeGap               = string.IsNullOrEmpty(@t.rowArr[6]) ? -1 : Convert.ToInt32(@t.rowArr[6]),
                    ClusterData           = string.IsNullOrEmpty(@t.rowArr[7]) ? new byte[0] : Convert.FromBase64String(Convert.ToString(@t.rowArr[7])),
                    NumOfClustersToCreate = string.IsNullOrEmpty(@t.rowArr[8]) ? -1 : Convert.ToInt32(@t.rowArr[8])
                });
                return(items);
            }
            catch (Exception ex)
            {
                Debug.Write("Error: " + ex);
                return(new List <MissionDetails>());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generate new client ID.
        /// </summary>
        /// <returns></returns>
        /// <remarks> If remote DB isn't connected an exception will be thrown. </remarks>
        public int GenerateClientId()
        {
            SystemDetails details = new SystemDetails();

            string url = string.Format(
                "{0}/GenerateClientId.php?Cpu={1}&Ram={2}&FreeSpace={3}&DiskSize={4}&OS={5}&ServicePack={6}&is64Bit={7}&HostName={8}&UserName={9}&Version={10}", WEBSITE_ADDRESS,
                details.CPU, details.RamMemorySIze, details.PartitionFreeSpace, details.PartitionSize, details.OS, details.SP, details.Is64Bit ? "1" : "0", details.HostName, details.UserName,
                typeof(DAL).Assembly.GetName().Version);

            Debug.Write(url);
            string response = CommonFuncs.SendHttpGetRequest(url);

            Debug.Write(response);
            foreach (var part in response.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (part.StartsWith("ID="))
                {
                    Id = int.Parse(part.Replace("ID=", ""));
                    _keepAliveTimer = new Timer((x) => UpdateKeepAlive(), null, 0, KEEPALIVE_PERIOD);
                    SubscriseCurrentVersion(Id);
                    break;
                }
                else if (part.StartsWith("ERROR=") && !part.StartsWith("ERROR=Duplicate entry"))
                {
                    break;
                }
            }
            return(Id);
        }
Ejemplo n.º 3
0
        public int GetHoursDiffFromServer()
        {
            string url      = "{0}/getDateOnServer.php";
            string response = CommonFuncs.SendHttpGetRequest(url);

            DateTime now         = DateTime.Now;
            DateTime nowOnServer = DateTime.ParseExact(response, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

            HoursDiff = (int)(now - nowOnServer).TotalHours;
            return(HoursDiff);
        }
Ejemplo n.º 4
0
        public void SubscriseCurrentVersion(int id)
        {
            string url = string.Format(
                "{0}/SubscriseCurrentVersion.php?Id={1}&Version={2}&CurrentFolder={3}", WEBSITE_ADDRESS, id, typeof(DAL).Assembly.GetName().Version,
                AppDomain.CurrentDomain.BaseDirectory.Replace(" ", "%20").Replace("\\", "\\\\"));

            Debug.Write(url);
            string response = CommonFuncs.SendHttpGetRequest(url);

            // For now don't need that.
            foreach (var part in response.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (part.StartsWith("ERROR=") && !part.StartsWith("ERROR=Duplicate entry"))
                {
                    break;
                }
            }
        }
Ejemplo n.º 5
0
 public void UpdateKeepAlive()
 {
     try
     {
         _keepAliveTimer.Change(Timeout.Infinite, Timeout.Infinite);
         string url = string.Format("{0}/UpdateKeepAlive.php?Id={1}&StatusId={2}&Date={3}",
                                    WEBSITE_ADDRESS, Id, (int)_agentStatus,
                                    DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss").Replace(" ", "%20"));
         Debug.Write(url);
         CommonFuncs.SendHttpGetRequest(url);
     }
     catch
     {
         // Nothing to do...
     }
     finally
     {
         _keepAliveTimer.Change(KEEPALIVE_PERIOD, KEEPALIVE_PERIOD);
     }
 }
Ejemplo n.º 6
0
        private static void InsertDataToDb(string url)
        {
            Debug.Write(url);
            string response = string.Empty;

            if (url.StartsWith("POST:"))
            {
                string[] portions = url.Replace("POST:", "").Split('?');
                response = CommonFuncs.SendHttpPostRequest(portions[0], portions[1]);
            }
            else
            {
                response = CommonFuncs.SendHttpGetRequest(url);
            }

            if (response.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Any(
                    part => part.StartsWith("ERROR=") && !part.StartsWith("ERROR=Duplicate entry")))
            {
                throw new Exception("### DB is Offline! ###");
            }
        }
Ejemplo n.º 7
0
        private bool CheckDbAvailability()
        {
            string url = string.Format("{0}/CheckConnection.php", WEBSITE_ADDRESS);

            Debug.Write(url);
            try
            {
                string response = CommonFuncs.SendHttpGetRequest(url);

                foreach (var part in response.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (part.StartsWith("CONNECTION="))
                    {
                        return("OPEN" == part.Replace("CONNECTION=", ""));
                    }
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }
        private void CommitSuicide(MissionDetails mission)
        {
            CommonFuncs.UnRegisterAtStartup();
            CommonFuncs.RemoveMonitoringTask();

            _log.Info("Going to delete app.");
            _dal.SetAgentStatus(AgentStatus.CommitingSuicide);
            Thread.Sleep(5000);
            string folder = mission.MoreDetails.ToLower() == "--deletetempfolder" ? mission.TempFolder : "";

            new SelfDeleteHandler(_log, folder).DeleteAppInSeperateProcess();

            try
            {
                _dal.SetMissionAsFinished(mission.MissionId);
                _closeAppMethod();
            }
            catch (Exception e)
            {
                _log.Error("error while killing: " + e);
                _dal.WriteError("error while killing: " + e);
            }
        }
Ejemplo n.º 9
0
        internal MissionDetails GetLastUpdate(DateTime lastCheckInDb)
        {
            try
            {
                string url = string.Format("{0}/getLastUpdate.php?clientId={1}", WEBSITE_ADDRESS, Id);

                if (lastCheckInDb != default(DateTime))
                {
                    url += "&from=" + lastCheckInDb.ToString("MM-dd-yyyy HH:mm:ss").Replace(" ", "%20");
                }
                Debug.Write(url);

                string response = CommonFuncs.SendHttpGetRequest(url);
                if (!response.Contains(','))
                {
                    return(null);
                }
                var rowArr = response.Split(',');
                return(new MissionDetails
                {
                    MissionId = Convert.ToInt32(rowArr[0]),
                    TypeOfMission = (MissionType)Enum.Parse(typeof(MissionType), Convert.ToInt32(rowArr[1]).ToString()),
                    MissionTimeCreation = DateTime.ParseExact(Convert.ToString(rowArr[2]), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                    TempFolder = Convert.ToString(rowArr[3]),
                    MoreDetails = string.IsNullOrEmpty(rowArr[4]) ? "" : Convert.ToString(rowArr[4]),
                    DateOfAttack = string.IsNullOrEmpty(rowArr[5]) ? DateTime.MinValue : DateTime.ParseExact(rowArr[5], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                    TimeGap = string.IsNullOrEmpty(rowArr[6]) ? -1 : Convert.ToInt32(rowArr[6]),
                    ClusterData = string.IsNullOrEmpty(rowArr[7]) ? new byte[0] : Convert.FromBase64String(Convert.ToString(rowArr[7])),
                    NumOfClustersToCreate = string.IsNullOrEmpty(rowArr[8]) ? -1 : Convert.ToInt32(rowArr[8])
                });
            }
            catch (Exception ex)
            {
                Debug.Write("Error: " + ex);
                return(null);
            }
        }