-
Notifications
You must be signed in to change notification settings - Fork 745
/
PortalController.cs
3835 lines (3381 loc) · 164 KB
/
PortalController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Entities.Portals
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using DotNetNuke.Common;
using DotNetNuke.Common.Internal;
using DotNetNuke.Common.Lists;
using DotNetNuke.Common.Utilities;
using DotNetNuke.ComponentModel;
using DotNetNuke.Data;
using DotNetNuke.Entities.Content.Workflow;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals.Internal;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Urls;
using DotNetNuke.Entities.Users;
using DotNetNuke.Entities.Users.Social;
using DotNetNuke.Framework;
using DotNetNuke.Instrumentation;
using DotNetNuke.Security.Membership;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Cache;
using DotNetNuke.Services.Cryptography;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Log.EventLog;
// using DotNetNuke.Services.Upgrade.Internals.InstallConfiguration;
using DotNetNuke.Services.Search.Entities;
using DotNetNuke.Web.Client;
using ICSharpCode.SharpZipLib.Zip;
using FileInfo = DotNetNuke.Services.FileSystem.FileInfo;
using IAbPortalSettings = DotNetNuke.Abstractions.Portals.IPortalSettings;
/// <summary>
/// PoralController provides business layer of poatal.
/// </summary>
/// <remarks>
/// DotNetNuke supports the concept of virtualised sites in a single install. This means that multiple sites,
/// each potentially with multiple unique URL's, can exist in one instance of DotNetNuke i.e. one set of files and one database.
/// </remarks>
public partial class PortalController : ServiceLocator<IPortalController, PortalController>, IPortalController
{
public const string HtmlText_TimeToAutoSave = "HtmlText_TimeToAutoSave";
public const string HtmlText_AutoSaveEnabled = "HtmlText_AutoSaveEnabled";
protected const string HttpContextKeyPortalSettingsDictionary = "PortalSettingsDictionary{0}{1}";
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(PortalController));
/// <summary>
/// Adds the portal dictionary.
/// </summary>
/// <param name="portalId">The portal id.</param>
/// <param name="tabId">The tab id.</param>
public static void AddPortalDictionary(int portalId, int tabId)
{
var portalDic = GetPortalDictionary();
portalDic[tabId] = portalId;
DataCache.SetCache(DataCache.PortalDictionaryCacheKey, portalDic);
}
/// <summary>
/// Creates the root folder for a child portal.
/// </summary>
/// <remarks>
/// If call this method, it will create the specific folder if the folder doesn't exist;
/// and will copy subhost.aspx to the folder if there is no 'Default.aspx'.
/// </remarks>
/// <param name="ChildPath">The child path.</param>
/// <returns>
/// If the method executed successful, it will return NullString, otherwise return error message.
/// </returns>
/// <example>
/// <code lang="C#">
/// string childPhysicalPath = Server.MapPath(childPath);
/// message = PortalController.CreateChildPortalFolder(childPhysicalPath);
/// </code>
/// </example>
public static string CreateChildPortalFolder(string ChildPath)
{
string message = Null.NullString;
// Set up Child Portal
try
{
// create the subdirectory for the new portal
if (!Directory.Exists(ChildPath))
{
Directory.CreateDirectory(ChildPath);
}
// create the subhost default.aspx file
if (!File.Exists(ChildPath + "\\" + Globals.glbDefaultPage))
{
File.Copy(Globals.HostMapPath + "subhost.aspx", ChildPath + "\\" + Globals.glbDefaultPage);
}
}
catch (Exception Exc)
{
Logger.Error(Exc);
message += Localization.GetString("ChildPortal.Error") + Exc.Message + Exc.StackTrace;
}
return message;
}
/// <summary>
/// Deletes all expired portals.
/// </summary>
/// <param name="serverPath">The server path.</param>
public static void DeleteExpiredPortals(string serverPath)
{
foreach (PortalInfo portal in GetExpiredPortals())
{
DeletePortal(portal, serverPath);
}
}
/// <summary>
/// Deletes the portal.
/// </summary>
/// <param name="portal">The portal.</param>
/// <param name="serverPath">The server path.</param>
/// <returns>If the method executed successful, it will return NullString, otherwise return error message.</returns>
public static string DeletePortal(PortalInfo portal, string serverPath)
{
string message = string.Empty;
// check if this is the last portal
var portals = Instance.GetPortals();
if (portals.Count > 1)
{
if (portal != null)
{
// delete custom resource files
Globals.DeleteFilesRecursive(serverPath, ".Portal-" + portal.PortalID + ".resx");
// If child portal delete child folder
var arr = PortalAliasController.Instance.GetPortalAliasesByPortalId(portal.PortalID).ToList();
if (arr.Count > 0)
{
var portalAliasInfo = arr[0];
string portalName = Globals.GetPortalDomainName(portalAliasInfo.HTTPAlias, null, true);
if (portalAliasInfo.HTTPAlias.IndexOf("/", StringComparison.Ordinal) > -1)
{
portalName = GetPortalFolder(portalAliasInfo.HTTPAlias);
}
if (!string.IsNullOrEmpty(portalName) && Directory.Exists(serverPath + portalName))
{
DeletePortalFolder(serverPath, portalName);
}
}
// delete upload directory
if (!string.IsNullOrEmpty(portal.HomeDirectory))
{
var homeDirectory = portal.HomeDirectoryMapPath;
// check whether home directory is not used by other portal
// it happens when new portal creation failed, but home directory defined by user is already in use with other portal
var homeDirectoryInUse = portals.OfType<PortalInfo>().Any(x =>
x.PortalID != portal.PortalID &&
x.HomeDirectoryMapPath.Equals(homeDirectory, StringComparison.OrdinalIgnoreCase));
if (!homeDirectoryInUse)
{
if (Directory.Exists(homeDirectory))
{
Globals.DeleteFolderRecursive(homeDirectory);
}
}
}
// remove database references
DeletePortalInternal(portal.PortalID);
}
}
else
{
message = Localization.GetString("LastPortal");
}
return message;
}
/// <summary>
/// Get the portal folder froma child portal alias.
/// </summary>
/// <param name="alias">portal alias.</param>
/// <returns>folder path of the child portal.</returns>
public static string GetPortalFolder(string alias)
{
alias = alias.ToLowerInvariant().Replace("http://", string.Empty).Replace("https://", string.Empty);
var appPath = Globals.ApplicationPath + "/";
if (string.IsNullOrEmpty(Globals.ApplicationPath) || alias.IndexOf(appPath, StringComparison.InvariantCultureIgnoreCase) == Null.NullInteger)
{
return alias.Contains("/") ? alias.Substring(alias.IndexOf("/", StringComparison.InvariantCultureIgnoreCase) + 1) : string.Empty;
}
return alias.Substring(alias.IndexOf(appPath, StringComparison.InvariantCultureIgnoreCase) + appPath.Length);
}
/// <summary>Delete the child portal folder and try to remove its parent when parent folder is empty.</summary>
/// <param name="serverPath">the server path.</param>
/// <param name="portalFolder">the child folder path.</param>
public static void DeletePortalFolder(string serverPath, string portalFolder)
{
var physicalPath = serverPath + portalFolder;
Globals.DeleteFolderRecursive(physicalPath);
// remove parent folder if its empty.
var parentFolder = Directory.GetParent(physicalPath);
while (parentFolder != null && !parentFolder.FullName.Equals(serverPath.TrimEnd('\\'), StringComparison.InvariantCultureIgnoreCase))
{
if (parentFolder.GetDirectories().Length + parentFolder.GetFiles().Length == 0)
{
parentFolder.Delete();
parentFolder = parentFolder.Parent;
}
else
{
break;
}
}
}
/// <summary>
/// Gets the portal dictionary.
/// </summary>
/// <returns>portal dictionary. the dictionary's Key -> Value is: TabId -> PortalId.</returns>
public static Dictionary<int, int> GetPortalDictionary()
{
string cacheKey = string.Format(DataCache.PortalDictionaryCacheKey);
return CBO.GetCachedObject<Dictionary<int, int>>(new CacheItemArgs(cacheKey, DataCache.PortalDictionaryTimeOut, DataCache.PortalDictionaryCachePriority), GetPortalDictionaryCallback);
}
/// -----------------------------------------------------------------------------
/// <summary>
/// GetPortalsByName gets all the portals whose name matches a provided filter expression.
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="nameToMatch">The email address to use to find a match.</param>
/// <param name="pageIndex">The page of records to return.</param>
/// <param name="pageSize">The size of the page.</param>
/// <param name="totalRecords">The total no of records that satisfy the criteria.</param>
/// <returns>An ArrayList of PortalInfo objects.</returns>
/// -----------------------------------------------------------------------------
public static ArrayList GetPortalsByName(string nameToMatch, int pageIndex, int pageSize, ref int totalRecords)
{
if (pageIndex == -1)
{
pageIndex = 0;
pageSize = int.MaxValue;
}
Type type = typeof(PortalInfo);
return CBO.FillCollection(DataProvider.Instance().GetPortalsByName(nameToMatch, pageIndex, pageSize), ref type, ref totalRecords);
}
public static ArrayList GetPortalsByUser(int userId)
{
Type type = typeof(PortalInfo);
return CBO.FillCollection(DataProvider.Instance().GetPortalsByUser(userId), type);
}
public static int GetEffectivePortalId(int portalId)
{
if (portalId > Null.NullInteger && Globals.Status != Globals.UpgradeStatus.Upgrade)
{
var portal = Instance.GetPortal(portalId);
var portalGroup = (from p in PortalGroupController.Instance.GetPortalGroups()
where p.PortalGroupId == portal.PortalGroupID
select p)
.SingleOrDefault();
if (portalGroup != null)
{
portalId = portalGroup.MasterPortalId;
}
}
return portalId;
}
/// <summary>
/// Gets all expired portals.
/// </summary>
/// <returns>all expired portals as array list.</returns>
public static ArrayList GetExpiredPortals()
{
return CBO.FillCollection(DataProvider.Instance().GetExpiredPortals(), typeof(PortalInfo));
}
/// <summary>
/// Determines whether the portal is child portal.
/// </summary>
/// <param name="portal">The portal.</param>
/// <param name="serverPath">The server path.</param>
/// <returns>
/// <c>true</c> if the portal is child portal; otherwise, <c>false</c>.
/// </returns>
public static bool IsChildPortal(PortalInfo portal, string serverPath)
{
bool isChild = Null.NullBoolean;
var arr = PortalAliasController.Instance.GetPortalAliasesByPortalId(portal.PortalID).ToList();
if (arr.Count > 0)
{
PortalAliasInfo portalAlias = arr[0];
var portalName = Globals.GetPortalDomainName(portalAlias.HTTPAlias, null, true);
if (portalAlias.HTTPAlias.IndexOf("/") > -1)
{
portalName = GetPortalFolder(portalAlias.HTTPAlias);
}
if (!string.IsNullOrEmpty(portalName) && Directory.Exists(serverPath + portalName))
{
isChild = true;
}
}
return isChild;
}
public static bool IsMemberOfPortalGroup(int portalId)
{
var portal = Instance.GetPortal(portalId);
return portal != null && portal.PortalGroupID > Null.NullInteger;
}
/// <summary>
/// Deletes the portal setting (neutral and for all languages).
/// </summary>
/// <param name="portalID">The portal ID.</param>
/// <param name="settingName">Name of the setting.</param>
public static void DeletePortalSetting(int portalID, string settingName)
{
DeletePortalSetting(portalID, settingName, Null.NullString);
}
/// <summary>
/// Deletes the portal setting in this language.
/// </summary>
/// <param name="portalID">The portal ID.</param>
/// <param name="settingName">Name of the setting.</param>
/// <param name="cultureCode">The culture code.</param>
public static void DeletePortalSetting(int portalID, string settingName, string cultureCode)
{
DataProvider.Instance().DeletePortalSetting(portalID, settingName, cultureCode.ToLowerInvariant());
EventLogController.Instance.AddLog("SettingName", settingName + ((cultureCode == Null.NullString) ? string.Empty : " (" + cultureCode + ")"), GetCurrentPortalSettingsInternal(), UserController.Instance.GetCurrentUserInfo().UserID, EventLogController.EventLogType.PORTAL_SETTING_DELETED);
DataCache.ClearHostCache(true);
}
/// <summary>
/// Deletes all portal settings by portal id.
/// </summary>
/// <param name="portalID">The portal ID.</param>
public static void DeletePortalSettings(int portalID)
{
DeletePortalSettings(portalID, Null.NullString);
}
/// <summary>
/// Deletes all portal settings by portal id and for a given language (Null: all languages and neutral settings).
/// </summary>
/// <param name="portalID">The portal ID.</param>
public static void DeletePortalSettings(int portalID, string cultureCode)
{
DataProvider.Instance().DeletePortalSettings(portalID, cultureCode);
EventLogController.Instance.AddLog("PortalID", portalID.ToString() + ((cultureCode == Null.NullString) ? string.Empty : " (" + cultureCode + ")"), GetCurrentPortalSettingsInternal(), UserController.Instance.GetCurrentUserInfo().UserID, EventLogController.EventLogType.PORTAL_SETTING_DELETED);
DataCache.ClearHostCache(true);
}
/// <summary>
/// takes in a text value, decrypts it with a FIPS compliant algorithm and returns the value.
/// </summary>
/// <param name="settingName">the setting to read.</param>
/// <param name="passPhrase">the pass phrase used for encryption/decryption.</param>
/// <returns></returns>
public static string GetEncryptedString(string settingName, int portalID, string passPhrase)
{
Requires.NotNullOrEmpty("key", settingName);
Requires.NotNullOrEmpty("passPhrase", passPhrase);
var cipherText = GetPortalSetting(settingName, portalID, string.Empty);
return Security.FIPSCompliant.DecryptAES(cipherText, passPhrase, Host.Host.GUID);
}
/// <summary>
/// Gets the portal setting.
/// </summary>
/// <param name="settingName">Name of the setting.</param>
/// <param name="portalID">The portal ID.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns>Returns setting's value if portal contains the specific setting, otherwise return defaultValue.</returns>
public static string GetPortalSetting(string settingName, int portalID, string defaultValue)
{
var retValue = Null.NullString;
try
{
string setting;
Instance.GetPortalSettings(portalID).TryGetValue(settingName, out setting);
retValue = string.IsNullOrEmpty(setting) ? defaultValue : setting;
}
catch (Exception exc)
{
Logger.Error(exc);
}
return retValue;
}
/// <summary>
/// Gets the portal setting for a specific language (or neutral).
/// </summary>
/// <param name="settingName">Name of the setting.</param>
/// <param name="portalID">The portal ID.</param>
/// <param name="defaultValue">The default value.</param>
/// <param name="cultureCode">culture code of the language to retrieve (not empty).</param>
/// <returns>Returns setting's value if portal contains the specific setting in specified language or neutral, otherwise return defaultValue.</returns>
public static string GetPortalSetting(string settingName, int portalID, string defaultValue, string cultureCode)
{
var retValue = Null.NullString;
try
{
string setting;
Instance.GetPortalSettings(portalID, cultureCode).TryGetValue(settingName, out setting);
retValue = string.IsNullOrEmpty(setting) ? defaultValue : setting;
}
catch (Exception exc)
{
Logger.Error(exc);
}
return retValue;
}
/// <summary>
/// Gets the portal setting as boolean.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="portalID">The portal ID.</param>
/// <param name="defaultValue">default value.</param>
/// <returns>Returns setting's value if portal contains the specific setting, otherwise return defaultValue.</returns>
public static bool GetPortalSettingAsBoolean(string key, int portalID, bool defaultValue)
{
bool retValue = Null.NullBoolean;
try
{
string setting;
Instance.GetPortalSettings(portalID).TryGetValue(key, out setting);
if (string.IsNullOrEmpty(setting))
{
retValue = defaultValue;
}
else
{
retValue = setting.StartsWith("Y", StringComparison.InvariantCultureIgnoreCase) || setting.Equals("TRUE", StringComparison.InvariantCultureIgnoreCase);
}
}
catch (Exception exc)
{
Logger.Error(exc);
}
return retValue;
}
/// <summary>
/// Gets the portal setting as boolean for a specific language (or neutral).
/// </summary>
/// <param name="key">The key.</param>
/// <param name="portalID">The portal ID.</param>
/// <param name="defaultValue">default value.</param>
/// <param name="cultureCode">culture code of the language to retrieve (not empty).</param>
/// <returns>Returns setting's value if portal contains the specific setting in specified language or neutral, otherwise return defaultValue.</returns>
public static bool GetPortalSettingAsBoolean(string key, int portalID, bool defaultValue, string cultureCode)
{
bool retValue = Null.NullBoolean;
try
{
string setting;
GetPortalSettingsDictionary(portalID, cultureCode).TryGetValue(key, out setting);
if (string.IsNullOrEmpty(setting))
{
retValue = defaultValue;
}
else
{
retValue = setting.StartsWith("Y", StringComparison.InvariantCultureIgnoreCase) || setting.Equals("TRUE", StringComparison.InvariantCultureIgnoreCase);
}
}
catch (Exception exc)
{
Logger.Error(exc);
}
return retValue;
}
/// <summary>
/// Gets the portal setting as integer.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="portalID">The portal ID.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns>Returns setting's value if portal contains the specific setting, otherwise return defaultValue.</returns>
public static int GetPortalSettingAsInteger(string key, int portalID, int defaultValue)
{
int retValue = Null.NullInteger;
try
{
string setting;
Instance.GetPortalSettings(portalID).TryGetValue(key, out setting);
if (string.IsNullOrEmpty(setting))
{
retValue = defaultValue;
}
else
{
retValue = Convert.ToInt32(setting);
}
}
catch (Exception exc)
{
Logger.Error(exc);
}
return retValue;
}
/// <summary>
/// Gets the portal setting as double.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="portalId">The portal Id.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns>Returns setting's value if portal contains the specific setting, otherwise return defaultValue.</returns>
public static double GetPortalSettingAsDouble(string key, int portalId, double defaultValue)
{
double retValue = Null.NullDouble;
try
{
string setting;
Instance.GetPortalSettings(portalId).TryGetValue(key, out setting);
if (string.IsNullOrEmpty(setting))
{
retValue = defaultValue;
}
else
{
retValue = Convert.ToDouble(setting);
}
}
catch (Exception exc)
{
Logger.Error(exc);
}
return retValue;
}
/// <summary>
/// Gets the portal setting as integer for a specific language (or neutral).
/// </summary>
/// <param name="key">The key.</param>
/// <param name="portalID">The portal ID.</param>
/// <param name="defaultValue">The default value.</param>
/// <param name="cultureCode">culture code of the language to retrieve (not empty).</param>
/// <returns>Returns setting's value if portal contains the specific setting (for specified lang, otherwise return defaultValue.</returns>
public static int GetPortalSettingAsInteger(string key, int portalID, int defaultValue, string cultureCode)
{
int retValue = Null.NullInteger;
try
{
string setting;
GetPortalSettingsDictionary(portalID, cultureCode).TryGetValue(key, out setting);
if (string.IsNullOrEmpty(setting))
{
retValue = defaultValue;
}
else
{
retValue = Convert.ToInt32(setting);
}
}
catch (Exception exc)
{
Logger.Error(exc);
}
return retValue;
}
/// <summary>
/// takes in a text value, encrypts it with a FIPS compliant algorithm and stores.
/// </summary>
/// <param name="portalID">The portal ID.</param>
/// <param name="settingName">host settings key.</param>
/// <param name="settingValue">host settings value.</param>
/// <param name="passPhrase">pass phrase to allow encryption/decryption.</param>
public static void UpdateEncryptedString(int portalID, string settingName, string settingValue, string passPhrase)
{
Requires.NotNullOrEmpty("key", settingName);
Requires.PropertyNotNull("value", settingValue);
Requires.NotNullOrEmpty("passPhrase", passPhrase);
var cipherText = Security.FIPSCompliant.EncryptAES(settingValue, passPhrase, Host.Host.GUID);
UpdatePortalSetting(portalID, settingName, cipherText);
}
/// <summary>
/// Updates a single neutral (not language specific) portal setting and clears it from the cache.
/// </summary>
/// <param name="portalID">The portal ID.</param>
/// <param name="settingName">Name of the setting.</param>
/// <param name="settingValue">The setting value.</param>
public static void UpdatePortalSetting(int portalID, string settingName, string settingValue)
{
UpdatePortalSetting(portalID, settingName, settingValue, true);
}
/// <summary>
/// Updates a single neutral (not language specific) portal setting, optionally without clearing the cache.
/// </summary>
/// <param name="portalID">The portal ID.</param>
/// <param name="settingName">Name of the setting.</param>
/// <param name="settingValue">The setting value.</param>
/// <param name="clearCache">if set to <c>true</c> [clear cache].</param>
public static void UpdatePortalSetting(int portalID, string settingName, string settingValue, bool clearCache)
{
UpdatePortalSetting(portalID, settingName, settingValue, clearCache, Null.NullString, false);
}
/// <summary>
/// Updates a language specific or neutral portal setting and clears it from the cache.
/// </summary>
/// <param name="portalID">The portal ID.</param>
/// <param name="settingName">Name of the setting.</param>
/// <param name="settingValue">The setting value.</param>
/// <param name="cultureCode">culture code for language specific settings, null string ontherwise.</param>
[Obsolete("Deprecated in DNN 9.2.0. Use the overloaded one with the 'isSecure' parameter instead. Scheduled removal in v11.0.0.")]
public static void UpdatePortalSetting(int portalID, string settingName, string settingValue, string cultureCode)
{
UpdatePortalSetting(portalID, settingName, settingValue, true, cultureCode, false);
}
/// <summary>
/// Updates a language specific or neutral portal setting and optionally clears it from the cache.
/// </summary>
/// <param name="portalID">The portal ID.</param>
/// <param name="settingName">Name of the setting.</param>
/// <param name="settingValue">The setting value.</param>
/// <param name="clearCache">if set to <c>true</c> [clear cache].</param>
/// <param name="cultureCode">culture code for language specific settings, null string ontherwise.</param>
public static void UpdatePortalSetting(int portalID, string settingName, string settingValue, bool clearCache, string cultureCode)
{
UpdatePortalSetting(portalID, settingName, settingValue, clearCache, cultureCode, false);
}
/// <summary>
/// Updates a language specific or neutral portal setting and optionally clears it from the cache.
/// All overloaded methors will not encrypt the setting value. Therefore, call this method whenever
/// there is a need to encrypt the setting value before storing it in the datanbase.
/// </summary>
/// <param name="portalID">The portal ID.</param>
/// <param name="settingName">Name of the setting.</param>
/// <param name="settingValue">The setting value.</param>
/// <param name="clearCache">if set to <c>true</c> [clear cache].</param>
/// <param name="cultureCode">culture code for language specific settings, null string ontherwise.</param>
/// <param name="isSecure">When true it encrypt the value before storing it in the database.</param>
public static void UpdatePortalSetting(int portalID, string settingName, string settingValue, bool clearCache, string cultureCode, bool isSecure)
{
Instance.UpdatePortalSetting(portalID, settingName, settingValue, clearCache, cultureCode, isSecure);
}
/// <summary>
/// Checks the desktop modules whether is installed.
/// </summary>
/// <param name="nav">The nav.</param>
/// <returns>Empty string if the module hasn't been installed, otherwise return the friendly name.</returns>
public static string CheckDesktopModulesInstalled(XPathNavigator nav)
{
string friendlyName;
DesktopModuleInfo desktopModule;
StringBuilder modulesNotInstalled = new StringBuilder();
foreach (XPathNavigator desktopModuleNav in nav.Select("portalDesktopModule"))
{
friendlyName = XmlUtils.GetNodeValue(desktopModuleNav, "friendlyname");
if (!string.IsNullOrEmpty(friendlyName))
{
desktopModule = DesktopModuleController.GetDesktopModuleByFriendlyName(friendlyName);
if (desktopModule == null)
{
// PE and EE templates have HTML as friendly name so check to make sure
// there is really no HTML module installed
if (friendlyName == "HTML")
{
desktopModule = DesktopModuleController.GetDesktopModuleByFriendlyName("HTML Pro");
if (desktopModule == null)
{
modulesNotInstalled.Append(friendlyName);
modulesNotInstalled.Append("<br/>");
}
}
else
{
modulesNotInstalled.Append(friendlyName);
modulesNotInstalled.Append("<br/>");
}
}
}
}
return modulesNotInstalled.ToString();
}
/// <summary>
/// function provides the language for portalinfo requests
/// in case where language has not been installed yet, will return the core install default of en-us.
/// </summary>
/// <param name = "portalID"></param>
/// <returns></returns>
/// <remarks>
/// </remarks>
public static string GetActivePortalLanguage(int portalID)
{
// get Language
string Language = Localization.SystemLocale;
string tmpLanguage = GetPortalDefaultLanguage(portalID);
var isDefaultLanguage = false;
if (!string.IsNullOrEmpty(tmpLanguage))
{
Language = tmpLanguage;
isDefaultLanguage = true;
}
// handles case where portalcontroller methods invoked before a language is installed
if (portalID > Null.NullInteger && Globals.Status == Globals.UpgradeStatus.None && Localization.ActiveLanguagesByPortalID(portalID) == 1)
{
return Language;
}
if (HttpContext.Current != null && Globals.Status == Globals.UpgradeStatus.None)
{
if (HttpContext.Current.Request.QueryString["language"] != null)
{
Language = HttpContext.Current.Request.QueryString["language"];
}
else
{
PortalSettings _PortalSettings = GetCurrentPortalSettingsInternal();
if (_PortalSettings != null && _PortalSettings.ActiveTab != null && !string.IsNullOrEmpty(_PortalSettings.ActiveTab.CultureCode))
{
Language = _PortalSettings.ActiveTab.CultureCode;
}
else
{
// PortalSettings IS Nothing - probably means we haven't set it yet (in Begin Request)
// so try detecting the user's cookie
if (HttpContext.Current.Request["language"] != null)
{
Language = HttpContext.Current.Request["language"];
isDefaultLanguage = false;
}
// if no cookie - try detecting browser
if ((string.IsNullOrEmpty(Language) || isDefaultLanguage) && EnableBrowserLanguageInDefault(portalID))
{
CultureInfo Culture = Localization.GetBrowserCulture(portalID);
if (Culture != null)
{
Language = Culture.Name;
}
}
}
}
}
return Language;
}
/// <summary>
/// return the current DefaultLanguage value from the Portals table for the requested Portalid.
/// </summary>
/// <param name = "portalID"></param>
/// <returns></returns>
/// <remarks>
/// </remarks>
public static string GetPortalDefaultLanguage(int portalID)
{
string cacheKey = string.Format("PortalDefaultLanguage_{0}", portalID);
return CBO.GetCachedObject<string>(new CacheItemArgs(cacheKey, DataCache.PortalCacheTimeOut, DataCache.PortalCachePriority, portalID), GetPortalDefaultLanguageCallBack);
}
/// <summary>
/// set the required DefaultLanguage in the Portals table for a particular portal
/// saves having to update an entire PortalInfo object.
/// </summary>
/// <param name = "portalID"></param>
/// <param name = "CultureCode"></param>
/// <remarks>
/// </remarks>
public static void UpdatePortalDefaultLanguage(int portalID, string CultureCode)
{
DataProvider.Instance().UpdatePortalDefaultLanguage(portalID, CultureCode);
// ensure localization record exists as new portal default language may be relying on fallback chain
// of which it is now the final part
DataProvider.Instance().EnsureLocalizationExists(portalID, CultureCode);
}
public static void IncrementCrmVersion(int portalID)
{
int currentVersion;
var versionSetting = GetPortalSetting(ClientResourceSettings.VersionKey, portalID, "1");
if (int.TryParse(versionSetting, out currentVersion))
{
var newVersion = currentVersion + 1;
UpdatePortalSetting(portalID, ClientResourceSettings.VersionKey, newVersion.ToString(CultureInfo.InvariantCulture), true);
}
}
public static void IncrementOverridingPortalsCrmVersion()
{
foreach (PortalInfo portal in Instance.GetPortals())
{
string setting = GetPortalSetting(ClientResourceSettings.OverrideDefaultSettingsKey, portal.PortalID, "False");
bool overriden;
// if this portal is overriding the host level...
if (bool.TryParse(setting, out overriden) && overriden)
{
// increment its version
IncrementCrmVersion(portal.PortalID);
}
}
}
/// <summary>
/// Creates a new portal alias.
/// </summary>
/// <param name="portalId">Id of the portal.</param>
/// <param name="portalAlias">Portal Alias to be created.</param>
public void AddPortalAlias(int portalId, string portalAlias)
{
// Check if the Alias exists
PortalAliasInfo portalAliasInfo = PortalAliasController.Instance.GetPortalAlias(portalAlias, portalId);
// If alias does not exist add new
if (portalAliasInfo == null)
{
portalAliasInfo = new PortalAliasInfo { PortalID = portalId, HTTPAlias = portalAlias, IsPrimary = true };
PortalAliasController.Instance.AddPortalAlias(portalAliasInfo);
}
}
/// <summary>
/// Copies the page template.
/// </summary>
/// <param name="templateFile">The template file.</param>
/// <param name="mappedHomeDirectory">The mapped home directory.</param>
public void CopyPageTemplate(string templateFile, string mappedHomeDirectory)
{
string hostTemplateFile = string.Format("{0}Templates\\{1}", Globals.HostMapPath, templateFile);
if (File.Exists(hostTemplateFile))
{
string portalTemplateFolder = string.Format("{0}Templates\\", mappedHomeDirectory);
if (!Directory.Exists(portalTemplateFolder))
{
// Create Portal Templates folder
Directory.CreateDirectory(portalTemplateFolder);
}
string portalTemplateFile = portalTemplateFolder + templateFile;
if (!File.Exists(portalTemplateFile))
{
File.Copy(hostTemplateFile, portalTemplateFile);
}
}
}
/// <summary>
/// Creates the portal.
/// </summary>
/// <param name="portalName">Name of the portal.</param>
/// <param name="adminUserId">The obj admin user.</param>
/// <param name="description">The description.</param>
/// <param name="keyWords">The key words.</param>
/// <param name="template"> </param>
/// <param name="homeDirectory">The home directory.</param>
/// <param name="portalAlias">The portal alias.</param>
/// <param name="serverPath">The server path.</param>
/// <param name="childPath">The child path.</param>
/// <param name="isChildPortal">if set to <c>true</c> means the portal is child portal.</param>
/// <returns>Portal id.</returns>
public int CreatePortal(string portalName, int adminUserId, string description, string keyWords, PortalTemplateInfo template,
string homeDirectory, string portalAlias, string serverPath, string childPath, bool isChildPortal)
{
// Attempt to create a new portal
int portalId = CreatePortal(portalName, homeDirectory, template.CultureCode);
// Log the portal if into http context, if exception occurred in next step, we can remove the portal which is not really created.
if (HttpContext.Current != null)
{
HttpContext.Current.Items.Add("CreatingPortalId", portalId);
}
string message = Null.NullString;
if (portalId != -1)
{
// add administrator
int administratorId = adminUserId;
var adminUser = new UserInfo();
// add userportal record
UserController.AddUserPortal(portalId, administratorId);
// retrieve existing administrator
try
{
adminUser = UserController.GetUserById(portalId, administratorId);
}
catch (Exception Exc)
{
Logger.Error(Exc);
}
if (administratorId > 0)
{
this.CreatePortalInternal(portalId, portalName, adminUser, description, keyWords, template, homeDirectory, portalAlias, serverPath, childPath, isChildPortal, ref message);
}
}
else
{
message += Localization.GetString("CreatePortal.Error");
throw new Exception(message);
}
try
{
EnsureRequiredEventLogTypesExist();
}
catch (Exception)
{
// should be no exception, but suppress just in case
}
// remove the portal id from http context as there is no exception.
if (HttpContext.Current != null && HttpContext.Current.Items.Contains("CreatingPortalId"))
{
HttpContext.Current.Items.Remove("CreatingPortalId");
}
return portalId;
}
/// <summary>
/// Creates the portal.
/// </summary>
/// <param name="portalName">Name of the portal.</param>
/// <param name="adminUser">The obj admin user.</param>
/// <param name="description">The description.</param>
/// <param name="keyWords">The key words.</param>
/// <param name="template"> </param>
/// <param name="homeDirectory">The home directory.</param>
/// <param name="portalAlias">The portal alias.</param>
/// <param name="serverPath">The server path.</param>
/// <param name="childPath">The child path.</param>
/// <param name="isChildPortal">if set to <c>true</c> means the portal is child portal.</param>
/// <returns>Portal id.</returns>
public int CreatePortal(string portalName, UserInfo adminUser, string description, string keyWords, PortalTemplateInfo template,
string homeDirectory, string portalAlias, string serverPath, string childPath, bool isChildPortal)