Пример #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);
        }
Пример #2
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;
            }
        }
Пример #3
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;
 }
Пример #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);
        }
Пример #5
0
    public static void GetReports( )
    {
        //if( replace == false ) Console.WriteLine("You have opted to view and not delete..Use enable to modify also "); else Console.WriteLine("It will modify the members");
        Store.Initialize(SimiasDataPath, true, -1);
        Store store = Store.GetStore();

        if (store == null)
        {
            Console.WriteLine("store could not be initialized.....");
        }
        Domain domain = store.GetDomain(store.DefaultDomain);

        Console.WriteLine("**************************IFOLDER REPORT********************* ");
        Console.WriteLine();
        Console.WriteLine();
        try
        {
            ICSList ifolders = store.GetCollectionsByType("iFolder");
            foreach (ShallowNode sn in ifolders)
            {
                object[] cells = new object[count];

                Collection ifolder = store.GetCollectionByID(sn.ID);
                Member     owner   = domain.GetMemberByID(ifolder.Owner.UserID);

                Console.WriteLine("                          *************");
                Console.WriteLine("user name is :{0} and iFolder name is :{1}", owner.FN, ifolder.Name);
                Console.WriteLine("iFolder quota is :{0}", DiskSpaceQuota.GetLimit(ifolder));
                Console.WriteLine("Users quota is :{0}", DiskSpaceQuota.Get(owner).Limit);
                Console.WriteLine("                         ");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(ex);
            Console.WriteLine(ex.StackTrace);
        }
        finally
        {
            Store.DeleteInstance();
        }
    }
Пример #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;
                }
            }
        }
Пример #7
0
        /// <summary>
        /// generate the report
        /// </summary>
        /// <param name="path">path where to generate</param>
        /// <param name="timestamp">time</param>
        public static void Generate(string path, DateTime timestamp)
        {
            const double MB = 1024 * 1024;

            string fileName = Path.Combine(path,
                                           String.Format("ifolder-{0}.csv", timestamp.ToString("yyyyMMdd-HHmmss")));

            StreamWriter file = File.CreateText(fileName);

            try
            {
                Store  store  = Store.GetStore();
                Domain domain = store.GetDomain(store.DefaultDomain);

                // headers
                Report.WriteHeaderRow(file, columns);

                // list iFolders
                ICSList ifolders = store.GetCollectionsByType("iFolder");

                foreach (ShallowNode sn in ifolders)
                {
                    object[] cells = new object[count];

                    Collection ifolder = store.GetCollectionByID(sn.ID);
                    Member     owner   = domain.GetMemberByID(ifolder.Owner.UserID);

                    // cells
                    cells[(int)ColumnID.ReportTime]     = timestamp;
                    cells[(int)ColumnID.iFolderSystem]  = domain.Name;
                    cells[(int)ColumnID.iFolderServer]  = "localhost";
                    cells[(int)ColumnID.iFolderID]      = ifolder.ID;
                    cells[(int)ColumnID.iFolderName]    = ifolder.Name;
                    cells[(int)ColumnID.iFolderSize]    = ifolder.StorageSize / MB;
                    cells[(int)ColumnID.iFolderPath]    = ifolder.UnmanagedPath;
                    cells[(int)ColumnID.iFolderQuota]   = DiskSpaceQuota.GetLimit(ifolder) / MB;
                    cells[(int)ColumnID.MemberCount]    = ifolder.GetMemberList().Count;
                    cells[(int)ColumnID.FileCount]      = ifolder.GetNodesByType(NodeTypes.FileNodeType).Count;
                    cells[(int)ColumnID.DirectoryCount] = ifolder.GetNodesByType(NodeTypes.DirNodeType).Count;
                    cells[(int)ColumnID.OwnerID]        = owner.UserID;
                    cells[(int)ColumnID.OwnerName]      = owner.FN;
                    cells[(int)ColumnID.OwnerCN]        = owner.Name;
                    cells[(int)ColumnID.OwnerDN]        = owner.Properties.GetSingleProperty("DN");
                    cells[(int)ColumnID.OwnerQuota]     = DiskSpaceQuota.Get(owner).Limit / MB;
                    cells[(int)ColumnID.OwnerLastLogin] = owner.Properties.GetSingleProperty("LastLogin");
                    cells[(int)ColumnID.OwnerDisabled]  = domain.IsLoginDisabled(owner.UserID);
                    cells[(int)ColumnID.PreviousOwner]  = ifolder.PreviousOwner;
                    cells[(int)ColumnID.OrphanedOwner]  = ifolder.Properties.GetSingleProperty("OrphanedOwner");

                    Report.WriteRow(file, columns, cells);
                }
            }
            catch (Exception e)
            {
                file.WriteLine();
                file.WriteLine();
                file.WriteLine(e);
                file.WriteLine(e.StackTrace);
            }
            finally
            {
                file.Close();
            }
        }
