Delete Domain

From Pbxnsip Wiki

Jump to: navigation, search

Usage

In order to use this script, you must provide the following parameters:

  • -s/--server: Contact the specified server. The address can be an IP-address or a DNS-name. You should include the port after a colon. For example "192.168.1.2:8080".
  • -u/--username: Specify the administrator's username. The default is "admin".
  • -p/--password: Specify the password. The password will be transported in clear text, so you should make this that this is in line with your security policy.

You may append one or more domains names after the parameters.

Example:

delete_domain.sh -s 192.168.2.3:8080 -u admin -p secret domain1 domain2

Code

#!/bin/bash
#
# Copyright (C) 2007 pbxnsip Inc.
#
# Delete a domain

# Default values:
server=127.0.0.1:80
myname=$0
username=admin
password=

# some internal variables:
CURL="curl -f -s"
COOKIE=/tmp/cookie$$.txt
OUTPUT=/tmp/output$$.txt

function help()
{
  echo "Usage: $myname [options] domain1 ..."
  echo "  -s/--server: Contact the specified server, for example --s 192.168.1.2:8080"
  echo "  -u/--username: Specify the administrator's username (default: admin)
  echo "  -p/--password: Specify the password
}

function delete_domain()
{
  # Log in:
  curl -c $COOKIE -o $OUTPUT http://$server 2>/dev/null
  curl -b $COOKIE -o $OUTPUT -d login_account=$username -d login_password=$password -d login_type=auto -d Login.x=0 -d Login.y=0 -d reg_link=reg_index.htm -d dom_link=dom_index.htm -d usr_link=usr_index.htm http://$server/login.htm 2>/dev/null 

  # Delete the domain:
  curl -b $COOKIE -o $OUTPUT http://$server/reg_domains.htm?domaindel=$1 2>/dev/null

  # Logout:
  curl -b $COOKIE -o $OUTPUT http://$server/logout.htm 2>/dev/null
  rm $COOKIE $OUTPUT
} # delete_domain

# Parse the arguments and execute the tasks:
while [ $# -gt 0 ]; do
    case $1 in
        -s | --server) shift; server=$1; shift;;
        -u | --username) shift; username=$1; shift;;
        -p | --password) shift; password=$1; shift;;
        -*) help; exit 0;;
        *) delete_domain $1; shift;;
    esac
done
Personal tools
Getting Help