-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSite.Master
221 lines (197 loc) · 10.4 KB
/
Site.Master
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
<!--
Active Directory-integrated Android Management
Copyright (C) 2022 Manuel Meitinger
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<%@ Master Language="C#" ClassName="Aufbauwerk.Tools.Emm.Master" %>
<%@ Reference Control="~/Controls/Devices.ascx" %>
<%@ Reference Control="~/Controls/Enrollment.ascx" %>
<%@ Reference Control="~/Controls/IFrame.ascx" %>
<%@ Reference Control="~/Controls/Policy.ascx" %>
<%@ Reference Control="~/Controls/Sync.ascx" %>
<%@ Reference Control="~/Controls/Welcome.ascx" %>
<script runat="server">
#nullable enable
private enum Arg
{
Name = 0x1000 | Tab.Policy,
User = 0x1000 | Tab.Enroll,
Feature = 0x1000 | Tab.IFrame,
}
private enum Tab
{
Invalid = 0x01,
Personal = 0x100,
Administrative = 0x200,
MyEnroll = Personal | 0x01,
MyDevices = Personal | 0x02,
Enroll = Administrative | 0x01,
Devices = Administrative | 0x02,
IFrame = Administrative | 0x04,
Policy = Administrative | 0x08,
Sync = Administrative | 0x10,
}
private Tab? _currentTab = null;
private Tab CurrentTab => _currentTab ?? throw new InvalidOperationException("No tab available.");
private void EnsureValidArg(Tab tab, Arg arg) { if (((int)arg & (int)tab) != (int)tab) { throw new ArgumentException($"Argument {arg} does not apply to tab {tab}."); } }
private T GetArg<T>(Arg arg, Func<string?, T> convert)
{
EnsureValidArg(CurrentTab, arg);
var value = Request.QueryString[arg.ToString().ToLowerInvariant()];
return convert(string.IsNullOrEmpty(value) ? null : value);
}
private string GetArg(Arg arg) => GetArg(arg, value => value ?? throw new HttpException((int)System.Net.HttpStatusCode.BadRequest, $"Argument '{arg}' is missing."));
private StringBuilder HrefFromTab(Tab tab) => new StringBuilder("?tab=").Append(tab.ToString().ToLowerInvariant());
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// parse the current tab
var tabString = Request.QueryString["tab"];
var tab = string.IsNullOrEmpty(tabString) ? 0 : Enum.TryParse<Tab>(tabString, ignoreCase: true, out var tabParsed) ? tabParsed : Tab.Invalid;
_currentTab = tab;
// ensure the logged-on principal has the necessary rights
var enterprise = Enterprise.Current;
if (!enterprise.IsUser && !enterprise.IsAdmin || (tab & Tab.Personal) != 0 && !enterprise.IsUser || (tab & Tab.Administrative) != 0 && !enterprise.IsAdmin) { throw new HttpException((int)System.Net.HttpStatusCode.Forbidden, $"Principal {Helpers.CurrentUser.Name} has insufficient privileges."); }
// add the matching tab
Content.Controls.Add(tab switch
{
Tab.MyDevices => new Controls.Devices() { ShowAllDevices = false },
Tab.MyEnroll => new Controls.Enrollment() { User = Helpers.CurrentUser, AllowPolicySelection = false },
Tab.Devices => new Controls.Devices() { ShowAllDevices = true },
Tab.Enroll => new Controls.Enrollment()
{
User = GetArg(Arg.User, user => user is null ? null : Helpers.FindUserBySid(new(user)) ?? throw new ArgumentException($"User {user} not found.")),
AllowPolicySelection = true
},
Tab.IFrame => new Controls.IFrame() { Feature = GetArg(Arg.Feature) },
Tab.Policy => new Controls.Policy() { PolicyName = GetArg(Arg.Name) },
Tab.Sync => new Controls.Sync(),
0 => new Controls.Welcome() { EnrollHref = enterprise.IsUser ? HrefFromTab(Tab.MyEnroll).ToString() : null },
_ => throw new HttpException((int)System.Net.HttpStatusCode.NotFound, $"Tab '{tabString}' not found."),
});
}
protected override void OnUnload(EventArgs e)
{
base.OnUnload(e);
_currentTab = null;
}
private void WriteMenuItem(Tab tab, string text, params (Arg, string)[] args)
{
// build the href for the item while checking for being the active link
var isActive = CurrentTab == tab;
var href = HrefFromTab(tab);
foreach (var (arg, value) in args)
{
EnsureValidArg(tab, arg);
var name = arg.ToString().ToLowerInvariant();
if (isActive && Request.QueryString[name] != value) { isActive = false; }
href.Append("&").Append(name).Append("=").Append(Uri.EscapeDataString(value));
}
Response.Write(System.FormattableString.Invariant($"<li class=\"{(isActive ? "uk-active" : "")}\"><a href=\"{HttpUtility.HtmlAttributeEncode(href.ToString())}\">{HttpUtility.HtmlEncode(text)}</a></li>"));
}
</script>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title><%: Enterprise.Current.DisplayName %></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="<%= HttpUtility.HtmlAttributeEncode(ResolveUrl("~/static/css/uikit.min.css")) %>" />
<script src="<%= HttpUtility.HtmlAttributeEncode(ResolveUrl("~/static/js/uikit.min.js")) %>"></script>
</head>
<body>
<form runat="server">
<asp:ScriptManager runat="server" />
<div uk-sticky="sel-target: .uk-navbar-container; cls-active: uk-navbar-sticky">
<nav class="uk-navbar-container" uk-navbar="" style="background-color: <%= Enterprise.Current.Color %>">
<div class="uk-navbar-left">
<div class="uk-navbar-left">
<a class="uk-navbar-item uk-logo" href="<%= HttpUtility.HtmlAttributeEncode(Request.Path) %>"><%: Enterprise.Current.DisplayName %></a>
</div>
<div class="uk-navbar-center">
<%
if (Enterprise.Current.IsUser)
{
%>
<ul class="uk-navbar-nav">
<li class="<%= (CurrentTab & Tab.Personal) != 0 ? "uk-active" : "" %>">
<a href="#"><%: Helpers.CurrentUser.GetDisplayName() %></a>
<div class="uk-navbar-dropdown">
<ul class="uk-nav uk-navbar-dropdown-nav">
<% WriteMenuItem(Tab.MyDevices, "List Devices"); %>
<% WriteMenuItem(Tab.MyEnroll, "Enroll New Device"); %>
</ul>
</div>
</li>
</ul>
<%
}
if (Enterprise.Current.IsUser && Enterprise.Current.IsAdmin)
{
%>
<span class="uk-navbar-item">|</span>
<%
}
if (Enterprise.Current.IsAdmin)
{
%>
<ul class="uk-navbar-nav">
<li class="<%= CurrentTab == Tab.Policy ? "uk-active" : "" %>">
<a href="#">Policies</a>
<div class="uk-navbar-dropdown">
<ul class="uk-nav uk-navbar-dropdown-nav">
<%
foreach (var policy in Enterprise.Current.Policies)
{
WriteMenuItem(Tab.Policy, $"{policy} (v{Enterprise.Current.FindPolicy(policy)?.Version ?? 0})", (Arg.Name, policy));
}
%>
</ul>
</div>
</li>
<% WriteMenuItem(Tab.Devices, "Devices"); %>
<% WriteMenuItem(Tab.Enroll, "Enroll"); %>
<li class="<%= CurrentTab == Tab.IFrame ? "uk-active" : "" %>">
<a href="#">Apps</a>
<div class="uk-navbar-dropdown">
<ul class="uk-nav uk-navbar-dropdown-nav">
<% WriteMenuItem(Tab.IFrame, "Find in Play Store", (Arg.Feature, "PLAY_SEARCH")); %>
<li class="uk-nav-divider"></li>
<% WriteMenuItem(Tab.IFrame, "Manage Web Apps", (Arg.Feature, "WEB_APPS")); %>
<% WriteMenuItem(Tab.IFrame, "Manage Private Apps", (Arg.Feature, "PRIVATE_APPS")); %>
<li class="uk-nav-divider"></li>
<% WriteMenuItem(Tab.IFrame, "Organize Apps", (Arg.Feature, "STORE_BUILDER")); %>
</ul>
</div>
</li>
<% WriteMenuItem(Tab.Sync, "Sync"); %>
</ul>
<%
}
%>
</div>
</div>
</nav>
</div>
<asp:PlaceHolder runat="server" ID="Content" />
<asp:UpdateProgress runat="server" DisplayAfter="500">
<ProgressTemplate>
<div class="uk-flex-top uk-modal uk-flex uk-open" uk-modal="" tabindex="-1">
<div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical uk-width-auto uk-border-circle uk-box-shadow-xlarge">
<div uk-spinner="ratio: 2"></div>
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
</html>