Changeset 604

Show
Ignore:
Timestamp:
03/30/07 17:12:03 (2 years ago)
Author:
sacha
Message:

moved all system calls from various places to one place in the util class.
target for multiplatform support
maybe required to do explicit calls (eg xyz_functionality_x options_hash) to then do platform (distribution dependent) stuff.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/hefeweizen_big_ania.rb

    r557 r604  
    365365 
    366366    def say_to_ania command 
    367       my_command = "echo \"#{command}\" >> #{@pipe_to_ania} " 
    368       system my_command 
     367      HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @pipe_to_ania 
    369368    end 
    370369 
  • trunk/src/hefeweizen_library_business_logic.rb

    r557 r604  
    19751975        "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
    19761976      } 
    1977       command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_to_http_server)}\" > #{instruction_pipe}" 
    1978       system command 
     1977 
     1978      command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_to_http_server) 
     1979      HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, instruction_pipe 
    19791980 
    19801981      # TODO 
     
    20142015        if true then 
    20152016           
    2016           command = "hefeweizen_sign_ebXML_signal_message \"#{file_path}\" \"#{hash['private_key_file']}\" \"#{hash['password_file']}\" \"#{hash['certificate_file']}\" \"#{temp_file_path}\"" 
    2017            
    2018           @logger.debug "#{me}: #{command}" if @debug 
     2017 
     2018          binary  = "hefeweizen_sign_ebXML_signal_message" 
     2019          arguments = "\"#{file_path}\" \"#{hash['private_key_file']}\" \"#{hash['password_file']}\" \"#{hash['certificate_file']}\" \"#{temp_file_path}\"" 
     2020           
     2021          @logger.debug "#{me}: #{binary} #{arguments}" if @debug 
    20192022 
    20202023          # blocking call 
    2021           system command 
     2024          HefeWeizen::HefeWeizenLibrary::Execution.execute_binary binary, arguments 
     2025 
    20222026          if $? == 0 then 
    20232027            @logger.debug "#{me}: Signing of ebXML signal message done." if @debug 
     
    20502054      # TODO 
    20512055      # fix 
    2052       command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_to_http_server)}\" > #{instruction_pipe}" 
    2053       system command 
     2056      command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_to_http_server 
     2057      HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, instruction_pipe 
    20542058 
    20552059    end 
     
    24592463              # this should be run in a tasker 
    24602464              my_pipe = "#{@config['PIPE_DIR']}/pipe_to_core_#{Time.now.to_f.to_s}" 
    2461               command = "mkfifo #{my_pipe}" 
    2462               system(command) 
    2463               command = "chmod 600 #{my_pipe}" 
    2464               system(command) 
     2465              binary = "mkfifo" 
     2466              HefeWeizen::HefeWeizenLibrary::Execution.execute_binary binary, my_pipe 
     2467              FileUtils.chmod 0600, my_pipe 
    24652468 
    24662469              command_hash = { 
     
    24762479              } 
    24772480               
    2478               command = "#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}" 
    2479               new_command = "echo \"#{command}\" > #{@config['PIPE_TO_ANIA']}" 
    2480  
    2481               system new_command 
     2481              command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 
     2482              HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @config['PIPE_TO_ANIA'] 
    24822483 
    24832484              pipe_to_me = File.open(my_pipe, "r+") 
     
    25562557            temp_dir = @config['TEMP_FILE_DIR'] 
    25572558            @logger.debug "#{me}: ebXML message with id '#{ebXML_message_object.message_id}' is digitally signed. Validating digital signature." if @debug 
     2559 
    25582560            # TODO Blocking system call to validate XML Digital Signature. 
    2559             command = "hefeweizen_validate_signature_ebXML_user_message \"#{ebXML_message_file_path}\" \"#{temp_dir}\" #{hash['certificate_file']}" 
    2560             result = system command 
     2561            binary = "hefeweizen_validate_signature_ebXML_user_message" 
     2562            arguments = "\"#{ebXML_message_file_path}\" \"#{temp_dir}\" #{hash['certificate_file']}" 
     2563            HefeWeizen::HefeWeizenLibrary::Execution.execute_binary binary, arguments 
     2564 
    25612565            if $? == 0 then 
    25622566              @logger.debug "#{me}: Successfully validated the digitally signed ebXML user messsage." if @debug 
     
    28362840     
    28372841    def say_to_ania command 
    2838       my_command = "echo \"#{command}\" >> #{@config['PIPE_DIR']}/pipe_to_ania" 
    2839       system my_command 
     2842      HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @config['PIPE_TO_ANIA'] 
    28402843    end 
    28412844 
  • trunk/src/hefeweizen_library_cpa.rb

    r557 r604  
    140140              # TODO a system command 
    141141              # Not criticial right here. 
    142               command = "c_rehash #{cpa_runtime_dir}/#{security_id}" 
    143               system command 
     142              command = "c_rehash" 
     143              arguments = "#{cpa_runtime_dir}/#{security_id}" 
     144              HefeWeizen::HefeWeizenLibrary::Execution.execute_binary command, arguments 
    144145            end 
    145146          } 
  • trunk/src/hefeweizen_library_ebMS_message2.rb

    r566 r604  
    425425 
    426426      def EBMessage2.get_good_message_id 
    427         %x(uuid).strip.gsub( /-/, "") 
     427        HefeWeizen::HefeWeizenLibrary::Execution.uuid.strip.gsub( /-/, "") 
    428428      end 
    429429 
     
    658658            logger.debug "#{me}: mime_type is: #{mime_type} with encoding: #{mime_type.encoding}" if debug 
    659659 
    660             #            command = "file -bi #{payload_path.strip}" 
    661             #            result = (%x{ #{command} } ).strip 
    662  
    663660            # adding multi-part mime part 
    664661            # -> seems default content-transfer-encoding is binary, no matter what. 
     
    716713          # TODO use Linux Tool file to try to get mime_type. 
    717714          command  = "file -bi #{payload_path}" 
    718           result = (%x{#{command}}).strip 
     715          result = HefeWeizen::HefeWeizenLibrary::Execution.execute_binary_get_output command 
    719716          logger.debug "#{me}: File command returned : #{result}" 
    720717          if result.nil? or result.empty? then 
  • trunk/src/hefeweizen_library_exchange_point.rb

    r557 r604  
    138138              "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
    139139            } 
    140             my_command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}\" >> #{@config['PIPE_TO_ANIA'].strip} " 
    141             write_to_ania my_command 
     140 
     141            command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 
     142            HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @config['PIPE_TO_ANIA'] 
    142143          else 
    143144            @logger.warn "#{me}: Protocol #{exchange_point_config[:protocol]} is not supported." if @warn 
     
    152153      end 
    153154 
    154       private 
    155  
    156       def write_to_ania my_command 
    157         system my_command 
    158       end 
    159  
    160155    end 
    161156  end 
  • trunk/src/hefeweizen_library_integration_point.rb

    r557 r604  
    138138            } 
    139139             
    140             my_command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}\" >> #{@config['PIPE_TO_ANIA'].strip} " 
    141             write_to_ania my_command 
     140            command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 
     141            HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @config['PIPE_TO_ANIA'] 
    142142          end 
    143143           
     
    180180      end 
    181181 
    182       private 
    183  
    184       def write_to_ania my_command 
    185         system my_command 
    186       end 
    187  
    188182    end 
    189183  end 
  • trunk/src/hefeweizen_library_utils.rb

    r553 r604  
    9292    class HefeWeizenUUID 
    9393      def HefeWeizenUUID.uuid 
     94        HefeWeizen::HefeWeizenLibrary::Execution.uuid 
     95      end 
     96 
     97    end 
     98 
     99    # This utility class is used to perform platform dependent code. 
     100    # HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe 
     101    # HefeWeizen::HefeWeizenLibrary::Execution.execute_binary 
     102    # HefeWeizen::HefeWeizenLibrary::Execution.execute_binary_get_output 
     103    # HefeWeizen::HefeWeizenLibrary::Execution.uuid 
     104    class Execution 
     105      def self.write_to_pipe command, pipe 
     106        # pipe = File.open(PIPE_TO_BIG_ANIA, "a"); pipe << 'system shutdown'; pipe.sync; pipe.close; 
     107        my_command = "echo \"#{command}\" >> #{pipe}" 
     108        system my_command 
     109      end 
     110 
     111      def self.execute_binary binary, arguments_as_string 
     112        system "#{binary} #{arguments_as_string}" 
     113        return $? 
     114      end 
     115 
     116      def self.execute_binary_get_output binary, arguments_as_string 
     117         
     118      end 
     119 
     120      def self.uuid 
    94121        %x( uuid ).strip 
    95122      end 
    96  
    97123    end 
    98124 
  • trunk/src/taskers/hefeweizen_tasker_application_decrypt_ebXML_message.rb

    r569 r604  
    175175        end 
    176176 
    177         my_command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}\" > #{@pipe_to_ania}" 
    178         @logger.debug "#{me}: Sending result to Big Ania: #{my_command}" if @debug 
    179         system my_command 
     177        command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 
     178        @logger.debug "#{me}: Sending result to Big Ania: #{command}" if @debug 
     179        HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @pipe_to_ania 
    180180 
    181181        FileUtils.rm files_to_delete 
     
    186186      private 
    187187       
     188      def get_id 
     189        HefeWeizen::HefeWeizenLibrary::Execution.uuid 
     190      end 
     191 
    188192      def repackage decrypted_file_paths 
    189193        old_ebMS = File.open @ebXML_message_file_path, "r" 
    190         id = %x( "uuid" ).strip 
     194        id = get_id 
    191195        new_ebXML_message_file_path = "#{@config['TEMP_FILE_DIR']}/new_ebXML_message_#{id}.bin" 
    192196        new_ebMS = File.new new_ebXML_message_file_path, "w" 
     
    245249        files_for_repackage = Hash.new 
    246250        content_hash.each_pair{ | content_id, content | 
    247           id = %x( "uuid" ).strip 
     251          id = get_id 
    248252          content_file_path = "#{@config['TEMP_FILE_DIR']}/encrypted_content_#{id}.bin" 
    249253          file = File.new content_file_path, "w" 
     
    252256          files_to_delete << content_file_path 
    253257           
    254           id = %x( "uuid" ).strip 
     258          id = get_id 
    255259          output_file_path = "#{@config['TEMP_FILE_DIR']}/decrypted_output_#{id}.bin" 
    256260 
    257261          # xmlsec1 decrypt --privkey-pem coronation_encryption_cert/Coronation_encryption_private_key.pem --output debian-logo-2.png out2.xml 
    258           command = "xmlsec1 decrypt --privkey-pem #{@private_key_file_path} --output #{output_file_path} #{content_file_path}" 
    259           @logger.debug "#{me}: Calling decryption code: #{command}" if @debug 
    260           system command 
     262          binary = "xmlsec1" 
     263          arguments = "decrypt --privkey-pem #{@private_key_file_path} --output #{output_file_path} #{content_file_path}" 
     264          @logger.debug "#{me}: Calling decryption code: #{binary} #{arguments}" if @debug 
     265          HefeWeizen::HefeWeizenLibrary::Execution.execute_binary binary, arguments 
     266 
    261267          if $? == 0 then 
    262268            files_to_delete << output_file_path 
     
    271277 
    272278      def get_xmlenc_template 
    273         filename = "#{@config['TEMP_FILE_DIR']}/encryption_template_#{%x( "uuid").strip}" 
     279        filename = "#{@config['TEMP_FILE_DIR']}/encryption_template_#{get_id}" 
    274280        file = File.new filename, "w" 
    275281        # <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/> 
  • trunk/src/taskers/hefeweizen_tasker_application_dir_observer.rb

    r569 r604  
    145145 
    146146      def get_a_new_transaction 
    147         %x( uuid ) 
     147        HefeWeizen::HefeWeizenLibrary::Execution.uuid 
    148148      end 
    149149 
  • trunk/src/taskers/hefeweizen_tasker_application_encrypt_ebXML_message.rb

    r569 r604  
    191191        end 
    192192 
    193         my_command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}\" > #{@pipe_to_ania}" 
    194         @logger.debug "#{me}: Sending result back to Big Ania: #{my_command}" if @debug 
    195         system my_command 
     193        command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 
     194        @logger.debug "#{me}: Sending result back to Big Ania: #{command}" if @debug 
     195        HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @pipe_to_ania 
    196196 
    197197        FileUtils.rm files_to_delete 
     
    204204      private 
    205205       
     206      def get_id 
     207        HefeWeizen::HefeWeizenLibrary::Execution.uuid 
     208      end 
     209 
     210 
    206211      def repackage files_to_repackage 
    207212        old_ebMS = File.open @ebXML_message_file_path, "r" 
    208         id = %x( "uuid" ).strip 
     213        id = get_id 
    209214        new_ebXML_message_file_path = "#{@config['TEMP_FILE_DIR']}/new_ebXML_message_#{id}.bin" 
    210215        new_ebMS = File.new new_ebXML_message_file_path, "w" 
     
    263268        files_for_repackage = Hash.new 
    264269        content_hash.each_pair{ | content_id, content | 
    265           id = %x( "uuid" ).strip 
     270          id = get_id 
    266271          content_file_path = "#{@config['TEMP_FILE_DIR']}/content_#{id}.bin" 
    267272          file = File.new content_file_path, "w" 
     
    270275          files_to_delete << content_file_path 
    271276           
    272           id = %x( "uuid" ).strip 
     277          id = get_id 
    273278          output_file_path = "#{@config['TEMP_FILE_DIR']}/encrypted_output_#{id}.xml" 
    274           command = "xmlsec1 encrypt --binary-data #{content_file_path} --session-key des-192 --pubkey-cert-pem #{@certificate} --output #{output_file_path} #{template_filename}" 
    275           system command 
     279          binary = "xmlsec1" 
     280          arguments = "encrypt --binary-data #{content_file_path} --session-key des-192 --pubkey-cert-pem #{@certificate} --output #{output_file_path} #{template_filename}" 
     281          @logger.debug "#{me}: Calling encryp code: #{binary} #{arguments}" if @debug 
     282          HefeWeizen::HefeWeizenLibrary::Execution.execute_binary binary, arguments 
     283 
    276284          if $? == 0 then 
    277285            files_to_delete << output_file_path 
     
    286294 
    287295      def get_xmlenc_template 
    288         filename = "#{@config['TEMP_FILE_DIR']}/encryption_template_#{%x( "uuid").strip}" 
     296        filename = "#{@config['TEMP_FILE_DIR']}/encryption_template_#{get_id}" 
    289297        file = File.new filename, "w" 
    290298        # <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/> 
  • trunk/src/taskers/hefeweizen_tasker_application_http_server.rb

    r580 r604  
    3939require 'logger' 
    4040require 'pp' 
    41 require 'monitor' 
    4241 
    4342$exit = false 
    4443 
    45 $instance = 0 
    46 $pipes = [] 
    47 $pipes.extend MonitorMixin 
    48  
    49 $mutex = Mutex.new 
    50  
    51  
    52 Signal.trap("INT") do  $stdout.puts "#{$0}: HefeWeizen Tasker HTTP Server caught INT signal. not exitting"; end 
     44Signal.trap("INT") do  $stderr.puts "#{$0}: HefeWeizen Tasker HTTP Server caught INT signal. not exitting"; end 
     45# Signal.trap("USR1") do  $stderr.puts "#{$0}: HefeWeizen Tasker HTTP Server caught USR1 signal. Exitting ... "; $exit = true; end 
    5346Signal.trap("USR1") { 
    54   $stdout.puts "#{$0}: HefeWeizen Tasker HTTP Server caught USR1 signal. Exitting ... " 
     47  $stderr.puts "#{$0}: HefeWeizen Tasker HTTP Server caught USR1 signal. Exitting ... " 
    5548  # TODO check where process is. Eg clean up pipe to HTTP Server. 
    56  
    57   $mutex.synchronize do 
    58     if $instance > 0 then 
    59       $pipes.synchronize do 
    60         $stdout.puts "HTTP Server Tasker needs to cleanup files." 
    61         $pipes.each{ | pipe | 
    62           begin 
    63             FileUtils.rm_rf(pipe) 
    64           rescue Exception => e 
    65             $stdout.puts "Exception: #{e.to_s}" 
    66           end 
    67         } 
    68       end 
    69     end 
    70     $stdout.puts "HTTP Server Taserk Exitting." 
    71     Process.exit! 0 
    72   end 
     49  Process.exit! 0 
    7350} 
    7451 
     
    9875 
    9976      def do_POST(req, resp) 
    100          
    101         $mutex.synchronize do 
    102           $instance += 1 
    103         end 
     77 
    10478        # 0. if we are in the testing environment 
    10579        if @config['BIG_ANIA_LOAD_TEST_ENVIRONMENT'] == 'true' then 
     
    11791              #              resp.body = "blah blah blah" 
    11892              #              resp.status = 204 
    119               return finished 
     93              return 
    12094            end 
    12195          end 
     
    159133        # 2. 
    160134        # create a named pipe so big ania (via ania) can tell us how to proceed. 
    161          
    162135        my_pipe = "#{@config['PIPE_DIR']}/pipe_to_http_server_#{now.to_f.to_s}" 
    163         $pipes.synchronize do 
    164           $pipes.push my_pipe 
    165         end 
    166         command = "mkfifo #{my_pipe}" 
    167         system(command) 
    168         command = "chmod 600 #{my_pipe}" 
    169         system(command) 
     136        binary = "mkfifo" 
     137        HefeWeizen::HefeWeizenLibrary::Execution.execute_binary binary, my_pipe 
     138        FileUtils.chmod 0600, my_pipe 
     139 
    170140         
    171141        # 3. 
     
    278248        pipe_to_me.close 
    279249        FileUtils.rm(my_pipe) 
    280         $pipes.synchronize do 
    281           $pipes.delete my_pipe 
    282         end 
    283         return finished 
    284       end 
    285  
    286       private 
    287       def finished 
    288         $mutex.synchronize do 
    289           $instance -= 1 
    290         end 
    291       end 
    292  
     250 
     251        return true 
     252      end 
    293253    end 
    294254 
     
    309269 
    310270      def write_to_ania string 
    311         my_command = "echo \"#{string}\" > #{@pipe_to_ania}" 
    312         system my_command 
     271        HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe string, @pipe_to_ania 
    313272      end 
    314273       
  • trunk/src/taskers/hefeweizen_tasker_application_send_ebXML_message.rb

    r567 r604  
    147147 
    148148        @ebXML_message_id = @ebXML_message_parameters['ebXML_message']['ebXML_message_id'] 
    149  
     149         
    150150        if @ebXML_message_parameters['info']['transport-protocol-name'].upcase == "HTTP" then 
    151151          # HTTP settings 
     
    205205          @logger.debug "#{me}: Extra headers for HTTP post: #{extra_header}" if @debug 
    206206          # added ignore-length ... had problems with it when using webrick and setting code 204 to it. 
    207           command = "wget -S #{ssl_configurations} --ignore-length --user-agent=\"HefeWeizen\" --post-file=\"#{@ebXML_message_file_path}\" --header='#{extra_header}' --header='SOAPAction: \"ebXML\"' --output-document=\"#{response_file_path}\" --append-output=\"#{transfer_info_file_path}\" #{http_url}
    208            
    209           @logger.debug "#{me}: Complete HTTP post command: #{command}" if @debug 
    210           system(command) 
    211           success = $? 
     207          binary = "wget
     208          arguments = "-S #{ssl_configurations} --ignore-length --user-agent=\"HefeWeizen\" --post-file=\"#{@ebXML_message_file_path}\" --header='#{extra_header}' --header='SOAPAction: \"ebXML\"' --output-document=\"#{response_file_path}\" --append-output=\"#{transfer_info_file_path}\" #{http_url} " 
     209           
     210          @logger.debug "#{me}: Complete HTTP post command: #{binary} #{arguments}" if @debug 
     211          success = HefeWeizen::HefeWeizenLibrary::Execution.execute_binary binary, arguments 
    212212 
    213213        elsif @ebXML_message_parameters['info']['transport-protocol-name'].upcase == "SMTP" then 
     
    291291        end 
    292292         
    293         my_command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}\" > #{@pipe_to_ania}" 
    294         @logger.debug "#{me}: Sending back result to Big Ania: #{my_command}" if @debug 
    295         system my_command 
     293        command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 
     294        @logger.debug "#{me}: Sending back result to Big Ania: #{command}" if @debug 
     295        HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @pipe_to_ania 
    296296         
    297297        return 0 
  • trunk/src/taskers/hefeweizen_tasker_application_sign_ebXML_message.rb

    r569 r604  
    241241 
    242242      def get_id 
    243         %x( "uuid" ).strip 
     243        HefeWeizen::HefeWeizenLibrary::Execution.uuid 
    244244      end 
    245245 
  • trunk/src/taskers/hefeweizen_tasker_application_wake_up_call.rb

    r569 r604  
    163163        end 
    164164 
    165         my_command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}\" > #{@pipe_to_ania}" 
    166         @logger.debug "#{me}: Sending result back to Big Ania: #{my_command}" if @debug 
    167         system my_command 
     165        command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 
     166        @logger.debug "#{me}: Sending result back to Big Ania: #{command}" if @debug 
     167        HefeWeizen::HefeWeizenLibrary::Execution.write_to_pipe command, @pipe_to_ania 
    168168         
    169169        return 0