예제 #1
0
		public PowwaSession CreateSession(string sessionId, RunspaceConnectionInfo connectionInfo, ClientInfo clientInfo, string authenticatedUserName)
		{
			bool flag = false;
			PowwaSession powwaSession;
			PowwaSession stringSid = new PowwaSession(sessionId, authenticatedUserName, connectionInfo, clientInfo);
			string str = null;
			stringSid.AuthenticatedUserSid = PowwaAuthorizationManager.Instance.activeDirectoryHelper.ConvertAccountNameToStringSid(authenticatedUserName, out flag, out str);
			lock (this.sessionsLock)
			{
				bool userActiveSessions = this.GetUserActiveSessions(stringSid.AuthenticatedUserSid) < PowwaAuthorizationManager.Instance.UserSessionsLimit;
				if (userActiveSessions)
				{
					stringSid.Name = this.GetSessionName(stringSid);
					try
					{
						this.sessions.Add(sessionId, stringSid);
					}
					catch (ArgumentException argumentException)
					{
						PowwaEvents.PowwaEVENT_DEBUG_LOG0("CreateSession: Attempt to create a session that already exists");
						throw new ArgumentException("There is already a PowWA session with the given ID", "sessionId");
					}
					powwaSession = stringSid;
				}
				else
				{
					object[] objArray = new object[1];
					objArray[0] = authenticatedUserName;
					throw new Exception(string.Format(CultureInfo.CurrentCulture, Resources.UserActiveSessionLimitReached, objArray));
				}
			}
			return powwaSession;
		}
예제 #2
0
		public PowwaHostRawUserInterface(ClientInfo clientInfo)
		{
			this.backgroundColor = ConsoleColor.DarkBlue;
			this.foregroundColor = ConsoleColor.White;
			this.windowTitle = string.Empty;
			if (!HtmlHelper.IsMobileBrowser(clientInfo.Agent))
			{
				this.bufferSize = PowwaHostRawUserInterface.DefaultBufferSizeDesktop;
				this.maxBufferSize = PowwaHostRawUserInterface.MaxBufferSizeDesktop;
				this.minBufferSize = PowwaHostRawUserInterface.MinBufferSizeDesktop;
				this.windowSize = PowwaHostRawUserInterface.DefaultWindowSizeDesktop;
				this.maxWindowSize = PowwaHostRawUserInterface.MaxWindowSizeDesktop;
				this.minWindowSize = PowwaHostRawUserInterface.MinWindowSizeDesktop;
				return;
			}
			else
			{
				this.bufferSize = PowwaHostRawUserInterface.DefaultBufferSizeMobile;
				this.maxBufferSize = PowwaHostRawUserInterface.MaxBufferSizeMobile;
				this.minBufferSize = PowwaHostRawUserInterface.MinBufferSizeMobile;
				this.windowSize = PowwaHostRawUserInterface.DefaultWindowSizeMobile;
				this.maxWindowSize = PowwaHostRawUserInterface.MaxWindowSizeMobile;
				this.minWindowSize = PowwaHostRawUserInterface.MinWindowSizeMobile;
				return;
			}
		}
예제 #3
0
파일: LogOn.cs 프로젝트: nickchal/pash
		private void CreateSession(LogOn.FormInfo formInfo)
		{
			string str;
			string applicationName;
			string str1;
			string originalString;
			WSManConnectionInfo wSManConnectionInfo = null;
			if (formInfo.ConfigurationName.Length == 0)
			{
				str = null;
			}
			else
			{
				str = string.Concat("http://schemas.microsoft.com/powershell/", formInfo.ConfigurationName);
			}
			string str2 = str;
			PSCredential pSCredential = new PSCredential(formInfo.DestinationUserName, formInfo.DestinationPassword);
			if (!formInfo.IsUriConnection)
			{
				if (string.Compare(formInfo.ApplicationName, "WSMAN", StringComparison.OrdinalIgnoreCase) == 0)
				{
					applicationName = null;
				}
				else
				{
					applicationName = formInfo.ApplicationName;
				}
				string str3 = applicationName;
				try
				{
					wSManConnectionInfo = new WSManConnectionInfo(formInfo.UseSsl, formInfo.ComputerName, formInfo.Port, str3, str2, pSCredential);
				}
				catch (UriFormatException uriFormatException)
				{
					throw PowwaException.CreateValidationErrorException(Resources.LogonError_InvalidComputerNameUriFormat);
				}
				wSManConnectionInfo.AuthenticationMechanism = formInfo.AuthenticationType;
				PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_COMPUTERNAME(formInfo.DestinationUserName, wSManConnectionInfo.ComputerName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri, wSManConnectionInfo.AuthenticationMechanism.ToString());
			}
			else
			{
				wSManConnectionInfo = new WSManConnectionInfo(formInfo.ConnectionUri, str2, pSCredential);
				if (!formInfo.AllowRedirection)
				{
					wSManConnectionInfo.MaximumConnectionRedirectionCount = 0;
				}
				PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_URI(formInfo.DestinationUserName, wSManConnectionInfo.ConnectionUri.AbsoluteUri, wSManConnectionInfo.ShellUri);
			}
			string sourceIPAddressRemoteAddr = SessionHelper.GetSourceIPAddressRemoteAddr();
			string sourceIPAddressHttpXForwardedFor = SessionHelper.GetSourceIPAddressHttpXForwardedFor();
			if (formInfo.IsUriConnection)
			{
				str1 = null;
			}
			else
			{
				str1 = PswaHelper.TranslateLocalComputerName(formInfo.ComputerName);
			}
			string str4 = str1;
			PowwaAuthorizationManager.Instance.CheckLogOnCredential(formInfo.UserName, formInfo.Password, str4, formInfo.ConnectionUri, formInfo.ConfigurationName, sourceIPAddressRemoteAddr, sourceIPAddressHttpXForwardedFor);
			ClientInfo clientInfo = new ClientInfo(HttpContext.Current.Request.UserAgent, CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture);
			PowwaSession powwaSession = PowwaSessionManager.Instance.CreateSession(this.Session.SessionID, wSManConnectionInfo, clientInfo, formInfo.UserName);
			string name = powwaSession.Name;
			string userName = formInfo.UserName;
			string str5 = sourceIPAddressRemoteAddr;
			string str6 = sourceIPAddressHttpXForwardedFor;
			if (formInfo.IsUriConnection)
			{
				originalString = wSManConnectionInfo.ConnectionUri.OriginalString;
			}
			else
			{
				originalString = wSManConnectionInfo.ComputerName;
			}
			PowwaEvents.PowwaEVENT_SESSION_START(name, userName, str5, str6, originalString, formInfo.DestinationUserName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri);
			HttpCookie item = base.Request.Cookies["ASP.NET_SessionId"];
			if (FormsAuthentication.RequireSSL && item != null)
			{
				item.Secure = true;
			}
			FormsAuthentication.SetAuthCookie(formInfo.UserName, false, "/");
			base.Response.Redirect ("~/default.aspx");
			//FormsAuthentication.RedirectFromLoginPage(formInfo.UserName, false);
		}
