Example #1
0
 public static XmlReader CreateXmlReader(string xmlsrc, int portalId, bool prohibitDtd)
 {
     if (xmlsrc == String.Empty) return null;
     var filecontroller = new FileController();
     var xmlFileInfo = filecontroller.GetFileById(filecontroller.ConvertFilePathToFileId(xmlsrc, portalId), portalId);
     return XmlReader.Create(FileSystemUtils.GetFileStream(xmlFileInfo), new XmlReaderSettings {ProhibitDtd = prohibitDtd});
 }
        public void UpdateUrlTracking(int PortalID, string Url, int ModuleId, int UserID)
        {

            TabType UrlType = Globals.GetURLType(Url);
            if (UrlType == TabType.File & Url.ToLower().StartsWith("fileid=") == false)
            {
                // to handle legacy scenarios before the introduction of the FileServerHandler
                FileController objFiles = new FileController();
                Url = "FileID=" + objFiles.ConvertFilePathToFileId(Url, PortalID);
            }

            UrlTrackingInfo objUrlTracking = GetUrlTracking(PortalID, Url, ModuleId);
            if (objUrlTracking != null)
            {
                if (objUrlTracking.TrackClicks)
                {
                    DataProvider.Instance().UpdateUrlTrackingStats(PortalID, Url, ModuleId);
                    if (objUrlTracking.LogActivity)
                    {
                        if (UserID == -1)
                        {
                            UserID = UserController.GetCurrentUserInfo().UserID;
                        }
                        DataProvider.Instance().AddUrlLog(objUrlTracking.UrlTrackingID, UserID);
                    }
                }
            }

        }
        private string ImportFile( int PortalId, string url )
        {
            string strUrl = url;

            if( Globals.GetURLType( url ) == TabType.File )
            {
                FileController objFileController = new FileController();
                int fileId = objFileController.ConvertFilePathToFileId( url, PortalId );
                if( fileId >= 0 )
                {
                    strUrl = "FileID=" + fileId.ToString();
                }
            }

            return strUrl;
        }
