SHARE
TWEET

Untitled

a guest May 21st, 2013 666 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Script Name: UpdateYaDNS
  2. # Created by Klajnor 16.05.2013
  3. # Last update by Klajnor 21.05.2013
  4. # Last update by Klajnor 22.05.2013
  5. # Tested on 6.0rc14 and 6.0
  6.  
  7. # Set needed variables
  8.  
  9. #Root domain
  10. :local YaDNSdomain "domain.ru"
  11.  
  12. # read http://api.yandex.ru/pdd/doc/api-pdd/reference/api-dns_get_token.xml#api-dns_get_token
  13. :local YaDNStoken "132456789012345678901234567890"
  14.  
  15. # read http://api.yandex.ru/pdd/doc/api-pdd/reference/api-dns_edit_a_record.xml
  16. :local YaDNSrecordid "1234567"
  17. :local YaDNSTTL "300"
  18.  
  19. :global YaDNSForceUpdateOnce
  20. :global YaDNSPreviousIP
  21. :local YaDNSInterfaceName "PPPoE_NBN"
  22. :local YaDNSDomainRecord
  23.  
  24. # get the current IP address from the interface
  25.  
  26. :if ([:len [/interface find name=$YaDNSInterfaceName]] = 0 ) do={
  27.  :log info "UpdateYaDNS: No interface named $YaDNSInterfaceName , please check configuration."
  28.  :error "UpdateYaDNS: No interface named $YaDNSInterfaceName , please check configuration."
  29. }
  30.  
  31. :if ([:typeof $YaDNSPreviousIP] = "nothing" ) do={ :global YaDNSPreviousIP 0.0.0.0 }
  32.  
  33. :local YaDNSYaDNSCurrentIPMask [ /ip address get [/ip address find interface=$YaDNSInterfaceName] address ]
  34.  
  35. :local YaDNSCurrentIP [:pick $YaDNSYaDNSCurrentIPMask 0 [:find $YaDNSYaDNSCurrentIPMask "/"]]
  36.  
  37.  
  38. :if ([ :typeof $YaDNSCurrentIP ] = "nothing" ) do= {
  39.  :log info "UpdateDynDNS: No ip address present on $YaDNSInterfaceName, please check."
  40.  :error "UpdateDynDNS: No ip address present on $YaDNSInterfaceName, please check."
  41. }
  42.  
  43. :local YaDNSsrcpath1 ( "nsapi/get_domain_records.xml\?token=" . $YaDNStoken . "&domain=" . $YaDNSdomain )
  44.  
  45. :local YaDNSAPI [:resolve "pddimp.yandex.ru"]
  46. /tool fetch mode=https address="$YaDNSAPI" host="pddimp.yandex.ru" src-path=$YaDNSsrcpath1 dst-path="/YaDNSGetDomainRecord.txt"
  47.  
  48. :local Result1 [/file get YaDNSGetDomainRecord.txt contents]
  49. :local Result2 [:pick $Result1 ([:find $Result1 "id=\"$YaDNSrecordid"]) ([:find $Result1 "id=\"$YaDNSrecordid"]+42) ]
  50. :set YaDNSDomainRecord [:pick $Result2 ([:find $Result2 ">"] + 1) ( [:find $Result2 "<"] ) ]
  51.  
  52. :if (($YaDNSForceUpdateOnce or ($YaDNSCurrentIP != $YaDNSPreviousIP) or ($YaDNSCurrentIP != $YaDNSDomainRecord)) =  true) do={
  53.  
  54.   :log info "UpdateYaDNS: Try Update"
  55.  
  56.   :log info "UpdateYaDNS: YaDNSForceUpdateOnce = $YaDNSForceUpdateOnce"
  57.   :log info "UpdateYaDNS: YaDNSPreviousIP = $YaDNSPreviousIP"
  58.   :log info "UpdateYaDNS: YaDNSCurrentIP = $YaDNSCurrentIP"
  59.   :log info "UpdateYaDNS: YaDNSDomainRecord = $YaDNSDomainRecord"
  60.  
  61.   :local YaDNSsrcpath2 ( "nsapi/edit_a_record.xml\?token=" . $YaDNStoken . "&domain=" . $YaDNSdomain . "&record_id=" . $YaDNSrecordid . "&ttl=" . $YaDNSTTL . "&content=" . $YaDNSCurrentIP )
  62.  
  63.   :local YaDNSAPI [:resolve "pddimp.yandex.ru"]
  64.  
  65.   /tool fetch mode=https address="$YaDNSAPI" host="pddimp.yandex.ru" src-path=$YaDNSsrcpath2 dst-path="/YaDNS.txt"
  66.   :local result [/file get YaDNS.txt contents]
  67.  
  68.   :global YaDNSResult [:pick $result ([:find $result "<error>"]+7) [:find $result "</error>"]]
  69.  
  70.   :if ( $YaDNSResult = "ok" ) do={
  71.     :set YaDNSForceUpdateOnce false
  72.     :set YaDNSPreviousIP $YaDNSCurrentIP
  73.     :log info "UpdateYaDNS: Update Success"
  74.   }
  75.  
  76.   :log info "UpdateYaDNS: Result: $YaDNSResult"
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top