Example #1
0
        // Overrides the IWMSEventNotificationPlugin.OnEvent method. This 
        // implementation displays a message box when a client either
        // connects or disconnects.
        public void OnEvent(
                            ref WMS_EVENT Event,
                            IWMSContext UserCtx,
                            IWMSContext PresentationCtx,
                            IWMSCommandContext CommandCtx)
        {
            try
            {
                switch (Event.Type)
                {
                    case WMS_EVENT_TYPE.WMS_EVENT_CONNECT:
                        MessageBox.Show("Client connected",
                                        "Event Plug-in",
                                        MessageBoxButtons.OK);
                        break;

                    case WMS_EVENT_TYPE.WMS_EVENT_DISCONNECT:
                        MessageBox.Show("Client disconnected",
                                        "Event Plug-in",
                                        MessageBoxButtons.OK);
                        break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message,
                               "Event Plug-in Error",
                               MessageBoxButtons.OK,
                               MessageBoxIcon.Error);
            }
        }
        public void AuthorizeEvent(ref WMS_EVENT pEvent, IWMSContext pUserCtx, IWMSContext pPresentationCtx, IWMSCommandContext pCommandCtx,
            IWMSEventAuthorizationCallback pCallback,
            object Context)
        {
            int hr = 0; // By deafault access is granted to user
            const int ACCESS_DENIED = unchecked((int)0x80070005);

            string initial_request = null;
            string user_ip_address = null;
            string user_agent = null;

            pPresentationCtx.GetStringValue(WMSDefines.WMS_PRESENT_REQUEST_NAME,
                                            WMSDefines.WMS_PRESENT_REQUEST_NAME_ID,
                                            out initial_request,
                                            0);
            pUserCtx.GetStringValue(WMSDefines.WMS_USER_IP_ADDRESS_STRING,
                                    WMSDefines.WMS_USER_IP_ADDRESS_STRING_ID,
                                    out user_ip_address,
                                    0);
            if (log.IsInfoEnabled)
            {
                pUserCtx.GetStringValue(WMSDefines.WMS_USER_AGENT,
                                        WMSDefines.WMS_USER_AGENT_ID,
                                        out user_agent,
                                        0);

            }

            URLValidationExceptionTyte errortype = url_procesor.CheckURLValidity(initial_request,
                                                                                 user_ip_address);
            if (URLValidationExceptionTyte.SUCCESS != errortype)
            {
                hr = ACCESS_DENIED;
            }

            if (log.IsInfoEnabled)
            {
                StringBuilder msg = new StringBuilder();
                if(user_agent != null)msg.Append("User-Agent="+ user_agent);
                msg.Append(" User-Ip-Address="+user_ip_address);
                msg.Append(" Request="+initial_request);
                msg.Append(" Autorization-Result=" + errortype.ToString());
                log.Info(msg.ToString());
            }

            pCallback.OnAuthorizeEvent(hr, Context);
        }
        public void AuthorizeEvent(ref WMS_EVENT pEvent, IWMSContext pUserCtx, IWMSContext pPresentationCtx, IWMSCommandContext pCommandCtx,
            IWMSEventAuthorizationCallback pCallback,
            object Context)
        {
            int hr = 0; // By deafault access is granted to user
            const int ACCESS_DENIED = unchecked((int)0x80070005);

            string user_ip_address = null;
            pUserCtx.GetStringValue(WMSDefines.WMS_USER_IP_ADDRESS_STRING,
                                    WMSDefines.WMS_USER_IP_ADDRESS_STRING_ID,
                                    out user_ip_address,
                                    0);

            try
            {
                DateTime lastWrite = System.IO.File.GetLastWriteTime(denylistname);

                if (denyList == null)
                {
                    denyList = IPListLoader.loadIpList(denylistname);
                    lastWriteTime = lastWrite;
                }
                else if (lastWriteTime.Ticks != lastWrite.Ticks)
                {
                    denyList = IPListLoader.loadIpList(denylistname);
                    lastWriteTime = lastWrite;
                }

                if (denyList.CheckNumber(user_ip_address))
                {
                    hr = ACCESS_DENIED;
                }
            }
            catch (Exception e) { }

            pCallback.OnAuthorizeEvent(hr, Context);
        }
