Пример #1
0
        void SetupBranchParam(BranchInfo branch)
        {
            string scanLogFile = Path.Combine(branch.PatternPath, "raw.log");

            if (branch.BranchName.ToLower().Equals("trend_icrc"))
            {
                string othPattern = Path.Combine(branch.PatternPath, branch.GetLastestPattern("icrc$oth.*"));

                string tblPattern = Path.Combine(branch.PatternPath, branch.GetLastestPattern("icrc$tbl.*"));

                branch.VscanParam = string.Format("/vszip={0} ", ScanLevel) + @"/s /nc /longvname /vsspyware+ /p=" + othPattern + @" /tbl=" + tblPattern + @" /lr=" + scanLogFile;
            }
            else if (branch.BranchName.ToLower().Equals("trendmicro"))
            {
                string[] files = Directory.GetFiles(branch.PatternPath, "tmaptn.*");
                foreach (string file in files)
                {
                    try
                    {
                        File.Delete(file);
                    }
                    catch { }
                }

                string lptPattern = Path.Combine(branch.PatternPath, branch.GetLastestPattern("lpt$vpn.*"));

                branch.VscanParam = string.Format("/vszip={0} ", ScanLevel) + @" /scantest /longvname /p=" + lptPattern + @" /nm /nb /tmaptn=" + branch.PatternPath + @" /vsspyware+ /vsseclvl=1 /lr=" + scanLogFile;
            }
            else
            {
                string lptPattern = Path.Combine(branch.PatternPath, branch.GetLastestPattern("lpt$vpn.*"));

                branch.VscanParam = string.Format("/vszip={0} ", ScanLevel) + @" /scantest /longvname /p=" + lptPattern + @" /nm /nb /vsseclvl=1 /lr=" + scanLogFile;
            }
        }
Пример #2
0
        private bool UnzipBranchPattern(BranchInfo branch)
        {
            if (!File.Exists(branch.ZipFilePath))
            {
                return(false);
            }

            List <string> backupFileName = new List <string>();

            try
            {
                Log.InfoFormat("Unzipping pattern file {0}....", branch.ZipFilePath);
                Utility.UnzipFile(SevenZipPath, branch.ZipFilePath, branch.PatternPath + "_tmp", "*"); // extract to _tmp first

                if (Directory.Exists(branch.PatternPath))
                {
                    Directory.Delete(branch.PatternPath, true);
                }
                Directory.Move(branch.PatternPath + "_tmp", branch.PatternPath);
                branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[0]);
            }
            catch (System.Exception ex)
            {
                Log.ErrorFormat("UnzipBranchPattern {0} fail: {1}", branch.BranchName, ex.Message);
                if (Directory.Exists(branch.PatternPath + "_tmp"))
                {
                    Directory.Delete(branch.PatternPath + "_tmp", true);
                }
                branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);
                throw new Exception(string.Format("UnzipBranchPattern {0} fail: {1}", branch.BranchName, ex.Message));
            }

            Regex rx = new Regex("^(lpt\\$vpn|icrc\\$(oth|tbl))\\.\\d{3}$");

            branch.VersionInfo = string.Empty;

            foreach (string file in Directory.GetFiles(branch.PatternPath))
            {
                if (!rx.IsMatch(Path.GetFileName(file)))
                {
                    File.Delete(file);
                }
                else
                {
                    branch.VersionInfo += Utility.GetPtnVersion(file);
                }
            }
            return(true);
        }
