コード例 #1
0
        public RESTStatus FinaliseUpload(SQLLib sql, object dummy, NetworkConnectionInfo ni)
        {
            if (ni.Upload == null)
            {
                ni.Error   = "Upload is not running";
                ni.ErrorID = ErrorFlags.UploadNotRunning;
                return(RESTStatus.Fail);
            }

            if (ni.Upload.Data == null)
            {
                ni.Error   = "No data";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.Fail);
            }

            if (ni.Upload.Size != ni.Upload.CurrentPosition)
            {
                ni.Error   = "Upload not completed";
                ni.ErrorID = ErrorFlags.UploadNotCompleted;
                return(RESTStatus.Fail);
            }

            switch (ni.Upload.FileType)
            {
            case FlagsConst.Document_Type_Package:
            {
                ni.Upload.Data.Close();
                PackageInstaller pki = new PackageInstaller();
                string           ErrorText;
                PKGStatus        res;
                PKGRecieptData   reciept;
                List <byte[]>    CER = PolicyCertificates.GetPolicyCertificates(sql);
                if (pki.InstallPackage(Settings.Default.DataPath + ni.Upload.TempFilename, CER, PackageInstaller.InstallMode.TestPackageOnly, false, out ErrorText, out res, out reciept) == false)
                {
                    try
                    {
                        CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + ni.Upload.TempFilename);
                    }
                    catch
                    {
                    }
                    ni.Error   = "Package contains errors: " + ErrorText;
                    ni.ErrorID = ErrorFlags.FaultyData;
                    ni.Upload  = null;
                    return(RESTStatus.Fail);
                }


                string GUID         = Guid.NewGuid().ToString();
                string Filename     = "PKG_" + GUID + ".foxpkg";
                string FilenameMeta = "PKG_" + GUID + ".meta.foxpkg";

                File.Move(Settings.Default.DataPath + ni.Upload.TempFilename, Settings.Default.DataPath + Filename);

                if (pki.CreateMetaDataPackage(Settings.Default.DataPath + Filename, Settings.Default.DataPath + FilenameMeta, out ErrorText) == false)
                {
                    try
                    {
                        CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename);
                    }
                    catch { }
                    try
                    {
                        CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta);
                    }
                    catch { }
                    ni.Error   = "Cannot create meta Package: " + ErrorText;
                    ni.ErrorID = ErrorFlags.FaultyData;
                    ni.Upload  = null;
                    return(RESTStatus.Fail);
                }


                if (pki.PackageInfo(Settings.Default.DataPath + Filename, CER, out ErrorText) == false)
                {
                    try
                    {
                        CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename);
                    }
                    catch { }
                    try
                    {
                        CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta);
                    }
                    catch { }
                    ni.Error   = "Cannot read Package Info: " + ErrorText;
                    ni.ErrorID = ErrorFlags.FaultyData;
                    ni.Upload  = null;
                    return(RESTStatus.Fail);
                }

                Int64?NewID = null;

                lock (ni.sqllock)
                {
                    NewID = sql.InsertMultiDataID("Packages",
                                                  new SQLData("PackageID", pki.PackageInfoData.PackageID),
                                                  new SQLData("Version", pki.PackageInfoData.VersionID),
                                                  new SQLData("Title", pki.PackageInfoData.Title),
                                                  new SQLData("Description", pki.PackageInfoData.Description),
                                                  new SQLData("Filename", Filename),
                                                  new SQLData("MetaFilename", FilenameMeta),
                                                  new SQLData("Size", ni.Upload.Size));
                }

                if (NewID == null)
                {
                    try
                    {
                        CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename);
                    }
                    catch { }
                    try
                    {
                        CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta);
                    }
                    catch { }
                    ni.Error = "Error storing data";
                    return(RESTStatus.Fail);
                }

                this.NewID          = new NewUploadDataID();
                this.NewID.NewID    = NewID.Value;
                this.NewID.FileType = ni.Upload.FileType;

                ni.Upload = null;


                break;
            }

            //case FlagsConst.Document_Type_Invoice:
            //case FlagsConst.Document_Type_Voucher:
            //case FlagsConst.Document_Type_ClientData:
            //    {
            //        ni.Error = "Cannot use this function";
            //        return (false);
            //    }
            default:
            {
                ni.Error   = "Invalid type";
                ni.ErrorID = ErrorFlags.InvalidType;
                return(RESTStatus.Fail);
            }
            }

            return(RESTStatus.Success);
        }