Example #4
0
        public void AuthorizeEvent(ref WMS_EVENT pEvent, IWMSContext pUserCtx, IWMSContext pPresentationCtx, IWMSCommandContext pCommandCtx,
                                   IWMSEventAuthorizationCallback pCallback,
                                   object Context)
        {
            int       hr            = 0; // By deafault access is granted to user
            const int ACCESS_DENIED = unchecked ((int)0x80070005);

            string initial_request = null;
            string user_ip_address = null;
            string user_agent      = null;

            pPresentationCtx.GetStringValue(WMSDefines.WMS_PRESENT_REQUEST_NAME,
                                            WMSDefines.WMS_PRESENT_REQUEST_NAME_ID,
                                            out initial_request,
                                            0);
            pUserCtx.GetStringValue(WMSDefines.WMS_USER_IP_ADDRESS_STRING,
                                    WMSDefines.WMS_USER_IP_ADDRESS_STRING_ID,
                                    out user_ip_address,
                                    0);
            if (log.IsInfoEnabled)
            {
                pUserCtx.GetStringValue(WMSDefines.WMS_USER_AGENT,
                                        WMSDefines.WMS_USER_AGENT_ID,
                                        out user_agent,
                                        0);
            }

            URLValidationExceptionTyte errortype = url_procesor.CheckURLValidity(initial_request,
                                                                                 user_ip_address);

            if (URLValidationExceptionTyte.SUCCESS != errortype)
            {
                hr = ACCESS_DENIED;
            }

            if (log.IsInfoEnabled)
            {
                StringBuilder msg = new StringBuilder();
                if (user_agent != null)
                {
                    msg.Append("User-Agent=" + user_agent);
                }
                msg.Append(" User-Ip-Address=" + user_ip_address);
                msg.Append(" Request=" + initial_request);
                msg.Append(" Autorization-Result=" + errortype.ToString());
                log.Info(msg.ToString());
            }

            pCallback.OnAuthorizeEvent(hr, Context);
        }
Example #5
0
        void IWMSCacheProxy.QueryCacheMissPolicy( string bstrOriginUrl , 
            IWMSContext pUserContext , 
            IWMSCommandContext pCommandContext , 
            IWMSContext pPresentationContext , 
            object pCachePluginContext , 
            int lQueryType , 
            IWMSCacheProxyCallback pCallback , 
            object varContext )
        {
            Debug.WriteLine("IWMSCacheProxy.QueryCacheMissPolicy entered");
            int nOpenFlag = (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_OPEN;
            int nGCI = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_GET_CONTENT_INFO);
            int nReverseProxy = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_REVERSE_PROXY);
            ContentInfo ci = new ContentInfo(bstrOriginUrl,null);
            if((nOpenFlag & lQueryType)!=0) // open query
            {
                if(nReverseProxy==0) //normal mode
                {
                    // get content information
                    ci.CacheProxyCallback = pCallback;
                    ci.varContext = varContext;
                    CacheProxyServer.GetContentInformation(bstrOriginUrl,pPresentationContext,null,
                        null,this,ci);
                }
                else // it's a reverse proxy mode
                {
                    // we simply look up our table to see if there is a mapping between the requested
                    //Url and the RP url and return it
                    // we distinguish the table entry if it's a reverse proxy or not by
                    // checking the CDL data
                    // we store a special string "ReverseProxy" there for the distinction
                    // one can simply add another entry in the table to be safer
                    // as there might be some CDL data written as "ReverseProxy" !!
                    ContentInfo ciRP = null;
                    GetContentInfo(bstrOriginUrl,out ciRP);
                    WMS_CACHE_QUERY_MISS_RESPONSE Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND;
                    if((ciRP.ContentType & 1 )!=0) // it's a brodcast content
                    {
                        Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_BROADCAST;
                    }
                    else
                    {
                        Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND;
                    }

                    IWMSContext ContentInfoContext = null;
                    GetContentInfoContext(ci,out ContentInfoContext);
                    pCallback.OnQueryCacheMissPolicy(0,Response,ciRP.CacheUrl,null,ContentInfoContext,varContext);

                }

            }
            if((nGCI & lQueryType)!=0) // GCI query from downstream server
            {
                WMS_CACHE_QUERY_MISS_RESPONSE Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_FORWARD_REQUEST;
                IWMSContext ContentInfoContext = null;
                GetContentInfoContext(ci,out ContentInfoContext);
                pCallback.OnQueryCacheMissPolicy(0,Response,bstrOriginUrl,null,ContentInfoContext,varContext);
            }

            if((lQueryType & (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_CACHE_EVENT)!=0)
            {
                pCallback.OnQueryCacheMissPolicy(0,WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_FORWARD_REQUEST,
                    null,this,null,varContext);
            }

            return;
        }
