. error_reporting(E_ALL); ini_set('display_errors', true); ini_set('display_startup_errors', true); require_once("../inc/db_ops.inc"); require_once("../inc/util.inc"); require_once("../project/project.inc"); function admin_page_head($title) { echo ""; echo "$title

".PROJECT.": $title

"; show_login_info(); } function admin_page_tail() { echo "
Main page
\n "; } // TODO: get rid of all the following function print_checkbox($text,$name,$checked) { echo "" . "$text\n" . "

\n"; } function print_radio_button($text,$name,$value,$checked) { echo "" . "$text\n" . "
\n"; } function print_text_field($text,$name,$value) { echo "$text \n" . "

\n"; } function row($x, $y) { echo "$x\n$y\n\n"; } function c_row2($color, $x, $y) { echo "$x$y\n"; } function show_profile_link_ops($user) { if ($user->has_profile) { row2("Profile", "id\">View" ); } } // initialize database connection with username & password from // command line instead of config.xml // function db_init_cli() { $config = get_config(); $db_name = parse_config($config, ""); $host = parse_config($config, ""); if ($host == null) { $host = "localhost"; } $in = fopen("php://stdin","r"); print "Database username (default: owner of mysqld process): "; $user = rtrim(fgets($in, 80)); print "Database password (if any): "; $pass = rtrim(fgets($in, 80)); $retval = _mysql_connect($host, $user, $pass, $db_name); if (!$retval) { die("Can't connect to DB\n"); } } function print_login_form_ops($next_url='') { if ($next_url == '') $next_url = $_SERVER['REQUEST_URI']; start_table(); echo "

"; row2("Email", ""); row2("Password", ""); row2(tra("Stay logged in on this computer"), ''); row2("", ""); end_table(); } function get_logged_in_user_ops() { global $g_logged_in_user; if ($g_logged_in_user) return $g_logged_in_user; $authenticator = null; if (isset($_COOKIE['auth'])) $authenticator = $_COOKIE['auth']; $authenticator = BoincDb::escape_string($authenticator); if ($authenticator) { $g_logged_in_user = BoincUser::lookup("authenticator='$authenticator'"); } return $g_logged_in_user; } ////////// functions for access control of admin web pages ///////////// // allow access only if logged in as user in a given set // function auth_ops_userid($admin_user_ids) { $user = get_logged_in_user_ops(); if (!$user) { admin_page_head("Log in"); echo "You must log in to performance admin functions.

\n"; print_login_form_ops(); admin_page_tail(); exit; } else if (!in_array($user->id, $admin_user_ids)) { admin_page_head("Log in"); echo " You must be logged in as an admin to perform admin functions.

Log out "; admin_page_tail(); exit; } } // allow access only to users with ADMIN/DEV flags in forum prefs. // If you use this, make sure you know who has these privileges // function auth_ops_privilege() { $user = get_logged_in_user_ops(); if (!$user) { admin_page_head("Log in"); echo "You must log in to performance admin functions.

\n"; print_login_form_ops(); admin_page_tail(); exit; } BoincForumPrefs::lookup($user); if ($user->prefs->privilege(S_ADMIN) || $user->prefs->privilege(S_DEV)) { return; } error_page("Access denied"); } // if project hasn't specified a policy in project.inc, // and no .htaccess, don't allow access // if (!function_exists('auth_ops')) { function auth_ops() { if (!file_exists(".htaccess")) { error_page(" You must protect the admin interface with either a .htaccess file or an auto_ops() function.

