Plesk scripting

From Rackerbox Wiki

Jump to: navigation, search

Contents

Updating FTP passwords

Plesk has multiple locations that it stores ftp passwords for users. In order to update all from a listing of all ftp usernames, you would need to run each of the following in order:

Domain ftp passwords

#!/bin/bash

for line in $(awk '{print $1}' < /home/rack/ftp)
do
  #since input was comma separated list, cut uses , as delimiter
  user=`echo $line | cut -d, -f1`
  pass=`echo $line | cut -d, -f2`
  #echo $user
  #echo $pass

  domain=`mysql psa -Nse "select domains.name as username from domains left join hosting on domains.id=hosting.dom_id left join sys_users on hosting.sys_user_id=sys_users.id left join accounts on sys_users.account_id=accounts.id where sys_users.login='$user'"`
  #echo $domain
  if [ -z $domain ]
   then
     echo $user,$pass >> /home/rack/subdomains_webusers
     #echo $user,$pass
  fi
  /usr/local/psa/bin/domain.sh -u $domain -login $user -passwd $pass
done

Subdomain ftp passwords

#!/bin/bash

for line in $(awk '{print $1}' < /home/rack/subdomains_webusers)
do
  #input file was comma delimited list
  user=`echo $line | cut -d, -f1`
  pass=`echo $line | cut -d, -f2`
  echo $user
  echo $pass

  subdomain=`mysql psa -Nse "select subdomains.name from domains,sys_users,subdomains,accounts where domains.id=subdomains.dom_id and subdomains.sys_user_id=sys_users.id and sys_users.account_id=accounts.id and sys_users.login='$user';"`
  domain=`mysql psa -Nse "select domains.name from domains,sys_users,subdomains,accounts where domains.id=subdomains.dom_id and subdomains.sys_user_id=sys_users.id and sys_users.account_id=accounts.id and sys_users.login='$user';"`
  echo $subdomain
  if [ -z $subdomain ]
   then
     echo $user,$pass >> /home/rack/webusers
     #echo $user,$pass
  else
    /usr/local/psa/bin/subdomain.sh -u $subdomain -d $domain -passwd $pass
  fi
done

Webusers FTP passwords

#!/bin/bash

for line in $(awk '{print $1}' < /home/rack/webusers)
do
  #input file was comma delimited list
  user=`echo $line | cut -d, -f1`
  pass=`echo $line | cut -d, -f2`
  #echo $user
  #echo $pass

  domain=`mysql psa -Nse "select domains.name from domains,sys_users,web_users where domains.id=web_users.dom_id and web_users.sys_user_id=sys_users.id and sys_users.login='$user';"`
  if [ -z $domain ]
   then
     echo domain not found
     #echo $user,$pass
  else
   /usr/local/psa/bin/webuser.sh -u $user -domain $domain -passwd $pass
  fi
done

Update all system passwords with what is contained in the psa database

for i in `mysql psa -uadmin -p\`cat /etc/psa/.psa.shadow \` -e 'select login from sys_users order by login;' | cat | grep -v login`;do echo `mysql psa -uadmin -p\`cat /etc/psa/.psa.shadow\` -e "select password from accounts,sys_users where sys_users.account_id=accounts.id and sys_users.login='$i'" | cat | grep -v password` | passwd --stdin $i;done;


Updating all email account passwords

for i in $(mysql psa -BNe'select concat(mail.mail_name,"@",domains.name) > as address from mail,domains,accounts where mail.dom_id=domains.id and > mail.account_id=accounts.id order by address;'); do export > PSA_PASSWORD="$(openssl rand 6 -base64)"; /usr/local/psa/bin/mail.sh -u > $i -passwd ''; echo "$i:$PSA_PASSWORD" >> mail_password; done

Adding Domains from a filelist

This will read in a list of domains from file, where the ftp username is the first 16 characters of the domain. It does also include enabling FrontPage, so you may wish to disable that if not needed.

#!/bin/bash

for line in $(awk '{print $1}' < domains)
do
  client='client_login_name'
  domain=`echo $line`
  ftpuser=`echo $line | cut -c 1-16`
  ftppass='password'
  shell='/usr/local/psa/bin/chrootsh'
  ipaddr='xx.xx.xx.xxx'
  hosting='true'
  frontpage='true'
  fpauth='true'

  echo "Adding domain $domain"
  /usr/local/psa/bin/domain.sh -c $domain -status enabled -clogin $client -ip $ipaddr -hosting $hosting -login $ftpuser -passwd $ftppass -shell $shell -fp $frontpage -fpauth $fpauth -fplogin $ftpuser -fppasswd $ftppass
done

Permissions Validation

This will check that files within the DocumentRoot, as well as Web Users, have the ownership set to what exists in the psa database.

#!/bin/bash

query="$(mysql psa -Bse "select id from sys_users;")"

for id in ${query[@]}
do
  user=`mysql psa -Bse "select login from sys_users where id=$id"`
  home=`mysql psa -Bse "select home from sys_users where id=$id"`

  if [ -d $home/httpdocs ]
  then
    echo "---checking `echo $home | cut -d/ -f5`----"
    find $home/httpdocs $home/httpsdocs $home/private $home/cgi-bin -not -user $user
    #find $home/httpsdocs -not -user $user
  else
    #for web_users
    echo "---checking web_user $user at `echo $home | cut -d/ -f5`----"
    find $home -not -user $user
  fi

done
Personal tools