Exemple #1
0
        /// <summary>
        /// Removes a file from all pages viewing backup files
        /// </summary>
        /// <param name="FileName">Name of file</param>
        public static void UpdateClientsFileDeleted(string FileName)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{\"fileName\":\"");
            sb.Append(CommonTypes.JsonStringEncode(FileName));
            sb.Append("\"}");

            string[] TabIDs = ClientEvents.GetTabIDsForLocation("/Settings/Backup.md");

            Task _ = ClientEvents.PushEvent(TabIDs, "FileDeleted", sb.ToString(), true, "User");
        }
Exemple #2
0
        /// <summary>
        /// Updates the status of a file on all pages viewing backup files
        /// </summary>
        /// <param name="FileName">Name of file</param>
        /// <param name="Length">Size of file</param>
        /// <param name="Created">When file was created</param>
        public static void UpdateClientsFileUpdated(string FileName, long Length, DateTime Created)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{\"fileName\":\"");
            sb.Append(CommonTypes.JsonStringEncode(FileName));
            sb.Append("\", \"size\": \"");
            if (Length >= 0)
            {
                sb.Append(CommonTypes.JsonStringEncode(Export.FormatBytes(Length)));
            }
            sb.Append("\", \"created\": \"");
            sb.Append(CommonTypes.JsonStringEncode(Created.ToString()));
            sb.Append("\", \"button\": \"");
            sb.Append(CommonTypes.JsonStringEncode("<button class=\"posButtonSm\" onclick=\"DeleteExport('" + FileName + "');\">Delete</button>"));
            sb.Append("\", \"isKey\": ");
            sb.Append(FileName.EndsWith(".key", StringComparison.CurrentCultureIgnoreCase) ? "true" : "false");
            sb.Append("}");

            string[] TabIDs = ClientEvents.GetTabIDsForLocation("/Settings/Backup.md");

            Task _ = ClientEvents.PushEvent(TabIDs, "UpdateExport", sb.ToString(), true, "User");
        }
