~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/webaccess/.svn/text-base/iFolderNew.aspx.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
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.
9
 
 |
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.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com
20
 
 |
21
 
 | Author: Rob
22
 
 |***************************************************************************/
23
 
 
24
 
using System;
25
 
using System.Collections;
26
 
using System.ComponentModel;
27
 
using System.Data;
28
 
using System.Drawing;
29
 
using System.Web;
30
 
using System.Web.SessionState;
31
 
using System.Web.UI;
32
 
using System.Web.UI.WebControls;
33
 
using System.Web.UI.HtmlControls;
34
 
using System.Resources;
35
 
using System.Web.Services.Protocols;
36
 
using System.Net;
37
 
 
38
 
namespace Novell.iFolderApp.Web
39
 
{
40
 
        /// <summary>
41
 
        /// New iFolder Page
42
 
        /// </summary>
43
 
        public class iFolderNewPage : Page
44
 
        {
45
 
                enum SecurityState
46
 
                {
47
 
                        encryption = 1,
48
 
                        enforceEncryption = 2,
49
 
                        SSL = 4,
50
 
                        enforceSSL = 8
51
 
                }
52
 
 
53
 
                /// <summary>
54
 
                /// Message Box
55
 
                /// </summary>
56
 
                protected MessageControl Message;
57
 
                
58
 
                /// <summary>
59
 
                /// Header page
60
 
                /// </summary>
61
 
                protected HeaderControl Head;
62
 
 
63
 
                /// <summary>
64
 
                /// The Create Button
65
 
                /// </summary>
66
 
                protected Button CreateButton;
67
 
 
68
 
                /// <summary>
69
 
                /// The Cancel Button
70
 
                /// </summary>
71
 
                protected Button CancelButton;
72
 
 
73
 
                /// <summary>
74
 
                /// New iFolder Name
75
 
                /// </summary>
76
 
                protected TextBox NewiFolderName;
77
 
 
78
 
                /// <summary>
79
 
                /// New iFolder Description
80
 
                /// </summary>
81
 
                protected TextBox NewiFolderDescription;
82
 
 
83
 
                /// <summary>
84
 
                /// Encrypt the file data
85
 
                /// </summary>
86
 
                protected RadioButton Encryption;
87
 
 
88
 
                /*/// <summary>
89
 
                /// ssl the thick client to server data transfer
90
 
                /// </summary>
91
 
                protected CheckBox ssl;*/
92
 
 
93
 
                /// <summary>
94
 
                /// share the thick client to server data transfer
95
 
                /// </summary>
96
 
                protected RadioButton shared;
97
 
                
98
 
                /// <summary>
99
 
                /// List the RA Agents
100
 
                /// </summary>
101
 
                protected DropDownList RAList;
102
 
 
103
 
                /// <summary>
104
 
                /// The Select RA Label
105
 
                /// </summary>
106
 
                protected Label SelectLabel;
107
 
 
108
 
                /// <summary>
109
 
                /// The pass-phrase Label Button
110
 
                /// </summary>
111
 
                protected Label PassPhraseLabel;
112
 
 
113
 
                /// <summary>
114
 
                /// The pass-phrase Label Button
115
 
                /// </summary>
116
 
                protected Label VerifyPassPhraseLabel;
117
 
 
118
 
 
119
 
                /// <summary>
120
 
                /// pass-phrase text box
121
 
                /// </summary>
122
 
                protected TextBox PassPhraseText;
123
 
 
124
 
                /// <summary>
125
 
                /// pass-phrase text box
126
 
                /// </summary>
127
 
                protected TextBox VerifyPassPhraseText;
128
 
                
129
 
                /// <summary>
130
 
                /// iFolder Connection
131
 
                /// </summary>
132
 
                private iFolderWeb web;
133
 
 
134
 
                /// <summary>
135
 
                /// Resource Manager
136
 
                /// </summary>
137
 
                private ResourceManager rm;
138
 
 
139
 
                /// <summary>
140
 
                /// SHARED
141
 
                /// </summary>
142
 
                bool Sharable;
143
 
 
144
 
                /// <summary>
145
 
                /// Encry Algorithm (in future it can be selected from gui)
146
 
                /// </summary>
147
 
                string EncryptionAlgorithm="";
148
 
                
149
 
 
150
 
                /// <summary>
151
 
                /// Page Load
152
 
                /// </summary>
153
 
                /// <param name="sender"></param>
154
 
                /// <param name="e"></param>
155
 
                private void Page_Load(object sender, EventArgs e)
156
 
                {
157
 
                        // connection
158
 
                        web = (iFolderWeb)Session["Connection"];
159
 
 
160
 
                        // localization
161
 
                        rm = (ResourceManager) Application["RM"];
162
 
 
163
 
                        if (!IsPostBack)
164
 
                        {
165
 
                                // strings
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;
181
 
                                ChangeStatus();
182
 
                                
183
 
                                // Pass this page information to create the help link
184
 
                                Head.AddHelpLink(GetString("IFOLDERNEW"));
185
 
                        }
186
 
                }
187
 
                
188
 
                /// <summayr>
189
 
                /// Whenever encryption is checked by user or enforced in the policy , then this will be called 
190
 
                /// <summary>
191
 
                private void ChangeForEncryption()
192
 
                {
193
 
                        bool PassPhraseSet = web.IsPassPhraseSet();
194
 
                                
195
 
                        if(PassPhraseSet )
196
 
                        {
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)
201
 
                                {
202
 
                                        // user is in current session, so don't ask again for the passphrase
203
 
                                        PassPhraseLabel.Visible = PassPhraseText.Enabled = PassPhraseText.Visible = false;
204
 
                                }
205
 
                                else
206
 
                                {
207
 
                                        PassPhraseText.Enabled = PassPhraseText.Visible = true;
208
 
                                }
209
 
                        }
210
 
                        else
211
 
                        {
212
 
                                string [] RAListStrTemp= web.GetRAList();
213
 
                                
214
 
                                if (RAListStrTemp != null)
215
 
                                {
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;
223
 
                                        RAList.DataBind();
224
 
                                        SelectLabel.Visible = RAList.Enabled = RAList.Visible = true;
225
 
                                }
226
 
                                else
227
 
                                {
228
 
                                        // admin had not configurred Recovery-agent 
229
 
                                        SelectLabel.Visible = RAList.Enabled = RAList.Visible = false;
230
 
                                }
231
 
        
232
 
                                PassPhraseText.Enabled = PassPhraseText.Visible = VerifyPassPhraseLabel.Visible = VerifyPassPhraseText.Visible = VerifyPassPhraseText.Enabled = true;
233
 
                        }       
234
 
                }
235
 
                
236
 
                
237
 
                /// <summary>           
238
 
                /// Get the policy from the server and displayed in the check box
239
 
                /// </summary>
240
 
                private void ChangeStatus()
241
 
                {
242
 
                        int SecurityPolicy= web.GetEncryptionPolicy();
243
 
                        Encryption.Checked = shared.Checked = false;
244
 
                        Encryption.Enabled = shared.Enabled = false;
245
 
 
246
 
                        if(SecurityPolicy !=0)
247
 
                        {
248
 
                                        
249
 
                                if( (SecurityPolicy & (int)SecurityState.encryption) == (int) SecurityState.encryption)
250
 
                                {
251
 
                                        if( (SecurityPolicy & (int)SecurityState.enforceEncryption) == (int) SecurityState.enforceEncryption)
252
 
                                        {
253
 
                                                Encryption.Checked = true;
254
 
                                                        Encryption.Enabled = true;
255
 
                                                        shared.Enabled = false;
256
 
                                                        ChangeForEncryption();
257
 
                                        }        
258
 
                                        else
259
 
                                        {
260
 
                                                                                                Encryption.Enabled = true;
261
 
                                                                                                shared.Enabled = true;
262
 
                                                                                                Encryption.Checked = true; 
263
 
                                                                                                ChangeForEncryption();
264
 
                                        }       
265
 
                                }
266
 
                                else
267
 
                                {
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;
273
 
                                }
274
 
                                /*if( (SecurityPolicy & (int)SecurityState.SSL) == (int) SecurityState.SSL)
275
 
                                {
276
 
                                        if( (SecurityPolicy & (int)SecurityState.enforceSSL) == (int) SecurityState.enforceSSL)
277
 
                                        {
278
 
                                                shared.Checked = true;
279
 
                                        }  
280
 
                                        else
281
 
                                        {
282
 
                                                shared.Enabled = true;
283
 
                                                        //Encryption.Enabled = false;      
284
 
                                        }  
285
 
                                }*/
286
 
                        }
287
 
                        else
288
 
                        {
289
 
                                                        Encryption.Checked = false;
290
 
                                                        Encryption.Enabled = false;
291
 
                                                        shared.Enabled = true;
292
 
                                                        shared.Checked = true;
293
 
                        }
294
 
                        
295
 
                        if(shared.Checked)
296
 
                                                {
297
 
                                                        RAList.Enabled = false;
298
 
                                                        PassPhraseText.Enabled = false;
299
 
                                                        VerifyPassPhraseText.Enabled = false;
300
 
                                                }
301
 
                }
302
 
 
303
 
                /// <summary>
304
 
                /// Handle Exceptions
305
 
                /// </summary>
306
 
                /// <param name="e"></param>
307
 
                /// <returns></returns>
308
 
                private bool HandleException(Exception e)
309
 
                {
310
 
                        bool result = true;
311
 
 
312
 
                        string type = WebUtility.GetExceptionType(e);
313
 
 
314
 
                        // types
315
 
                        switch(type)
316
 
                        {
317
 
                                case "AccessException":
318
 
                                        Message.Text = GetString("ENTRY.ACCESSEXCEPTION");
319
 
                                        break;
320
 
 
321
 
                                default:
322
 
                                        
323
 
                                        // TEMP
324
 
                                        Message.Text = type;
325
 
 
326
 
                                        result = false;
327
 
                                        break;
328
 
                        }
329
 
 
330
 
                        return result;
331
 
                }
332
 
 
333
 
                /// <summary>
334
 
                /// Get a Localized String
335
 
                /// </summary>
336
 
                /// <param name="key"></param>
337
 
                /// <returns></returns>
338
 
                protected string GetString(string key)
339
 
                {
340
 
                        return WebUtility.GetString(key, rm);
341
 
                }
342
 
 
343
 
                #region Web Form Designer
344
 
 
345
 
                /// <summary>
346
 
                /// On Initialize
347
 
                /// </summary>
348
 
                /// <param name="e"></param>
349
 
                override protected void OnInit(EventArgs e)
350
 
                {
351
 
                        InitializeComponent();
352
 
                        base.OnInit(e);
353
 
                }
354
 
                
355
 
                /// <summary>
356
 
                /// Initialize Components
357
 
                /// </summary>
358
 
                private void InitializeComponent()
359
 
                {    
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);
365
 
                }
