private bool ExecuteWebService(string name, Func <HeContext, bool> method, bool isUnattended)
        {
            if (HttpContext.Current == null)
            {
                GeneralLog.StaticWrite(DateTime.Now, "", 0, 0, 0, name + " Called (Context is null)", GeneralLogType.WARNING.ToString(), "", "");
            }
            else
            {
                HeContext heContext = Global.App.OsContext;

                int timeout = 0;
                if (isUnattended)
                {
                    timeout = SchedulerAutomaticActivitiesTimeout;
                }
                else
                {
                    timeout = SchedulerActivitiesTimeout;
                }



                SetWebserviceTimeout(heContext, timeout);

                // Check if the request is from a valid IP
                if (!NetworkInterfaceUtils.IsLoopbackAddress(HttpContext.Current.Request.UserHostAddress))
                {
                    ErrorLog.StaticWrite(DateTime.Now, heContext.Session.SessionID,
                                         (heContext.AppInfo != null ? heContext.AppInfo.eSpaceId: 0),
                                         (heContext.AppInfo != null && heContext.AppInfo.Tenant != null ? heContext.AppInfo.Tenant.Id: 0),
                                         heContext.Session.UserId,
                                         "Access to ActivityActionsHandler with invalid IP: " + HttpContext.Current.Request.UserHostAddress,
                                         "The activity actions handler can only be accessed by the 127.0.0.1 IP", "BPM");
                    return(false);
                }

                bool processedOk = false;
                try {
                    processedOk = method(heContext);
                    return(processedOk);
                } catch (Exception e) {
                    if (e.InnerException != null && (e is TypeInitializationException))
                    {
                        throw e.InnerException;
                    }
                    else
                    {
                        throw;
                    }
                } finally {
                    DatabaseAccess.FreeupResources(processedOk);
                }
            }
            return(false);
        }
        public static Uri ReplaceLoopbackAddressByModuleZone(string moduleResourceUrl)
        {
            var uri = CreateUri(moduleResourceUrl);

            if (uri != null && NetworkInterfaceUtils.IsLoopbackAddress(uri.Host))
            {
                return(ReplaceUrlHostByModuleZone(uri));
            }
            else
            {
                return(uri);
            }
        }