예제 #4
0
        internal PowwaSession(string sessionId, string sessionUser, RunspaceConnectionInfo connectionInfo, ClientInfo clientInfo)
        {
            EventHandler <MessageCreatedEventArgs> eventHandler  = null;
            EventHandler <MessageCreatedEventArgs> eventHandler1 = null;
            EventHandler <MessageCreatedEventArgs> eventHandler2 = null;

            if (sessionId != null)
            {
                if (connectionInfo != null)
                {
                    if (clientInfo != null)
                    {
                        this.Id       = sessionId;
                        this.Name     = string.Empty;
                        this.UserName = sessionUser;
                        this.host     = new PowwaHost(clientInfo);
                        this.host.UI.RawUI.WindowTitle = connectionInfo.ComputerName;
                        PowwaHost powwaHost = this.host;
                        if (eventHandler == null)
                        {
                            eventHandler = (object sender, MessageCreatedEventArgs e) => this.OnClientMessageCreated(e);
                        }
                        powwaHost.MessageCreated += eventHandler;
                        IMessageCreated uI = (IMessageCreated)this.host.UI;
                        if (eventHandler1 == null)
                        {
                            eventHandler1 = (object sender, MessageCreatedEventArgs e) => this.OnClientMessageCreated(e);
                        }
                        uI.MessageCreated += eventHandler1;
                        IMessageCreated rawUI = (IMessageCreated)this.host.UI.RawUI;
                        if (eventHandler2 == null)
                        {
                            eventHandler2 = (object sender, MessageCreatedEventArgs e) => this.OnClientMessageCreated(e);
                        }
                        rawUI.MessageCreated                    += eventHandler2;
                        this.Runspace                            = RunspaceFactory.CreateRunspace(connectionInfo, this.host, PowwaSession.TypeTableLoader.Instance.LoadDefaultTypeFiles());
                        this.Runspace.StateChanged              += new EventHandler <RunspaceStateEventArgs>(this.OnRunspaceStateChanged);
                        this.executingCommandPowerShell          = System.Management.Automation.PowerShell.Create();
                        this.executingCommandPowerShell.Runspace = this.Runspace;
                        this.executingCommandPowerShell.InvocationStateChanged += new EventHandler <PSInvocationStateChangedEventArgs>(this.OnExecutingCommandInvocationStateChanged);
                        this.messageQueue      = new MessageQueue();
                        this.clientRequestLock = new object();
                        this.cancelCommandLock = new object();
                        this.sessionStateLock  = new object();
                        this.SessionKey        = PowwaSession.CreateSessionKey();
                        this.State             = PowwaSession.SessionState.Available;
                        try {
                            this.Runspace.Open();
                        }
                        catch (Exception ex)
                        {
                            var stackTrace = ex.StackTrace;
                            System.Diagnostics.Debug.WriteLine(stackTrace);
                        }
                        this.exec = new Microsoft.PowerShell.Executor(this.host, false, false);
                        this.exec.OutputHandler += HandleOutputHandler;
                        if (this.messageQueue.GetMessageCount() > 0)
                        {
                            this.PostClientMessage(new CommandCompletedMessage(this.GetPowerShellPrompt()), false);
                        }
                        return;
                    }
                    else
                    {
                        throw new ArgumentNullException("clientInfo");
                    }
                }
                else
                {
                    throw new ArgumentNullException("connectionInfo");
                }
            }
            else
            {
                throw new ArgumentNullException("sessionId");
            }
        }
예제 #5
0
		public PowwaHostUserInterface(ClientInfo clientInfo)
		{
			this.rawUi = new PowwaHostRawUserInterface(clientInfo);
		}
예제 #6
0
파일: PowwaHost.cs 프로젝트: nickchal/pash
		public PowwaHost(ClientInfo clientInfo)
		{
			this.instanceId = new Guid("3BADF81F-2A26-468B-ADCC-F93DC13F8084");
			this.version = new Version(1, 0, 0);
			this.userInterface = new PowwaHostUserInterface(clientInfo);
			this.currentCulture = clientInfo.CurrentCulture;
			this.currentUICulture = clientInfo.CurrentUICulture;
			standardErrorWriter = new WebWriter(this);
			standardOutputWriter = new WebWriter(this);
			standardInputReader = new WebReader(this);
		}