Example #4
0
        /// <Summary>
        /// This handler handles requests for LinkClick.aspx, but only those specifc
        /// to file serving
        /// </Summary>
        /// <Param name="context">System.Web.HttpContext)</Param>
        public virtual void ProcessRequest(HttpContext context)
        {
            PortalSettings portalSettings = PortalController.GetCurrentPortalSettings();

            // get TabId
            int tabId = -1;

            if (context.Request.QueryString["tabid"] != null)
            {
                tabId = int.Parse(context.Request.QueryString["tabid"]);
            }

            // get ModuleId
            int moduleId = -1;

            if (context.Request.QueryString["mid"] != null)
            {
                moduleId = int.Parse(context.Request.QueryString["mid"]);
            }



            // get the URL
            string URL              = "";
            bool   blnClientCache   = true;
            bool   blnForceDownload = false;

            if (context.Request.QueryString["fileticket"] != null)
            {
                URL = "FileID=" + UrlUtils.DecryptParameter(context.Request.QueryString["fileticket"]);
            }
            if (context.Request.QueryString["userticket"] != null)
            {
                URL = "UserId=" + UrlUtils.DecryptParameter(context.Request.QueryString["userticket"]);
            }
            if (context.Request.QueryString["link"] != null)
            {
                URL = context.Request.QueryString["link"];
                if (URL.ToLower().StartsWith("fileid="))
                {
                    URL = ""; // restrict direct access by FileID
                }
            }

            if (!String.IsNullOrEmpty(URL))
            {
                TabType UrlType = Globals.GetURLType(URL);

                if (UrlType != TabType.File)
                {
                    URL = Globals.LinkClick(URL, tabId, moduleId, false);
                }

                if (UrlType == TabType.File && URL.ToLower().StartsWith("fileid=") == false)
                {
                    // to handle legacy scenarios before the introduction of the FileServerHandler
                    FileController objFiles = new FileController();
                    URL = "FileID=" + objFiles.ConvertFilePathToFileId(URL, portalSettings.PortalId);
                }

                // get optional parameters
                if (context.Request.QueryString["clientcache"] != null)
                {
                    blnClientCache = bool.Parse(context.Request.QueryString["clientcache"]);
                }

                if ((context.Request.QueryString["forcedownload"] != null) || (context.Request.QueryString["contenttype"] != null))
                {
                    blnForceDownload = bool.Parse(context.Request.QueryString["forcedownload"]);
                }

                // update clicks
                UrlController objUrls = new UrlController();
                objUrls.UpdateUrlTracking(portalSettings.PortalId, URL, moduleId, -1);

                // clear the current response
                context.Response.Clear();

                if (UrlType == TabType.File)
                {
                    // serve the file
                    if (tabId == Null.NullInteger)
                    {
                        if (!(FileSystemUtils.DownloadFile(portalSettings.PortalId, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload)))
                        {
                            context.Response.Write(Services.Localization.Localization.GetString("FilePermission.Error"));
                        }
                    }
                    else
                    {
                        if (!(FileSystemUtils.DownloadFile(portalSettings, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload)))
                        {
                            context.Response.Write(Services.Localization.Localization.GetString("FilePermission.Error"));
                        }
                    }
                }
                else
                {
                    // redirect to URL
                    context.Response.Redirect(URL, true);
                }
            }
        }
        /// <Summary>
        /// This handler handles requests for LinkClick.aspx, but only those specifc
        /// to file serving
        /// </Summary>
        /// <Param name="context">System.Web.HttpContext)</Param>
        public virtual void ProcessRequest( HttpContext context )
        {
            PortalSettings portalSettings = PortalController.GetCurrentPortalSettings();

            // get TabId
            int tabId = -1;
            if (context.Request.QueryString["tabid"] != null)
            {
                tabId = int.Parse(context.Request.QueryString["tabid"]);
            }

            // get ModuleId
            int moduleId = -1;
            if (context.Request.QueryString["mid"] != null)
            {
                moduleId = int.Parse(context.Request.QueryString["mid"]);
            }

            

            // get the URL
            string URL = "";
            bool blnClientCache = true;
            bool blnForceDownload = false;

            if (context.Request.QueryString["fileticket"] != null)
            {
                URL = "FileID=" + UrlUtils.DecryptParameter(context.Request.QueryString["fileticket"]);
            }
            if (context.Request.QueryString["userticket"] != null)
            {
                URL = "UserId=" + UrlUtils.DecryptParameter(context.Request.QueryString["userticket"]);
            }
            if (context.Request.QueryString["link"] != null)
            {
                URL = context.Request.QueryString["link"];
                if (URL.ToLower().StartsWith("fileid="))
                {
                    URL = ""; // restrict direct access by FileID
                }
            }

            if (!String.IsNullOrEmpty(URL))
            {
                TabType UrlType = Globals.GetURLType(URL);

                if (UrlType != TabType.File)
                {
                    URL = Globals.LinkClick(URL, tabId, moduleId, false);
                }

                if (UrlType == TabType.File && URL.ToLower().StartsWith("fileid=") == false)
                {
                    // to handle legacy scenarios before the introduction of the FileServerHandler
                    FileController objFiles = new FileController();
                    URL = "FileID=" + objFiles.ConvertFilePathToFileId(URL, portalSettings.PortalId);
                }

                // get optional parameters
                if (context.Request.QueryString["clientcache"] != null)
                {
                    blnClientCache = bool.Parse(context.Request.QueryString["clientcache"]);
                }

                if ((context.Request.QueryString["forcedownload"] != null) || (context.Request.QueryString["contenttype"] != null))
                {
                    blnForceDownload = bool.Parse(context.Request.QueryString["forcedownload"]);
                }

                // update clicks
                UrlController objUrls = new UrlController();
                objUrls.UpdateUrlTracking(portalSettings.PortalId, URL, moduleId, -1);

                // clear the current response
                context.Response.Clear();

                if (UrlType == TabType.File)
{
                    // serve the file
                    if (tabId == Null.NullInteger)
                    {
                        if (! (FileSystemUtils.DownloadFile(portalSettings.PortalId, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload)))
                        {
                            context.Response.Write(Services.Localization.Localization.GetString("FilePermission.Error"));
                        }
                    }
                    else
                    {
                        if (! (FileSystemUtils.DownloadFile(portalSettings, int.Parse(UrlUtils.GetParameterValue(URL)), blnClientCache, blnForceDownload)))
                        {
                            context.Response.Write(Services.Localization.Localization.GetString("FilePermission.Error"));
                        }
                    }
                }
                else
                {
                    // redirect to URL
                    context.Response.Redirect(URL, true);
                }
            }
        }
