// ...
//
// 1.3
// ...
//
//
// ...
//
//
//
// and
//
//
// 4
//
// ... (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
include_once("../project/project_specific_prefs.inc");
// strings describing various preference fields
//
define("CPU_LIMIT_DESC", "Processor usage");
define("RUN_ON_BATTERIES_DESC",
"Do work while computer is running on batteries?
(matters only for portable computers)"
);
define("RUN_IF_USER_ACTIVE_DESC",
"Do work while computer is in use?"
);
define("IDLE_TIME_TO_RUN_DESC", "Do work only after computer is idle for");
define("IDLE_TIME_TO_RUN_DESC2", " (applies only if above is 'no')");
define("START_END_DESC", "Do work only between the hours of");
define("START_END_DESC2", " (no restriction if equal)");
define("LEAVE_APPS_IN_MEMORY_DESC",
"Leave applications in memory while preempted?
(suspended applications will consume swap space if 'yes')");
define("CPU_SCHEDULING_DESC", "Switch between applications every
(recommended: 60 minutes)");
define("CONFIRM_BEFORE_CONNECTING_DESC",
"Confirm before connecting to Internet?
(matters only if you have a modem, ISDN or VPN connection)"
);
define("HANGUP_IF_DIALED_DESC",
"Disconnect when done?
(matters only if you have a modem, ISDN or VPN connection)"
);
define("WORK_BUF_DESC",
"Connect to network about every
(determines size of work cache; maximum 10 days)
"
);
define("MAX_CPUS_DESC", "On multiprocessors, use at most");
define("MAX_CPUS_DESC2", "processors");
define("DISK_INTERVAL_DESC", "Write to disk at most every");
define("DISK_LIMIT_DESC", "Disk and memory usage");
define("DISK_MAX_USED_GB_DESC", "Use no more than");
define("DISK_MIN_FREE_GB_DESC", "Leave at least");
define("DISK_SCHED_MIN_FREE_DESC1", " (Values smaller than ");
define("DISK_SCHED_MIN_FREE_DESC2", " are ignored)");
define("DISK_MAX_USED_PCT_DESC", "Use no more than");
define("DISK_MAX_USED_PCT_DESC2", "% of total disk space");
define("VM_MAX_USED_PCT_DESC", "Use no more than");
define("VM_MAX_USED_PCT_DESC2", "% of total virtual memory");
define("NETWORK_LIMIT_DESC", "Network usage");
define("MAX_BYTES_SEC_DOWN_DESC", "Maximum download rate:");
define("MAX_BYTES_SEC_UP_DESC", "Maximum upload rate:");
define("NET_START_END_DESC",
"Use network only between the hours of
Enforced by versions 4.46 and greater"
);
define("DONT_VERIFY_IMAGES_DESC",
"Skip image file verification?
Check this ONLY if your Internet provider
modifies image files (UMTS does this, for example).
Skipping verification reduces the security of BOINC."
);
define("BYTE_CONVERSION", 1000.0);
define("BYTE_UNITS", "Kbytes/sec");
define("BYTE_ABBR", "KB/s");
define("MISC_DESC", "Miscellaneous");
global $text;
global $parse_result;
global $top_parse_result;
global $in_project_specific;
global $venue_name;
global $disk_prefs;
// 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
//
$disk_prefs = null;
function get_disk_space_config() {
global $disk_prefs;
global $config;
if ($disk_prefs == null) {
$config = get_config();
$disk_prefs->disk_max_used_gb = parse_config($config, "");
$disk_prefs->disk_max_used_pct = parse_config($config, "");
$disk_prefs->disk_min_free_gb = parse_config($config, "");
// set some defaults if not found
if (!$disk_prefs->disk_max_used_gb) $disk_prefs->disk_max_used_gb = 100; // 100 gb
if (!$disk_prefs->disk_max_used_pct) $disk_prefs->disk_max_used_pct = 50; // 50 percent
if (!$disk_prefs->disk_min_free_gb) $disk_prefs->disk_min_free_gb=.001; // 1 megabyte
// set mininimum free space scheduler allows
// - depends on which scheduler is running
$disk_prefs->new_sched_flag = 1;
$disk_prefs->sched_disk_min_free_gb = $disk_prefs->disk_min_free_gb;
if (parse_config($config, "scheduler_disk_space_check_hardcoded>")) {
$disk_prefs->new_sched_flag = 0;
$disk_prefs->sched_disl_min_free_gb = 0;
}
}
return $disk_prefs;
}
function check_venue($x) {
if ($x == "home") return;
if ($x == "work") return;
if ($x == "school") return;
error_page("bad venue: $x");
}
function check_subset($x) {
if ($x == "global") return;
if ($x == "project") return;
error_page("bad subset: $x");
}
// functions to convert between max_bytes_sec_* as stored in the
// database and max_bytes_sec_* as displayed/entered on the web
// pages. Currently max_bytes_sec_* is stored in bytes and
// displayed/entered in Kbytes.
//
function max_bytes_display_mode($db_bytes) {
$disp_bytes = 0;
if ($db_bytes) {
$disp_bytes = $db_bytes / BYTE_CONVERSION;
}
return $disp_bytes;
}
function max_bytes_db_mode($disp_bytes) {
$db_bytes = 0;
if ($disp_bytes) {
$db_bytes = $disp_bytes * BYTE_CONVERSION;
}
return $db_bytes;
}
// 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 = null;
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 = null;
break;
}
$text = "";
}
function element_end_project($parser, $name) {
global $text;
global $parse_result;
global $in_project_specific;
global $top_parse_result;
global $venue_name;
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 "resource_share":
$parse_result->resource_share = $text;
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;
switch($name) {
case "venue":
$top_parse_result->$venue_name = $parse_result;
$parse_result = $top_parse_result;
break;
case "run_on_batteries":
$parse_result->run_on_batteries = true;
break;
case "run_if_user_active":
$parse_result->run_if_user_active = true;
break;
case "idle_time_to_run":
$parse_result->idle_time_to_run = $text;
break;
case "start_hour":
$parse_result->start_hour = $text;
break;
case "end_hour":
$parse_result->end_hour = $text;
break;
case "leave_apps_in_memory":
$parse_result->leave_apps_in_memory = true;
break;
case "cpu_scheduling_period_minutes":
$parse_result->cpu_scheduling_period_minutes = $text;
break;
case "confirm_before_connecting":
$parse_result->confirm_before_connecting = true;
break;
case "hangup_if_dialed":
$parse_result->hangup_if_dialed = true;
break;
case "work_buf_min_days":
$parse_result->work_buf_min_days = $text;
break;
case "max_cpus":
$parse_result->max_cpus = $text;
break;
case "disk_interval":
$parse_result->disk_interval = $text;
break;
case "disk_max_used_gb":
$parse_result->disk_max_used_gb = $text;
break;
case "disk_max_used_pct":
$parse_result->disk_max_used_pct = $text;
break;
case "disk_min_free_gb":
$parse_result->disk_min_free_gb = $text;
break;
case "vm_max_used_pct":
$parse_result->vm_max_used_pct = $text;
break;
case "max_bytes_sec_down":
$parse_result->max_bytes_sec_down = $text;
break;
case "max_bytes_sec_up":
$parse_result->max_bytes_sec_up = $text;
break;
case "net_start_hour":
$parse_result->net_start_hour = $text;
break;
case "net_end_hour":
$parse_result->net_end_hour = $text;
break;
case "dont_verify_images":
$parse_result->dont_verify_images = true;
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 for new users
//
function default_prefs_global() {
$p = null;
$p->run_on_batteries = false;
$p->run_if_user_active = true;
$p->idle_time_to_run = 3;
$p->start_hour = 0;
$p->end_hour = 0;
$p->leave_apps_in_memory = false;
$p->cpu_scheduling_period_minutes = 60;
$p->confirm_before_connecting = false;
$p->hangup_if_dialed = true;
$p->work_buf_min_days = .1;
$p->max_cpus = 2;
$p->disk_interval = 60;
$dp = get_disk_space_config();
$p->disk_max_used_gb = $dp->disk_max_used_gb;
$p->disk_max_used_pct = $dp->disk_max_used_pct;
$p->disk_min_free_gb = $dp->disk_min_free_gb;
$p->vm_max_used_pct = 75;
$p->max_bytes_sec_down = 0;
$p->max_bytes_sec_up = 0;
$p->net_start_hour = 0;
$p->net_end_hour = 0;
$p->dont_verify_images = false;
return $p;
}
function default_prefs_project() {
$p = null;
$p->resource_share = 100;
$p->project_specific = project_specific_prefs_default();
return $p;
}
// state of prefs before parsing; initialize all booleans to false
//
function initialize_prefs_before_parsing_global() {
$p = default_prefs_global();
$p->run_on_batteries = false;
$p->run_if_user_active = false;
$p->leave_apps_in_memory = false;
$p->confirm_before_connecting = false;
$p->hangup_if_dialed = false;
return $p;
}
function initialize_prefs_before_parsing_project() {
$p = default_prefs_project();
return $p;
}
// parse prefs from XML to a struct
//
function prefs_parse_project($prefs_xml) {
global $parse_result;
$parse_result = initialize_prefs_before_parsing_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 = initialize_prefs_before_parsing_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;
}
function hour_str($x) {
return "$x:00";
}
function hour_select($x, $name) {
$s = "";
$s = $s. "\n";
return $s;
}
////////////////////////////////////////////
//
// display preference subsets
//
function prefs_show_global($prefs) {
row1(CPU_LIMIT_DESC);
row2(RUN_ON_BATTERIES_DESC, $prefs->run_on_batteries?"yes":"no");
row2(RUN_IF_USER_ACTIVE_DESC, $prefs->run_if_user_active?"yes":"no");
if (!$prefs->run_if_user_active) {
row2(IDLE_TIME_TO_RUN_DESC, "$prefs->idle_time_to_run minutes");
}
if ($prefs->start_hour == $prefs->end_hour) {
$x = "(no restriction)";
} else {
$s = hour_str($prefs->start_hour);
$e = hour_str($prefs->end_hour);
$x = "$s and $e";
}
row2(START_END_DESC, $x);
row2(LEAVE_APPS_IN_MEMORY_DESC, $prefs->leave_apps_in_memory?"yes":"no");
row2(CPU_SCHEDULING_DESC, "$prefs->cpu_scheduling_period_minutes minutes");
row2(MAX_CPUS_DESC, "$prefs->max_cpus ".MAX_CPUS_DESC2);
row1(DISK_LIMIT_DESC);
row2(DISK_MAX_USED_GB_DESC, "$prefs->disk_max_used_gb GB disk space");
$dp = get_disk_space_config();
$msg=null;
if ($dp->new_sched_flag) {
$msg = DISK_SCHED_MIN_FREE_DESC1.$dp->sched_disk_min_free_gb.DISK_SCHED_MIN_FREE_DESC2;
}
row2(DISK_MIN_FREE_GB_DESC.$msg, "$prefs->disk_min_free_gb GB disk space free");
row2(DISK_MAX_USED_PCT_DESC, "$prefs->disk_max_used_pct".DISK_MAX_USED_PCT_DESC2);
row2(DISK_INTERVAL_DESC, "$prefs->disk_interval seconds");
row2(VM_MAX_USED_PCT_DESC, "$prefs->vm_max_used_pct".VM_MAX_USED_PCT_DESC2);
row1(NETWORK_LIMIT_DESC);
row2(WORK_BUF_DESC, "$prefs->work_buf_min_days days");
row2(CONFIRM_BEFORE_CONNECTING_DESC, $prefs->confirm_before_connecting?"yes":"no");
row2(HANGUP_IF_DIALED_DESC, $prefs->hangup_if_dialed?"yes":"no");
$x = max_bytes_display_mode($prefs->max_bytes_sec_down);
$y = "$x " . BYTE_ABBR;
row2(MAX_BYTES_SEC_DOWN_DESC, $x?"$y":"no limit");
$x = max_bytes_display_mode($prefs->max_bytes_sec_up);
$y = "$x " . BYTE_ABBR;
row2(MAX_BYTES_SEC_UP_DESC, $x?"$y":"no limit");
if ($prefs->net_start_hour == $prefs->net_end_hour) {
$x = "(no restriction)";
} else {
$s = hour_str($prefs->net_start_hour);
$e = hour_str($prefs->net_end_hour);
$x = "$s and $e";
}
row2(NET_START_END_DESC, $x);
row2(DONT_VERIFY_IMAGES_DESC, $prefs->dont_verify_images?"yes":"no");
}
function prefs_show_resource($prefs) {
row2(
"Resource share
If you participate in multiple BOINC projects, this is the proportion of your resources used by ".PROJECT."",
$prefs->resource_share
);
}
function prefs_show_privacy($user) {
row1(MISC_DESC);
row2("Should ".PROJECT." send you email newsletters?", $user->send_email?"yes":"no");
row2("Should ".PROJECT." show your computers on its web site?", $user->show_hosts?"yes":"no");
}
function prefs_show_project($prefs) {
$project_specific_prefs = project_specific_prefs_parse($prefs->project_specific);
project_specific_prefs_show($project_specific_prefs);
}
function subset_name($subset) {
if ($subset == "global") return "General";
return PROJECT;
}
function prefs_display_venue($prefs, $venue, $subset) {
$x = $prefs->$venue;
if ($x) {
row1("Separate preferences for $venue", 2, "heading2");
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) {
$global_prefs = prefs_parse_global($user->global_prefs);
echo "
These apply to all BOINC projects in which you participate.
On computers attached to multiple projects,
the most recently modified preferences will be used.
Preferences last modified: ", pretty_time_str($global_prefs->mod_time), "