#*********************************************************************** #* Rwd/Tinker -- A Ruby program for the RudyWebDialog. #* Copyright (c) 2004, 2005 by Steven Gibson. All Rights Reserved. #* #* This library is free software; you can redistribute it and/or #* modify it under the terms of the GNU General Public #* License as published by the Free Software Foundation; either #* . #* #* These files are distributed in the hope that they will be useful, #* but WITHOUT ANY WARRANTY; without even the implied warranty of #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #* General Public License for more details. #* #* You should have received a copy of the GNU General Public #* License along with these files; if not, write to the Free Software #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #* #* For further information please contact the author by e-mail #* at "smalllinux@gmail.com". #***********************************************************************/ require 'logger' $rwdtinkerlog = Logger.new( 'rwd_files/log/rwdtinker.log', 'weekly' ) $rwdtinkerlog.level = Logger::INFO require "lib/rwd/rwd" require 'fileutils' require 'lib/rconftool' $progdir = File::expand_path( File.dirname(__FILE__)) tempdoc = " " # integrate the new configuration files MAINconfignew = "rwdconfig.cnf" MAINconfigdist = "rwdconfig.dist" Rconftool::install(MAINconfigdist,MAINconfignew) #load main config file load 'rwdconfig.cnf' Dir.chdir("configuration") #changes the current working directory fileList = Dir.new(".").entries.sort.reverse.delete_if { |x| ! (x =~ /dist$/) } #creates an Array separated with \n @doc = "" fileList.length.times{ #opening of a block configdist =fileList.pop #pops the first item out of the Array tempconfigfile = configdist.gsub(/\.dist$/, "") confignew = tempconfigfile + ".cnf" Rconftool::install(configdist,confignew) #integrates new file with old } #closing block # END of configuration integration Dir.chdir($progdir) # Read in the configuration files Dir.chdir("configuration") #changes the current working directory fileList = Dir.new(".").entries.sort.reverse.delete_if { |x| ! (x =~ /cnf$/) } #creates an Array separated with \n @doc = "" fileList.length.times{ #opening of a block fileName=fileList.pop #pops the first item out of the Array load fileName #loads the the config file thats in fileName } #closing block # END of configuration reading Dir.chdir($progdir) # change back to top program directory # build the English Language hash file from the parts Message = Hash.new { |hh, kk| hh[kk] = "ERROR: Message not found: #{kk.inspect}."; hh[kk] } langmessage = { :clear => "Clear", :rwdtinker => "Rwdtinker" } ; langmessage.each { |kk, vv| Message[kk] = vv } def msgid(programkey) $programkey = programkey end def msgstr(programmsg) if programmsg == "" $rwdtinkerlog.info "msgstr: no translation for #{$programkey}" else Message.update( $programkey.to_sym => programmsg ) end end require 'lib/rwdtinker/rwdlangdir' tempdoc = " " #go get all the po language file files in english tempdoc = RwdtinkerTools.findlanguagefiles(LangDir,"en") #writes the contents of doc into the languagehashvariable languagehashvariable = tempdoc # END of en Lang building tempdoc = " " Dir.chdir($progdir) # change back to top program directory # build the local Language hash file from the parts $lang = $langarray[0] # pick the language of choice # Go get all the po files for the language of choice tempdoc = RwdtinkerTools.findlanguagefiles(LangDir,$lang) # the contents of doc into the variable languagehashvariable = languagehashvariable + tempdoc Dir.chdir($progdir) # change back to top program directory # lets read those po files, first english then the chosen language temp = eval( languagehashvariable ) # build the actual program from the code parts require 'lib/rwdtinker/rwdcodedir' tempdoc = RwdtinkerTools.findprogramfiles(CodeDir) # load the program file tempcoderesult = eval( tempdoc ) # build the actual GUI from the gui parts require 'lib/rwdtinker/rwdguidir' tempdoc = RwdtinkerTools.findguifiles(GuiDir) # gui variable is done guiRWD = "" $rwd_gui_tinker = tempdoc require 'socket' # Network stuff host = "127.0.0.1" port = $port # Create a socket to listen on and bind it to the host and port freeportfound = false until freeportfound begin @socket = UDPSocket::new() @socket.bind(host, port) freeportfound = true $port = port # Rescue the "Address in use" error rescue Errno::EADDRINUSE $rwdtinkerlog.warn "RWD Startup: Port #{port} on host #{host} is already in use." port=port +1 $rwdtinkerlog.warn "trying port: #{port}" # Rescue the "Address not available' error rescue Errno::EADDRNOTAVAIL $rwdtinkerlog.warn "RWD Startup: Address #{host} is not available to bind." port =port + 1 $rwdtinkerlog.warn "trying port: #{port}" # Rescue "permission denied errors rescue Errno::EACCES $rwdtinkerlog.warn "RWD Startup: Access denied when binding interface addresses. ?" port =port + 1 $rwdtinkerlog.warn "trying port: #{port}" # Rescue all other errors rescue $rwdtinkerlog.warn "RWD Startup: An error occured." port =port + 1 $rwdtinkerlog.warn "trying port: #{port}" # Rescue all other errors end $port = port end RwdTinker.new( $rwd_gui_tinker ).serve(port) # start the main class and program