Class: PleskKit::Subscription
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PleskKit::Subscription
- Defined in:
- app/models/plesk_kit/subscription.rb
Instance Method Summary collapse
- #analyse(response_string, customer = nil) ⇒ Object
- #analyse_for_id(response_string, customer = nil) ⇒ Object
- #analyse_usage(response_string) ⇒ Object
- #downgradable?(new_plan) ⇒ Boolean
- #id_pack(shell, domain_name) ⇒ Object
- #pack_this(shell, customer) ⇒ Object
-
#provision_in_plesk ⇒ Object
request should look like this: <packet version=“1.6.3.0”> <webspace> <get> <filter> <id>subscription_id.to_i</id> </filter> <gen_info> <stat/> </get> </webspace> </packet>.
-
#switch_in_plesk ⇒ Object
update the plan name attr here before switching.
- #switch_pack(shell, sub_guid, plesk_sub_id) ⇒ Object
- #sync_pack(shell, sub_guid) ⇒ Object
- #usage_pack(shell, plesk_sub_id) ⇒ Object
Instance Method Details
#analyse(response_string, customer = nil) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/models/plesk_kit/subscription.rb', line 187 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 = xml.root.elements['//errtext'].text raise "#{code}: #{}" 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
200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'app/models/plesk_kit/subscription.rb', line 200 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 = xml.root.elements['//errtext'].text raise "#{code}: #{}" else sub_guid = xml.root.elements['//id'].text if xml.root.elements['//id'].present? end return sub_guid || true end |
#analyse_usage(response_string) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'app/models/plesk_kit/subscription.rb', line 214 def analyse_usage response_string xml = REXML::Document.new(response_string) status = xml.root.elements['//status'].text if xml.root.elements['//status'].present? space = '' mbox = '' if status == "error" code = xml.root.elements['//errcode'].text = xml.root.elements['//errtext'].text raise "#{code}: #{}" else space = xml.root.elements['//real_size'].text if xml.root.elements['//real_size'].present? mbox = xml.root.elements['//box'].text if xml.root.elements['//box'].present? end return [space,mbox] end |
#downgradable?(new_plan) ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/plesk_kit/subscription.rb', line 49 def downgradable?(new_plan) account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?"))) mbox_limit = new_plan.mailboxes space_limit = new_plan.storage #needs to be in bytes or convert the next value to GB plesk_subscription_identifier = PleskKit::Communicator.get_subscription_id(self) usage = PleskKit::Communicator.get_subscription_usage(self,plesk_subscription_identifier, account.server) if usage[0] < space_limit && usage[1] < mbox_limit return true else return false end end |
#id_pack(shell, domain_name) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/models/plesk_kit/subscription.rb', line 156 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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/plesk_kit/subscription.rb', line 106 def pack_this shell, customer digits = customer.login.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.owner_login 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_plesk ⇒ Object
request should look like this: <packet version=“1.6.3.0”>
<webspace>
<get>
<filter>
<id>subscription_id.to_i</id>
</filter>
<gen_info>
<stat/>
</get>
</webspace>
</packet>
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/plesk_kit/subscription.rb', line 27 def provision_in_plesk account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?"))) plan = PleskKit::ServicePlan.find_by_name self.plan_name self.service_plan_id = plan.id if plan.find_or_push(account.server).present? self.plan_name = self.plan_name self.ip_address = account.server.host self.owner_login = account.login self.name = self.name if account.class.to_s == 'PleskKit::ResellerAccount' self.reseller_account_id = account.id elsif account.class.to_s == 'PleskKit::CustomerAccount' self.customer_account_id = account.id end guid = PleskKit::Communicator.pack_and_play_with_subscription self, account PleskKit::Communicator.sync_subscription self, guid, account self.id else return false end end |
#switch_in_plesk ⇒ Object
update the plan name attr here before switching
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/plesk_kit/subscription.rb', line 81 def switch_in_plesk account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : 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(account.server).present? #guid = PleskKit::Communicator.pack_and_play_with_subscription self, account guid = PleskKit::Communicator.get_service_plan plan, account.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.customer_account true else puts "could not find or push?" end end |
#switch_pack(shell, sub_guid, plesk_sub_id) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/models/plesk_kit/subscription.rb', line 141 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
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'app/models/plesk_kit/subscription.rb', line 173 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 |
#usage_pack(shell, plesk_sub_id) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/plesk_kit/subscription.rb', line 64 def usage_pack shell, plesk_sub_id xml = shell xml.instruct! xml.packet(:version => '1.6.3.0') { xml.webspace{ xml.get { xml.filter{ xml.id(plesk_sub_id) # TODO!!! } xml.gen_info xml.stat } } } end |