Exemplo n.º 1
0
        public SessionManagerHandler(FileHandlerFactoryLocator fileHandlerFactoryLocator, string path)
            : base(fileHandlerFactoryLocator)
        {
            this.persistedSessionDatas = new PersistedObject<Dictionary<ID<ISession, Guid>, SessionData>>(
                path,
                () => new Dictionary<ID<ISession, Guid>, SessionData>(),
                this.Deserialize,
                this.Serialize);

            me = this;

            this.persistedSessionDatas.Read(sessionDatas =>
            {
                this.sessions = new Dictionary<ID<ISession, Guid>, Session>(sessionDatas.Count);

                foreach (var sessionDataKVP in sessionDatas)
                {
                    var sessionId = sessionDataKVP.Key;
                    var sessionData = sessionDataKVP.Value;

                    this.sessions[sessionId] = new Session(
                        this,
                        fileHandlerFactoryLocator,
                        this.persistedSessionDatas,
                        sessionId,
                        sessionData);
                }
            });

            // Clean old sessions every hour or so
            this.cleanOldSessionsTimer = new Timer(CleanOldSessions, null, 0, 6000000);
        }
Exemplo n.º 2
0
 public BinaryHandler(string path, FileHandlerFactoryLocator fileHandlerFactoryLocator)
     : base(fileHandlerFactoryLocator, path)
 {
     CachePath = path;
     BinaryFile = CreateBinaryFilename(path);
     ContentsChanged += new EventHandler<IBinaryHandler, EventArgs>(BinaryHandler_ContentsChanged);
 }
Exemplo n.º 3
0
        public GUIForm(FileHandlerFactoryLocator fileHandlerFactoryLocator)
            : this()
        {
            _FileHandlerFactoryLocator = fileHandlerFactoryLocator;

            this.Text = LinkLabel.Text = "http://" + FileHandlerFactoryLocator.HostnameAndPort;
            this.Shown += HandleShown;
        }
Exemplo n.º 4
0
 public NameValuePairsHandler(FileHandlerFactoryLocator fileHandlerFactoryLocator, string path)
     : base(fileHandlerFactoryLocator, path)
 {
     this.persistedPairs = new PersistedObject<Dictionary<string, string>>(
         path,
         () => new Dictionary<string, string>(),
         this.Deserialize,
         this.Serialize);
 }
Exemplo n.º 5
0
 public User(
     ID<IUserOrGroup, Guid> id,
     string name,
     bool builtIn,
     bool local,
     FileHandlerFactoryLocator fileHandlerFactoryLocator,
     string displayName,
     IIdentityProvider identityProvider)
     : base(id, name, builtIn, fileHandlerFactoryLocator, displayName)
 {
     _Local = local;
     _IdentityProvider = identityProvider;
 }
