protected void Page_Load(object sender, EventArgs e)
        {
            string currentWiki = Tools.DetectCurrentWiki();

            if (!Page.IsPostBack)
            {
                // Localized strings for JavaScript
                StringBuilder sb = new StringBuilder();
                sb.Append(@"<script type=""text/javascript"">" + "\r\n<!--\n");
                sb.Append("var ConfirmMessage = '");
                sb.Append(Properties.Messages.ConfirmOperation);
                sb.Append("';\r\n");
                sb.AppendFormat("var UploadControl = '{0}';\r\n", fileUpload.ClientID);
                //sb.AppendFormat("var RefreshCommandParameter = '{0}';\r\n", btnRefresh.UniqueID);
                sb.AppendFormat("var OverwriteControl = '{0}';\r\n", chkOverwrite.ClientID);
                sb.Append("// -->\n</script>\n");
                lblStrings.Text = sb.ToString();

                // Setup upload information (max file size, allowed file types)
                lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$1", Tools.BytesToString(GlobalSettings.MaxFileSize * 1024));
                sb = new StringBuilder();
                string[] aft = Settings.GetAllowedFileTypes(currentWiki);
                for (int i = 0; i < aft.Length; i++)
                {
                    sb.Append(aft[i].ToUpper());
                    if (i != aft.Length - 1)
                    {
                        sb.Append(", ");
                    }
                }
                lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$2", sb.ToString());

                // Load Providers
                foreach (IFilesStorageProviderV40 prov in Collectors.CollectorsBox.FilesProviderCollector.GetAllProviders(currentWiki))
                {
                    ListItem item = new ListItem(prov.Information.Name, prov.GetType().FullName);
                    if (item.Value == GlobalSettings.DefaultFilesProvider)
                    {
                        item.Selected = true;
                    }
                    lstProviders.Items.Add(item);
                }

                if (CurrentPage == null)
                {
                    btnUpload.Enabled = false;
                }
            }

            // Set provider
            provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(lstProviders.SelectedValue, currentWiki);

            if (!Page.IsPostBack)
            {
                rptItems.DataBind();
            }

            DetectPermissions();
            SetupControls();
        }
Beispiel #2
0
        /// <summary>
        /// Loads the security configuration.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        private void LoadSecurityConfig(string currentWiki)
        {
            chkAllowUsersToRegister.Checked = Settings.UsersCanRegister(currentWiki);
            PopulateAccountActivationMode(Settings.GetAccountActivationMode(currentWiki));
            PopulateDefaultGroups(Settings.GetUsersGroup(currentWiki),
                                  Settings.GetAdministratorsGroup(currentWiki),
                                  Settings.GetAnonymousGroup(currentWiki));
            chkEnableCaptchaControl.Checked     = !Settings.GetDisableCaptchaControl(currentWiki);
            chkPreventConcurrentEditing.Checked = Settings.GetDisableConcurrentEditing(currentWiki);

            switch (Settings.GetModerationMode(currentWiki))
            {
            case ChangeModerationMode.None:
                rdoNoModeration.Checked = true;
                break;

            case ChangeModerationMode.RequirePageViewingPermissions:
                rdoRequirePageViewingPermissions.Checked = true;
                break;

            case ChangeModerationMode.RequirePageEditingPermissions:
                rdoRequirePageEditingPermissions.Checked = true;
                break;
            }

            txtExtensionsAllowed.Text = string.Join(", ", Settings.GetAllowedFileTypes(currentWiki));

            lstFileDownloadCountFilterMode.SelectedIndex = -1;
            switch (Settings.GetFileDownloadCountFilterMode(currentWiki))
            {
            case FileDownloadCountFilterMode.CountAll:
                lstFileDownloadCountFilterMode.SelectedIndex = 0;
                txtFileDownloadCountFilter.Enabled           = false;
                break;

            case FileDownloadCountFilterMode.CountSpecifiedExtensions:
                lstFileDownloadCountFilterMode.SelectedIndex = 1;
                txtFileDownloadCountFilter.Enabled           = true;
                txtFileDownloadCountFilter.Text = string.Join(", ", Settings.GetFileDownloadCountFilter(currentWiki));
                break;

            case FileDownloadCountFilterMode.ExcludeSpecifiedExtensions:
                txtFileDownloadCountFilter.Text              = string.Join(", ", Settings.GetFileDownloadCountFilter(currentWiki));
                txtFileDownloadCountFilter.Enabled           = true;
                lstFileDownloadCountFilterMode.SelectedIndex = 2;
                break;

            default:
                throw new NotSupportedException();
            }

            chkAllowScriptTags.Checked = Settings.GetScriptTagsAllowed(currentWiki);
            txtIpHostFilter.Text       = Settings.GetIpHostFilter(currentWiki);
        }
