Esempio n. 1
0
        /// <summary>
        /// Get the iFolder System Policy
        /// </summary>
        /// <returns>An SystemPolicy Object</returns>
        public static SystemPolicy GetPolicy()
        {
            SystemPolicy props = new SystemPolicy();

            Store store = Store.GetStore();

            string domain = store.DefaultDomain;

            // space limit
            props.SpaceLimitUser = DiskSpaceQuota.GetLimit(domain);

            //ifolder limit
            props.NoiFoldersLimit = iFolderLimit.GetLimit(domain);

            // sync internval
            props.SyncInterval = Simias.Policy.SyncInterval.GetInterval(domain);

            // file size
            props.FileSizeLimit = FileSizeFilter.GetLimit(domain);

            props.EncryptionStatus = Simias.Policy.SecurityState.GetStatus(domain);

            // Disable sharing policy
            props.SharingStatus = Simias.Policy.Sharing.GetStatus(domain);

            // file types
            SystemPolicy.SplitFileTypes(FileTypeFilter.GetPatterns(domain),
                                        out props.FileTypesIncludes, out props.FileTypesExcludes);

            return(props);
        }
Esempio n. 2
0
        private void AddExtractList(string folder, FileSizeFilter filter)
        {
            try
            {
                foreach (string file in Directory.GetFiles(folder))
                {
                    if (CheckFile(file, txtExtractFileFilter.Text) && CheckFileSize(file, filter))
                    {
                        ListViewItem lvi = new ListViewItem(file);
                        lvExtractList.Items.Add(lvi);
                        UpdateExtractFileCount();
                        break;
                    }
                }

                if (Program.Settings.SearchSubFolders)
                {
                    foreach (string directory in Directory.GetDirectories(folder))
                    {
                        AddExtractList(directory, filter);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 3
0
 private void lvExtractList_DragDrop(object sender, DragEventArgs e)
 {
     try
     {
         string[] folders = (string[])e.Data.GetData(DataFormats.FileDrop, true);
         Array.Sort(folders);
         FileSizeFilter filter = ParseFileSizeFilter(txtExtractFileSizeFilter.Text);
         foreach (string folder in folders)
         {
             if (Directory.Exists(folder))
             {
                 AddExtractList(folder, filter);
             }
             else if (File.Exists(folder))
             {
                 ListViewItem lvi = new ListViewItem(folder);
                 lvExtractList.Items.Add(lvi);
                 UpdateExtractFileCount();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Esempio n. 4
0
        private void btnExtractAdd_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (!string.IsNullOrEmpty(Program.Settings.LastExtractFolder) && Directory.Exists(Program.Settings.LastExtractFolder))
            {
                fbd.SelectedPath = Program.Settings.LastExtractFolder;
            }
            else if (!string.IsNullOrEmpty(txtExtractPath.Text) && Directory.Exists(txtExtractPath.Text))
            {
                fbd.SelectedPath = txtExtractPath.Text;
            }
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                Program.Settings.LastExtractFolder = fbd.SelectedPath;
                try
                {
                    FileSizeFilter filter = ParseFileSizeFilter(txtExtractFileSizeFilter.Text);
                    AddExtractList(fbd.SelectedPath, filter);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Get the User Policy
        /// </summary>
        /// <param name="userID">The User ID</param>
        /// <returns>The UserPolicy Object</returns>
        public static UserPolicy GetPolicy(string userID, string AdminId)
        {
            UserPolicy props = new UserPolicy();

            props.UserID = userID;

            Store store = Store.GetStore();

            Domain domain = store.GetDomain(store.DefaultDomain);

            Member member = domain.GetMemberByID(userID);

            if (member == null)
            {
                throw new UserDoesNotExistException(userID);
            }

            Access.Rights rights = (member != null) ? member.Rights : Access.Rights.Deny;

            props.isAdmin = (rights == Access.Rights.Admin);

            props.LoginEnabled = !(domain.GetLoginpolicy(userID));

            // disk space
            DiskSpaceQuota quota = DiskSpaceQuota.Get(member);

            props.SpaceLimitEffective = quota.Limit;
            //props.SpaceUsed = quota.UsedSpace;
            props.SpaceUsed = Simias.Server.Catalog.GetUsedSpaceOfUserID(userID);
            //props.SpaceAvailable = quota.AvailableSpace;

            props.SpaceLimit       = DiskSpaceQuota.GetLimit(member);
            props.SpaceAvailable   = props.SpaceLimitEffective - props.SpaceUsed;
            props.EncryptionStatus = Simias.Policy.SecurityState.GetStatus(member);

            // To return disable sharing value for an user
            props.SharingStatus = Simias.Policy.Sharing.GetStatus(member);

            // file size
            props.FileSizeLimit          = FileSizeFilter.GetLimit(member);
            props.FileSizeLimitEffective = FileSizeFilter.Get(member).Limit;

            //No of ifolders limit
            props.NoiFoldersLimit = iFolderLimit.Get(member).Limit;

            // sync interval
            props.SyncInterval          = Simias.Policy.SyncInterval.GetInterval(member);
            props.SyncIntervalEffective = Simias.Policy.SyncInterval.Get(member).Interval;

            // file types
            SystemPolicy.SplitFileTypes(FileTypeFilter.GetPatterns(member),
                                        out props.FileTypesIncludes, out props.FileTypesExcludes);

            // file types effective
            SystemPolicy.SplitFileTypes(FileTypeFilter.Get(member, false).FilterUserList,
                                        out props.FileTypesIncludesEffective, out props.FileTypesExcludesEffective);
            props.AdminGroupRights = iFolderUser.GetAdminRights(AdminId, userID);
            return(props);
        }
Esempio n. 6
0
 /// <summary>
 /// Constructs a SyncPolicy object.
 /// </summary>
 /// <param name="collection">The collection the policy belongs to.</param>
 public SyncPolicy(Collection collection)
 {
     // Check if files pass policy.
     //Member member = collection.GetCurrentMember();
     dsQuota  = DiskSpaceQuota.Get(collection);
     fsFilter = FileSizeFilter.Get(collection);
     ftFilter = FileTypeFilter.Get(collection);
     OwnerID  = collection.Owner.UserID;
 }
Esempio n. 7
0
        /// <summary>
        /// Open the File for Writing.
        /// </summary>
        /// <param name="length">New file length.</param>
        public void OpenWrite(long length)
        {
            this.length = length;

            try
            {
                // check access
                member = collection.GetMemberByID(accessID);

                // does the member exist?
                if (member == null)
                {
                    throw new MemberDoesNotExistException(accessID);
                }

                // does the member have wright rights
                if ((member.Rights != Access.Rights.Admin) && (member.Rights != Access.Rights.ReadWrite))
                {
                    throw new AccessException(collection, member, Access.Rights.ReadWrite);
                }

                // backup file
                backupPath = String.Format("{0}.simias.temp", path);
                File.Copy(path, backupPath, true);
                long deltaSize = length - (new FileInfo(backupPath)).Length;

                // open file
                stream   = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None);
                updating = true;

                // check file size policy
                FileSizeFilter fsFilter = FileSizeFilter.Get(collection);
                if (!fsFilter.Allowed(deltaSize))
                {
                    throw new FileSizeException(node.Name);
                }

                // check disk quota policy
                DiskSpaceQuota dsQuota = DiskSpaceQuota.Get(collection);
                if (!dsQuota.Allowed(deltaSize))
                {
                    throw new DiskQuotaException(node.Name);
                }

                // log
                log.LogAccess("OpenWrite", node.GetRelativePath(), node.ID, "Success");
            }
            catch
            {
                // log
                log.LogAccess("OpenWrite", node.GetRelativePath(), node.ID, "Failed");

                Close(true);

                throw;
            }
        }
Esempio n. 8
0
        private bool CheckFileSize(string file, FileSizeFilter filter)
        {
            FileInfo fi = new FileInfo(file);

            if ((filter.MathOperator == '<' && fi.Length < filter.FileSize) || (filter.MathOperator == '>' && fi.Length > filter.FileSize))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// Set the iFolder System Policy
        /// </summary>
        /// <param name="props">The SystemPolicy Object</param>
        public static void SetPolicy(SystemPolicy props)
        {
            Store store = Store.GetStore();

            string domain = store.DefaultDomain;

            // space limit
            if (props.SpaceLimitUser >= -1)
            {
                DiskSpaceQuota.Set(domain, props.SpaceLimitUser);
            }

            // ifolder limit
            iFolderLimit.Set(domain, props.NoiFoldersLimit);

            // sync interval
            if (props.SyncInterval >= 0)
            {
                Simias.Policy.SyncInterval.Set(domain, props.SyncInterval);
            }
            // Added by Ramesh
            //Encryption Status
            Simias.Policy.SecurityState.Create(domain, props.EncryptionStatus);

            // Setting the enumerator value for disabling sharing
            Simias.Policy.Sharing.Create(domain, props.SharingStatus);

            // file size
            if (props.FileSizeLimit >= 0)
            {
                FileSizeFilter.Set(domain, props.FileSizeLimit);
            }

            // file types
            if ((props.FileTypesExcludes != null) || (props.FileTypesIncludes != null))
            {
                FileTypeFilter.Set(domain, SystemPolicy.CombineFileTypes(
                                       props.FileTypesIncludes, props.FileTypesExcludes));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Read required filters from the GUI and then put them in the queue
        /// for processing of the images
        /// </summary>
        private void setFilters()
        {
            // remove filters from the previous execution. In case the settings has changed
            filters.Clear();

            // check if the checkbox is set
            if (mainGUI.GetHours() != null)
            {
                // if checkbox is set on hours, set the filter
                IFilter dateFilter = new DateFilter(
                    DateTime.Now.AddHours(-1 * (int)mainGUI.GetHours()));
                addFilter(dateFilter);
            }

            if (mainGUI.GetKilobytes() != null)
            {
                IFilter FileSizeFilter = new FileSizeFilter((int)mainGUI.GetKilobytes() * 1000);
                addFilter(FileSizeFilter);
            }


            // always add jpeg filter before filter with image size.
            IFilter imageFilter = new ImageTypeFilter(mainGUI.IsJPG(), mainGUI.IsPNG(), mainGUI.IsGIF());

            addFilter(imageFilter);


            // we only need to check if one of the dimensions is set,
            // as both of them are required on the form.
            if (mainGUI.GetMinHeight() != null)
            {
                int     minWidth        = (int)mainGUI.GetMinWidth();
                int     minHeight       = (int)mainGUI.GetMinHeight();
                IFilter imageSizeFilter = new ImageSizeFilter(minWidth, minHeight);
                addFilter(imageSizeFilter);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Set the User Policy
        /// </summary>
        /// <param name="props">The UserPolicy Object</param>
        public static void SetPolicy(UserPolicy props)
        {
            Store store = Store.GetStore();

            Domain domain = store.GetDomain(store.DefaultDomain);

            Member member = domain.GetMemberByID(props.UserID);

            if (member == null)
            {
                throw new UserDoesNotExistException(props.UserID);
            }

            if (props.LoginEnabled == true)
            {
                domain.SetLoginDisabled(props.UserID, false);
            }
            else
            {
                domain.SetLoginDisabled(props.UserID, true);
            }


// Added by Ramesh
            if (props.EncryptionStatus >= 0)
            {
                Simias.Policy.SecurityState.Create(member, props.EncryptionStatus);
            }

            // to set disable sharing policy value for an user
            if (props.SharingStatus >= 0)
            {
                Simias.Policy.Sharing.Create(member, props.SharingStatus);
            }

            // disk space
            if (props.SpaceLimit >= -1)
            {
                DiskSpaceQuota.Set(member, props.SpaceLimit);
            }


            //limiting no of ifolder per user policy.
            if (props.NoiFoldersLimit >= -2)
            {
                iFolderLimit.Set(member, props.NoiFoldersLimit);
            }


            // file size
            if (props.FileSizeLimit >= 0)
            {
                FileSizeFilter.Set(member, props.FileSizeLimit);
            }

            // sync interval
            if (props.SyncInterval >= 0)
            {
                Simias.Policy.SyncInterval.Set(member, props.SyncInterval);
            }

            // file types
            if ((props.FileTypesExcludes != null) || (props.FileTypesIncludes != null))
            {
                FileTypeFilter.Set(member, SystemPolicy.CombineFileTypes(
                                       props.FileTypesIncludes, props.FileTypesExcludes));
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Process the Request
        /// </summary>
        /// <param name="context">The HttpContext object.</param>
        public override void ProcessRequest(HttpContext context)
        {
            const int BUFFERSIZE = (16 * 1024);
            string    backupPath = null;

            try
            {
                bool DontCheckPolicies = false;
                // initialize
                Initialize(context);
                Length = int.Parse(context.Request.QueryString["Length"]);
                string dontCheckPolicies = null;
                long   NodeLength        = Length;
                try
                {
                    dontCheckPolicies = context.Request.QueryString["DontCheckPolicies"];
                    if (dontCheckPolicies != null && dontCheckPolicies == "true")
                    {
                        DontCheckPolicies = true;
                    }
                }
                catch
                {
                }

                try
                {
                    string nodelength = context.Request.QueryString["NodeLength"];
                    if (nodelength != null && nodelength != string.Empty)
                    {
                        Length = int.Parse(nodelength);
                    }
                }
                catch
                {
                }


                // does member have write rights
                if ((member.Rights != Access.Rights.Admin) && (member.Rights != Access.Rights.ReadWrite))
                {
                    throw new AccessException(collection, member, Access.Rights.ReadWrite);
                }

                long backupLength = 0;

                // new file?
                if (node == null)
                {
                    filename = System.IO.Path.GetFileName(entryPath);

                    Node parent = iFolderEntry.GetEntryByPath(collection,
                                                              System.IO.Path.GetDirectoryName(entryPath).Replace('\\', '/'));

                    node = (FileNode)iFolderEntry.CreateEntry(collection, parent,
                                                              iFolderEntryType.File, filename, out filePath, DontCheckPolicies);
                }
                else
                {
                    // check file type policy
                    FileTypeFilter fsFilter = FileTypeFilter.Get(collection);
                    if (!fsFilter.Allowed(filename))
                    {
                        throw new FileTypeException(filename);
                    }
                    // backup file
                    backupPath = String.Format("{0}.simias.temp", filePath);
                    File.Copy(filePath, backupPath, true);
                    backupLength = (new FileInfo(backupPath)).Length;
                }

                long deltaSize = context.Request.ContentLength - backupLength;

                if (DontCheckPolicies == false)
                {
                    if (collection.Disabled)
                    {
                        throw new LockException();
                    }
                    // Check first, if this file is violating aggregate disk quota limit set to his group
                    if (!iFolderUser.GroupQuotaUploadAllowed(collection.Owner.UserID, deltaSize))
                    {
                        throw new DiskQuotaException(filename);
                    }

                    // check file size policy
                    FileSizeFilter fsFilter = FileSizeFilter.Get(collection);
                    if (!fsFilter.Allowed(deltaSize))
                    {
                        throw new FileSizeException(filename);
                    }

                    // check disk quota policy
                    DiskSpaceQuota dsQuota = DiskSpaceQuota.Get(collection);
                    if (!dsQuota.Allowed(deltaSize))
                    {
                        throw new DiskQuotaException(filename);
                    }
                }
                try{
                    // lock the file
                    FileStream stream = File.Open(filePath, FileMode.Create, FileAccess.Write, FileShare.None);

                    // reader
                    Stream reader = context.Request.InputStream;

                    try
                    {
                        byte[] buffer = new byte[BUFFERSIZE];

                        int count = 0;

                        // download file
                        while ((count = reader.Read(buffer, 0, BUFFERSIZE)) > 0)
                        {
                            stream.Write(buffer, 0, count);
                            stream.Flush();
                        }
                    }
                    finally
                    {
                        // release the file
                        stream.Close();

                        // release the reader
                        reader.Close();
                    }


                    // update node
                    node.UpdateWebFileInfo(collection, Length);
                    //node.UpdateFileInfo(collection);
                    collection.Commit(node);

                    /*
                     *      As of now the hash map from web access is being uploaded only for unencrypted files. So for encrypted files, if we are doing delta sync, then the existing hashmap should be removed immediately after the file is uploaded ( because we are not uploading the new hashmap for the file.)
                     */
                    /* Uploading Hash map for unencrypted files */
                    if (collection.EncryptionAlgorithm == null || collection.EncryptionAlgorithm == "")
                    {
                        // Upload hashmap for unencrypted iFolders..
                        log.LogAccess("Upload hash", node.GetRelativePath(), node.ID, "Success");
                        HashMap map = new HashMap(collection, node);
                        map.CreateHashMapFile();
                    }

                    // log
                    log.LogAccess("Upload", node.GetRelativePath(), node.ID, "Success");
                }
                catch
                {
                    // restore backup
                    if (backupPath != null)
                    {
                        File.Copy(backupPath, filePath, true);
                    }

                    // log
                    log.LogAccess("Upload", node.GetRelativePath(), node.ID, "Failed");

                    throw;
                }
                finally
                {
                    // delete backup file
                    if ((backupPath != null) && File.Exists(backupPath))
                    {
                        File.Delete(backupPath);
                        backupPath = null;
                    }
                }
            }
            catch (Exception e)
            {
                // consume the file for better error reporting
                Stream reader = null;

                try
                {
                    // reader
                    reader = context.Request.InputStream;

                    byte[] buffer = new byte[BUFFERSIZE];

                    // download file
                    while (reader.Read(buffer, 0, BUFFERSIZE) > 0)
                    {
                        ;
                    }
                }
                catch
                {
                    // ignore
                }
                finally
                {
                    // release the reader
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }

                // create an HTTP error
                context.Response.StatusCode        = (int)HttpStatusCode.InternalServerError;
                context.Response.StatusDescription = e.GetType().Name;
            }
            finally
            {
                // delete backup file
                if ((backupPath != null) && File.Exists(backupPath))
                {
                    File.Delete(backupPath);
                    backupPath = null;
                }
            }
        }
Esempio n. 13
0
        private FileSizeFilter ParseFileSizeFilter(string filter)
        {
            filter = filter.Trim();
            if (!string.IsNullOrEmpty(filter) && (filter[0] == '<' || filter[0] == '>'))
            {
                FileSizeFilter result = new FileSizeFilter();
                result.MathOperator = filter[0];
                if (filter.Length > 1 && char.IsDigit(filter[1]))
                {
                    for (int i = 2; i < filter.Length; i++)
                    {
                        if (!char.IsDigit(filter[i]) && filter[i] != ' ')
                        {
                            long number = long.Parse(filter.Substring(1, i - 1));
                            switch (filter.Remove(0, i).ToLowerInvariant())
                            {
                            case "gigabyte":
                            case "gb":
                                number *= 1000 * 1000 * 1000;
                                break;

                            case "gibibyte":
                            case "gib":
                                number *= 1024 * 1024 * 1024;
                                break;

                            case "megabyte":
                            case "mb":
                                number *= 1000 * 1000;
                                break;

                            case "mebibyte":
                            case "mib":
                                number *= 1024 * 1024;
                                break;

                            case "kilobyte":
                            case "kb":
                                number *= 1000;
                                break;

                            case "kibibyte":
                            case "kib":
                                number *= 1024;
                                break;

                            case "byte":
                            case "b":
                                break;

                            default:
                                throw new Exception("File size filter not end with file size type. (B, KiB, MiB, GiB)");
                            }
                            result.FileSize = number;
                            return(result);
                        }
                    }
                    throw new Exception("File size filter not end with file size type. (B, KiB, MiB, GiB)");
                }
                else
                {
                    throw new Exception("File size filter need to have number after math operator.");
                }
            }
            else
            {
                throw new Exception("File size filter not start with math operator. (< or >)");
            }
        }