Example #6
0
        //
        // IWMSCacheProxy
        //
        void IWMSCacheProxy.QueryCache(string bstrOriginUrl , 
            IWMSContext pUserContext , 
            IWMSCommandContext pCommandContext , 
            IWMSContext pPresentationContext , 
            int lQueryType , 
            IWMSCacheProxyCallback pCallback , 
            object varContext )
        {
            Debug.WriteLine("IWMSCacheProxy.QueryCache entered");
            // we simply return a hard coded URL for the request WMS_CACHE_QUERY_OPEN for now
            int nFlag = (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_OPEN;
            int nOpen = lQueryType & nFlag;
            int nGCI = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_GET_CONTENT_INFO);
            int nReverseProxy = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_REVERSE_PROXY);

            // either open or GCI is called
            // for GCI we don't care about CompareContentInformation
            // if not upto date, we treat as a miss
            if((nOpen!=0)||(nGCI!=0))
            {
                // allocate ContentInfoContext and DataContainerObject
                // stuff it with the information
                // and call back
                IWMSContext Context;
                WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS;

                ContentInfo ci;
                //gets allocated here
                GetContentInfo(bstrOriginUrl,out ci);
                ci.CacheProxyCallback = pCallback;
                ci.varContext = varContext;
                GetContentInfoContext(ci,out Context);

                bool bQueryCache = true;
                bool bOnDemand = true;
                if((ci.CacheUrl!=null) && (nReverseProxy==0)) // there is something in the cache
                {
                    // if content is not expired, this is a hit
                    DateTime now = DateTime.Now;
                    Debug.WriteLine(string.Format("Current local time={0}",now));
                    //covert to UTC time
                    now = now.ToUniversalTime();
                    Debug.WriteLine(string.Format("Current UTC time={0}",now));

                    Debug.WriteLine(string.Format("Expiration time={0}",ci.ExpirationTime));
                    if(ci.ExpirationTime > now)
                    {
                        if((ci.ContentType & 1 )!=0) // it's a brodcast content
                        {
                            Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_BROADCAST;
                            bOnDemand = false;
                        }
                        else
                        {
                            Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND;
                            bOnDemand = true;
                        }
                    }
                    else // content appears expired, we will have to call CompareContentInformation
                    {
                        if(nOpen!=0) // only for open queries
                        {
                            bQueryCache = false;
                        }
                    }
                }

                if(bQueryCache)
                {
                    string CacheUrl = ci.CacheUrl;
                    if(bOnDemand)
                    {
                        CacheUrl = string.Format("file://{0}",ci.CacheUrl);
                    }
                    pCallback.OnQueryCache( 0,
                        Response,
                        CacheUrl,
                        Context,
                        null,
                        varContext);
                }
                else
                {
                    CacheProxyServer.CompareContentInformation(bstrOriginUrl,Context,pPresentationContext,
                        this,null,this,(object)ci);
                }
            }
            else
            {
                // see of this is for event propagation
                int nCacheEvent = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_CACHE_EVENT);
                int nLocalEvent = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_LOCAL_EVENT);
                if((nCacheEvent | nLocalEvent)!=0)
                {
                    // we declare it as a miss
                    // and on QCP, we ask the cachemanager to forward it
                    WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS;
                    pCallback.OnQueryCache( 0,
                        Response,
                        bstrOriginUrl,
                        null,
                        null,
                        varContext);
                }

            }

            return;
        }
    public void Authenticate(object responseBlob, IWMSContext pUserCtx, IWMSContext pPresentationCtx, IWMSCommandContext pCommandContext, IWMSAuthenticationCallback pCallback, object context)
    {
        // must be Unicode.  If it isn't, the
        // challenge isn't sent correctly
        Encoding enc = Encoding.Unicode;

        byte[] response;
        byte[] challenge = enc.GetBytes("");
        try
        {
            response = (byte[])responseBlob;
            if (response.Length == 0)
            {
                // The client requested authentication; prepare the
                // challenge response to send to the client.  In order to
                // do Basic authentication, be sure to return "Basic" from
                // your implementation of IWMSAuthenticationPlugin.GetProtocolName()
                string challengeTxt = "WWW-Authenticate: Basic realm=\"Domain\"";
                challenge = enc.GetBytes(challengeTxt);
                _result   = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_CONTINUE;
            }
            else
            {
                // parses Base64 encoded response and gets passed in credentials
                SetCredentials(enc.GetString(response));
                LdapConnection    ldc = new LdapConnection("Domain");
                NetworkCredential nc  = new NetworkCredential(_credentials.Username, _credentials.Password, "Domain");
                ldc.Credential = nc;
                ldc.AuthType   = AuthType.Negotiate;
                ldc.Bind(nc); // user has authenticated at this point, as the credentials were used to login to the dc.
                // must log in with a local windows account and get a handle for the account.
                // even if success is returned, the plugin still needs a valid windows account
                // to stream the file.
                bool result = LogonAPI.LogonUser("local username", "local domain", "local password", LogonAPI.LOGON32_LOGON_NETWORK, LogonAPI.LOGON32_PROVIDER_DEFAULT, ref _userToken);
                _result = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_SUCCESS;
            }
        }
        catch (LdapException e)
        {
            _result = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_DENIED;
        }
        catch (Exception e)
        {
            _result = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_ERROR;
        }
        finally
        {
            pCallback.OnAuthenticateComplete(_result, challenge, context);
        }
    }