5 // will trash this eventually
6 require_once 'plc_functions_trash.php';
8 //////////////////////////////////////////////////////////// validation functions
9 function topdomain ($hostname) {
10 $exploded=array_reverse(explode(".",$hostname));
14 function is_valid_email_addr ($email) {
15 if (ereg("^.+@.+\\..+$", $email) ) {
22 function is_valid_url ($url) {
23 if (ereg("^(http|https)://.+\..+$", strtolower($url) ) ) {
30 function is_valid_ip ($ip) {
31 if (ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $ip ) ) {
32 // it's at least in the right format, now check to see if
33 // each part is equal to less than 255
34 $parts= explode( '.', $ip );
35 $count= count($parts);
37 for( $i= 0; $i < $count; $i++ ) {
38 if( intval($parts[$i]) > 255 )
48 function is_valid_network_addr($network_addr,$mask) {
49 $lNetwork= ip2long($network_addr);
50 $lMask= ip2long($mask);
52 // are they the correct format?
53 if( $lNetwork == -1 || $lMask == -1 )
56 // is network address valid for the mask?
57 if( ($lNetwork & $lMask) != $lNetwork )
64 // returns whether or not a network address is in the reserved space
65 // in the case of a invalid network address, false will be returned.
66 function is_reserved_network_addr($network_addr) {
67 $lNetwork= ip2long($network_addr);
72 // does the network address fall in a reserved block?
73 $reserved_ips = array (
74 array('10.0.0.0','10.255.255.255'),
75 array('172.16.0.0','172.31.0.0'),
76 array('192.168.0.0','192.168.255.0')
78 foreach ($reserved_ips as $r) {
79 $min = ip2long($r[0]);
80 $max = ip2long($r[1]);
82 if (($lNetwork >= $min) && ($lNetwork <= $max))
89 //////////////////////////////////////////////////////////// peerscopes
90 function plc_peer_info ($api,$peerscope) {
91 switch ($_GET['peerscope']) {
94 $peer_label="all peers";
97 $peer_filter=array("peer_id"=>NULL);
98 $peer_label=PLC_SHORTNAME;
101 $peer_filter=array("~peer_id"=>NULL);
102 $peer_label="foreign peers";
105 $peer_id=intval($_GET['peerscope']);
106 $peer_filter=array("peer_id"=>$peer_id);
107 $peer=$api->GetPeers(array("peer_id"=>$peer_id));
108 $peer_label='peer "' . $peer[0]['peername'] . '"';
111 return array ($peer_filter,$peer_label);
114 //////////////////////////////////////////////////////////// links
115 function href ($url,$text) { return "<a href='" . $url . "'>" . $text . "</a>"; }
117 function l_nodes () { return "/db/nodes/newindex.php"; }
118 function l_node_u ($node_id) { return "/db/nodes/node.php?id=" . $node_id; }
119 function l_node ($node_id) { return href (l_node_u($node_id),$node_id); }
120 function l_node2 ($node_id,$text) { return href (l_node_u($node_id),$text); }
122 function l_sites () { return "/db/sites/index.php"; }
123 function l_site_u ($site_id) { return "/db/persons/index.php?id=" . $site_id; }
124 function l_site ($site_id) { return href (l_site_u($site_id),$site_id); }
125 function l_site2 ($site_id,$text) { return href (l_site_u($site_id),$text); }
127 function l_slices () { return "/db/slices/index.php"; }
128 function l_slice_u ($slice_id) { return "/db/persons/index.php?id=" . $slice_id; }
129 function l_slice ($slice_id) { return href (l_slice_u($slice_id),$slice_id); }
130 function l_slice2 ($slice_id,$text) { return href (l_slice_u($slice_id),$text); }
132 function l_persons () { return "/db/persons/index.php"; }
133 function l_person_u ($person_id) { return "/db/persons/index.php?id=" . $person_id; }
134 function l_person ($person_id) { return href (l_person_u($person_id),$person_id); }
135 function l_person2 ($person_id,$text) { return href (l_person_u($person_id),$text); }
137 function l_interfaces () { return "/db/interfaces/index.php"; }
138 function l_interface_u ($interface_id) { return "/db/interfaces/index.php?id=" . $interface_id; }
139 function l_interface ($interface_id) { return href (l_interface_u($interface_id),$interface_id); }
140 function l_interface2 ($interface_id,$text) { return href (l_interface_u($interface_id),$text); }
142 function l_event ($type,$param,$id) { return '/db/events/index.php?type=' . $type . '&' . $param . '=' . $id; }
143 function l_comon($id_name,$id_value) { return '/db/nodes/comon.php?' . $id_name . "=" . $id_value; }
145 //////////////////////////////////////////////////////////// titles
146 function t_site($site) { return " on site " . $site['name'] . " (" . $site['login_base'] .")"; }
147 function t_slice ($slice) { return " running slice " . $slice['name'] . " (" . $slice['slice_id'] . ")"; }
149 //////////////////////////////////////////////////////////// nav tabs
150 function tabs_node($node) { return array('Node ' . $node['hostname']=>l_node_u($node_id)); }
151 function tabs_site($site) { return array('Site ' . $site['name']=>l_site_u($site_id)); }
152 function tabs_slice($slice) { return array('Slice ' . $slice['name']=>l_slice_u($slice_id)); }
154 //////////////////////////////////////////////////////////// presentation
155 // builds a table from an array of strings, with the given class
156 // attempt to normalize the delete buttons and confirmations
157 function plc_delete_button($width=15) {
158 return '<span title="Delete this entry"><img width=' . $width . ' alt="Delete this entry" src="/planetlab/icons/delete.png"></span>';
161 function plc_js_confirm($message) {
162 return "onclick=\"javascript:return confirm('Are you sure you want to delete " . $message . " ?')\"";
165 function plc_delete_link($url,$delete_message,$visible) {
166 return "<a href='" . $url . "' " . plc_js_confirm($delete_message) . ">" . $visible . "</a>";
169 function plc_delete_link_button($url,$delete_message,$width=15) {
170 return "<a href='" . $url . "' " . plc_js_confirm($delete_message) . ">" . plc_delete_button($width) . "</a>";
173 function plc_event_button($type,$param,$id) {
174 return '<a href="' . l_event($type,$param,$id) . '"> <span title="Related events"> <img src="/planetlab/icons/event.png" width=18></span></a>';
177 function plc_comon_button ($id_name, $id_value,$target="") {
179 if (!empty($target)) {
180 $result.='target="' . $target . '" ';
182 $result.='href="' . l_comon($id_name,$id_value) . '">';
183 $result.='<span title="Link to Comon"> <img src="/planetlab/icons/comon.png" width="18"></span></a>';
187 function plc_make_table ($class, $messages) {
188 // pretty print the cell
190 if (! empty ($messages)) {
191 $formatted="<table class='" . $class . "'>";
192 foreach ($messages as $message) {
193 $formatted .= "<tr><td>" . $message . "</td></tr>";
195 $formatted .= "</table>";
200 ////////////////////////////////////////////////////////////
201 function plc_error ($text) {
202 // should use the same channel as the php errors..
203 print "<div class='plc-warning'> Error " . $text . "</div>";
206 function plc_warning ($text) {
207 print "<div class='plc-warning'> Warning " . $text . "</div>";
210 // shows a php variable verbatim with a heading message
211 function plc_debug ($message,$object) {
212 print "<br>" . $message . "<pre>";