Example #1
0
        private static List <Rdp> ConvertRdpRdmToRdp(List <RdpRDM> rdpRdmList, List <GroupRDM> groups, List <string> listaIdIstniejacychElementow)
        {
            IBazaDanych db   = new BazaLocalDb();
            List <Rdp>  list = new List <Rdp>();

            for (int i = 0; i < list.Count; i++)
            {
                if (listaIdIstniejacychElementow.Any(a => a == list[i].Klucz))
                {
                    list.Remove(list[i]);
                    ilosPominietychElementow++;
                }
            }

            foreach (RdpRDM RdpRdm in rdpRdmList)
            {
                string group = "";

                foreach (var item in groups)
                {
                    if (item.group.Length >= RdpRdm.group.Length && item.group.Substring(0, RdpRdm.group.Length) == RdpRdm.group)
                    {
                        group = item.id;
                    }
                }
                Rdp rdp = new Rdp(RdpRdm.name, group, RdpRdm.description, "hasło", "Rdp", RdpRdm.url, "", RdpRdm.id);
                db.DodajElement(rdp);
                IloscPoprawnieZaimportowanych++;
            }
            return(list);
        }
Example #2
0
 public void TestMethod1()
 {
     Rdp.SetRdpEnabled(true);
     Assert.IsTrue(Rdp.GetRdpEnabled());
     Rdp.SetRdpEnabled(false);
     Assert.IsFalse(Rdp.GetRdpEnabled());
 }
Example #3
0
 public ResponseBase EnableWindowsRemoteDesktop()
 {
     try {
         Rdp.SetRdpEnabled(true, true);
         Firewall.AddRemoteDesktopRule();
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Example #4
0
        static bool ConsoleEventCallback(int eventType)
        {
            //Console is being forcefully closed. Make sure that remote desktop is disabled
            if (eventType == 2 && disableOnClose)
            {
                Console.WriteLine("Attempting to disable remote desktop connections.");

                Rdp.SetRdpEnabled(false);
                Firewall.RemoveRemoteDesktopRule();

                Console.Write("Remote desktop connections disabled.");
            }
            return(false);
        }
Example #5
0
        private void TemporarelyEnableRemoteDesktop(int seconds)
        {
            Rdp.SetRdpEnabled(true);
            ShowRdpStatus();

            Console.WriteLine();

            Firewall.AddRemoteDesktopRule();
            ShowFirewallStatus();

            Console.WriteLine();

            System.Threading.Thread.Sleep(seconds * 1000);

            Rdp.SetRdpEnabled(false);
            ShowRdpStatus();

            Console.WriteLine();
        }
Example #6
0
 private void Link()
 {
     VirtualRoot.Window <CloseNTMinerCommand>("处理关闭NTMiner客户端命令", LogEnum.UserConsole,
                                              action: message => {
         UIThread.Execute(() => {
             try {
                 if (MainWindow != null)
                 {
                     MainWindow.Close();
                 }
                 Shutdown();
             }
             catch (Exception e) {
                 Logger.ErrorDebugLine(e);
                 Environment.Exit(0);
             }
         });
     });
     VirtualRoot.Window <CloseMainWindowCommand>("处理关闭主界面命令", LogEnum.DevConsole,
                                                 action: message => {
         UIThread.Execute(() => {
             if (NTMinerRoot.GetIsCloseMeanExit())
             {
                 VirtualRoot.Execute(new CloseNTMinerCommand());
                 return;
             }
             MainWindow = NotiCenterWindow.Instance;
             foreach (Window window in Windows)
             {
                 if (window != MainWindow)
                 {
                     window.Close();
                 }
             }
             NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage(message.Message, "开源矿工");
         });
     });
     #region 周期确保守护进程在运行
     VirtualRoot.On <Per1MinuteEvent>("周期确保守护进程在运行", LogEnum.DevConsole,
                                      action: message => {
         Daemon.DaemonUtil.RunNTMinerDaemon();
     });
     #endregion
     #region 1080小药丸
     VirtualRoot.On <MineStartedEvent>("开始挖矿后启动1080ti小药丸、挖矿开始后如果需要启动DevConsole则启动DevConsole", LogEnum.DevConsole,
                                       action: message => {
         // 启动DevConsole
         if (NTMinerRoot.IsUseDevConsole)
         {
             var mineContext     = message.MineContext;
             string poolIp       = mineContext.MainCoinPool.GetIp();
             string consoleTitle = mineContext.MainCoinPool.Server;
             Daemon.DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle);
         }
         OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Start();
     });
     VirtualRoot.On <MineStopedEvent>("停止挖矿后停止1080ti小药丸", LogEnum.DevConsole,
                                      action: message => {
         OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop();
     });
     #endregion
     #region 处理禁用win10系统更新
     VirtualRoot.Window <BlockWAUCommand>("处理禁用win10系统更新命令", LogEnum.DevConsole,
                                          action: message => {
         NTMiner.Windows.WindowsUtil.BlockWAU();
     });
     #endregion
     #region 优化windows
     VirtualRoot.Window <Win10OptimizeCommand>("处理优化windows命令", LogEnum.DevConsole,
                                               action: message => {
         NTMiner.Windows.WindowsUtil.Win10Optimize();
     });
     #endregion
     #region 处理开启A卡计算模式
     VirtualRoot.Window <SwitchRadeonGpuCommand>("处理开启A卡计算模式命令", LogEnum.DevConsole,
                                                 action: message => {
         if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD)
         {
             SwitchRadeonGpuMode();
         }
     });
     #endregion
     #region 处理A卡驱动签名
     VirtualRoot.Window <AtikmdagPatcherCommand>("处理A卡驱动签名命令", LogEnum.DevConsole,
                                                 action: message => {
         if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD)
         {
             AtikmdagPatcher.AtikmdagPatcherUtil.Run();
         }
     });
     #endregion
     #region 启用或禁用windows远程桌面
     VirtualRoot.Window <EnableWindowsRemoteDesktopCommand>("处理启用或禁用Windows远程桌面命令", LogEnum.DevConsole,
                                                            action: message => {
         if (NTMinerRoot.GetIsRemoteDesktopEnabled())
         {
             return;
         }
         string msg = "确定启用Windows远程桌面吗?";
         DialogWindow.ShowDialog(message: msg, title: "确认", onYes: () => {
             Rdp.SetRdpEnabled(true, true);
             Firewall.AddRemoteDesktopRule();
         }, icon: IconConst.IconConfirm);
     });
     #endregion
     #region 启用或禁用windows开机自动登录
     VirtualRoot.Window <EnableOrDisableWindowsAutoLoginCommand>("处理启用或禁用Windows开机自动登录命令", LogEnum.DevConsole,
                                                                 action: message => {
         if (NTMiner.Windows.OS.Instance.IsAutoAdminLogon)
         {
             return;
         }
         NTMiner.Windows.Cmd.RunClose("control", "userpasswords2");
     });
     #endregion
 }