Exemple #3
0
        /// <summary>
        /// Exports gateway data
        /// </summary>
        /// <param name="Output">Export Output</param>
        /// <param name="Database">If the contents of the database is to be exported.</param>
        /// <param name="WebContent">If web content is to be exported.</param>
        /// <param name="Folders">Root subfolders to export.</param>
        public static async Task DoExport(IExportFormat Output, bool Database, bool WebContent, string[] Folders)
        {
            try
            {
                List <KeyValuePair <string, object> > Tags = new List <KeyValuePair <string, object> >()
                {
                    new KeyValuePair <string, object>("Database", Database)
                };

                foreach (string Folder in Folders)
                {
                    Tags.Add(new KeyValuePair <string, object>(Folder, true));
                }

                Log.Informational("Starting export.", Output.FileName, Tags.ToArray());

                await Output.Start();

                if (Database)
                {
                    StringBuilder Temp = new StringBuilder();
                    using (XmlWriter w = XmlWriter.Create(Temp, XML.WriterSettings(false, true)))
                    {
                        await Persistence.Database.Analyze(w, string.Empty, Path.Combine(Gateway.RootFolder, "Data"), false, true);
                    }

                    await Persistence.Database.Export(Output);
                }

                if (WebContent || Folders.Length > 0)
                {
                    await Output.StartFiles();

                    try
                    {
                        string[] FileNames;
                        string   Folder2;

                        if (WebContent)
                        {
                            FileNames = Directory.GetFiles(Gateway.RootFolder, "*.*", SearchOption.TopDirectoryOnly);

                            foreach (string FileName in FileNames)
                            {
                                await ExportFile(FileName, Output);
                            }

                            Export.FolderCategory[] ExportFolders = Export.GetRegisteredFolders();

                            foreach (string Folder in Directory.GetDirectories(Gateway.RootFolder, "*.*", SearchOption.TopDirectoryOnly))
                            {
                                bool IsWebContent = true;

                                foreach (Export.FolderCategory FolderCategory in ExportFolders)
                                {
                                    foreach (string Folder3 in FolderCategory.Folders)
                                    {
                                        if (string.Compare(Folder3, Folder, true) == 0)
                                        {
                                            IsWebContent = false;
                                            break;
                                        }
                                    }

                                    if (!IsWebContent)
                                    {
                                        break;
                                    }
                                }

                                if (IsWebContent)
                                {
                                    FileNames = Directory.GetFiles(Folder, "*.*", SearchOption.AllDirectories);

                                    foreach (string FileName in FileNames)
                                    {
                                        await ExportFile(FileName, Output);
                                    }
                                }
                            }
                        }

                        foreach (string Folder in Folders)
                        {
                            if (Directory.Exists(Folder2 = Path.Combine(Gateway.RootFolder, Folder)))
                            {
                                FileNames = Directory.GetFiles(Folder2, "*.*", SearchOption.AllDirectories);

                                foreach (string FileName in FileNames)
                                {
                                    await ExportFile(FileName, Output);
                                }
                            }
                        }
                    }
                    finally
                    {
                        await Output.EndFiles();
                    }
                }

                Log.Informational("Export successfully completed.", Output.FileName);
            }
            catch (Exception ex)
            {
                Log.Critical(ex);

                string[] Tabs = ClientEvents.GetTabIDsForLocation("/Backup.md");
                ClientEvents.PushEvent(Tabs, "BackupFailed", "{\"fileName\":\"" + CommonTypes.JsonStringEncode(Output.FileName) +
                                       "\", \"message\": \"" + CommonTypes.JsonStringEncode(ex.Message) + "\"}", true, "User");
            }
            finally
            {
                try
                {
                    await Output.End();

                    Output.Dispose();
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }

                lock (synchObject)
                {
                    exporting = false;
                }
            }
        }
        private Task GetGroups(HttpRequest Request, HttpResponse Response)
        {
            Gateway.AssertUserAuthenticated(Request, this.ConfigPrivilege);

            if (!Request.HasData)
            {
                throw new BadRequestException();
            }

            string StartsWith = Request.DecodeData() as string;

            if (string.IsNullOrEmpty(StartsWith))
            {
                throw new BadRequestException();
            }

            SuggestionEventArgs e = new SuggestionEventArgs(StartsWith.Trim());

            foreach (RosterItem Item in Gateway.XmppClient.Roster)
            {
                foreach (string Group in Item.Groups)
                {
                    e.AddSuggestion(Group);
                }
            }

            try
            {
                OnGetGroupSuggestions?.Invoke(this, e);
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }

            StringBuilder sb = new StringBuilder();

            string[] Groups = e.ToArray();
            bool     First  = true;
            int      Nr     = 0;

            sb.Append("{\"groups\":[");

            foreach (string Group in Groups)
            {
                if (First)
                {
                    First = false;
                }
                else
                {
                    sb.Append(',');
                }

                sb.Append('"');
                sb.Append(CommonTypes.JsonStringEncode(Group));
                sb.Append('"');

                Nr++;
            }

            sb.Append("],\"count\":");
            sb.Append(Nr.ToString());
            sb.Append("}");

            Response.ContentType = "application/json";
            return(Response.Write(sb.ToString()));
        }
        /// <summary>
        /// Analyzes the object database
        /// </summary>
        /// <param name="FullPath">Full path of report file</param>
        /// <param name="FileName">Filename of report</param>
        /// <param name="Created">Time when report file was created</param>
        /// <param name="XmlOutput">XML Output</param>
        /// <param name="fs">File stream</param>
        /// <param name="Repair">If database should be repaired, if errors are found</param>
        public static async Task DoAnalyze(string FullPath, string FileName, DateTime Created, XmlWriter XmlOutput, FileStream fs, bool Repair)
        {
            try
            {
                Log.Informational("Starting analyzing database.", FileName);

                ExportFormats.ExportFormat.UpdateClientsFileUpdated(FileName, 0, Created);

                await Database.Analyze(XmlOutput, Path.Combine(Gateway.AppDataFolder, "Transforms", "DbStatXmlToHtml.xslt"),
                                       Gateway.AppDataFolder, false, Repair);

                XmlOutput.Flush();
                fs.Flush();

                ExportFormats.ExportFormat.UpdateClientsFileUpdated(FileName, fs.Length, Created);

                XmlOutput.Dispose();
                XmlOutput = null;

                fs.Dispose();
                fs = null;

                if (xslt is null)
                {
                    xslt = XSL.LoadTransform(typeof(Gateway).Namespace + ".Transforms.DbStatXmlToHtml.xslt");
                }

                string s = File.ReadAllText(FullPath);
                s = XSL.Transform(s, xslt);
                byte[] Bin = utf8Bom.GetBytes(s);

                string FullPath2 = FullPath.Substring(0, FullPath.Length - 4) + ".html";
                File.WriteAllBytes(FullPath2, Bin);

                ExportFormats.ExportFormat.UpdateClientsFileUpdated(FileName.Substring(0, FileName.Length - 4) + ".html", Bin.Length, Created);

                Log.Informational("Database analysis successfully completed.", FileName);
            }
            catch (Exception ex)
            {
                Log.Critical(ex);

                string[] Tabs = ClientEvents.GetTabIDsForLocation("/Settings/Backup.md");
                ClientEvents.PushEvent(Tabs, "BackupFailed", "{\"fileName\":\"" + CommonTypes.JsonStringEncode(FileName) +
                                       "\", \"message\": \"" + CommonTypes.JsonStringEncode(ex.Message) + "\"}", true, "User");
            }
            finally
            {
                try
                {
                    XmlOutput?.Dispose();
                    fs?.Dispose();
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }

                lock (synchObject)
                {
                    analyzing = false;
                }
            }
        }