Пример #3
0
        private bool DownloadBranchPattern(BranchInfo branch)
        {
            if (branch.URI.StartsWith("ftp"))
            {
                Log.InfoFormat("Downloading ({0}) from {1}...", branch.BranchName, branch.URI);

                try
                {
                    if (false == Network.DownloadFileIfHasUpdate(branch.URI, branch.ZipFilePath))
                    {
                        branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[1]);;
                        Log.InfoFormat("DownloadBranchPattern {0} remote doesn't update yet, next download: {1}.", branch.BranchName, branch.NextUpdateTime);
                        return(false);
                    }

                    if (false == Utility.TestZipFile(SevenZipPath, branch.ZipFilePath))
                    {
                        branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);;
                        Log.InfoFormat("DownloadBranchPattern {0} zip damage, next download: {1}.", branch.BranchName, branch.NextUpdateTime);
                        File.Delete(branch.ZipFilePath);
                        return(false);
                    }

                    Log.InfoFormat("DownloadBranchPattern {0} success.", branch.BranchName);
                    branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[0]);
                    return(true);
                }
                catch (System.Exception ex)
                {
                    Log.ErrorFormat("DownloadBranchPattern from FTP fail: {0}", ex.Message);
                    throw new System.Exception(string.Format("DownloadBranchPattern fail: {0}", ex.Message));
                }
            }

            string vsapiPath = string.Empty;
            long   vsapiSize = 0;

            Regex rx = new Regex("^P\\.4=(?<file_name>[^,]+),(?<file_version>\\d+),(?<file_size>\\d+)$");

            try
            {
                Network.DownloadFile(branch.URI + @"/server.ini", @".\download\server.ini");

                bool hasFindPatternInfo = false;

                foreach (string line in File.ReadLines(@".\download\server.ini"))
                {
                    Match match = rx.Match(line);

                    if (match.Success)
                    {
                        hasFindPatternInfo = true;
                        if ((vsapiPath = match.Groups["file_name"].Value) == branch.LastPatternName)
                        {
                            branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[1]);;
                            Log.InfoFormat("DownloadBranchPattern {0} remote doesn't update yet, next download: {1}.", branch.BranchName, branch.NextUpdateTime);
                            return(false);
                        }
                        vsapiSize = Convert.ToInt64(match.Groups["file_size"].Value);
                        break;
                    }
                }

                if (!hasFindPatternInfo)
                {
                    branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);
                    Log.InfoFormat("DownloadBranchPattern {0} doesn't find pattern infomation in server.ini, next download: {1}", branch.BranchName, branch.NextUpdateTime);
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Log.ErrorFormat("DownloadBranchPattern from AU fail: {0}", ex.Message);
                throw new System.Exception(string.Format("DownloadBranchPattern fail: {0}", ex.Message));
            }

            try
            {
                Log.InfoFormat("Downloading ({0}) from {1}...", branch.BranchName, branch.URI + "/" + vsapiPath);
                Network.DownloadFile(branch.URI + "/" + vsapiPath, branch.ZipFilePath);

                FileInfo f = new FileInfo(branch.ZipFilePath);
                if (vsapiSize != f.Length)
                {
                    branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);
                    Log.InfoFormat("DownloadBranchPattern {0} filesize wrong, next download: {1}.", branch.BranchName, branch.NextUpdateTime);

                    File.Delete(branch.ZipFilePath);
                    return(false);
                }

                if (false == Utility.TestZipFile(SevenZipPath, branch.ZipFilePath))
                {
                    branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);
                    Log.InfoFormat("DownloadBranchPattern {0} zip damage, next download: {1}.", branch.BranchName, branch.NextUpdateTime);
                    File.Delete(branch.ZipFilePath);
                    return(false);
                }

                Log.InfoFormat("DownloadBranchPattern {0} success.", branch.BranchName);
                branch.NextUpdateTime  = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[0]);
                branch.LastPatternName = vsapiPath;
                return(true);
            }
            catch (System.Exception ex)
            {
                Log.ErrorFormat("DownloadBranchPattern from AU fail: {0}", ex.Message);
                throw new System.Exception(string.Format("DownloadBranchPattern fail: {0}", ex.Message));
            }
        }
Пример #4
0
        private bool UnzipBranchPattern(BranchInfo branch)
        {
            if (!File.Exists(branch.ZipFilePath))
            {
                return false;
            }

            List<string> backupFileName = new List<string>();

            try
            {
                Log.InfoFormat("Unzipping pattern file {0}....", branch.ZipFilePath);
                Utility.UnzipFile(SevenZipPath, branch.ZipFilePath, branch.PatternPath + "_tmp", "*"); // extract to _tmp first

                if (Directory.Exists(branch.PatternPath))
                {
                    Directory.Delete(branch.PatternPath, true);
                }
                Directory.Move(branch.PatternPath + "_tmp", branch.PatternPath);
                branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[0]);
            }
            catch (System.Exception ex)
            {
                Log.ErrorFormat("UnzipBranchPattern {0} fail: {1}", branch.BranchName, ex.Message);
                if (Directory.Exists(branch.PatternPath + "_tmp"))
                {
                    Directory.Delete(branch.PatternPath + "_tmp", true);
                }
                branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);
                throw new Exception(string.Format("UnzipBranchPattern {0} fail: {1}", branch.BranchName, ex.Message));

            }

            Regex rx = new Regex("^(lpt\\$vpn|icrc\\$(oth|tbl))\\.\\d{3}$");
            branch.VersionInfo = string.Empty;

            foreach (string file in Directory.GetFiles(branch.PatternPath))
            {
                if (!rx.IsMatch(Path.GetFileName(file)))
                {
                    File.Delete(file);
                }
                else
                {
                    branch.VersionInfo += Utility.GetPtnVersion(file);
                }
            }
            return true;
        }
Пример #5
0
        void SetupBranchParam(BranchInfo branch)
        {
            string scanLogFile = Path.Combine(branch.PatternPath, "raw.log");

            if (branch.BranchName.ToLower().Equals("trend_icrc"))
            {
                string othPattern = Path.Combine(branch.PatternPath, branch.GetLastestPattern("icrc$oth.*"));

                string tblPattern = Path.Combine(branch.PatternPath, branch.GetLastestPattern("icrc$tbl.*"));

                branch.VscanParam = string.Format("/vszip={0} ", ScanLevel) + @"/s /nc /longvname /vsspyware+ /p=" + othPattern + @" /tbl=" + tblPattern + @" /lr=" + scanLogFile;
            }
            else if (branch.BranchName.ToLower().Equals("trendmicro"))
            {
                string[] files = Directory.GetFiles(branch.PatternPath, "tmaptn.*");
                foreach (string file in files)
                {
                    try
                    {
                        File.Delete(file);
                    }
                    catch { }
                }

                string lptPattern = Path.Combine(branch.PatternPath, branch.GetLastestPattern("lpt$vpn.*"));

                branch.VscanParam = string.Format("/vszip={0} ", ScanLevel) + @" /scantest /longvname /p=" + lptPattern + @" /nm /nb /tmaptn=" + branch.PatternPath + @" /vsspyware+ /vsseclvl=1 /lr=" + scanLogFile;
            }
            else
            {
                string lptPattern = Path.Combine(branch.PatternPath, branch.GetLastestPattern("lpt$vpn.*"));

                branch.VscanParam = string.Format("/vszip={0} ", ScanLevel) + @" /scantest /longvname /p=" + lptPattern + @" /nm /nb /vsseclvl=1 /lr=" + scanLogFile;
            }
        }
