aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2013-05-29 19:45:23 -0400
committerRalph Amissah <ralph@amissah.com>2013-05-29 19:45:23 -0400
commitd8369e7a159aaa2a1b12ed7ba6ede361e62cea9a (patch)
tree3d2139ea94b0cdb35c8b4523c911aab18b2d1de2 /lib
parentv4 v5: document version check, disable (diff)
v4 v5: cgi helper script, sample search form generator, adjust/improve
* adds settings * db type --db-pq or db-sqlite * webserver for cgi script & db --webserv-search='' * webserver for sisu ouptut files --webserv-output='' * cgi search form link name --cgi-search-form-name='' * db user (pg) --db-user=''
Diffstat (limited to 'lib')
-rw-r--r--lib/sisu/v4/cgi.rb16
-rw-r--r--lib/sisu/v4/cgi_pgsql.rb105
-rw-r--r--lib/sisu/v4/cgi_sql_common.rb1
-rw-r--r--lib/sisu/v4/cgi_sqlite.rb77
-rw-r--r--lib/sisu/v4/dbi.rb6
-rw-r--r--lib/sisu/v4/sysenv.rb99
-rw-r--r--lib/sisu/v5/cgi.rb16
-rw-r--r--lib/sisu/v5/cgi_pgsql.rb105
-rw-r--r--lib/sisu/v5/cgi_sql_common.rb1
-rw-r--r--lib/sisu/v5/cgi_sqlite.rb77
-rw-r--r--lib/sisu/v5/dbi.rb6
-rw-r--r--lib/sisu/v5/sysenv.rb99
12 files changed, 436 insertions, 172 deletions
diff --git a/lib/sisu/v4/cgi.rb b/lib/sisu/v4/cgi.rb
index 600d7146..acaa5396 100644
--- a/lib/sisu/v4/cgi.rb
+++ b/lib/sisu/v4/cgi.rb
@@ -70,8 +70,20 @@ module SiSU_CGI
@webserv=@opt.files[0].to_s.strip
end
def read
- SiSU_CGI_SQLite::SearchSQLite.new(@opt,@webserv).sqlite
- SiSU_CGI_PgSQL::SearchPgSQL.new(@opt,@webserv).pgsql
+ if @opt.mod.inspect =~/--db[=-]["']?(?:pg|pg?sql|postgres(?:ql)?)["']+/
+ SiSU_CGI_PgSQL::SearchPgSQL.new(@opt,@webserv).pgsql
+ elsif @opt.mod.inspect =~/--db[=-](?:sqlite)/
+ SiSU_CGI_SQLite::SearchSQLite.new(@opt,@webserv).sqlite
+ else
+ puts <<-WOK
+ please select database type for which sample search form should be built (pgsql or sqlite)
+ sisu --sample-search-form --db=sqlite
+ sisu --sample-search-form --db=pg
+ other options include
+ --webserv-cgi='[cgi-server-name]'
+ --webserv-output='[sisu-output-server-with-base-path]'
+ WOK
+ end
end
end
end
diff --git a/lib/sisu/v4/cgi_pgsql.rb b/lib/sisu/v4/cgi_pgsql.rb
index 70a60d81..61c20965 100644
--- a/lib/sisu/v4/cgi_pgsql.rb
+++ b/lib/sisu/v4/cgi_pgsql.rb
@@ -56,7 +56,7 @@
<ralph@amissah.com>
<ralph.amissah@gmail.com>
- ** Description: generates naive cgi search form for search of sisu database (pgsql sqlite)
+ ** Description: generates naive cgi search form for search of sisu database (pgsql)
=end
module SiSU_CGI_PgSQL #% database building documents
@@ -66,6 +66,7 @@ module SiSU_CGI_PgSQL
class SearchPgSQL < CGI_Common
def initialize(opt,webserv)
@opt,@webserv=opt,webserv
+ @cX=SiSU_Screen::Ansi.new(opt.cmd).cX
@env=SiSU_Env::InfoEnv.new('',opt)
@sys=SiSU_Env::SystemCall.new
@db=SiSU_Env::InfoDb.new
@@ -90,18 +91,19 @@ module SiSU_CGI_PgSQL
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]
+ @name_of[:host_url_cgi]=/(https?:\/\/\S+?)\/(?:[^\/]+?)\.cgi$/.match(@rc['search']['sisu']['action'])[1]
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'
+ @name_of[:host_url_docs]=@env.url.webserv_files_from_db(@opt)
+ @name_of[:db]=@env.path.stub_pwd #'sisu' #breaks if not present
+ @name_of[:host_url_cgi]=@env.url.webserv_base_cgi(@opt)
false
end
+ @name_of[:cgi_script]=@env.url.cgi_sample_search_form_name(@opt)
@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"
+ @cgi_link_name=@name_of[:cgi_script] #sisu_pgsql.cgi,
+ @image_src="#{@env.url.webserv_base_cgi(@opt)}/_sisu/image_sys"
@common=SiSU_CGI_SQL::CGI_Common.new(@webserv,@opt,@image_src,@env)
+ @user=@db.psql.user(@opt)
end
def pgsql
serve=[]
@@ -125,25 +127,69 @@ 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 #{@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
- c=case @webserv
+ puts <<-WOK
+ generated sample search form: #{@cX.green}#{@cgi_file_name}#{@cX.off}
+ default database name: #{@cX.green}#{Db[:name_prefix]}#{@name_of[:db]}#{@cX.off} (#{@name_of[:db]})
+ db user: #{@cX.green}#{@db.psql.user(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --db-user='#{@db.psql.user(@opt)}'#{@cX.off}
+ cgi & db host on: #{@cX.blue}#{@env.url.webserv_base_cgi(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --webserv-search='#{@env.url.webserv_base_cgi(@opt)}'#{@cX.off}
+ sisu output on: #{@cX.blue}#{@env.url.webserv_files_from_db(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --webserv-output='#{@env.url.webserv_files_from_db(@opt)}'#{@cX.off}
+ cgi search form link name: #{@cX.green}#{@env.url.cgi_sample_search_form_name(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --cgi-search-form-name='#{@env.url.cgi_sample_search_form_name(@opt)}'#{@cX.off}
+ #{@cX.fuschia}(settings priority: command line; sisurc.yml; else defaults)#{@cX.off}
+
+ #{@cX.fuschia}BASED ON ALREADY EXISTING databases#{@cX.off} (default database name: #{@db.psql.db})
+ NOTE it is first necessary to createdb,
+ use sisu to create the tables & populate the postgresql db
+
+ the database to be used for this directory (#{@db.psql.db})
+ will have to be created manually if it does not exist:
+ using postgresql tools directly (the following may work):
+ (i) if you are not yet a postgresql user,
+ #{@cX.brown}sudo su postgres
+ createuser -d -a #{@env.user}
+ exit#{@cX.off}
+ (ii) create the database:
+ #{@cX.brown}createdb #{@db.psql.db}#{@cX.off}
+ [for a list of existing databases try 'psql --list']"
+
+ now you can use sisu to create the database tables and populate the database with documents
+
+ sisu --pg --dropall # removes existing postgresql db & tables
+ sisu --pg --createall -v # creates postgresql db & tables
+ sisu --pg --update -v *.sst *.ssm # populate the db
+ sisu --sample-search-form --pg # creates the postgresql search form
+ # this should be done after creating the db
+ # to be searched
+ sisu --webrick & # starts ruby webrick web server
+
+ # if necessary make the directory '/usr/lib/cgi-bin'
+ # here we copy the postgresql search form to cgi-bin
+ # (copy #{@cgi_file_name} to your cgi directory)
+ # set file permissions to 755, &
+ # make symbolic link to #{@cgi_link_name}
+ WOK
+ a=case @webserv
when /pwd/; ''
- 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/#{@cgi_link_name}
- (copy #{@cgi_file_name} to your cgi directory) set file permissions to 755, and make symbolic link to #{@cgi_link_name}"
+ else <<-WOK
+
+ sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/.; \\
+ cd /usr/lib/cgi-bin && \\
+ sudo chmod -v 755 #{@cgi_file_name}; \\
+ sudo rm -vi #{@cgi_link_name}; \\
+ sudo ln -s #{@cgi_file_name} #{@cgi_link_name}; \\
+ cd -
+ WOK
end
- a=%{#{c}
- #{@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}"
- b="\n\t(to create and populate postgresql database see 'man sisu' and in particular the -D flag)\n\t[the database to be used for this directory (#{@db.psql.db}) will have to be created manually if it does not exist,\n\tsee 'sisu --help sql'\n\tif you have permission to create databases:\n\t'sisu -d --createdb'\n\tor using postgresql tools directly:\n\t'createdb #{@db.psql.db}'\n\tfor a list of existing databases try 'psql --list']"
- SiSU_Screen::Ansi.new(@opt.cmd,a,b).txt_cyan
+ a=<<-WOK
+ #{@env.webserv_base_cgi(@opt)}/cgi-bin/#{@cgi_link_name}
+ WOK
+ SiSU_Screen::Ansi.new(@opt.cmd,a).print_blue
+ a="\n\t(to create and populate postgresql database see 'man sisu' and in particular the --pg option)\n\t[the database to be used for this directory (#{@db.psql.db}) will have to be created manually if it does not exist,\n\tusing postgresql tools directly: 'createdb #{@db.psql.db}' for a list of existing databases try 'psql --list']"
+ SiSU_Screen::Ansi.new(@opt.cmd,a).txt_grey
else puts 'failed in attempt to write #{@cgi_file_name} to present directory, is directory writable?'
end
end
@@ -159,13 +205,14 @@ module SiSU_CGI_PgSQL
require 'fcgi'
require 'dbi'
@stub_default='#{@name_of[:db]}'
- @image_src='#{@name_of[:host_url_docs]}/_sisu/image_sys'
- @hosturl_cgi='#{@name_of[:host_url_cgi]}'
- @hosturl_files='#{@name_of[:host_url_docs]}'
+ @image_src='#{@image_src}'
+ @hosturl_cgi='#{@env.url.webserv_base_cgi(@opt)}/cgi-bin'
+ @hosturl_files='#{@env.url.webserv_files_from_db(@opt)}'
@output_dir_structure_by='#{@name_of[:output_dir_structure]}'
@port='#{@db.psql.port}'
@db_name_prefix='#{Db[:name_prefix]}'
- user='www-data' # check user name for access to pg database: e.g. www-data or '#{@env.user}'
+ @user='#{@user}' # check user name for access to pg database: e.g. www-data or '#{@env.user}'
+ @base='#{@name_of[:host_url_cgi]}/cgi-bin/#{@name_of[:cgi_script]}.cgi' #fix sqlite
WOK_SQL
end
def search_statement
@@ -250,7 +297,7 @@ module SiSU_CGI_PgSQL
def dbi_connect
<<-'WOK_SQL'
dbi="dbi:Pg:database=#{@db};port=#{@port}"
- @conn=DBI.connect(dbi,user)
+ @conn=DBI.connect(dbi,@user)
WOK_SQL
end
end
diff --git a/lib/sisu/v4/cgi_sql_common.rb b/lib/sisu/v4/cgi_sql_common.rb
index 6c0550e6..33cb2dc6 100644
--- a/lib/sisu/v4/cgi_sql_common.rb
+++ b/lib/sisu/v4/cgi_sql_common.rb
@@ -130,7 +130,6 @@ module SiSU_CGI_SQL
<<-'WOK_SQL'
#Common TOP
@@offset=0
- @base="#{@hosturl_cgi}/#{@stub_default}.cgi" #fix sqlite
@@canned_search_url=@base
@color_heading='#DDFFAA'
@color_match='#ffff48'
diff --git a/lib/sisu/v4/cgi_sqlite.rb b/lib/sisu/v4/cgi_sqlite.rb
index 05c7e6a7..93129b5c 100644
--- a/lib/sisu/v4/cgi_sqlite.rb
+++ b/lib/sisu/v4/cgi_sqlite.rb
@@ -56,7 +56,7 @@
<ralph@amissah.com>
<ralph.amissah@gmail.com>
- ** Description: generates naive cgi search form for search of sisu database (pgsql sqlite)
+ ** Description: generates naive cgi search form for search of sisu database (sqlite)
=end
module SiSU_CGI_SQLite #% database building documents
@@ -66,17 +66,19 @@ module SiSU_CGI_SQLite
class SearchSQLite < CGI_Common
def initialize(opt,webserv)
@opt,@webserv=opt,webserv
+ @cX=SiSU_Screen::Ansi.new(opt.cmd).cX
@env=SiSU_Env::InfoEnv.new('',opt)
- @image_src="#{@env.url.webserv_cgi}/_sisu/image_sys"
+ @image_src="#{@env.url.webserv_cgi(@opt)}/_sisu/image_sys"
@common=SiSU_CGI_SQL::CGI_Common.new(@webserv,@opt,@image_src,@env)
@cgi_file_name="#{Db[:name_prefix_db]}by_#{opt.dir_structure_by.to_s}_sqlite.cgi"
+ @name_of_sqlite_db_file='sisu_sqlite.db'
end
def sqlite
serve=[]
Dir.foreach(@env.path.webserv) do |x|
if x !~/^\./ \
and FileTest.directory?("#{@env.path.webserv}/#{x}")
- if FileTest.file?("#{@env.path.webserv}/#{x}/sisu_sqlite.db")
+ if FileTest.file?("#{@env.path.webserv}/#{x}/#{@name_of_sqlite_db_file}")
serve << x unless x =~/^_\S+/
end
end
@@ -91,32 +93,62 @@ module SiSU_CGI_SQLite
f2 << %{ when /#{Db[:name_prefix]}#{x}/; '<option value="#{Db[:name_prefix]}#{x}">#{x}</option>'\n}
end
f2 << " end\n"
- f3 << %{ db_name='sisu_sqlite.db'\n}
+ f3 << %{ db_name='#{@name_of_sqlite_db_file}'\n}
f3 << %{ db_sqlite=case cgi['db']\n}
serve.each do |x|
- f3 << %{ when /#{Db[:name_prefix]}#{x}/; "#{@env.path.webserv}/#{x}/sisu_sqlite.db"\n}
+ f3 << %{ when /#{Db[:name_prefix]}#{x}/; "#{@env.path.webserv}/#{x}/\#{db_name}"\n}
end
- f3 << %{ else '#{@env.path.webserv}/#{serve[0]}/sisu_sqlite.db'\n end\n}
+ f3 << %{ else '#{@env.path.webserv}/#{serve[0]}/\#{db_name}'\n end\n}
if FileTest.writable?('.')
output=File.open(@cgi_file_name,'w')
output << header0 << header1 << header_desc << header2 << f1 << buttons1 << buttons2 << search_request << search_statement << search_statement_common << search_query1 << @common.pages << search_query2 << @common.tail << @common.main1 << f2 << f3 << dbi_connect << @common.main2 << @common.dir_structure << @common.main3
- a=%{ generated sisu_sqlite.cgi,
- BASED ON ALREADY CREATED sisu_sqlite.db OUTPUT, (-d)
- }
- SiSU_Screen::Ansi.new(@opt.cmd,a).print_grey
- c=case @webserv
+ puts <<-WOK
+ generated sample search form: #{@cX.green}#{@cgi_file_name}#{@cX.off}
+ default database name: #{@cX.green}#{Db[:name_prefix]}#{@env.path.stub_pwd}#{@cX.off} (#{@env.path.stub_pwd})
+ cgi & db host on: #{@cX.blue}#{@env.url.webserv_base_cgi(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --webserv-search='#{@env.url.webserv_base_cgi(@opt)}'#{@cX.off}
+ sisu output on: #{@cX.blue}#{@env.url.webserv_files_from_db(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --webserv-output='#{@env.url.webserv_files_from_db(@opt)}'#{@cX.off}
+ cgi search form link name: #{@cX.green}#{@env.url.cgi_sample_search_form_name(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --cgi-search-form-name='#{@env.url.cgi_sample_search_form_name(@opt)}'#{@cX.off}
+ #{@cX.fuschia}(settings priority: command line; sisurc.yml; else defaults)#{@cX.off}
+
+ #{@cX.fuschia}NOTE it is first necessary to create the database and tables and populate it#{@cX.off}
+
+ sisu --sqlite --dropall # removes existing postgresql db & tables
+ sisu --sqlite --createall -v # creates postgresql db & tables
+ sisu --sqlite --update -v *.sst *.ssm # populate the db
+ sisu --sample-search-form --sqlite # creates the postgresql search form
+ # this should be done after creating the db
+ # to be searched
+ sisu --webrick & # starts ruby webrick web server
+
+ # if necessary make the directory '/usr/lib/cgi-bin'
+ # here we copy the postgresql search form to cgi-bin
+ # (copy #{@cgi_file_name} to your cgi directory)
+ # set file permissions to 755, &
+ # make symbolic link to #{@cgi_link_name}
+ WOK
+ a=case @webserv
when /pwd/; ''
- 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_sqlite.cgi
- (copy #{@cgi_file_name} to your cgi directory) set file permissions to 755, and make symbolic link to sisu_sqlite.cgi"
+ else <<-WOK
+
+ sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/.; \\
+ cd /usr/lib/cgi-bin && \\
+ sudo chmod -v 755 #{@cgi_file_name}; \\
+ sudo rm -vi #{@env.url.cgi_sample_search_form_name(@opt)}; \\
+ sudo ln -sf #{@cgi_file_name} #{@env.url.cgi_sample_search_form_name(@opt)}; \\
+ cd -
+ WOK
end
- a=%{#{c}
- #{@env.webserv_base_cgi}/cgi-bin/sisu_sqlite.cgi
- }
b='(to create and populate sisu sqlite database see "man sisu" and in particular the -d flag)'
SiSU_Screen::Ansi.new(@opt.cmd,a,b).warn
+ a=<<-WOK
+
+ #{@env.webserv_base_cgi(@opt)}/cgi-bin/#{@cgi_link_name}
+
+ WOK
+ SiSU_Screen::Ansi.new(@opt.cmd,a).print_blue
else puts "failed in attempt to write #{@cgi_file_name} to present directory, is directory writable?"
end
end
@@ -132,10 +164,11 @@ module SiSU_CGI_SQLite
require 'fcgi'
require 'dbi'
@stub_default='sisu_sqlite'
- @image_src='#{@env.url.webserv_cgi}/_sisu/image_sys'
- @hosturl_cgi='#{@env.url.webserv_base_cgi}/cgi-bin'
- @hosturl_files='#{@env.url.webserv_files_from_db}'
+ @image_src='#{@image_src}'
+ @hosturl_cgi='#{@env.url.webserv_base_cgi(@opt)}/cgi-bin'
+ @hosturl_files='#{@env.url.webserv_files_from_db(@opt)}'
@db_name_prefix='#{Db[:name_prefix]}'
+ @base='#{@env.url.webserv_base_cgi(@opt)}/cgi-bin/#{@env.url.cgi_sample_search_form_name(@opt)}' #fix sqlite
WOK_SQL
end
def search_statement
diff --git a/lib/sisu/v4/dbi.rb b/lib/sisu/v4/dbi.rb
index c05d61fb..867585dd 100644
--- a/lib/sisu/v4/dbi.rb
+++ b/lib/sisu/v4/dbi.rb
@@ -107,7 +107,11 @@ module SiSU_DBI
@conn=@db.psql.conn_dbi
rescue
if @opt.mod.inspect=~/--(createall|create)/
- puts %{manually create the database: "#{@db.db}" if it does not yet exist}
+ cX=SiSU_Screen::Ansi.new(@opt.cmd).cX
+ puts <<-WOK
+manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet exist
+ #{cX.yellow}createdb #{@db.db}#{cX.off}
+ WOK
#sudo su -p postgres; createdb #{@db.db}; #[createuser?]
end
ensure
diff --git a/lib/sisu/v4/sysenv.rb b/lib/sisu/v4/sysenv.rb
index 7cbb0044..6bc97396 100644
--- a/lib/sisu/v4/sysenv.rb
+++ b/lib/sisu/v4/sysenv.rb
@@ -2383,7 +2383,7 @@ WOK
def po
"#{root}/po4a/po"
end
- def webserv_host_base
+ def webserv_host_base(opt=nil)
if defined? @rc['webserv']['host']
case @rc['webserv']['host']
when /https?:\/\//; @rc['webserv']['host']
@@ -2393,7 +2393,7 @@ WOK
else defaults[:webserv_host_cgi]
end
end
- def webserv_cgi #web url for local webserv (localhost, or hostname)
+ def webserv_cgi(opt=nil) #web url for local webserv (localhost, or hostname)
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
@@ -2403,25 +2403,28 @@ WOK
end
else
http=((webserv_host_base=~/https?:\/\//) ? '' : 'http://')
- if port.webserv_port_cgi
- "#{http}#{webserv_host_base}:#{port.webserv_port_cgi}/#{@stub_pwd}"
+ if port.webserv_port_cgi(opt)
+ "#{http}#{webserv_host_base}:#{port.webserv_port_cgi(opt)}/#{@stub_pwd}"
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)
- http=if defined? @rc['webserv_cgi']['host'] \
+ def webserv_base_cgi(opt=nil) #web url for local webserv (localhost, or hostname)
+ http=if opt.mod.inspect =~/--webserv-(?:cgi|db|search)[=-]["']?(\S+)["']+/
+ m=$1
+ (m=~/http\/\/:/) ? m : %{http://#{m}}
+ elsif 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
- "#{http}#{@rc['webserv_cgi']['host']}:#{port.webserv_port_cgi}"
+ if port.webserv_port_cgi(opt)
+ "#{http}#{@rc['webserv_cgi']['host']}:#{port.webserv_port_cgi(opt)}"
else "#{http}#{@rc['webserv_cgi']['host']}"
end
else
http=((webserv_host_base=~/https?:\/\//) ? '' : 'http://')
- if port.webserv_port_cgi
- "#{http}#{webserv_host_base}:#{port.webserv_port_cgi}"
+ if port.webserv_port_cgi(opt)
+ "#{http}#{webserv_host_base}:#{port.webserv_port_cgi(opt)}"
else "#{http}#{webserv_host_base}"
end
end
@@ -2469,16 +2472,39 @@ WOK
else "#{url.webrick_base}"
end
end
- def webserv_files_from_db #sort this out, messy
- if defined? @rc['webserv_cgi']['file_links']
- case @rc['webserv_cgi']['file_links']
- when /webserv_cgi/; url.webserv_base_cgi
+ def webserv_files_from_db(opt=nil) #sort this out, messy
+ if opt.mod.inspect =~/--webserv-output[=-]["']?(\S+)["']+/
+ m=$1
+ (m=~/(?:http|file\/)\/\/:/) ? m : %{http://#{m}}
+ else
+ show_output_on=if defined? @rc['webserv_cgi']['show_output_on']
+ @rc['webserv_cgi']['show_output_on']
+ elsif defined? @rc['webserv_cgi']['file_links']
+ @rc['webserv_cgi']['file_links']
+ else ''
+ end
+ m=case show_output_on
+ when /webserv_cgi/; url.webserv_base_cgi(opt)
when /webserv/; @rc['webserv']['url_root']
when /https?:\/\//; @rc['webserv_cgi']['file_links']
when /\S+/; "http://#{@rc['webserv_cgi']['file_links']}"
- else webserv_base_cgi
+ else webserv_base_cgi(opt)
end
- else webserv_base_cgi
+ end
+ end
+ def cgi_sample_search_form_name(opt=nil)
+ if opt.mod.inspect =~/--(?:cgi-)?search-form-name[=-]["']?(\S+?\.cgi)/
+ m=$1
+ elsif not (opt.mod.inspect =~/--db[=-]["']?sqlite/) \
+ and defined? @rc['search'] \
+ and defined? @rc['search']['sisu'] \
+ and defined? @rc['search']['sisu']['action'] \
+ and @rc['search']['sisu']['action'] =~/https?:\/\/\S+?\.cgi/
+ x=/(?:https?:\/\/\S+?)\/([^\/]+?\.cgi)$/.match(@rc['search']['sisu']['action'])[1]
+ else
+ (opt.mod.inspect =~/--db[=-]["']?sqlite/) \
+ ? 'sisu_sqlite.cgi' \
+ : 'sisu_pgsql.cgi'
end
end
def sample_search_form_title(organised_by=:language)
@@ -2569,24 +2595,29 @@ WOK
end
end
end
- def webserv_port_cgi
- if @md \
- and defined? @md.opt \
- and @md.opt.cmd.inspect=~/-F/ \
- and @md.opt.mod.inspect=~/port=(\d+)/
+ def webserv_port_cgi(opt=nil)
+ port=if opt \
+ and opt.cmd.inspect=~/-F/ \
+ and opt.mod.inspect=~/port=(\d+)/
$1
else
- if defined? @rc['webserv_cgi']['port']
+ port=if defined? @rc['webserv_cgi']['port']
if @rc['webserv_cgi']['port'].nil? \
- and (defined? @md.opt.mod \
- and not @md.opt.mod.nil? \
- and @md.opt.mod.inspect=~/webrick/)
+ and (defined? opt.mod \
+ and not opt.mod.nil? \
+ and opt.mod.inspect=~/webrick/)
defaults[:webserv_port_cgi]
elsif not @rc['webserv_cgi']['port'].nil?
@rc['webserv_cgi']['port']
else nil
end
- else nil
+ else
+ if (defined? opt.mod \
+ and not opt.mod.nil? \
+ and opt.mod.inspect=~/webrick/)
+ defaults[:webserv_port_cgi]
+ else nil
+ end
end
end
end
@@ -4036,11 +4067,17 @@ WOK
self
end
def psql
- def user
- ((defined? @rc['db']['postgresql']['user']) \
- && @rc['db']['postgresql']['user']=~/\S+/) \
- ? @rc['db']['postgresql']['user']
- : @env.user
+ def user(opt)
+ if opt.mod.inspect =~/--db-user[=-]["']?(\S+)["']+/
+ m=$1
+ elsif opt.mod =~/--webserv[=-]webrick/
+ @env.user
+ else
+ ((defined? @rc['db']['postgresql']['user']) \
+ && @rc['db']['postgresql']['user']=~/\S+/) \
+ ? @rc['db']['postgresql']['user']
+ : @env.user
+ end
end
def db #db_name
"#{Db[:name_prefix]}#{@pwd_stub}"
diff --git a/lib/sisu/v5/cgi.rb b/lib/sisu/v5/cgi.rb
index dd9cdf22..1c0e023a 100644
--- a/lib/sisu/v5/cgi.rb
+++ b/lib/sisu/v5/cgi.rb
@@ -70,8 +70,20 @@ module SiSU_CGI
@webserv=@opt.files[0].to_s.strip
end
def read
- SiSU_CGI_SQLite::SearchSQLite.new(@opt,@webserv).sqlite
- SiSU_CGI_PgSQL::SearchPgSQL.new(@opt,@webserv).pgsql
+ if @opt.mod.inspect =~/--db[=-]["']?(?:pg|pg?sql|postgres(?:ql)?)["']+/
+ SiSU_CGI_PgSQL::SearchPgSQL.new(@opt,@webserv).pgsql
+ elsif @opt.mod.inspect =~/--db[=-](?:sqlite)/
+ SiSU_CGI_SQLite::SearchSQLite.new(@opt,@webserv).sqlite
+ else
+ puts <<-WOK
+ please select database type for which sample search form should be built (pgsql or sqlite)
+ sisu --sample-search-form --db=sqlite
+ sisu --sample-search-form --db=pg
+ other options include
+ --webserv-cgi='[cgi-server-name]'
+ --webserv-output='[sisu-output-server-with-base-path]'
+ WOK
+ end
end
end
end
diff --git a/lib/sisu/v5/cgi_pgsql.rb b/lib/sisu/v5/cgi_pgsql.rb
index 1fa19e0d..45a4aae9 100644
--- a/lib/sisu/v5/cgi_pgsql.rb
+++ b/lib/sisu/v5/cgi_pgsql.rb
@@ -56,7 +56,7 @@
<ralph@amissah.com>
<ralph.amissah@gmail.com>
- ** Description: generates naive cgi search form for search of sisu database (pgsql sqlite)
+ ** Description: generates naive cgi search form for search of sisu database (pgsql)
=end
module SiSU_CGI_PgSQL #% database building documents
@@ -66,6 +66,7 @@ module SiSU_CGI_PgSQL
class SearchPgSQL < CGI_Common
def initialize(opt,webserv)
@opt,@webserv=opt,webserv
+ @cX=SiSU_Screen::Ansi.new(opt.cmd).cX
@env=SiSU_Env::InfoEnv.new('',opt)
@sys=SiSU_Env::SystemCall.new
@db=SiSU_Env::InfoDb.new
@@ -90,18 +91,19 @@ module SiSU_CGI_PgSQL
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]
+ @name_of[:host_url_cgi]=/(https?:\/\/\S+?)\/(?:[^\/]+?)\.cgi$/.match(@rc['search']['sisu']['action'])[1]
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'
+ @name_of[:host_url_docs]=@env.url.webserv_files_from_db(@opt)
+ @name_of[:db]=@env.path.stub_pwd #'sisu' #breaks if not present
+ @name_of[:host_url_cgi]=@env.url.webserv_base_cgi(@opt)
false
end
+ @name_of[:cgi_script]=@env.url.cgi_sample_search_form_name(@opt)
@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"
+ @cgi_link_name=@name_of[:cgi_script] #sisu_pgsql.cgi,
+ @image_src="#{@env.url.webserv_base_cgi(@opt)}/_sisu/image_sys"
@common=SiSU_CGI_SQL::CGI_Common.new(@webserv,@opt,@image_src,@env)
+ @user=@db.psql.user(@opt)
end
def pgsql
serve=[]
@@ -125,25 +127,69 @@ 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 #{@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
- c=case @webserv
+ puts <<-WOK
+ generated sample search form: #{@cX.green}#{@cgi_file_name}#{@cX.off}
+ default database name: #{@cX.green}#{Db[:name_prefix]}#{@name_of[:db]}#{@cX.off} (#{@name_of[:db]})
+ db user: #{@cX.green}#{@db.psql.user(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --db-user='#{@db.psql.user(@opt)}'#{@cX.off}
+ cgi & db host on: #{@cX.blue}#{@env.url.webserv_base_cgi(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --webserv-search='#{@env.url.webserv_base_cgi(@opt)}'#{@cX.off}
+ sisu output on: #{@cX.blue}#{@env.url.webserv_files_from_db(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --webserv-output='#{@env.url.webserv_files_from_db(@opt)}'#{@cX.off}
+ cgi search form link name: #{@cX.green}#{@env.url.cgi_sample_search_form_name(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --cgi-search-form-name='#{@env.url.cgi_sample_search_form_name(@opt)}'#{@cX.off}
+ #{@cX.fuschia}(settings priority: command line; sisurc.yml; else defaults)#{@cX.off}
+
+ #{@cX.fuschia}BASED ON ALREADY EXISTING databases#{@cX.off} (default database name: #{@db.psql.db})
+ NOTE it is first necessary to createdb,
+ use sisu to create the tables & populate the postgresql db
+
+ the database to be used for this directory (#{@db.psql.db})
+ will have to be created manually if it does not exist:
+ using postgresql tools directly (the following may work):
+ (i) if you are not yet a postgresql user,
+ #{@cX.brown}sudo su postgres
+ createuser -d -a #{@env.user}
+ exit#{@cX.off}
+ (ii) create the database:
+ #{@cX.brown}createdb #{@db.psql.db}#{@cX.off}
+ [for a list of existing databases try 'psql --list']"
+
+ now you can use sisu to create the database tables and populate the database with documents
+
+ sisu --pg --dropall # removes existing postgresql db & tables
+ sisu --pg --createall -v # creates postgresql db & tables
+ sisu --pg --update -v *.sst *.ssm # populate the db
+ sisu --sample-search-form --pg # creates the postgresql search form
+ # this should be done after creating the db
+ # to be searched
+ sisu --webrick & # starts ruby webrick web server
+
+ # if necessary make the directory '/usr/lib/cgi-bin'
+ # here we copy the postgresql search form to cgi-bin
+ # (copy #{@cgi_file_name} to your cgi directory)
+ # set file permissions to 755, &
+ # make symbolic link to #{@cgi_link_name}
+ WOK
+ a=case @webserv
when /pwd/; ''
- 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/#{@cgi_link_name}
- (copy #{@cgi_file_name} to your cgi directory) set file permissions to 755, and make symbolic link to #{@cgi_link_name}"
+ else <<-WOK
+
+ sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/.; \\
+ cd /usr/lib/cgi-bin && \\
+ sudo chmod -v 755 #{@cgi_file_name}; \\
+ sudo rm -vi #{@cgi_link_name}; \\
+ sudo ln -s #{@cgi_file_name} #{@cgi_link_name}; \\
+ cd -
+ WOK
end
- a=%{#{c}
- #{@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}"
- b="\n\t(to create and populate postgresql database see 'man sisu' and in particular the -D flag)\n\t[the database to be used for this directory (#{@db.psql.db}) will have to be created manually if it does not exist,\n\tsee 'sisu --help sql'\n\tif you have permission to create databases:\n\t'sisu -d --createdb'\n\tor using postgresql tools directly:\n\t'createdb #{@db.psql.db}'\n\tfor a list of existing databases try 'psql --list']"
- SiSU_Screen::Ansi.new(@opt.cmd,a,b).txt_cyan
+ a=<<-WOK
+ #{@env.webserv_base_cgi(@opt)}/cgi-bin/#{@cgi_link_name}
+ WOK
+ SiSU_Screen::Ansi.new(@opt.cmd,a).print_blue
+ a="\n\t(to create and populate postgresql database see 'man sisu' and in particular the --pg option)\n\t[the database to be used for this directory (#{@db.psql.db}) will have to be created manually if it does not exist,\n\tusing postgresql tools directly: 'createdb #{@db.psql.db}' for a list of existing databases try 'psql --list']"
+ SiSU_Screen::Ansi.new(@opt.cmd,a).txt_grey
else puts 'failed in attempt to write #{@cgi_file_name} to present directory, is directory writable?'
end
end
@@ -159,13 +205,14 @@ module SiSU_CGI_PgSQL
require 'fcgi'
require 'dbi'
@stub_default='#{@name_of[:db]}'
- @image_src='#{@name_of[:host_url_docs]}/_sisu/image_sys'
- @hosturl_cgi='#{@name_of[:host_url_cgi]}'
- @hosturl_files='#{@name_of[:host_url_docs]}'
+ @image_src='#{@image_src}'
+ @hosturl_cgi='#{@env.url.webserv_base_cgi(@opt)}/cgi-bin'
+ @hosturl_files='#{@env.url.webserv_files_from_db(@opt)}'
@output_dir_structure_by='#{@name_of[:output_dir_structure]}'
@port='#{@db.psql.port}'
@db_name_prefix='#{Db[:name_prefix]}'
- user='www-data' # check user name for access to pg database: e.g. www-data or '#{@env.user}'
+ @user='#{@user}' # check user name for access to pg database: e.g. www-data or '#{@env.user}'
+ @base='#{@name_of[:host_url_cgi]}/cgi-bin/#{@name_of[:cgi_script]}.cgi' #fix sqlite
WOK_SQL
end
def search_statement
@@ -250,7 +297,7 @@ module SiSU_CGI_PgSQL
def dbi_connect
<<-'WOK_SQL'
dbi="dbi:Pg:database=#{@db};port=#{@port}"
- @conn=DBI.connect(dbi,user)
+ @conn=DBI.connect(dbi,@user)
WOK_SQL
end
end
diff --git a/lib/sisu/v5/cgi_sql_common.rb b/lib/sisu/v5/cgi_sql_common.rb
index 5604d6cb..9e872139 100644
--- a/lib/sisu/v5/cgi_sql_common.rb
+++ b/lib/sisu/v5/cgi_sql_common.rb
@@ -130,7 +130,6 @@ module SiSU_CGI_SQL
<<-'WOK_SQL'
#Common TOP
@@offset=0
- @base="#{@hosturl_cgi}/#{@stub_default}.cgi" #fix sqlite
@@canned_search_url=@base
@color_heading='#DDFFAA'
@color_match='#ffff48'
diff --git a/lib/sisu/v5/cgi_sqlite.rb b/lib/sisu/v5/cgi_sqlite.rb
index cf891c5a..e53497e1 100644
--- a/lib/sisu/v5/cgi_sqlite.rb
+++ b/lib/sisu/v5/cgi_sqlite.rb
@@ -56,7 +56,7 @@
<ralph@amissah.com>
<ralph.amissah@gmail.com>
- ** Description: generates naive cgi search form for search of sisu database (pgsql sqlite)
+ ** Description: generates naive cgi search form for search of sisu database (sqlite)
=end
module SiSU_CGI_SQLite #% database building documents
@@ -66,17 +66,19 @@ module SiSU_CGI_SQLite
class SearchSQLite < CGI_Common
def initialize(opt,webserv)
@opt,@webserv=opt,webserv
+ @cX=SiSU_Screen::Ansi.new(opt.cmd).cX
@env=SiSU_Env::InfoEnv.new('',opt)
- @image_src="#{@env.url.webserv_cgi}/_sisu/image_sys"
+ @image_src="#{@env.url.webserv_cgi(@opt)}/_sisu/image_sys"
@common=SiSU_CGI_SQL::CGI_Common.new(@webserv,@opt,@image_src,@env)
@cgi_file_name="#{Db[:name_prefix_db]}by_#{opt.dir_structure_by.to_s}_sqlite.cgi"
+ @name_of_sqlite_db_file='sisu_sqlite.db'
end
def sqlite
serve=[]
Dir.foreach(@env.path.webserv) do |x|
if x !~/^\./ \
and FileTest.directory?("#{@env.path.webserv}/#{x}")
- if FileTest.file?("#{@env.path.webserv}/#{x}/sisu_sqlite.db")
+ if FileTest.file?("#{@env.path.webserv}/#{x}/#{@name_of_sqlite_db_file}")
serve << x unless x =~/^_\S+/
end
end
@@ -91,32 +93,62 @@ module SiSU_CGI_SQLite
f2 << %{ when /#{Db[:name_prefix]}#{x}/; '<option value="#{Db[:name_prefix]}#{x}">#{x}</option>'\n}
end
f2 << " end\n"
- f3 << %{ db_name='sisu_sqlite.db'\n}
+ f3 << %{ db_name='#{@name_of_sqlite_db_file}'\n}
f3 << %{ db_sqlite=case cgi['db']\n}
serve.each do |x|
- f3 << %{ when /#{Db[:name_prefix]}#{x}/; "#{@env.path.webserv}/#{x}/sisu_sqlite.db"\n}
+ f3 << %{ when /#{Db[:name_prefix]}#{x}/; "#{@env.path.webserv}/#{x}/\#{db_name}"\n}
end
- f3 << %{ else '#{@env.path.webserv}/#{serve[0]}/sisu_sqlite.db'\n end\n}
+ f3 << %{ else '#{@env.path.webserv}/#{serve[0]}/\#{db_name}'\n end\n}
if FileTest.writable?('.')
output=File.open(@cgi_file_name,'w')
output << header0 << header1 << header_desc << header2 << f1 << buttons1 << buttons2 << search_request << search_statement << search_statement_common << search_query1 << @common.pages << search_query2 << @common.tail << @common.main1 << f2 << f3 << dbi_connect << @common.main2 << @common.dir_structure << @common.main3
- a=%{ generated sisu_sqlite.cgi,
- BASED ON ALREADY CREATED sisu_sqlite.db OUTPUT, (-d)
- }
- SiSU_Screen::Ansi.new(@opt.cmd,a).print_grey
- c=case @webserv
+ puts <<-WOK
+ generated sample search form: #{@cX.green}#{@cgi_file_name}#{@cX.off}
+ default database name: #{@cX.green}#{Db[:name_prefix]}#{@env.path.stub_pwd}#{@cX.off} (#{@env.path.stub_pwd})
+ cgi & db host on: #{@cX.blue}#{@env.url.webserv_base_cgi(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --webserv-search='#{@env.url.webserv_base_cgi(@opt)}'#{@cX.off}
+ sisu output on: #{@cX.blue}#{@env.url.webserv_files_from_db(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --webserv-output='#{@env.url.webserv_files_from_db(@opt)}'#{@cX.off}
+ cgi search form link name: #{@cX.green}#{@env.url.cgi_sample_search_form_name(@opt)}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-sqlite --cgi-search-form-name='#{@env.url.cgi_sample_search_form_name(@opt)}'#{@cX.off}
+ #{@cX.fuschia}(settings priority: command line; sisurc.yml; else defaults)#{@cX.off}
+
+ #{@cX.fuschia}NOTE it is first necessary to create the database and tables and populate it#{@cX.off}
+
+ sisu --sqlite --dropall # removes existing postgresql db & tables
+ sisu --sqlite --createall -v # creates postgresql db & tables
+ sisu --sqlite --update -v *.sst *.ssm # populate the db
+ sisu --sample-search-form --sqlite # creates the postgresql search form
+ # this should be done after creating the db
+ # to be searched
+ sisu --webrick & # starts ruby webrick web server
+
+ # if necessary make the directory '/usr/lib/cgi-bin'
+ # here we copy the postgresql search form to cgi-bin
+ # (copy #{@cgi_file_name} to your cgi directory)
+ # set file permissions to 755, &
+ # make symbolic link to #{@cgi_link_name}
+ WOK
+ a=case @webserv
when /pwd/; ''
- 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_sqlite.cgi
- (copy #{@cgi_file_name} to your cgi directory) set file permissions to 755, and make symbolic link to sisu_sqlite.cgi"
+ else <<-WOK
+
+ sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/.; \\
+ cd /usr/lib/cgi-bin && \\
+ sudo chmod -v 755 #{@cgi_file_name}; \\
+ sudo rm -vi #{@env.url.cgi_sample_search_form_name(@opt)}; \\
+ sudo ln -sf #{@cgi_file_name} #{@env.url.cgi_sample_search_form_name(@opt)}; \\
+ cd -
+ WOK
end
- a=%{#{c}
- #{@env.webserv_base_cgi}/cgi-bin/sisu_sqlite.cgi
- }
b='(to create and populate sisu sqlite database see "man sisu" and in particular the -d flag)'
SiSU_Screen::Ansi.new(@opt.cmd,a,b).warn
+ a=<<-WOK
+
+ #{@env.webserv_base_cgi(@opt)}/cgi-bin/#{@cgi_link_name}
+
+ WOK
+ SiSU_Screen::Ansi.new(@opt.cmd,a).print_blue
else puts "failed in attempt to write #{@cgi_file_name} to present directory, is directory writable?"
end
end
@@ -132,10 +164,11 @@ module SiSU_CGI_SQLite
require 'fcgi'
require 'dbi'
@stub_default='sisu_sqlite'
- @image_src='#{@env.url.webserv_cgi}/_sisu/image_sys'
- @hosturl_cgi='#{@env.url.webserv_base_cgi}/cgi-bin'
- @hosturl_files='#{@env.url.webserv_files_from_db}'
+ @image_src='#{@image_src}'
+ @hosturl_cgi='#{@env.url.webserv_base_cgi(@opt)}/cgi-bin'
+ @hosturl_files='#{@env.url.webserv_files_from_db(@opt)}'
@db_name_prefix='#{Db[:name_prefix]}'
+ @base='#{@env.url.webserv_base_cgi(@opt)}/cgi-bin/#{@env.url.cgi_sample_search_form_name(@opt)}' #fix sqlite
WOK_SQL
end
def search_statement
diff --git a/lib/sisu/v5/dbi.rb b/lib/sisu/v5/dbi.rb
index 62c93976..eae39ae8 100644
--- a/lib/sisu/v5/dbi.rb
+++ b/lib/sisu/v5/dbi.rb
@@ -107,7 +107,11 @@ module SiSU_DBI
@conn=@db.psql.conn_dbi
rescue
if @opt.mod.inspect=~/--(createall|create)/
- puts %{manually create the database: "#{@db.db}" if it does not yet exist}
+ cX=SiSU_Screen::Ansi.new(@opt.cmd).cX
+ puts <<-WOK
+manually create the database: "#{cX.green}#{@db.db}#{cX.off}" if it does not yet exist
+ #{cX.yellow}createdb #{@db.db}#{cX.off}
+ WOK
#sudo su -p postgres; createdb #{@db.db}; #[createuser?]
end
ensure
diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb
index 3df0e612..edaec7f8 100644
--- a/lib/sisu/v5/sysenv.rb
+++ b/lib/sisu/v5/sysenv.rb
@@ -2383,7 +2383,7 @@ WOK
def po
"#{root}/po4a/po"
end
- def webserv_host_base
+ def webserv_host_base(opt=nil)
if defined? @rc['webserv']['host']
case @rc['webserv']['host']
when /https?:\/\//; @rc['webserv']['host']
@@ -2393,7 +2393,7 @@ WOK
else defaults[:webserv_host_cgi]
end
end
- def webserv_cgi #web url for local webserv (localhost, or hostname)
+ def webserv_cgi(opt=nil) #web url for local webserv (localhost, or hostname)
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
@@ -2403,25 +2403,28 @@ WOK
end
else
http=((webserv_host_base=~/https?:\/\//) ? '' : 'http://')
- if port.webserv_port_cgi
- "#{http}#{webserv_host_base}:#{port.webserv_port_cgi}/#{@stub_pwd}"
+ if port.webserv_port_cgi(opt)
+ "#{http}#{webserv_host_base}:#{port.webserv_port_cgi(opt)}/#{@stub_pwd}"
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)
- http=if defined? @rc['webserv_cgi']['host'] \
+ def webserv_base_cgi(opt=nil) #web url for local webserv (localhost, or hostname)
+ http=if opt.mod.inspect =~/--webserv-(?:cgi|db|search)[=-]["']?(\S+)["']+/
+ m=$1
+ (m=~/http\/\/:/) ? m : %{http://#{m}}
+ elsif 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
- "#{http}#{@rc['webserv_cgi']['host']}:#{port.webserv_port_cgi}"
+ if port.webserv_port_cgi(opt)
+ "#{http}#{@rc['webserv_cgi']['host']}:#{port.webserv_port_cgi(opt)}"
else "#{http}#{@rc['webserv_cgi']['host']}"
end
else
http=((webserv_host_base=~/https?:\/\//) ? '' : 'http://')
- if port.webserv_port_cgi
- "#{http}#{webserv_host_base}:#{port.webserv_port_cgi}"
+ if port.webserv_port_cgi(opt)
+ "#{http}#{webserv_host_base}:#{port.webserv_port_cgi(opt)}"
else "#{http}#{webserv_host_base}"
end
end
@@ -2469,16 +2472,39 @@ WOK
else "#{url.webrick_base}"
end
end
- def webserv_files_from_db #sort this out, messy
- if defined? @rc['webserv_cgi']['file_links']
- case @rc['webserv_cgi']['file_links']
- when /webserv_cgi/; url.webserv_base_cgi
+ def webserv_files_from_db(opt=nil) #sort this out, messy
+ if opt.mod.inspect =~/--webserv-output[=-]["']?(\S+)["']+/
+ m=$1
+ (m=~/(?:http|file\/)\/\/:/) ? m : %{http://#{m}}
+ else
+ show_output_on=if defined? @rc['webserv_cgi']['show_output_on']
+ @rc['webserv_cgi']['show_output_on']
+ elsif defined? @rc['webserv_cgi']['file_links']
+ @rc['webserv_cgi']['file_links']
+ else ''
+ end
+ m=case show_output_on
+ when /webserv_cgi/; url.webserv_base_cgi(opt)
when /webserv/; @rc['webserv']['url_root']
when /https?:\/\//; @rc['webserv_cgi']['file_links']
when /\S+/; "http://#{@rc['webserv_cgi']['file_links']}"
- else webserv_base_cgi
+ else webserv_base_cgi(opt)
end
- else webserv_base_cgi
+ end
+ end
+ def cgi_sample_search_form_name(opt=nil)
+ if opt.mod.inspect =~/--(?:cgi-)?search-form-name[=-]["']?(\S+?\.cgi)/
+ m=$1
+ elsif not (opt.mod.inspect =~/--db[=-]["']?sqlite/) \
+ and defined? @rc['search'] \
+ and defined? @rc['search']['sisu'] \
+ and defined? @rc['search']['sisu']['action'] \
+ and @rc['search']['sisu']['action'] =~/https?:\/\/\S+?\.cgi/
+ x=/(?:https?:\/\/\S+?)\/([^\/]+?\.cgi)$/.match(@rc['search']['sisu']['action'])[1]
+ else
+ (opt.mod.inspect =~/--db[=-]["']?sqlite/) \
+ ? 'sisu_sqlite.cgi' \
+ : 'sisu_pgsql.cgi'
end
end
def sample_search_form_title(organised_by=:language)
@@ -2569,24 +2595,29 @@ WOK
end
end
end
- def webserv_port_cgi
- if @md \
- and defined? @md.opt \
- and @md.opt.cmd.inspect=~/-F/ \
- and @md.opt.mod.inspect=~/port=(\d+)/
+ def webserv_port_cgi(opt=nil)
+ port=if opt \
+ and opt.cmd.inspect=~/-F/ \
+ and opt.mod.inspect=~/port=(\d+)/
$1
else
- if defined? @rc['webserv_cgi']['port']
+ port=if defined? @rc['webserv_cgi']['port']
if @rc['webserv_cgi']['port'].nil? \
- and (defined? @md.opt.mod \
- and not @md.opt.mod.nil? \
- and @md.opt.mod.inspect=~/webrick/)
+ and (defined? opt.mod \
+ and not opt.mod.nil? \
+ and opt.mod.inspect=~/webrick/)
defaults[:webserv_port_cgi]
elsif not @rc['webserv_cgi']['port'].nil?
@rc['webserv_cgi']['port']
else nil
end
- else nil
+ else
+ if (defined? opt.mod \
+ and not opt.mod.nil? \
+ and opt.mod.inspect=~/webrick/)
+ defaults[:webserv_port_cgi]
+ else nil
+ end
end
end
end
@@ -4036,11 +4067,17 @@ WOK
self
end
def psql
- def user
- ((defined? @rc['db']['postgresql']['user']) \
- && @rc['db']['postgresql']['user']=~/\S+/) \
- ? @rc['db']['postgresql']['user']
- : @env.user
+ def user(opt)
+ if opt.mod.inspect =~/--db-user[=-]["']?(\S+)["']+/
+ m=$1
+ elsif opt.mod =~/--webserv[=-]webrick/
+ @env.user
+ else
+ ((defined? @rc['db']['postgresql']['user']) \
+ && @rc['db']['postgresql']['user']=~/\S+/) \
+ ? @rc['db']['postgresql']['user']
+ : @env.user
+ end
end
def db #db_name
"#{Db[:name_prefix]}#{@pwd_stub}"