From fd99a4ec297c3a38253983fc923715e9a4935078 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 19 Dec 2017 03:42:17 +0000 Subject: [PATCH] etc/profile.d/net.sh --- etc/profile.d/git.sh | 2 +- etc/profile.d/net.sh | 49 ++++++++++++++++++++------------------ lib/php/db/table.php | 1 + lib/php/db/types/pgsql.php | 4 ++++ www/dbq/dbq.php | 25 +++++++++---------- 5 files changed, 45 insertions(+), 36 deletions(-) diff --git a/etc/profile.d/git.sh b/etc/profile.d/git.sh index c4a55a11..d60579df 100644 --- a/etc/profile.d/git.sh +++ b/etc/profile.d/git.sh @@ -103,7 +103,7 @@ git_create() { git init # Create files - [ -e README.md ] || printf "\n=============\n## Synopsis\n\nDESCRIPTION\n" > README.md + [ -e README.md ] || printf "${dir}=============\n## Synopsis\n\nDESCRIPTION\n" > README.md echo ">git add README.md" git add README.md diff --git a/etc/profile.d/net.sh b/etc/profile.d/net.sh index 1e001a20..172f1668 100644 --- a/etc/profile.d/net.sh +++ b/etc/profile.d/net.sh @@ -1,35 +1,34 @@ resolve() { - ( - if [ -t 0 ]; then - while [ $# -gt 0 ]; do - printf '%s\n' "$1" - shift - done - else - cat - fi - ) | 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' + ( + if [ -t 0 ]; then + while [ $# -gt 0 ]; do + printf '%s\n' "$1" + shift + done + else + cat + fi + ) | 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' } -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) )) +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} } - -cdr2mask() { - # Number of args to shift, 255..255, first non-255 byte, zeroes - 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() { + # 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" + 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 @@ -38,6 +37,10 @@ html2txt() { fi } +html2pdf() { + iconv -f utf-8 -t iso-8859-1 -c | htmldoc --encryption --webpage --continuous --no-title --header '...' --footer '...' - +} + xml2csv() { xsltproc lib/xslt/xml2csv.xslt $@ } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index a53903be..02afb3c8 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -923,6 +923,7 @@ Class Table extends nb { public function buttons() { if (!$this->show_buttons or empty(self::$params)) return false; if (!preg_match('/(table|view)/',$this->type())) return false; + if ($fct = $this->db()->conf_type('print_buttons')) { $r = $fct($this); if ($r!==null) return $r; } return true; } diff --git a/lib/php/db/types/pgsql.php b/lib/php/db/types/pgsql.php index d9cb1508..41b50837 100644 --- a/lib/php/db/types/pgsql.php +++ b/lib/php/db/types/pgsql.php @@ -1,6 +1,10 @@ true, +# NB 19.12.17 'print_buttons' => function(&$t) { +# NB 19.12.17 if ($t->type = 'view' and preg_match('/GROUP BY/i',$t->sql())) return false; +# NB 19.12.17 return true; +# NB 19.12.17 }, 'replace_insert' => function(&$sql,&$table,$fields=[]) { $keys = $table->fields_keys($others); #if ($table->p('debug')) { diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 65f91285..20c01d5a 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -372,13 +372,14 @@ class DbQ extends nb { if (!$keys) $keys = $all; $keys = array_keys($keys); - $fields = $this->vi_extract_fields(); + #$fields = $this->vi_extract_fields(); $values = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : explode($this->param_args_sep,$this->params['args']); $values = $add ? array_fill(0,count($keys),'') : $values; +#bye([$this->params['args'],$keys,$values]); $values = array_combine($keys,$values); - # NB 23.11.17: Handle format for /vi/ + # NB 23.11.17: Handle format for /vi if ($this->params['format'] != $this->format_html) { $row = $this->db->query2h($this->table->sql_edit($values)); @@ -422,24 +423,24 @@ class DbQ extends nb { $args = $GLOBALS['dbq_args']; - if (1) { - $r = ['view' => join(' ',[ - 'View' - ]) ] + $r; - } else { +# NB 19.12.17 if (0) { +# NB 19.12.17 $r = ['view' => join(' ',[ +# NB 19.12.17 'View' +# NB 19.12.17 ]) ] + $r; +# NB 19.12.17 } else { $r = ['view' => join(' ',['' - .'
' - .'View' + .'' + .'View' .$this->form_hidden($r) .'
' ]) ] + $r; - } +# NB 19.12.17 } if ($this->perm < self::DELETE) return; if ($this->db->type == 'sqlite' and !is_writeable($this->db->host)) return; -# NB 11.12.17 $rm = $this->table->base.'/rm/'.$args; - $rm = $this->uri_add_referer($this->table->base.'/rm/'); +# NB 11.12.17 $rm = $this->table->base.'/rm'.$args; + $rm = $this->uri_add_referer($this->table->base.'/rm'); $r['delete'] = '' .'
' .'Delete' -- 2.47.3