Class: PleskKit::Subscription

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/plesk_kit/subscription.rb

Instance Method Summary collapse

Instance Method Details

#analyse(response_string, customer = nil) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/models/plesk_kit/subscription.rb', line 131

def analyse response_string, customer = nil
  xml = REXML::Document.new(response_string)
  status = xml.root.elements['//status'].text if xml.root.elements['//status'].present?
  if status == "error"
    code = xml.root.elements['//errcode'].text
    message = xml.root.elements['//errtext'].text
    raise "#{code}: #{message}"
  else
    sub_guid = xml.root.elements['//guid'].text if xml.root.elements['//guid'].present?
  end
  return sub_guid || true # TODO save plesk_id? Probably not necessary as we have the customer login
end

#analyse_for_id(response_string, customer = nil) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/models/plesk_kit/subscription.rb', line 144

def analyse_for_id response_string, customer = nil
  xml = REXML::Document.new(response_string)
  status = xml.root.elements['//status'].text if xml.root.elements['//status'].present?
  if status == "error"
    code = xml.root.elements['//errcode'].text
    message = xml.root.elements['//errtext'].text
    raise "#{code}: #{message}"
  else
    sub_guid = xml.root.elements['//id'].text if xml.root.elements['//id'].present?
  end
  return id || true
end

#id_pack(shell, domain_name) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/models/plesk_kit/subscription.rb', line 100

def id_pack shell, domain_name
  xml = shell
  xml.instruct!
  xml.packet(:version => '1.6.3.5') {
    xml.webspace{
      xml.get{
        xml.filter{
          xml.name(domain_name)
        }
        xml.dataset{
          xml.gen_info
        }
      }
    }
  }
end

#pack_this(shell, customer) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/plesk_kit/subscription.rb', line 50

def pack_this shell, customer
  digits = customer..to_s.split('')
  xx = ''
  digits.each {|d|xx << (d.to_i + 65).chr}
  xml = shell
  xml.instruct!
  xml.packet(:version => '1.6.3.5') {
    xml.webspace {
      xml.add{
        xml.gen_setup{
          xml.name(self.name)
          xml.tag! 'owner-login', self.
          xml.ip_address(self.ip_address)
        }
        xml.hosting{
          xml.vrt_hst{
            xml.property{
              xml.name('ftp_login')
              xml.value(xx.downcase)     #rand(36**8).to_s(36)
            }
            xml.property{
              xml.name('ftp_password')
              xml.value(customer.passwd)
            }
            xml.ip_address(self.ip_address)
          }
        }
        xml.tag! 'plan-name', self.plan_name
      }
    }
  }
  puts xml.target!
  return xml.target!
end

#provision_in_pleskObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/plesk_kit/subscription.rb', line 12

def provision_in_plesk

   = (.present? ?  : (.present? ?  : raise(msg="no accounts?")))
  plan = PleskKit::ServicePlan.find_by_name self.plan_name
  self.service_plan_id = plan.id
  if plan.find_or_push(.server) == true
    self.plan_name = self.plan_name
    self.ip_address = .server.host
    self. = .
    self.name = self.name
    if .class.to_s == 'PleskKit::ResellerAccount'
      self. = .id
    elsif .class.to_s == 'PleskKit::CustomerAccount'
      self. = .id
    end
    guid = PleskKit::Communicator.pack_and_play_with_subscription self, 
    PleskKit::Communicator.sync_subscription self, guid, 
    self.id
  else
    return false
  end
end

#switch_in_pleskObject

update the plan name attr here before switching



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/plesk_kit/subscription.rb', line 36

def switch_in_plesk
   = (.present? ?  : (.present? ?  : raise(msg="no accounts?")))
  plan = PleskKit::ServicePlan.find_by_name self.plan_name
  plesk_subscription_identifier = PleskKit::Communicator.get_subscription_id(self)
  if plan.find_or_push(.server) == true
    #guid = PleskKit::Communicator.pack_and_play_with_subscription self, account
    guid = PleskKit::Communicator.get_service_plan plan, .server
    PleskKit::Communicator.pack_and_switch_subscription(self, guid, plesk_subscription_identifier)
    sub_guid = PleskKit::Communicator.get_subscription_guid(self)
    PleskKit::Communicator.sync_subscription self, sub_guid, self.
    true
  end
end

#switch_pack(shell, sub_guid, plesk_sub_id) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/models/plesk_kit/subscription.rb', line 85

def switch_pack shell, sub_guid, plesk_sub_id
  xml = shell
  xml.instruct!
  xml.packet(:version => '1.6.3.5') {
    xml.webspace{
      xml.send(:"switch-subscription") {
        xml.filter{
          xml.id(plesk_sub_id)    # TODO!!!
        }
        xml.tag! 'plan-guid', sub_guid
      }
    }
  }
end

#sync_pack(shell, sub_guid) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/models/plesk_kit/subscription.rb', line 117

def sync_pack shell, sub_guid
  xml = shell
  xml.instruct!
  xml.packet(:version => '1.6.3.5') {
    xml.webspace{
      xml.send(:"sync-subscription") {
        xml.filter{
          xml.guid(sub_guid)
        }
      }
    }
  }
end