X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=index.cgi;h=68d0ef2c21d126b8d8e1d5c08a5d8a4368b53455;hb=6ce0d169f8dd165c215fbcce58f15e6be2e805de;hp=9ba696abe827ad71aeafd48f8bc178e96905d575;hpb=1a5612ef66703f28969500e8ff7df258747c7169;p=rigidfind diff --git a/index.cgi b/index.cgi index 9ba696a..68d0ef2 100755 --- a/index.cgi +++ b/index.cgi @@ -9,7 +9,7 @@ debug "$REQUEST_METHOD $REQUEST_URI $SERVER_PROTOCOL $_DATE" ingest() { - local J="$1" + local J="$1" ztmp="${TMP:-/tmp}/zipfile_$$.zip" # json_get "$J" title # json_get "$J" parts.comments @@ -39,24 +39,28 @@ ingest() { | sed 's;<[^>]*>;;g' ;; *.docx) - printf %s "$content" |base64 -d \ - | unzip -qc /dev/stdin word/document.xml \ + printf %s "$content" |base64 -d >"$ztmp" + unzip -qc "$ztmp" word/document.xml \ | head -c 128M | sed 's;<[^>]*>;;g' + rm -- "$ztmp" ;; *.xlsx) - printf %s "$content" |base64 -d \ - | unzip -qc /dev/stdin xl/sharedStrings.xml \ + printf %s "$content" |base64 -d >"$ztmp" + unzip -qc "$ztmp" xl/sharedStrings.xml \ | head -c 128M | sed 's;<[^>]*>; ;g' + rm -- "$ztmp" ;; *.odt) - printf %s "$content" |base64 -d \ - | unzip -qc /dev/stdin content.xml \ + printf %s "$content" |base64 -d >"$ztmp" + unzip -qc "$ztmp" content.xml \ | head -c 128M | sed 's;<[^>]*>;;g' + rm -- "$ztmp" ;; *.ods|*.odp) - printf %s "$content" |base64 -d \ - | unzip -qc /dev/stdin content.xml \ + printf %s "$content" |base64 -d >"$ztmp" + unzip -qc "$ztmp" content.xml \ | head -c 128M | sed 's;<[^>]*>; ;g' + rm -- "$ztmp" ;; *):;; esac @@ -105,6 +109,23 @@ search() { _INDEX="${PATH_INFO#/}" _INDEX="${_INDEX%%/*}" _records="${_DATA}/${_INDEX}/_0_DOCS" +if [ "${INDEX}" -a ! -d "${_DATA}/${_INDEX}" ]; then + printf '%s\r\n' "Status: 404 Not Found" "" + exit 0 +elif authlist="$(DBM "${_DATA}/auth.db" get "${_INDEX}" )"; then + auth="$(HEADER Authorization)" auth="${auth#Basic }" + for a in $authlist deny; do + [ "$auth" = "$a" ] && break + done + if [ "$a" = "deny" -o ! "$auth" ]; then + printf '%s\r\n' "Status: 401 Unauthorized" \ + "WWW-Authenticate: Basic realm=\"Rigid Find\"" "" \ + | debug + exit 0 + fi + unset a auth authlist +fi + if [ "$REQUEST_METHOD" = "PUT" ]; then _doc="${PATH_INFO#"/${_INDEX}/_doc"}" @@ -190,7 +211,7 @@ elif [ "$REQUEST_METHOD" = "DELETE" ]; then exit 0 elif [ "$REQUEST_METHOD" = "POST" ]; then - J="$(json_load "$(head -c "${CONTENT_LENGTH:-0}")")" + J="$(json_load "$(head -c "${CONTENT_LENGTH:-0}" |debug)")" J="$(json_get "$J" query.bool.must.bool.should)" words="$( @@ -198,10 +219,12 @@ elif [ "$REQUEST_METHOD" = "POST" ]; then json_get "$(UNSTRING "$j")" match_phrase_prefix.content done 2>/dev/null )" + debug "Search words: $words" results="@ $( search "${_DATA}/${_INDEX}" $words \ | while read -r score id source; do + debug "Hit: $id $score" S="$(DB2 "" set _index str:"${_INDEX}")" S="$(DB2 "$S" set _id str:"$(UNSTRING "${id#/}")")" S="$(DB2 "$S" set _score num:"$score")" @@ -233,73 +256,21 @@ elif [ "$REQUEST_METHOD" = "HEAD" ]; then && ctype="${accept}" || ctype="application/json" cat <<-EOF - HTTP/1.1 200 OK + Status: 200 OK X-elastic-product: Elasticsearch content-type: ${ctype} EOF exit 0 -elif [ "$REQUEST_METHOD" = "GET" ]; then - accept="$(HEADER Accept)" - [ ! "${accept#*"vnd.elasticsearch+json"*}" ] \ - && ctype="${accept}" || ctype="application/json" - +else + # elif [ "$REQUEST_METHOD" = "GET" ]; then cat <<-EOF - HTTP/1.1 200 OK + Status: 501 Not Implemented X-elastic-product: Elasticsearch - content-type: ${ctype} + content-type: text/plain + Use the Nextcloud Elastic Search Plugin to use this service. EOF - - if [ "$PATH_INFO" = "/${_INDEX}/" ]; then - cat <<-EOF - { $(json_dump str:"${_INDEX}"): { - "aliases":{}, - "mappings": { - "properties": { - "content": {"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, - "hash":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, - "metatags":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, - "owner":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, - "parts":{"properties":{"comments":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}, - "provider":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, - "share_names":{"properties":{"paul":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}, - "source":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}, - "title":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}} - } - }, - "settings": { - "index": { - "routing":{"allocation":{"include":{"_tier_preference":"data_content"}}}, - "number_of_shards":"1", - "provided_name": $(json_dump str:"${_INDEX}"), - "creation_date": "$(stat -c %W "${_DATA}/${_INDEX}")", - "number_of_replicas":"1", - "uuid":"0000000000000000000000", - "version":{"created":"8500010"} - } - } - } - } - EOF - else - cat <<-EOF - { "name" : "head", - "cluster_name" : "elasticsearch", - "version" : { - "number" : "8.12.1", - "lucene_version" : "9.9.2", - "minimum_wire_compatibility_version" : "7.17.0", - "minimum_index_compatibility_version" : "7.0.0" - }, - "tagline" : "You Know, for Search" - } - EOF - fi - exit 0 - -else - printf '%s\r\n' "Status: 500 Internal Server Error" "" exit 0 fi