Beispiel #3
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (canUpload && (chkOverwrite.Checked && canDeleteFiles || !chkOverwrite.Checked))
            {
                lblUploadResult.Text = "";
                if (fileUpload.HasFile)
                {
                    if (fileUpload.FileBytes.Length > GlobalSettings.MaxFileSize * 1024)
                    {
                        lblUploadResult.Text     = Properties.Messages.FileTooBig;
                        lblUploadResult.CssClass = "resulterror";
                    }
                    else
                    {
                        // Check file extension
                        string[] aft     = Settings.GetAllowedFileTypes(currentWiki);
                        bool     allowed = false;

                        if (aft.Length > 0 && aft[0] == "*")
                        {
                            allowed = true;
                        }
                        else
                        {
                            string ext = Path.GetExtension(fileUpload.FileName);
                            if (ext == null)
                            {
                                ext = "";
                            }
                            if (ext.StartsWith("."))
                            {
                                ext = ext.Substring(1).ToLowerInvariant();
                            }
                            foreach (string ft in aft)
                            {
                                if (ft == ext)
                                {
                                    allowed = true;
                                    break;
                                }
                            }
                        }

                        if (!allowed)
                        {
                            lblUploadResult.Text     = Properties.Messages.InvalidFileType;
                            lblUploadResult.CssClass = "resulterror";
                        }
                        else
                        {
                            bool done = FilesAndAttachments.StoreFile(provider, CurrentDirectory + fileUpload.FileName, fileUpload.FileContent, chkOverwrite.Checked);

                            if (!done)
                            {
                                lblUploadResult.Text     = Properties.Messages.CannotStoreFile;
                                lblUploadResult.CssClass = "resulterror";
                            }
                            rptItems.DataBind();
                        }
                    }
                }
                else
                {
                    lblUploadResult.Text     = Properties.Messages.FileVoid;
                    lblUploadResult.CssClass = "resulterror";
                }
            }
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            currentWiki = Tools.DetectCurrentWiki();

            if (!Page.IsPostBack)
            {
                permissionsManager.CurrentResourceName = "/";

                // Localized strings for JavaScript
                StringBuilder sb = new StringBuilder();
                sb.Append(@"<script type=""text/javascript"">" + "\n<!--\n");
                sb.Append("var ConfirmMessage = '");
                sb.Append(Properties.Messages.ConfirmOperation);
                sb.Append("';\r\n");
                sb.AppendFormat("var CurrentNamespace = \"{0}\";\r\n", Tools.DetectCurrentNamespace());
                sb.Append("// -->\n</script>\n");
                lblStrings.Text = sb.ToString();

                // Setup upload information (max file size, allowed file types)
                lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$1", Tools.BytesToString(GlobalSettings.MaxFileSize * 1024));
                sb = new StringBuilder();
                string[] aft = Settings.GetAllowedFileTypes(currentWiki);
                for (int i = 0; i < aft.Length; i++)
                {
                    sb.Append(aft[i].ToUpper());
                    if (i != aft.Length - 1)
                    {
                        sb.Append(", ");
                    }
                }
                lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$2", sb.ToString());

                LoadProviders();

                permissionsManager.CurrentFilesProvider = lstProviders.SelectedValue;

                // See if a dir is specified in query string
                if (Request["Dir"] != null)
                {
                    string currDir = Request["Dir"];
                    if (!currDir.StartsWith("/"))
                    {
                        currDir = "/" + currDir;
                    }
                    if (!currDir.EndsWith("/"))
                    {
                        currDir += "/";
                    }
                    CurrentDirectory = currDir;
                }
            }

            // Set provider
            provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(lstProviders.SelectedValue, currentWiki);

            // The following actions are verified ***FOR THE CURRENT DIRECTORY***:
            // - List contents
            // - Download files
            // - Upload files
            // - Create directories
            // - Delete/Rename files -> hide/show buttons in repeater
            // - Delete/Rename directories --> hide/show buttons in repeater
            // - Manage Permissions -> avoid setting permissionsManager.CurrentResourceName/CurrentFilesProvider if not authorized
            // - Member of Administrators -> hide/show provider selection
            // ---> recheck everywhere an action is performed

            DetectPermissions();

            if (!Page.IsPostBack)
            {
                rptItems.DataBind();
            }

            PopulateBreadcrumb();

            SetupControlsForPermissions();
        }