Пример #6
0
        private bool DownloadBranchPattern(BranchInfo branch)
        {
            if (branch.URI.StartsWith("ftp"))
            {
                Log.InfoFormat("Downloading ({0}) from {1}...", branch.BranchName, branch.URI);

                try
                {
                    if (false == Network.DownloadFileIfHasUpdate(branch.URI, branch.ZipFilePath))
                    {
                        branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[1]); ;
                        Log.InfoFormat("DownloadBranchPattern {0} remote doesn't update yet, next download: {1}.", branch.BranchName, branch.NextUpdateTime);
                        return false;
                    }

                    if (false == Utility.TestZipFile(SevenZipPath, branch.ZipFilePath))
                    {
                        branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]); ;
                        Log.InfoFormat("DownloadBranchPattern {0} zip damage, next download: {1}.", branch.BranchName, branch.NextUpdateTime);
                        File.Delete(branch.ZipFilePath);
                        return false;
                    }

                    Log.InfoFormat("DownloadBranchPattern {0} success.", branch.BranchName);
                    branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[0]);
                    return true;
                }
                catch (System.Exception ex)
                {
                    Log.ErrorFormat("DownloadBranchPattern from FTP fail: {0}", ex.Message);
                    throw new System.Exception(string.Format("DownloadBranchPattern fail: {0}", ex.Message));
                }
            }

            string vsapiPath = string.Empty;
            long   vsapiSize = 0;

            Regex rx = new Regex("^P\\.4=(?<file_name>[^,]+),(?<file_version>\\d+),(?<file_size>\\d+)$");
            try
            {
                Network.DownloadFile(branch.URI + @"/server.ini", @".\download\server.ini");

                bool hasFindPatternInfo = false;

                foreach (string line in File.ReadLines(@".\download\server.ini"))
                {
                    Match match = rx.Match(line);

                    if (match.Success)
                    {
                        hasFindPatternInfo = true;
                        if ((vsapiPath = match.Groups["file_name"].Value) == branch.LastPatternName)
                        {
                            branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[1]); ;
                            Log.InfoFormat("DownloadBranchPattern {0} remote doesn't update yet, next download: {1}.", branch.BranchName, branch.NextUpdateTime);
                            return false;
                        }
                        vsapiSize = Convert.ToInt64(match.Groups["file_size"].Value);
                        break;
                    }
                }

                if (!hasFindPatternInfo)
                {
                    branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);
                    Log.InfoFormat("DownloadBranchPattern {0} doesn't find pattern infomation in server.ini, next download: {1}", branch.BranchName, branch.NextUpdateTime);
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Log.ErrorFormat("DownloadBranchPattern from AU fail: {0}", ex.Message);
                throw new System.Exception(string.Format("DownloadBranchPattern fail: {0}", ex.Message));
            }

            try
            {
                Log.InfoFormat("Downloading ({0}) from {1}...", branch.BranchName, branch.URI + "/" + vsapiPath);
                Network.DownloadFile(branch.URI + "/" + vsapiPath, branch.ZipFilePath);

                FileInfo f = new FileInfo(branch.ZipFilePath);
                if (vsapiSize != f.Length)
                {
                    branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);
                    Log.InfoFormat("DownloadBranchPattern {0} filesize wrong, next download: {1}.", branch.BranchName, branch.NextUpdateTime);

                    File.Delete(branch.ZipFilePath);
                    return false;
                }

                if (false == Utility.TestZipFile(SevenZipPath, branch.ZipFilePath))
                {
                    branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[2]);
                    Log.InfoFormat("DownloadBranchPattern {0} zip damage, next download: {1}.", branch.BranchName, branch.NextUpdateTime);
                    File.Delete(branch.ZipFilePath);
                    return false;
                }

                Log.InfoFormat("DownloadBranchPattern {0} success.", branch.BranchName);
                branch.NextUpdateTime = DateTime.Now + TimeSpan.FromSeconds(UpdateInterval[0]);
                branch.LastPatternName = vsapiPath;
                return true;
            }
            catch (System.Exception ex)
            {
                Log.ErrorFormat("DownloadBranchPattern from AU fail: {0}", ex.Message);
                throw new System.Exception(string.Format("DownloadBranchPattern fail: {0}", ex.Message));
            }
        }