Example #7
0
 private void Link()
 {
     VirtualRoot.BuildEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole,
                                                          action: message => {
         AppContext.Instance.MinerProfileVm.IsMining = false;
         VirtualRoot.Out.ShowError(message.Message);
     });
     #region 处理显示主界面命令
     VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(action: message => {
         ShowMainWindow(message.IsToggle);
     });
     #endregion
     VirtualRoot.BuildCmdPath <CloseNTMinerCommand>(action: message => {
         // 不能推迟这个日志记录的时机,因为推迟会有windows异常日志
         VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"退出{VirtualRoot.AppName}。原因:{message.Reason}");
         UIThread.Execute(() => {
             try {
                 Shutdown();
             }
             catch (Exception e) {
                 Logger.ErrorDebugLine(e);
                 Environment.Exit(0);
             }
         });
     });
     #region 周期确保守护进程在运行
     VirtualRoot.BuildEventPath <Per1MinuteEvent>("周期确保守护进程在运行", LogEnum.DevConsole,
                                                  action: message => {
         Daemon.DaemonUtil.RunNTMinerDaemon();
     });
     #endregion
     #region 开始和停止挖矿后
     VirtualRoot.BuildEventPath <MineStartedEvent>("启动1080ti小药丸、启动DevConsole? 更新挖矿按钮状态", LogEnum.DevConsole,
                                                   action: message => {
         AppContext.Instance.MinerProfileVm.IsMining       = true;
         StartStopMineButtonViewModel.Instance.BtnStopText = "正在挖矿";
         // 启动DevConsole
         if (NTMinerRoot.IsUseDevConsole)
         {
             var mineContext     = message.MineContext;
             string poolIp       = mineContext.MainCoinPool.GetIp();
             string consoleTitle = mineContext.MainCoinPool.Server;
             Daemon.DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle);
         }
         OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Start();
     });
     VirtualRoot.BuildEventPath <MineStopedEvent>("停止挖矿后停止1080ti小药丸 挖矿停止后更新界面挖矿状态", LogEnum.DevConsole,
                                                  action: message => {
         AppContext.Instance.MinerProfileVm.IsMining       = false;
         StartStopMineButtonViewModel.Instance.BtnStopText = "尚未开始";
         OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop();
     });
     #endregion
     #region 处理禁用win10系统更新
     VirtualRoot.BuildCmdPath <BlockWAUCommand>(action: message => {
         NTMiner.Windows.WindowsUtil.BlockWAU();
     });
     #endregion
     #region 优化windows
     VirtualRoot.BuildCmdPath <Win10OptimizeCommand>(action: message => {
         NTMiner.Windows.WindowsUtil.Win10Optimize();
     });
     #endregion
     #region 处理开启A卡计算模式
     VirtualRoot.BuildCmdPath <SwitchRadeonGpuCommand>(action: message => {
         if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD)
         {
             SwitchRadeonGpuMode(message.On);
         }
     });
     #endregion
     #region 处理A卡驱动签名
     VirtualRoot.BuildCmdPath <AtikmdagPatcherCommand>(action: message => {
         if (NTMinerRoot.Instance.GpuSet.GpuType == GpuType.AMD)
         {
             AtikmdagPatcher.AtikmdagPatcherUtil.Run();
         }
     });
     #endregion
     #region 启用或禁用windows远程桌面
     VirtualRoot.BuildCmdPath <EnableWindowsRemoteDesktopCommand>(action: message => {
         if (NTMinerRegistry.GetIsRemoteDesktopEnabled())
         {
             return;
         }
         string msg = "确定启用Windows远程桌面吗?";
         DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                         message: msg,
                                         title: "确认",
                                         onYes: () => {
             Rdp.SetRdpEnabled(true);
             Firewall.AddRdpRule();
         }));
     });
     #endregion
     #region 启用或禁用windows开机自动登录
     VirtualRoot.BuildCmdPath <EnableOrDisableWindowsAutoLoginCommand>(action: message => {
         if (NTMiner.Windows.OS.Instance.IsAutoAdminLogon)
         {
             return;
         }
         NTMiner.Windows.Cmd.RunClose("control", "userpasswords2");
     });
     #endregion
 }
