From 1a21bfdc762d2dfb0de56dba75fa46d8a31861af Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 29 Mar 2013 20:28:29 -0400 Subject: v4: cgi, auto-generated sample search form * for various sisu output directory structures * fixes --- data/doc/sisu/CHANGELOG_v4 | 4 ++++ lib/sisu/v4/cgi.rb | 8 -------- lib/sisu/v4/cgi_pgsql.rb | 48 +++++++++++++++++++++++++++++++++---------- lib/sisu/v4/cgi_sql_common.rb | 24 ++++++++++------------ lib/sisu/v4/cgi_sqlite.rb | 2 +- lib/sisu/v4/sysenv.rb | 15 +++++++------- 6 files changed, 61 insertions(+), 40 deletions(-) diff --git a/data/doc/sisu/CHANGELOG_v4 b/data/doc/sisu/CHANGELOG_v4 index 78b11e9b..0910d98b 100644 --- a/data/doc/sisu/CHANGELOG_v4 +++ b/data/doc/sisu/CHANGELOG_v4 @@ -32,6 +32,10 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_4.0.18.orig.tar.xz * v4: dbi, import composite files (.ssm) correctly +* v4: cgi, auto-generated sample search form + * for various sisu output directory structures + * fixes + %% 4.0.17.orig.tar.xz (2013-03-25:12/1) http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=shortlog;h=refs/tags/sisu_4.0.17 http://sources.sisudoc.org/gitweb/?p=code/sisu.git;a=shortlog;h=refs/tags/debian/sisu_4.0.17-1 diff --git a/lib/sisu/v4/cgi.rb b/lib/sisu/v4/cgi.rb index 518770a5..600d7146 100644 --- a/lib/sisu/v4/cgi.rb +++ b/lib/sisu/v4/cgi.rb @@ -69,17 +69,9 @@ module SiSU_CGI @opt=opt @webserv=@opt.files[0].to_s.strip end - def search_info - a=%{ - For help on sisu search, type: - sisu --help search - } - SiSU_Screen::Ansi.new(@opt.cmd,a).print_grey - end def read SiSU_CGI_SQLite::SearchSQLite.new(@opt,@webserv).sqlite SiSU_CGI_PgSQL::SearchPgSQL.new(@opt,@webserv).pgsql - search_info unless @opt.cmd =~/q/ end end end diff --git a/lib/sisu/v4/cgi_pgsql.rb b/lib/sisu/v4/cgi_pgsql.rb index 6102d585..36f9782b 100644 --- a/lib/sisu/v4/cgi_pgsql.rb +++ b/lib/sisu/v4/cgi_pgsql.rb @@ -68,10 +68,35 @@ module SiSU_CGI_PgSQL @opt,@webserv=opt,webserv @env=SiSU_Env::InfoEnv.new('',opt) @sys=SiSU_Env::SystemCall.new - @image_src="#{@env.url.webserv_cgi}/_sisu/image_sys" - @common=SiSU_CGI_SQL::CGI_Common.new(@webserv,@opt,@image_src,@env) @db=SiSU_Env::InfoDb.new + get_init=SiSU_Env::GetInit.new + @rc=get_init.sisu_yaml.rc + @name_of={} + if defined? @rc['webserv'] \ + and defined? @rc['webserv']['url_root'] \ + and defined? @rc['webserv']['url_root'] =~/\S+/ + @name_of[:host_url_docs]=@rc['webserv']['url_root'] + end + if defined? @rc['search'] \ + and defined? @rc['search']['sisu'] \ + and defined? @rc['search']['sisu']['action'] \ + and @rc['search']['sisu']['action'] =~/https?:\/\/\S+?\.cgi/ \ + and defined? @rc['search']['sisu']['db'] \ + and @rc['search']['sisu']['db'] =~/\S+/ + @name_of[:db]=@rc['search']['sisu']['db'] + #@name_of[:cgi_script]=/https?:\/\/\S+?([^\/]+?)\.cgi$/.match(@rc['search']['sisu']['action'])[1] + @name_of[:host_url_cgi],@name_of[:cgi_script]=/(https?:\/\/\S+?)\/([^\/]+?)\.cgi$/.match(@rc['search']['sisu']['action'])[1,2] + else + @name_of[:host_url_docs]=@env.url.webserv_files_from_db + @name_of[:db]='sisu' #breaks if not present + @name_of[:host_url_cgi]=@env.url.webserv_base_cgi + @name_of[:cgi_script]='sisu_pgsql' + false + end @cgi_file_name="#{Db[:name_prefix_db]}by_#{opt.dir_structure_by.to_s}_pgsql.cgi" + @cgi_link_name="#{@name_of[:db]}.cgi" #sisu_pgsql.cgi, + @image_src="#{@name_of[:host_url_docs]}/_sisu/image_sys" + @common=SiSU_CGI_SQL::CGI_Common.new(@webserv,@opt,@image_src,@env) end def pgsql serve=[] @@ -99,7 +124,7 @@ module SiSU_CGI_PgSQL if FileTest.writable?('.') output=File.open(@cgi_file_name,'w') output << header0 << header1 << header_desc << header2 << f1 << buttons1 << buttons1_pgsql << buttons2 << search_request << search_statement << search_statement_common << search_query1 << @common.pages << search_query2 << @common.tail << @common.main1 << f2 << dbi_connect << @common.main2 << @common.dir_structure << @common.main3 - a=%{ generated sisu_pgsql.cgi, + a=%{ generated #{@cgi_file_name}, BASED ON ALREADY EXISTING directories that could potentially be used to populate postgresql db, (-D) } SiSU_Screen::Ansi.new(@opt.cmd,a).print_grey @@ -108,11 +133,11 @@ module SiSU_CGI_PgSQL else "if necessary make the directory /usr/lib/cgi-bin : sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/. sudo chmod -v 755 /usr/lib/cgi-bin/#{@cgi_file_name} - sudo ln -s /usr/lib/cgi-bin/#{@cgi_file_name} /usr/lib/cgi-bin/sisu_pgsql.cgi - (copy #{@cgi_file_name} to your cgi directory) set file permissions to 755, and make symbolic link to sisu_pgsql.cgi" + sudo ln -s /usr/lib/cgi-bin/#{@cgi_file_name} /usr/lib/cgi-bin/#{@cgi_link_name} + (copy #{@cgi_file_name} to your cgi directory) set file permissions to 755, and make symbolic link to #{@cgi_link_name}" end a=%{#{c} - #{@env.webserv_base_cgi}/cgi-bin/sisu_pgsql.cgi + #{@env.webserv_base_cgi}/cgi-bin/#{@cgi_link_name} } SiSU_Screen::Ansi.new(@opt.cmd,a).warn a="postgresql db used for present directory: #{@db.psql.db}" @@ -132,13 +157,14 @@ module SiSU_CGI_PgSQL require 'cgi' require 'fcgi' require 'dbi' - @version='sisu_pgsql' - @image_src="#{@env.url.webserv_cgi}/_sisu/image_sys" - @hosturl_db="#{@env.url.webserv_base_cgi}" - @hosturl_files="#{@env.url.webserv_files_from_db}" + @stub_default="#{@name_of[:db]}" + @image_src="#{@name_of[:host_url_docs]}/_sisu/image_sys" + @hosturl_db="#{@name_of[:host_url_cgi]}" + @hosturl_files="#{@name_of[:host_url_docs]}" + @output_dir_structure_by="#{@name_of[:output_dir_structure]}" @port="#{@db.psql.port}" @db_name_prefix="#{Db[:name_prefix]}" - user='#{@env.user}' # check user name for access to pg database: '#{@env.user}' + user='www-data' # check user name for access to pg database: e.g. www-data or '#{@env.user}' WOK_SQL end def search_statement diff --git a/lib/sisu/v4/cgi_sql_common.rb b/lib/sisu/v4/cgi_sql_common.rb index c3c07bdb..058d04ec 100644 --- a/lib/sisu/v4/cgi_sql_common.rb +++ b/lib/sisu/v4/cgi_sql_common.rb @@ -130,7 +130,7 @@ module SiSU_CGI_SQL <<-'WOK_SQL' #Common TOP @@offset=0 - @base="#{@hosturl_db}/cgi-bin/#{@version}.cgi" + @base="#{@hosturl_db}/#{@stub_default}.cgi" #fix sqlite @@canned_search_url=@base @color_heading='#DDFFAA' @color_match='#ffff48' @@ -167,8 +167,7 @@ module SiSU_CGI_SQL
SiSU --> - - +
WOK_SQL @@ -655,8 +654,8 @@ module SiSU_CGI_SQL @stub=/#{@db_name_prefix}(\S+)/.match(cgi['db'])[1] cgi['db'] else - @stub='sisu' - "#{@db_name_prefix}#{@stub}" + @stub=@stub_default + @db_name_prefix + @stub end checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' result_type=(cgi['view']=~/text/) \ @@ -834,7 +833,6 @@ module SiSU_CGI_SQL else end @hostpath="#{@hosturl_files}/#{@stub}" - @ln='en' WOK_SQL end def dir_structure @@ -922,7 +920,7 @@ module SiSU_CGI_SQL can_txt_srch=(cgi['view']=~/index/) \ ? %{search } : %{search } - title=%{toc html #{ti} [#{c['language_document_char']}] by #{c['creator_author']} #{can_txt_srch}toc html manifest
} if file_suffix=~/s/ #hmm watch file_suffix + title=%{toc html #{ti} [#{c['language_document_char']}] by #{c['creator_author']} manifest #{can_txt_srch}
} if file_suffix=~/s/ #hmm watch file_suffix title=@text_search_flag \ ? '

