done
rm -rf "$tmp"
}
+
+html2txt() {
+ if which lynx > /dev/null; then
+ lynx -pseudo_inlines -nomargins -display_charset=utf8 -nocolor -nolist -width=999999 -dump "$1"
+ elif which w3m > /dev/null; then
+ w3m -dump -cols 999999 "$1"
+ else
+ echo "Please install lynx or w3m" 1>&2
+ return 1
+ fi
+}
+
+html2pdf() {
+ iconv -f utf-8 -t iso-8859-1 -c $@ | htmldoc --encryption --webpage --continuous --no-title --header '...' --footer '...' -
+}
+
+xml2csv() {
+ xsltproc $NB_ROOT/lib/xslt/xml2csv.xslt $@
+}
return
}
-_ldap_gup() {
- local usage="Usage: ldap_gup [filter attrs ...]"
- case "$*" in
- -h|-help) echo $usage; return;;
- esac
- local filer=$1; shift; [ -n "$filter" ] && filter="($filter)"
- local attrs=${*:-"uid"}; shift
-
- eval '
- local args
- slapcat_csv "(&(objectClass=posixGroup)(memberUid=*)$filter)" cn memberUid | while read -r -a rec; do
-
- group=${rec[0]}
- rec=("${rec[@]:1}") # shift
-
- for uid in ${rec[@]}; do
- rec=( $(slapcat_csv "(&(uid=$uid)(userPassword=*)(!(uid=test)))" userPassword $attrs) )
- pass=${rec[0]}
- rec=("${rec[@]:1}") # shift
- for field in ${rec[@]}; do
- echo $group:$field:$pass
- done
- done
-
- done
- '
- return
-}
-
ldap_backup() {
local keep_days=7
local dir=/var/backups/ldap
- local now=$(date +'%F-%H%M')
- local preff="$dir/$now"
+ local preff="$(date +'%F-%H%M')"
local usage="ldap_backup [-dir PATH] [-days DAYS]"
+
while [ $# -gt 0 ]; do
case "$1" in
-days) keep_days="$2"; shift ;;
esac
shift
done
- slapcat -n 0 -l $preff-config.ldif
- slapcat -n 1 -l $preff-data.ldif
- gzip $preff-*.ldif
- [ -n "$keep_days" -a "$keep_days" -gt 0 ] && find $dir/ -type f -mtime +$keep_days -delete
+
+ if [ ! -w "$dir" ] ; then
+ echo "ERR: can't write into $dir"
+ return 1
+ fi
+
+ slapcat -n 0 -l $dir/$preff-config.ldif
+ slapcat -n 1 -l $dir/$preff-data.ldif
+ gzip $dir/$preff-*.ldif
+
+ if [ -n "$keep_days" -a "$keep_days" -gt 0 ]; then
+ find $dir/ -type f -mtime +$keep_days -delete
+ fi
+
}
-resolve() {
+net_gateway_ip() {
+ case "$OSTYPE" in
+ darwin*) netstat -nr -f inet | awk '$1=="default"{print $2; exit}' ;;
+ *) ip route | awk '$1 == "default"{print $3; exit}' ;;
+ esac
+}
+
+net_gateway_interface() {
+ case "$OSTYPE" in
+ darwin*) netstat -nr -f inet | awk '$1=="default"{print $2; exit}' ;;
+ *) ip route | awk '$1 == "default"{print $5; exit}' ;;
+ esac
+}
+
+net_resolve() {
(
if [ -t 0 ]; then
while [ $# -gt 0 ]; do
) | perl -MSocket -pe 'BEGIN{sub ip2host{$i=shift;return $c{$i} if $c{$i};$h=gethostbyaddr(inet_aton($i),AF_INET);%c=()if keys(%c)>10000;return $c{$i}=$h?$h:$i;};}; s/(\b)(\d+(?:\.\d+){3})(\b)/$1.ip2host($2).$3/ge'
}
-cdr2mask() {
+net_cdr2mask() {
# Number of args to shift, 255..255, first non-255 byte, zeroes
eval 'set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0'
[ $1 -gt 1 ] && shift $1 || shift
echo ${1-0}.${2-0}.${3-0}.${4-0}
}
-mask2cdr() {
+net_mask2cdr() {
# Assumes there's no "255." after a non-255 byte in the mask
local x=${1##*255.}
set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*}
x=${1%%$3*}
echo $(( $2 + (${#x}/4) ))
}
-
-html2txt() {
- if which lynx > /dev/null; then
- lynx -pseudo_inlines -nomargins -display_charset=utf8 -nocolor -nolist -width=999999 -dump "$1"
- elif which w3m > /dev/null; then
- w3m -dump -cols 999999 "$1"
- else
- echo "Please install lynx or w3m" 1>&2
- return 1
- fi
-}
-
-html2pdf() {
- iconv -f utf-8 -t iso-8859-1 -c $@ | htmldoc --encryption --webpage --continuous --no-title --header '...' --footer '...' -
-}
-
-xml2csv() {
- xsltproc $NB_ROOT/lib/xslt/xml2csv.xslt $@
-}
+++ /dev/null
-DROP TABLE IF EXISTS http_status;
-CREATE TABLE http_status(id int primary key,name varchar(100),description varchar(1000));
-DELETE FROM http_status;
-.sep "\t"
-.import /Users/nico/tmp/http_status.txt http_status
--- SELECT * FROM http_status limit 5;