Skip to content
Permalink
Browse files

Merge pull request #3681 from verhoek/epic/keyring/1-refactor-server-…

…program

Epic/keyring/1 refactor server program
  • Loading branch information...
kenkendk committed Mar 17, 2019
2 parents 9816cfa + 9a39276 commit 38dfdffb903a13a65169006b0d9444c25f92ef43
@@ -19,10 +19,8 @@
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Duplicati.Library.Localization.Short;
using Duplicati.Library.Utility;
using System.IO;
using Duplicati.Library.Common;

@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Duplicati.Library.Common;
using Duplicati.Library.Common;
using Duplicati.Library.Interface;

namespace Duplicati.GUI.TrayIcon
@@ -34,6 +34,11 @@ public enum PasswordSource
private const string DEFAULT_HOSTURL = "http://localhost:8200";

private static string _browser_command = null;
private static bool disableTrayIconLogin = false;
private static bool openui = false;
private static Uri serverURL = new Uri(DEFAULT_HOSTURL);


public static string BrowserCommand { get { return _browser_command; } }
public static Server.Database.Connection databaseConnection = null;

@@ -76,7 +81,7 @@ public static void RealMain(string[] _args)

if (Platform.IsClientWindows && (Duplicati.Library.AutoUpdater.UpdaterManager.IsRunningInUpdateEnvironment || !Duplicati.Library.Utility.Utility.ParseBoolOption(options, DETACHED_PROCESS)))
Duplicati.Library.Utility.Win32.AttachConsole(Duplicati.Library.Utility.Win32.ATTACH_PARENT_PROCESS);

foreach (string s in args)
if (
s.Equals("help", StringComparison.OrdinalIgnoreCase) ||
@@ -94,7 +99,7 @@ public static void RealMain(string[] _args)
{
Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);
if (arg.Name == TOOLKIT_OPTION)
Console.WriteLine(" Supported toolkits: {0}{1}", string.Join(", ", arg.ValidValues), Environment.NewLine);
Console.WriteLine(" Supported toolkits: {0}{1}", string.Join(", ", arg.ValidValues), Environment.NewLine);
}

Console.WriteLine("Additionally, these server options are also supported:");
@@ -107,7 +112,7 @@ public static void RealMain(string[] _args)
}

options.TryGetValue(BROWSER_COMMAND_OPTION, out _browser_command);

string toolkit;
if (!options.TryGetValue(TOOLKIT_OPTION, out toolkit))
{
@@ -117,7 +122,7 @@ public static void RealMain(string[] _args)
#endif
toolkit = GetDefaultToolKit();
}
else
else
{
if (TOOLKIT_WINDOWS_FORMS.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
toolkit = TOOLKIT_WINDOWS_FORMS;
@@ -136,10 +141,9 @@ public static void RealMain(string[] _args)
}

HostedInstanceKeeper hosted = null;
var openui = false;

string password = null;
var saltedpassword = false;
var serverURL = new Uri(DEFAULT_HOSTURL);

if (!Library.Utility.Utility.ParseBoolOption(options, NOHOSTEDSERVER_OPTION))
{
@@ -172,29 +176,28 @@ public static void RealMain(string[] _args)
Scheme = scheme
}).Uri;
}

if (Library.Utility.Utility.ParseBoolOption(options, NOHOSTEDSERVER_OPTION) && Library.Utility.Utility.ParseBoolOption(options, READCONFIGFROMDB_OPTION))
else if (Library.Utility.Utility.ParseBoolOption(options, READCONFIGFROMDB_OPTION))
{
databaseConnection = Server.Program.GetDatabaseConnection(options);

var disableTrayIconLogin = false;

if (databaseConnection != null)
{
disableTrayIconLogin = databaseConnection.ApplicationSettings.DisableTrayIconLogin;
password = databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon;
saltedpassword = false;
if (databaseConnection != null)
{
disableTrayIconLogin = databaseConnection.ApplicationSettings.DisableTrayIconLogin;
password = databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon;
saltedpassword = false;

var cert = databaseConnection.ApplicationSettings.ServerSSLCertificate;
var scheme = "http";
var cert = databaseConnection.ApplicationSettings.ServerSSLCertificate;
var scheme = "http";

if (cert != null && cert.HasPrivateKey)
scheme = "https";
if (cert != null && cert.HasPrivateKey)
scheme = "https";

serverURL = (new UriBuilder(serverURL)
serverURL = (new UriBuilder(serverURL)
{
Port = databaseConnection.ApplicationSettings.LastWebserverPort == -1 ? serverURL.Port : databaseConnection.ApplicationSettings.LastWebserverPort,
Scheme = scheme
}).Uri;
}
}

string pwd;
@@ -209,7 +212,12 @@ public static void RealMain(string[] _args)

if (options.TryGetValue(HOSTURL_OPTION, out url))
serverURL = new Uri(url);


StartTray(_args, options, toolkit, hosted, password, saltedpassword);
}

private static void StartTray(string[] _args, Dictionary<string, string> options, string toolkit, HostedInstanceKeeper hosted, string password, bool saltedpassword)
{
using (hosted)
{
var reSpawn = 0;
@@ -224,8 +232,8 @@ public static void RealMain(string[] _args)
{
using (var tk = RunTrayIcon(toolkit))
{
if (hosted != null && Server.Program.Instance != null)
Server.Program.Instance.SecondInstanceDetected +=
if (hosted != null && Server.Program.ApplicationInstance != null)
Server.Program.ApplicationInstance.SecondInstanceDetected +=
new Server.SingleInstance.SecondInstanceDelegate(
x => { tk.ShowUrlInWindow(serverURL.ToString()); });

@@ -47,12 +47,11 @@ internal void LogError(string backupid, string message, Exception ex)
{
lock(m_lock)
{
long id;
if (!long.TryParse(backupid, out id))
if (!long.TryParse(backupid, out long id))
id = -1;
((System.Data.IDbDataParameter)m_errorcmd.Parameters[0]).Value = id;
((System.Data.IDbDataParameter)m_errorcmd.Parameters[1]).Value = message;
((System.Data.IDbDataParameter)m_errorcmd.Parameters[2]).Value = ex == null ? null : ex.ToString();
((System.Data.IDbDataParameter)m_errorcmd.Parameters[2]).Value = ex?.ToString();
((System.Data.IDbDataParameter)m_errorcmd.Parameters[3]).Value = NormalizeDateTimeToEpochSeconds(DateTime.UtcNow);
m_errorcmd.ExecuteNonQuery();
}
@@ -179,8 +178,8 @@ internal void SetFilters(IEnumerable<IFilter> values, long id, System.Data.IDbTr
tr.Commit();
}
}
internal ISetting[] GetSettings(long id)

public ISetting[] GetSettings(long id)
{
lock(m_lock)
return ReadFromDb(
@@ -540,7 +539,7 @@ private void AddOrUpdateBackup(IBackup item, bool updateSchedule, ISchedule sche

return new object[] {
n.Name,
n.Description == null ? "" : n.Description, // Description is optional but the column is set to NOT NULL, an additional check is welcome
n.Description ?? "" , // Description is optional but the column is set to NOT NULL, an additional check is welcome
string.Join(",", n.Tags ?? new string[0]),
n.TargetURL,
update ? item.ID : n.DBPath
Oops, something went wrong.

0 comments on commit 38dfdff

Please sign in to comment.
You can’t perform that action at this time.