';
print_r ($var);
echo '
';
}
function getTagChart ($limit = 0, $realm = 'total', $special_tags = array())
{
global $taglist;
// first build top-N chart...
$toplist = array();
foreach ($taglist as $taginfo)
if (isset ($taginfo['refcnt'][$realm]))
$toplist[$taginfo['id']] = $taginfo['refcnt'][$realm];
arsort ($toplist, SORT_NUMERIC);
$ret = array();
$done = 0;
foreach (array_keys ($toplist) as $tag_id)
{
$ret[$tag_id] = $taglist[$tag_id];
if (++$done == $limit)
break;
}
// ...then make sure, that every item of the special list is shown
// (using the same sort order)
$extra = array();
foreach ($special_tags as $taginfo)
if (!array_key_exists ($taginfo['id'], $ret))
$extra[$taginfo['id']] = $taglist[$taginfo['id']]['refcnt'][$realm];
arsort ($extra, SORT_NUMERIC);
foreach (array_keys ($extra) as $tag_id)
$ret[] = $taglist[$tag_id];
return $ret;
}
function decodeObjectType ($objtype_id, $style = 'r')
{
static $types = array();
if (!count ($types))
$types = array
(
'r' => readChapter (CHAP_OBJTYPE),
'a' => readChapter (CHAP_OBJTYPE, 'a'),
'o' => readChapter (CHAP_OBJTYPE, 'o')
);
return $types[$style][$objtype_id];
}
function isolatedPermission ($p, $t, $cell)
{
// This function is called from both "file" page and a number of other pages,
// which have already fixed security context and authorized the user for it.
// OTOH, it is necessary here to authorize against the current file, which
// means saving the current context and building a new one.
global
$expl_tags,
$impl_tags,
$target_given_tags,
$auto_tags;
// push current context
$orig_expl_tags = $expl_tags;
$orig_impl_tags = $impl_tags;
$orig_target_given_tags = $target_given_tags;
$orig_auto_tags = $auto_tags;
// retarget
fixContext ($cell);
// remember decision
$ret = permitted ($p, $t);
// pop context
$expl_tags = $orig_expl_tags;
$impl_tags = $orig_impl_tags;
$target_given_tags = $orig_target_given_tags;
$auto_tags = $orig_auto_tags;
return $ret;
}
function getPortListPrefs()
{
$ret = array();
if (0 >= ($ret['iif_pick'] = getConfigVar ('DEFAULT_PORT_IIF_ID')))
$ret['iif_pick'] = 1;
$ret['oif_picks'] = array();
foreach (explode (';', getConfigVar ('DEFAULT_PORT_OIF_IDS')) as $tmp)
{
$tmp = explode ('=', trim ($tmp));
if (count ($tmp) == 2 and $tmp[0] > 0 and $tmp[1] > 0)
$ret['oif_picks'][$tmp[0]] = $tmp[1];
}
// enforce default value
if (!array_key_exists (1, $ret['oif_picks']))
$ret['oif_picks'][1] = 24;
$ret['selected'] = $ret['iif_pick'] . '-' . $ret['oif_picks'][$ret['iif_pick']];
return $ret;
}
// Return data for printNiftySelect() with port type options. All OIF options
// for the default IIF will be shown, but only the default OIFs will be present
// for each other IIFs. IIFs, for which there is no default OIF, will not
// be listed.
// This SELECT will be used for the "add new port" form.
function getNewPortTypeOptions()
{
$ret = array();
$prefs = getPortListPrefs();
foreach (getPortInterfaceCompat() as $row)
{
if ($row['iif_id'] == $prefs['iif_pick'])
$optgroup = $row['iif_name'];
elseif (array_key_exists ($row['iif_id'], $prefs['oif_picks']) and $prefs['oif_picks'][$row['iif_id']] == $row['oif_id'])
$optgroup = 'other';
else
continue;
if (!array_key_exists ($optgroup, $ret))
$ret[$optgroup] = array();
$ret[$optgroup][$row['iif_id'] . '-' . $row['oif_id']] = $row['oif_name'];
}
return $ret;
}
// Return a serialized version of VLAN configuration for a port.
// If a native VLAN is defined, print it first. All other VLANs
// are tagged and are listed after a plus sign. When no configuration
// is set for a port, return "default" string.
function serializeVLANPack ($vlanport)
{
if (!array_key_exists ('mode', $vlanport))
return 'error';
switch ($vlanport['mode'])
{
case 'none':
return 'none';
case 'access':
$ret = 'A';
break;
case 'trunk':
$ret = 'T';
break;
case 'uplink':
$ret = 'U';
break;
case 'downlink':
$ret = 'D';
break;
default:
return 'error';
}
if ($vlanport['native'])
$ret .= $vlanport['native'];
$tagged_bits = groupIntsToRanges ($vlanport['allowed'], $vlanport['native']);
if (count ($tagged_bits))
$ret .= '+' . implode (', ', $tagged_bits);
return strlen ($ret) ? $ret : 'default';
}
function groupIntsToRanges ($list, $exclude_value = NULL)
{
$result = array();
sort ($list);
$id_from = $id_to = 0;
$list[] = -1;
foreach ($list as $next_id)
if (!isset ($exclude_value) or $next_id != $exclude_value)
if ($id_to && $next_id == $id_to + 1)
$id_to = $next_id; // merge
else
{
if ($id_to)
$result[] = $id_from == $id_to ? $id_from : "${id_from}-${id_to}"; // flush
$id_from = $id_to = $next_id; // start next pair
}
return $result;
}
// Decode VLAN compound key (which is a string formatted DOMAINID-VLANID) and
// return the numbers as an array of two.
function decodeVLANCK ($string)
{
$matches = array();
if (1 != preg_match ('/^([[:digit:]]+)-([[:digit:]]+)$/', $string, $matches))
throw new InvalidArgException ('VLAN compound key', $string);
return array ($matches[1], $matches[2]);
}
// Return VLAN name formatted for HTML output (note, that input
// argument comes from database unescaped).
function formatVLANName ($vlaninfo, $context = 'markup long')
{
switch ($context)
{
case 'option':
$ret = $vlaninfo['vlan_id'];
if ($vlaninfo['vlan_descr'] != '')
$ret .= ' ' . niftyString ($vlaninfo['vlan_descr']);
return $ret;
case 'label':
$ret = $vlaninfo['vlan_id'];
if ($vlaninfo['vlan_descr'] != '')
$ret .= '