Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 3440feb7067f8f721feb4667090eba13fbfdef7a root committed Sep 23, 2010
@@ -0,0 +1,4 @@
+[user]
+ name = Justin Erny
+ email = justinerny@gmail.com
+
@@ -0,0 +1,2 @@
+*.log
+*.tgz
@@ -0,0 +1,11 @@
+<?xml version='1.0' standalone='yes'?>
+<configuration>
+ <dbtype>mysql</dbtype>
+ <host>localhost</host>
+ <user>whmcs</user>
+ <db>whmcs</db>
+ <pass>whmcsfinal123</pass>
+ <path>/var/www/lighttpd/whmcs/modules/servers/virtuozzo/</path>
+ <whmcsuser>wallywest</whmcsuser>
+ <whmcspass>wallywest!@#</whmcspass>
+</configuration>
@@ -0,0 +1,79 @@
+require 'xmlsimple'
+require 'active_record'
+require 'openssl'
+require 'socket'
+require 'net/ssh'
+require 'net/sftp'
+require 'net/ping'
+require 'base64'
+require 'ipaddress'
+require 'eventmachine'
+%w{log packetgenerator connection panel postsetup setup params revsetup licenses}.each do |file|
+ require File.dirname(__FILE__) + '/virtuozzo/' + file
+end
+%w{ippool iplib servers emsync synctidy sync}.each do |file|
+ require File.dirname(__FILE__) + '/virtuozzo/sync/' + file
+end
+#begin
+@file=File.join(File.dirname(__FILE__),'..','config.xml')
+@config=XmlSimple.xml_in(@file)
+ ActiveRecord::Base.establish_connection(
+ :adapter => "mysql2",
+ :host => @config['host'][0],
+ :username => @config['user'][0],
+ :password => @config['pass'][0],
+ :database => @config['db'][0],
+ :pool => 10
+ )
+ class Vdspool < ActiveRecord::Base
+ set_table_name 'vdspool'
+ validates_uniqueness_of :eid
+ class << self
+ def next_veid
+ select("veid").order("veid DESC").limit(1).where("veid < 22000").first.veid.to_i + 1
+ end
+ def get_veid(veid,node)
+ select("id AS vdsid,eid").where("veid='#{veid}' and vdsid='#{node}'").first
+ end
+ end
+
+ end
+ class Tblproducts < ActiveRecord::Base
+ set_primary_key :id
+ end
+ class Tblhosting < ActiveRecord::Base
+ set_primary_key :id
+ set_table_name 'tblhosting'
+ has_many :tblclients
+ end
+ class Tblservers < ActiveRecord::Base
+ set_primary_key :id
+ end
+ class Tblclients < ActiveRecord::Base
+ belongs_to :tblhosting
+ scope :name_clients,
+ :joins => :tblhosting,
+ :conditions => "tblclients.id=tblhosting.userid"
+ end
+ class Tblcustomfieldsvalues < ActiveRecord::Base
+ set_primary_key :relid
+ end
+ class Tblhostingconfigoptions < ActiveRecord::Base
+ end
+ class Ippool < ActiveRecord::Base
+ set_table_name 'ippool'
+ belongs_to :iprange, :class_name => 'Iprange'
+ end
+ class Iprange < ActiveRecord::Base
+ has_many :ippool, :class_name => 'Ippool'
+ end
+
+
+Virtuozzo::Log::create('vzctl.log')
+Virtuozzo::Log::write("running module with mode #{ARGV[0]}")
+print Virtuozzo::setup(ARGV[0],@config)
+#print Virtuozzo::Socket::setup(Virtuozzo::PacketGenerator::new)
+#rescue Exception => e
+# Virtuozzo::Log::error("#{e.backtrace}")
+# puts "Error in virtuozzo: #{e}"
+#end
@@ -0,0 +1,62 @@
+module Virtuozzo
+class Socket
+ class << self
+ include Virtuozzo
+ def setup
+ @params=Virtuozzo.getparams
+ @nodeip=@params["serverip"]
+ @packet=Virtuozzo::PacketGenerator::new
+ ctx=OpenSSL::SSL::SSLContext.new(:TLSv1)
+ ctx.ciphers= [['ADH-AES256-SHA','TLSv1','256','256']]
+ ctx.setup
+ sock=TCPSocket.new(@nodeip,4434)
+ @socket=OpenSSL::SSL::SSLSocket.new(sock,ctx)
+ @socket.sync=true
+ @socket.connect
+ run
+ end
+ def run
+ @packet.packet_list.each do |p|
+ if p=='end'
+ send(p.to_s)
+ Virtuozzo::Log::write("module finished")
+ return 'success'
+ else
+ response
+ #puts "sending packet #{p}"
+ Virtuozzo::Log::write("sending packet #{p}")
+ sendpacket(@packet.send(p.to_s))
+ end
+ end
+ end
+ def response
+ while str=@socket.gets
+ if str=~/<ns1:message>/
+ Virtuozzo::Log::error("#{str}")
+ raise str
+ end
+ if str.chomp=='</packet>'
+ return
+ end
+ if str.chomp=~/<ns4:eid>/
+ @eid=str.sub(/<\/.*>/,'').sub(/<.*>/,'').chomp
+ p @eid
+ @packet.actions @eid
+ end
+ end
+ end
+
+ def sendpacket(p)
+ @socket.write("\0")
+ @socket.write(p)
+ @socket.write("\0")
+ end
+ def end
+ @socket.close
+ Virtuozzo::Log::write('postsetup is running')
+ PostSetup::run
+ return 'success'
+ end
+ end
+end
+end
@@ -0,0 +1,124 @@
+module Virtuozzo
+class LicenseSetup
+include Virtuozzo
+ class << self
+ def run
+ Virtuozzo::Log::write('setting panel')
+ @params=Virtuozzo.getparams
+ @veip=@params[:mainip]
+ @panel=@params["panel"]
+ @vepass=@params["password"]
+ @hostname=@params["domain"]
+ @details=@params["clientsdetails"]
+ case @panel
+ when 'plesk' then @port=8443
+ else @port=22
+ end
+ if !@port.nil?
+ @p1=Net::Ping::TCP.new("#{@veip}","#{@port}")
+ 5.times do |x|
+ if @p1.ping?
+ self.send(@panel.to_s)
+ return 'success'
+ #break
+ end
+ end
+ raise
+ end
+ #raise "IP IS NOT RESOLVABLE"
+ end
+
+ #CPANEL LICENSE SETUP
+ def cpanel
+
+ end
+
+ def webmin
+
+ end
+
+ def plesk
+ @AuthInfo=Struct.new("AuthInfo", :login, :password)
+ @ServerAddress=Struct.new("ServerAddress", :ips,:macs)
+ #@CreationParameters=Struct.new("CreationParameters",:hwid)
+ @server=XMLRPC::Client.new2('https://ka.parallels.com:7050/',nil,900)
+ #self.keycreate
+ self.sendreq
+
+ end
+
+ def keycreate
+ @result=@server.call("partner10.createKey",
+ @AuthInfo.new("eboundhost","fMg9xSe2Rc7jtyXWmtP00U74z2SlIe16"),
+ @ServerAddress.new([],[]),
+ 'eboundhost.com',
+ 'PLESK_95_FOR_VZ',
+ ["#{@params["license_type"]}"]) #set variable here
+ @call=@server.call("partner10.retrieveKey",
+ @AuthInfo.new("eboundhost","fMg9xSe2Rc7jtyXWmtP00U74z2SlIe16"),
+ "#{@result['mainKeyNumber']}"
+ )
+ @license=Base64.encode64(@call['key'])
+ end
+
+ def sendreq
+ @initial_setup=%Q[
+ <packet version="1.4.2.0">
+ <server>
+ <initial_setup>
+ <admin>
+ <admin_cname>#{@details["companyname"]}</admin_cname>
+ <admin_pname>#{@details["firstname"]} #{@details["lastname"]}</admin_pname>
+ <admin_phone>#{@details["phonenumber"].gsub(/\s/,'')}</admin_phone>
+ <admin_fax></admin_fax>
+ <admin_email>#{@details["email"]}</admin_email>
+ <admin_address>#{@details["address1"]}</admin_address>
+ <admin_city>#{@details["city"]}</admin_city>
+ <admin_state>#{@details["state"]}</admin_state>
+ <admin_pcode>#{@details["postcode"].gsub(/\s/,'')}</admin_pcode>
+ <admin_country>#{@details["country"]}</admin_country>
+ <send_announce>true</send_announce>
+ </admin>
+ <password>#{@vepass}</password>
+ <server_name>#{@hostname}</server_name>
+ </initial_setup>
+ </server>
+ </packet>
+ ]
+ Virtuozzo::Log::write("#{@initial_setup}")
+ @lic_install=%Q[
+ <packet version="1.4.2.0">
+ <server>
+ <lic_install>
+ <license>#{@license}</license>
+ </lic_install>
+ </server>
+ </packet>
+ ]
+ c=Curl::Easy.new()
+ sendsetup(c)
+ sendlicense(c)
+ Tblcustomfieldsvalues.update_all("value='#{@result["mainKeyNumber"]}'",{:relid=>"#{@params["serviceid"]}",:fieldid => [11,13]})
+ end
+ def sendsetup(c)
+ c.url="https://#{@veip}:8443/enterprise/control/agent.php"
+ c.headers={'HTTP_AUTH_LOGIN' => 'admin','HTTP_AUTH_PASSWD' => 'setup','HTTP_PRETTY_PRINT' => 'true', 'Content-Type' => 'text/xml'}
+ c.enable_cookies=true
+ c.ssl_verify_host=false
+ c.ssl_verify_peer=false
+ c.http_post("#{@initial_setup}")
+ if c.body_str.include? "<errcode>1002</errcode>"
+ Virtuozzo::Log::write("#{c.body_str}")
+ sleep 2
+ sendsetup(c)
+ elsif c.body_str.include? "error"
+ Virtuozzo::Log::write("#{c.body_str}")
+ end
+ end
+ def sendlicense(c)
+ c.headers={'HTTP_AUTH_LOGIN' => 'admin','HTTP_PRETTY_PRINT' => 'true', 'Content-Type' => 'text/xml','HTTP_AUTH_PASSWD' => "#{@vepass}"}
+ c.http_post("#{@lic_install}")
+ end
+ end
+end
+end
@@ -0,0 +1,28 @@
+require 'log4r'
+require 'logger'
+include Log4r
+$path=File.join(File.dirname(__FILE__),'..','log')
+module Virtuozzo
+ class Log
+ class <<self
+ def create(file)
+ @file=file
+ @log=Log4r::Logger.new(@file)
+ p=PatternFormatter.new(:pattern => "[ %d ] %l\t %m")
+ Log4r::FileOutputter.new('logfile',
+ :filename=>"#{$path}/#{@file}",
+ :trunc=>false,
+ :formatter=>p,
+ :level => Log4r::INFO
+ )
+ @log.add('logfile')
+ end
+ def write(message)
+ @log.info "#{message}"
+ end
+ def error(message)
+ @log.error "ERROR: #{message}"
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 3440feb

Please sign in to comment.