Skip to content

Commit

Permalink
Merge pull request #3080 from BOINC/dpa_autoattach4
Browse files Browse the repository at this point in the history
web: Fix auto-attach process for VBox projects
  • Loading branch information
lfield committed Apr 11, 2019
2 parents 39cd547 + 4a3eb03 commit ffe6739
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 36 deletions.
2 changes: 1 addition & 1 deletion html/inc/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function navbar_right($user) {
);
} else {
echo sprintf('
<li><a href="%screate_account_form.php">Sign Up</a></li>
<li><a href="%ssignup.php">Join</a></li>
<li><a href="%slogin_form.php">Login</a></li>
', url_base(), url_base()
);
Expand Down
136 changes: 105 additions & 31 deletions html/user/download.php → html/user/download_software.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Show a page with download links and instructions.
// There's a logged-in user.
//
// If no project ID, redirect to BOINC web site
// If no project ID, direct user to BOINC web site
// otherwise...
//
// - get platform from user agent string
Expand All @@ -28,9 +28,15 @@
// - Show download button(s)
// The download will be via concierge, using the login token.
//
// By default both regular and vbox buttons will be shown, if available.
// You can suppress one or the other by setting
// <disable_regular_download> or <disable_vbox_download>.
// VirtualBox
//
// config.xml entries:
// <need_vbox/> This project requires VBox
// <recommend_vbox> This project can use VBox
//
// Windows has combined BOINC/VBox installers.
// For other platforms, direct user to VBox download page
// before installing BOINC
//
// Notes:
// 1) You need to have the client versions file
Expand All @@ -41,30 +47,33 @@
require_once("../inc/util.inc");
require_once("../inc/account.inc");

// take the client info string reported by web browser,
define("VBOX_DOWNLOAD_URL", "https://www.virtualbox.org/wiki/Downloads");

// take the user agent string reported by web browser,
// and return best guess for platform
//
function client_info_to_platform($client_info) {
if (strstr($client_info, 'Windows')) {
if (strstr($client_info, 'Win64')||strstr($client_info, 'WOW64')) {
function get_platform() {
global $user_agent;
if (strstr($user_agent, 'Windows')) {
if (strstr($user_agent, 'Win64')||strstr($user_agent, 'WOW64')) {
return 'windows_x86_64';
} else {
return 'windows_intelx86';
}
} else if (strstr($client_info, 'Mac')) {
if (strstr($client_info, 'PPC Mac OS X')) {
} else if (strstr($user_agent, 'Mac')) {
if (strstr($user_agent, 'PPC Mac OS X')) {
return 'powerpc-apple-darwin';
} else {
return 'x86_64-apple-darwin';
}
} else if (strstr($client_info, 'Android')) {
} else if (strstr($user_agent, 'Android')) {
// Check for Android before Linux,
// since Android contains the Linux kernel and the
// web browser user agent string lists Linux too.
//
return 'arm-android-linux-gnu';
} else if (strstr($client_info, 'Linux')) {
if (strstr($client_info, 'x86_64')) {
} else if (strstr($user_agent, 'Linux')) {
if (strstr($user_agent, 'x86_64')) {
return 'x86_64-pc-linux-gnu';
} else {
return 'i686-pc-linux-gnu';
Expand All @@ -74,12 +83,20 @@ function client_info_to_platform($client_info) {
}
}

function is_windows() {
global $user_agent;
if (strstr($user_agent, 'Windows')) {
return true;
}
return false;
}

// find release version for user's platform
//
function get_version($dev) {
global $user_agent;
$v = simplexml_load_file("versions.xml");
$client_info = $_SERVER['HTTP_USER_AGENT'];
$p = client_info_to_platform($client_info);
$p = get_platform();
foreach ($v->version as $i=>$v) {
if ((string)$v->dbplatform != $p) {
continue;
Expand All @@ -96,14 +113,14 @@ function get_version($dev) {
return null;
}

function download_button($v, $project_id, $token, $user) {
function download_button($v, $project_id, $token, $user, $green) {
return sprintf(
'<form action="https://boinc.berkeley.edu/concierge.php" method="post">
<input type=hidden name=project_id value="%d">
<input type=hidden name=token value="%s">
<input type=hidden name=user_id value="%d">
<input type=hidden name=filename value="%s">
<button class="btn btn-info">
<button class="btn %s">
<font size=2><u>Download BOINC</u></font>
<br>for %s (%s MB)
<br><small>BOINC %s</small></button>
Expand All @@ -113,6 +130,7 @@ function download_button($v, $project_id, $token, $user) {
$token,
$user->id,
(string)$v->filename,
$green?"btn-success":"btn-info",
(string)$v->platform,
(string)$v->size_mb,
(string)$v->version_num
Expand Down Expand Up @@ -147,18 +165,54 @@ function download_button_vbox($v, $project_id, $token, $user) {
);
}

// We can't use auto-attach; direct them to the BOINC download page
function show_vbox_info($where) {
global $need_vbox, $recommend_vbox;

if ($need_vbox || $recommend_vbox) {
echo "<p>";
if ($need_vbox) {
echo tra("This project requires VirtualBox.");
}
if ($recommend_vbox) {
echo tra("This project recommends VirtualBox.");
}
echo " ";
switch ($where) {
case "installed":
echo tra(
"If it is not installed on this computer, get it %1here%2, then restart BOINC.",
"<a href=".VBOX_DOWNLOAD_URL.">",
"</a>"
);
break;
case "direct":
case "main":
if (is_windows()) {
echo tra("Use the BOINC+VirtualBox installer.");
} else {
echo tra(
"If it is not installed on this computer, get it %1here%2.",
"<a href=".VBOX_DOWNLOAD_URL.">",
"</a>"
);
}
}
echo "<p>";
}
}

// We can't use auto-attach; direct user to the BOINC download page
//
function direct_to_boinc() {
global $master_url;
page_head(tra("Download BOINC"));
text_start();
show_vbox_info("direct");
echo sprintf(
'<p>%s
<p><p>
%s
<p>
<a href=https://boinc.berkeley.edu/download.php>%s</a>
',
tra("To download and install BOINC,
click on the link below and follow the instructions.
Expand All @@ -168,17 +222,21 @@ function direct_to_boinc() {
or enter this project's URL: %2",
PROJECT,
$master_url
),
)
);
show_button(
"https://boinc.berkeley.edu/download.php",
tra("Go to the BOINC download page.")
);
text_end();
page_tail();
}

function show_download_page($user, $dev) {
global $config;
$need_vbox = parse_bool($config, "need_vbox");
$project_id = parse_config($config, "<project_id>");
global $need_vbox, $project_id;

// If no project ID, we can't use simplified install
//
if (!$project_id) {
direct_to_boinc();
return;
Expand Down Expand Up @@ -209,39 +267,42 @@ function show_download_page($user, $dev) {
echo"
<p>
";
echo tra("If %1 already installed, %2click here%3; otherwise:",
echo tra("If %1 already installed, %2click here%3.",
$phrase,
"<a href=download.php?action=installed>",
"<a href=download_software.php?action=installed>",
"</a>"
);
echo "
<p>
";

show_vbox_info("main");

$token = make_login_token($user);
echo "<center><table border=0 cellpadding=20>\n";
echo "<table border=0 cellpadding=20>\n";
if ($v->vbox_filename) {
table_row(
"",
download_button_vbox($v, $project_id, $token, $user),
"&nbsp;&nbsp;",
download_button($v, $project_id, $token, $user),
download_button($v, $project_id, $token, $user, false),
""
);
} else {
table_row("", download_button($v, $project_id, $token, $user), "");
table_row("", download_button($v, $project_id, $token, $user, true), "");
}
echo "</table></center>\n";
echo "</table>\n";
echo "<p><p>";
echo tra("When the download is finished, open the downloaded file to install %1.", $dl);
echo "<p><p>";
echo tra("All done? %1Click here to finish%2.", "<a href=welcome.php>", "</a>");
page_tail();
}

// if user already has BOINC installed, tell them how to attach
// if user already has BOINC installed, tell them how to attach.
//
function installed() {
global $config;
global $config, $need_vbox, $recommend_vbox;
$am = parse_bool($config, "account_manager");
if ($am) {
page_head(tra("Use %1", PROJECT));
Expand All @@ -261,6 +322,7 @@ function installed() {
);
} else {
page_head(tra("Add %1", PROJECT));
show_vbox_info("installed");
echo sprintf("%s
<ul>
<li> %s
Expand All @@ -284,9 +346,21 @@ function installed() {
page_tail();
}

// get config.xml items
//
$need_vbox = parse_bool($config, "need_vbox");
$recommend_vbox = parse_bool($config, "recommend_vbox");
$project_id = parse_config($config, "<project_id>");

$user = get_logged_in_user();
$action = get_str("action", true);
$dev = get_str("dev", true);

$user_agent = get_str("user_agent", true); // for debugging
if (!$user_agent) {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
}

if ($action == "installed") {
installed();
} else {
Expand Down
2 changes: 2 additions & 0 deletions html/user/join.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
// This page routes people to the right place depending on whether
// they already have BOINC installed on this device.

// DEPRECATED. Use signup.php instead

require_once("../inc/util.inc");

// "old" (misnomer) means BOINC is already installed on this device
Expand Down
6 changes: 4 additions & 2 deletions html/user/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
//
// Link to this from a "Join" button on home page

// DEPRECATED; use signup.php instead

require_once("../inc/util.inc");
require_once("../inc/account.inc");
require_once("../inc/recaptchalib.php");
Expand All @@ -34,15 +36,15 @@ function reg_form() {
page_head("Register", null, null, null, boinc_recaptcha_get_head_extra());
echo "<h3>Create an account</h3>";
form_start("create_account_action.php", "post");
create_account_form(0, "download.php");
create_account_form(0, "download_software.php");
if ($recaptcha_public_key) {
form_general("", boinc_recaptcha_get_html($recaptcha_public_key));
}
form_submit("Join");
form_end();

echo "<h3>If you already have an account, log in</h3>";
login_form("download.php");
login_form("download_software.php");
echo "</td></tr>";
page_tail();
}
Expand Down
2 changes: 1 addition & 1 deletion html/user/sample_index.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function() use($user) {
',
tra("Want to help more?"),
tra("If BOINC is not installed on this computer, %1download it%2.",
"<a href=download.php>", "</a>"
"<a href=download_software.php>", "</a>"
),
tra("Install BOINC on your other computers, tablets, and phones."),
tra("Tell your friends about BOINC, and show them how to join %1.", PROJECT)
Expand Down
2 changes: 1 addition & 1 deletion html/user/signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function join_action() {
$prefs = compute_prefs_xml($preset);
$user->update("global_prefs='$prefs'");
}
Header("Location: download.php");
Header("Location: download_software.php");
send_cookie('auth', $user->authenticator, false);
}

Expand Down

0 comments on commit ffe6739

Please sign in to comment.