1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
22
|***************************************************************************/
25
using System.Collections;
31
namespace iFolder.WebService
34
/// iFolder User Policy
37
public class UserPolicy
39
private static readonly ISimiasLog log = SimiasLogManager.GetLogger(typeof(Member));
46
/// Is the User's Login Enabled?
48
public bool LoginEnabled;
51
/// The User Disk Space Limit
53
public long SpaceLimit;
56
public int EncryptionStatus;
59
/// The Effective User Disk Space Limit
61
public long SpaceLimitEffective;
64
/// The Maximum File Size Limit
66
public long FileSizeLimit;
69
/// The Effective Maximum File Size Limit
71
public long FileSizeLimitEffective;
74
/// The User Disk Space Used
76
public long SpaceUsed;
79
/// The User Disk Space Available
81
public long SpaceAvailable;
84
/// The User Sync Interval
86
public int SyncInterval;
89
/// The Effect User Sync Interval
91
public int SyncIntervalEffective;
94
/// The File Types to Be Included
96
public string[] FileTypesIncludes;
99
/// The File Types to Be Included
101
public string[] FileTypesIncludesEffective;
104
/// The File Types to Be Excluded
106
public string[] FileTypesExcludes;
109
/// The File Types to Be Excluded
111
public string[] FileTypesExcludesEffective;
121
/// Get the User Policy
123
/// <param name="userID">The User ID</param>
124
/// <returns>The UserPolicy Object</returns>
125
public static UserPolicy GetPolicy(string userID)
127
UserPolicy props = new UserPolicy();
129
props.UserID = userID;
131
Store store = Store.GetStore();
133
Domain domain = store.GetDomain(store.DefaultDomain);
135
Member member = domain.GetMemberByID(userID);
137
if (member == null) throw new UserDoesNotExistException(userID);
139
props.LoginEnabled = !(domain.IsLoginDisabled(userID));
142
DiskSpaceQuota quota = DiskSpaceQuota.Get(member);
144
props.SpaceLimitEffective = quota.Limit;
145
props.SpaceUsed = quota.UsedSpace;
146
props.SpaceAvailable = quota.AvailableSpace;
148
props.SpaceLimit = DiskSpaceQuota.GetLimit(member);
149
props.EncryptionStatus = Simias.Policy.SecurityState.GetStatus( member );
152
props.FileSizeLimit = FileSizeFilter.GetLimit(member);
153
props.FileSizeLimitEffective = FileSizeFilter.Get(member).Limit;
156
props.SyncInterval = Simias.Policy.SyncInterval.GetInterval(member);
157
props.SyncIntervalEffective = Simias.Policy.SyncInterval.Get(member).Interval;
160
SystemPolicy.SplitFileTypes(FileTypeFilter.GetPatterns(member),
161
out props.FileTypesIncludes, out props.FileTypesExcludes);
163
// file types effective
164
SystemPolicy.SplitFileTypes(FileTypeFilter.Get(member).FilterList,
165
out props.FileTypesIncludesEffective, out props.FileTypesExcludesEffective);
171
/// Set the User Policy
173
/// <param name="props">The UserPolicy Object</param>
174
public static void SetPolicy(UserPolicy props)
176
Store store = Store.GetStore();
178
Domain domain = store.GetDomain(store.DefaultDomain);
180
Member member = domain.GetMemberByID(props.UserID);
182
if (member == null) throw new UserDoesNotExistException(props.UserID);
184
if(props.LoginEnabled == true)
186
domain.SetLoginDisabled(props.UserID, false);
190
domain.SetLoginDisabled(props.UserID, true);
195
Simias.Policy.SecurityState.Create( member, props.EncryptionStatus );
198
if (props.SpaceLimit >= 0)
200
DiskSpaceQuota.Set(member, props.SpaceLimit);
204
if (props.FileSizeLimit >= 0)
206
FileSizeFilter.Set(member, props.FileSizeLimit);
210
if (props.SyncInterval >= 0)
212
Simias.Policy.SyncInterval.Set(member, props.SyncInterval);
216
if ((props.FileTypesExcludes != null) || (props.FileTypesIncludes != null))
218
FileTypeFilter.Set(member, SystemPolicy.CombineFileTypes(
219
props.FileTypesIncludes, props.FileTypesExcludes));