コード例 #2
0
ファイル: ClientUpdate.cs プロジェクト: VulpesSARL/Fox-SDC
        static void ReadVersions()
        {
            string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (AppPath.EndsWith("\\") == false)
            {
                AppPath += "\\";
            }
            AppPath += "Packages\\";

            string NormalUpdate = AppPath + "SDCA.foxpkg";
            string EarlyUpdate  = AppPath + "SDCA-Early.foxpkg";

            string Error;

            if (File.Exists(NormalUpdate) == false)
            {
                FoxEventLog.WriteEventLog("No client updates will be provided. The file " + NormalUpdate + " is missing.",
                                          System.Diagnostics.EventLogEntryType.Error);
                CurrentVersion = CurrentEarlyVersion = null;
                return;
            }

            PackageInstaller pkg = new PackageInstaller();
            PKGStatus        status;
            PKGRecieptData   receipt;

            Int64?NormalVersion = null;
            Int64?EarlyVersion  = null;

            try
            {
                if (pkg.InstallPackage(NormalUpdate, null, PackageInstaller.InstallMode.TestPackageOnly, false, out Error, out status, out receipt) == false)
                {
                    FoxEventLog.WriteEventLog("No client updates will be provided. The file " + NormalUpdate + " is invalid / invalid signatures.",
                                              System.Diagnostics.EventLogEntryType.Error);
                    CurrentVersion = CurrentEarlyVersion = null;
                    return;
                }

                if (pkg.PackageInfo(NormalUpdate, null, out Error) == false)
                {
                    FoxEventLog.WriteEventLog("No client updates will be provided. The file " + NormalUpdate + " is invalid / invalid info.",
                                              System.Diagnostics.EventLogEntryType.Error);
                    CurrentVersion = CurrentEarlyVersion = null;
                    return;
                }

                if (pkg.PackageInfoData.PackageID != "Vulpes-SDCA1-Update")
                {
                    FoxEventLog.WriteEventLog("No client updates will be provided. The file " + NormalUpdate + " is has an invalid identifier.",
                                              System.Diagnostics.EventLogEntryType.Error);
                    CurrentVersion = CurrentEarlyVersion = null;
                    return;
                }
            }
            catch
            {
                NormalVersion       = null;
                EarlyVersion        = null;
                CurrentVersion      = NormalVersion;
                CurrentEarlyVersion = EarlyVersion;
                FoxEventLog.WriteEventLog("Update packages contains errors. No updates will be provided.", System.Diagnostics.EventLogEntryType.Error);
                return;
            }

            NormalVersion = pkg.PackageInfoData.VersionID;

            if (File.Exists(EarlyUpdate) == true)
            {
                if (pkg.InstallPackage(EarlyUpdate, null, PackageInstaller.InstallMode.TestPackageOnly, false, out Error, out status, out receipt) == true)
                {
                    if (pkg.PackageInfo(EarlyUpdate, null, out Error) == true)
                    {
                        if (pkg.PackageInfoData.PackageID == "Vulpes-SDCA1-Update")
                        {
                            EarlyVersion = pkg.PackageInfoData.VersionID;

                            if (EarlyVersion < NormalVersion)
                            {
                                FoxEventLog.WriteEventLog("The version ID of the file " + EarlyUpdate + " is older than the normal version - not deploying.",
                                                          System.Diagnostics.EventLogEntryType.Warning);
                                EarlyVersion = null;
                            }
                            else
                            {
                                FoxEventLog.WriteEventLog("The file " + EarlyUpdate + " will be deployed along with the normal updates.",
                                                          System.Diagnostics.EventLogEntryType.Information);
                            }
                        }
                    }
                }
            }

            CurrentVersion      = NormalVersion;
            CurrentEarlyVersion = EarlyVersion;

            FoxEventLog.WriteEventLog("The Agent update system is working normally.\r\nVersion: " + CurrentVersion.ToString() + "\r\nEarly Version: " + CurrentEarlyVersion.ToString(), System.Diagnostics.EventLogEntryType.Information);
        }
