This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
UploadSkin.ascx.vb
200 lines (158 loc) · 8.43 KB
/
UploadSkin.ascx.vb
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
Imports System
Imports System.Configuration
Imports System.Data
Imports System.IO
Imports ICSharpCode.SharpZipLib.Zip
Imports System.Xml
Imports System.Text.RegularExpressions
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Services.Localization
Imports DotNetNuke
Imports DotNetNuke.UI.Skins
Imports DotNetNuke.Entities.Host
Namespace DNNStuff.Aggregator
Partial Class UploadSkin
Inherits DotNetNuke.Entities.Modules.PortalModuleBase
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DNNUtilities.InjectCSS(Me.Page, ResolveUrl("Resources/Support/edit.css"))
Page.ClientScript.RegisterClientScriptInclude(Me.GetType, "yeti", ResolveUrl("resources/support/yetii-min.js"))
End Sub
#End Region
#Region " Navigation"
Private Sub cmdReturn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdReturn.Click, cmdReturn2.Click
Response.Redirect(NavigateBack())
End Sub
Private Function NavigateBack() As String
Return DotNetNuke.Common.NavigateURL(TabId)
End Function
#End Region
#Region " Upload"
Private Sub cmdAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
Try
Dim strFileName As String
Dim strExtension As String = ""
Dim strMessage As String = ""
Dim postedFile As HttpPostedFile = cmdBrowse.PostedFile
'Get localized Strings
Dim strInvalid As String = DotNetNuke.Services.Localization.Localization.GetString("InvalidExt", Me.LocalResourceFile)
strFileName = System.IO.Path.GetFileName(postedFile.FileName)
strExtension = Path.GetExtension(strFileName)
If postedFile.FileName <> "" Then
If strExtension.ToLower = ".zip" Then
Dim objLbl As New Label
objLbl.CssClass = "Normal"
objLbl.Text = UploadSkin(MapPath("Skins"), postedFile.InputStream)
phPaLogs.Controls.Add(objLbl)
Else
strMessage += strInvalid & " skin file " & strFileName
End If
Else
strMessage = DotNetNuke.Services.Localization.Localization.GetString("NoFile", Me.LocalResourceFile)
End If
If phPaLogs.Controls.Count > 0 Then
tblLogs.Visible = True
ElseIf strMessage = "" Then
Response.Redirect(NavigateBack())
Else
lblMessage.Text = strMessage
End If
Catch exc As Exception 'Module failed to load
DotNetNuke.Services.Exceptions.ProcessModuleLoadException(Me, exc)
End Try
End Sub
Public Shared Function UploadSkin(ByVal RootPath As String, ByVal objInputStream As Stream) As String
Dim objZipInputStream As New ZipInputStream(objInputStream)
Dim objZipEntry As ZipEntry
Dim strExtension As String
Dim strFileName As String
Dim objFileStream As FileStream
Dim intSize As Integer = 2048
Dim arrData(2048) As Byte
Dim strMessage As String = ""
Dim arrSkinFiles As New ArrayList
'Localized Strings
Dim ResourcePortalSettings As PortalSettings = DotNetNuke.Common.Globals.GetPortalSettings()
Dim BEGIN_MESSAGE As String = Localization.GetString("BeginZip", ResourcePortalSettings)
Dim CREATE_DIR As String = Localization.GetString("CreateDir", ResourcePortalSettings)
Dim WRITE_FILE As String = Localization.GetString("WriteFile", ResourcePortalSettings)
Dim FILE_ERROR As String = Localization.GetString("FileError", ResourcePortalSettings)
Dim END_MESSAGE As String = Localization.GetString("EndZip", ResourcePortalSettings)
Dim FILE_RESTICTED As String = Localization.GetString("FileRestricted", ResourcePortalSettings)
strMessage += FormatMessage(BEGIN_MESSAGE, "", -1, False)
objZipEntry = objZipInputStream.GetNextEntry
While Not objZipEntry Is Nothing
If Not objZipEntry.IsDirectory Then
' validate file extension
strExtension = objZipEntry.Name.Substring(objZipEntry.Name.LastIndexOf(".") + 1)
If Compatibility.IsAllowedExtension(strExtension) Then
' process embedded zip files
Select Case objZipEntry.Name.ToLower
Case Else
strFileName = RootPath & "\" & objZipEntry.Name
' create the directory if it does not exist
If Not Directory.Exists(Path.GetDirectoryName(strFileName)) Then
strMessage += FormatMessage(CREATE_DIR, Path.GetDirectoryName(strFileName), 2, False)
Directory.CreateDirectory(Path.GetDirectoryName(strFileName))
End If
' remove the old file
If File.Exists(strFileName) Then
File.SetAttributes(strFileName, FileAttributes.Normal)
File.Delete(strFileName)
End If
' create the new file
objFileStream = File.Create(strFileName)
' unzip the file
strMessage += FormatMessage(WRITE_FILE, Path.GetFileName(strFileName), 2, False)
intSize = objZipInputStream.Read(arrData, 0, arrData.Length)
While intSize > 0
objFileStream.Write(arrData, 0, intSize)
intSize = objZipInputStream.Read(arrData, 0, arrData.Length)
End While
objFileStream.Close()
' save the skin file
Select Case Path.GetExtension(strFileName)
Case ".htm", ".html", ".ascx", ".css", ".txt"
If strFileName.ToLower.IndexOf(DotNetNuke.Common.glbAboutPage.ToLower) < 0 Then
arrSkinFiles.Add(strFileName)
End If
End Select
End Select
Else
strMessage += FormatMessage(FILE_ERROR, String.Format(FILE_RESTICTED, objZipEntry.Name, Compatibility.AllowedExtensions), 2, True)
End If
End If
objZipEntry = objZipInputStream.GetNextEntry
End While
strMessage += FormatMessage(END_MESSAGE, "", 1, False)
objZipInputStream.Close()
Return strMessage
End Function
Public Shared Function FormatMessage(ByVal Title As String, ByVal Body As String, ByVal Level As Integer, ByVal IsError As Boolean) As String
Dim Message As String = Title
If IsError Then
Message = "<font class=""NormalRed"">" & Title & "</font>"
End If
Select Case Level
Case -1
Message = "<hr><br><b>" & Message & "</b>"
Case 0
Message = "<br><br><b>" & Message & "</b>"
Case 1
Message = "<br><b>" & Message & "</b>"
Case Else
Message = "<br><li>" & Message
End Select
Return Message & ": " & Body & vbCrLf
End Function
#End Region
End Class
End Namespace