Beispiel #3
0
        public void handleRequest(HeContext heContext)
        {
            SmsNode currentNode;

            if (!NetworkInterfaceUtils.IsLoopbackAddress(Request.UserHostAddress))
            {
                ErrorLog.LogApplicationError("Access denied from " + Request.UserHostAddress,
                                             "I is only possible to access the smshandler from 127.0.0.1", heContext, "SmsHandler");
                return;
            }
            currentNode = getState();
            Response.Write("<html><head><meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"><title>SMS Message</title></head><body>");
            // Response.Write ("<p>Message: ("+heContext.MOMsg.Message+")</p>");
            if (heContext.MOMsg != null)
            {
                SmsNode res;
                bool    matched;
                // Response.Write ("<p>Current State: "+currentNode.Key+"</p><hr/>");
                res     = currentNode.Match(heContext);
                matched = (res != null);
                if (!matched && heContext.AppInfo.IsApplicationEnabled)
                {
                    res = GetSmsEntry(heContext);
                    if (res != null && res.Key != currentNode.Key)
                    {
                        res     = res.Match(heContext);
                        matched = (res != null);
                    }
                }
                setState(res);
                Response.AddHeader("Matched", matched.ToString());
                if (res != null)
                {
                    // Response.Write ("<hr/><p>Next State: "+res.Key+"</p>");
                    if (res.ExpectedPatterns != "")
                    {
                        Response.AddHeader("ExpectedPatterns", res.ExpectedPatterns);
                    }
                }
                else
                {
                    // Response.Write ("<hr/><p>Next State is null</p>");
                }
            }
            // Response.Write ("<form name=\"form1\" method=\"get\"><input type=\"text\" name=\"message\"/><br/><input type=\"submit\" value=\"Send\"/></form>");
            // Response.Write ("<script type=\"text/javascript\"> document.form1.message.focus(); </script>");
        }
        public int ExecuteTimer(string ssKey, int timeout, int tenantId)
        {
            ObjectKey timerKey = ObjectKey.Parse(ssKey);

            if (HttpContext.Current == null)
            {
                GeneralLog.StaticWrite(DateTime.Now, "", 0, 0, 0, "ExecuteTimer Called (Context is null)", GeneralLogType.WARNING.ToString(), "", "");
            }
            else
            {
                HeContext context = Global.App.OsContext;

                // Check if the request is from a valid IP
                if (!NetworkInterfaceUtils.IsLoopbackAddress(HttpContext.Current.Request.UserHostAddress))
                {
                    ErrorLog.LogApplicationError("Access to timerhandler with invalid IP: " + HttpContext.Current.Request.UserHostAddress,
                                                 "The timer handler can only be accessed by the 127.0.0.1 IP", context, "ExecuteTimer");
                    return(0);
                }
                if (tenantId > 0)
                {
                    context.Session.TenantId = tenantId;
                }
                bool processedOk = false;
                try {
                    if (timerKey == TimerBootstrap.TimerKey)
                    {
                        TimerBootstrap.Execute(context, timeout);
                    }
                    else
                    {
                        GeneralLog.StaticWrite(DateTime.Now, context.Session.SessionID, Global.eSpaceId,
                                               context.AppInfo.Tenant.Id,
                                               context.Session.UserId, "Timer " + ssKey + " isn't mapped",
                                               GeneralLogType.INFO.ToString(), "", "");
                    }
                    processedOk = true;
                } finally {
                    DatabaseAccess.FreeupResources(processedOk);
                }
            }
            return(1);
        }
 public int SendSms(SmsNode node, string largeAccount, string msisdn)
 {
     OutSystems.ObjectKeys.ObjectKey nodeKey = OutSystems.ObjectKeys.ObjectKey.Parse(node.Key);
     if (HttpContext.Current == null)
     {
         GeneralLog log = new GeneralLog();
         log.Write(DateTime.Now, "", 0, 0, 0, "SendSms Called (Context is null)", GeneralLogType.WARNING.ToString(), "", "");
     }
     else if (HttpContext.Current.Session == null)
     {
         GeneralLog log = new GeneralLog();
         log.Write(DateTime.Now, "", 0, 0, 0, "SendSms Called (Session is null)", GeneralLogType.WARNING.ToString(), "", "");
     }
     else
     {
         HeContext context = Global.App.OsContext;
         if (!NetworkInterfaceUtils.IsLoopbackAddress(HttpContext.Current.Request.UserHostAddress))
         {
             ErrorLog.LogApplicationError("Access to iSmsHandler with invalid IP: " + HttpContext.Current.Request.UserHostAddress,
                                          "The iSmsHandler can only be accessed by the 127.0.0.1 IP", context, "ExecuteTimer");
             return(0);
         }
         GeneralLog log = new GeneralLog();
         log.Write(DateTime.Now, context.Session.SessionID, context.AppInfo.eSpaceId,
                   context.AppInfo.Tenant.Id, context.Session.UserId,
                   "SendSms Called, The node received has type " + node.GetType().ToString() + ", Large Account: " + largeAccount + " MSISDN: " + msisdn,
                   GeneralLogType.INFO.ToString(), "", "");
         node.MTMsg.LargeAccount   = largeAccount;
         node.MTMsg.MSISDN         = msisdn;
         context.Session["MSISDN"] = node.MTMsg.MSISDN;
         bool ok = false;
         try {
             node.Execute(context);
             ok = true;
         } finally {
             DatabaseAccess.FreeupResources(ok);
         }
     }
     return(1);
 }
Beispiel #6
0
        private void ValidateToken(HeContext heContext, int userId, int tenantId, string eSpaceKey)
        {
            if (!HttpContext.Current.Request.Headers.AllKeys.Contains("Authorization"))
            {
                // check if in compatibility mode with pre-O11 versions
                if (RuntimePlatformSettings.Authentication.ReferencesAllowLegacyAuth.GetValue())
                {
                    // Check if the request is from a valid IP
                    if (!NetworkInterfaceUtils.IsLoopbackAddress(HttpContext.Current.Request.UserHostAddress))
                    {
                        ErrorLog.StaticWrite(DateTime.Now,
                                             heContext.Session.SessionID,
                                             heContext.AppInfo != null ? heContext.AppInfo.eSpaceId: 0,
                                             heContext.AppInfo != null ? heContext.AppInfo.Tenant.Id: 0,
                                             heContext.Session.UserId,
                                             "Access to ActivityActionsHandler with invalid IP: " + HttpContext.Current.Request.UserHostAddress,
                                             "The activity actions handler can only be accessed by the 127.0.0.1 IP", "BPM");

                        throw new Exception("The activity actions handler can only be accessed by the 127.0.0.1 IP");
                    }
                    else
                    {
                        // Request is valid in compatibility mode
                        return;
                    }
                }
                else
                {
                    throw new Exception("Token validation failed");
                }
            }

            SecurityTokenManager.ValidateAuthorizationHeader(
                RuntimeSettingsProvider.Instance,
                HttpContext.Current.Request.Headers["Authorization"],
                userId,
                tenantId,
                eSpaceKey);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            HeContext heContext = Global.App.OsContext;

            if (!NetworkInterfaceUtils.IsLoopbackAddress(Request.UserHostAddress))
            {
                ErrorLog.LogApplicationError("Access denied from " + Request.UserHostAddress,
                                             "It is only possible to access the smshandler from 127.0.0.1", heContext, "SmsHandler");
                Response.StatusCode = 403;
                Response.Write("IP address " + Request.UserHostAddress + " is not allowed for this service");
                DatabaseAccess.FreeupResources(true);
                Response.End();
                return;
            }

            bool ok = false;

            try {
                string ssMSISDN             = "";
                string ssLargeAccount       = "";
                int    ssCustomId           = 0;
                string ssScreen             = "";
                string ssMessageId          = "";
                string ssResult             = "";
                int    ssResultCode         = 0;
                string ssExtendedErrorCode  = "";
                string ssConnection         = "";
                string ssOperatorCode       = "";
                string ssBillingDescription = "";
                string ssBillingCode        = "";
                string ssCustom1            = "";
                string ssCustom2            = "";
                string ssCustom3            = "";

                if (Request.QueryString["msisdn"] != null)
                {
                    ssMSISDN = Request.QueryString["msisdn"];
                }
                if (Request.QueryString["la"] != null)
                {
                    ssLargeAccount = Request.QueryString["la"];
                }
                if (Request.QueryString["customid"] != null)
                {
                    ssCustomId = System.Convert.ToInt32(Request.QueryString["customid"]);
                }
                if (Request.QueryString["screen"] != null)
                {
                    ssScreen = Request.QueryString["screen"];
                }
                if (Request.QueryString["msgid"] != null)
                {
                    ssMessageId = Request.QueryString["msgid"];
                }
                if (Request.QueryString["res"] != null)
                {
                    ssResult = Request.QueryString["res"];
                }
                if (Request.QueryString["rescode"] != null)
                {
                    ssResultCode = System.Convert.ToInt32(Request.QueryString["rescode"]);
                }
                if (Request.QueryString["exerrcode"] != null)
                {
                    ssExtendedErrorCode = Request.QueryString["exerrcode"];
                }
                if (Request.QueryString["conn"] != null)
                {
                    ssConnection = Request.QueryString["conn"];
                }
                if (Request.QueryString["opcode"] != null)
                {
                    ssOperatorCode = Request.QueryString["opcode"];
                }
                if (Request.QueryString["billdesc"] != null)
                {
                    ssBillingDescription = Request.QueryString["billdesc"];
                }
                if (Request.QueryString["billcode"] != null)
                {
                    ssBillingCode = Request.QueryString["billcode"];
                }
                if (Request.QueryString["custom1"] != null)
                {
                    ssCustom1 = Request.QueryString["custom1"];
                }
                if (Request.QueryString["custom2"] != null)
                {
                    ssCustom2 = Request.QueryString["custom2"];
                }
                if (Request.QueryString["custom3"] != null)
                {
                    ssCustom3 = Request.QueryString["custom3"];
                }


                ok = true;
            } catch (Exception exc) {
                ErrorLog.LogApplicationError(exc, heContext, "DeliveryHandler");
            } finally {
                DatabaseAccess.FreeupResources(ok);
            }
            Response.End();
        }