cpanel

package module
v0.0.0-...-efc3353 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 14 Imported by: 0

README

cpapi

Golang cPanel API bindings

A few demo examples:

jhayhurst@jack:~/Downloads|⇒  GOOS=linux GOARCH=amd64 go build github.com/jakdept/cpapi/demo/listresellers
jhayhurst@jack:~/Downloads|⇒  GOOS=linux GOARCH=amd64 go build github.com/jakdept/cpapi/demo/listaccts
jhayhurst@jack:~/Downloads|⇒  scp listaccts listresellers wopr:~/
listaccts                                                                         100%   11MB  63.4MB/s   00:00
listresellers                                                                     100%   11MB  55.8MB/s   00:00
{20-02-11 19:57}wopr:~ jack% ./listaccts --host cpanel.jakdept.dev --port 12345 --keyfile /home/jack/.ssh/id_rsa
All accounts on server:
wordpressy
singledb
whousescpanel
{20-02-11 19:59}wopr:~ jack% ./listresellers --host cpanel.jakdept.dev --port 12345 --keyfile /home/jack/.ssh/id_rsa
All resellers on server:
whousescpanel
cookiejar="$(mktemp)"

url="$(ssh cpanel.jakdept.dev 'whmapi1 create_user_session --output=json user=root service=whostmgrd locale=en' |jq -r '.data.url')"
echo "${url}"

curl \
--location \
--output /dev/null \
--cookie "${cookiejar}" \
--cookie-jar "${cookiejar}" \
"${url}"

cat "${cookiejar}"

url="$(echo "${url}" | sed 's/login.*$/json-api\/listaccts\?want=user/g')"
echo "${url}"

echo

curl \
--cookie "${cookiejar}" \
--cookie-jar "${cookiejar}" \
"${url}" | jq

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateUserSessionCmd = []string{
	"/usr/bin/env",
	"whmapi1",
	"create_user_session",
	"--output=json",
	"user=root",
	"service=whostmgrd",
	"preferred_domain=",
}

Functions

func InsecureSSHKeyfileConfig

func InsecureSSHKeyfileConfig(username, keyFile string) (ssh.ClientConfig, error)

Types

type Account

type Account struct {
	Username      string `json:"user,omitempty"`
	PrimaryDomain string `json:"domain,omitempty"`
	ContactEmail  string

	Reseller      string
	HomePartition string
	Shell         string
	Package       string `json:"package"`
	Theme         string

	BackupsEnabled        bool
	Suspended             bool
	Locked                bool
	OutgoingMailSuspended bool
	OutgoingMailHold      bool

	MailboxFormat            int8
	MaxDeferPrecent          string
	MinDeferBeforeProtection string
	MaxEmailPerHour          string

	MainIPv4 net.IP
	MainIPv6 net.IP

	EmailQuotaLimit string
	MaxAddons       string
	MaxFtp          string
	MaxMailingLists string
	MaxParked       string
	MaxPop          string
	MaxDatabases    string
	MaxSubdomains   string

	BandwidthUsed      *FloatLimit `json:"bandwidthused,omitempty"`
	BandwidthLimit     *FloatLimit `json:"bandwidthlimit,omitempty"`
	DiskUsed           *FloatLimit `json:"diskused,omitempty"`
	DiskLimit          *IntLimit   `json:"disklimit,omitempty"`
	AlternateDiskLimit *IntLimit   `json:"diskquota,omitempty"`
	InodeUsed          *IntLimit   `json:"inodeused,omitempty"`
	InodeLimit         *IntLimit   `json:"inodequota,omitempty"`
}

Account represents a cPanel account

type CpBool

type CpBool bool

func (*CpBool) MarshalJSON

func (b *CpBool) MarshalJSON() ([]byte, error)

func (*CpBool) String

func (b *CpBool) String() string

func (*CpBool) UnmarshalJSON

func (b *CpBool) UnmarshalJSON(v []byte) error

type FloatLimit

type FloatLimit struct {
	// contains filtered or unexported fields
}

func (*FloatLimit) MarshalJSON

func (l *FloatLimit) MarshalJSON() ([]byte, error)

func (*FloatLimit) String

func (l *FloatLimit) String() string

func (*FloatLimit) UnmarshalJSON

func (l *FloatLimit) UnmarshalJSON(v []byte) error

type IntLimit

type IntLimit struct {
	// contains filtered or unexported fields
}

func (*IntLimit) MarshalJSON

func (l *IntLimit) MarshalJSON() ([]byte, error)

func (*IntLimit) String

func (l *IntLimit) String() string

func (*IntLimit) UnmarshalJSON

func (l *IntLimit) UnmarshalJSON(v []byte) error

type Reseller

type Reseller struct {
	User     string    `json:"user"`
	Accounts []Account `json:"acct"`

	BandwidthUsed        *IntLimit `json:"totalbwused,omitempty"`
	BandwidthAlloc       *IntLimit `json:"totalbwalloc,omitempty"`
	BandwidthLimit       *IntLimit `json:"bandwidthlimit,omitempty"`
	BandwidthOverSelling *CpBool   `json:"bwoverselling,omitempty"`

	DiskUsed        *FloatLimit `json:"diskused,omitempty"`
	DiskAlloc       *IntLimit   `json:"totaldiskalloc,omitempty"`
	DiskLimit       *IntLimit   `json:"diskquota,omitempty"`
	DiskOverselling *CpBool     `json:"diskoverselling,omitempty"`
}

type WhmAPI

type WhmAPI struct {
	// contains filtered or unexported fields
}

func NewWhmApi

func NewWhmApi(hostname string) (*WhmAPI, error)

func (*WhmAPI) ActivateTokenUrl

func (a *WhmAPI) ActivateTokenUrl(url, token, hostname string) error

func (*WhmAPI) Call

func (a *WhmAPI) Call(
	method string,
	endpoint string,
	args url.Values,
	out interface{},
) error

func (*WhmAPI) ListAccounts

func (a *WhmAPI) ListAccounts() ([]string, error)

func (*WhmAPI) ListAllResellerNames

func (a *WhmAPI) ListAllResellerNames() ([]string, error)

func (*WhmAPI) LocalSessionAuthenticate

func (a *WhmAPI) LocalSessionAuthenticate() error

func (*WhmAPI) ResellerUsers

func (a *WhmAPI) ResellerUsers(reseller string) (Reseller, error)

func (*WhmAPI) SSHSessionAuthenticate

func (a *WhmAPI) SSHSessionAuthenticate(
	hostname string,
	port int,
	config ssh.ClientConfig,
) error

Directories

Path Synopsis
demo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL