@@ -20,6 +20,9 @@ |
||
20 | 20 | require_once("../inc/util.inc"); |
21 | 21 | require_once("../inc/host.inc"); |
22 | 22 | |
23 | +/** |
|
24 | + * @param string $msg |
|
25 | + */ |
|
23 | 26 | function fail($msg) { |
24 | 27 | echo "Error: $msg"; |
25 | 28 | page_tail(); |
@@ -41,7 +41,7 @@ |
||
41 | 41 | $nhosts = get_int("nhosts"); |
42 | 42 | $hostid = get_int("id_0"); |
43 | 43 | $latest_host = get_host($hostid, $user); |
44 | -for ($i=1; $i<$nhosts; $i++) { |
|
44 | +for ($i = 1; $i < $nhosts; $i++) { |
|
45 | 45 | $var = "id_$i"; |
46 | 46 | $hostid = get_int($var, true); |
47 | 47 | if (!$hostid) continue; |
@@ -44,7 +44,9 @@ |
||
44 | 44 | for ($i=1; $i<$nhosts; $i++) { |
45 | 45 | $var = "id_$i"; |
46 | 46 | $hostid = get_int($var, true); |
47 | - if (!$hostid) continue; |
|
47 | + if (!$hostid) { |
|
48 | + continue; |
|
49 | + } |
|
48 | 50 | $host = get_host($hostid, $user); |
49 | 51 | if ($host->create_time > $latest_host->create_time) { |
50 | 52 | $error = merge_hosts($latest_host, $host); |
@@ -30,6 +30,9 @@ discard block |
||
30 | 30 | // |
31 | 31 | // output: success flag, CPU time per step, est. disk usage per job |
32 | 32 | // |
33 | +/** |
|
34 | + * @param resource $p |
|
35 | + */ |
|
33 | 36 | function terminate_job($p) { |
34 | 37 | $pstatus=proc_get_status($p); |
35 | 38 | $ppid=$pstatus['pid']; |
@@ -86,6 +89,9 @@ discard block |
||
86 | 89 | return array($test_result, $total_cpu, $disk_space); |
87 | 90 | } |
88 | 91 | |
92 | +/** |
|
93 | + * @param string $cmd_file |
|
94 | + */ |
|
89 | 95 | function get_total_steps($cmd_file) { |
90 | 96 | $fd = fopen($cmd_file,"r"); |
91 | 97 | if (!$fd) { |
@@ -116,6 +122,9 @@ discard block |
||
116 | 122 | return $total_steps; |
117 | 123 | } |
118 | 124 | |
125 | +/** |
|
126 | + * @param string $filename |
|
127 | + */ |
|
119 | 128 | function calc_step_cpu($filename) { |
120 | 129 | $fd = fopen("$filename", "r"); |
121 | 130 | $start_line = "Step CPU "; |
@@ -169,6 +178,11 @@ discard block |
||
169 | 178 | return array($avg_cpu,$test_steps); |
170 | 179 | } |
171 | 180 | |
181 | +/** |
|
182 | + * @param string $lammps_script |
|
183 | + * @param string $structure_file |
|
184 | + * @param string $cmd_file |
|
185 | + */ |
|
172 | 186 | function calc_est_size($lammps_script, $structure_file, $cmd_file,$test_steps){ |
173 | 187 | $dump_types = 0; |
174 | 188 | $fd = fopen($lammps_script,"r"); |
@@ -280,6 +294,11 @@ discard block |
||
280 | 294 | |
281 | 295 | // verify that an input file exists in sandbox, and return its physical path |
282 | 296 | // |
297 | +/** |
|
298 | + * @param string $name |
|
299 | + * |
|
300 | + * @return string |
|
301 | + */ |
|
283 | 302 | function get_file_path($user, $name) { |
284 | 303 | $fname = get_str($name); |
285 | 304 | |
@@ -308,6 +327,10 @@ discard block |
||
308 | 327 | // |
309 | 328 | // Note: these are both extremely optimistic estimates |
310 | 329 | // |
330 | +/** |
|
331 | + * @param integer $njobs |
|
332 | + * @param double $flops_per_job |
|
333 | + */ |
|
311 | 334 | function estimated_makespan($njobs, $flops_per_job) { |
312 | 335 | $nhosts = BoincHost::count("expavg_credit > 1"); |
313 | 336 | if ($nhosts < 10) { |
@@ -416,6 +439,9 @@ discard block |
||
416 | 439 | page_tail(); |
417 | 440 | } |
418 | 441 | |
442 | +/** |
|
443 | + * @param integer $i |
|
444 | + */ |
|
419 | 445 | function submit_job($app, $batch_id, $info, $cmdline, $i) { |
420 | 446 | $client_disk=$info->rsc_disk_bound*2; |
421 | 447 | if($client_disk<500000000) $client_disk=500000000; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $ppid=$pstatus['pid']; |
36 | 36 | $ret=`ps -o pid --no-heading --ppid $ppid`; |
37 | 37 | //echo "parent pid is $ppid\nterninate it\n"; |
38 | - proc_terminate($p); |
|
38 | + proc_terminate($p); |
|
39 | 39 | // echo "child process is $ret\n"; |
40 | 40 | $pids=preg_split('/\s+/',$ret); |
41 | 41 | foreach($pids as $pid){ |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | while (1) { |
62 | 62 | $ctime=time(); |
63 | 63 | if($ctime-$stime >=2 and ! file_exists("log.1")){ |
64 | - if($GLOBALS["debug"]) echo "time out "."<br>"; |
|
65 | - terminate_job($p); |
|
66 | - break; |
|
64 | + if($GLOBALS["debug"]) echo "time out "."<br>"; |
|
65 | + terminate_job($p); |
|
66 | + break; |
|
67 | 67 | } |
68 | 68 | if (file_exists("log.1")) { |
69 | 69 | list($avg_cpu, $test_steps) = calc_step_cpu("log.1"); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | fclose($fd); |
114 | 114 | //$total_steps = $loopno*$looprun; |
115 | - if($GLOBALS["debug"])print "total_steps = ".$total_steps."<br>"; |
|
115 | + if($GLOBALS["debug"])print "total_steps = ".$total_steps."<br>"; |
|
116 | 116 | return $total_steps; |
117 | 117 | } |
118 | 118 | |
@@ -147,12 +147,12 @@ discard block |
||
147 | 147 | $cpu = (float)$arr[2]; |
148 | 148 | //echo "step=".$step." cpu=".$cpu."\n"; |
149 | 149 | if ($cpu==0) { |
150 | - $count=0; |
|
151 | - $start_step = $step; |
|
150 | + $count=0; |
|
151 | + $start_step = $step; |
|
152 | 152 | } else { |
153 | 153 | $count+=1; |
154 | 154 | if($GLOBALS["debug"])echo "step=".$step." cpu=".$cpu."count=".$count."<br>"; |
155 | - if($count >= 10) { |
|
155 | + if($count >= 10) { |
|
156 | 156 | $end_step = $step; |
157 | 157 | $steps = $end_step-$start_step; |
158 | 158 | $avg_cpu = $cpu/$steps; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | |
184 | 184 | if(preg_match("/^\s*dump\s+(\d)\s+/", $line,$matches)) |
185 | 185 | { |
186 | - if($GLOBALS["debug"]){print "matches=";print_r($matches);} |
|
186 | + if($GLOBALS["debug"]){print "matches=";print_r($matches);} |
|
187 | 187 | |
188 | 188 | $dump_types=(int)$matches[1]; |
189 | 189 | break; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | echo "can not open file $cmd_file\n"; |
199 | 199 | exit(-1); |
200 | 200 | } |
201 | - if($GLOBALS["debug"]) print "structure_file_size=".$structure_file_size."<br>"; |
|
201 | + if($GLOBALS["debug"]) print "structure_file_size=".$structure_file_size."<br>"; |
|
202 | 202 | |
203 | 203 | $loopno=1; |
204 | 204 | $looprun=1; |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | } |
217 | 217 | fclose($fd); |
218 | 218 | if($GLOBALS["debug"]){ |
219 | - print "max loopno(number of loops to run)=".$loopno."<br>"; |
|
220 | - print "max looprun(steps for each loop)=".$looprun."<br>"; |
|
219 | + print "max loopno(number of loops to run)=".$loopno."<br>"; |
|
220 | + print "max looprun(steps for each loop)=".$looprun."<br>"; |
|
221 | 221 | } |
222 | 222 | //$est_size = $loopno*$structure_file_size*0.8*$dump_types; |
223 | 223 | $test_log_size = filesize("log.1"); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | <br>Please refer to the following Error Message:<br><p> |
369 | 369 | "; |
370 | 370 | foreach($err_msgs as $line){ |
371 | - $err=$err.$line."<br>"; |
|
371 | + $err=$err.$line."<br>"; |
|
372 | 372 | } |
373 | 373 | $err=$err." <p> |
374 | 374 | <a href=sandbox.php><strong> File_Sandbox </strong></a> |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | // |
394 | 394 | $njobs = count(file($cmdline_file_path)); |
395 | 395 | $secs_est = estimated_makespan($njobs, $info->rsc_fpops_est); |
396 | - if($GLOBALS["debug"])echo "secs_est is $secs_est\n"; |
|
396 | + if($GLOBALS["debug"])echo "secs_est is $secs_est\n"; |
|
397 | 397 | //assume the server's flops is 1.5G and the average client's flops is 1G |
398 | 398 | $hrs_est = number_format($secs_est*1.5/60, 2); |
399 | 399 | //$hrs_est = number_format($secs_est, 2); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | require_once("../inc/util.inc"); |
19 | 19 | require_once("../inc/submit_db.inc"); |
20 | 20 | require_once("../inc/sandbox.inc"); |
21 | -$debug=0; |
|
21 | +$debug = 0; |
|
22 | 22 | |
23 | 23 | // test a LAMMPS job |
24 | 24 | // |
@@ -31,17 +31,17 @@ discard block |
||
31 | 31 | // output: success flag, CPU time per step, est. disk usage per job |
32 | 32 | // |
33 | 33 | function terminate_job($p) { |
34 | - $pstatus=proc_get_status($p); |
|
35 | - $ppid=$pstatus['pid']; |
|
36 | - $ret=`ps -o pid --no-heading --ppid $ppid`; |
|
34 | + $pstatus = proc_get_status($p); |
|
35 | + $ppid = $pstatus['pid']; |
|
36 | + $ret = `ps -o pid --no-heading --ppid $ppid`; |
|
37 | 37 | //echo "parent pid is $ppid\nterninate it\n"; |
38 | 38 | proc_terminate($p); |
39 | 39 | // echo "child process is $ret\n"; |
40 | - $pids=preg_split('/\s+/',$ret); |
|
41 | - foreach($pids as $pid){ |
|
42 | - if(is_numeric($pid)){ |
|
43 | - if($GLOBALS["debug"])echo "killing child process $pid\n"; |
|
44 | - posix_kill($pid,9); |
|
40 | + $pids = preg_split('/\s+/', $ret); |
|
41 | + foreach ($pids as $pid) { |
|
42 | + if (is_numeric($pid)) { |
|
43 | + if ($GLOBALS["debug"])echo "killing child process $pid\n"; |
|
44 | + posix_kill($pid, 9); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
@@ -52,23 +52,23 @@ discard block |
||
52 | 52 | $descs = array(); |
53 | 53 | $pipes = array(); |
54 | 54 | $options = file("cmd_variables"); |
55 | - $options[0] = chop($options[0],"\n"); |
|
55 | + $options[0] = chop($options[0], "\n"); |
|
56 | 56 | $cmd = "../lmp_linux ".$options[0]."&>output"; |
57 | 57 | if ($GLOBALS["debug"]) echo $cmd."<br>"; |
58 | 58 | system("unzip pot_files >/dev/null"); |
59 | 59 | $stime = time(); |
60 | 60 | $p = proc_open("$cmd", $descs, $pipes); |
61 | 61 | while (1) { |
62 | - $ctime=time(); |
|
63 | - if($ctime-$stime >=2 and ! file_exists("log.1")){ |
|
64 | - if($GLOBALS["debug"]) echo "time out "."<br>"; |
|
62 | + $ctime = time(); |
|
63 | + if ($ctime - $stime >= 2 and !file_exists("log.1")) { |
|
64 | + if ($GLOBALS["debug"]) echo "time out "."<br>"; |
|
65 | 65 | terminate_job($p); |
66 | 66 | break; |
67 | 67 | } |
68 | 68 | if (file_exists("log.1")) { |
69 | 69 | list($avg_cpu, $test_steps) = calc_step_cpu("log.1"); |
70 | 70 | if ($avg_cpu != 0) { |
71 | - if($GLOBALS["debug"])echo "avg_cpu is ".$avg_cpu."<br>"; |
|
71 | + if ($GLOBALS["debug"])echo "avg_cpu is ".$avg_cpu."<br>"; |
|
72 | 72 | terminate_job($p); |
73 | 73 | $test_result = 1; |
74 | 74 | break; |
@@ -87,32 +87,32 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | function get_total_steps($cmd_file) { |
90 | - $fd = fopen($cmd_file,"r"); |
|
90 | + $fd = fopen($cmd_file, "r"); |
|
91 | 91 | if (!$fd) { |
92 | 92 | echo "can not open file $cmd_file\n"; |
93 | 93 | exit(-1); |
94 | 94 | } |
95 | 95 | $this_loopno = 1; |
96 | 96 | $this_looprun = 1; |
97 | - $total_steps=1; |
|
97 | + $total_steps = 1; |
|
98 | 98 | while (!feof($fd)) { |
99 | - $line = fgets($fd,4096); |
|
99 | + $line = fgets($fd, 4096); |
|
100 | 100 | if (preg_match("/loopnumber\s+\d+/", $line, $matches) |
101 | 101 | && preg_match("/\d+/", $matches[0], $no) |
102 | 102 | ) { |
103 | - $this_loopno=$no[0]; |
|
103 | + $this_loopno = $no[0]; |
|
104 | 104 | } |
105 | 105 | if (preg_match("/looprun\s+\d+/", $line, $matches) |
106 | 106 | and preg_match("/\d+/", $matches[0], $no) |
107 | 107 | ) { |
108 | - $this_looprun=$no[0]; |
|
109 | - if($this_loopno*$this_looprun>$total_steps)$total_steps=$this_loopno*$this_looprun; |
|
108 | + $this_looprun = $no[0]; |
|
109 | + if ($this_loopno*$this_looprun > $total_steps)$total_steps = $this_loopno*$this_looprun; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | } |
113 | 113 | fclose($fd); |
114 | 114 | //$total_steps = $loopno*$looprun; |
115 | - if($GLOBALS["debug"])print "total_steps = ".$total_steps."<br>"; |
|
115 | + if ($GLOBALS["debug"])print "total_steps = ".$total_steps."<br>"; |
|
116 | 116 | return $total_steps; |
117 | 117 | } |
118 | 118 | |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | } |
131 | 131 | $count = 0; |
132 | 132 | while (!feof($fd)) { |
133 | - $line = fgets($fd,4096); |
|
134 | - if (preg_match('/^Step\s+CPU/',$line)) { |
|
133 | + $line = fgets($fd, 4096); |
|
134 | + if (preg_match('/^Step\s+CPU/', $line)) { |
|
135 | 135 | //echo $line."\n"; |
136 | 136 | $start = 1; |
137 | 137 | continue; |
@@ -140,24 +140,24 @@ discard block |
||
140 | 140 | $arr = preg_split("/\s+/", $line); |
141 | 141 | //print_r($arr); |
142 | 142 | |
143 | - if (count($arr) <=6 || !is_numeric($arr[1])) { |
|
143 | + if (count($arr) <= 6 || !is_numeric($arr[1])) { |
|
144 | 144 | continue; |
145 | 145 | } |
146 | 146 | $step = (int)$arr[1]; |
147 | 147 | $cpu = (float)$arr[2]; |
148 | 148 | //echo "step=".$step." cpu=".$cpu."\n"; |
149 | - if ($cpu==0) { |
|
150 | - $count=0; |
|
149 | + if ($cpu == 0) { |
|
150 | + $count = 0; |
|
151 | 151 | $start_step = $step; |
152 | 152 | } else { |
153 | - $count+=1; |
|
154 | - if($GLOBALS["debug"])echo "step=".$step." cpu=".$cpu."count=".$count."<br>"; |
|
155 | - if($count >= 10) { |
|
153 | + $count += 1; |
|
154 | + if ($GLOBALS["debug"])echo "step=".$step." cpu=".$cpu."count=".$count."<br>"; |
|
155 | + if ($count >= 10) { |
|
156 | 156 | $end_step = $step; |
157 | - $steps = $end_step-$start_step; |
|
157 | + $steps = $end_step - $start_step; |
|
158 | 158 | $avg_cpu = $cpu/$steps; |
159 | 159 | #$avg_cpu = $cpu/$count; |
160 | - if ($GLOBALS["debug"]){ |
|
160 | + if ($GLOBALS["debug"]) { |
|
161 | 161 | echo "test steps is ".$steps."<br>"; |
162 | 162 | echo "avg_cpu is ".$avg_cpu."<br>"; |
163 | 163 | } |
@@ -166,56 +166,56 @@ discard block |
||
166 | 166 | } |
167 | 167 | } |
168 | 168 | } |
169 | - return array($avg_cpu,$test_steps); |
|
169 | + return array($avg_cpu, $test_steps); |
|
170 | 170 | } |
171 | 171 | |
172 | -function calc_est_size($lammps_script, $structure_file, $cmd_file,$test_steps){ |
|
172 | +function calc_est_size($lammps_script, $structure_file, $cmd_file, $test_steps) { |
|
173 | 173 | $dump_types = 0; |
174 | - $fd = fopen($lammps_script,"r"); |
|
175 | - if (!$fd){ |
|
174 | + $fd = fopen($lammps_script, "r"); |
|
175 | + if (!$fd) { |
|
176 | 176 | echo "can not open file $lammps_script\n"; |
177 | 177 | exit(-1); |
178 | 178 | } |
179 | - while (!feof($fd)){ |
|
179 | + while (!feof($fd)) { |
|
180 | 180 | $line = fgets($fd, 4096); |
181 | 181 | //if (preg_match("/^\s*dump/", $line) |
182 | 182 | // and preg_match_all("/dump\S+\.\w{3}/", $line, $matches, PREG_PATTERN_ORDER)) |
183 | 183 | |
184 | - if(preg_match("/^\s*dump\s+(\d)\s+/", $line,$matches)) |
|
184 | + if (preg_match("/^\s*dump\s+(\d)\s+/", $line, $matches)) |
|
185 | 185 | { |
186 | - if($GLOBALS["debug"]){print "matches=";print_r($matches);} |
|
186 | + if ($GLOBALS["debug"]) {print "matches="; print_r($matches); } |
|
187 | 187 | |
188 | - $dump_types=(int)$matches[1]; |
|
188 | + $dump_types = (int)$matches[1]; |
|
189 | 189 | break; |
190 | 190 | } |
191 | 191 | } |
192 | 192 | fclose($fd); |
193 | - if($GLOBALS["debug"])print "dump_types= ".$dump_types."<br>"; |
|
193 | + if ($GLOBALS["debug"])print "dump_types= ".$dump_types."<br>"; |
|
194 | 194 | |
195 | 195 | $structure_file_size = filesize($structure_file); |
196 | - $fd = fopen($cmd_file,"r"); |
|
197 | - if (!$fd){ |
|
196 | + $fd = fopen($cmd_file, "r"); |
|
197 | + if (!$fd) { |
|
198 | 198 | echo "can not open file $cmd_file\n"; |
199 | 199 | exit(-1); |
200 | 200 | } |
201 | - if($GLOBALS["debug"]) print "structure_file_size=".$structure_file_size."<br>"; |
|
201 | + if ($GLOBALS["debug"]) print "structure_file_size=".$structure_file_size."<br>"; |
|
202 | 202 | |
203 | - $loopno=1; |
|
204 | - $looprun=1; |
|
205 | - while (!feof($fd)){ |
|
206 | - $line = fgets($fd,4096); |
|
207 | - if(preg_match("/loopnumber\s+\d+/", $line, $matches)){ |
|
208 | - if(preg_match("/\d+/", $matches[0], $no)){ |
|
203 | + $loopno = 1; |
|
204 | + $looprun = 1; |
|
205 | + while (!feof($fd)) { |
|
206 | + $line = fgets($fd, 4096); |
|
207 | + if (preg_match("/loopnumber\s+\d+/", $line, $matches)) { |
|
208 | + if (preg_match("/\d+/", $matches[0], $no)) { |
|
209 | 209 | //$loopno=$no[0]; |
210 | - if($no[0]>$loopno)$loopno=$no[0]; |
|
210 | + if ($no[0] > $loopno)$loopno = $no[0]; |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | if (preg_match("/looprun\s+\d+/", $line, $matches) and preg_match("/\d+/", $matches[0], $no)) { |
214 | - if($no[0]>$looprun)$looprun=$no[0]; |
|
214 | + if ($no[0] > $looprun)$looprun = $no[0]; |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | fclose($fd); |
218 | - if($GLOBALS["debug"]){ |
|
218 | + if ($GLOBALS["debug"]) { |
|
219 | 219 | print "max loopno(number of loops to run)=".$loopno."<br>"; |
220 | 220 | print "max looprun(steps for each loop)=".$looprun."<br>"; |
221 | 221 | } |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | $dump_files = glob("dump1*"); |
227 | 227 | $test_dump_file = $dump_files[0]; |
228 | 228 | $test_dump_size = filesize($test_dump_file); |
229 | - $dump_size1 = $test_dump_size+0.5*$test_dump_size*ceil(($looprun-$test_steps)/$test_steps); |
|
229 | + $dump_size1 = $test_dump_size + 0.5*$test_dump_size*ceil(($looprun - $test_steps)/$test_steps); |
|
230 | 230 | $dump_size = $loopno*$dump_size1*$dump_types; |
231 | 231 | $app_fixed_size = 5e7; |
232 | - $est_size = $log_size+$dump_size+$app_fixed_size; |
|
232 | + $est_size = $log_size + $dump_size + $app_fixed_size; |
|
233 | 233 | |
234 | - if($GLOBALS["debug"]){ |
|
234 | + if ($GLOBALS["debug"]) { |
|
235 | 235 | print "test_steps=".$test_steps."<br>"; |
236 | 236 | print "test_log_size=".$test_log_size."<br>"; |
237 | 237 | print "log_size1=".$log_size1."<br>"; |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | if ($njobs < $nhosts) { |
323 | 323 | return $flops_per_job/$median_flops; |
324 | 324 | } else { |
325 | - $k = (int)(($njobs+$nhosts-1)/$nhosts); |
|
325 | + $k = (int)(($njobs + $nhosts - 1)/$nhosts); |
|
326 | 326 | return $k*$flops_per_job/$median_flops; |
327 | 327 | } |
328 | 328 | } |
@@ -362,27 +362,27 @@ discard block |
||
362 | 362 | if ($GLOBALS["debug"]) { |
363 | 363 | print "est_cpu_time is ".$est_cpu_time."<br>"; |
364 | 364 | } |
365 | - if ($error==0) { |
|
366 | - $err_msgs=file("output"); |
|
367 | - $err="Your test job <strong>failed</strong> |
|
365 | + if ($error == 0) { |
|
366 | + $err_msgs = file("output"); |
|
367 | + $err = "Your test job <strong>failed</strong> |
|
368 | 368 | <br>Please refer to the following Error Message:<br><p> |
369 | 369 | "; |
370 | - foreach($err_msgs as $line){ |
|
371 | - $err=$err.$line."<br>"; |
|
370 | + foreach ($err_msgs as $line) { |
|
371 | + $err = $err.$line."<br>"; |
|
372 | 372 | } |
373 | - $err=$err." <p> |
|
373 | + $err = $err." <p> |
|
374 | 374 | <a href=sandbox.php><strong> File_Sandbox </strong></a> |
375 | 375 | "; |
376 | 376 | error_page($err); |
377 | 377 | } |
378 | 378 | |
379 | 379 | system("rm *"); |
380 | - $info->rsc_fpops_est = $est_cpu_time * 1.5e9; |
|
381 | - $info->rsc_fpops_bound = $info->rsc_fpops_est * 20; |
|
380 | + $info->rsc_fpops_est = $est_cpu_time*1.5e9; |
|
381 | + $info->rsc_fpops_bound = $info->rsc_fpops_est*20; |
|
382 | 382 | |
383 | - if ($disk==0){ |
|
384 | - $info->rsc_disk_bound=1000000; |
|
385 | - } else{ |
|
383 | + if ($disk == 0) { |
|
384 | + $info->rsc_disk_bound = 1000000; |
|
385 | + } else { |
|
386 | 386 | $info->rsc_disk_bound = $disk; |
387 | 387 | } |
388 | 388 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | // |
394 | 394 | $njobs = count(file($cmdline_file_path)); |
395 | 395 | $secs_est = estimated_makespan($njobs, $info->rsc_fpops_est); |
396 | - if($GLOBALS["debug"])echo "secs_est is $secs_est\n"; |
|
396 | + if ($GLOBALS["debug"])echo "secs_est is $secs_est\n"; |
|
397 | 397 | //assume the server's flops is 1.5G and the average client's flops is 1G |
398 | 398 | $hrs_est = number_format($secs_est*1.5/60, 2); |
399 | 399 | //$hrs_est = number_format($secs_est, 2); |
@@ -417,8 +417,8 @@ discard block |
||
417 | 417 | } |
418 | 418 | |
419 | 419 | function submit_job($app, $batch_id, $info, $cmdline, $i) { |
420 | - $client_disk=$info->rsc_disk_bound*2; |
|
421 | - if($client_disk<500000000) $client_disk=500000000; |
|
420 | + $client_disk = $info->rsc_disk_bound*2; |
|
421 | + if ($client_disk < 500000000) $client_disk = 500000000; |
|
422 | 422 | $cmd = "cd ../..; ./bin/create_work --appname $app->name --batch $batch_id --rsc_fpops_est $info->rsc_fpops_est --rsc_fpops_bound $info->rsc_fpops_bound --rsc_disk_bound $client_disk"; |
423 | 423 | if ($cmdline) { |
424 | 424 | $cmd .= " --command_line \"$cmdline\""; |
@@ -442,9 +442,9 @@ discard block |
||
442 | 442 | $x = file_get_contents("$tmpfile"); |
443 | 443 | $info = unserialize($x); |
444 | 444 | |
445 | - $njobs=0; |
|
445 | + $njobs = 0; |
|
446 | 446 | $cmdlines = file($info->cmdline_file_path); |
447 | - foreach ($cmdlines as $cmdline){ |
|
447 | + foreach ($cmdlines as $cmdline) { |
|
448 | 448 | if (preg_match("/^\s*-var/", $cmdline)) { |
449 | 449 | $njobs++; |
450 | 450 | } |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | |
461 | 461 | $i = 0; |
462 | 462 | foreach ($cmdlines as $cmdline) { |
463 | - if (preg_match("/^\s*-var/", $cmdline)){ |
|
463 | + if (preg_match("/^\s*-var/", $cmdline)) { |
|
464 | 464 | submit_job($app, $batch_id, $info, $cmdline, $i); |
465 | 465 | $i++; |
466 | 466 | } |
@@ -40,7 +40,9 @@ discard block |
||
40 | 40 | $pids=preg_split('/\s+/',$ret); |
41 | 41 | foreach($pids as $pid){ |
42 | 42 | if(is_numeric($pid)){ |
43 | - if($GLOBALS["debug"])echo "killing child process $pid\n"; |
|
43 | + if($GLOBALS["debug"]) { |
|
44 | + echo "killing child process $pid\n"; |
|
45 | + } |
|
44 | 46 | posix_kill($pid,9); |
45 | 47 | } |
46 | 48 | } |
@@ -54,21 +56,27 @@ discard block |
||
54 | 56 | $options = file("cmd_variables"); |
55 | 57 | $options[0] = chop($options[0],"\n"); |
56 | 58 | $cmd = "../lmp_linux ".$options[0]."&>output"; |
57 | - if ($GLOBALS["debug"]) echo $cmd."<br>"; |
|
59 | + if ($GLOBALS["debug"]) { |
|
60 | + echo $cmd."<br>"; |
|
61 | + } |
|
58 | 62 | system("unzip pot_files >/dev/null"); |
59 | 63 | $stime = time(); |
60 | 64 | $p = proc_open("$cmd", $descs, $pipes); |
61 | 65 | while (1) { |
62 | 66 | $ctime=time(); |
63 | 67 | if($ctime-$stime >=2 and ! file_exists("log.1")){ |
64 | - if($GLOBALS["debug"]) echo "time out "."<br>"; |
|
68 | + if($GLOBALS["debug"]) { |
|
69 | + echo "time out "."<br>"; |
|
70 | + } |
|
65 | 71 | terminate_job($p); |
66 | 72 | break; |
67 | 73 | } |
68 | 74 | if (file_exists("log.1")) { |
69 | 75 | list($avg_cpu, $test_steps) = calc_step_cpu("log.1"); |
70 | 76 | if ($avg_cpu != 0) { |
71 | - if($GLOBALS["debug"])echo "avg_cpu is ".$avg_cpu."<br>"; |
|
77 | + if($GLOBALS["debug"]) { |
|
78 | + echo "avg_cpu is ".$avg_cpu."<br>"; |
|
79 | + } |
|
72 | 80 | terminate_job($p); |
73 | 81 | $test_result = 1; |
74 | 82 | break; |
@@ -106,13 +114,17 @@ discard block |
||
106 | 114 | and preg_match("/\d+/", $matches[0], $no) |
107 | 115 | ) { |
108 | 116 | $this_looprun=$no[0]; |
109 | - if($this_loopno*$this_looprun>$total_steps)$total_steps=$this_loopno*$this_looprun; |
|
117 | + if($this_loopno*$this_looprun>$total_steps) { |
|
118 | + $total_steps=$this_loopno*$this_looprun; |
|
119 | + } |
|
110 | 120 | } |
111 | 121 | |
112 | 122 | } |
113 | 123 | fclose($fd); |
114 | 124 | //$total_steps = $loopno*$looprun; |
115 | - if($GLOBALS["debug"])print "total_steps = ".$total_steps."<br>"; |
|
125 | + if($GLOBALS["debug"]) { |
|
126 | + print "total_steps = ".$total_steps."<br>"; |
|
127 | + } |
|
116 | 128 | return $total_steps; |
117 | 129 | } |
118 | 130 | |
@@ -136,7 +148,9 @@ discard block |
||
136 | 148 | $start = 1; |
137 | 149 | continue; |
138 | 150 | } |
139 | - if (!$start) continue; |
|
151 | + if (!$start) { |
|
152 | + continue; |
|
153 | + } |
|
140 | 154 | $arr = preg_split("/\s+/", $line); |
141 | 155 | //print_r($arr); |
142 | 156 | |
@@ -151,7 +165,9 @@ discard block |
||
151 | 165 | $start_step = $step; |
152 | 166 | } else { |
153 | 167 | $count+=1; |
154 | - if($GLOBALS["debug"])echo "step=".$step." cpu=".$cpu."count=".$count."<br>"; |
|
168 | + if($GLOBALS["debug"]) { |
|
169 | + echo "step=".$step." cpu=".$cpu."count=".$count."<br>"; |
|
170 | + } |
|
155 | 171 | if($count >= 10) { |
156 | 172 | $end_step = $step; |
157 | 173 | $steps = $end_step-$start_step; |
@@ -190,7 +206,9 @@ discard block |
||
190 | 206 | } |
191 | 207 | } |
192 | 208 | fclose($fd); |
193 | - if($GLOBALS["debug"])print "dump_types= ".$dump_types."<br>"; |
|
209 | + if($GLOBALS["debug"]) { |
|
210 | + print "dump_types= ".$dump_types."<br>"; |
|
211 | + } |
|
194 | 212 | |
195 | 213 | $structure_file_size = filesize($structure_file); |
196 | 214 | $fd = fopen($cmd_file,"r"); |
@@ -198,7 +216,9 @@ discard block |
||
198 | 216 | echo "can not open file $cmd_file\n"; |
199 | 217 | exit(-1); |
200 | 218 | } |
201 | - if($GLOBALS["debug"]) print "structure_file_size=".$structure_file_size."<br>"; |
|
219 | + if($GLOBALS["debug"]) { |
|
220 | + print "structure_file_size=".$structure_file_size."<br>"; |
|
221 | + } |
|
202 | 222 | |
203 | 223 | $loopno=1; |
204 | 224 | $looprun=1; |
@@ -207,11 +227,15 @@ discard block |
||
207 | 227 | if(preg_match("/loopnumber\s+\d+/", $line, $matches)){ |
208 | 228 | if(preg_match("/\d+/", $matches[0], $no)){ |
209 | 229 | //$loopno=$no[0]; |
210 | - if($no[0]>$loopno)$loopno=$no[0]; |
|
230 | + if($no[0]>$loopno) { |
|
231 | + $loopno=$no[0]; |
|
232 | + } |
|
211 | 233 | } |
212 | 234 | } |
213 | 235 | if (preg_match("/looprun\s+\d+/", $line, $matches) and preg_match("/\d+/", $matches[0], $no)) { |
214 | - if($no[0]>$looprun)$looprun=$no[0]; |
|
236 | + if($no[0]>$looprun) { |
|
237 | + $looprun=$no[0]; |
|
238 | + } |
|
215 | 239 | } |
216 | 240 | } |
217 | 241 | fclose($fd); |
@@ -287,14 +311,18 @@ discard block |
||
287 | 311 | // |
288 | 312 | $sbdir = sandbox_dir($user); |
289 | 313 | list($error, $size, $md5) = sandbox_parse_link_file("$sbdir/$fname"); |
290 | - if ($error) error_page("no $name file"); |
|
314 | + if ($error) { |
|
315 | + error_page("no $name file"); |
|
316 | + } |
|
291 | 317 | |
292 | 318 | return sandbox_physical_path($user, $md5); |
293 | 319 | } |
294 | 320 | |
295 | 321 | function project_flops() { |
296 | 322 | $x = BoincUser::sum("expavg_credit"); |
297 | - if ($x == 0) $x = 200; |
|
323 | + if ($x == 0) { |
|
324 | + $x = 200; |
|
325 | + } |
|
298 | 326 | $y = 1e9*$x/200; |
299 | 327 | return $y; |
300 | 328 | } |
@@ -393,7 +421,9 @@ discard block |
||
393 | 421 | // |
394 | 422 | $njobs = count(file($cmdline_file_path)); |
395 | 423 | $secs_est = estimated_makespan($njobs, $info->rsc_fpops_est); |
396 | - if($GLOBALS["debug"])echo "secs_est is $secs_est\n"; |
|
424 | + if($GLOBALS["debug"]) { |
|
425 | + echo "secs_est is $secs_est\n"; |
|
426 | + } |
|
397 | 427 | //assume the server's flops is 1.5G and the average client's flops is 1G |
398 | 428 | $hrs_est = number_format($secs_est*1.5/60, 2); |
399 | 429 | //$hrs_est = number_format($secs_est, 2); |
@@ -418,7 +448,9 @@ discard block |
||
418 | 448 | |
419 | 449 | function submit_job($app, $batch_id, $info, $cmdline, $i) { |
420 | 450 | $client_disk=$info->rsc_disk_bound*2; |
421 | - if($client_disk<500000000) $client_disk=500000000; |
|
451 | + if($client_disk<500000000) { |
|
452 | + $client_disk=500000000; |
|
453 | + } |
|
422 | 454 | $cmd = "cd ../..; ./bin/create_work --appname $app->name --batch $batch_id --rsc_fpops_est $info->rsc_fpops_est --rsc_fpops_bound $info->rsc_fpops_bound --rsc_disk_bound $client_disk"; |
423 | 455 | if ($cmdline) { |
424 | 456 | $cmd .= " --command_line \"$cmdline\""; |
@@ -469,9 +501,13 @@ discard block |
||
469 | 501 | |
470 | 502 | $user = get_logged_in_user(); |
471 | 503 | $user_submit = BoincUserSubmit::lookup_userid($user->id); |
472 | -if (!$user_submit) error_page("no submit access"); |
|
504 | +if (!$user_submit) { |
|
505 | + error_page("no submit access"); |
|
506 | +} |
|
473 | 507 | $app = BoincApp::lookup("name='lammps'"); |
474 | -if (!$app) error_page("no lammps app"); |
|
508 | +if (!$app) { |
|
509 | + error_page("no lammps app"); |
|
510 | +} |
|
475 | 511 | |
476 | 512 | if (!$user_submit->submit_all) { |
477 | 513 | $usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$app->id"); |
@@ -315,6 +315,11 @@ discard block |
||
315 | 315 | /** |
316 | 316 | * Helper function used to scan for <meta>/<link> tags and extract information |
317 | 317 | * from them |
318 | + * @param string $tag |
|
319 | + * @param string $attrName |
|
320 | + * @param string $attrValue |
|
321 | + * @param string $valueName |
|
322 | + * @return string |
|
318 | 323 | */ |
319 | 324 | protected function htmlTag($content, $tag, $attrName, $attrValue, $valueName) |
320 | 325 | { |
@@ -531,6 +536,9 @@ discard block |
||
531 | 536 | return $params; |
532 | 537 | } |
533 | 538 | |
539 | + /** |
|
540 | + * @param boolean $immediate |
|
541 | + */ |
|
534 | 542 | protected function authUrl_v1($immediate) |
535 | 543 | { |
536 | 544 | $returnUrl = $this->returnUrl; |
@@ -552,6 +560,9 @@ discard block |
||
552 | 560 | , array('query' => http_build_query($params, '', '&'))); |
553 | 561 | } |
554 | 562 | |
563 | + /** |
|
564 | + * @param boolean $immediate |
|
565 | + */ |
|
555 | 566 | protected function authUrl_v2($immediate) |
556 | 567 | { |
557 | 568 | $params = array( |
@@ -587,7 +598,6 @@ discard block |
||
587 | 598 | /** |
588 | 599 | * Returns authentication url. Usually, you want to redirect your user to it. |
589 | 600 | * @return String The authentication url. |
590 | - * @param String $select_identifier Whether to request OP to select identity for an user in OpenID 2. Does not affect OpenID 1. |
|
591 | 601 | * @throws ErrorException |
592 | 602 | */ |
593 | 603 | function authUrl($immediate = false) |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | class LightOpenID |
48 | 48 | { |
49 | 49 | public $returnUrl |
50 | - , $required = array() |
|
51 | - , $optional = array() |
|
52 | - , $verify_peer = null |
|
53 | - , $capath = null |
|
54 | - , $cainfo = null; |
|
50 | + , $required = array() |
|
51 | + , $optional = array() |
|
52 | + , $verify_peer = null |
|
53 | + , $capath = null |
|
54 | + , $cainfo = null; |
|
55 | 55 | private $identity, $claimed_id; |
56 | 56 | protected $server, $version, $trustRoot, $aliases, $identifier_select = false |
57 | 57 | , $ax = false, $sreg = false, $data, $setup_url = null; |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | $parsed_url = parse_url($this->claimed_id); |
262 | 262 | $this->identity = |
263 | 263 | $this->claimed_id = $parsed_url['scheme'] . '://' |
264 | - . $parsed_url['host'] |
|
265 | - . $headers[$name]; |
|
264 | + . $parsed_url['host'] |
|
265 | + . $headers[$name]; |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | } |
@@ -301,14 +301,14 @@ discard block |
||
301 | 301 | |
302 | 302 | $url = $parts + $url; |
303 | 303 | $url = $url['scheme'] . '://' |
304 | - . (empty($url['username'])?'' |
|
304 | + . (empty($url['username'])?'' |
|
305 | 305 | :(empty($url['password'])? "{$url['username']}@" |
306 | 306 | :"{$url['username']}:{$url['password']}@")) |
307 | - . $url['host'] |
|
308 | - . (empty($url['port'])?'':":{$url['port']}") |
|
309 | - . (empty($url['path'])?'':$url['path']) |
|
310 | - . (empty($url['query'])?'':"?{$url['query']}") |
|
311 | - . (empty($url['fragment'])?'':"#{$url['fragment']}"); |
|
307 | + . $url['host'] |
|
308 | + . (empty($url['port'])?'':":{$url['port']}") |
|
309 | + . (empty($url['path'])?'':$url['path']) |
|
310 | + . (empty($url['query'])?'':"?{$url['query']}") |
|
311 | + . (empty($url['fragment'])?'':"#{$url['fragment']}"); |
|
312 | 312 | return $url; |
313 | 313 | } |
314 | 314 | |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | |
534 | 534 | protected function authUrl_v1($immediate) |
535 | 535 | { |
536 | - $returnUrl = $this->returnUrl; |
|
536 | + $returnUrl = $this->returnUrl; |
|
537 | 537 | # If we have an openid.delegate that is different from our claimed id, |
538 | 538 | # we need to somehow preserve the claimed id between requests. |
539 | 539 | # The simplest way is to just send it along with the return_to url. |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | ) + $this->sregParams(); |
550 | 550 | |
551 | 551 | return $this->build_url(parse_url($this->server) |
552 | - , array('query' => http_build_query($params, '', '&'))); |
|
552 | + , array('query' => http_build_query($params, '', '&'))); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | protected function authUrl_v2($immediate) |
@@ -574,14 +574,14 @@ discard block |
||
574 | 574 | |
575 | 575 | if ($this->identifier_select) { |
576 | 576 | $params['openid.identity'] = $params['openid.claimed_id'] |
577 | - = 'http://specs.openid.net/auth/2.0/identifier_select'; |
|
577 | + = 'http://specs.openid.net/auth/2.0/identifier_select'; |
|
578 | 578 | } else { |
579 | 579 | $params['openid.identity'] = $this->identity; |
580 | 580 | $params['openid.claimed_id'] = $this->claimed_id; |
581 | 581 | } |
582 | 582 | |
583 | 583 | return $this->build_url(parse_url($this->server) |
584 | - , array('query' => http_build_query($params, '', '&'))); |
|
584 | + , array('query' => http_build_query($params, '', '&'))); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | # If it's an OpenID 1 provider, and we've got claimed_id, |
639 | 639 | # we have to append it to the returnUrl, like authUrl_v1 does. |
640 | 640 | $this->returnUrl .= (strpos($this->returnUrl, '?') ? '&' : '?') |
641 | - . 'openid.claimed_id=' . $this->claimed_id; |
|
641 | + . 'openid.claimed_id=' . $this->claimed_id; |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | if ($this->data['openid_return_to'] != $this->returnUrl) { |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | continue; |
708 | 708 | } |
709 | 709 | $key = substr($this->data['openid_' . $alias . '_type_' . $key], |
710 | - strlen('http://axschema.org/')); |
|
710 | + strlen('http://axschema.org/')); |
|
711 | 711 | $attributes[$key] = $value; |
712 | 712 | } |
713 | 713 | return $attributes; |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | |
70 | 70 | function __construct() |
71 | 71 | { |
72 | - $this->trustRoot = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; |
|
72 | + $this->trustRoot = (!empty($_SERVER['HTTPS']) ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST']; |
|
73 | 73 | $uri = rtrim(preg_replace('#((?<=\?)|&)openid\.[^&]+#', '', $_SERVER['REQUEST_URI']), '?'); |
74 | - $this->returnUrl = $this->trustRoot . $uri; |
|
74 | + $this->returnUrl = $this->trustRoot.$uri; |
|
75 | 75 | |
76 | 76 | $this->data = $_POST + $_GET; # OPs may send data as POST or GET. |
77 | 77 | |
78 | - if(!function_exists('curl_init') && !in_array('https', stream_get_wrappers())) { |
|
78 | + if (!function_exists('curl_init') && !in_array('https', stream_get_wrappers())) { |
|
79 | 79 | throw new ErrorException('You must have either https wrappers or curl enabled.'); |
80 | 80 | } |
81 | 81 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | { |
85 | 85 | switch ($name) { |
86 | 86 | case 'identity': |
87 | - if (strlen($value = trim((String) $value))) { |
|
87 | + if (strlen($value = trim((String)$value))) { |
|
88 | 88 | if (preg_match('#^xri:/*#i', $value, $m)) { |
89 | 89 | $value = substr($value, strlen($m[0])); |
90 | 90 | } elseif (!preg_match('/^(?:[=@+\$!\(]|https?:)/i', $value)) { |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | return !!gethostbynamel($server); |
140 | 140 | } |
141 | 141 | |
142 | - protected function request_curl($url, $method='GET', $params=array()) |
|
142 | + protected function request_curl($url, $method = 'GET', $params = array()) |
|
143 | 143 | { |
144 | 144 | $params = http_build_query($params, '', '&'); |
145 | - $curl = curl_init($url . ($method == 'GET' && $params ? '?' . $params : '')); |
|
145 | + $curl = curl_init($url.($method == 'GET' && $params ? '?'.$params : '')); |
|
146 | 146 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
147 | 147 | curl_setopt($curl, CURLOPT_HEADER, false); |
148 | 148 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
149 | 149 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
150 | 150 | curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/xrds+xml, */*')); |
151 | 151 | |
152 | - if($this->verify_peer !== null) { |
|
152 | + if ($this->verify_peer !== null) { |
|
153 | 153 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verify_peer); |
154 | - if($this->capath) { |
|
154 | + if ($this->capath) { |
|
155 | 155 | curl_setopt($curl, CURLOPT_CAPATH, $this->capath); |
156 | 156 | } |
157 | 157 | |
158 | - if($this->cainfo) { |
|
158 | + if ($this->cainfo) { |
|
159 | 159 | curl_setopt($curl, CURLOPT_CAINFO, $this->cainfo); |
160 | 160 | } |
161 | 161 | } |
@@ -171,17 +171,17 @@ discard block |
||
171 | 171 | } |
172 | 172 | $response = curl_exec($curl); |
173 | 173 | |
174 | - if($method == 'HEAD') { |
|
174 | + if ($method == 'HEAD') { |
|
175 | 175 | $headers = array(); |
176 | - foreach(explode("\n", $response) as $header) { |
|
177 | - $pos = strpos($header,':'); |
|
176 | + foreach (explode("\n", $response) as $header) { |
|
177 | + $pos = strpos($header, ':'); |
|
178 | 178 | $name = strtolower(trim(substr($header, 0, $pos))); |
179 | - $headers[$name] = trim(substr($header, $pos+1)); |
|
179 | + $headers[$name] = trim(substr($header, $pos + 1)); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | # Updating claimed_id in case of redirections. |
183 | 183 | $effective_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); |
184 | - if($effective_url != $url) { |
|
184 | + if ($effective_url != $url) { |
|
185 | 185 | $this->identity = $this->claimed_id = $effective_url; |
186 | 186 | } |
187 | 187 | |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | return $response; |
196 | 196 | } |
197 | 197 | |
198 | - protected function request_streams($url, $method='GET', $params=array()) |
|
198 | + protected function request_streams($url, $method = 'GET', $params = array()) |
|
199 | 199 | { |
200 | - if(!$this->hostExists($url)) { |
|
200 | + if (!$this->hostExists($url)) { |
|
201 | 201 | throw new ErrorException('Invalid request.'); |
202 | 202 | } |
203 | 203 | |
204 | 204 | $params = http_build_query($params, '', '&'); |
205 | - switch($method) { |
|
205 | + switch ($method) { |
|
206 | 206 | case 'GET': |
207 | 207 | $opts = array( |
208 | 208 | 'http' => array( |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | 'ignore_errors' => true, |
212 | 212 | ) |
213 | 213 | ); |
214 | - $url = $url . ($params ? '?' . $params : ''); |
|
214 | + $url = $url.($params ? '?'.$params : ''); |
|
215 | 215 | break; |
216 | 216 | case 'POST': |
217 | 217 | $opts = array( |
@@ -236,31 +236,31 @@ discard block |
||
236 | 236 | )) |
237 | 237 | ); |
238 | 238 | |
239 | - $url = $url . ($params ? '?' . $params : ''); |
|
240 | - $headers_tmp = get_headers ($url); |
|
241 | - if(!$headers_tmp) { |
|
239 | + $url = $url.($params ? '?'.$params : ''); |
|
240 | + $headers_tmp = get_headers($url); |
|
241 | + if (!$headers_tmp) { |
|
242 | 242 | return array(); |
243 | 243 | } |
244 | 244 | |
245 | 245 | # Parsing headers. |
246 | 246 | $headers = array(); |
247 | - foreach($headers_tmp as $header) { |
|
248 | - $pos = strpos($header,':'); |
|
247 | + foreach ($headers_tmp as $header) { |
|
248 | + $pos = strpos($header, ':'); |
|
249 | 249 | $name = strtolower(trim(substr($header, 0, $pos))); |
250 | - $headers[$name] = trim(substr($header, $pos+1)); |
|
250 | + $headers[$name] = trim(substr($header, $pos + 1)); |
|
251 | 251 | |
252 | 252 | # Following possible redirections. The point is just to have |
253 | 253 | # claimed_id change with them, because get_headers() will |
254 | 254 | # follow redirections automatically. |
255 | 255 | # We ignore redirections with relative paths. |
256 | 256 | # If any known provider uses them, file a bug report. |
257 | - if($name == 'location') { |
|
258 | - if(strpos($headers[$name], 'http') === 0) { |
|
257 | + if ($name == 'location') { |
|
258 | + if (strpos($headers[$name], 'http') === 0) { |
|
259 | 259 | $this->identity = $this->claimed_id = $headers[$name]; |
260 | - } elseif($headers[$name][0] == '/') { |
|
260 | + } elseif ($headers[$name][0] == '/') { |
|
261 | 261 | $parsed_url = parse_url($this->claimed_id); |
262 | 262 | $this->identity = |
263 | - $this->claimed_id = $parsed_url['scheme'] . '://' |
|
263 | + $this->claimed_id = $parsed_url['scheme'].'://' |
|
264 | 264 | . $parsed_url['host'] |
265 | 265 | . $headers[$name]; |
266 | 266 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | return $headers; |
273 | 273 | } |
274 | 274 | |
275 | - if($this->verify_peer) { |
|
275 | + if ($this->verify_peer) { |
|
276 | 276 | $opts += array('ssl' => array( |
277 | 277 | 'verify_peer' => true, |
278 | 278 | 'capath' => $this->capath, |
@@ -280,14 +280,14 @@ discard block |
||
280 | 280 | )); |
281 | 281 | } |
282 | 282 | |
283 | - $context = stream_context_create ($opts); |
|
283 | + $context = stream_context_create($opts); |
|
284 | 284 | |
285 | 285 | return file_get_contents($url, false, $context); |
286 | 286 | } |
287 | 287 | |
288 | - protected function request($url, $method='GET', $params=array()) |
|
288 | + protected function request($url, $method = 'GET', $params = array()) |
|
289 | 289 | { |
290 | - if(function_exists('curl_init') && !ini_get('safe_mode') && !ini_get('open_basedir')) { |
|
290 | + if (function_exists('curl_init') && !ini_get('safe_mode') && !ini_get('open_basedir')) { |
|
291 | 291 | return $this->request_curl($url, $method, $params); |
292 | 292 | } |
293 | 293 | return $this->request_streams($url, $method, $params); |
@@ -296,19 +296,19 @@ discard block |
||
296 | 296 | protected function build_url($url, $parts) |
297 | 297 | { |
298 | 298 | if (isset($url['query'], $parts['query'])) { |
299 | - $parts['query'] = $url['query'] . '&' . $parts['query']; |
|
299 | + $parts['query'] = $url['query'].'&'.$parts['query']; |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | $url = $parts + $url; |
303 | - $url = $url['scheme'] . '://' |
|
304 | - . (empty($url['username'])?'' |
|
305 | - :(empty($url['password'])? "{$url['username']}@" |
|
303 | + $url = $url['scheme'].'://' |
|
304 | + . (empty($url['username']) ? '' |
|
305 | + :(empty($url['password']) ? "{$url['username']}@" |
|
306 | 306 | :"{$url['username']}:{$url['password']}@")) |
307 | 307 | . $url['host'] |
308 | - . (empty($url['port'])?'':":{$url['port']}") |
|
309 | - . (empty($url['path'])?'':$url['path']) |
|
310 | - . (empty($url['query'])?'':"?{$url['query']}") |
|
311 | - . (empty($url['fragment'])?'':"#{$url['fragment']}"); |
|
308 | + . (empty($url['port']) ? '' : ":{$url['port']}") |
|
309 | + . (empty($url['path']) ? '' : $url['path']) |
|
310 | + . (empty($url['query']) ? '' : "?{$url['query']}") |
|
311 | + . (empty($url['fragment']) ? '' : "#{$url['fragment']}"); |
|
312 | 312 | return $url; |
313 | 313 | } |
314 | 314 | |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | preg_match_all("#<{$tag}[^>]*$valueName=['\"](.+?)['\"][^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*/?>#i", $content, $matches2); |
323 | 323 | |
324 | 324 | $result = array_merge($matches1[1], $matches2[1]); |
325 | - return empty($result)?false:$result[0]; |
|
325 | + return empty($result) ? false : $result[0]; |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $yadis = true; |
349 | 349 | |
350 | 350 | # We'll jump a maximum of 5 times, to avoid endless redirections. |
351 | - for ($i = 0; $i < 5; $i ++) { |
|
351 | + for ($i = 0; $i < 5; $i++) { |
|
352 | 352 | if ($yadis) { |
353 | 353 | $headers = $this->request($url, 'HEAD'); |
354 | 354 | |
@@ -370,12 +370,12 @@ discard block |
||
370 | 370 | $content = $this->request($url, 'GET'); |
371 | 371 | |
372 | 372 | preg_match_all('#<Service.*?>(.*?)</Service>#s', $content, $m); |
373 | - foreach($m[1] as $content) { |
|
374 | - $content = ' ' . $content; # The space is added, so that strpos doesn't return 0. |
|
373 | + foreach ($m[1] as $content) { |
|
374 | + $content = ' '.$content; # The space is added, so that strpos doesn't return 0. |
|
375 | 375 | |
376 | 376 | # OpenID 2 |
377 | 377 | $ns = preg_quote('http://specs.openid.net/auth/2.0/'); |
378 | - if(preg_match('#<Type>\s*'.$ns.'(server|signon)\s*</Type>#s', $content, $type)) { |
|
378 | + if (preg_match('#<Type>\s*'.$ns.'(server|signon)\s*</Type>#s', $content, $type)) { |
|
379 | 379 | if ($type[1] == 'server') $this->identifier_select = true; |
380 | 380 | |
381 | 381 | preg_match('#<URI.*?>(.*)</URI>#', $content, $server); |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | return false; |
385 | 385 | } |
386 | 386 | # Does the server advertise support for either AX or SREG? |
387 | - $this->ax = (bool) strpos($content, '<Type>http://openid.net/srv/ax/1.0</Type>'); |
|
387 | + $this->ax = (bool)strpos($content, '<Type>http://openid.net/srv/ax/1.0</Type>'); |
|
388 | 388 | $this->sreg = strpos($content, '<Type>http://openid.net/sreg/1.0</Type>') |
389 | 389 | || strpos($content, '<Type>http://openid.net/extensions/sreg/1.1</Type>'); |
390 | 390 | |
@@ -498,33 +498,33 @@ discard block |
||
498 | 498 | if ($this->required || $this->optional) { |
499 | 499 | $params['openid.ns.ax'] = 'http://openid.net/srv/ax/1.0'; |
500 | 500 | $params['openid.ax.mode'] = 'fetch_request'; |
501 | - $this->aliases = array(); |
|
501 | + $this->aliases = array(); |
|
502 | 502 | $counts = array(); |
503 | 503 | $required = array(); |
504 | 504 | $optional = array(); |
505 | - foreach (array('required','optional') as $type) { |
|
505 | + foreach (array('required', 'optional') as $type) { |
|
506 | 506 | foreach ($this->$type as $alias => $field) { |
507 | 507 | if (is_int($alias)) $alias = strtr($field, '/', '_'); |
508 | - $this->aliases[$alias] = 'http://axschema.org/' . $field; |
|
508 | + $this->aliases[$alias] = 'http://axschema.org/'.$field; |
|
509 | 509 | if (empty($counts[$alias])) $counts[$alias] = 0; |
510 | 510 | $counts[$alias] += 1; |
511 | 511 | ${$type}[] = $alias; |
512 | 512 | } |
513 | 513 | } |
514 | 514 | foreach ($this->aliases as $alias => $ns) { |
515 | - $params['openid.ax.type.' . $alias] = $ns; |
|
515 | + $params['openid.ax.type.'.$alias] = $ns; |
|
516 | 516 | } |
517 | 517 | foreach ($counts as $alias => $count) { |
518 | 518 | if ($count == 1) continue; |
519 | - $params['openid.ax.count.' . $alias] = $count; |
|
519 | + $params['openid.ax.count.'.$alias] = $count; |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | # Don't send empty ax.requied and ax.if_available. |
523 | 523 | # Google and possibly other providers refuse to support ax when one of these is empty. |
524 | - if($required) { |
|
524 | + if ($required) { |
|
525 | 525 | $params['openid.ax.required'] = implode(',', $required); |
526 | 526 | } |
527 | - if($optional) { |
|
527 | + if ($optional) { |
|
528 | 528 | $params['openid.ax.if_available'] = implode(',', $optional); |
529 | 529 | } |
530 | 530 | } |
@@ -537,8 +537,8 @@ discard block |
||
537 | 537 | # If we have an openid.delegate that is different from our claimed id, |
538 | 538 | # we need to somehow preserve the claimed id between requests. |
539 | 539 | # The simplest way is to just send it along with the return_to url. |
540 | - if($this->identity != $this->claimed_id) { |
|
541 | - $returnUrl .= (strpos($returnUrl, '?') ? '&' : '?') . 'openid.claimed_id=' . $this->claimed_id; |
|
540 | + if ($this->identity != $this->claimed_id) { |
|
541 | + $returnUrl .= (strpos($returnUrl, '?') ? '&' : '?').'openid.claimed_id='.$this->claimed_id; |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | $params = array( |
@@ -612,15 +612,15 @@ discard block |
||
612 | 612 | # by presenting user_setup_url (for 1.1) or reporting |
613 | 613 | # mode 'setup_needed' (for 2.0). Also catching all modes other than |
614 | 614 | # id_res, in order to avoid throwing errors. |
615 | - if(isset($this->data['openid_user_setup_url'])) { |
|
615 | + if (isset($this->data['openid_user_setup_url'])) { |
|
616 | 616 | $this->setup_url = $this->data['openid_user_setup_url']; |
617 | 617 | return false; |
618 | 618 | } |
619 | - if($this->mode != 'id_res') { |
|
619 | + if ($this->mode != 'id_res') { |
|
620 | 620 | return false; |
621 | 621 | } |
622 | 622 | |
623 | - $this->claimed_id = isset($this->data['openid_claimed_id'])?$this->data['openid_claimed_id']:$this->data['openid_identity']; |
|
623 | + $this->claimed_id = isset($this->data['openid_claimed_id']) ? $this->data['openid_claimed_id'] : $this->data['openid_identity']; |
|
624 | 624 | $params = array( |
625 | 625 | 'openid.assoc_handle' => $this->data['openid_assoc_handle'], |
626 | 626 | 'openid.signed' => $this->data['openid_signed'], |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | # If it's an OpenID 1 provider, and we've got claimed_id, |
639 | 639 | # we have to append it to the returnUrl, like authUrl_v1 does. |
640 | 640 | $this->returnUrl .= (strpos($this->returnUrl, '?') ? '&' : '?') |
641 | - . 'openid.claimed_id=' . $this->claimed_id; |
|
641 | + . 'openid.claimed_id='.$this->claimed_id; |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | if ($this->data['openid_return_to'] != $this->returnUrl) { |
@@ -656,8 +656,8 @@ discard block |
||
656 | 656 | # In such case, validation would fail, since we'd send different data than OP |
657 | 657 | # wants to verify. stripslashes() should solve that problem, but we can't |
658 | 658 | # use it when magic_quotes is off. |
659 | - $value = $this->data['openid_' . str_replace('.','_',$item)]; |
|
660 | - $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($value) : $value; |
|
659 | + $value = $this->data['openid_'.str_replace('.', '_', $item)]; |
|
660 | + $params['openid.'.$item] = get_magic_quotes_gpc() ? stripslashes($value) : $value; |
|
661 | 661 | |
662 | 662 | } |
663 | 663 | |
@@ -695,18 +695,18 @@ discard block |
||
695 | 695 | |
696 | 696 | $attributes = array(); |
697 | 697 | foreach ($this->data as $key => $value) { |
698 | - $keyMatch = 'openid_' . $alias . '_value_'; |
|
698 | + $keyMatch = 'openid_'.$alias.'_value_'; |
|
699 | 699 | if (substr($key, 0, strlen($keyMatch)) != $keyMatch) { |
700 | 700 | continue; |
701 | 701 | } |
702 | 702 | $key = substr($key, strlen($keyMatch)); |
703 | - if (!isset($this->data['openid_' . $alias . '_type_' . $key])) { |
|
703 | + if (!isset($this->data['openid_'.$alias.'_type_'.$key])) { |
|
704 | 704 | # OP is breaking the spec by returning a field without |
705 | 705 | # associated ns. This shouldn't happen, but it's better |
706 | 706 | # to check, than cause an E_NOTICE. |
707 | 707 | continue; |
708 | 708 | } |
709 | - $key = substr($this->data['openid_' . $alias . '_type_' . $key], |
|
709 | + $key = substr($this->data['openid_'.$alias.'_type_'.$key], |
|
710 | 710 | strlen('http://axschema.org/')); |
711 | 711 | $attributes[$key] = $value; |
712 | 712 | } |
@@ -333,7 +333,9 @@ discard block |
||
333 | 333 | */ |
334 | 334 | function discover($url) |
335 | 335 | { |
336 | - if (!$url) throw new ErrorException('No identity supplied.'); |
|
336 | + if (!$url) { |
|
337 | + throw new ErrorException('No identity supplied.'); |
|
338 | + } |
|
337 | 339 | # Use xri.net proxy to resolve i-name identities |
338 | 340 | if (!preg_match('#^https?:#', $url)) { |
339 | 341 | $url = "https://xri.net/$url"; |
@@ -376,7 +378,9 @@ discard block |
||
376 | 378 | # OpenID 2 |
377 | 379 | $ns = preg_quote('http://specs.openid.net/auth/2.0/'); |
378 | 380 | if(preg_match('#<Type>\s*'.$ns.'(server|signon)\s*</Type>#s', $content, $type)) { |
379 | - if ($type[1] == 'server') $this->identifier_select = true; |
|
381 | + if ($type[1] == 'server') { |
|
382 | + $this->identifier_select = true; |
|
383 | + } |
|
380 | 384 | |
381 | 385 | preg_match('#<URI.*?>(.*)</URI>#', $content, $server); |
382 | 386 | preg_match('#<(Local|Canonical)ID>(.*)</\1ID>#', $content, $delegate); |
@@ -389,7 +393,9 @@ discard block |
||
389 | 393 | || strpos($content, '<Type>http://openid.net/extensions/sreg/1.1</Type>'); |
390 | 394 | |
391 | 395 | $server = $server[1]; |
392 | - if (isset($delegate[2])) $this->identity = trim($delegate[2]); |
|
396 | + if (isset($delegate[2])) { |
|
397 | + $this->identity = trim($delegate[2]); |
|
398 | + } |
|
393 | 399 | $this->version = 2; |
394 | 400 | |
395 | 401 | $this->server = $server; |
@@ -410,7 +416,9 @@ discard block |
||
410 | 416 | || strpos($content, '<Type>http://openid.net/extensions/sreg/1.1</Type>'); |
411 | 417 | |
412 | 418 | $server = $server[1]; |
413 | - if (isset($delegate[1])) $this->identity = $delegate[1]; |
|
419 | + if (isset($delegate[1])) { |
|
420 | + $this->identity = $delegate[1]; |
|
421 | + } |
|
414 | 422 | $this->version = 1; |
415 | 423 | |
416 | 424 | $this->server = $server; |
@@ -424,7 +432,9 @@ discard block |
||
424 | 432 | $content = null; |
425 | 433 | break; |
426 | 434 | } |
427 | - if ($next) continue; |
|
435 | + if ($next) { |
|
436 | + continue; |
|
437 | + } |
|
428 | 438 | |
429 | 439 | # There are no relevant information in headers, so we search the body. |
430 | 440 | $content = $this->request($url, 'GET'); |
@@ -435,7 +445,9 @@ discard block |
||
435 | 445 | } |
436 | 446 | } |
437 | 447 | |
438 | - if (!$content) $content = $this->request($url, 'GET'); |
|
448 | + if (!$content) { |
|
449 | + $content = $this->request($url, 'GET'); |
|
450 | + } |
|
439 | 451 | |
440 | 452 | # At this point, the YADIS Discovery has failed, so we'll switch |
441 | 453 | # to openid2 HTML discovery, then fallback to openid 1.1 discovery. |
@@ -475,7 +487,9 @@ discard block |
||
475 | 487 | if ($this->required) { |
476 | 488 | $params['openid.sreg.required'] = array(); |
477 | 489 | foreach ($this->required as $required) { |
478 | - if (!isset(self::$ax_to_sreg[$required])) continue; |
|
490 | + if (!isset(self::$ax_to_sreg[$required])) { |
|
491 | + continue; |
|
492 | + } |
|
479 | 493 | $params['openid.sreg.required'][] = self::$ax_to_sreg[$required]; |
480 | 494 | } |
481 | 495 | $params['openid.sreg.required'] = implode(',', $params['openid.sreg.required']); |
@@ -484,7 +498,9 @@ discard block |
||
484 | 498 | if ($this->optional) { |
485 | 499 | $params['openid.sreg.optional'] = array(); |
486 | 500 | foreach ($this->optional as $optional) { |
487 | - if (!isset(self::$ax_to_sreg[$optional])) continue; |
|
501 | + if (!isset(self::$ax_to_sreg[$optional])) { |
|
502 | + continue; |
|
503 | + } |
|
488 | 504 | $params['openid.sreg.optional'][] = self::$ax_to_sreg[$optional]; |
489 | 505 | } |
490 | 506 | $params['openid.sreg.optional'] = implode(',', $params['openid.sreg.optional']); |
@@ -504,9 +520,13 @@ discard block |
||
504 | 520 | $optional = array(); |
505 | 521 | foreach (array('required','optional') as $type) { |
506 | 522 | foreach ($this->$type as $alias => $field) { |
507 | - if (is_int($alias)) $alias = strtr($field, '/', '_'); |
|
523 | + if (is_int($alias)) { |
|
524 | + $alias = strtr($field, '/', '_'); |
|
525 | + } |
|
508 | 526 | $this->aliases[$alias] = 'http://axschema.org/' . $field; |
509 | - if (empty($counts[$alias])) $counts[$alias] = 0; |
|
527 | + if (empty($counts[$alias])) { |
|
528 | + $counts[$alias] = 0; |
|
529 | + } |
|
510 | 530 | $counts[$alias] += 1; |
511 | 531 | ${$type}[] = $alias; |
512 | 532 | } |
@@ -515,7 +535,9 @@ discard block |
||
515 | 535 | $params['openid.ax.type.' . $alias] = $ns; |
516 | 536 | } |
517 | 537 | foreach ($counts as $alias => $count) { |
518 | - if ($count == 1) continue; |
|
538 | + if ($count == 1) { |
|
539 | + continue; |
|
540 | + } |
|
519 | 541 | $params['openid.ax.count.' . $alias] = $count; |
520 | 542 | } |
521 | 543 | |
@@ -592,8 +614,12 @@ discard block |
||
592 | 614 | */ |
593 | 615 | function authUrl($immediate = false) |
594 | 616 | { |
595 | - if ($this->setup_url && !$immediate) return $this->setup_url; |
|
596 | - if (!$this->server) $this->discover($this->identity); |
|
617 | + if ($this->setup_url && !$immediate) { |
|
618 | + return $this->setup_url; |
|
619 | + } |
|
620 | + if (!$this->server) { |
|
621 | + $this->discover($this->identity); |
|
622 | + } |
|
597 | 623 | |
598 | 624 | if ($this->version == 2) { |
599 | 625 | return $this->authUrl_v2($immediate); |
@@ -29,6 +29,9 @@ discard block |
||
29 | 29 | // return a column title (Average or Total), |
30 | 30 | // hyperlinked if this is not the current sort column |
31 | 31 | // |
32 | +/** |
|
33 | + * @param integer $i |
|
34 | + */ |
|
32 | 35 | function col_title($is_team, $app, $appid, $is_total, $i) { |
33 | 36 | $x = $i?"Total":"Average"; |
34 | 37 | if ($app->id == $appid && ($is_total?$i:!$i)) { |
@@ -62,6 +65,9 @@ discard block |
||
62 | 65 | |
63 | 66 | // show a user or team, with their credit for each app |
64 | 67 | // |
68 | +/** |
|
69 | + * @param integer $i |
|
70 | + */ |
|
65 | 71 | function show_row($item, $apps, $is_team, $i) { |
66 | 72 | if ($is_team) { |
67 | 73 | $team = BoincTeam::lookup_id($item->teamid); |
@@ -96,6 +102,9 @@ discard block |
||
96 | 102 | echo "</tr>\n"; |
97 | 103 | } |
98 | 104 | |
105 | +/** |
|
106 | + * @param string $appid |
|
107 | + */ |
|
99 | 108 | function show_list($is_team, $appid, $is_total) { |
100 | 109 | $x = $is_team?"teams":"participants"; |
101 | 110 | page_head("Top $x by application"); |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | // hyperlinked if this is not the current sort column |
31 | 31 | // |
32 | 32 | function col_title($is_team, $app, $appid, $is_total, $i) { |
33 | - $x = $i?"Total":"Average"; |
|
34 | - if ($app->id == $appid && ($is_total?$i:!$i)) { |
|
33 | + $x = $i ? "Total" : "Average"; |
|
34 | + if ($app->id == $appid && ($is_total ? $i : !$i)) { |
|
35 | 35 | return $x; |
36 | 36 | } else { |
37 | 37 | return "<a href=per_app_list.php?appid=$app->id&is_team=$is_team&is_total=$i>$x</a>"; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | echo "<tr>"; |
52 | 52 | echo "<th>Rank</th><th>Name</th>\n"; |
53 | 53 | foreach ($apps as $app) { |
54 | - for ($i=0; $i<2; $i++) { |
|
54 | + for ($i = 0; $i < 2; $i++) { |
|
55 | 55 | $x = col_title($is_team, $app, $appid, $is_total, $i); |
56 | 56 | echo "<th>$x</th>\n"; |
57 | 57 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | } else { |
71 | 71 | $user = BoincUser::lookup_id($item->userid); |
72 | 72 | if (!$user) return; |
73 | - $x= "<td>".user_links($user, BADGE_HEIGHT_MEDIUM)."</td>\n"; |
|
73 | + $x = "<td>".user_links($user, BADGE_HEIGHT_MEDIUM)."</td>\n"; |
|
74 | 74 | } |
75 | 75 | echo "<tr>"; |
76 | 76 | echo "<td>$i</td>\n"; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | function show_list($is_team, $appid, $is_total) { |
100 | - $x = $is_team?"teams":"participants"; |
|
100 | + $x = $is_team ? "teams" : "participants"; |
|
101 | 101 | page_head("Top $x by application"); |
102 | 102 | $apps = BoincApp::enum("deprecated=0"); |
103 | 103 | if (!$appid) { |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | } |
106 | 106 | start_table('table-striped'); |
107 | 107 | show_header($is_team, $apps, $appid, $is_total); |
108 | - $x = $is_total?"total":"expavg"; |
|
108 | + $x = $is_total ? "total" : "expavg"; |
|
109 | 109 | if ($is_team) { |
110 | 110 | $items = BoincCreditTeam::enum("appid=$appid order by $x desc"); |
111 | 111 | } else { |
@@ -65,11 +65,15 @@ |
||
65 | 65 | function show_row($item, $apps, $is_team, $i) { |
66 | 66 | if ($is_team) { |
67 | 67 | $team = BoincTeam::lookup_id($item->teamid); |
68 | - if (!$team) return; |
|
68 | + if (!$team) { |
|
69 | + return; |
|
70 | + } |
|
69 | 71 | $x = "<td>".team_links($team)."</td>\n"; |
70 | 72 | } else { |
71 | 73 | $user = BoincUser::lookup_id($item->userid); |
72 | - if (!$user) return; |
|
74 | + if (!$user) { |
|
75 | + return; |
|
76 | + } |
|
73 | 77 | $x= "<td>".user_links($user, BADGE_HEIGHT_MEDIUM)."</td>\n"; |
74 | 78 | } |
75 | 79 | echo "<tr>"; |
@@ -88,17 +88,26 @@ discard block |
||
88 | 88 | "; |
89 | 89 | } |
90 | 90 | |
91 | +/** |
|
92 | + * @param string $name |
|
93 | + */ |
|
91 | 94 | function item_xml($name, $val) { |
92 | 95 | if (!$val) $val = 0; |
93 | 96 | echo " <$name>$val</$name>\n"; |
94 | 97 | } |
95 | 98 | |
99 | +/** |
|
100 | + * @param string $name |
|
101 | + */ |
|
96 | 102 | function item_html($name, $val) { |
97 | 103 | $name = tra($name); |
98 | 104 | echo "<tr><td>$name</td><td>$val</td></tr>\n"; |
99 | 105 | //echo "<tr><td align=right>$name</td><td align=right>$val</td></tr>\n"; |
100 | 106 | } |
101 | 107 | |
108 | +/** |
|
109 | + * @param stdClass $x |
|
110 | + */ |
|
102 | 111 | function show_status_html($x) { |
103 | 112 | page_head(tra("Project status")); |
104 | 113 | $j = $x->jobs; |
@@ -190,6 +199,9 @@ discard block |
||
190 | 199 | page_tail(); |
191 | 200 | } |
192 | 201 | |
202 | +/** |
|
203 | + * @param stdClass $x |
|
204 | + */ |
|
193 | 205 | function show_status_xml($x) { |
194 | 206 | xml_header(); |
195 | 207 | echo "<server_status>\n<daemon_status>\n"; |
@@ -239,6 +251,11 @@ discard block |
||
239 | 251 | "; |
240 | 252 | } |
241 | 253 | |
254 | +/** |
|
255 | + * @param string $cmd |
|
256 | + * @param string $pidname |
|
257 | + * @param string $host |
|
258 | + */ |
|
242 | 259 | function local_daemon_running($cmd, $pidname, $host) { |
243 | 260 | if (!$pidname) { |
244 | 261 | $cmd = trim($cmd); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $avg = round($app->info->avg, 2); |
172 | 172 | $min = round($app->info->min, 2); |
173 | 173 | $max = round($app->info->max, 2); |
174 | - $x = $max?"$avg ($min - $max)":"---"; |
|
174 | + $x = $max ? "$avg ($min - $max)" : "---"; |
|
175 | 175 | $u = $app->info->users; |
176 | 176 | echo "<tr> |
177 | 177 | <td>$app->user_friendly_name</td> |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | $cmd = trim($cmd); |
245 | 245 | $x = explode(" ", $cmd); |
246 | 246 | $prog = $x[0]; |
247 | - $pidname = $prog . '.pid'; |
|
247 | + $pidname = $prog.'.pid'; |
|
248 | 248 | } |
249 | 249 | $path = "../../pid_$host/$pidname"; |
250 | 250 | if (is_file($path)) { |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | } |
286 | 286 | $master_host = $u["host"]; |
287 | 287 | if ($config->www_host) { |
288 | - $web_host = trim((string) $config->www_host); |
|
288 | + $web_host = trim((string)$config->www_host); |
|
289 | 289 | } else { |
290 | 290 | $web_host = $main_host; |
291 | 291 | } |
292 | 292 | if ($config->sched_host) { |
293 | - $sched_host = trim((string) $config->sched_host); |
|
293 | + $sched_host = trim((string)$config->sched_host); |
|
294 | 294 | } else { |
295 | 295 | $sched_host = $main_host; |
296 | 296 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | |
301 | 301 | // the upload and download servers are sort of daemons too |
302 | 302 | // |
303 | - $url = trim((string) $config->download_url); |
|
303 | + $url = trim((string)$config->download_url); |
|
304 | 304 | $u = parse_url($url); |
305 | 305 | $h = $u["host"]; |
306 | 306 | if ($h == $master_host) { |
@@ -312,14 +312,14 @@ discard block |
||
312 | 312 | } else { |
313 | 313 | $have_remote = true; |
314 | 314 | } |
315 | - $url = trim((string) $config->upload_url); |
|
315 | + $url = trim((string)$config->upload_url); |
|
316 | 316 | $u = parse_url($url); |
317 | 317 | $h = $u["host"]; |
318 | 318 | if ($h == $master_host) { |
319 | 319 | $y = new StdClass; |
320 | 320 | $y->cmd = "Upload server"; |
321 | 321 | $y->host = $h; |
322 | - $y->status = !file_exists("../../stop_upload");; |
|
322 | + $y->status = !file_exists("../../stop_upload"); ; |
|
323 | 323 | $local_daemons[] = $y; |
324 | 324 | } else { |
325 | 325 | $have_remote = true; |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | $y = new StdClass; |
332 | 332 | $y->cmd = "Scheduler"; |
333 | 333 | $y->host = $sched_host; |
334 | - $y->status = !file_exists("../../stop_sched");; |
|
334 | + $y->status = !file_exists("../../stop_sched"); ; |
|
335 | 335 | $local_daemons[] = $y; |
336 | 336 | } else { |
337 | 337 | $have_remote = true; |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | $disabled_daemons[] = $x; |
348 | 348 | continue; |
349 | 349 | } |
350 | - $host = $d->host?(string)$d->host:$main_host; |
|
350 | + $host = $d->host ? (string)$d->host : $main_host; |
|
351 | 351 | if ($host != $web_host) { |
352 | 352 | $have_remote = true; |
353 | 353 | continue; |
@@ -89,7 +89,9 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | function item_xml($name, $val) { |
92 | - if (!$val) $val = 0; |
|
92 | + if (!$val) { |
|
93 | + $val = 0; |
|
94 | + } |
|
93 | 95 | echo " <$name>$val</$name>\n"; |
94 | 96 | } |
95 | 97 | |
@@ -254,7 +256,9 @@ discard block |
||
254 | 256 | $out = Array(); |
255 | 257 | exec("ps -ww $pid", $out); |
256 | 258 | foreach ($out as $y) { |
257 | - if (strstr($y, (string)$pid)) return 1; |
|
259 | + if (strstr($y, (string)$pid)) { |
|
260 | + return 1; |
|
261 | + } |
|
258 | 262 | } |
259 | 263 | } |
260 | 264 | } |
@@ -342,7 +346,9 @@ discard block |
||
342 | 346 | $x = new StdClass; |
343 | 347 | $x->cmd = (string)$d->cmd; |
344 | 348 | $x->host = (string)$d->host; |
345 | - if (!$x->host) $x->host = $main_host; |
|
349 | + if (!$x->host) { |
|
350 | + $x->host = $main_host; |
|
351 | + } |
|
346 | 352 | $x->status = -1; |
347 | 353 | $disabled_daemons[] = $x; |
348 | 354 | continue; |
@@ -429,7 +435,9 @@ discard block |
||
429 | 435 | |
430 | 436 | $s->cached_time = time(); |
431 | 437 | $e = set_cached_data(STATUS_PAGE_TTL, serialize($s), "job_status"); |
432 | - if ($e) echo "set_cached_data(): $e\n"; |
|
438 | + if ($e) { |
|
439 | + echo "set_cached_data(): $e\n"; |
|
440 | + } |
|
433 | 441 | return $s; |
434 | 442 | } |
435 | 443 |
@@ -25,6 +25,9 @@ |
||
25 | 25 | |
26 | 26 | check_get_args(array("mode")); |
27 | 27 | |
28 | +/** |
|
29 | + * @param string $mode |
|
30 | + */ |
|
28 | 31 | function filename($mode) { |
29 | 32 | switch ($mode) { |
30 | 33 | case 'host': return "cuda_hosts.dat"; |
@@ -92,7 +92,7 @@ |
||
92 | 92 | echo $x; |
93 | 93 | break; |
94 | 94 | } |
95 | - echo "</td><td align=right>".format_credit_large($y->credit),"</td><td align=right>$y->nresults</td></tr>\n"; |
|
95 | + echo "</td><td align=right>".format_credit_large($y->credit), "</td><td align=right>$y->nresults</td></tr>\n"; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $mode = get_str('mode', true); |
@@ -37,6 +37,9 @@ discard block |
||
37 | 37 | return $n; |
38 | 38 | } |
39 | 39 | |
40 | +/** |
|
41 | + * @param integer $state |
|
42 | + */ |
|
40 | 43 | function show_all_link($batches, $state, $limit, $user, $app) { |
41 | 44 | $n = state_count($batches, $state); |
42 | 45 | if ($n > $limit) { |
@@ -269,6 +272,9 @@ discard block |
||
269 | 272 | page_tail(); |
270 | 273 | } |
271 | 274 | |
275 | +/** |
|
276 | + * @param null|integer $app_id |
|
277 | + */ |
|
272 | 278 | function check_admin_access($user, $app_id) { |
273 | 279 | $user_submit = BoincUserSubmit::lookup_userid($user->id); |
274 | 280 | if (!$user_submit) error_page("no access"); |
@@ -523,6 +529,9 @@ discard block |
||
523 | 529 | page_tail(); |
524 | 530 | } |
525 | 531 | |
532 | +/** |
|
533 | + * @param null|integer $state |
|
534 | + */ |
|
526 | 535 | function show_batches_in_state($batches, $state) { |
527 | 536 | switch ($state) { |
528 | 537 | case BATCH_STATE_IN_PROGRESS: |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | } |
324 | 324 | row2("GFLOP/hours, estimated", number_format(credit_to_gflop_hours($batch->credit_estimate), 2)); |
325 | 325 | row2("GFLOP/hours, actual", number_format(credit_to_gflop_hours($batch->credit_canonical), 2)); |
326 | - row2("Output File Size (MB)", number_format(batch_output_file_size($batch->id)/1e6,2)); |
|
326 | + row2("Output File Size (MB)", number_format(batch_output_file_size($batch->id)/1e6, 2)); |
|
327 | 327 | end_table(); |
328 | 328 | if (batch_output_file_size($batch->id) <= 1e8) { |
329 | 329 | $url = boinc_get_output_files_url($user, $batch_id); |
@@ -357,9 +357,9 @@ discard block |
||
357 | 357 | "Canonical instance<br><p class=\"text-muted\">click to see result page on BOINC server</p>", |
358 | 358 | "Download Results" |
359 | 359 | ); |
360 | - foreach($wus as $wu) { |
|
360 | + foreach ($wus as $wu) { |
|
361 | 361 | $resultid = $wu->canonical_resultid; |
362 | - $durl = boinc_get_wu_output_files_url($user,$wu->id); |
|
362 | + $durl = boinc_get_wu_output_files_url($user, $wu->id); |
|
363 | 363 | if ($resultid) { |
364 | 364 | $x = "<a href=result.php?resultid=$resultid>$resultid</a>"; |
365 | 365 | $y = '<font color="green">completed</font>'; |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | $text = "---"; |
370 | 370 | if ($batch->state == BATCH_STATE_COMPLETE) { |
371 | 371 | $y = '<font color="red">failed</font>'; |
372 | - } else { |
|
372 | + } else { |
|
373 | 373 | $y = "in progress"; |
374 | 374 | } |
375 | 375 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | $results = BoincResult::enum("workunitid=$wuid"); |
435 | 435 | $upload_dir = parse_config(get_config(), "<upload_dir>"); |
436 | 436 | $fanout = parse_config(get_config(), "<uldl_dir_fanout>"); |
437 | - foreach($results as $result) { |
|
437 | + foreach ($results as $result) { |
|
438 | 438 | echo "<tr> |
439 | 439 | <td><a href=result.php?resultid=$result->id>$result->id · $result->name </a></td> |
440 | 440 | <td>".state_string($result)."</td> |
@@ -32,7 +32,9 @@ discard block |
||
32 | 32 | function state_count($batches, $state) { |
33 | 33 | $n = 0; |
34 | 34 | foreach ($batches as $batch) { |
35 | - if ($batch->state == $state) $n++; |
|
35 | + if ($batch->state == $state) { |
|
36 | + $n++; |
|
37 | + } |
|
36 | 38 | } |
37 | 39 | return $n; |
38 | 40 | } |
@@ -40,10 +42,16 @@ discard block |
||
40 | 42 | function show_all_link($batches, $state, $limit, $user, $app) { |
41 | 43 | $n = state_count($batches, $state); |
42 | 44 | if ($n > $limit) { |
43 | - if ($user) $userid = $user->id; |
|
44 | - else $userid = 0; |
|
45 | - if ($app) $appid = $app->id; |
|
46 | - else $appid = 0; |
|
45 | + if ($user) { |
|
46 | + $userid = $user->id; |
|
47 | + } else { |
|
48 | + $userid = 0; |
|
49 | + } |
|
50 | + if ($app) { |
|
51 | + $appid = $app->id; |
|
52 | + } else { |
|
53 | + $appid = 0; |
|
54 | + } |
|
47 | 55 | |
48 | 56 | echo "Showing the most recent $limit of $n batches. |
49 | 57 | <a href=submit.php?action=show_all&state=$state&userid=$userid&appid=$appid>Show all $n</a> |
@@ -56,8 +64,12 @@ discard block |
||
56 | 64 | $first = true; |
57 | 65 | $n = 0; |
58 | 66 | foreach ($batches as $batch) { |
59 | - if ($batch->state != BATCH_STATE_IN_PROGRESS) continue; |
|
60 | - if ($limit && $n == $limit) break; |
|
67 | + if ($batch->state != BATCH_STATE_IN_PROGRESS) { |
|
68 | + continue; |
|
69 | + } |
|
70 | + if ($limit && $n == $limit) { |
|
71 | + break; |
|
72 | + } |
|
61 | 73 | $n++; |
62 | 74 | if ($first) { |
63 | 75 | $first = false; |
@@ -100,8 +112,12 @@ discard block |
||
100 | 112 | $first = true; |
101 | 113 | $n = 0; |
102 | 114 | foreach ($batches as $batch) { |
103 | - if ($batch->state != BATCH_STATE_COMPLETE) continue; |
|
104 | - if ($limit && $n == $limit) break; |
|
115 | + if ($batch->state != BATCH_STATE_COMPLETE) { |
|
116 | + continue; |
|
117 | + } |
|
118 | + if ($limit && $n == $limit) { |
|
119 | + break; |
|
120 | + } |
|
105 | 121 | $n++; |
106 | 122 | if ($first) { |
107 | 123 | $first = false; |
@@ -132,8 +148,12 @@ discard block |
||
132 | 148 | $first = true; |
133 | 149 | $n = 0; |
134 | 150 | foreach ($batches as $batch) { |
135 | - if ($batch->state != BATCH_STATE_ABORTED) continue; |
|
136 | - if ($limit && $n == $limit) break; |
|
151 | + if ($batch->state != BATCH_STATE_ABORTED) { |
|
152 | + continue; |
|
153 | + } |
|
154 | + if ($limit && $n == $limit) { |
|
155 | + break; |
|
156 | + } |
|
137 | 157 | $n++; |
138 | 158 | if ($first) { |
139 | 159 | $first = false; |
@@ -212,7 +232,9 @@ discard block |
||
212 | 232 | foreach ($submit_urls as $appname=>$submit_url) { |
213 | 233 | $appname = BoincDb::escape_string($appname); |
214 | 234 | $app = BoincApp::lookup("name='$appname'"); |
215 | - if (!$app) error_page("bad submit_url name: $appname"); |
|
235 | + if (!$app) { |
|
236 | + error_page("bad submit_url name: $appname"); |
|
237 | + } |
|
216 | 238 | $usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$app->id"); |
217 | 239 | if ($usa || $user_submit->submit_all) { |
218 | 240 | echo "<li> <a href=$submit_url> $app->user_friendly_name </a>"; |
@@ -271,14 +293,20 @@ discard block |
||
271 | 293 | |
272 | 294 | function check_admin_access($user, $app_id) { |
273 | 295 | $user_submit = BoincUserSubmit::lookup_userid($user->id); |
274 | - if (!$user_submit) error_page("no access"); |
|
296 | + if (!$user_submit) { |
|
297 | + error_page("no access"); |
|
298 | + } |
|
275 | 299 | if ($app_id) { |
276 | 300 | if (!$user_submit->manage_all) { |
277 | 301 | $usa = BoincUserSubmitApp::lookup("user_id = $user->id and app_id=$app_id"); |
278 | - if (!$usa) error_page("no access"); |
|
302 | + if (!$usa) { |
|
303 | + error_page("no access"); |
|
304 | + } |
|
279 | 305 | } |
280 | 306 | } else { |
281 | - if (!$user_submit->manage_all) error_page("no access"); |
|
307 | + if (!$user_submit->manage_all) { |
|
308 | + error_page("no access"); |
|
309 | + } |
|
282 | 310 | } |
283 | 311 | } |
284 | 312 | |
@@ -287,7 +315,9 @@ discard block |
||
287 | 315 | check_admin_access($user, $app_id); |
288 | 316 | if ($app_id) { |
289 | 317 | $app = BoincApp::lookup_id($app_id); |
290 | - if (!$app) error_page("no such app"); |
|
318 | + if (!$app) { |
|
319 | + error_page("no such app"); |
|
320 | + } |
|
291 | 321 | page_head("Administer batches for $app->user_friendly_name"); |
292 | 322 | $batches = BoincBatch::enum("app_id = $app_id order by id desc"); |
293 | 323 | show_batches($batches, PAGE_SIZE, null, $app); |
@@ -369,7 +399,7 @@ discard block |
||
369 | 399 | $text = "---"; |
370 | 400 | if ($batch->state == BATCH_STATE_COMPLETE) { |
371 | 401 | $y = '<font color="red">failed</font>'; |
372 | - } else { |
|
402 | + } else { |
|
373 | 403 | $y = "in progress"; |
374 | 404 | } |
375 | 405 | } |
@@ -391,7 +421,9 @@ discard block |
||
391 | 421 | function handle_query_job($user) { |
392 | 422 | $wuid = get_int('wuid'); |
393 | 423 | $wu = BoincWorkunit::lookup_id($wuid); |
394 | - if (!$wu) error_page("no such job"); |
|
424 | + if (!$wu) { |
|
425 | + error_page("no such job"); |
|
426 | + } |
|
395 | 427 | |
396 | 428 | page_head("Job $wuid"); |
397 | 429 | |
@@ -477,18 +509,26 @@ discard block |
||
477 | 509 | } |
478 | 510 | |
479 | 511 | function check_access($user, $batch) { |
480 | - if ($user->id == $batch->user_id) return; |
|
512 | + if ($user->id == $batch->user_id) { |
|
513 | + return; |
|
514 | + } |
|
481 | 515 | $user_submit = BoincUserSubmit::lookup_userid($user->id); |
482 | - if ($user_submit->manage_all) return; |
|
516 | + if ($user_submit->manage_all) { |
|
517 | + return; |
|
518 | + } |
|
483 | 519 | $usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$batch->app_id"); |
484 | - if ($usa->manage) return; |
|
520 | + if ($usa->manage) { |
|
521 | + return; |
|
522 | + } |
|
485 | 523 | error_page("no access"); |
486 | 524 | } |
487 | 525 | |
488 | 526 | function handle_abort_batch($user) { |
489 | 527 | $batch_id = get_int('batch_id'); |
490 | 528 | $batch = BoincBatch::lookup_id($batch_id); |
491 | - if (!$batch) error_page("no such batch"); |
|
529 | + if (!$batch) { |
|
530 | + error_page("no such batch"); |
|
531 | + } |
|
492 | 532 | check_access($user, $batch); |
493 | 533 | abort_batch($batch); |
494 | 534 | page_head("Batch aborted"); |
@@ -515,7 +555,9 @@ discard block |
||
515 | 555 | function handle_retire_batch($user) { |
516 | 556 | $batch_id = get_int('batch_id'); |
517 | 557 | $batch = BoincBatch::lookup_id($batch_id); |
518 | - if (!$batch) error_page("no such batch"); |
|
558 | + if (!$batch) { |
|
559 | + error_page("no such batch"); |
|
560 | + } |
|
519 | 561 | check_access($user, $batch); |
520 | 562 | retire_batch($batch); |
521 | 563 | page_head("Batch retired"); |
@@ -548,7 +590,9 @@ discard block |
||
548 | 590 | if ($userid) { |
549 | 591 | // user looking at their own batches |
550 | 592 | // |
551 | - if ($userid != $user->id) error_page("wrong user"); |
|
593 | + if ($userid != $user->id) { |
|
594 | + error_page("wrong user"); |
|
595 | + } |
|
552 | 596 | $batches = BoincBatch::enum("user_id = $user->id and state=$state order by id desc"); |
553 | 597 | fill_in_app_and_user_names($batches); |
554 | 598 | show_batches_in_state($batches, $state); |
@@ -558,7 +602,9 @@ discard block |
||
558 | 602 | check_admin_access($user, $appid); |
559 | 603 | if ($appid) { |
560 | 604 | $app = BoincApp::lookup_id($appid); |
561 | - if (!$app) error_page("no such app"); |
|
605 | + if (!$app) { |
|
606 | + error_page("no such app"); |
|
607 | + } |
|
562 | 608 | $batches = BoincBatch::enum("app_id = $appid and state=$state order by id desc"); |
563 | 609 | } else { |
564 | 610 | $batches = BoincBatch::enum("state=$state order by id desc"); |
@@ -30,6 +30,9 @@ discard block |
||
30 | 30 | ini_set('display_errors', true); |
31 | 31 | ini_set('display_startup_errors', true); |
32 | 32 | |
33 | +/** |
|
34 | + * @param string $name |
|
35 | + */ |
|
33 | 36 | function get_wu($name) { |
34 | 37 | $name = BoincDb::escape_string($name); |
35 | 38 | $wu = BoincWorkunit::lookup("name='$name'"); |
@@ -37,6 +40,9 @@ discard block |
||
37 | 40 | return $wu; |
38 | 41 | } |
39 | 42 | |
43 | +/** |
|
44 | + * @param string $name |
|
45 | + */ |
|
40 | 46 | function get_submit_app($name) { |
41 | 47 | $name = BoincDb::escape_string($name); |
42 | 48 | $app = BoincApp::lookup("name='$name'"); |
@@ -76,6 +82,9 @@ discard block |
||
76 | 82 | return $y; |
77 | 83 | } |
78 | 84 | |
85 | +/** |
|
86 | + * @param SimpleXMLElement|null $template |
|
87 | + */ |
|
79 | 88 | function est_elapsed_time($r, $template) { |
80 | 89 | // crude estimate: batch FLOPs / project FLOPS |
81 | 90 | // |
@@ -122,6 +131,9 @@ discard block |
||
122 | 131 | "; |
123 | 132 | } |
124 | 133 | |
134 | +/** |
|
135 | + * @param SimpleXMLElement $template |
|
136 | + */ |
|
125 | 137 | function validate_batch($jobs, $template) { |
126 | 138 | $i = 0; |
127 | 139 | $n = count($template->file_info); |
@@ -191,6 +203,10 @@ discard block |
||
191 | 203 | |
192 | 204 | // submit a list of jobs with a single create_work command. |
193 | 205 | // |
206 | +/** |
|
207 | + * @param SimpleXMLElement|null $template |
|
208 | + * @param double $priority |
|
209 | + */ |
|
194 | 210 | function submit_jobs( |
195 | 211 | $jobs, $template, $app, $batch_id, $priority, |
196 | 212 | $result_template_file, // batch-level; can also specify per job |
@@ -267,6 +283,9 @@ discard block |
||
267 | 283 | // Check whether the template is already in our map. |
268 | 284 | // If not, write it to a temp file. |
269 | 285 | // |
286 | +/** |
|
287 | + * @param stdClass $job |
|
288 | + */ |
|
270 | 289 | function make_wu_template($job) { |
271 | 290 | global $wu_templates; |
272 | 291 | if (!array_key_exists($job->wu_template, $wu_templates)) { |
@@ -283,6 +302,9 @@ discard block |
||
283 | 302 | // A little different because these have to exist for life of job. |
284 | 303 | // Store them in templates/tmp/, with content-based filenames |
285 | 304 | // |
305 | +/** |
|
306 | + * @param stdClass $job |
|
307 | + */ |
|
286 | 308 | function make_result_template($job) { |
287 | 309 | global $result_templates; |
288 | 310 | if (!array_key_exists($job->result_template, $result_templates)) { |
@@ -468,6 +490,9 @@ discard block |
||
468 | 490 | "; |
469 | 491 | } |
470 | 492 | |
493 | +/** |
|
494 | + * @param integer $get_cpu_time |
|
495 | + */ |
|
471 | 496 | function print_batch_params($batch, $get_cpu_time) { |
472 | 497 | $app = BoincApp::lookup_id($batch->app_id); |
473 | 498 | if (!$app) $app->name = "none"; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | if ($template) { |
55 | 55 | $t = (double)$template->workunit->rsc_fpops_est; |
56 | 56 | } |
57 | - foreach($r->batch->job as $job) { |
|
57 | + foreach ($r->batch->job as $job) { |
|
58 | 58 | $y = (double)$job->rsc_fpops_est; |
59 | 59 | if ($y) { |
60 | 60 | $x += $y; |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | function est_elapsed_time($r, $template) { |
80 | 80 | // crude estimate: batch FLOPs / project FLOPS |
81 | 81 | // |
82 | - return batch_flop_count($r, $template) / project_flops(); |
|
82 | + return batch_flop_count($r, $template)/project_flops(); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | function read_input_template($app, $r) { |
86 | 86 | if ((isset($r->batch)) && (isset($r->batch->workunit_template_file)) && ($r->batch->workunit_template_file)) { |
87 | - $path = project_dir() . "/templates/".$r->batch->workunit_template_file; |
|
87 | + $path = project_dir()."/templates/".$r->batch->workunit_template_file; |
|
88 | 88 | } else { |
89 | - $path = project_dir() . "/templates/$app->name"."_in"; |
|
89 | + $path = project_dir()."/templates/$app->name"."_in"; |
|
90 | 90 | } |
91 | 91 | if (file_exists($path)) { |
92 | 92 | $x = simplexml_load_file($path); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | function validate_batch($jobs, $template) { |
126 | 126 | $i = 0; |
127 | 127 | $n = count($template->file_info); |
128 | - foreach($jobs as $job) { |
|
128 | + foreach ($jobs as $job) { |
|
129 | 129 | $m = count($job->input_files); |
130 | 130 | if ($n != $m) { |
131 | 131 | xml_error(-1, "BOINC server: wrong # of input files for job $i: need $n, got $m"); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | // stage all the files |
181 | 181 | // |
182 | 182 | function stage_files(&$jobs) { |
183 | - foreach($jobs as $job) { |
|
183 | + foreach ($jobs as $job) { |
|
184 | 184 | foreach ($job->input_files as $file) { |
185 | 185 | if ($file->mode != "remote") { |
186 | 186 | $file->name = stage_file($file); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | // |
194 | 194 | function submit_jobs( |
195 | 195 | $jobs, $template, $app, $batch_id, $priority, |
196 | - $result_template_file, // batch-level; can also specify per job |
|
196 | + $result_template_file, // batch-level; can also specify per job |
|
197 | 197 | $workunit_template_file |
198 | 198 | ) { |
199 | 199 | global $wu_templates, $result_templates; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | // one line per job |
203 | 203 | // |
204 | 204 | $x = ""; |
205 | - foreach($jobs as $job) { |
|
205 | + foreach ($jobs as $job) { |
|
206 | 206 | if ($job->name) { |
207 | 207 | $x .= " --wu_name $job->name"; |
208 | 208 | } |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | $x .= "\n"; |
235 | 235 | } |
236 | 236 | |
237 | - $errfile = "/tmp/create_work_" . getmypid() . ".err"; |
|
238 | - $cmd = "cd " . project_dir() . "; ./bin/create_work --appname $app->name --batch $batch_id --priority $priority"; |
|
237 | + $errfile = "/tmp/create_work_".getmypid().".err"; |
|
238 | + $cmd = "cd ".project_dir()."; ./bin/create_work --appname $app->name --batch $batch_id --priority $priority"; |
|
239 | 239 | if ($result_template_file) { |
240 | 240 | $cmd .= " --result_template templates/$result_template_file"; |
241 | 241 | } |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | // |
314 | 314 | function xml_get_jobs($r) { |
315 | 315 | $jobs = array(); |
316 | - foreach($r->batch->job as $j) { |
|
316 | + foreach ($r->batch->job as $j) { |
|
317 | 317 | $job = new StdClass; |
318 | 318 | $job->input_files = array(); |
319 | 319 | $job->command_line = (string)$j->command_line; |
@@ -384,11 +384,11 @@ discard block |
||
384 | 384 | // - use that for batch logical end time and job priority |
385 | 385 | // |
386 | 386 | $total_flops = 0; |
387 | - foreach($jobs as $job) { |
|
387 | + foreach ($jobs as $job) { |
|
388 | 388 | if ($job->rsc_fpops_est) { |
389 | 389 | $total_flops += $job->rsc_fpops_est; |
390 | 390 | } else { |
391 | - $x = (double) $template->workunit->rsc_fpops_est; |
|
391 | + $x = (double)$template->workunit->rsc_fpops_est; |
|
392 | 392 | if ($x) { |
393 | 393 | $total_flops += $x; |
394 | 394 | } else { |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | } |
397 | 397 | } |
398 | 398 | } |
399 | - $cmd = "cd " . project_dir() . "/bin; ./adjust_user_priority --user $user->id --flops $total_flops --app $app->name"; |
|
399 | + $cmd = "cd ".project_dir()."/bin; ./adjust_user_priority --user $user->id --flops $total_flops --app $app->name"; |
|
400 | 400 | $x = exec($cmd); |
401 | 401 | if (!is_numeric($x) || (double)$x == 0) { |
402 | 402 | xml_error(-1, "BOINC server: $cmd returned $x"); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | } |
511 | 511 | |
512 | 512 | function n_outfiles($wu) { |
513 | - $path = project_dir() . "/$wu->result_template_file"; |
|
513 | + $path = project_dir()."/$wu->result_template_file"; |
|
514 | 514 | $r = simplexml_load_file($path); |
515 | 515 | return count($r->file_info); |
516 | 516 | } |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | "; |
694 | 694 | if ($result->server_state == 5) { // over? |
695 | 695 | $paths = get_outfile_paths($result); |
696 | - foreach($paths as $path) { |
|
696 | + foreach ($paths as $path) { |
|
697 | 697 | if (is_file($path)) { |
698 | 698 | $size = filesize($path); |
699 | 699 | echo " <outfile> |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | } else { |
734 | 734 | $results = BoincResult::enum("workunitid=$job_id"); |
735 | 735 | foreach ($results as $r) { |
736 | - switch($r->outcome) { |
|
736 | + switch ($r->outcome) { |
|
737 | 737 | case 1: |
738 | 738 | case 3: |
739 | 739 | case 6: |
@@ -841,8 +841,8 @@ discard block |
||
841 | 841 | } |
842 | 842 | |
843 | 843 | list($user, $user_submit) = authenticate_user($r, $app); |
844 | - $in = file_get_contents(project_dir() . "/templates/".$app->name."_in"); |
|
845 | - $out = file_get_contents(project_dir() . "/templates/".$app->name."_out"); |
|
844 | + $in = file_get_contents(project_dir()."/templates/".$app->name."_in"); |
|
845 | + $out = file_get_contents(project_dir()."/templates/".$app->name."_out"); |
|
846 | 846 | if ($in === false || $out === false) { |
847 | 847 | xml_error(-1, "template file missing"); |
848 | 848 | } |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | |
854 | 854 | function ping($r) { |
855 | 855 | xml_start_tag("ping"); |
856 | - BoincDb::get(); // errors out if DB down or web disabled |
|
856 | + BoincDb::get(); // errors out if DB down or web disabled |
|
857 | 857 | echo "<success>1</success> |
858 | 858 | </ping> |
859 | 859 | "; |
@@ -907,10 +907,10 @@ discard block |
||
907 | 907 | if ($request_log) { |
908 | 908 | $request_log_dir = parse_config(get_config(), "<log_dir>"); |
909 | 909 | if ($request_log_dir) { |
910 | - $request_log = $request_log_dir . "/" . $request_log; |
|
910 | + $request_log = $request_log_dir."/".$request_log; |
|
911 | 911 | } |
912 | 912 | if ($file = fopen($request_log, "a+")) { |
913 | - fwrite($file, "\n<submit_rpc_handler date=\"" . date(DATE_ATOM) . "\">\n" . $_POST['request'] . "\n</submit_rpc_handler>\n"); |
|
913 | + fwrite($file, "\n<submit_rpc_handler date=\"".date(DATE_ATOM)."\">\n".$_POST['request']."\n</submit_rpc_handler>\n"); |
|
914 | 914 | fclose($file); |
915 | 915 | } |
916 | 916 | } |
@@ -33,14 +33,18 @@ discard block |
||
33 | 33 | function get_wu($name) { |
34 | 34 | $name = BoincDb::escape_string($name); |
35 | 35 | $wu = BoincWorkunit::lookup("name='$name'"); |
36 | - if (!$wu) xml_error(-1, "BOINC server: no job named $name was found"); |
|
36 | + if (!$wu) { |
|
37 | + xml_error(-1, "BOINC server: no job named $name was found"); |
|
38 | + } |
|
37 | 39 | return $wu; |
38 | 40 | } |
39 | 41 | |
40 | 42 | function get_submit_app($name) { |
41 | 43 | $name = BoincDb::escape_string($name); |
42 | 44 | $app = BoincApp::lookup("name='$name'"); |
43 | - if (!$app) xml_error(-1, "BOINC server: no app named $name was found"); |
|
45 | + if (!$app) { |
|
46 | + xml_error(-1, "BOINC server: no app named $name was found"); |
|
47 | + } |
|
44 | 48 | return $app; |
45 | 49 | } |
46 | 50 | |
@@ -71,7 +75,9 @@ discard block |
||
71 | 75 | // |
72 | 76 | function project_flops() { |
73 | 77 | $x = BoincUser::sum("expavg_credit"); |
74 | - if ($x == 0) $x = 200; |
|
78 | + if ($x == 0) { |
|
79 | + $x = 200; |
|
80 | + } |
|
75 | 81 | $y = 1e9*$x/200; |
76 | 82 | return $y; |
77 | 83 | } |
@@ -100,11 +106,15 @@ discard block |
||
100 | 106 | } |
101 | 107 | |
102 | 108 | function check_max_jobs_in_progress($r, $user_submit) { |
103 | - if (!$user_submit->max_jobs_in_progress) return; |
|
109 | + if (!$user_submit->max_jobs_in_progress) { |
|
110 | + return; |
|
111 | + } |
|
104 | 112 | $query = "select count(*) as total from DBNAME.result, DBNAME.batch where batch.user_id=$userid and result.batch = batch.id and result.server_state<".RESULT_SERVER_STATE_OVER; |
105 | 113 | $db = BoincDb::get(); |
106 | 114 | $n = $db->get_int($query); |
107 | - if ($n === false) return; |
|
115 | + if ($n === false) { |
|
116 | + return; |
|
117 | + } |
|
108 | 118 | if ($n + count($r->batch->job) > $user_submit->max_jobs_in_progress) { |
109 | 119 | xml_error(-1, "BOINC server: limit on jobs in progress exceeded"); |
110 | 120 | } |
@@ -154,7 +164,9 @@ discard block |
||
154 | 164 | } |
155 | 165 | $name = job_file_name($md5); |
156 | 166 | $path = dir_hier_path($name, $download_dir, $fanout); |
157 | - if (file_exists($path)) return $name; |
|
167 | + if (file_exists($path)) { |
|
168 | + return $name; |
|
169 | + } |
|
158 | 170 | if (!copy($file->source, $path)) { |
159 | 171 | xml_error(-1, "BOINC server: can't copy file from $file->source to $path"); |
160 | 172 | } |
@@ -168,7 +180,9 @@ discard block |
||
168 | 180 | } |
169 | 181 | $name = job_file_name($md5); |
170 | 182 | $path = dir_hier_path($name, $download_dir, $fanout); |
171 | - if (file_exists($path)) return $name; |
|
183 | + if (file_exists($path)) { |
|
184 | + return $name; |
|
185 | + } |
|
172 | 186 | if (!file_put_contents($path, $file->source)) { |
173 | 187 | xml_error(-1, "BOINC server: can't write to file $path"); |
174 | 188 | } |
@@ -406,7 +420,9 @@ discard block |
||
406 | 420 | if ($batch_id) { |
407 | 421 | $njobs = count($jobs); |
408 | 422 | $ret = $batch->update("njobs=$njobs, logical_end_time=$let"); |
409 | - if (!$ret) xml_error(-1, "BOINC server: batch->update() failed"); |
|
423 | + if (!$ret) { |
|
424 | + xml_error(-1, "BOINC server: batch->update() failed"); |
|
425 | + } |
|
410 | 426 | } else { |
411 | 427 | $batch_name = (string)($r->batch->batch_name); |
412 | 428 | $batch_name = BoincDb::escape_string($batch_name); |
@@ -440,7 +456,9 @@ discard block |
||
440 | 456 | // otherwise we might flag batch as COMPLETED |
441 | 457 | // |
442 | 458 | $ret = $batch->update("state= ".BATCH_STATE_IN_PROGRESS); |
443 | - if (!$ret) xml_error(-1, "BOINC server: batch->update() failed"); |
|
459 | + if (!$ret) { |
|
460 | + xml_error(-1, "BOINC server: batch->update() failed"); |
|
461 | + } |
|
444 | 462 | |
445 | 463 | echo "<batch_id>$batch_id</batch_id> |
446 | 464 | </submit_batch> |
@@ -470,7 +488,9 @@ discard block |
||
470 | 488 | |
471 | 489 | function print_batch_params($batch, $get_cpu_time) { |
472 | 490 | $app = BoincApp::lookup_id($batch->app_id); |
473 | - if (!$app) $app->name = "none"; |
|
491 | + if (!$app) { |
|
492 | + $app->name = "none"; |
|
493 | + } |
|
474 | 494 | echo " |
475 | 495 | <id>$batch->id</id> |
476 | 496 | <create_time>$batch->create_time</create_time> |
@@ -497,7 +517,9 @@ discard block |
||
497 | 517 | $batches = BoincBatch::enum("user_id = $user->id"); |
498 | 518 | $get_cpu_time = (int)($r->get_cpu_time); |
499 | 519 | foreach ($batches as $batch) { |
500 | - if ($batch->state == BATCH_STATE_RETIRED) continue; |
|
520 | + if ($batch->state == BATCH_STATE_RETIRED) { |
|
521 | + continue; |
|
522 | + } |
|
501 | 523 | if ($batch->state < BATCH_STATE_COMPLETE) { |
502 | 524 | $wus = BoincWorkunit::enum("batch = $batch->id"); |
503 | 525 | $batch = get_batch_params($batch, $wus); |
@@ -584,7 +606,9 @@ discard block |
||
584 | 606 | } else { |
585 | 607 | xml_error(-1, "BOINC server: batch not specified"); |
586 | 608 | } |
587 | - if (!$batch) xml_error(-1, "BOINC server: no such batch"); |
|
609 | + if (!$batch) { |
|
610 | + xml_error(-1, "BOINC server: no such batch"); |
|
611 | + } |
|
588 | 612 | return $batch; |
589 | 613 | } |
590 | 614 | |
@@ -679,7 +703,9 @@ discard block |
||
679 | 703 | list($user, $user_submit) = authenticate_user($r, null); |
680 | 704 | $job_id = (int)($r->job_id); |
681 | 705 | $wu = BoincWorkunit::lookup_id($job_id); |
682 | - if (!$wu) xml_error(-1, "no such job"); |
|
706 | + if (!$wu) { |
|
707 | + xml_error(-1, "no such job"); |
|
708 | + } |
|
683 | 709 | $batch = BoincBatch::lookup_id($wu->batch); |
684 | 710 | if ($batch->user_id != $user->id) { |
685 | 711 | xml_error(-1, "not owner"); |
@@ -719,7 +745,9 @@ discard block |
||
719 | 745 | $job_name = (string)($r->job_name); |
720 | 746 | $job_name = BoincDb::escape_string($job_name); |
721 | 747 | $wu = BoincWorkunit::lookup("name='$job_name'"); |
722 | - if (!$wu) xml_error(-1, "no such job"); |
|
748 | + if (!$wu) { |
|
749 | + xml_error(-1, "no such job"); |
|
750 | + } |
|
723 | 751 | $batch = BoincBatch::lookup_id($wu->batch); |
724 | 752 | if ($batch->user_id != $user->id) { |
725 | 753 | xml_error(-1, "not owner"); |
@@ -57,6 +57,9 @@ |
||
57 | 57 | edit_form($user, $team, $forum, true); |
58 | 58 | } |
59 | 59 | |
60 | +/** |
|
61 | + * @param boolean $first |
|
62 | + */ |
|
60 | 63 | function edit_form($user, $team, $forum, $first) { |
61 | 64 | page_head(tra("Team Message Board")); |
62 | 65 | echo " |
@@ -22,7 +22,9 @@ discard block |
||
22 | 22 | require_once("../inc/team.inc"); |
23 | 23 | require_once("../inc/forum_db.inc"); |
24 | 24 | |
25 | -if (DISABLE_TEAMS) error_page("Teams are disabled"); |
|
25 | +if (DISABLE_TEAMS) { |
|
26 | + error_page("Teams are disabled"); |
|
27 | +} |
|
26 | 28 | |
27 | 29 | check_get_args(array("tnow", "ttok", "teamid", "cmd")); |
28 | 30 | |
@@ -66,8 +68,12 @@ discard block |
||
66 | 68 | "; |
67 | 69 | echo form_tokens($user->authenticator); |
68 | 70 | start_table(); |
69 | - if (!strlen($forum->title)) $forum->title = $team->name; |
|
70 | - if (!strlen($forum->description)) $forum->description = tra("Discussion among members of %1", $team->name); |
|
71 | + if (!strlen($forum->title)) { |
|
72 | + $forum->title = $team->name; |
|
73 | + } |
|
74 | + if (!strlen($forum->description)) { |
|
75 | + $forum->description = tra("Discussion among members of %1", $team->name); |
|
76 | + } |
|
71 | 77 | row2( |
72 | 78 | tra("Title"), |
73 | 79 | '<input class="form-control" name="title" value="'.$forum->title.'">' |
@@ -112,7 +118,9 @@ discard block |
||
112 | 118 | |
113 | 119 | function remove($team) { |
114 | 120 | $forum = BoincForum::lookup("parent_type=1 and category=$team->id"); |
115 | - if (!$forum) error_page("message board not found"); |
|
121 | + if (!$forum) { |
|
122 | + error_page("message board not found"); |
|
123 | + } |
|
116 | 124 | |
117 | 125 | // delete threads and posts |
118 | 126 | // |
@@ -165,7 +173,9 @@ discard block |
||
165 | 173 | } |
166 | 174 | |
167 | 175 | $teamid = get_int("teamid", true); |
168 | -if (!$teamid) $teamid = post_int('teamid'); |
|
176 | +if (!$teamid) { |
|
177 | + $teamid = post_int('teamid'); |
|
178 | +} |
|
169 | 179 | |
170 | 180 | $team = BoincTeam::lookup_id($teamid); |
171 | 181 | if (!$team) { |
@@ -173,7 +183,9 @@ discard block |
||
173 | 183 | } |
174 | 184 | |
175 | 185 | $cmd = get_str('cmd', true); |
176 | -if (!$cmd) $cmd = post_str('cmd', true); |
|
186 | +if (!$cmd) { |
|
187 | + $cmd = post_str('cmd', true); |
|
188 | +} |
|
177 | 189 | |
178 | 190 | if ($cmd == 'manage') { |
179 | 191 | $user = get_logged_in_user(); |
@@ -194,7 +206,9 @@ discard block |
||
194 | 206 | require_founder_login($user, $team); |
195 | 207 | check_tokens($user->authenticator); |
196 | 208 | $forum = BoincForum::lookup("parent_type=1 and category=$teamid"); |
197 | - if (!$forum) error_page("no such forum"); |
|
209 | + if (!$forum) { |
|
210 | + error_page("no such forum"); |
|
211 | + } |
|
198 | 212 | edit_action($forum); |
199 | 213 | } else if ($cmd == "remove_confirm") { |
200 | 214 | $user = get_logged_in_user(); |