[services-cvs] CVS services/etc/misc
CVS User miham
root at tempel.bibl.u-szeged.hu
2004. Nov. 23., K, 21:06:57 CET
Update of /var/lib/cvs/services/etc/misc
In directory tempel:/tmp/cvs-serv16506
Modified Files:
listDB.php
Log Message:
Some minor tweaks:
* fixed search parameterhandling
* fixed docs
* fixed the zero-result search displays
--- /var/lib/cvs/services/etc/misc/listDB.php 2004/11/23 16:38:37 1.1
+++ /var/lib/cvs/services/etc/misc/listDB.php 2004/11/23 20:06:57 1.2
@@ -16,7 +16,7 @@
if (!sizeof($argv)) {
write_error("Missing parameter for search!");
exit(1);
- } elseif (!validate_search_param($sp = array_shift($argv))) {
+ } elseif (!($sp = validate_search_param(array_shift($argv)))) {
// Error notification done in validate_search_param() function
exit(1);
} else {
@@ -44,7 +44,7 @@
exit(1);
} elseif (!validate_display_fields($fields = explode(":",
($f = array_shift($argv))),$params)) {
- write_error("Wrong parameter format ({$f}) for fields!");
+ // Error notification done in validate_display_fields() function
exit(1);
} else {
$fieldlens = array();
@@ -107,7 +107,10 @@
write_error("Requested functionality ({$oper}) is under development!");
exit(1);
} else {
- call_user_func("handle_{$oper}", $params);
+ if (call_user_func("handle_{$oper}", $params))
+ exit(0);
+ else
+ exit(1);
}
// {{{ HELP SECTION
@@ -130,21 +133,21 @@
function display_general_help() {
echo "Usage: listDB.php action [options]\n\n";
echo "Actions:\n";
- echo "--search | -s [paramtype:paramvalue] - Searches for the given pattern\n";
- echo "--list | -l - Lists every host entry\n";
- echo "--help | -h - Displays the help\n\n";
+ echo "--search | -s [search expression] - Searches for the given pattern\n";
+ echo "--list | -l - Lists every host entry\n";
+ echo "--help | -h - Displays the help\n\n";
echo "Options:\n";
- echo " --short | -S - Displays entries in short form\n";
- echo " --fields | -F - Supply a colon-separated list \n";
- echo " of displayed fields\n";
- echo " If not supplied, the default\n";
- echo " is: room, user, host, subd, mac\n";
- echo " --columns | -C - Supply the width of your terminal\n";
- echo " The default value is 80\n";
- echo " --normal | -N - Displays entries in normal form\n";
- echo " This is the default behaviour.\n";
- echo " --long | -L - Displays entries in long form\n";
- echo " --force | -f - Force mode\n\n";
+ echo " --short | -S - Displays entries in short form\n";
+ echo " --fields | -F - Supply a colon-separated list \n";
+ echo " of displayed fields\n";
+ echo " If not supplied, the default\n";
+ echo " is: room, user, host, subd, mac\n";
+ echo " --columns | -C - Supply the width of your terminal\n";
+ echo " The default value is 80\n";
+ echo " --normal | -N - Displays entries in normal form\n";
+ echo " This is the default behaviour.\n";
+ echo " --long | -L - Displays entries in long form\n";
+ echo " --force | -f - Force mode\n\n";
echo "Examples:\n";
echo "listDB.php -l -S -F mac:ip:host:subd - Lists the entries in short form,\n";
echo " only displaying the macaddress,\n";
@@ -165,10 +168,11 @@
}
function display_search_help() {
- echo "\nDetailed help about search:\n\n";
+ echo "Detailed help about search:\n\n";
+ echo "Syntax: listDB.php -s 'key:value[|key2:value2[..]]'\n\n";
echo "Search is working the following way:\n";
echo "The program restricts the list of hosts to display to those which\n";
- echo "matches the search criteria, then displays them as if you were called\n";
+ echo "matches every search criterias then displays them as if you were called\n";
echo "the list action.\n\n";
echo "Examples:\n";
echo "listDB.php -s mac:00:0f:20:74:cb -S -F mac:ip\n";
@@ -178,6 +182,9 @@
echo "listDB.php -s rack:R4 -L\n";
echo "The above command will display every host which is connected to the R4\n";
echo "rack cupboard in long form.\n\n";
+ echo "listDB.php -s 'rack:R4|vlan:olv' -L\n";
+ echo "The above command will display every host in long form which is connected \n";
+ echo "to the R4 rack cupboard and is connected to the olv vlan.\n\n";
display_copyright();
exit(0);
@@ -318,6 +325,11 @@
$searchres[] = $actent;
}
+ if (!sizeof($searchres)) {
+ write_error("No host matches your query!");
+ return FALSE;
+ }
+
$display = $params['display'];
if ($display == 'short') {
display_item_short_header($params);
@@ -329,6 +341,12 @@
}
function validate_search_param($sp) {
+ if ($sp[0] == '"' || $sp[0] == "'") {
+ $sp = substr($sp, 1, -1);
+ } else {
+ $sp = $sp;
+ }
+
$searchreqs = explode('|', $sp);
foreach ($searchreqs as $actsr) {
@@ -353,7 +371,7 @@
}
}
- return TRUE;
+ return $sp;
}
// }}}
// {{{ MISC SECTION
@@ -421,18 +439,24 @@
}
function validate_display_fields($fields, $params) {
- if (!sizeof($fields))
+ if (!sizeof($fields)) {
+ write_error("Please supply the fields to be displayed!");
return FALSE;
+ }
$len = 0;
foreach ($fields as $actf) {
if (!($actl = get_param_length($actf))) {
+ write_error("Unknown field '{$actf}'!");
return FALSE;
}
$len += $actl + 2;
}
- if (!isset($params['force']) && $len > $params['columns'])
+ if (!isset($params['force']) && $len > $params['columns']) {
+ write_error("The requested fields are too wide to be displayed correctly!");
+ write_error("Please use -C <width> or the --force option!");
return FALSE;
+ }
return TRUE;
}
További információk a(z) Services-cvs levelezőlistáról