From: Jeff Leggett Date: 2009-05-10T02:42:41+09:00 Subject: Re: CGI help Douglas Seifert wrote: >> >> >> *SIGH* Sure enough that fixed the syntax errors... Darn thing still >> doesn't work though :( Writes the h1 TITLE, and the submit, nothing in >> between... >> > > Can you post the contents of classification.txt? Some sample data would > help. Is the file readable by the web server process? Are you sure > that > the working directory when the cgi is run is such that opening > classification.txt with no other path info will work ( puts Dir.pwd ) > ...? > > -Doug Seifert [jleggett@binford cgi-bin]$ cat classification.txt Access Control,access,High,0,Medium,5,Low,10 Authentication,auth,High,0,Medium,5,Low,10 Confidentiality Impact,confi,High,10,Medium,5,Low,0 Confidentiality modifier,confm,Employee Data,30,Customer Data,20,System/network Data,10,application metadata,5,N/A,0 integrity impact,integi,High,10,Medium,5,Low,0 integrity modifier,integm,System/Application,30,Customer Information,20,Employee Info,30,Individual Info,10,N/A,0 Availability Impact,avail,High,10,medium,5,Low,0 [jleggett@binford cgi-bin]$ Yeah I added an else to the File.readable link to make sure it's there... it's there... the problem seems to be now it's not building the CGI all up... I get errors again. 1 #!/usr/bin/ruby 2 require "cgi" 3 Filename = 'classification.txt' 4 EMPTY_STRING = '' 5 TITLE = 'Vulnerability Classification' 6 cgi = CGI.new('html4') 7 output = cgi.html do 8 cgi.head { cgi.title { TITLE } } + 9 cgi.body { cgi.h1 { TITLE } + 10 cgi.form('post', 'http://binford.x.com/cgi-bin/vulnclass.rb') do 11 if File.readable?(Filename) then 12 f = File.open(Filename,"r") 13 f.each_line { |l| l.chomp 14 inputs = l.split(',') 15 cgi.p { inputs[0].to_s + ": " } + 16 #opts = "\"" + inputs[1].to_s + "\"" 17 2.times { inputs.delete_at(0) } 18 until inputs.empty? do 19 opts = opts + "[\"" + inputs[1].to_s + "\",\"" + inputs[0].to_s + "\"]" 20 2.times { inputs.delete_at(0) } 21 end 22 # puts opts 23 cgi.popup_menu(opts) + 24 cgi.br 25 } 26 f.close 27 else 28 puts "File not read-able!\n" 29 end 30 cgi.submit 31 end 32 } 33 end 34 cgi.out { output.gsub('><', ">\n<") } Produces: [jleggett@binford cgi-bin]$ ./vuln.rb (offline mode: enter name=value pairs on standard input) ./vuln.rb:20:in `+': can't convert Fixnum into String (TypeError) from ./vuln.rb:20 from ./vuln.rb:16:in `each_line' from ./vuln.rb:16 from /usr/lib/ruby/1.8/cgi.rb:1557:in `form' from ./vuln.rb:13 from (eval):1022:in `body' from ./vuln.rb:12 from /usr/lib/ruby/1.8/cgi.rb:1657:in `html' from (eval):1006:in `html' from /usr/lib/ruby/1.8/cgi.rb:1657:in `html' from ./vuln.rb:10 [jleggett@binford cgi-bin]$ -- Posted via http://www.ruby-forum.com/.