'+title : '
'+title @@ -959,7 +957,7 @@ module SiSU_CGI_SQL matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) : c['body'] - %{

ocn #{c['ocn']}:

#{matched_para}} + %{

ocn #{c['ocn']}:

#{matched_para}} elsif c['suffix'] =~/1/ #doc %{#{title}

ocn #{c['ocn']}:#{c['body']}} end @@ -967,9 +965,9 @@ module SiSU_CGI_SQL output=title+text else #elsif cgi['view']=~/index/ #% idx body if c['suffix'] !~/1/ #seg - index=%{#{c['ocn']}, } if @text_search_flag + index=%{#{c['ocn']}, } if @text_search_flag elsif c['suffix'] =~/1/ #doc #FIX - index=%{#{c['ocn']}, } + index=%{#{c['ocn']}, } end if c['seg'] =~/\S+/ if @text_search_flag @@ -1015,7 +1013,7 @@ module SiSU_CGI_SQL can_txt_srch=(cgi['view']=~/index/) \ ? %{search } : %{search } - title=%{


toc html #{ti} [#{e['language_document_char']}] by #{e['creator_author']} #{can_txt_srch}toc html manifest
} if file_suffix=~/s/ + title=%{

toc html #{ti} [#{e['language_document_char']}] by #{e['creator_author']} #{can_txt_srch}toc html manifest
} if file_suffix=~/s/ @counter_endn_doc+=1 oldtid=e['metadata_tid'].to_i else title = '' @@ -1027,10 +1025,10 @@ module SiSU_CGI_SQL && @search_regx.to_s=~/\S\S+/) \ ? (matched=e['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) : e['body'] - output=%{#{title}
note #{e['nr']} referred to from ocn #{e['ocn']}: #{matched_endnote}} + output=%{#{title}
note #{e['nr']} referred to from ocn #{e['ocn']}: #{matched_endnote}} else #elsif cgi['view']=~/index/ #doc #FIX #% idx endnotes @counter_endn_ocn+=1 - output=%{#{title}#{e['nr']}#{e['ocn']}], } + output=%{#{title}#{e['nr']}#{e['ocn']}], } end @counters_endn=if @counter_endn_doc > 0 if checked_stats =~/\S/ diff --git a/lib/sisu/v4/cgi_sqlite.rb b/lib/sisu/v4/cgi_sqlite.rb index 8d15b4ee..6f8bc4cc 100644 --- a/lib/sisu/v4/cgi_sqlite.rb +++ b/lib/sisu/v4/cgi_sqlite.rb @@ -133,7 +133,7 @@ module SiSU_CGI_SQLite require 'dbi' @version='sisu_sqlite' @image_src="#{@env.url.webserv_cgi}/_sisu/image_sys" - @hosturl_db="#{@env.url.webserv_base_cgi}" + @hosturl_db="#{@env.url.webserv_base_cgi}/cgi-bin" @hosturl_files="#{@env.url.webserv_files_from_db}" @db_name_prefix="#{Db[:name_prefix]}" WOK_SQL diff --git a/lib/sisu/v4/sysenv.rb b/lib/sisu/v4/sysenv.rb index 6ed94d5d..d77672a6 100644 --- a/lib/sisu/v4/sysenv.rb +++ b/lib/sisu/v4/sysenv.rb @@ -1668,8 +1668,6 @@ WOK and defined? @rc['search']['sisu']['action'] \ and @rc['search']['sisu']['action'] =~/https?:\/\// \ and defined? @rc['search']['sisu']['db'] \ - and @rc['search']['sisu']['db'] =~/\S+/ \ - and defined? @rc['search']['sisu']['db'] \ and @rc['search']['sisu']['db'] =~/\S+/ flag=if defined? @vz.widget_search \ and @vz.widget_search==true @@ -2394,7 +2392,7 @@ WOK end end def webserv_cgi #web url for local webserv (localhost, or hostname) - if defined? @rc['webserv_cgi']['host'] \ + http=if defined? @rc['webserv_cgi']['host'] \ and @rc['webserv_cgi']['host'].is_a?(String) http=((@rc['webserv_cgi']['host'] =~ /https?:\/\//) ? '' : 'http://') #check https? missing if port.webserv_port_cgi @@ -2408,9 +2406,10 @@ WOK else "#{http}#{webserv_host_base}/#{@stub_pwd}" end end + http=http.strip end def webserv_base_cgi #web url for local webserv (localhost, or hostname) - if defined? @rc['webserv_cgi']['host'] \ + http=if defined? @rc['webserv_cgi']['host'] \ and @rc['webserv_cgi']['host'].is_a?(String) http=((@rc['webserv_cgi']['host'] =~ /https?:\/\//) ? '' : 'http://') if port.webserv_port_cgi @@ -2424,6 +2423,7 @@ WOK else "#{http}#{webserv_host_base}" end end + http=http.strip end def webrick #must have a port #REMOVE if defined? @rc['webserv_cgi']['host'] \ @@ -2479,12 +2479,13 @@ WOK else webserv_base_cgi end end - def sample_search_form_title - if defined? @rc['search']['sisu']['title'] \ + def sample_search_form_title(organised_by=:language) + title=if defined? @rc['search']['sisu']['title'] \ and @rc['search']['sisu']['title'] =~/\S+/ @rc['search']['sisu']['title'] - else %{(SiSU (generated sample) search form} + else %{SiSU (generated sample) search form} end + title=title + " (content organised by #{organised_by})" end def output_tell #BROKEN Revisit 2011-02 output_type=if defined? @rc['show_output_on'] \ -- cgit v1.2.3