See how here" ); } } } function admin_error_page($msg) { admin_page_head("Unable to handle request"); echo $msg; admin_page_tail(); exit; } // given a list of app versions, // return a list of the current, non-deprecated ones // function current_versions($avs) { foreach($avs as $av) { foreach ($avs as $av2) { if ($av->id == $av2->id) continue; if ($av->platformid == $av2->platformid && $av->plan_class == $av2->plan_class && $av->version_num > $av2->version_num) { $av2->deprecated = 1; } } } $x = array(); foreach($avs as $av) { if (!$av->deprecated) $x[] = $av; } return $x; } // cancel WUs with IDs in a given range. // This means: // // - for any results w/ server state UNSENT, set server state to OVER // - set the CANCELLED bit in workunit.error_mask // function cancel_wus($wuid1, $wuid2) { $retval = BoincResult::update_aux("server_state=5, outcome=5 where server_state=2 and $wuid1<=workunitid and workunitid<=$wuid2"); if (!$retval) { error_page("Result update failed"); } $retval = BoincWorkunit::update_aux("error_mask=error_mask|16 where $wuid1<=id and id<=$wuid2"); if (!$retval) { error_page("Workunit update failed"); } // trigger the transitioner (it will set file_delete_state) $now = time(); $retval = BoincWorkunit::update_aux("transition_time=$now where $wuid1<=id and id<=$wuid2"); return 0; } // like above, but if a workunit has a result that's already sent, // don't cancel the workunit // function cancel_wus_if_unsent($id1, $id2) { $wus = BoincWorkunit::enum("id >= $id1 and id <= $id2"); foreach ($wus as $wu) { $results = BoincResult::enum("workunitid=$wu->id and server_state > 2"); if (count($results)) continue; $retval = BoincResult::update_aux("server_state=5, outcome=5 where workunitid=$wu->id"); if (!$retval) { error_page("result update failed"); } if (!$wu->update("error_mask=error_mask|16")) { error_page("WU update failed"); } } return 0; } function app_version_desc($avid) { switch ($avid) { case ANON_PLATFORM_UNKNOWN: return "Anonymous platform: unknown type"; case ANON_PLATFORM_CPU: return "Anonymous platform: CPU"; case ANON_PLATFORM_NVIDIA: return "Anonymous platform: NVIDIA GPU"; case ANON_PLATFORM_ATI: return "Anonymous platform: AMD GPU"; case ANON_PLATFORM_INTEL: return "Anonymous platform: Intel GPU"; } if ($avid <= 0) { return "unknown: $avid"; } $av = BoincAppVersion::lookup_id($avid); if ($av) { $p = BoincPlatform::lookup_id($av->platformid); if ($p) { return sprintf("%.2f", $av->version_num/100)." $p->name [$av->plan_class]"; } else { return sprintf("%.2f", $av->version_num/100)." MISSING PLATFORM $av->platformid [$av->plan_class]"; } } else { return "App version missing ($avid)"; } } ////// badge-related stuff function get_badge($name, $title, $image_url) { $b = BoincBadge::lookup("name='$name'"); if ($b) return $b; $now = time(); $id = BoincBadge::insert("(create_time, name, title, image_url) values ($now, '$name', '$title', 'img/$image_url')"); $b = BoincBadge::lookup_id($id); if ($b) return $b; die("can't create badge $name\n"); } function assign_badge($is_user, $item, $badge) { $now = time(); if ($is_user) { $bbu = BoincBadgeUser::lookup("user_id=$item->id and badge_id=$badge->id"); if ($bbu) { $bbu->update("reassign_time=$now where user_id=$item->id and badge_id=$badge->id"); } else { BoincBadgeUser::insert("(create_time, user_id, badge_id, reassign_time) values ($now, $item->id, $badge->id, $now)"); } } else { $bbt = BoincBadgeTeam::lookup("team_id=$item->id and badge_id=$badge->id"); if ($bbt) { $bbt->update("reassign_time=$now where team_id=$item->id and badge_id=$badge->id"); } else { BoincBadgeTeam::insert("(create_time, team_id, badge_id, reassign_time) values ($now, $item->id, $badge->id, $now)"); } } } // unassign all badges except the given one // function unassign_badges($is_user, $item, $badges, $k) { $list = null; for ($i=0; $iid and badge_id in ($list)"); } else { BoincBadgeTeam::delete("team_id=$item->id and badge_id in ($list)"); } } ////// end badge-related stuff function running_from_web_server() { return array_key_exists("SERVER_PORT", $_SERVER); } if (isset($cli_only)) { if (running_from_web_server()) { die("This script is intended to be run from the command line, not from the web server." ); } } if (!isset($skip_auth_ops) && array_key_exists("SERVER_PORT", $_SERVER)) { auth_ops(); } // TODO: use DB interface layer // function cancel_wus_where($clause) { $q1 = "CREATE TEMPORARY TABLE tmp SELECT id FROM workunit WHERE $clause;"; $q2 = "UPDATE result SET server_state=5, outcome=5 WHERE server_state=2 AND workunitid in (SELECT id FROM tmp);"; $q3 = "UPDATE workunit SET error_mask=error_mask|16 WHERE id in (SELECT id FROM tmp);"; $q4 = "UPDATE workunit SET transition_time=0 WHERE id in (SELECT id FROM tmp);"; $q5 = "DROP TABLE tmp;"; if (!_mysql_query($q1)) { echo "MySQL command '$q1' failed:
unable to create temporary WU id table.
\n"; return 1; } else if (!_mysql_query($q2)) { echo "MySQL command '$q2' failed:
unable to cancel unsent results.
\n"; _mysql_query($q5); return 2; } else if (!_mysql_query($q3)) { echo "MySQL command '$q3' failed:
unable to cancel workunits.
\n"; _mysql_query($q5); return 3; } else if (!_mysql_query($q4)) { echo "MySQL command '$q4' failed:
unable to trigger transitioner.
\n"; _mysql_query($q5); return 4; } _mysql_query($q5); echo "Successfully canceled WUs WHERE '$clause'
\n"; return 0; } $cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit ?>