WHM/cPanel API

From My Wiki
Revision as of 18:46, September 13, 2022 by J-Admin (talk | contribs) (WHM: Added modsec2.cpanel.conf fix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

For doing WHM or cPanel tasks at the command line.

Current documentation: https://api.docs.cpanel.net

Their examples currently have --output=jsonpretty listed by default. This isn't necessary if you don't need JSON-pretty output. YAML output is default.

cPanel

E-mail Accounts

Create list of current e-mail accounts

 uapi --user=CPUSER Email list_pops | grep 'email:' | awk '{print $2}' >> email_accounts.txt

Mass Create E-mail Accounts

This creates them from a list "names" which does not have the @domain.com within it, with an 18-character random password. Fill in the cPanel user and domain name.

for account in $(cat names); do echo $account; uapi --user=CPUSER Email add_pop email='$account' password=`strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 18 | tr -d '\n'` domain='EXAMPLE.COM'; done

This creates them from a list "names" for domain B, with an 18-character random password, and creates forwarders from their counterparts on domain A. Assumes they're in the same cPanel account.

for account in $(cat names); do echo $account; uapi --user=CPUSER Email add_pop email='$account' password=`strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 18 | tr -d '\n'` domain='EXAMPLE.COM'; uapi --user=CPUSER Email add_forwarder domain='OLDEXAMPLE.COM' email='$account@OLDEXAMPLE.COM' fwdopt='fwd'  fwdemail=@account@EXAMPLE.COM; done

WHM

Repopulate modsec2.cpanel.conf

 whmapi1 modsec_deploy_settings_changes