uhferret-server 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #! /usr/bin/env ruby
  2. #
  3. # This file is part of uhferret, providing a web service interface.
  4. #
  5. # Author:: Peter Lane
  6. # Copyright:: Copyright 2012, Peter Lane.
  7. # License:: GPLv3
  8. #
  9. # uhferret is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # uhferret is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with uhferret. If not, see <http://www.gnu.org/licenses/>.
  21. require "optparse"
  22. require "webferret"
  23. # Name of the ferret software
  24. FERRET = "uhferret"
  25. # Base folder for working with files
  26. $base = "#{Dir.pwd}/FerretFiles/"
  27. # Port number for server
  28. port = 2000
  29. options = OptionParser.new do |opts|
  30. opts.banner = "Usage: uhferret-server [options]"
  31. opts.on("-h", "--help", "help message") do |v|
  32. puts options
  33. exit!
  34. end
  35. # -- port number
  36. opts.on("-p", "--port n", Integer, "port number") do |v|
  37. port = v
  38. end
  39. # -- base folder
  40. opts.on("-f", "--folder FOLDER", "base folder") do |v|
  41. $base = File.expand_path v
  42. end
  43. end
  44. begin
  45. options.parse!
  46. # Refuse to work if the folder already exists
  47. if File.exists? $base
  48. puts "Folder #{$base} already exists"
  49. puts "Please empty the folder before starting the ferret server"
  50. exit!
  51. end
  52. # install the ferret server at given Port number
  53. ferret = HTTPServer.new(:Port => port, :DocumentRoot => "/")
  54. ferret.mount "/ferret/home", UHFerret::FerretHomeServlet
  55. ferret.mount "/ferret/report", UHFerret::FerretReportServlet
  56. trap("INT") { ferret.shutdown }
  57. ferret.start
  58. end