0

I am not a programmer yet I found a ruby script to download VoiceMail from a voice mail system. It appears that the xml response is not being input. It is supposed to write the wav file to the path folder. I suspect there is an issue with this line

resp, xml = http.post(path, data, headers)

When I run the script I get the following error

[ccurry@ans1 ruby]$ ruby -w soap_getSubMessages.rb soap_getSubMessages.rb:66: warning: assigned but unused variable - resp /home/ccurry/.gem/ruby/gems/xml-simple-1.1.9/lib/xmlsimple.rb:1006:in find_xml_file': Could not find <soap_getSubMessages.xml> in <.> (ArgumentError) from /home/ccurry/.gem/ruby/gems/xml-simple-1.1.9/lib/xmlsimple.rb:168:in xml_in' from /home/ccurry/.gem/ruby/gems/xml-simple-1.1.9/lib/xmlsimple.rb:203:in xml_in' from soap_getSubMessages.rb:70:in '

# 2009Sep22
#
# ----------------------------------------------------
require 'rubygems'
require 'base64'
require 'net/http'
require 'net/https'
require 'xmlsimple'

WSPOOL      = '10.49.238.29'            # <-- change to your deployments wspool address
WSPORT      = 8086                      # <-- change to your deployments wspool port, secure is 8444
VM_PATH     = '/home/ccurry/ruby/VM'    # <-- local copy of voice messages are stored here
USER_DN     = '7205016784'              # <-- DN of voicemail box
ADMIN       = 'thecheto'                # <-- trusted admin
ADMIN_PASS  = 'xxxxxxxxxx'              # <-- admins password

# Create te http object - 
http = Net::HTTP.new(WSPOOL, WSPORT) 
http.use_ssl = false
path = '/wsd/services/ShService'

# Set Headers
headers = {
  'Referer' => 'http://0.0.0.0:8080',
  'Content-Type' => 'text/xml',
  'Host' => '0.0.0.0'
}

# get a count of messages by type
data = <<-EOF
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mp="http://mp.wsd.dcl" xmlns:sh="http://www.metaswitch.com/sdp/soap/sh">
   <soap:Header/>
   <soap:Body>
     <sh:ShPull>
         <sh:UserIdentity>#{USER_DN}</sh:UserIdentity>
         <sh:DataReference>0</sh:DataReference>
         <sh:ServiceIndication>Msph_Subscriber_Messaging_Status</sh:ServiceIndication>
         <sh:OriginHost>?clientVersion=1.0&amp;adminName=#{ADMIN}&amp;password=#{ADMIN_PASS}</sh:OriginHost>
      </sh:ShPull>
   </soap:Body>
</soap:Envelope>
EOF
# Post the request
# resp, xml = http.post(path, data, headers)
# puts xml # contains number of messages by type

# get message data
data = <<-EOF
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mp="http://mp.wsd.dcl" xmlns:sh="http://www.metaswitch.com/sdp/soap/sh">
   <soap:Header/>
   <soap:Body>
     <sh:ShPull>
         <sh:UserIdentity>#{USER_DN}</sh:UserIdentity>
         <sh:DataReference>0</sh:DataReference>
         <sh:ServiceIndication>Msph_Subscriber_Messaging_Data</sh:ServiceIndication>
         <sh:OriginHost>?clientVersion=1.0&amp;adminName=#{ADMIN}&amp;password=#{ADMIN_PASS}</sh:OriginHost>
      </sh:ShPull>
   </soap:Body>
</soap:Envelope>
EOF
# Post the request
resp, xml = http.post(path, data, headers)
#puts xml

# parse the returned xml
data = XmlSimple.xml_in(xml)
data['Body'].each do |body|
  body['ShPullResponse'].each do |spr|
    spr['UserData'].each do |ud|
      ud['Sh-Data'].each do |shd|
        shd['RepositoryData'].each do |resp|
          resp['ServiceData'].each do |sd|
            sd['MetaSphereData'].each do |msd|
              msd['Msph_Subscriber_Messaging_Data'].each do |msmd|
                msmd['Message'].each do |msg|
                  sentDate = msg['SentDate'][0]
                  msg['Voicemail'].each do |vm|
                    caller_DN = vm['CallerNumber'][0]
                    vm['VoiceAttachment'].each do |vma|
                      vma['Data'].each do |vmad|
                        wav = Base64.decode64(vmad['content'])
                        open("/#{VM_PATH}/#{caller_DN}_#{sentDate}.wav", "w") { |f| f.print wav }
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end
__END__

0 Answers0