Пример #8
0
        /// <summary>
        /// Generates a report
        /// </summary>
        public void GenerateReport()
        {
            bool         hadException = false;
            const double MB           = 1024 * 1024;
            ReportConfig config       = GetReportConfiguration();

            string reportPath = null;

            if (config.IsiFolder)
            {
                DirNode dirNode = reportCollection.GetRootDirectory();
                reportPath = dirNode.GetFullPath(reportCollection);
            }
            else
            {
                reportPath = ReportPath;
            }

            string fileName = String.Format("ifolder-{0}-{1}.csv",
                                            Environment.MachineName,
                                            currentReportTime.ToString("yyyyMMdd-HHmmss"));

            string filePath = Path.Combine(reportPath, fileName);

            log.Debug("Report file name = {0}", filePath);
            StreamWriter file = File.CreateText(filePath);

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

                // headers
                WriteHeaderRow(file, columns);

                // list iFolders
                ICSList ifolders = store.GetCollectionsByType("iFolder");

                foreach (ShallowNode sn in ifolders)
                {
                    object[] cells = new object[count];

                    Collection ifolder = store.GetCollectionByID(sn.ID);
                    Member     owner   = domain.GetMemberByID(ifolder.Owner.UserID);

                    // cells
                    if (cli != null)
                    {
                        cells[(int)ColumnID.ReportTime]     = currentReportTime.ToString(cli);
                        cells[(int)ColumnID.OwnerLastLogin] = owner.Properties.GetSingleProperty("LastLogin").ToString(cli);
                        cells[(int)ColumnID.LastSyncTime]   = ifolder.Properties.GetSingleProperty("LastModified").ToString(cli);
                    }
                    else
                    {
                        cells[(int)ColumnID.ReportTime]     = currentReportTime.ToString("F");
                        cells[(int)ColumnID.OwnerLastLogin] = owner.Properties.GetSingleProperty("LastLogin").ToString("F");
                        cells[(int)ColumnID.LastSyncTime]   = ifolder.Properties.GetSingleProperty("LastModified").ToString("F");
                    }
                    cells[( int )ColumnID.iFolderSystem]  = domain.Name;
                    cells[( int )ColumnID.iFolderServer]  = Environment.MachineName;
                    cells[( int )ColumnID.iFolderID]      = ifolder.ID;
                    cells[( int )ColumnID.iFolderName]    = ifolder.Name;
                    cells[( int )ColumnID.iFolderSize]    = ifolder.StorageSize / MB;
                    cells[( int )ColumnID.iFolderPath]    = ifolder.UnmanagedPath;
                    cells[( int )ColumnID.iFolderQuota]   = DiskSpaceQuota.GetLimit(ifolder) / MB;
                    cells[( int )ColumnID.MemberCount]    = ifolder.GetMemberList().Count;
                    cells[( int )ColumnID.FileCount]      = ifolder.GetNodesByType(NodeTypes.FileNodeType).Count;
                    cells[( int )ColumnID.DirectoryCount] = ifolder.GetNodesByType(NodeTypes.DirNodeType).Count;
                    cells[( int )ColumnID.OwnerID]        = owner.UserID;
                    cells[( int )ColumnID.OwnerName]      = owner.FN;
                    cells[( int )ColumnID.OwnerCN]        = owner.Name;
                    cells[( int )ColumnID.OwnerDN]        = owner.Properties.GetSingleProperty("DN");
                    cells[( int )ColumnID.OwnerQuota]     = DiskSpaceQuota.Get(owner).Limit / MB;
                    cells[( int )ColumnID.OwnerDisabled]  = domain.IsLoginDisabled(owner.UserID);
                    cells[( int )ColumnID.PreviousOwner]  = ifolder.PreviousOwner;
                    cells[( int )ColumnID.OrphanedOwner]  = ifolder.Properties.GetSingleProperty("OrphanedOwner");

                    WriteRow(file, columns, cells);
                }
            }
            catch (Exception ex)
            {
                hadException = true;
                file.WriteLine();
                file.WriteLine();
                file.WriteLine(ex);
                file.WriteLine(ex.StackTrace);
            }
            finally
            {
                file.Close();

                if (hadException == false)
                {
                    // If this is an iFolder create the file node for the report file.
                    if (config.IsiFolder)
                    {
                        CreateFileNode(fileName);
                    }

                    // Set the time of the last successful report.
                    SetLastReportTime(currentReportTime);
                }
            }
        }