Exemplo n.º 6
0
 protected UserOrGroup(
     ID<IUserOrGroup, Guid> id,
     string name,
     bool builtIn,
     FileHandlerFactoryLocator fileHandlerFactoryLocator,
     string displayName)
 {
     _Id = id;
     _Name = name;
     _BuiltIn = builtIn;
     FileHandlerFactoryLocator = fileHandlerFactoryLocator;
     _DisplayName = displayName;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a Javascript execution environment
        /// </summary>
        /// <param name="fileContainer">The object that will be accessed through Javascript</param>
        /// <param name="javascriptContainer">The text file that contains the javascript</param>
        public ExecutionEnvironment(
            FileHandlerFactoryLocator fileHandlerFactoryLocator,
            IFileContainer javascriptContainer,
            IFileContainer fileContainer,
            SubProcess subProcess,
            ParentScope parentScope)
        {
            _FileHandlerFactoryLocator = fileHandlerFactoryLocator;
            _JavascriptContainer = javascriptContainer;
            _JavascriptLastModified = javascriptContainer.LastModified;

            parentScope.WebHandlersWithThisAsParent.Enqueue(fileContainer.WebHandler);

            object toDiscard;

            ISession ownerSession = FileHandlerFactoryLocator.SessionManagerHandler.CreateSession();

            try
            {
                if (null != fileContainer.Owner)
                    ownerSession.Login(fileContainer.Owner);

                IWebConnection ownerWebConnection = new BlockingShellWebConnection(
                    FileHandlerFactoryLocator.WebServer,
                    ownerSession,
                    fileContainer.FullPath,
                    null,
                    null,
                    new CookiesFromBrowser(),
                    CallingFrom.Web,
                    WebMethod.GET);

                ScopeWrapper = new ScopeWrapper(
                    fileHandlerFactoryLocator,
                    subProcess,
                    fileContainer,
                    parentScope,
                    ownerWebConnection,
                    out toDiscard);
            }
            catch (Exception e)
            {
                // If the Javascript has an error in it, it must be ignored.  If an error were returned, then malformed Javascript could hose the system!
                this._ExecutionEnvironmentErrors = e.ToString();
                log.Error("Error creating scope", e);
            }
            finally
            {
                FileHandlerFactoryLocator.SessionManagerHandler.EndSession(ownerSession.SessionId);
            }
        }
Exemplo n.º 8
0
        public static void StartCallHome(FileHandlerFactoryLocator fileHandlerFactoryLocator)
        {
            if (null == fileHandlerFactoryLocator.CallHomeEndpoint)
                return;

            // Only call home when running on port 80
            if (80 != fileHandlerFactoryLocator.WebServer.Port)
                return;

            FileHandlerFactoryLocator = fileHandlerFactoryLocator;

            // Call home every hour
            Timer = new Timer(DoCallHome, null, 0, 3600000);
        }
Exemplo n.º 9
0
        public Group(ID<IUserOrGroup, Guid> id,
		    string name,
		    bool builtIn,
            bool automatic,
            GroupType type,
            FileHandlerFactoryLocator fileHandlerFactoryLocator,
            string displayName)
            : base(id, name, builtIn, fileHandlerFactoryLocator, displayName)
        {
            _Id = id;
            _Name = name;
            _Automatic = automatic;
            _Type = type;
        }
Exemplo n.º 10
0
        public Session(
			SessionManagerHandler sessionManagerHandler, 
			FileHandlerFactoryLocator fileHandlerFactoryLocator,
			PersistedObject<Dictionary<ID<ISession, Guid>, SessionData>> persistedSessionDatas,
			ID<ISession, Guid> sessionId,
			SessionData sessionData)
        {
            this.sessionManagerHandler = sessionManagerHandler;
            this.fileHandlerFactoryLocator = fileHandlerFactoryLocator;
            this.persistedSessionDatas = persistedSessionDatas;
            this.sessionId = sessionId;

            this.maxAge = sessionData.maxAge;
            this.lastQuery = sessionData.lastQuery;
            this.keepAlive = sessionData.keepAlive;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a scope wrapper
        /// </summary>
        /// <param name="fileHandlerFactoryLocator"></param>
        /// <param name="webConnection"></param>
        /// <param name="javascript"></param>
        /// <param name="fileContainer"></param>
        /// <param name="constructScopeResults"></param>
        public ScopeWrapper(
            FileHandlerFactoryLocator fileHandlerFactoryLocator,
            SubProcess subProcess,
            IFileContainer fileContainer,
            ParentScope parentScope,
            IWebConnection constructWebConnection,
            out object constructScopeResults)
        {
            _FileContainer = fileContainer;
            _SubProcess = subProcess;
            _ParentScope = parentScope;

            _ScopeId = GetScopeID();

            _FileHandlerFactoryLocator = fileHandlerFactoryLocator;

            constructScopeResults = ConstructScope(constructWebConnection);
        }
Exemplo n.º 12
0
        public LogHandler(PersistedObjectSequence<LoggingEvent> sequence, FileHandlerFactoryLocator fileHandlerFactoryLocator, bool writeToConsole, DelegateQueue delegateQueue)
            : base(fileHandlerFactoryLocator)
        {
            this.sequence = sequence;
            this.delegateQueue = delegateQueue;
            this.writeToConsole = writeToConsole;

            this.sequence.ReadSequence(DateTime.MaxValue, 1, loggingEvent =>
            {
                if (null != loggingEvent.Classname)
                    this.classNames.Add(loggingEvent.Classname);

                if (null != loggingEvent.ExceptionClassname)
                    this.classNames.Add(loggingEvent.ExceptionClassname);

                return false;
            });
        }
Exemplo n.º 13
0
        public IUser CreateUserObject(
            FileHandlerFactoryLocator FileHandlerFactoryLocator,
            ID<IUserOrGroup, Guid> userId,
            string name,
            bool builtIn,
            string displayName,
            string identityProviderArgs)
        {
            IUser toReturn = new User(
                userId,
                name,
                builtIn,
                true,
                FileHandlerFactoryLocator,
                displayName,
                this);

            return toReturn;
        }
Exemplo n.º 14
0
 /// <summary>
 /// Helper to allow built-in users to be declared in Spring
 /// </summary>
 /// <param name="id">
 /// A <see cref="System.String"/>
 /// </param>
 /// <param name="name">
 /// A <see cref="System.String"/>
 /// </param>
 /// <returns>
 /// A <see cref="User"/>
 /// </returns>
 public static User SpringContructor(string id, string name, FileHandlerFactoryLocator fileHandlerFactoryLocator, IIdentityProvider identityProvider)
 {
     return new User(new ID<IUserOrGroup, Guid>(new Guid(id)), name, true, true, fileHandlerFactoryLocator, name, identityProvider);
 }
Exemplo n.º 15
0
 internal TemplateParsingState(IWebConnection webConnection)
 {
     _WebConnection = webConnection;
     _FileHandlerFactoryLocator = webConnection.WebServer.FileHandlerFactoryLocator;
     _TemplateHandlerLocator = _FileHandlerFactoryLocator.TemplateHandlerLocator;
 }
Exemplo n.º 16
0
 public CallHomeFileHandler(PersistedObject<Dictionary<string, Server>> persistedServers, FileHandlerFactoryLocator fileHandlerFactoryLocator)
     : base(fileHandlerFactoryLocator)
 {
     this.persistedServers = persistedServers;
 }
Exemplo n.º 17
0
 public ParentScopeFactory(FileHandlerFactoryLocator fileHandlerFactoryLocator, SubProcess subProcess)
 {
     FileHandlerFactoryLocator = fileHandlerFactoryLocator;
     _SubProcess = subProcess;
 }
Exemplo n.º 18
0
 public GroupAndAlias(ID<IUserOrGroup, Guid>? ownerId,
     ID<IUserOrGroup, Guid> id,
     string name,
     bool builtIn,
     bool automatic,
     GroupType type,
     string alias,
     FileHandlerFactoryLocator fileHandlerFactoryLocator,
     string displayName)
     : base(ownerId, id, name, builtIn, automatic, type, fileHandlerFactoryLocator, displayName)
 {
     _Alias = alias;
 }
Exemplo n.º 19
0
 public FileHandler(FileHandlerFactoryLocator fileHandlerFactoryLocator)
 {
     _FileHandlerFactoryLocator = fileHandlerFactoryLocator;
 }
 public CompiledJavascriptManager(FileHandlerFactoryLocator fileHandlerFactoryLocator)
 {
     FileHandlerFactoryLocator = fileHandlerFactoryLocator;
 }
Exemplo n.º 21
0
 public TextHandler(string path, FileHandlerFactoryLocator fileHandlerFactoryLocator)
     : base(fileHandlerFactoryLocator, path)
 {
     this.path = path;
 }
Exemplo n.º 22
0
 //static ILog log = LogManager.GetLogger<UserHandler>();
 internal UserHandler(PersistedObject<UserData> persistedUserData, PersistedObjectSequence<Notification> persistedNotifications, FileHandlerFactoryLocator fileHandlerFactoryLocator)
     : base(fileHandlerFactoryLocator)
 {
     this.persistedUserData = persistedUserData;
     this.persistedNotifications = persistedNotifications;
 }
Exemplo n.º 23
0
        /*static SubProcess()
        {
            StartProcessKiller();
        }

        /// <summary>
        /// Helper to start the process killer
        /// </summary>
        private static void StartProcessKiller()
        {
            try
            {
                Process pkp = new Process();
                pkp.StartInfo = new ProcessStartInfo("ProcessKiller.exe", Process.GetCurrentProcess().Id.ToString());
                pkp.StartInfo.RedirectStandardInput = true;
                pkp.StartInfo.UseShellExecute = false;

                pkp.EnableRaisingEvents = true;
                pkp.Exited += new EventHandler(pkp_Exited);

                if (!pkp.Start())
                {
                    Exception e = new JavascriptException("Could not start sub process");
                    log.Error("Error starting Process Killer sub process", e);

                    throw e;
                }

                log.Info("Process Killer started, parent process id (" + Process.GetCurrentProcess().Id.ToString() + "): " + pkp.ToString());

                SubProcessIdWriteStream = pkp.StandardInput;

                HashSet<Process> subProcesses;
                using (TimedLock.Lock(SubProcesses))
                    subProcesses = new HashSet<Process>(SubProcesses);

                using (TimedLock.Lock(SubProcessIdWriteStream))
                    foreach (Process subProcess in subProcesses)
                        SubProcessIdWriteStream.WriteLine(subProcess.Id.ToString());

            }
            catch (Exception e)
            {
                log.Error("Error starting process killer", e);
            }
        }

        static void pkp_Exited(object sender, EventArgs e)
        {
            ((Process)sender).Exited -= new EventHandler(pkp_Exited);
            StartProcessKiller();
        }*/
        public SubProcess(FileHandlerFactoryLocator fileHandlerFactoryLocator)
        {
            _Process = new Process();
            _Process.StartInfo = new ProcessStartInfo("java", "-cp ." + Path.DirectorySeparatorChar + "js.jar -jar JavascriptProcess.jar " + Process.GetCurrentProcess().Id.ToString());
            _Process.StartInfo.RedirectStandardInput = true;
            _Process.StartInfo.RedirectStandardOutput = true;
            _Process.StartInfo.RedirectStandardError = true;
            _Process.StartInfo.UseShellExecute = false;
            _Process.EnableRaisingEvents = true;
            _Process.Exited += new EventHandler(Process_Exited);

            log.Info("Starting sub process");

            if (!Process.Start())
            {
                Exception e = new JavascriptException("Could not start sub process");
                log.Error("Error starting Javascript sub process", e);

                throw e;
            }

            log.Info("Javascript sub process started: " + _Process.ToString());

            if (null != SubProcessIdWriteStream)
                using (TimedLock.Lock(SubProcessIdWriteStream))
                    SubProcessIdWriteStream.WriteLine(_Process.Id.ToString());

            JSONSender = new JsonWriter(_Process.StandardInput);

            // Failed attempt to handle processes without Threads
            _Process.ErrorDataReceived += new DataReceivedEventHandler(Process_ErrorDataReceived);
            _Process.BeginErrorReadLine();

            using (TimedLock.Lock(SubProcesses))
                SubProcesses.Add(_Process);
        }
Exemplo n.º 24
0
 public JSONSetReader(FileHandlerFactoryLocator fileHandlerFactoryLocator, string filename)
 {
     FileHandlerFactoryLocator = fileHandlerFactoryLocator;
     Filename = filename;
 }
Exemplo n.º 25
0
 public IFileContainer ConstructFileContainer(IFileHandler fileHandler, IFileId fileId, string typeId, IDirectoryHandler parentDirectoryHandler, FileHandlerFactoryLocator fileHandlerFactoryLocator, DateTime created)
 {
     return new FileContainer(fileHandler, fileId, typeId, parentDirectoryHandler, fileHandlerFactoryLocator, created);
 }
Exemplo n.º 26
0
 public LastModifiedFileHandler(FileHandlerFactoryLocator fileHandlerFactoryLocator, string filename)
     : base(fileHandlerFactoryLocator)
 {
     _Filename = filename;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Helper to allow built-in users to be declared in Spring
 /// </summary>
 /// <param name="id">
 /// A <see cref="System.String"/>
 /// </param>
 /// <param name="name">
 /// A <see cref="System.String"/>
 /// </param>
 /// <returns>
 /// A <see cref="User"/>
 /// </returns>
 public static Group SpringContructor(string id, string name, bool automatic, FileHandlerFactoryLocator fileHandlerFactoryLocator)
 {
     return new Group(new ID<IUserOrGroup, Guid>(new Guid(id)), name, true, automatic, GroupType.Private, fileHandlerFactoryLocator, name);
 }
Exemplo n.º 28
0
 internal UserManagerHandler(PersistedObject<UserManagerData> persistedUserManagerData, FileHandlerFactoryLocator fileHandlerFactoryLocator, int? maxLocalUsers)
     : base(fileHandlerFactoryLocator)
 {
     this.MaxLocalUsers = maxLocalUsers;
     this.persistedUserManagerData = persistedUserManagerData;
 }
Exemplo n.º 29
0
        /// <summary>
        /// Generates runtime metadata for the server-side javascript
        /// </summary>
        /// <param name="webConnection"></param>
        /// <param name="context"></param>
        internal static Dictionary<string, object> CreateMetadata(FileHandlerFactoryLocator fileHandlerFactoryLocator, IFileContainer fileContainer)
        {
            Dictionary<string, object> toReturn = new Dictionary<string, object>();

            //Ability to know the following from within Javascript:  File name, file path, owner name, owner ID, connected user name, connected user id
            Dictionary<string, object> fileMetadata = new Dictionary<string, object>();
            fileMetadata["filename"] = fileContainer.Filename;
            fileMetadata["fullpath"] = fileContainer.FullPath;
            fileMetadata["url"] = fileContainer.ObjectUrl;

            if (null != fileContainer.Owner)
                fileMetadata["owner"] = fileContainer.Owner.Name;
            else
                fileMetadata["owner"] = null;

            if (null != fileContainer.OwnerId)
            {
                fileMetadata["ownerId"] = fileContainer.OwnerId.Value;

                IUserOrGroup owner = fileHandlerFactoryLocator.UserManagerHandler.GetUserOrGroupNoException(fileContainer.OwnerId.Value);
                if (null != owner)
                {
                    fileMetadata["owner"] = owner.Name;

                    if (owner is IUser)
                        fileMetadata["ownerIdentity"] = ((IUser)owner).Identity;
                }
            }

            toReturn["fileMetadata"] = fileMetadata;

            Dictionary<string, object> hostMetadata = new Dictionary<string, object>();
            hostMetadata["host"] = fileHandlerFactoryLocator.HostnameAndPort;
            hostMetadata["justHost"] = fileHandlerFactoryLocator.Hostname;
            hostMetadata["port"] = fileHandlerFactoryLocator.WebServer.Port;

            toReturn["hostMetadata"] = hostMetadata;

            return toReturn;
        }