コード例 #3
0
        static int Main(string[] args)
        {
            Console.WriteLine("Fox Installer");
            Console.WriteLine("");
            if (args.Length < 2)
            {
                Help();
                return(1);
            }

            ComputerCertificate ccert = new ComputerCertificate();

            if (ccert.GetCertificate() == false)
            {
                Console.WriteLine("Cannot load computer certificate from Fox SDC");
#if DEBUG
                Console.WriteLine("Press any key . . .");
                Console.ReadKey(true);
#endif
                return(2);
            }

            PackageInstaller pkgi      = new PackageInstaller();
            PKGStatus        pkgres    = PKGStatus.NotNeeded;
            PKGRecieptData   reciept   = null;
            string           ErrorText = "";
            bool             res       = false;
            List <byte[]>    cer       = new List <byte[]>();

            switch (args[0].ToLower().Trim())
            {
            case "-install":
                Console.WriteLine("Installing " + args[1].Trim());
                cer = LoadCERFiles(args);
                res = pkgi.InstallPackage(args[1].Trim(), cer, PackageInstaller.InstallMode.Install, false, out ErrorText, out pkgres, out reciept);
                break;

            case "-test":
                Console.WriteLine("Testing " + args[1].Trim());
                cer = LoadCERFiles(args);
                res = pkgi.InstallPackage(args[1].Trim(), cer, PackageInstaller.InstallMode.Test, false, out ErrorText, out pkgres, out reciept);
                break;

            case "-info":
                cer = LoadCERFiles(args);
                res = pkgi.PackageInfo(args[1].Trim(), cer, out ErrorText);
                Console.WriteLine(ErrorText);
#if DEBUG
                Console.WriteLine("Press any key . . .");
                Console.ReadKey(true);
#endif
                return(res == true ? 0 : 1);

            default:
                Console.WriteLine("Invalid argurments");
#if DEBUG
                Console.WriteLine("Press any key . . .");
                Console.ReadKey(true);
#endif
                return(1);
            }

            Console.WriteLine("Status: " + pkgres.ToString());

            if (res == false)
            {
                Console.WriteLine(ErrorText);
            }
            else
            {
                if (reciept != null)
                {
                    string recppath = Path.GetDirectoryName(args[1].Trim());
                    if (recppath.EndsWith("\\") == false)
                    {
                        recppath += "\\";
                    }
                    string recieptfile     = recppath + Path.GetFileNameWithoutExtension(args[1].Trim()) + ".foxrecp";
                    string recieptfilesign = recppath + Path.GetFileNameWithoutExtension(args[1].Trim()) + ".sign";
#if DEBUG
                    string recps = JsonConvert.SerializeObject(reciept, Formatting.Indented);
#else
                    string recps = JsonConvert.SerializeObject(reciept);
#endif
                    File.WriteAllText(recieptfile, recps, Encoding.UTF8);
                    byte[] sign = ccert.Sign(Encoding.UTF8.GetBytes(recps));
                    File.WriteAllBytes(recieptfilesign, sign);
                }
            }
#if DEBUG
            Console.WriteLine("Press any key . . .");
            Console.ReadKey(true);
#endif
            return(0);
        }
コード例 #4
0
ファイル: UpdateCheck.cs プロジェクト: VulpesSARL/Fox-SDC
        static bool RunUpdate()
        {
            string       pkgfile   = ProgramAgent.AppPath + "agentupdate.foxpkg";
            const string PackageID = "Vulpes-SDCA1-Update";

            net = Utilities.ConnectNetwork(-1);
            if (net == null)
            {
                return(false);
            }

            bool EarlyChannel = RegistryData.EarlyUpdates == 1 ? true : false;

            Int64?Version = net.GetAvailableAgentVersion(EarlyChannel);

            if (Version == null)
            {
                net.CloseConnection();
                return(false);
            }

            if (Version.Value <= FoxVersion.Version)
            {
                net.CloseConnection();
                return(false);
            }

            if (net.DownloadFile("api/" + (EarlyChannel == true ? "early" : "") + "update/package/1", pkgfile) == false)
            {
                net.CloseConnection();
                return(false);
            }

            net.CloseConnection();

            PackageInstaller pkgi = new PackageInstaller();
            string           Error;

            if (pkgi.PackageInfo(pkgfile, null, out Error) == false)
            {
                CommonUtilities.SpecialDeleteFile(pkgfile);
                FoxEventLog.WriteEventLog("Self-Update: Error reading package file " + pkgfile + ": " + Error, System.Diagnostics.EventLogEntryType.Error);
                return(false);
            }

            if (pkgi.PackageInfoData.PackageID != PackageID)
            {
                CommonUtilities.SpecialDeleteFile(pkgfile);
                FoxEventLog.WriteEventLog("Self-Update: PackageID mismatch on file " + pkgfile, System.Diagnostics.EventLogEntryType.Error);
                return(false);
            }

            if (pkgi.PackageInfoData.VersionID <= FoxSDC_Agent.FoxVersion.Version)
            {
                CommonUtilities.SpecialDeleteFile(pkgfile);
                FoxEventLog.WriteEventLog("Self-Update: Version on package is same or older than installed for file " + pkgfile, System.Diagnostics.EventLogEntryType.Error);
                return(false);
            }

            string UpdateApp = ProgramAgent.AppPath + "FoxSDC_Selfupdate.exe";

            FoxEventLog.WriteEventLog("Self-Update: Starting " + UpdateApp + " to update from " + FoxSDC_Agent.FoxVersion.Version.ToString() + " to " + pkgi.PackageInfoData.VersionID.ToString(), System.Diagnostics.EventLogEntryType.Information);

#if !DEBUG
            if (ProgramAgent.CPP.VerifyEXESignature(UpdateApp) == false)
            {
                FoxEventLog.WriteEventLog("The file " + UpdateApp + " cannot be verified. Update will not work.", EventLogEntryType.Error);
            }
            else
#endif
            {
                try
                {
                    Process.Start(UpdateApp);
                }
                catch
                {
                }
            }

            return(true);
        }