Esempio n. 1
0
 private static async void Pipe_ClientMessage(NamedPipeWrapper.NamedPipeConnection <RPAMessage, RPAMessage> connection, RPAMessage message)
 {
     if (message.command == "pong")
     {
         return;
     }
     if (message.command == "hello")
     {
         var windowsusername = message.windowsusername.ToLower();
         var session         = sessions.Where(x => x.client.windowsusername == windowsusername).FirstOrDefault();
         if (session == null)
         {
             //Log.Information("Adding new unattendedclient for " + windowsusername);
             string computername = NativeMethods.GetHostName().ToLower();
             string computerfqdn = NativeMethods.GetFQDN().ToLower();
             var    client       = new unattendedclient()
             {
                 computername = computername, computerfqdn = computerfqdn, windowsusername = windowsusername, name = computername + " " + windowsusername, openrpapath = message.openrpapath
             };
             // client = await global.webSocketClient.InsertOne("openrpa", 1, false, client);
             session = new RobotUserSession(client);
             sessions.Add(session);
         }
         if (session.client != null)
         {
             session.client.openrpapath = message.openrpapath;
             session.AddConnection(connection);
         }
     }
     if (message.command == "reloadconfig")
     {
         await ReloadConfig();
     }
 }
Esempio n. 2
0
        private static async Task ReloadConfig()
        {
            try
            {
                string computername = NativeMethods.GetHostName().ToLower();
                string computerfqdn = NativeMethods.GetFQDN().ToLower();

                var servers = await global.webSocketClient.Query <unattendedserver>("openrpa", "{'_type':'unattendedserver', 'computername':'" + computername + "', 'computerfqdn':'" + computerfqdn + "'}");

                server = servers.FirstOrDefault();

                unattendedclient[] clients = new unattendedclient[] { };
                if (server != null && server.enabled)
                {
                    disabledmessageshown = false;
                    clients = await global.webSocketClient.Query <unattendedclient>("openrpa", "{'_type':'unattendedclient', 'computername':'" + computername + "', 'computerfqdn':'" + computerfqdn + "'}");
                }
                else if (disabledmessageshown == false)
                {
                    Log.Information("No server for " + computerfqdn + " found, or server is disabled");
                    disabledmessageshown = true;
                }
                var sessioncount = sessions.Count();
                foreach (var c in clients)
                {
                    RobotUserSession session = null;
                    if (sessions != null)
                    {
                        session = sessions.Where(x => x.client.windowsusername == c.windowsusername).FirstOrDefault();
                    }
                    if (session == null)
                    {
                        if (c.enabled)
                        {
                            UnattendedclientUpdated(c);
                        }
                    }
                    else
                    {
                        if (c._modified != session.client._modified || c._version != session.client._version)
                        {
                            UnattendedclientUpdated(c);
                        }
                    }
                }
                cleanup();
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
Esempio n. 3
0
        private static void UnattendedclientUpdated(unattendedclient unattendedclient)
        {
            if (unattendedclient == null)
            {
                return;
            }
            try
            {
                RobotUserSession session = null;
                if (sessions != null)
                {
                    session = sessions.Where(x => x.client._id == unattendedclient._id).FirstOrDefault();
                }
                if (!unattendedclient.enabled)
                {
                    if (session != null)
                    {
                        session.client = unattendedclient;
                        if (session.rdp != null || session.freerdp != null)
                        {
                            Log.Information("disconnecting session for " + session.client.windowsusername);
                            try
                            {
                                session.disconnectrdp();
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex.ToString());
                            }
                        }
                    }
                    Log.Information("GetOwnerExplorer");
                    System.Diagnostics.Process ownerexplorer = RobotUserSession.GetOwnerExplorer(unattendedclient);
                    if (ownerexplorer != null)
                    {
                        if (server.logoff || session.client.autosignout)
                        {
                            Log.Information("WTSLogoffSession " + ownerexplorer.SessionId);
                            NativeMethods.WTSLogoffSession(IntPtr.Zero, (int)ownerexplorer.SessionId, true);
                        }
                        else
                        {
                            Log.Information("WTSDisconnectSession " + ownerexplorer.SessionId);
                            NativeMethods.WTSDisconnectSession(IntPtr.Zero, (int)ownerexplorer.SessionId, true);
                        }
                    }
                }
                if (unattendedclient.enabled)
                {
                    if (server != null && server.singleuser)
                    {
                        Log.Information("GetOwnerExplorer");
                        System.Diagnostics.Process ownerexplorer = RobotUserSession.GetOwnerExplorer(unattendedclient);
                        int sessionid = -1;
                        if (ownerexplorer != null)
                        {
                            sessionid = ownerexplorer.SessionId;
                        }
                        var procs = System.Diagnostics.Process.GetProcessesByName("explorer");
                        foreach (var explorer in procs)
                        {
                            if (explorer.SessionId != sessionid)
                            {
                                if (server.logoff || session.client.autosignout)
                                {
                                    Log.Information("WTSLogoffSession " + explorer.SessionId);
                                    NativeMethods.WTSLogoffSession(IntPtr.Zero, (int)explorer.SessionId, true);
                                }
                                else
                                {
                                    Log.Information("WTSDisconnectSession " + explorer.SessionId);
                                    NativeMethods.WTSDisconnectSession(IntPtr.Zero, (int)explorer.SessionId, true);
                                }
                            }
                        }
                    }
                    else if (server == null)
                    {
                        Log.Information("server is null!!!");
                    }

                    if (session != null)
                    {
                        Log.Information("Updating session for " + unattendedclient.windowsusername);
                        session.client = unattendedclient;
                        if (session.rdp == null && session.freerdp == null)
                        {
                            session.BeginWork();
                        }
                    }
                    else
                    {
                        Log.Information("Adding session for " + unattendedclient.windowsusername);
                        sessions.Add(new RobotUserSession(unattendedclient));
                    }
                }
                cleanup();
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
            finally
            {
            }
        }
Esempio n. 4
0
 public Process GetOwnerExplorer()
 {
     return(RobotUserSession.GetOwnerExplorer(client));
 }