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



140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/models/plesk_kit/subscription.rb', line 140

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



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/models/plesk_kit/subscription.rb', line 153

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?
  sub_guid =''
  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 sub_guid || true
end

#id_pack(shell, domain_name) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/models/plesk_kit/subscription.rb', line 109

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



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
84
85
86
87
88
89
90
91
92
# File 'app/models/plesk_kit/subscription.rb', line 59

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
49
50
51
52
53
54
55
56
57
# 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
  puts "|=|plan = PleskKit::ServicePlan.find_by_name self.plan_name ||| #{plan.inspect}"
  puts plan
  puts plan_name
  puts '_-_-_'
  plesk_subscription_identifier = PleskKit::Communicator.get_subscription_id(self)
  puts "plesk_subscription_identifier #{plesk_subscription_identifier}"
  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
    puts "|=| THE GUID IS #{guid}"
    puts "|=| about to start the switch cmd"
    PleskKit::Communicator.pack_and_switch_subscription(self, guid, plesk_subscription_identifier)
    puts "|=| about to start the get_subscription_guid cmd"
    sub_guid = PleskKit::Communicator.get_subscription_guid(self)
    puts "|=| about to sync up"
    PleskKit::Communicator.sync_subscription self, sub_guid, self.
    true
  end
end

#switch_pack(shell, sub_guid, plesk_sub_id) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/plesk_kit/subscription.rb', line 94

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



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/models/plesk_kit/subscription.rb', line 126

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