-
Notifications
You must be signed in to change notification settings - Fork 7
/
su_hosts.php
294 lines (281 loc) · 8.86 KB
/
su_hosts.php
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
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2017 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/util.inc");
require_once("../inc/host.inc");
require_once("../inc/su_schedule.inc");
require_once("../inc/su.inc");
// show list of user's hosts, minimal info, link to details
//
function show_user_hosts_page($user, $show_all, $is_me) {
$hosts = BoincHost::enum(
"userid=$user->id order by domain_name, rpc_time desc"
);
if ($is_me) {
page_head(tra("Your computers"));
} else {
page_head(sprintf('%s\'s computers', $user->name));
}
if (count($hosts) == 0) {
echo tra("No computers yet");
page_tail();
return;
}
start_table("table-striped");
row_heading_array([
tra("Computer name"),
tra("Operating system"),
tra("Hardware/software info"),
tra("Science United info"),
tra("Last contact")
]);
$now = time();
$have_hidden = False;
foreach($hosts as $h) {
if ($h->total_credit) {
$have_hidden = true;
if (!$show_all) continue;
}
row_array([
$h->domain_name,
$h->os_name,
sprintf(
'<a href=su_hosts.php?action=hw_sw_info&user_id=%d&host_id=%d>view</a>',
$user->id, $h->id
),
sprintf(
'<a href=su_hosts.php?action=su_info&user_id=%d&host_id=%d>view</a>',
$user->id, $h->id
),
time_diff_str($h->rpc_time, $now)
]);
}
end_table();
if ($is_me && $have_hidden) {
if ($show_all) {
echo "<p>Showing all computers.
<a href=su_hosts.php>Don't show hidden computers</a>.
";
} else {
echo "<p>Some of your computers are hidden.
<a href=su_hosts.php?show_all=1>Show all computers</a>.
";
}
}
page_tail();
}
function hide_host($user, $hidden) {
$id = get_int("host_id");
$h = BoincHost::lookup_id($id);
if (!$h || $h->userid != $user->id) {
error_page("no such host");
}
if ($hidden) {
$h->update("total_credit=-1"); // otherwise unused field
} else {
$h->update("total_credit=0");
}
}
function host_project_select($user, $host) {
echo tra('To decide which projects this computer should work for, we compute a "score" for each project. The components of the score are:');
echo sprintf("
<ul>
<li><b>%s</b>: %s
<li><b>%s</b>: %s
<li><b>%s</b>: %s
</ul>",
tra("Keyword score"),
tra("How well your keyword preferences match the project's keywords."),
tra("Platform score"),
tra("-1 if the project has no programs that will run on the computer; 0 if it does; +0.1 if one of them uses a GPU or VirtualBox."),
tra("Allocation score"),
tra("How much work is owed to the project; this changes from one day to the next.")
);
echo tra("We then choose the highest-scoring projects (at least 2) that together can use all the computer's processors."
);
echo "
<p>
";
$projects = rank_projects($user, $host, null, false);
start_table("table-striped");
$x = array(
tra("Project"),
tra("Keyword score"),
tra("Platform score"),
tra("Allocation score"),
tra("Score")
);
foreach ($host->resources as $r) {
$x[] = tra("Can use %1?", human_resource_name($r));
}
$x[] = tra("Opted out?");
row_heading_array($x);
foreach($projects as $p) {
$x = array(
"<a href=su_show_project.php?id=$p->id>$p->name</a>",
$p->keyword_score,
$p->platform_score,
number_format($p->allocation_score, 3),
number_format($p->score, 3)
);
foreach ($host->resources as $r) {
$x[] = can_use($p, $host, $r) ? "yes" : "no";
}
$x[] = $p->opt_out?tra("Yes"):"";
row_array($x);
}
end_table();
echo tra("Given the above info, this computer would do work for these projects:");
echo "
<p>
";
$projects = select_projects_resource($host, $projects);
start_table("table-striped");
$x = array(tra("Project"), tra("Score"));
foreach ($host->resources as $r) {
$x[] = "Use $r?";
}
row_heading_array($x);
foreach($projects as $p) {
$x = array(
"<a href=su_show_project.php?id=$p->id>$p->name</a>",
$p->score,
);
foreach ($host->resources as $r) {
$x[] = $p->use[$r] ? tra("Yes") : tra("No");
}
row_array($x);
}
end_table();
}
function hw_sw_info_page($host, $user, $is_me) {
page_head(tra("Computer hardware and software"));
start_table("table-striped");
if (!$is_me) {
row2('Owner',
sprintf('<a href=su_show_user.php?userid=%d>%s</a>',
$user->id, $user->name
)
);
}
show_host_hw_sw($host);
end_table();
page_tail();
}
function host_project_accounting($host) {
$ps = SUHostProject::enum("host_id=$host->id");
start_table("table-striped");
row_heading_array(array(
tra("Name"),
tra("CPU days"),
tra("GPU days"),
tra("# jobs success"),
tra("#jobs fail")
));
foreach ($ps as $p) {
$project = SUProject::lookup_id($p->project_id);
if ($p->cpu_time || $p->gpu_time || $p->njobs_success || $p->njobs_fail) {
row_array(array(
$project->name,
show_days($p->cpu_time),
show_days($p->gpu_time),
$p->njobs_success, $p->njobs_fail
));
}
}
end_table();
}
// show SU-specific info about this host
//
function su_info_page($host, $is_me) {
global $user;
page_head(tra("Science United computer info"));
start_table("table-striped");
$view = tra("View");
row2(tra("Name"), $host->domain_name);
show_host_detail($host);
if ($is_me) {
row2(
"Location<br><small>determines which set of computing preferences is used for this computer",
location_form($host)
);
if ($host->total_credit) {
row2(
'This computer is currently hidden',
sprintf(
'<a class="btn btn-success" href="su_hosts.php?action=hide&host_id=%d&hidden=0">%s</a>',
$host->id, 'Un-hide'
)
);
} else {
row2(
'Hide this computer<br><small>If this is a duplicate or the computer is no longer running BOINC.</small>',
sprintf(
'<a class="btn" %s href="su_hosts.php?action=hide&host_id=%d&hidden=1">%s</a>',
button_style(),
$host->id, 'Hide'
)
);
}
}
end_table();
echo sprintf('<h3>%s</h3>',
tra("Projects for which this computer has done work")
);
host_project_accounting($host);
echo sprintf('<h3>%s</h3>',
tra("How projects are chosen for %1", $host->domain_name)
);
$host = populate_score_info($host, null);
host_project_select($user, $host);
page_tail();
}
$user = get_logged_in_user();
$id = get_int('user_id', true);
if ($id) {
if ($id == $user->id) {
$is_me = true;
} else {
$user = BoincUser::lookup_id($id);
if (!$user) error_page('no user');
if (!$user->donated) error_page('no access');
$is_me = false;
}
} else {
$is_me = true;
}
$action = get_str("action", true);
switch ($action) {
case "hide":
if (!$is_me) break;
hide_host($user, get_int('hidden'));
show_user_hosts_page($user, false, true);
break;
case "su_info":
$host = BoincHost::lookup_id(get_int("host_id"));
if ($host->userid != $user->id) error_page('no access');
su_info_page($host, $is_me);
break;
case "hw_sw_info":
$host = BoincHost::lookup_id(get_int("host_id"));
if ($host->userid != $user->id) error_page('no access');
hw_sw_info_page($host, $user, $is_me);
break;
default:
$show_all = $is_me?get_int('show_all', true):false;
show_user_hosts_page($user, $show_all, $is_me);
}