module Lumberg module Whm # Some WHM functions require different params for the same 'thing' # e.g. some accept 'username' while others accept 'user' # Be sure to keep our API consistent and work around those inconsistencies internally class Account < Base # Creates a hosting account and sets up its associated domain information # # ==== Required # * :username - PENDING # * :domain - PENDING # * :password - PENDING # # ==== Optional # * :plan - PENDING # * :pkgname - PENDING # * :savepkg - PENDING # * :featurelist - PENDING # * :quota - PENDING # * :ip - PENDING # * :cgi - PENDING # * : - PENDING def create(options = {}) server.perform_request('createacct', options) end # Permanently removes a cPanel account # # ==== Required # * :username - PENDING def remove(options = {}) options[:user] = options.delete(:username) server.perform_request('removeacct', options) end # Changes the password of a domain owner (cPanel) or reseller (WHM) account # # ==== Required # * :username - PENDING # * :password - PENDING def change_password(options = {}) options[:user] = options.delete(:username) options[:pass] = options.delete(:password) server.perform_request('passwd', options.merge(response_key: 'passwd')) end # Displays pertinent information about a specific account # # ==== Required # * :username - PENDING def summary(options = {}) options[:user] = options.delete(:username) server.perform_request('accountsummary', options) end # Modifies the bandwidth usage (transfer) limit for a specific account # # ==== Required # * :username - PENDING # * :bwlimit - PENDING def limit_bandwidth(options = {}) verify_user(options[:username]) do options[:user] = options.delete(:username) server.perform_request('limitbw', options) do |s| s.boolean_params = :unlimited, :bwlimitenable end end end # Lists all accounts on the server, and also allows you to search for a specific account or set of accounts # # ==== Optional # * :searchtype - PENDING # * :search - PENDING def list(options = {}) server.perform_request('listaccts', options) do |s| s.boolean_params = :suspended end end # Modifies settings for an account # # ==== Required # * :username - PENDING # # ==== Optional # * :domain - PENDING # * :newuser - PENDING # * :owner - PENDING # * :CPTHEME - PENDING # * :HASCGI - PENDING # * :LANG - PENDING # * :LOCALE - PENDING # * :MAXFTP - PENDING # * :MAXSQL - PENDING # * :MAXPOP - PENDING # * :MAXLST - PENDING # * :MAXSUB - PENDING # * :MAXPARK - PENDING # * :MAXADDON - PENDING # * :shell - PENDING def modify(options = {}) options[:user] = options.delete(:username) server.perform_request('modifyacct', options) do |s| s.boolean_params = :DEMO end end # Changes an account's disk space usage quota # # ==== Required # * :username - PENDING # * :quota - PENDING def edit_quota(options = {}) options[:user] = options.delete(:username) server.perform_request('editquota', options) end # Adds a new hosting package # # ==== Required # * :name - PENDING # # ==== Optional # * :featurelist - PENDING # * :quota - PENDING # * :ip - PENDING # * :cgi - PENDING # * :frontpage - PENDING # * :cpmod - PENDING # * :language - PENDING # * :maxftp - PENDING # * :maxsql - PENDING # * :maxpop - PENDING # * :maxlists - PENDING # * :maxsub - PENDING # * :maxpark - PENDING # * :maxaddon - PENDING # * :hasshell - PENDING # * :bwlimit - PENDING def add_package(options = {}) server.perform_request('addpkg', options) end # Changes the hosting package associated with a cPanel account # # ==== Required # * :username - PENDING # * :pkg - PENDING def change_package(options = {}) options[:user] = options.delete(:username) server.perform_request('changepackage', options) end # Obtains user data for a specific domain # # ==== Required # * :domain - PENDING def domain_user_data(options = {}) server.perform_request('domainuserdata', options.merge(response_key: 'userdata')) do |s| s.boolean_params = :hascgi end end # Prevents a cPanel user from accessing his or her account. Once an account is suspended, it can be un-suspended to allow a user to access the account again # # ==== Required # * :username - PENDING # # ==== Optional # * :reason - PENDING def suspend(options ={}) options[:user] = options.delete(:username) server.perform_request('suspendacct', options) end # Unsuspend a suspended account. When a user's account is unsuspended, he or she will be able to access cPanel again # # ==== Required # * :username - PENDING def unsuspend(options ={}) options[:user] = options.delete(:username) server.perform_request('unsuspendacct', options) end # Generates a list of suspended accounts def list_suspended(options = {}) server.perform_request('listsuspended', options) end # Generates a list of features you are allowed to use in WHM. Each feature will display either a 1 or 0. You are only able to use features with a corresponding 1 # # ==== Required # * :username - PENDING def privs(options ={}) verify_user(options[:username]) do resp = server.perform_request('myprivs', options.merge(response_key: 'privs')) do |s| s.boolean_params = :all end # if you get this far, it's successful resp[:success] = true resp end end # Changes the IP address of a website, or a user account, hosted on your server # # ==== Required # * :ip - PENDING def set_site_ip(options = {}) options[:user] = options.delete(:username) if options[:username] server.perform_request('setsiteip', options) end # Restores a user's account from a backup file. You may restore a monthly, weekly, or daily backup # # ==== Required # * :username - PENDING # * :type - PENDING # * :all - PENDING # * :ip - PENDING # * :mail - PENDING # * :mysql - PENDING # * :subs - PENDING def restore_account(options = {}) options[:user] = options.delete(:username) if options[:username] server.perform_request('restoreaccount', options.merge(response_key: 'metadata')) end protected # Some WHM API methods always return a result, even if the user # doesn't actually exist. This makes it seem like your request # was successful when it really wasn't # # Example # verify_user('bob') do # change_password() # end def verify_user(username, &block) exists = summary(username: username) if exists[:success] yield else raise WhmInvalidUser, "User #{username} does not exist" end end end end end