Exemple #1
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);
        }
Exemple #2
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;
 }
Exemple #3
0
        /// <summary>
        /// Create An iFolder Entry
        /// </summary>
        /// <param name="c"></param>
        /// <param name="parent"></param>
        /// <param name="type"></param>
        /// <param name="entryName"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        internal static Node CreateEntry(Collection c, Node parent,
                                         iFolderEntryType type, string entryName, out string path, bool DontCheckPolicies)
        {
            Node result = null;

            // NOTE: a new entry off the iFolder is not allowed, it must be off the root directory node or lower
            if ((parent == null) || (c.ID.Equals(parent.ID)))
            {
                throw new EntryDoesNotExistException(parent.ID);
            }

            // NOTE: only directories can have children
            if (!parent.IsBaseType(NodeTypes.DirNodeType))
            {
                throw new DirectoryEntryRequiredException(parent.ID);
            }

            // check the name
            CheckName(entryName);

            // create new path
            DirNode parentDirNode = (DirNode)parent;

            path = parentDirNode.GetFullPath(c);
            path = System.IO.Path.Combine(path, entryName);

            // check for existing entry (case insensitive test)
            if (SyncFile.DoesNodeExist(c, parentDirNode, entryName))
            {
                throw new EntryAlreadyExistException(entryName);
            }

            // directory
            if (type == iFolderEntryType.Directory)
            {
                result = new DirNode(c, parentDirNode, entryName);
            }
            // file
            else
            {
                if (DontCheckPolicies == false)
                {
                    // check file type policy
                    FileTypeFilter filter = FileTypeFilter.Get(c);
                    if (!filter.Allowed(entryName))
                    {
                        throw new FileTypeException(entryName);
                    }
                }

                result = new FileNode(c, parentDirNode, entryName);
            }

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Get the iFolder Policy
        /// </summary>
        /// <param name="ifolderID">The iFolder ID</param>
        /// <param name="accessID">The Access User ID</param>
        /// <param name="adminID">The logged in Admin ID</param>
        /// <returns>An iFolderPolicy Object</returns>
        public static iFolderPolicy GetPolicy(string ifolderID, string accessID, string adminID)
        {
            iFolderPolicy props = new iFolderPolicy();

            props.iFolderID = ifolderID;

            Store store = Store.GetStore();

            Collection c = store.GetCollectionByID(ifolderID);

            if (c == null)
            {
                throw new iFolderDoesNotExistException(ifolderID);
            }

            // impersonate
            iFolder.Impersonate(c, accessID);

            // disk space
            DiskSpaceQuota dsq = DiskSpaceQuota.Get(c);

            props.SpaceLimitEffective = dsq.Limit;
            props.SpaceAvailable      = dsq.AvailableSpace;
            props.SpaceUsed           = c.StorageSize;
            props.SpaceLimit          = DiskSpaceQuota.GetLimit(c);

            // no syncing (locked)
            //props.Locked = IsLocked(c);
            props.Locked = c.Disabled;

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

            // to return the value of disable sharing policy for an iFolder
            props.SharingStatus = Simias.Policy.Sharing.GetStatus(c);

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

            SystemPolicy.SplitFileTypes(FileTypeFilter.Get(c, false).FilterList,
                                        out props.FileTypesIncludesEffective, out props.FileTypesExcludesEffective);

            // file size
            props.FileSizeLimit          = Simias.Policy.FileSizeFilter.GetLimit(c);
            props.FileSizeLimitEffective = Simias.Policy.FileSizeFilter.Get(c).Limit;
            props.AdminGroupRights       = iFolderUser.GetAdminRights(adminID, c.Owner.UserID);
            return(props);
        }
Exemple #5
0
        /// <summary>
        /// Create An iFolder Entry
        /// </summary>
        /// <param name="ifolderID">The iFolder ID</param>
        /// <param name="parentID">The Parent Entry ID</param>
        /// <param name="entryName">The New Entry Name</param>
        /// <param name="type">The iFolder Entry Type</param>
        /// <param name="accessID">The Access User ID</param>
        /// <returns>An iFolderEntry Object</returns>
        public static iFolderEntry CreateEntry(string ifolderID, string parentID,
                                               iFolderEntryType type, string entryName, string accessID, bool DontCheckPolicies)
        {
            Store store = Store.GetStore();

            // collection
            Collection c = store.GetCollectionByID(ifolderID);

            if (c == null)
            {
                throw new iFolderDoesNotExistException(ifolderID);
            }

            // does member exist?
            Member member = c.GetMemberByID(accessID);

            if (member == null && Simias.Service.Manager.LdapServiceEnabled == true)
            {
                Domain   domain = store.GetDomain(store.DefaultDomain);
                string[] IDs    = domain.GetMemberFamilyList(accessID);
                foreach (string id in IDs)
                {
                    member = c.GetMemberByID(id);
                    if (member != null)
                    {
                        break;
                    }
                }
            }

            if (member == null)
            {
                throw new MemberDoesNotExistException(accessID);
            }

            // impersonate
            iFolder.Impersonate(c, accessID);

            Node parent = c.GetNodeByID(parentID);

            string path;
            Node   entry = CreateEntry(c, parent, type, entryName, out path, DontCheckPolicies);

            // directory
            if (type == iFolderEntryType.Directory)
            {
                try
                {
                    // create directory and node
                    DirectoryInfo info = Directory.CreateDirectory(path);

                    // update
                    (entry as DirNode).CreationTime = info.CreationTime;

                    c.Commit(entry);
                }
                catch
                {
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path);
                    }

                    throw;
                }
            }

            // file
            else
            {
                if (DontCheckPolicies == false)
                {
                    // check file type policy
                    FileTypeFilter filter = FileTypeFilter.Get(c);
                    if (!filter.Allowed(entryName))
                    {
                        throw new FileTypeException(entryName);
                    }
                }

                try
                {
                    // create the file and node
                    File.Create(path).Close();

                    // update
                    (entry as FileNode).UpdateFileInfo(c);

                    c.Commit(entry);
                }
                catch
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    throw;
                }
            }

            // open the new node
            Node n = c.GetNodeByID(entry.ID);

            return(iFolderEntry.GetEntry(c, n));
        }
Exemple #6
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;
                }
            }
        }