PHPAddSubaccounts
From Rackspace Email & Apps API
Copy and paste this script into an empty file, then make it executable (*nix). It works with PHP that has compiled SOAP support.
<?php ################################################################# # # # This script will create subaccounts from a list # # # ################################################################# $debug=false; if(($argv[1]=="-h")||($argv[1]=="--help")||(count($argv)<4)||(count($argv)>5)) { echo "PHP script to create a list of accounts for a Webmail.us reseller\n"; echo "Created April 2007 by Kirk Averett\n"; echo "\n"; echo "Usage:\n"; echo "php ".$argv[0]." filename username password [optional separator value] \n"; echo "\n"; echo "The username and password should be for an admin login to a reseller account\n"; echo "The filename should be the file with the list of account names to be created\n"; echo "'\\n' is the default separator, meaning that each account appears on a separate line\n"; echo "\n"; exit; } array_shift($argv); $file=array_shift($argv); $ruser=array_shift($argv); $rpass=array_shift($argv); if(count($argv)==1) { $sep = $argv[0]; } else { $sep = "\n"; } $wsdl="https://admin.webmail.us/excedentsoap/excedentsoap.wsdl"; $client = new SoapClient($wsdl, array('trace' => true, 'exceptions' => true)); $accounts_string=trim(file_get_contents($file)); $accounts_array = explode($sep,$accounts_string); $num = count($accounts_array); for ($i=0; $i<$num; $i++) { $currentaccount = trim($accounts_array[$i]); if($currentaccount=="") { continue; } $res = $client->__soapCall('SearchSubaccounts', array('ResellerUsername' => $ruser, 'ResellerPassword' => $rpass, 'SubaccountName' => $currentaccount, 'accountList' => "")); if ($res[Result] == 1) { } else { echo "Couldn't search for account ".$currentaccount." with error:\n"; print_r($res); echo "\n"; } $subfound = true; if ($res[accountList] == "") { $subfound = false; } else { $subacclistarr = explode("\n",$res[accountList]); list($subnum,$subname) = explode(",",$subacclistarr[0]); if(!(trim($subname) == $currentaccount)) { $subfound = false; } } if($subfound == false) { // Add subaccount $res = $client->__soapCall('AddSubaccount', array('ResellerUsername' => $ruser, 'ResellerPassword' => $rpass, 'SubaccountName' => $currentaccount, 'accountNumber' => "")); if ($res[Result] == 1) { echo "New account $currentaccount added to system and identified as #".$res[accountNumber]."\n"; } elseif ($res[Result] == -200) { echo "Account exists\n"; } else { echo "Could not add ".$currentaccount." as a new account with error:\n"; print_r($res); echo "\n";} } else { echo "Account $currentaccount already in system\n"; } } ?>