366
 
 
367
 
                #endregion
368
 
 
369
 
                /// <summary>
370
 
                /// Encrypt radio button checked/unchecked
371
 
                /// </summary>
372
 
                /// <param name="sender"></param>
373
 
                /// <param name="e"></param>
374
 
                private void Encryption_CheckedChanged(object sender, EventArgs e)
375
 
                {
376
 
                        if(Encryption.Checked)
377
 
                        {       
378
 
                                ChangeForEncryption();
379
 
                        }       
380
 
                }
381
 
 
382
 
                /// <summary>
383
 
                /// shared radio button checked/unchecked
384
 
                /// </summary>
385
 
                /// <param name="sender"></param>
386
 
                /// <param name="e"></param>
387
 
                private void shared_CheckedChanged(object sender, EventArgs e)
388
 
                {
389
 
                        if(shared.Checked)
390
 
                        {
391
 
                                RAList.SelectedValue = GetString("NONE");
392
 
                                RAList.Enabled = false;
393
 
                                PassPhraseText.Enabled = false;
394
 
                                PassPhraseText.Text = "";
395
 
                                VerifyPassPhraseText.Enabled = false;
396
 
                                VerifyPassPhraseText.Text = "";
397
 
                        }
398
 
                
399
 
                }
400
 
 
401
 
                /// <summary>
