.
// This file contains support functions for display and editing
// preferences (global and project).
// Preferences are represented in two ways:
// - As a PHP structure (usually called $prefs)
// This has fields run_if_user_active, etc.
// The fields "project_specific" is plain XML
// - As XML (usually called $prefs_xml)
//
// This XML has the general structure
//
// ...
//
// 1.3
// ...
//
//
// ...
//
//
//
// and
//
//
// 4
// [ 0|1 ]
// [ 1 ]
// [ 1 ]
// [ 1 ]
//
// ... (arbitrary project-specific XML)
//
//
// ...
//
//
//
// In addition there are some fields of the user table
// (send_email and show_hosts) that are treated as project preferences
// Various functions are defined below for converting between these forms,
// and also to/from HTML form elements
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
include_once("../inc/prefs_util.inc");
include_once("../project/project_specific_prefs.inc");
$app_types = get_app_types();
$venues = array("home", "school", "work");
$cpu_prefs = array(
new PREF_BOOL(
tra(
"Suspend work while computer is on battery power? %1 Matters only for portable computers %2",
" ",
""
),
"run_on_batteries",
false, true
),
new PREF_BOOL(
tra("Suspend work while computer is in use?"),
"run_if_user_active",
true, true
),
new PREF_BOOL(
tra(
"Suspend GPU work while computer is in use? %1 Enforced by version 6.6.21+ %2",
" ",
""
),
"run_gpu_if_user_active",
false, true
),
new PREF_NUM(
tra("'In use' means mouse/keyboard activity in last"),
"idle_time_to_run",
new NUM_SPEC(tra("minutes"), 1, 9999, 3)
),
new PREF_NUM(
tra(
"Suspend work if no mouse/keyboard activity in last %1 Needed to enter low-power mode on some computers %2",
" ",
""
),
"suspend_if_no_recent_input",
new NUM_SPEC(tra("minutes"), 0, 9999, 0)
),
new PREF_NUM(
tra(
"Suspend work if CPU usage is above %1 0 means no restriction Enforced by version 6.10.30+ %2",
" ",
""
),
"suspend_cpu_usage",
new NUM_SPEC("%", 0, 100, 25)
),
new PREF_HOUR_RANGE(
tra("Do work only between the hours of %1 No restriction if equal %2",
" ",
""
),
"start_hour", "end_hour"
),
new PREF_BOOL(
tra(
"Leave tasks in memory while suspended? %1 Suspended tasks will consume swap space if 'yes' %2",
" ",
""
),
"leave_apps_in_memory",
false
),
new PREF_NUM(
tra(
"Switch between tasks every %1 Recommended: 60 minutes %2",
" ",
""
),
"cpu_scheduling_period_minutes",
new NUM_SPEC(tra("minutes"), 1, 9999, 60)
),
new PREF_NUM(
tra("On multiprocessors, use at most"),
"max_cpus",
new NUM_SPEC(tra("processors"), 0, 9999, 0)
),
new PREF_NUM(
tra(
"On multiprocessors, use at most %1 Enforced by version 6.1+ %2",
" ",
""
),
"max_ncpus_pct",
new NUM_SPEC(tra("% of the processors"), 0, 100, 100)
),
new PREF_NUM(
tra(
"Use at most %1 Can be used to reduce CPU heat %2",
" ",
""
),
"cpu_usage_limit",
new NUM_SPEC(tra("% of CPU time"), 0, 100, 100)
),
);
$dp = get_disk_space_config();
$disk_prefs = array(
new PREF_NUM(
tra("Disk: use at most"),
"disk_max_used_gb",
new NUM_SPEC(tra("GB"), 0, 9999999, $dp->disk_max_used_gb)
),
new PREF_NUM(
tra("Disk: leave free at least %1 Values smaller than %2 are ignored %3",
" ",
"0.001",
""
),
"disk_min_free_gb",
new NUM_SPEC(tra("GB"), 0.001, 9999999, $dp->disk_min_free_gb)
),
new PREF_NUM(
tra("Disk: use at most"),
"disk_max_used_pct",
new NUM_SPEC(tra("% of total"), 0, 100, $dp->disk_max_used_pct)
),
new PREF_NUM(
tra("Tasks checkpoint to disk at most every"),
"disk_interval",
new NUM_SPEC(tra("seconds"), 0, 9999999, 60)
),
new PREF_NUM(
tra("Swap space: use at most"),
"vm_max_used_pct",
new NUM_SPEC(tra("% of total"), 0, 100, 75)
),
new PREF_NUM(
tra("Memory: when computer is in use, use at most"),
"ram_max_used_busy_pct",
new NUM_SPEC(tra("% of total"), 0, 100, 50)
),
new PREF_NUM(
tra("Memory: when computer is not in use, use at most"),
"ram_max_used_idle_pct",
new NUM_SPEC(tra("% of total"), 0, 100, 90)
),
);
$net_prefs = array(
new PREF_NUM(
tra(
"Computer is connected to the Internet about every %1 Leave blank or 0 if always connected. %2 BOINC will try to maintain at least this much work. %3",
" ",
" ",
""
),
"work_buf_min_days",
new NUM_SPEC(tra("days"), 0, 10, 0)
),
new PREF_NUM(
tra("Maintain enough work for an additional"),
"work_buf_additional_days",
new NUM_SPEC(tra("days"), 0, 10, .25)
),
new PREF_BOOL(
tra(
"Confirm before connecting to Internet? %1 Matters only if you have a modem, ISDN or VPN connection %2",
" ",
""
),
"confirm_before_connecting",
false
),
new PREF_BOOL(
tra(
"Disconnect when done? %1 Matters only if you have a modem, ISDN or VPN connection %2",
" ",
""
),
"hangup_if_dialed",
false
),
new PREF_NUM(
tra("Maximum download rate:"),
"max_bytes_sec_down",
new NUM_SPEC(tra("Kbytes/sec"), 0, 9999999, 0, 1000)
),
new PREF_NUM(
tra("Maximum upload rate:"),
"max_bytes_sec_up",
new NUM_SPEC(tra("Kbytes/sec"), 0, 9999999, 0, 1000)
),
new PREF_HOUR_RANGE(
tra("Use network only between the hours of"),
"net_start_hour", "net_end_hour"
),
new PREF_NUM2(
tra("Transfer at most %1 Enforced by version 6.10.46+ %2",
" ",
""
),
"daily_xfer_limit_mb",
"daily_xfer_period_days",
new NUM_SPEC(tra("Mbytes every"), 0, 9999999, 0),
new NUM_SPEC(tra("days"), 0, 9999999, 0)
),
new PREF_BOOL(
tra(
"Skip image file verification? %1 Check this ONLY if your Internet provider modifies image files (UMTS does this, for example). %2 Skipping verification reduces the security of BOINC. %3",
" ",
"",
""
),
"dont_verify_images",
false
),
);
$project_pref_descs = array(
new PREF_NUM(
$x = tra(
"Resource share %1 Determines the proportion of your computer's resources allocated to this project. Example: if you participate in two BOINC projects with resource shares of 100 and 200, the first will get 1/3 of your resources and the second will get 2/3. %2",
" ",
""
),
"resource_share",
new NUM_SPEC("", 0, 9999999, 100)
),
);
if (isset($accelerate_gpu_apps_pref) && $accelerate_gpu_apps_pref) {
$project_pref_descs[] = new PREF_BOOL(
tra("Accelerate GPU tasks by dedicating a CPU to each one?"),
"accelerate_gpu_apps",
false
);
}
if ($app_types->count > 1) {
if ($app_types->cpu) {
$project_pref_descs[] = new PREF_BOOL (
tra(
"Use CPU %1 Enforced by version 6.10+ %2",
" ",
""
),
"no_cpu",
false,
true
);
}
if ($app_types->ati) {
$project_pref_descs[] = new PREF_BOOL (
tra(
"Use ATI GPU %1 Enforced by version 6.10+ %2",
" ",
""
),
"no_ati",
false,
true
);
}
if ($app_types->cuda) {
$project_pref_descs[] = new PREF_BOOL (
tra(
"Use NVIDIA GPU %1 Enforced by version 6.10+ %2",
" ",
""
),
"no_cuda",
false,
true
);
}
}
if (isset($project_has_beta) && $project_has_beta) {
$project_pref_descs[] = new PREF_BOOL(
tra(
"Run test applications? %1 This helps us develop applications, but may cause jobs to fail on your computer %2",
" ",
""
),
"allow_beta_work",
false
);
}
if (defined("EMAIL_FROM")) {
$x = " ".tra("Emails will be sent from %1; make sure your spam filter accepts this address.", EMAIL_FROM)."";
} else {
$x = "";
}
$privacy_pref_descs = array (
new PREF_BOOL(
tra("Is it OK for %1 and your team (if any) to email you?", PROJECT).$x,
"send_email",
true,
false
),
new PREF_BOOL(
tra("Should %1 show your computers on its web site?", PROJECT),
"show_hosts",
true,
false
),
);
define("DISK_LIMIT_DESC", tra("Disk and memory usage"));
define("CPU_LIMIT_DESC", tra("Processor usage"));
define("NETWORK_LIMIT_DESC", tra("Network usage"));
// These texts are used in multiple places in prefs_edit.php and add_venue.php
define("PREFS_FORM_DESC1", tra("These preferences apply to all the BOINC projects in which you participate.")."
");
define("PREFS_FORM_ERROR_DESC",
tra(
"%1Unable to update preferences.%2 The values marked in red below were out of range or not numeric.",
"",
""
).
"
"
);
global $text;
global $parse_result;
global $top_parse_result;
global $in_project_specific;
global $venue_name;
// get default settings for disk space usage so the default user
// preferences match the settings used by the scheduler.
// Defaults are set if the tags are missing, they depend on
// which scheduler is running:
// - 'old' has the default hardcoded
// - 'new' uses config settings
// if running the old scheduler, set
// in config.xml so the right default is set for minimum free disk space
//
function get_disk_space_config() {
global $config;
$config = get_config();
$dp->disk_max_used_gb = parse_config($config, "");
$dp->disk_max_used_pct = parse_config($config, "");
$dp->disk_min_free_gb = parse_config($config, "");
// set some defaults if not found
if (!$dp->disk_max_used_gb) $dp->disk_max_used_gb = 100; // 100 gb
if (!$dp->disk_max_used_pct) $dp->disk_max_used_pct = 50; // 50 percent
if (!$dp->disk_min_free_gb) $dp->disk_min_free_gb=.001; // 1 megabyte
// set mininimum free space scheduler allows
// - depends on which scheduler is running
$dp->new_sched_flag = 1;
$dp->sched_disk_min_free_gb = $dp->disk_min_free_gb;
if (parse_config($config, "scheduler_disk_space_check_hardcoded>")) {
$dp->new_sched_flag = 0;
$dp->sched_disk_min_free_gb = 0;
}
return $dp;
}
function check_venue($x) {
if ($x == "home") return;
if ($x == "work") return;
if ($x == "school") return;
error_page(tra("bad venue: %1", $x));
}
function check_subset($x) {
if ($x == "global") return;
if ($x == "project") return;
error_page(tra("bad subset: %1", $x));
}
// functions to parse preferences XML into a struct
//
function element_start_project($parser, $name, $attrs) {
global $top_parse_result;
global $parse_result;
global $text;
global $in_project_specific;
global $venue_name;
switch($name) {
case "venue":
$venue_name = $attrs["name"];
$top_parse_result = $parse_result;
$parse_result = default_prefs_project();
break;
case "project_specific":
$in_project_specific = 1;
$text = "";
break;
default:
if ($in_project_specific) {
$text= $text."<$name>";
} else {
$text = "";
}
}
}
function element_start_global($parser, $name, $attrs) {
global $top_parse_result;
global $parse_result;
global $text;
global $venue_name;
switch($name) {
case "venue":
$venue_name = $attrs["name"];
$top_parse_result = $parse_result;
$parse_result = default_prefs_global();
break;
}
$text = "";
}
function element_end_project($parser, $name) {
global $text;
global $parse_result;
global $in_project_specific;
global $top_parse_result;
global $venue_name;
global $project_pref_descs;
foreach($project_pref_descs as $p) {
if ($p->xml_parse($parse_result, $name, $text)) {
return;
}
}
switch($name) {
case "venue":
$top_parse_result->$venue_name = $parse_result;
$parse_result = $top_parse_result;
break;
case "project_specific":
$parse_result->project_specific = $text;
$in_project_specific = false;
break;
case "project_preferences":
break;
default:
if ($in_project_specific) {
$text = $text."$name>";
} else {
//echo "Unknown tag: $name\n";
}
}
}
function element_end_global($parser, $name) {
global $text;
global $parse_result;
global $top_parse_result;
global $venue_name;
global $cpu_prefs;
global $disk_prefs;
global $disk_prefs;
global $net_prefs;
foreach ($cpu_prefs as $p) {
if ($p->xml_parse($parse_result, $name, $text)) {
return;
}
}
foreach ($disk_prefs as $p) {
if ($p->xml_parse($parse_result, $name, $text)) {
return;
}
}
foreach ($net_prefs as $p) {
if ($p->xml_parse($parse_result, $name, $text)) {
return;
}
}
switch($name) {
case "venue":
$top_parse_result->$venue_name = $parse_result;
$parse_result = $top_parse_result;
break;
case "mod_time":
$parse_result->mod_time = $text;
break;
case "global_preferences":
break;
default:
//echo "Unknown tag: $name\n";
}
}
function char_handler($parser, $x) {
global $text;
$text = $text.$x;
}
// state of prefs before parsing; defines prefs for new users
//
function default_prefs_global() {
global $cpu_prefs;
global $disk_prefs;
global $net_prefs;
$p = null;
foreach ($cpu_prefs as $pref) {
$pref->set_default($p);
}
foreach ($disk_prefs as $pref) {
$pref->set_default($p);
}
foreach ($net_prefs as $pref) {
$pref->set_default($p);
}
return $p;
}
function default_prefs_project() {
global $project_pref_descs;
$p = null;
foreach($project_pref_descs as $pref) {
$pref->set_default($p);
}
$p->project_specific = project_specific_prefs_default();
return $p;
}
// parse prefs from XML to a struct
//
function prefs_parse_project($prefs_xml) {
global $parse_result;
$parse_result = default_prefs_project();
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "element_start_project", "element_end_project");
xml_set_character_data_handler($xml_parser, "char_handler");
xml_parse($xml_parser, $prefs_xml, 1);
return $parse_result;
}
function prefs_parse_global($prefs_xml) {
global $parse_result;
$parse_result = default_prefs_global();
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "element_start_global", "element_end_global");
xml_set_character_data_handler($xml_parser, "char_handler");
xml_parse($xml_parser, $prefs_xml, 1);
return $parse_result;
}
////////////////////////////////////////////
//
// display preference subsets as Columns
//
function row_top($x, $ncols=6, $class="heading") {
echo "
$x
";
echo "
".tra("Default")."
".tra("Home")."
".tra("School")."
".tra("Work")."
";
echo "
\n";
}
//
// row_defs - Display a value for all 4 venues in one row
//
function row_defs($pre, $item, $post, $type, $prefs) {
$gen = $prefs->$item;
$hom = (isset($prefs->home) && isset($prefs->home->$item)) ? $prefs->home->$item : "--";
$schl = (isset($prefs->school) && isset($prefs->school->$item)) ? $prefs->school->$item : "--";
$wrk = (isset($prefs->work) && isset($prefs->work->$item)) ? $prefs->work->$item : "--";
echo "
\n";
prefs_display_venue($project_prefs, "home", "project");
prefs_display_venue($project_prefs, "school", "project");
prefs_display_venue($project_prefs, "work", "project");
}
end_table();
}
function print_prefs_display_global($user, $columns=false) {
$global_prefs = prefs_parse_global($user->global_prefs);
echo "".
tra("These apply to all BOINC projects in which you participate.
On computers participating in multiple projects, the most recently modified preferences will be used.").
"
";
if (isset($global_prefs->mod_time)) {
echo tra("Preferences last modified:")." ".pretty_time_str($global_prefs->mod_time);
}
echo "