BOINC /
boinc
| 1 | <?php |
||
| 2 | // This file is part of BOINC. |
||
| 3 | // http://boinc.berkeley.edu |
||
| 4 | // Copyright (C) 2015 University of California |
||
| 5 | // |
||
| 6 | // BOINC is free software; you can redistribute it and/or modify it |
||
| 7 | // under the terms of the GNU Lesser General Public License |
||
| 8 | // as published by the Free Software Foundation, |
||
| 9 | // either version 3 of the License, or (at your option) any later version. |
||
| 10 | // |
||
| 11 | // BOINC is distributed in the hope that it will be useful, |
||
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 14 | // See the GNU Lesser General Public License for more details. |
||
| 15 | // |
||
| 16 | // You should have received a copy of the GNU Lesser General Public License |
||
| 17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
| 18 | |||
| 19 | // Page for downloading the BOINC client, with support for autoattach: |
||
| 20 | // https://github.com/BOINC/boinc/wiki/SimpleAttach |
||
| 21 | // Note: to use autoattach: |
||
| 22 | // 1) You need to have the latest client versions file |
||
| 23 | // run html/ops/get_versions.php |
||
| 24 | // 2) Put your project ID (ask DPA if you don't have one) |
||
| 25 | // in config.xml as <project_id>x</project_id> |
||
| 26 | // |
||
| 27 | // There's a logged-in user. |
||
| 28 | // |
||
| 29 | // Autoattach case: if project has an ID and client is Win or Mac: |
||
| 30 | // - find latest version for that platform |
||
| 31 | // - Create a login token. |
||
| 32 | // - Show download button(s) |
||
| 33 | // The download will be via concierge, using the login token. |
||
| 34 | // Otherwise: |
||
| 35 | // - show link to download page on BOINC web site, |
||
| 36 | // and instructions for what to do after that. |
||
| 37 | |||
| 38 | // Can also be called as a web RPC; |
||
| 39 | // see https://github.com/BOINC/boinc/wiki/WebRpc#download |
||
| 40 | // NOT USED - OK TO REMOVE |
||
| 41 | // rpc this says it's an RPC |
||
| 42 | // user_agent web browser info |
||
| 43 | // authenticator the account to link to |
||
| 44 | // returns an XML doc of the form |
||
| 45 | // <download_info> |
||
| 46 | // [ <manual/> ] // not win or mac - tell user to visit BOINC download page |
||
| 47 | // <project_id>X</project_id> |
||
| 48 | |||
| 49 | require_once("../inc/util.inc"); |
||
| 50 | require_once("../inc/account.inc"); |
||
| 51 | |||
| 52 | // take the user agent string reported by web browser, |
||
| 53 | // and return best guess for platform |
||
| 54 | // |
||
| 55 | function get_platform($user_agent) { |
||
| 56 | if (strstr($user_agent, 'Windows')) { |
||
| 57 | if (strstr($user_agent, 'x64')) { |
||
| 58 | return 'windows_x86_64'; |
||
| 59 | } else if (strstr($user_agent, 'arm')) { |
||
| 60 | return 'windows_arm64'; |
||
| 61 | } else { |
||
| 62 | return 'windows_intelx86'; |
||
| 63 | } |
||
| 64 | } else if (strstr($user_agent, 'Mac')) { |
||
| 65 | if (strstr($user_agent, 'PPC Mac OS X')) { |
||
| 66 | return 'powerpc-apple-darwin'; |
||
| 67 | } else { |
||
| 68 | return 'x86_64-apple-darwin'; |
||
| 69 | } |
||
| 70 | } else if (strstr($user_agent, 'Android')) { |
||
| 71 | // Check for Android before Linux, |
||
| 72 | // since Android contains the Linux kernel and the |
||
| 73 | // web browser user agent string lists Linux too. |
||
| 74 | // |
||
| 75 | return 'arm-android-linux-gnu'; |
||
| 76 | } else if (strstr($user_agent, 'Linux')) { |
||
| 77 | if (strstr($user_agent, 'x86_64')) { |
||
| 78 | return 'x86_64-pc-linux-gnu'; |
||
| 79 | } else { |
||
| 80 | return 'i686-pc-linux-gnu'; |
||
| 81 | } |
||
| 82 | } else { |
||
| 83 | return null; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | function is_windows() { |
||
| 88 | global $user_agent; |
||
| 89 | if (strstr($user_agent, 'Windows')) { |
||
| 90 | return true; |
||
| 91 | } |
||
| 92 | return false; |
||
| 93 | } |
||
| 94 | |||
| 95 | function is_windows_or_mac() { |
||
| 96 | global $user_agent; |
||
| 97 | if (strstr($user_agent, 'Windows')) return true; |
||
| 98 | if (strstr($user_agent, 'Mac')) return true; |
||
| 99 | return false; |
||
| 100 | } |
||
| 101 | |||
| 102 | // find release version for user's platform |
||
| 103 | // |
||
| 104 | function get_version($user_agent, $dev) { |
||
| 105 | $v = simplexml_load_file("versions.xml"); |
||
| 106 | $p = get_platform($user_agent); |
||
| 107 | foreach ($v->version as $i=>$v) { |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 108 | if ((string)$v->dbplatform != $p) { |
||
| 109 | continue; |
||
| 110 | } |
||
| 111 | if (strstr((string)$v->description, "Recommended")) { |
||
| 112 | return $v; |
||
| 113 | } |
||
| 114 | if ($dev) { |
||
| 115 | if (strstr((string)$v->description, "Development")) { |
||
| 116 | return $v; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | return null; |
||
| 121 | } |
||
| 122 | |||
| 123 | function download_button($v, $project_id, $token, $user) { |
||
| 124 | return sprintf( |
||
| 125 | '<form action="https://boinc.berkeley.edu/concierge.php" method="post"> |
||
| 126 | <input type=hidden name=project_id value="%d"> |
||
| 127 | <input type=hidden name=token value="%s"> |
||
| 128 | <input type=hidden name=user_id value="%d"> |
||
| 129 | <input type=hidden name=filename value="%s"> |
||
| 130 | <button %s class="btn"> |
||
| 131 | <font size=2><u>Download BOINC</u></font> |
||
| 132 | <br>for %s (%s MB) |
||
| 133 | <br>BOINC %s</button> |
||
| 134 | </form> |
||
| 135 | ', |
||
| 136 | $project_id, |
||
| 137 | $token, |
||
| 138 | $user->id, |
||
| 139 | (string)$v->filename, |
||
| 140 | button_style(), |
||
| 141 | (string)$v->platform, |
||
| 142 | (string)$v->size_mb, |
||
| 143 | (string)$v->version_num |
||
| 144 | ); |
||
| 145 | } |
||
| 146 | |||
| 147 | // We can't use auto-attach; direct user to the BOINC download page |
||
| 148 | // |
||
| 149 | function direct_to_boinc() { |
||
| 150 | page_head(tra("Download BOINC")); |
||
| 151 | text_start(); |
||
| 152 | echo "<p>"; |
||
| 153 | echo tra("To download and install BOINC, |
||
| 154 | click on the link below and follow the instructions. |
||
| 155 | "); |
||
| 156 | echo "<p>"; |
||
| 157 | show_button( |
||
| 158 | "https://boinc.berkeley.edu/download.php", |
||
| 159 | tra("Go to the BOINC download page"), |
||
| 160 | null, null, button_style().' target=_new ' |
||
| 161 | ); |
||
| 162 | |||
| 163 | if (parse_bool(get_config(), 'account_manager')) { |
||
| 164 | echo sprintf( |
||
| 165 | "<p><p>%s<p>", |
||
| 166 | tra("When BOINC first runs it will ask you to select a project. |
||
| 167 | Cancel out of this dialog, |
||
| 168 | then select <b>Tools / Use Account Manager</b> |
||
| 169 | to connect BOINC to your %1 account. |
||
| 170 | See <a href=%2>detailed instructions</a>.", |
||
| 171 | PROJECT, |
||
| 172 | 'https://boinc.berkeley.edu/wiki/Account_managers' |
||
| 173 | ) |
||
| 174 | ); |
||
| 175 | } else { |
||
| 176 | echo sprintf( |
||
| 177 | "<p><p>%s<p>", |
||
| 178 | tra("When BOINC first runs it will ask you to select a project. |
||
| 179 | Select '%1' from the list, |
||
| 180 | or enter this project's URL:<p>%2", |
||
| 181 | PROJECT, |
||
| 182 | master_url() |
||
| 183 | ) |
||
| 184 | ); |
||
| 185 | } |
||
| 186 | text_end(); |
||
| 187 | page_tail(); |
||
| 188 | } |
||
| 189 | |||
| 190 | function show_download_page($user, $user_agent, $dev) { |
||
| 191 | global $project_id; |
||
| 192 | |||
| 193 | // If no project ID, we can't use simplified install |
||
| 194 | // |
||
| 195 | if (!$project_id || !is_windows_or_mac()) { |
||
| 196 | direct_to_boinc(); |
||
| 197 | return; |
||
| 198 | } |
||
| 199 | $v = get_version($user_agent, $dev); |
||
| 200 | |||
| 201 | // if we can't figure out the user's platform, |
||
| 202 | // take them to the download page on the BOINC site |
||
| 203 | // |
||
| 204 | if (!$v) { |
||
| 205 | direct_to_boinc(); |
||
| 206 | return; |
||
| 207 | } |
||
| 208 | |||
| 209 | page_head("Download software"); |
||
| 210 | |||
| 211 | $phrase = ""; |
||
| 212 | $dlv = tra("the current version of BOINC"); |
||
| 213 | $phrase = tra("this version is"); |
||
| 214 | $dl = "BOINC"; |
||
| 215 | echo tra("To participate in %1, %2 must be installed on your computer.", PROJECT, $dlv); |
||
| 216 | echo" |
||
|
0 ignored issues
–
show
|
|||
| 217 | <p> |
||
| 218 | "; |
||
| 219 | echo tra("If %1 already installed, %2click here%3.", |
||
| 220 | $phrase, |
||
| 221 | "<a href=download_software.php?action=installed>", |
||
| 222 | "</a>" |
||
| 223 | ); |
||
| 224 | echo " |
||
| 225 | <p> |
||
| 226 | "; |
||
| 227 | |||
| 228 | $token = make_login_token($user); |
||
| 229 | echo "<table border=0 cellpadding=20>\n"; |
||
| 230 | table_row("", download_button($v, $project_id, $token, $user), ""); |
||
| 231 | echo "</table>\n"; |
||
| 232 | echo "<p><p>"; |
||
| 233 | echo tra("When the download is finished, open the downloaded file to install %1.", $dl); |
||
| 234 | echo "<p><p>"; |
||
| 235 | echo tra("All done? %1Click here to finish%2.", "<a href=welcome.php>", "</a>"); |
||
| 236 | page_tail(); |
||
| 237 | } |
||
| 238 | |||
| 239 | // if user already has BOINC installed, tell them how to attach. |
||
| 240 | // |
||
| 241 | function installed() { |
||
| 242 | $config = get_config(); |
||
| 243 | $am = parse_bool($config, "account_manager"); |
||
| 244 | if ($am) { |
||
| 245 | page_head(tra("Use %1", PROJECT)); |
||
| 246 | echo sprintf("%s |
||
| 247 | <ul> |
||
| 248 | <li> %s |
||
| 249 | <li> %s |
||
| 250 | <li> %s |
||
| 251 | <li> %s |
||
| 252 | </ul> |
||
| 253 | ", |
||
| 254 | tra("To use %1 on this computer:", PROJECT), |
||
| 255 | tra("In the BOINC manager, go to the Tools menu"), |
||
| 256 | tra("Select Use Account Manager"), |
||
| 257 | tra("Select %1 from the list", PROJECT), |
||
| 258 | tra("Enter your %1 email address and password.", PROJECT) |
||
| 259 | ); |
||
| 260 | } else { |
||
| 261 | page_head(tra("Add %1", PROJECT)); |
||
| 262 | echo sprintf("%s |
||
| 263 | <ul> |
||
| 264 | <li> %s |
||
| 265 | <li> %s |
||
| 266 | <li> %s |
||
| 267 | <li> %s |
||
| 268 | </ul> |
||
| 269 | ", |
||
| 270 | tra("To add %1 on this computer:", PROJECT), |
||
| 271 | tra("In the BOINC manager, go to the Tools menu"), |
||
| 272 | tra("Select Add Project"), |
||
| 273 | tra("Select %1 from the list", PROJECT), |
||
| 274 | tra("Enter your %1 email address and password.", PROJECT) |
||
| 275 | ); |
||
| 276 | } |
||
| 277 | echo "<p><p>"; |
||
| 278 | echo sprintf('<a href=home.php class="btn btn-success">%s</a> |
||
| 279 | ', |
||
| 280 | tra('Continue to your home page') |
||
| 281 | ); |
||
| 282 | page_tail(); |
||
| 283 | } |
||
| 284 | |||
| 285 | // RPC handler |
||
| 286 | // NOT USED - OK TO REMOVE |
||
| 287 | // |
||
| 288 | function handle_get_info() { |
||
| 289 | require_once("../inc/xml.inc"); |
||
| 290 | global $user; |
||
| 291 | $config = get_config(); |
||
| 292 | xml_header(); |
||
| 293 | $rpc_key = get_str('rpc_key'); |
||
| 294 | if ($rpc_key != parse_config($config, "<rpc_key>")) { |
||
| 295 | xml_error(-1, "RPC key mismatch"); |
||
| 296 | } |
||
| 297 | $user = BoincUser::lookup_auth(get_str('auth')); |
||
| 298 | if (!$user) { |
||
| 299 | xml_error(-1, "user not found"); |
||
| 300 | } |
||
| 301 | $project_id = parse_config($config, '<project_id>'); |
||
| 302 | if (!$project_id) { |
||
| 303 | xml_error(-1, "no project ID"); |
||
| 304 | } |
||
| 305 | $user_agent = get_str('user_agent'); |
||
| 306 | $v = get_version($user_agent, false); |
||
| 307 | if (!$v) { |
||
| 308 | xml_error(-1, "no version for platform"); |
||
| 309 | } |
||
| 310 | |||
| 311 | $token = make_login_token($user); |
||
| 312 | echo sprintf( |
||
| 313 | '<download_info> |
||
| 314 | <project_id>%s</project_id> |
||
| 315 | <token>%s</token> |
||
| 316 | <user_id>%d</user_id> |
||
| 317 | <platform>%s</platform> |
||
| 318 | <boinc> |
||
| 319 | <filename>%s</filename> |
||
| 320 | <size_mb>%s</size_mb> |
||
| 321 | <boinc_version>%s</boinc_version> |
||
| 322 | </boinc> |
||
| 323 | ', |
||
| 324 | $project_id, |
||
| 325 | $token, |
||
| 326 | $user->id, |
||
| 327 | (string)$v->platform, |
||
| 328 | (string)$v->filename, |
||
| 329 | (string)$v->size_mb, |
||
| 330 | (string)$v->version_num |
||
| 331 | ); |
||
| 332 | echo '</download_info> |
||
| 333 | '; |
||
| 334 | } |
||
| 335 | |||
| 336 | // get config.xml items |
||
| 337 | // |
||
| 338 | $config = get_config(); |
||
| 339 | $project_id = parse_config($config, "<project_id>"); |
||
| 340 | |||
| 341 | $action = get_str("action", true); |
||
| 342 | |||
| 343 | if ($action == "installed") { |
||
| 344 | installed(); |
||
| 345 | } else if ($action == 'get_info') { |
||
| 346 | handle_get_info(); |
||
| 347 | } else { |
||
| 348 | $dev = get_str("dev", true); |
||
| 349 | $user_agent = get_str("user_agent", true); // for debugging |
||
| 350 | if (!$user_agent) { |
||
| 351 | $user_agent = $_SERVER['HTTP_USER_AGENT']; |
||
| 352 | } |
||
| 353 | $user = get_logged_in_user(); |
||
|
0 ignored issues
–
show
Are you sure the assignment to
$user is correct as get_logged_in_user() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 354 | show_download_page($user, $user_agent, $dev); |
||
| 355 | } |
||
| 356 | |||
| 357 | ?> |
||
| 358 |