Example #6
0
        public static string ImportUrl(int ModuleId, string url)
        {
            string strUrl = url;

            if (GetURLType(url) == TabType.File)
            {
                ModuleController objModuleController = new ModuleController();
                FileController objFileController = new FileController();
                ModuleInfo objModule = objModuleController.GetModule(ModuleId, Null.NullInteger, true);

                strUrl = "FileID=" + objFileController.ConvertFilePathToFileId(url, objModule.PortalID);
            }

            return strUrl;
        }
        private void ShowControls()
        {
            UrlController objUrls = new UrlController();

            // set url type
            if (optType.SelectedItem == null)
            {
                if (!String.IsNullOrEmpty(_Url))
                {
                    string TrackingUrl = _Url;

                    _UrlType = Globals.GetURLType(_Url).ToString("g").Substring(0, 1);

                    if (_UrlType == "F")
                    {
                        FileController objFiles = new FileController();
                        if (_Url.ToLower().StartsWith("fileid="))
                        {
                            TrackingUrl = _Url;
                            FileInfo objFile = objFiles.GetFileById(int.Parse(_Url.Substring(7)), _objPortal.PortalID);
                            if (objFile != null)
                            {
                                _Url = objFile.Folder + objFile.FileName;
                            }
                        }
                        else
                        {
                            // to handle legacy scenarios before the introduction of the FileServerHandler
                            TrackingUrl = "FileID=" + objFiles.ConvertFilePathToFileId(_Url, _objPortal.PortalID);
                        }
                    }

                    if (_UrlType == "M")
                    {
                        if (_Url.ToLower().StartsWith("userid="))
                        {
                            UserInfo objUser = UserController.GetUser(_objPortal.PortalID, int.Parse(_Url.Substring(7)), false);
                            if (objUser != null)
                            {
                                _Url = objUser.Username;
                            }
                        }
                    }

                    UrlTrackingInfo objUrlTracking = objUrls.GetUrlTracking(_objPortal.PortalID, TrackingUrl, ModuleID);
                    if (objUrlTracking != null)
                    {
                        optType.Items.FindByValue(objUrlTracking.UrlType).Selected = true;
                        chkNewWindow.Checked = objUrlTracking.NewWindow;
                        chkTrack.Checked = objUrlTracking.TrackClicks;
                        chkLog.Checked = objUrlTracking.LogActivity;
                    }
                    else // the url does not exist in the tracking table
                    {
                        optType.Items.FindByValue(_UrlType).Selected = true;
                        chkNewWindow.Checked = false;
                        chkTrack.Checked = true;
                        chkLog.Checked = false;
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(_UrlType))
                    {
                        if (optType.Items.FindByValue(_UrlType) != null)
                        {
                            optType.Items.FindByValue(_UrlType).Selected = true;
                        }
                        else
                        {
                            optType.Items[0].Selected = true;
                        }
                    }
                    else
                    {
                        optType.Items[0].Selected = true;
                    }
                    chkNewWindow.Checked = false;
                    chkTrack.Checked = true;
                    chkLog.Checked = false;
                }
            }

            // load listitems
            switch (optType.SelectedItem.Value)
            {
                case "N": // None

                    URLRow.Visible = false;
                    TabRow.Visible = false;
                    FileRow.Visible = false;
                    UserRow.Visible = false;
                    break;
                case "U": // Url

                    URLRow.Visible = true;
                    TabRow.Visible = false;
                    FileRow.Visible = false;
                    UserRow.Visible = false;

                    if (txtUrl.Text == "")
                    {
                        txtUrl.Text = _Url;
                    }
                    if (txtUrl.Text == "")
                    {
                        txtUrl.Text = "http://";
                    }
                    txtUrl.Visible = true;

                    cmdSelect.Visible = true;

                    cboUrls.Items.Clear();
                    cboUrls.DataSource = objUrls.GetUrls(_objPortal.PortalID);
                    cboUrls.DataBind();
                    if (cboUrls.Items.FindByValue(_Url) != null)
                    {
                        cboUrls.Items.FindByValue(_Url).Selected = true;
                    }
                    cboUrls.Visible = false;

                    cmdAdd.Visible = false;
                    cmdDelete.Visible = false;
                    break;
                case "T": // tab

                    URLRow.Visible = false;
                    TabRow.Visible = true;
                    FileRow.Visible = false;
                    UserRow.Visible = false;

                    cboTabs.Items.Clear();

                    cboTabs.DataSource = Globals.GetPortalTabs(_objPortal.PortalID, !_Required, true, false, false, false);
                    cboTabs.DataBind();
                    if (cboTabs.Items.FindByValue(_Url) != null)
                    {
                        cboTabs.Items.FindByValue(_Url).Selected = true;
                    }
                    break;
                case "F": // file

                    URLRow.Visible = false;
                    TabRow.Visible = false;
                    FileRow.Visible = true;
                    UserRow.Visible = false;

                    LoadFolders();

                    if (cboFolders.Items.Count == 0)
                    {
                        lblMessage.Text = Localization.GetString("NoPermission", this.LocalResourceFile);
                        FileRow.Visible = false;
                        return;
                    }

                    // select folder
                    string FileName;
                    string FolderPath;
                    if (_Url != string.Empty)
                    {
                        FileName = _Url.Substring(_Url.LastIndexOf("/") + 1);
                        FolderPath = _Url.Replace(FileName, "");
                    }
                    else
                    {
                        FileName = _Url;
                        FolderPath = string.Empty;
                    }
                    if (cboFolders.Items.FindByValue(FolderPath) != null)
                    {
                        cboFolders.Items.FindByValue(FolderPath).Selected = true;
                    }
                    else
                    {
                        cboFolders.Items[0].Selected = true;
                        FolderPath = cboFolders.SelectedValue;
                    }

                    //cboFiles.DataSource = GetFileList(FileFilter, !_Required, cboFolders.SelectedItem.Value);
                    cboFiles.DataSource = GetFileList(!_Required);
                    cboFiles.DataBind();
                    if (cboFiles.Items.FindByText(FileName) != null)
                    {
                        cboFiles.Items.FindByText(FileName).Selected = true;
                    }
                    cboFiles.Visible = true;
                    txtFile.Visible = false;

                    string strWriteRoles = GetWriteRoles(FolderPath);
                    cmdUpload.Visible = PortalSecurity.IsInRoles(strWriteRoles) && _ShowUpLoad;

                    SetStorageLocationType();

                    txtUrl.Visible = false;
                    cmdSave.Visible = false;
                    cmdCancel.Visible = false;
                    break;
                case "M": // membership users

                    URLRow.Visible = false;
                    TabRow.Visible = false;
                    FileRow.Visible = false;
                    UserRow.Visible = true;

                    if (txtUser.Text == "")
                    {
                        txtUser.Text = _Url;
                    }
                    break;
            }
        }
        /// <summary>
        /// Re-Formats Url from the Url Control
        /// </summary>
        /// <param name="inputUrl">
        /// The input Url.
        /// </param>
        /// <returns>
        /// Returns the Formatted Url.
        /// </returns>
        private string ReFormatURL(string inputUrl)
        {
            if (inputUrl.StartsWith("http://") || inputUrl.StartsWith("FileID="))
            {
                return inputUrl;
            }

            var objFileController = new FileController();

            return string.Format(
                "FileID={0}",
                objFileController.ConvertFilePathToFileId(inputUrl, this._portalSettings.PortalId));
        }
        /// <summary>
        /// The Page_Load server event handler on this page is used to populate the role information for the page
        /// </summary>
        protected void Page_Load( object sender, EventArgs e )
        {
            try
            {
                //this needs to execute always to the client script code is registred in InvokePopupCal
                cmdStartCalendar.NavigateUrl = Calendar.InvokePopupCal( txtStartDate );
                cmdEndCalendar.NavigateUrl = Calendar.InvokePopupCal( txtEndDate );

                if( !Page.IsPostBack )
                {
                    if( !String.IsNullOrEmpty(_URL) )
                    {
                        lblLogURL.Text = URL; // saved for loading Log grid

                        TabType URLType = Globals.GetURLType( _URL );
                        if( URLType == TabType.File && _URL.ToLower().StartsWith( "fileid=" ) == false )
                        {
                            // to handle legacy scenarios before the introduction of the FileServerHandler
                            FileController objFiles = new FileController();
                            lblLogURL.Text = "FileID=" + objFiles.ConvertFilePathToFileId( _URL, PortalSettings.PortalId );
                        }

                        UrlController objUrls = new UrlController();
                        UrlTrackingInfo objUrlTracking = objUrls.GetUrlTracking( PortalSettings.PortalId, lblLogURL.Text, ModuleID );
                        if( objUrlTracking != null )
                        {
                            if( _FormattedURL == "" )
                            {
                                if( !URL.StartsWith( "http" ) && !URL.StartsWith( "mailto" ) )
                                {
                                    lblURL.Text = Globals.AddHTTP( Request.Url.Host );
                                }
                                lblURL.Text += Globals.LinkClick( URL, PortalSettings.ActiveTab.TabID, ModuleID, false );
                            }
                            else
                            {
                                lblURL.Text = _FormattedURL;
                            }
                            lblCreatedDate.Text = objUrlTracking.CreatedDate.ToString();

                            if( objUrlTracking.TrackClicks )
                            {
                                pnlTrack.Visible = true;
                                if( _TrackingURL == "" )
                                {
                                    if( !URL.StartsWith( "http" ) )
                                    {
                                        lblTrackingURL.Text = Globals.AddHTTP( Request.Url.Host );
                                    }
                                    lblTrackingURL.Text += Globals.LinkClick( URL, PortalSettings.ActiveTab.TabID, ModuleID, objUrlTracking.TrackClicks );
                                }
                                else
                                {
                                    lblTrackingURL.Text = _TrackingURL;
                                }
                                lblClicks.Text = objUrlTracking.Clicks.ToString();
                                if( !Null.IsNull( objUrlTracking.LastClick ) )
                                {
                                    lblLastClick.Text = objUrlTracking.LastClick.ToString();
                                }
                            }

                            if( objUrlTracking.LogActivity )
                            {
                                pnlLog.Visible = true;

                                txtStartDate.Text = DateAndTime.DateAdd( DateInterval.Day, -6, DateTime.Today ).ToShortDateString();
                                txtEndDate.Text = DateAndTime.DateAdd( DateInterval.Day, 1, DateTime.Today ).ToShortDateString();
                            }
                        }
                    }
                    else
                    {
                        this.Visible = false;
                    }
                }
            }
            catch( Exception exc ) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException( this, exc );
            }
        }