PHPProperSizeAllUsers

From Rackspace Email & Apps API
Revision as of 15:58, 25 August 2008 by APIAdmin (talk | contribs) (New page: <pre> <?php $domain = 'somedomain.com'; $ruser = 'someuser'; $rpass = 'somepass'; $newdomainsize = 100; //Default mailbox size in MB $proximitymultiplier = 1.12; ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

<?php

$domain = 'somedomain.com';
$ruser = 'someuser';
$rpass = 'somepass';
$newdomainsize = 100;                    //Default mailbox size in MB
$proximitymultiplier = 1.12;             //This allows about 10% padding; 5% =  1.06, 20% = 1.26
$steps = array(250,500,1024,2048,5000);  //For tiered pricing; use values from Webmail contract

$client = new SoapClient('https://admin.webmail.us/excedentsoap/excedentsoap.wsdl');

$userlist = array("");

$res = $client->__soapCall('GetDomainAllUserCurrentSize',
                     array('ResellerUsername' => $ruser,
                           'ResellerPassword' => $rpass,
                           'HostName'         => $domain,
                           'UserStatArray'     => $userlist));

$num = count($res[UserStatArray]);

$userarray=$res[UserStatArray];

$usernames=array("");
$userPos=0;

$usernewsizes=array(0);

for ($count=0; $count<$num; $count  ) {
  $thisuserdata = trim($userarray[$count]);
  $thisuserdataArray = explode(',',$thisuserdata);
  $user = $thisuserdataArray[0];
  $usage = $thisuserdataArray[1];
  $approximatesize = $usage * $proximitymultiplier;
  if ($approximatesize < $newdomainsize) {
    print $user . " is fine at " . $usage . "/" . $newdomainsize . "\n";
  }
  else {
    $currentstep = 0;
    while ($approximatesize > $steps[$currentstep]) {
      $currentstep  ;
    }
    $usernames[$userPos]=$user;
    $usernewsizes[$userPos]=$steps[$currentstep];
    $userPos  ;
  }
}

$res = $client->__soapCall('ModifyDomainMaxMailboxSize',
                     array('ResellerUsername' => $ruser,
                           'ResellerPassword' => $rpass,
                           'HostName'         => $domain,
                           'MaxMbxSize'       => $newdomainsize));

if ($res == 1) {
  print "Successfully set " . $domain . " to have a mailbox size of " . $newdomainsize . "MB\n";
}
else {
  print "Couldn\'t set " . $domain . " to have a mailbox size of " . $newdomainsize . "MB with error " . $res . "\n";
}

$num = count($usernames);

for ($count=0; $count<$num; $count  ) {
  $res = $client->__soapCall('SetUserMailboxMaxSize',
                       array('ResellerUsername' => $ruser,
                             'ResellerPassword' => $rpass,
                             'HostName'         => $domain,
                             'UserID'           => $usernames[$count],
			     'MaxMbxSize'       => $usernewsizes[$count]));
  if ($res == 1) {
    print "Set " . $usernames[$count] . " to " . $usernewsizes[$count] . "\n";
  }
  else {
    print "Couldn\'t set " . $usernames[$count] . " to " . $usernewsizes[$count] . " with error " . $res . "\n";
  }
}

?>