Example #8
0
 // SendExtKey - клавиша отпущена
 internal static void SendKeyExOff(uint key)
 {
     Rdp.SendInput(Main.InputTime++, Rdp.InputType.INPUT_EVENT_SCANCODE, (int)(Rdp.KeyboardFlags.KBDFLAGS_EXTENDED | Rdp.KeyboardFlags.KBDFLAGS_RELEASE), key, 0);
 }
Example #9
0
 // SendKey - клавиша нажата
 internal static void SendKeyOn(uint key)
 {
     Rdp.SendInput(Main.InputTime++, Rdp.InputType.INPUT_EVENT_SCANCODE, (int)Rdp.KeyboardFlags.KBDFLAGS_DOWN, key, 0);
 }
Example #10
0
 // SendKey - клавиша нажата и отпущена
 internal static void SendKey(uint key)
 {
     Rdp.SendInput(Main.InputTime++, Rdp.InputType.INPUT_EVENT_SCANCODE, (int)Rdp.KeyboardFlags.KBDFLAGS_DOWN, key, 0);
     Rdp.SendInput(Main.InputTime++, Rdp.InputType.INPUT_EVENT_SCANCODE, (int)Rdp.KeyboardFlags.KBDFLAGS_RELEASE, key, 0);
     Thread.Sleep(11);
 }
Example #11
0
 // SendKey - клавиша нажата и отпущена
 internal static void SendKey(uint key)
 {
     Rdp.SendInput(Main.InputTime++, Rdp.InputType.INPUT_EVENT_UNICODE, 0, key, 0);
     Rdp.SendInput(Main.InputTime++, Rdp.InputType.INPUT_EVENT_UNICODE, (int)Rdp.KeyboardFlags.KBDFLAGS_RELEASE, key, 0);
 }
Example #12
0
 private static void deserializujRdp(XmlNode node, out Element element)
 {
     element = new Rdp(node.Attributes["Name"].InnerText, node.Attributes["Group"].InnerText, node.Attributes["Description"].InnerText, node.Attributes["Password"].InnerText, node.Attributes["Type"].InnerText, node.Attributes["Address"].InnerText, node.Attributes["Login"].InnerText, node.Attributes["Id"].InnerText);
 }