402
 
                /// Create Button Click
403
 
                /// </summary>
404
 
                /// <param name="sender"></param>
405
 
                /// <param name="e"></param>
406
 
                private void CreateButton_Click(object sender, EventArgs e)
407
 
                {
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;
413
 
 
414
 
                        //Validate the inputs
415
 
                        if(name.Length == 0)
416
 
                        {
417
 
                                Message.Text = GetString("IFOLDER.NONAME");
418
 
                                return;
419
 
                        }
420
 
 
421
 
                        //Very first time this code will be executed
422
 
                        if(Encryption.Checked == true && (web.IsPassPhraseSet()==false))
423
 
                        {
424
 
                                if((PassPhraseStr == "" || VerifyPassPhraseStr == ""))
425
 
                                {
426
 
                                        Message.Text = GetString("ENTER_PASSPHRASE");
427
 
                                        return;
428
 
                                }
429
 
                                if((! PassPhraseStr.Equals(VerifyPassPhraseStr)))
430
 
                                {
431
 
                                        Message.Text = GetString("PASSPHRASE_NOT_MATCH");
432
 
                                        VerifyPassPhraseText.Text = "";
433
 
                                        return;
434
 
                                }
435
 
                        }
436
 
                        else if(Encryption.Checked == true && PassPhraseStr == "" && SessionPassPhrase == null)
437
 
                        {
438
 
                                //create encrypted folder and pasphrase is not provided
439
 
                                Message.Text = GetString("ENTER_PASSPHRASE");
440
 
                                return;
441
 
                        }
442
 
 
443
 
                        // create iFolder
444
 
                        iFolder ifolder;                                
445
 
                        try
446
 
                        {
447
 
                                if(Encryption.Checked == true)
448
 
                                {
449
 
                                        EncryptionAlgorithm = "BlowFish";
450
 
                                        Sharable = false;
451
 
 
452
 
                                        //If not avaiable in the session 
453
 
                                        if(SessionPassPhrase == null)
454
 
                                        {
455
 
                                                bool PassPhraseSet = web.IsPassPhraseSet();
456
 
                                                if(PassPhraseSet)
457
 
                                                {
458
 
                                                        Status ObjValidate = web.ValidatePassPhrase(PassPhraseStr);
459
 
                                                        if(ObjValidate.statusCode != StatusCodes.Success)
460
 
                                                        {
461
 
                                                                Message.Text = GetString("PASSPHRASE_INCORRECT");
462
 
                                                                PassPhraseText.Text = "";
463
 
                                                                return;
464
 
                                                        }
465
 
                                                        else
466
 
                                                                Session["SessionPassPhrase"]= PassPhraseStr;    
467
 
                                                }
468
 
                                                else 
469
 
                                                {
470
 
                                                        //This block will get executed very first time
471
 
                                                        
472
 
                                                        if(web.GetRAList() != null)
473
 
                                                        {
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
477
 
                                                        }
478
 
                                                        else
479
 
                                                        {
480
 
                                                                //This case should come when no RA is configured by the admin
481
 
                                                                web.SetPassPhrase(PassPhraseStr, null, null);
482
 
                                                        }
483
 
                                                }
484
 
                                        }
485
 
                                        else
486
 
                                                PassPhraseStr = Session["SessionPassPhrase"] as string;
487
 
                                }
488
 
                                else
489
 
                                {
490
 
                                        PassPhraseStr = null;
491
 
                                        //if not encrypted then sharable must be true
492
 
                                        Sharable = true;
493
 
                                }
494
 
                                
495
 
                                // Send the ifolder Name, Description, Security details and the encryption algorithm                            
496
 
                                ifolder = web.CreateiFolder(name, description, Sharable, EncryptionAlgorithm, PassPhraseStr);
497
 
                                
498
 
                                if(SessionPassPhrase == null)
499
 
                                        Session["SessionPassPhrase"] = PassPhraseStr;
500
 
                                        
501
 
                                // Redirect to the browser page
502
 
                                Response.Redirect("Browse.aspx?iFolder=" + ifolder.ID);
503
 
                        }       
504
 
                        catch(SoapException ex)
505
 
                        {
506
 
                                if (!HandleException(ex))
507
 
                                {
508
 
                                        Message.Text = ex.Message;
509
 
                                        return;
510
 
                                }
511
 
                        }
512
 
                }
513
 
                
514
 
                
515
 
        
516
 
                /// <summary>
517
 
                /// Cancel Button Click
518
 
                /// </summary>
519
 
                /// <param name="sender"></param>
520
 
                /// <param name="e"></param>
521
 
                private void CancelButton_Click(object sender, EventArgs e)
522
 
                {
523
 
                        // redirect
524
 
                        Response.Redirect("iFolders.aspx");
525
 
                }
526
 
                
527
 
        }
528
 
}