From ddd18cfc3315e989c3a6b8a9852e9e0298880505 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 3 Apr 2018 03:37:41 +0100 Subject: [PATCH] etc/profile.d/net.sh --- etc/profile.d/functions | 19 +++++++++++++++ etc/profile.d/ldap.sh | 51 ++++++++++++--------------------------- etc/profile.d/net.sh | 39 +++++++++++++----------------- src/db/http_status.script | 6 ----- 4 files changed, 52 insertions(+), 63 deletions(-) delete mode 100644 src/db/http_status.script diff --git a/etc/profile.d/functions b/etc/profile.d/functions index 267bb79a..edc853d5 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -917,3 +917,22 @@ minify_dir() { 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 $@ +} diff --git a/etc/profile.d/ldap.sh b/etc/profile.d/ldap.sh index 8c3a4fc4..12c8ea2c 100644 --- a/etc/profile.d/ldap.sh +++ b/etc/profile.d/ldap.sh @@ -139,41 +139,12 @@ ldap_gup() { 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 ;; @@ -182,8 +153,18 @@ ldap_backup() { 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 + } diff --git a/etc/profile.d/net.sh b/etc/profile.d/net.sh index 812c689d..ccd7565e 100644 --- a/etc/profile.d/net.sh +++ b/etc/profile.d/net.sh @@ -1,4 +1,18 @@ -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 @@ -11,36 +25,17 @@ resolve() { ) | 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 $@ -} diff --git a/src/db/http_status.script b/src/db/http_status.script deleted file mode 100644 index cd3afb3e..00000000 --- a/src/db/http_status.script +++ /dev/null @@ -1,6 +0,0 @@ -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; -- 2.47.3