Example #13
0
        public static void serializuj(Element obj)
        {
            try
            {
                string      connectionsPath = Properties.Settings.Default.baseXmlPath;
                XmlDocument xml             = new XmlDocument();

                xml.Load(connectionsPath);
                XmlNode rootNode = xml["Connections"];

                XmlNode connectNode = xml.CreateElement(obj.GetType().Name);

                connectNode.Attributes.Append(xml.CreateAttribute("Id"));
                connectNode.Attributes.Append(xml.CreateAttribute("Group"));
                connectNode.Attributes.Append(xml.CreateAttribute("Name"));
                connectNode.Attributes.Append(xml.CreateAttribute("Type"));
                connectNode.Attributes.Append(xml.CreateAttribute("Description"));

                connectNode.Attributes["Id"].InnerText = obj.id.ToString();

                if (obj.parent is Folder)
                {
                    connectNode.Attributes["Group"].InnerText = (obj.parent as Folder).id.ToString();
                }
                else if (!string.IsNullOrWhiteSpace(obj.group))
                {
                    connectNode.Attributes["Group"].InnerText = obj.group;
                }
                else
                {
                    connectNode.Attributes["Group"].InnerText = "";
                }

                connectNode.Attributes["Description"].InnerText = obj.opis;

                if (obj is Klient)
                {
                    Klient klient = (Klient)obj;

                    connectNode.Attributes["Type"].InnerText = "Klient";
                    connectNode.Attributes["Name"].InnerText = klient.nazwa;


                    XmlNode emails = xml.CreateElement("Emails");

                    for (int i = 0; i < klient.emailList.Count; i++)
                    {
                        XmlNode email = xml.CreateElement("Email");
                        email.Attributes.Append(xml.CreateAttribute("Address"));
                        email.Attributes["Address"].InnerText = klient.emailList[i].adresEmail;
                        emails.AppendChild(email);
                    }

                    connectNode.AppendChild(emails);


                    XmlNode phones = xml.CreateElement("Phones");

                    for (int i = 0; i < klient.telefonList.Count; i++)
                    {
                        XmlNode phone = xml.CreateElement("Phone");
                        phone.Attributes.Append(xml.CreateAttribute("Name"));
                        phone.Attributes.Append(xml.CreateAttribute("Number"));
                        phone.Attributes["Name"].InnerText   = klient.telefonList[i].nazwa;
                        phone.Attributes["Number"].InnerText = klient.telefonList[i].numer;
                        phones.AppendChild(phone);
                    }

                    connectNode.AppendChild(phones);


                    XmlNode credentials = xml.CreateElement("Credentials");

                    for (int i = 0; i < klient.daneLogowaniaList.Count; i++)
                    {
                        XmlNode credential = xml.CreateElement("Credential");
                        credential.Attributes.Append(xml.CreateAttribute("Login"));
                        credential.Attributes.Append(xml.CreateAttribute("Password"));
                        credential.Attributes.Append(xml.CreateAttribute("Type"));
                        credential.Attributes["Login"].InnerText    = klient.daneLogowaniaList[i].login;
                        credential.Attributes["Password"].InnerText = klient.daneLogowaniaList[i].haslo;
                        credential.Attributes["Type"].InnerText     = klient.daneLogowaniaList[i].system;
                        credentials.AppendChild(credential);
                    }
                    connectNode.AppendChild(credentials);
                }
                else if (obj is Folder) // if obj is Folder
                {
                    connectNode.Attributes["Type"].InnerText = "Folder";
                    connectNode.Attributes["Name"].InnerText = obj.nazwa;
                }
                else if (obj is TeamViewer)
                {
                    TeamViewer tv = obj as TeamViewer;
                    connectNode.Attributes.Append(xml.CreateAttribute("TeamViewerId"));
                    connectNode.Attributes.Append(xml.CreateAttribute("Password"));

                    connectNode.Attributes["Name"].InnerText         = tv.nazwa;
                    connectNode.Attributes["Type"].InnerText         = "TeamViewer";
                    connectNode.Attributes["TeamViewerId"].InnerText = tv.teamViewerId;
                    if (string.IsNullOrWhiteSpace(tv.haslo))
                    {
                        tv.haslo = Properties.Settings.Default.defaultPasswordOfTeamViewer;
                    }
                    connectNode.Attributes["Password"].InnerText = tv.haslo;
                }
                else if (obj is Rdp)
                {
                    Rdp rdp = obj as Rdp;
                    connectNode.Attributes.Append(xml.CreateAttribute("Address"));
                    connectNode.Attributes.Append(xml.CreateAttribute("Login"));
                    connectNode.Attributes.Append(xml.CreateAttribute("Password"));

                    connectNode.Attributes["Name"].InnerText     = rdp.nazwa;
                    connectNode.Attributes["Type"].InnerText     = "Rdp";
                    connectNode.Attributes["Address"].InnerText  = rdp.adresRDP;
                    connectNode.Attributes["Login"].InnerText    = rdp.login;
                    connectNode.Attributes["Password"].InnerText = rdp.haslo;
                }


                rootNode.AppendChild(connectNode);

                xml.Save(connectionsPath);
            }
            catch (Exception ex)
            {
                MyMessageBox.Show("Treść błędu: \n" + ex.Message, "Wystąpił nieoczekiwany błąd", MyMessageBoxButtons.Ok);
            }
        }
Example #14
0
        private void ShowRdpStatus()
        {
            var status = Rdp.GetStatus();

            Console.WriteLine($"Remote Desktop connections {status.ToString()}");
        }
Example #15
0
 private void ForceRdpDisable()
 {
     Rdp.SetRdpEnabled(false, true);
     ShowRdpStatus();
 }