Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: add options for not collecting or showing URL and country #2906

Merged
merged 2 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions html/inc/account.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ function create_account_form($teamid, $next_url) {
),
"passwd", "", "password",'id="passwd"',passwd_visible_checkbox("passwd")
);
form_select(
sprintf('<span title="%s">%s</span>',
tra("Select the country you want to represent, if any."),
tra("Country")
),
"country",
country_select_options()
);
if (USER_COUNTRY) {
form_select(
sprintf('<span title="%s">%s</span>',
tra("Select the country you want to represent, if any."),
tra("Country")
),
"country",
country_select_options()
);
}
if (POSTAL_CODE) {
form_input_text(
tra("Postal or ZIP Code")."<br><small>".tra("Optional")."</small>",
Expand Down
2 changes: 1 addition & 1 deletion html/inc/forum.inc
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ function show_post(
// - put the .png's in html/user/flags/
// - put define("COUNTRY_FLAGS", 1); in your html/project/project.inc
//
if (defined("COUNTRY_FLAGS")) {
if (USER_COUNTRY && defined("COUNTRY_FLAGS")) {
if (array_key_exists($user->country, $country_to_iso3166_2)) {
$code = $country_to_iso3166_2[$user->country];
echo "<img class=flag alt=\"$user->country\" title=\"$user->country\" src=flags/$code.png>\n";
Expand Down
30 changes: 19 additions & 11 deletions html/inc/user.inc
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,15 @@ function show_user_info_private($user) {
}
row2(tra("Email address"), $email_text);
}
if (strlen($user->url)) {
$u = normalize_user_url($user->url);
row2(tra("URL"), sprintf('<a href="%s">%s</a>', $u, $u));
if (USER_URL) {
if (strlen($user->url)) {
$u = normalize_user_url($user->url);
row2(tra("URL"), sprintf('<a href="%s">%s</a>', $u, $u));
}
}
if (USER_COUNTRY) {
row2(tra("Country"), $user->country);
}
row2(tra("Country"), $user->country);
if (POSTAL_CODE) {
row2(tra("Postal code"), $user->postal_code);
}
Expand Down Expand Up @@ -433,13 +437,17 @@ function show_user_summary_public($user) {
global $g_logged_in_user;
row2(tra("User ID"), $user->id);
row2(tra("%1 member since", PROJECT), date_str($user->create_time));
row2(tra("Country"), $user->country);
// don't show URL if user has no recent credit (spam suppression)
//
if (strlen($user->url)) {
if (!NO_COMPUTING || $user->expavg_credit > 1) {
$u = normalize_user_url($user->url);
row2(tra("URL"), sprintf('<a href="%s">%s</a>', $u, $u));
if (USER_COUNTRY) {
row2(tra("Country"), $user->country);
}
if (USER_URL) {
// don't show URL if user has no recent credit (spam suppression)
//
if (strlen($user->url)) {
if (!NO_COMPUTING || $user->expavg_credit > 1) {
$u = normalize_user_url($user->url);
row2(tra("URL"), sprintf('<a href="%s">%s</a>', $u, $u));
}
}
}
if (!NO_COMPUTING) {
Expand Down
13 changes: 7 additions & 6 deletions html/inc/user_util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function validate_post_make_user() {
}

// Check if consent to terms of use has been given.
//
$myconsent = FALSE;
list($checkct, $ctid) = check_consent_type(CONSENT_TYPE_ENROLL);
if ($checkct and check_termsofuse()) {
Expand Down Expand Up @@ -258,12 +259,12 @@ function validate_post_make_user() {

$passwd_hash = md5($passwd.$new_email_addr);

$country = post_str("country", true);
if (!$country) {
$country = "None";
}
if (!is_valid_country($country)) {
error_page("bad country");
$country = "";
if (USER_COUNTRY) {
$country = post_str("country", true);
if ($country && !is_valid_country($country)) {
error_page("bad country");
}
}

if (POSTAL_CODE) {
Expand Down
12 changes: 10 additions & 2 deletions html/inc/util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,24 @@ require_once("../inc/translation.inc");
require_once("../inc/profile.inc");
require_once("../inc/bootstrap.inc");

// parse some stuff from config (do it here for efficiency)
// parse some stuff from config.xml (do it here for efficiency)
//
$config = get_config();
global $master_url;
$master_url = parse_config($config , "<master_url>");
$recaptcha_public_key = parse_config($config, "<recaptcha_public_key>");
$recaptcha_private_key = parse_config($config, "<recaptcha_private_key>");

// don't allow /... at the end of URL
// the following default to on
//
$x = parse_config($config, "<user_country>");
define('USER_COUNTRY', ($x===null)?1:(int)$x);

$x = parse_config($config, "<user_url>");
define('USER_URL', ($x===null)?1:(int)$x);

// don't allow /... at the end of URL
//
if (array_key_exists("PATH_INFO", $_SERVER)) {
die("bad URL");
}
Expand Down
4 changes: 2 additions & 2 deletions html/inc/util_basic.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ function get_config() {
// If it's a single-tag element, and it's present, just return the tag
//
function parse_element($xml, $tag) {
$element = null;
$closetag = "</" . substr($tag,1);
$x = strstr($xml, $tag);
if ($x) {
Expand All @@ -104,9 +103,10 @@ function parse_element($xml, $tag) {
$n = strpos($y, $closetag);
if ($n) {
$element = substr($y, 0, $n);
return trim($element);
}
}
return trim($element);
return null;
}

function parse_next_element($xml, $tag, &$cursor) {
Expand Down
22 changes: 15 additions & 7 deletions html/inc/xml.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,15 @@ function show_host_xml($host) {
//
function show_user_xml($user, $show_hosts) {
$cpid = md5($user->cross_project_id.$user->email_addr);
$url = normalize_user_url($user->url);
echo "<user>
<id>$user->id</id>
<cpid>$cpid</cpid>
<create_time>$user->create_time</create_time>
<name>".htmlspecialchars($user->name)."</name>
<country>$user->country</country>
<total_credit>$user->total_credit</total_credit>
<expavg_credit>$user->expavg_credit</expavg_credit>
<expavg_time>$user->expavg_time</expavg_time>
<teamid>$user->teamid</teamid>
<url>".htmlspecialchars($url)."</url>
<has_profile>$user->has_profile</has_profile>
";
if ($show_hosts) {
Expand All @@ -116,8 +113,14 @@ function show_user_xml($user, $show_hosts) {
show_host_xml($host);
}
}
echo"</user>
";
if (USER_COUNTRY) {
echo " <country>$user->country</country>\n";
}
if (USER_URL) {
$url = normalize_user_url($user->url);
echo " <url>".htmlspecialchars($url)."</url>\n";
}
echo "</user>\n";
}

function show_team_member($user, $creditonly = false) {
Expand All @@ -131,12 +134,17 @@ function show_team_member($user, $creditonly = false) {
if (!$creditonly) {
echo " <create_time>$user->create_time</create_time>
<name>".htmlspecialchars($user->name)."</name>
<country>$user->country</country>
<expavg_credit>$user->expavg_credit</expavg_credit>
<expavg_time>$user->expavg_time</expavg_time>
<url>".htmlspecialchars($url)."</url>
<has_profile>$user->has_profile</has_profile>
";
if (USER_COUNTRY) {
echo " <country>$user->country</country>\n";
}
if (USER_URL) {
$url = normalize_user_url($user->url);
echo " <url>".htmlspecialchars($url)."</url>\n";
}
}
echo "</user>
";
Expand Down
8 changes: 7 additions & 1 deletion html/user/am_set_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ function success($x) {
}

$name = BoincDb::escape_string($name);
if ($country && !is_valid_country($country)) {
if (!USER_COUNTRY) {
$country = "";
}
if (!is_valid_country($country)) {
xml_error(-1, "invalid country");
}
$country = BoincDb::escape_string($country);
Expand All @@ -118,6 +121,9 @@ function success($x) {
$project_prefs = str_ireplace("<project_preferences>", "<project_preferences>\n".$orig_project_specific, $project_prefs);
}

if (!USER_URL) {
$url = "";
}
$url = BoincDb::escape_string($url);
$send_email = BoincDb::escape_string($send_email);
$show_hosts = BoincDb::escape_string($show_hosts);
Expand Down
28 changes: 15 additions & 13 deletions html/user/edit_user_info_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@
if (strlen($name) == 0) {
error_page(tra("You must supply a name for your account."));
}
$url = post_str("url", true);
$url = sanitize_tags($url);
$country = post_str("country");
if ($country == "") {
$country = "International";
$name = BoincDb::escape_string($name);

$url = "";
$country = "";
$postal_code = "";
if (USER_URL) {
$url = post_str("url", true);
$url = sanitize_tags($url);
$url = BoincDb::escape_string($url);
}
if (!is_valid_country($country)) {
error_page("bad country");
if (USER_COUNTRY) {
$country = post_str("country");
if (!is_valid_country($country)) {
error_page("bad country");
}
$country = BoincDb::escape_string($country);
}
$country = BoincDb::escape_string($country);
if (POSTAL_CODE) {
$postal_code = BoincDb::escape_string(sanitize_tags(post_str("postal_code", true)));
} else {
$postal_code = '';
}

$name = BoincDb::escape_string($name);
$url = BoincDb::escape_string($url);

$result = $user->update(
"name='$name', url='$url', country='$country', postal_code='$postal_code'"
);
Expand Down
24 changes: 14 additions & 10 deletions html/user/edit_user_info_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@
$user->name
);

form_input_text(
tra("URL %1 of your personal web page; optional%2", "<br><p class=\"small\">", "</p>"),
'url',
$user->url
);
if (USER_URL) {
form_input_text(
tra("URL %1 of your personal web page; optional%2", "<br><p class=\"small\">", "</p>"),
'url',
$user->url
);
}

form_select(
tra("Country"),
'country',
country_select_options($user->country)
);
if (USER_COUNTRY) {
form_select(
tra("Country"),
'country',
country_select_options($user->country)
);
}

if (POSTAL_CODE) {
form_input_text(
Expand Down
1 change: 1 addition & 0 deletions lib/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ int run_program(
FCGI::perror("execvp");
#else
perror("execvp");
fprintf(stderr, "couldn't exec %s: %d\n", file, errno);
#endif
exit(errno);
}
Expand Down
9 changes: 7 additions & 2 deletions sched/db_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ void write_user(USER& user, ZFILE* f, bool /*detail*/) {
"<user>\n"
" <id>%lu</id>\n"
" <name>%s</name>\n"
" <country>%s</country>\n"
" <create_time>%d</create_time>\n"
" <total_credit>%f</total_credit>\n"
" <expavg_credit>%f</expavg_credit>\n"
Expand All @@ -597,7 +596,13 @@ void write_user(USER& user, ZFILE* f, bool /*detail*/) {
user.expavg_time,
cpid
);
if (strlen(user.url)) {
if (config.user_country && strlen(user.country)) {
f->write(
" <country>%s</country>\n",
user.country
);
}
if (config.user_url && strlen(user.url)) {
f->write(
" <url>%s</url>\n",
url
Expand Down
4 changes: 4 additions & 0 deletions sched/sched_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ int SCHED_CONFIG::parse(FILE* f) {
scheduler_log_buffer = 32768;
version_select_random_factor = 1.;
maintenance_delay = 3600;
user_url = true;
user_country = true;

if (!xp.parse_start("boinc")) return ERR_XML_PARSE;
if (!xp.parse_start("config")) return ERR_XML_PARSE;
Expand Down Expand Up @@ -194,6 +196,8 @@ int SCHED_CONFIG::parse(FILE* f) {
if (xp.parse_bool("job_size_matching", job_size_matching)) continue;
if (xp.parse_bool("dont_send_jobs", dont_send_jobs)) continue;
if (xp.parse_bool("estimate_flops_from_hav_pfc", estimate_flops_from_hav_pfc)) continue;
if (xp.parse_bool("user_url", user_url)) continue;
if (xp.parse_bool("user_country", user_country)) continue;

//////////// STUFF RELEVANT ONLY TO SCHEDULER STARTS HERE ///////

Expand Down
2 changes: 2 additions & 0 deletions sched/sched_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ struct SCHED_CONFIG {
bool enable_assignment_multi;
bool job_size_matching;
bool dont_send_jobs;
bool user_url; // whether to export user.url in db dump
bool user_country;

//////////// STUFF RELEVANT ONLY TO SCHEDULER FOLLOWS ///////////

Expand Down