";
+ return true;
+ } else {
+ // set two classes, one eneraic to all foreign, and one based on the peer's shortname for finer grain tuning
+ printf ('
\n";
+}
+
+// interpret standard syntax for peerscope
function plc_peer_info ($api,$peerscope) {
- switch ($_GET['peerscope']) {
+ switch ($peerscope) {
case '':
$peer_filter=array();
$peer_label="all peers";
@@ -102,54 +277,50 @@ function plc_peer_info ($api,$peerscope) {
$peer_label="foreign peers";
break;
default:
- $peer_id=intval($_GET['peerscope']);
- $peer_filter=array("peer_id"=>$peer_id);
- $peer=$api->GetPeers(array("peer_id"=>$peer_id));
- $peer_label='peer "' . $peer[0]['peername'] . '"';
+ if (is_int ($peerscope)) {
+ $peer_id=intval($peerscope);
+ $peers=$api->GetPeers(array("peer_id"=>$peer_id));
+ } else {
+ $peers=$api->GetPeers(array("shortname"=>$peerscope));
+ }
+ if ($peers) {
+ $peer=$peers[0];
+ $peer_id=$peer['peer_id'];
+ $peer_filter=array("peer_id"=>$peer_id);
+ $peer_label='peer "' . $peer['shortname'] . '"';
+ } else {
+ $peer_filter=array();
+ $peer_label="[no such peer " . $peerscope . "]";
+ }
break;
}
return array ($peer_filter,$peer_label);
}
-//////////////////////////////////////////////////////////// links
-function href ($url,$text) { return "
" . $text . ""; }
-
-function l_nodes () { return "/db/nodes/newindex.php"; }
-function l_node_u ($node_id) { return "/db/nodes/node.php?id=" . $node_id; }
-function l_node ($node_id) { return href (l_node_u($node_id),$node_id); }
-function l_node2 ($node_id,$text) { return href (l_node_u($node_id),$text); }
-
-function l_sites () { return "/db/sites/index.php"; }
-function l_site_u ($site_id) { return "/db/persons/index.php?id=" . $site_id; }
-function l_site ($site_id) { return href (l_site_u($site_id),$site_id); }
-function l_site2 ($site_id,$text) { return href (l_site_u($site_id),$text); }
-
-function l_slices () { return "/db/slices/index.php"; }
-function l_slice_u ($slice_id) { return "/db/persons/index.php?id=" . $slice_id; }
-function l_slice ($slice_id) { return href (l_slice_u($slice_id),$slice_id); }
-function l_slice2 ($slice_id,$text) { return href (l_slice_u($slice_id),$text); }
-
-function l_persons () { return "/db/persons/index.php"; }
-function l_person_u ($person_id) { return "/db/persons/index.php?id=" . $person_id; }
-function l_person ($person_id) { return href (l_person_u($person_id),$person_id); }
-function l_person2 ($person_id,$text) { return href (l_person_u($person_id),$text); }
-
-function l_interfaces () { return "/db/interfaces/index.php"; }
-function l_interface_u ($interface_id) { return "/db/interfaces/index.php?id=" . $interface_id; }
-function l_interface ($interface_id) { return href (l_interface_u($interface_id),$interface_id); }
-function l_interface2 ($interface_id,$text) { return href (l_interface_u($interface_id),$text); }
-
-function l_event ($type,$param,$id) { return '/db/events/index.php?type=' . $type . '&' . $param . '=' . $id; }
-function l_comon($id_name,$id_value) { return '/db/nodes/comon.php?' . $id_name . "=" . $id_value; }
-
+//////////////////////////////////////////////////////////// nodegroups
+// hash by 'tagname=value'
+function plc_nodegroup_global_hash ($api,$tagnames=NULL) {
+ $filter=NULL;
+ // xxx somehow this does not work; I've checked that the feature is working from plcsh
+ // but I suspect the php marshalling or something; no time to fix, get all nodegroups for now
+ // if ($tagnames) $filter=array("tagname"=>$tagnames);
+ $nodegroups=$api->GetNodeGroups($filter);
+ $hash=array();
+ if ($nodegroups) foreach ($nodegroups as $nodegroup) {
+ $key=$nodegroup['tagname']."=".$nodegroup['value'];
+ $hash[$key]=$nodegroup;
+ }
+ return $hash;
+}
+
//////////////////////////////////////////////////////////// titles
function t_site($site) { return " on site " . $site['name'] . " (" . $site['login_base'] .")"; }
function t_slice ($slice) { return " running slice " . $slice['name'] . " (" . $slice['slice_id'] . ")"; }
//////////////////////////////////////////////////////////// nav tabs
-function tabs_node($node) { return array('Node ' . $node['hostname']=>l_node_u($node_id)); }
-function tabs_site($site) { return array('Site ' . $site['name']=>l_site_u($site_id)); }
-function tabs_slice($slice) { return array('Slice ' . $slice['name']=>l_slice_u($slice_id)); }
+function tabs_node($node) { return array('Node ' . $node['hostname']=>l_node($node_id)); }
+function tabs_site($site) { return array('Site ' . $site['name']=>l_site($site_id)); }
+function tabs_slice($slice) { return array('Slice ' . $slice['name']=>l_slice($slice_id)); }
//////////////////////////////////////////////////////////// presentation
// builds a table from an array of strings, with the given class
@@ -184,29 +355,50 @@ function plc_comon_button ($id_name, $id_value,$target="") {
return $result;
}
-function plc_make_table ($class, $messages) {
+function plc_vertical_table ($messages, $class="") {
// pretty print the cell
+ if ( empty( $messages) ) return "";
$formatted = "";
- if (! empty ($messages)) {
- $formatted="
";
- foreach ($messages as $message) {
- $formatted .= "" . $message . " |
";
- }
- $formatted .= "
";
+ $formatted .= "
";
return $formatted;
}
+//////////////////////////////////////////////////////////// various mappers
+// could not figure how to use anonymous lambdas..
+function get_site_id ($site) { return $site['site_id'];}
+function get_tagname ($tag) { return $tag['tagname'];}
+
////////////////////////////////////////////////////////////
+function plc_section ($text,$line=true) {
+ if ($line) { print "
";}
+ print "
$text
\n";
+}
+
function plc_error ($text) {
// should use the same channel as the php errors..
- print "
Error " . $text . "
";
+ print "
Error " . $text . "
";
}
-function plc_warning ($text) {
- print "
Warning " . $text . "
";
+function plc_errors ($list) {
+ print( "
" );
+ print( "
The following errors occured:
" );
+ print("
");
+ foreach( $errors as $err ) {
+ print( "- $err
\n" );
+ }
+ print( "
\n" );
}
+function plc_warning_text ($text) { return "
" . $text . "
";}
+function plc_warning ($text) { print plc_warning_text("Warning " . $text); }
+function plc_foreign_text($text) { return "
$text
"; }
+
// shows a php variable verbatim with a heading message
function plc_debug ($message,$object) {
print "
" . $message . "
";
@@ -214,4 +406,5 @@ function plc_debug ($message,$object) {
print "
";
}
+
?>