This repository has been archived by the owner on Dec 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathEditHost.aspx.cs
executable file
·228 lines (199 loc) · 8.25 KB
/
EditHost.aspx.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
/*
* EditHost.aspx.cs
*
* Authors:
* Rolf Bjarne Kvinge ([email protected])
*
* Copyright 2009 Novell, Inc. (http://www.novell.com)
*
* See the LICENSE file included with the distribution for details.
*
*/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MonkeyWrench.DataClasses;
using MonkeyWrench.DataClasses.Logic;
using MonkeyWrench.Web.WebServices;
public partial class EditHost : System.Web.UI.Page
{
GetHostForEditResponse response;
private new Master Master
{
get { return base.Master as Master; }
}
private void RedirectToSelf ()
{
Response.Redirect ("EditHost.aspx?host_id=" + response.Host.id.ToString (), false);
}
protected override void OnInit (EventArgs e)
{
base.OnInit (e);
TableRow row;
string html;
string page;
List<string> current_lanes = new List<string> ();
List<DBLane> all_lanes;
string disable = Request ["disablelane"];
string enable = Request ["enablelane"];
string remove = Request ["removelane"];
string add = Request ["addlane"];
string action = Request ["action"];
int id;
bool redirect = false;
txtID.Attributes ["readonly"] = "readonly";
response = Utils.LocalWebService.GetHostForEdit (Master.WebServiceLogin, Utils.TryParseInt32 (Request ["host_id"]), Request ["host"]);
if (response == null || response.Host == null) {
Response.Redirect ("EditHosts.aspx", false);
return;
}
if (!IsPostBack) {
switch (action) {
case "editEnvironmentVariableValue":
if (int.TryParse (Request ["id"], out id)) {
foreach (DBEnvironmentVariable ev in response.Variables) {
if (ev.id == id) {
ev.value = Request ["value"];
Utils.LocalWebService.EditEnvironmentVariable (Master.WebServiceLogin, ev);
break;
}
}
}
redirect = true;
break;
}
if (!string.IsNullOrEmpty (disable) && int.TryParse (disable, out id)) {
Utils.LocalWebService.SwitchHostEnabledForLane (Master.WebServiceLogin, id, response.Host.id);
redirect = true;
}
if (!string.IsNullOrEmpty (enable) && int.TryParse (enable, out id)) {
Utils.LocalWebService.SwitchHostEnabledForLane (Master.WebServiceLogin, id, response.Host.id);
redirect = true;
}
if (!string.IsNullOrEmpty (remove) && int.TryParse (remove, out id)) {
Utils.LocalWebService.RemoveHostForLane (Master.WebServiceLogin, id, response.Host.id);
redirect = true;
}
if (!string.IsNullOrEmpty (add) && int.TryParse (add, out id)) {
Utils.LocalWebService.AddHostToLane (Master.WebServiceLogin, id, response.Host.id);
redirect = true;
}
if (redirect) {
RedirectToSelf ();
return;
}
txtID.Text = response.Host.id.ToString ();
txtArchitecture.Text = response.Host.architecture;
txtDescription.Text = response.Host.description;
txtHost.Text = response.Host.host;
chkEnabled.Checked = response.Host.enabled;
cmbQueueManagement.SelectedIndex = response.Host.queuemanagement;
if (response.Person == null) {
string valid_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMOPQRSUVWXYZ1234567890";
System.Text.StringBuilder builder = new System.Text.StringBuilder ();
Random random = new Random ();
for (int i = 0; i < 64; i++)
builder.Append ((char) valid_chars [random.Next (valid_chars.Length)]);
txtPassword.Text = builder.ToString ();
lblPasswordWarning.Text = "A password for the host has been generated, please hit Save to save it.";
} else {
txtPassword.Text = response.Person.password;
}
}
editorVariables.Host = response.Host;
editorVariables.Variables = response.Variables;
editorVariables.Master = Master;
foreach (DBHostLaneView view in response.HostLaneViews) {
string ed = view.enabled ? "enabled" : "disabled";
row = new TableRow ();
row.Cells.Add (Utils.CreateTableCell (string.Format ("<a href='EditLane.aspx?lane_id={0}'>{1}</a>", view.lane_id, view.lane), view.enabled ? "enabled" : "disabled"));
page = "EditHost.aspx?host_id=" + response.Host.id.ToString ();
html = "<a href='" + page + "&removelane=" + view.lane_id.ToString () + "'>Remove</a> ";
row.Cells.Add (Utils.CreateTableCell (html, ed));
html = "<a href='" + page + "&" + (view.enabled ? "disable" : "enable") + "lane=" + view.lane_id.ToString () + "'>" + (view.enabled ? "Disable" : "Enable") + "</a>";
row.Cells.Add (Utils.CreateTableCell (html, ed));
tblLanes.Rows.Add (row);
current_lanes.Add (view.lane);
}
all_lanes = response.Lanes;
if (all_lanes.Count != current_lanes.Count) {
row = new TableRow ();
html = "<select id='addhostlane'>";
foreach (DBLane lane in all_lanes) {
if (!current_lanes.Contains (lane.lane))
html += "<option value='" + lane.id + "'>" + lane.lane + "</option>";
}
html += "</select>";
row.Cells.Add (Utils.CreateTableCell (html));
row.Cells.Add (Utils.CreateTableCell ("<a href='javascript:addLane()'>Add</a>"));
row.Cells.Add (Utils.CreateTableCell ("-"));
tblLanes.Rows.Add (row);
}
foreach (DBHost host in response.Hosts) {
if (response.MasterHosts.Find (d => host.id == d.id) != null)
continue; // don't add master hosts already added
if (response.SlaveHosts.Find (d => host.id == d.id) != null)
continue; // don't add any slave hosts, circular references is never a good thing
cmbMasterHosts.Items.Add (new ListItem (host.host, host.id.ToString ()));
}
foreach (DBHost host in response.MasterHosts) {
tblMasters.Rows.AddAt (1, Utils.CreateTableRow (
string.Format ("<a href='EditHost.aspx?host_id={0}'>{1}</a>", host.id, host.host),
Utils.CreateLinkButton ("removeMasterHostLinkButton_" + host.id.ToString (), "Remove", "RemoveMasterHost", host.id.ToString (), OnLinkButtonCommand)));
}
foreach (DBHost host in response.SlaveHosts) {
tblSlaves.Rows.AddAt (1, Utils.CreateTableRow (
string.Format ("<a href='EditHost.aspx?host_id={0}'>{1}</a>", host.id, host.host),
Utils.CreateLinkButton ("removeSaveHostLinkButton_" + host.id.ToString (), "Remove", "RemoveSlaveHost", host.id.ToString (), OnLinkButtonCommand),
host.description));
}
string txt = string.Format (@"
<MonkeyWrench Version='2'>
<Configuration>
<WebServiceUrl>https://{0}/Wrench/WebServices/</WebServiceUrl>
<WebServicePassword>{1}</WebServicePassword>
<Host>{2}</Host>
<DataDirectory>[FULL PATH TO HOME DIRECTORY, NOT ~]/moonbuilder/data</DataDirectory>
<LockingAlgorithm>fileexistence</LockingAlgorithm>
</Configuration>
</MonkeyWrench>
", Request.Url.Host + (Request.Url.Port != 0 && Request.Url.Port != 80 ? ":" + Request.Url.Port.ToString () : ""), txtPassword.Text, txtHost.Text);
lblConfiguration.InnerHtml = "<pre>" + HttpUtility.HtmlEncode (txt) + "</pre>";
}
protected void OnLinkButtonCommand (object sender, CommandEventArgs e)
{
switch (e.CommandName) {
case "RemoveMasterHost":
Utils.LocalWebService.RemoveMasterHost (Master.WebServiceLogin, response.Host.id, int.Parse ((string) e.CommandArgument));
break;
case "AddMasterHost":
Utils.LocalWebService.AddMasterHost (Master.WebServiceLogin, response.Host.id, int.Parse (cmbMasterHosts.SelectedValue));
break;
case "RemoveSlaveHost":
Utils.LocalWebService.RemoveMasterHost (Master.WebServiceLogin, int.Parse ((string) e.CommandArgument), response.Host.id);
break;
}
RedirectToSelf ();
}
protected void cmdSave_Click (object sender, EventArgs e)
{
DBHost host = response.Host;
host.host = txtHost.Text;
host.architecture = txtArchitecture.Text;
host.description = txtDescription.Text;
host.queuemanagement = cmbQueueManagement.SelectedIndex;
host.enabled = chkEnabled.Checked;
Utils.LocalWebService.EditHostWithPassword (Master.WebServiceLogin, host, txtPassword.Text);
RedirectToSelf ();
}
protected void cmdDeleteAllWork_Click (object sender, EventArgs e)
{
Response.Redirect ("Delete.aspx?action=delete-all-work-for-host&host_id=" + response.Host.id.ToString (), false);
}
protected void cmdClearAllWork_Click (object sender, EventArgs e)
{
Response.Redirect ("Delete.aspx?action=clear-all-work-for-host&host_id=" + response.Host.id.ToString (), false);
}
}