]> git.plutz.net Git - cgilite/commitdiff
new function RXLITERAL() for escaping regex characters master
authorPaul Hänsch <paul@plutz.net>
Tue, 14 May 2024 10:11:55 +0000 (12:11 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 14 May 2024 10:11:55 +0000 (12:11 +0200)
cgilite.awk
common.css
markdown.awk
storage.sh
users.sh

index f16ed6a3281746d6182cd4f340eb15910f6c5a87..ebf44113d1b3333eec25166a81201d01b3cd3703 100644 (file)
@@ -1,5 +1,7 @@
 #!/bin/env awk -f
 
 #!/bin/env awk -f
 
+function debug(t) { printf "%s\n", t >>"/dev/stderr"; }
+
 function PATH( str,    seg, out ) {
   while ( str ) {
     seg = str;
 function PATH( str,    seg, out ) {
   while ( str ) {
     seg = str;
@@ -151,8 +153,9 @@ BEGIN {
   split("", _GET); split("", _POST); split("", _REF);
   split("", _HEADER); split("", _COOKIE);
 
   split("", _GET); split("", _POST); split("", _REF);
   split("", _HEADER); split("", _COOKIE);
 
-  if ( ENVIRON["REQUEST_METHOD"] )
+  if ( ENVIRON["REQUEST_METHOD"] ) {
     _cgilite_headers();
     _cgilite_headers();
-  else
+  } else {
     _cgilite_request();
     _cgilite_request();
+  }
 }
 }
index 30c3942eb5d8a2b4ef42e3fceb972b2d8c54a495..16e99f23befd1f945ee7efbd71707a48ccd367ad 100644 (file)
@@ -31,7 +31,7 @@ a {
   color: #068;
   word-break: break-word;
 }
   color: #068;
   word-break: break-word;
 }
-a.button {
+a.button, label.button {
   font-style: inherit;
   text-decoration: inherit;
   color: inherit;
   font-style: inherit;
   text-decoration: inherit;
   color: inherit;
@@ -86,7 +86,7 @@ h1 {
 }
 h2 { font-size: 1.125em; }
 
 }
 h2 { font-size: 1.125em; }
 
-select, input, button, textarea, a.button {
+select, input, button, textarea, a.button, label.button {
   display: inline-block;
   color: #000; background-color: #FFF;
   border: .5pt solid;
   display: inline-block;
   color: #000; background-color: #FFF;
   border: .5pt solid;
@@ -103,7 +103,7 @@ input[type=radio], input[type=checkbox] {
 }
 input[type=number] { text-align: right; padding-right: 0; }
 
 }
 input[type=number] { text-align: right; padding-right: 0; }
 
-button, input[type=button], a.button {
+button, input[type=button], a.button, label.button {
   box-shadow: .125em .125em .25em;
   cursor: pointer;
 }
   box-shadow: .125em .125em .25em;
   cursor: pointer;
 }
index c08d856da87c1e3a1b30ea4d3b8a212bfa6856d2..34879d25c22ba3498633c366374a9feeac6be943 100755 (executable)
@@ -158,18 +158,18 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
     href = gensub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\1", 1, substr(line, 1, len) );
     text = gensub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\3", 1, substr(line, 1, len) );
     if ( ! text ) text = href;
     href = gensub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\1", 1, substr(line, 1, len) );
     text = gensub(/^\[\[([^]|]+)(\|([^]]+))?\]\]/, "\\3", 1, substr(line, 1, len) );
     if ( ! text ) text = href;
-    return "<a href=\"" URL(href) "\">" HTML(text) "</a>" inline( substr( line, len + 1) );
+    return "<a href=\"" HTML(href) "\">" HTML(text) "</a>" inline( substr( line, len + 1) );
 
   #  quick links ("automatic links" in md doc)
   } else if ( match( line, /^<[a-zA-Z]+:\/\/([-\.[:alnum:]]+)(:[0-9]*)?(\/[^>]*)?>/ ) ) {
     len = RLENGTH;
 
   #  quick links ("automatic links" in md doc)
   } else if ( match( line, /^<[a-zA-Z]+:\/\/([-\.[:alnum:]]+)(:[0-9]*)?(\/[^>]*)?>/ ) ) {
     len = RLENGTH;
-    href = URL( substr( line, 2, len - 2) );
+    href = HTML( substr( line, 2, len - 2) );
     return "<a href=\"" href "\">" href "</a>" inline( substr( line, len + 1) );
 
   # quick link email
   } else if ( match( line, /^<[a-zA-Z0-9.!#$%&'\''*+\/=?^_`{|}~-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*>/ ) ) {
     len = RLENGTH;
     return "<a href=\"" href "\">" href "</a>" inline( substr( line, len + 1) );
 
   # quick link email
   } else if ( match( line, /^<[a-zA-Z0-9.!#$%&'\''*+\/=?^_`{|}~-]+@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*>/ ) ) {
     len = RLENGTH;
-    href = URL( substr( line, 2, len - 2) );
+    href = HTML( substr( line, 2, len - 2) );
     return "<a href=\"mailto:" href "\">" href "</a>" inline( substr( line, len + 1) );
 
   # Verbatim inline HTML
     return "<a href=\"mailto:" href "\">" href "</a>" inline( substr( line, len + 1) );
 
   # Verbatim inline HTML
@@ -192,7 +192,7 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
 
     gsub(/\\/, "", href); gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
 
 
     gsub(/\\/, "", href); gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
 
-    return "<a href=\"" URL(href) "\"" (title?" title=\"" HTML(title) "\"":"") ">" \
+    return "<a href=\"" HTML(href) "\"" (title?" title=\"" HTML(title) "\"":"") ">" \
            inline( text ) "</a>" inline( substr( line, len + 1) );
 
   # reference style links
            inline( text ) "</a>" inline( substr( line, len + 1) );
 
   # reference style links
@@ -202,9 +202,9 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
       id = gensub(/^\[([^\n]+)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
     if ( ! id ) id = text;
     if ( rl_href[id] && rl_title[id] ) {
       id = gensub(/^\[([^\n]+)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
     if ( ! id ) id = text;
     if ( rl_href[id] && rl_title[id] ) {
-      return "<a href=\"" URL(rl_href[id]) "\" title=\"" HTML(rl_title[id]) "\">" inline(text) "</a>" inline( substr( line, len + 1) );
+      return "<a href=\"" HTML(rl_href[id]) "\" title=\"" HTML(rl_title[id]) "\">" inline(text) "</a>" inline( substr( line, len + 1) );
     } else if ( rl_href[id] ) {
     } else if ( rl_href[id] ) {
-      return "<a href=\"" URL(rl_href[id]) "\">" inline(text) "</a>" inline( substr( line, len + 1) );
+      return "<a href=\"" HTML(rl_href[id]) "\">" inline(text) "</a>" inline( substr( line, len + 1) );
     } else {
       return "" HTML(substr(line, 1, len)) inline( substr(line, len + 1) );
     }
     } else {
       return "" HTML(substr(line, 1, len)) inline( substr(line, len + 1) );
     }
@@ -234,7 +234,7 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
     gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
     gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
 
     gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
     gsub(/\\/, "", title); gsub(/[\n\t]+/, " ", title);
 
-    return "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
+    return "<img src=\"" HTML(href, 1) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
            (title?" title=\"" HTML(title) "\"":"") (attrib?" class=\"" HTML(attrib) "\"":"") \
            ">" inline( substr( line, len + 1) );
 
            (title?" title=\"" HTML(title) "\"":"") (attrib?" class=\"" HTML(attrib) "\"":"") \
            ">" inline( substr( line, len + 1) );
 
@@ -245,10 +245,10 @@ function inline( line, LOCAL, len, text, code, href, guard ) {
       id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
     if ( ! id ) id = text;
     if ( rl_href[id] && rl_title[id] ) {
       id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\].*/, "\\2", 1, substr(line, 1, len) );
     if ( ! id ) id = text;
     if ( rl_href[id] && rl_title[id] ) {
-      return "<img src=\"" URL(rl_href[id], 1) "\" alt=\"" HTML(text) "\" title=\"" HTML(rl_title[id]) "\">" \
+      return "<img src=\"" HTML(rl_href[id], 1) "\" alt=\"" HTML(text) "\" title=\"" HTML(rl_title[id]) "\">" \
              inline( substr( line, len + 1) );
     } else if ( rl_href[id] ) {
              inline( substr( line, len + 1) );
     } else if ( rl_href[id] ) {
-      return "<img src=\"" URL(rl_href[id], 1) "\" alt=\"" HTML(text) "\">" \
+      return "<img src=\"" HTML(rl_href[id], 1) "\" alt=\"" HTML(text) "\">" \
              inline( substr( line, len + 1) );
     } else {
       return "" HTML(substr(line, 1, len)) inline( substr(line, len + 1) );
              inline( substr( line, len + 1) );
     } else {
       return "" HTML(substr(line, 1, len)) inline( substr(line, len + 1) );
@@ -663,8 +663,8 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
 
     gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
 
 
     gsub(/^[\t ]+$/, "", text); gsub(/\\/, "", href);
 
-    return "<figure data-src=\"" URL(href, 1) "\"" (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
-           "<img src=\"" URL(href, 1) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
+    return "<figure data-src=\"" HTML(href, 1) "\"" (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
+           "<img src=\"" HTML(href, 1) "\" alt=\"" HTML(text?text:title?title:href) "\"" \
            (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
            (title?"<figcaption>" inline(title) "</figcaption>":"") \
            "</figure>\n\n" \
            (attrib?" class=\"" HTML(attrib) "\"":"") ">" \
            (title?"<figcaption>" inline(title) "</figcaption>":"") \
            "</figure>\n\n" \
@@ -677,14 +677,14 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code,
       id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\2", 1, block);
     if ( ! id ) id = text;
     if ( rl_href[id] && rl_title[id] ) {
       id = gensub(/^!\[([^\n]*)\] ?\[([^\n]*)\](\n.*)?$/, "\\2", 1, block);
     if ( ! id ) id = text;
     if ( rl_href[id] && rl_title[id] ) {
-      return "<figure data-src=\"" URL(rl_href[id], 1) "\">" \
-               "<img src=\"" URL(rl_href[id], 1) "\" alt=\"" HTML(text) "\">" \
+      return "<figure data-src=\"" HTML(rl_href[id], 1) "\">" \
+               "<img src=\"" HTML(rl_href[id], 1) "\" alt=\"" HTML(text) "\">" \
                "<figcaption>" inline(rl_title[id]) "</figcaption>" \
              "</figure>\n\n" \
              _block( substr( block, len + 1) );
     } else if ( rl_href[id] ) {
                "<figcaption>" inline(rl_title[id]) "</figcaption>" \
              "</figure>\n\n" \
              _block( substr( block, len + 1) );
     } else if ( rl_href[id] ) {
-      return "<figure data-src=\"" URL(rl_href[id], 1) "\">" \
-               "<img src=\"" URL(rl_href[id], 1) "\" alt=\"" HTML(text) "\">" \
+      return "<figure data-src=\"" HTML(rl_href[id], 1) "\">" \
+               "<img src=\"" HTML(rl_href[id], 1) "\" alt=\"" HTML(text) "\">" \
              "</figure>\n\n" \
              _block( substr( block, len + 1) );
     } else {
              "</figure>\n\n" \
              _block( substr( block, len + 1) );
     } else {
index 17ea0d051eaf27233f8b5cd96f7396974c7a87f1..5c61df0a041e75df0e1ee0e81aa0c09078cdabc1 100755 (executable)
@@ -94,6 +94,21 @@ UNSTRING(){
   printf '%s\n' "$out"
 }
 
   printf '%s\n' "$out"
 }
 
+RXLITERAL(){
+  # sed -E 's;[].*+?^${}()|\[];\\&;g'
+  local in out=''
+  [ $# -gt 0 ] && in="$*" || in="$(cat)"
+  while [ "$in" ]; do case $in in
+    [.+^\$\{\}\(\)\[\]\*\?\|\\]*)
+      out="${out}\\${in%"${in#?}"}"; in="${in#?}";
+      ;;
+    *)out="${out}${in%%[.+^\$\{\}\(\)\[\]\*\?\|\\]*}"
+      in="${in#"${in%%[.+^\$\{\}\(\)\[\]\*\?\|\\]*}"}"
+      ;;
+  esac; done
+  printf '%s\n' "$out"
+}
+
 DBM() {
   local file="$1" cmd="$2"
   local k v key value
 DBM() {
   local file="$1" cmd="$2"
   local k v key value
index c924789c2e25a6fcb71b7b60eb9980373e9038ec..32299ff1e3f97f26f7cb2c7d3860d56c1a3e83d2 100755 (executable)
--- a/users.sh
+++ b/users.sh
@@ -621,7 +621,7 @@ w_user_invite(){
 
   if [ "$(GET user_confirm)" ]; then
     w_user_confirm
 
   if [ "$(GET user_confirm)" ]; then
     w_user_confirm
-  elif [ "$USER_ID" -a "$SENDMAIL" ]; then
+  elif [ "$USER_ID" -a "$USER_REQUIREEMAIL" = true ]; then
     w_user_invite_email
   elif [ "$USER_ID" ]; then
     uid="$(timeid)"
     w_user_invite_email
   elif [ "$USER_ID" ]; then
     uid="$(timeid)"