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;
26
using System.ComponentModel;
30
using System.Web.SessionState;
32
using System.Web.UI.WebControls;
33
using System.Web.UI.HtmlControls;
34
using System.Resources;
35
using System.Web.Services.Protocols;
38
namespace Novell.iFolderApp.Web
43
public class iFolderNewPage : Page
48
enforceEncryption = 2,
56
protected MessageControl Message;
61
protected HeaderControl Head;
66
protected Button CreateButton;
71
protected Button CancelButton;
76
protected TextBox NewiFolderName;
79
/// New iFolder Description
81
protected TextBox NewiFolderDescription;
84
/// Encrypt the file data
86
protected RadioButton Encryption;
89
/// ssl the thick client to server data transfer
91
protected CheckBox ssl;*/
94
/// share the thick client to server data transfer
96
protected RadioButton shared;
99
/// List the RA Agents
101
protected DropDownList RAList;
104
/// The Select RA Label
106
protected Label SelectLabel;
109
/// The pass-phrase Label Button
111
protected Label PassPhraseLabel;
114
/// The pass-phrase Label Button
116
protected Label VerifyPassPhraseLabel;
120
/// pass-phrase text box
122
protected TextBox PassPhraseText;
125
/// pass-phrase text box
127
protected TextBox VerifyPassPhraseText;
130
/// iFolder Connection
132
private iFolderWeb web;
137
private ResourceManager rm;
145
/// Encry Algorithm (in future it can be selected from gui)
147
string EncryptionAlgorithm="";
153
/// <param name="sender"></param>
154
/// <param name="e"></param>
155
private void Page_Load(object sender, EventArgs e)
158
web = (iFolderWeb)Session["Connection"];
161
rm = (ResourceManager) Application["RM"];
166
CreateButton.Text = GetString("CREATE");
167
CancelButton.Text = GetString("CANCEL");
168
//Localization need to be enabled
169
Encryption.Text = GetString("ENCRYPTTHEIFOLDER");
170
Encryption.ToolTip = GetString("ENCRYPTIONCONDITION");
171
//ssl.Text = GetString("Secure Data Transfer");
172
shared.Text = GetString("SHARABLE");
173
shared.Checked = true;
174
shared.ToolTip = GetString("SHARECONDITION");
175
SelectLabel.Text = GetString("SELECTRECOVERYAGENT");
176
PassPhraseLabel.Text = GetString("ENTERPASSPHRASE");
177
VerifyPassPhraseLabel.Text = GetString("REENTER_PASSPHRASE");
178
VerifyPassPhraseLabel.Visible=VerifyPassPhraseText.Visible = false;
179
RAList.Enabled = false;
180
PassPhraseText.Enabled = false;
183
// Pass this page information to create the help link
184
Head.AddHelpLink(GetString("IFOLDERNEW"));
189
/// Whenever encryption is checked by user or enforced in the policy , then this will be called
191
private void ChangeForEncryption()
193
bool PassPhraseSet = web.IsPassPhraseSet();
197
SelectLabel.Visible = RAList.Visible = VerifyPassPhraseLabel.Visible = VerifyPassPhraseText.Visible = false;
198
PassPhraseText.Enabled = true;
199
string SessionPassPhrase = Session["SessionPassPhrase"] as string;
200
if(SessionPassPhrase != null)
202
// user is in current session, so don't ask again for the passphrase
203
PassPhraseLabel.Visible = PassPhraseText.Enabled = PassPhraseText.Visible = false;
207
PassPhraseText.Enabled = PassPhraseText.Visible = true;
212
string [] RAListStrTemp= web.GetRAList();
214
if (RAListStrTemp != null)
216
string [] RAListStr = new string [RAListStrTemp.Length + 1];
217
// making 1st entry of dropdownlist as None
218
RAListStr[0] = GetString("NONE");
219
//There may be a case that there is no certificate in the configured certificate path
220
for (int i = 1; i <= RAListStrTemp.Length ; i++)
221
RAListStr[i] = String.Copy(RAListStrTemp[i-1]);
222
RAList.DataSource = RAListStr;
224
SelectLabel.Visible = RAList.Enabled = RAList.Visible = true;
228
// admin had not configurred Recovery-agent
229
SelectLabel.Visible = RAList.Enabled = RAList.Visible = false;
232
PassPhraseText.Enabled = PassPhraseText.Visible = VerifyPassPhraseLabel.Visible = VerifyPassPhraseText.Visible = VerifyPassPhraseText.Enabled = true;
238
/// Get the policy from the server and displayed in the check box
240
private void ChangeStatus()
242
int SecurityPolicy= web.GetEncryptionPolicy();
243
Encryption.Checked = shared.Checked = false;
244
Encryption.Enabled = shared.Enabled = false;
246
if(SecurityPolicy !=0)
249
if( (SecurityPolicy & (int)SecurityState.encryption) == (int) SecurityState.encryption)
251
if( (SecurityPolicy & (int)SecurityState.enforceEncryption) == (int) SecurityState.enforceEncryption)
253
Encryption.Checked = true;
254
Encryption.Enabled = true;
255
shared.Enabled = false;
256
ChangeForEncryption();
260
Encryption.Enabled = true;
261
shared.Enabled = true;
262
Encryption.Checked = true;
263
ChangeForEncryption();
268
// it means enforce sharing is enabled for this user.
269
Encryption.Checked = false;
270
Encryption.Enabled = false;
271
shared.Enabled = true;
272
shared.Checked = true;
274
/*if( (SecurityPolicy & (int)SecurityState.SSL) == (int) SecurityState.SSL)
276
if( (SecurityPolicy & (int)SecurityState.enforceSSL) == (int) SecurityState.enforceSSL)
278
shared.Checked = true;
282
shared.Enabled = true;
283
//Encryption.Enabled = false;
289
Encryption.Checked = false;
290
Encryption.Enabled = false;
291
shared.Enabled = true;
292
shared.Checked = true;
297
RAList.Enabled = false;
298
PassPhraseText.Enabled = false;
299
VerifyPassPhraseText.Enabled = false;
304
/// Handle Exceptions
306
/// <param name="e"></param>
307
/// <returns></returns>
308
private bool HandleException(Exception e)
312
string type = WebUtility.GetExceptionType(e);
317
case "AccessException":
318
Message.Text = GetString("ENTRY.ACCESSEXCEPTION");
334
/// Get a Localized String
336
/// <param name="key"></param>
337
/// <returns></returns>
338
protected string GetString(string key)
340
return WebUtility.GetString(key, rm);
343
#region Web Form Designer
348
/// <param name="e"></param>
349
override protected void OnInit(EventArgs e)
351
InitializeComponent();
356
/// Initialize Components
358
private void InitializeComponent()
360
this.Load += new System.EventHandler(this.Page_Load);
361
this.CreateButton.Click += new EventHandler(CreateButton_Click);
362
this.CancelButton.Click += new EventHandler(CancelButton_Click);
363
this.Encryption.CheckedChanged += new EventHandler(Encryption_CheckedChanged);
364
this.shared.CheckedChanged += new EventHandler(shared_CheckedChanged);
370
/// Encrypt radio button checked/unchecked
372
/// <param name="sender"></param>
373
/// <param name="e"></param>
374
private void Encryption_CheckedChanged(object sender, EventArgs e)
376
if(Encryption.Checked)
378
ChangeForEncryption();
383
/// shared radio button checked/unchecked
385
/// <param name="sender"></param>
386
/// <param name="e"></param>
387
private void shared_CheckedChanged(object sender, EventArgs e)
391
RAList.SelectedValue = GetString("NONE");
392
RAList.Enabled = false;
393
PassPhraseText.Enabled = false;
394
PassPhraseText.Text = "";
395
VerifyPassPhraseText.Enabled = false;
396
VerifyPassPhraseText.Text = "";
402
/// Create Button Click
404
/// <param name="sender"></param>
405
/// <param name="e"></param>
406
private void CreateButton_Click(object sender, EventArgs e)
408
string name = NewiFolderName.Text.Trim();
409
string description = NewiFolderDescription.Text.Trim();
410
string PassPhraseStr = PassPhraseText.Text.Trim();
411
string VerifyPassPhraseStr = VerifyPassPhraseText.Text.Trim();
412
string SessionPassPhrase = Session["SessionPassPhrase"] as string;
414
//Validate the inputs
417
Message.Text = GetString("IFOLDER.NONAME");
421
//Very first time this code will be executed
422
if(Encryption.Checked == true && (web.IsPassPhraseSet()==false))
424
if((PassPhraseStr == "" || VerifyPassPhraseStr == ""))
426
Message.Text = GetString("ENTER_PASSPHRASE");
429
if((! PassPhraseStr.Equals(VerifyPassPhraseStr)))
431
Message.Text = GetString("PASSPHRASE_NOT_MATCH");
432
VerifyPassPhraseText.Text = "";
436
else if(Encryption.Checked == true && PassPhraseStr == "" && SessionPassPhrase == null)
438
//create encrypted folder and pasphrase is not provided
439
Message.Text = GetString("ENTER_PASSPHRASE");
447
if(Encryption.Checked == true)
449
EncryptionAlgorithm = "BlowFish";
452
//If not avaiable in the session
453
if(SessionPassPhrase == null)
455
bool PassPhraseSet = web.IsPassPhraseSet();
458
Status ObjValidate = web.ValidatePassPhrase(PassPhraseStr);
459
if(ObjValidate.statusCode != StatusCodes.Success)
461
Message.Text = GetString("PASSPHRASE_INCORRECT");
462
PassPhraseText.Text = "";
466
Session["SessionPassPhrase"]= PassPhraseStr;
470
//This block will get executed very first time
472
if(web.GetRAList() != null)
474
Response.Redirect(String.Format("iFolderCertificate.aspx?RAName={0}&EncryptionAlgorithm={1}&PassPhrase={2}&name={3}&description={4}",
475
RAList.SelectedValue, EncryptionAlgorithm, PassPhraseStr, name, description));
476
//SetPassphrase will be done in the redirected page and store in the session
480
//This case should come when no RA is configured by the admin
481
web.SetPassPhrase(PassPhraseStr, null, null);
486
PassPhraseStr = Session["SessionPassPhrase"] as string;
490
PassPhraseStr = null;
491
//if not encrypted then sharable must be true
495
// Send the ifolder Name, Description, Security details and the encryption algorithm
496
ifolder = web.CreateiFolder(name, description, Sharable, EncryptionAlgorithm, PassPhraseStr);
498
if(SessionPassPhrase == null)
499
Session["SessionPassPhrase"] = PassPhraseStr;
501
// Redirect to the browser page
502
Response.Redirect("Browse.aspx?iFolder=" + ifolder.ID);
504
catch(SoapException ex)
506
if (!HandleException(ex))
508
Message.Text = ex.Message;
517
/// Cancel Button Click
519
/// <param name="sender"></param>
520
/// <param name="e"></param>
521
private void CancelButton_Click(object sender, EventArgs e)
524
Response.Redirect("iFolders.aspx");