Hi all,
My website has been using php code to manage MailMan mailing lists, to create list and set many options. Now with the update to cpanel that makes security tokens mandatory, my scripts don't work.
So the old style URLS were like this:
/https://server.host.net:2083/frontend/x3/mail/doaddlist.html
New URLs are like this:
/https://server.host.net:2083/frontend/x3/mail/doaddlist.html/cpsessXXXXXXXXXX/frontend/x3/mail/doaddlist.html
Can anyone help me to update my php code, or post their own code that does similar things? I'll post my current code below.
Thanks a lot for any help!
Simon.
By the way, I was inspired to post this question by benwiggy who posted 2 years ago that he would create a PHP class to do this very thing here: http://forums.cpanel.net/f42/create-mailman-list-api-212042.html
My website has been using php code to manage MailMan mailing lists, to create list and set many options. Now with the update to cpanel that makes security tokens mandatory, my scripts don't work.
So the old style URLS were like this:
/https://server.host.net:2083/frontend/x3/mail/doaddlist.html
New URLs are like this:
/https://server.host.net:2083/frontend/x3/mail/doaddlist.html/cpsessXXXXXXXXXX/frontend/x3/mail/doaddlist.html
Can anyone help me to update my php code, or post their own code that does similar things? I'll post my current code below.
Thanks a lot for any help!
Simon.
PHP:
// Example simple function to create a mailmain list and set a couple of options
// doesn't work any more as not using cpsess URLs
------------------------------------------------------------------------------
function createMailingList($mailinglist,$password,$emails){
$http = createCPanelHttpClient("https://myhost.net:2083/");
$pageContents = postHttpClient($http,"https://myhost.net:2083/frontend/x3/mail/doaddlist.html",
array('email' => $mailinglist,
'password' => $password,
'domain' => 'mysite.net'));
$pos = strpos($pageContents, 'was successfully created');
if ($pos === false) {
return false;}
// code here to set all the mailman options
$baseMailmanUrl= "http://myhost.net/mailman/admin/".$mailinglist."_mysite.net/";
$http = createMailmanHttpClient();
// set all the mailman General options here
$pageContents = postHttpClient($http,$baseMailmanUrl."general",
array('adminpw' => $password,
'description' => $mailinglist));
return true}
// -------------------
function createCPanelHttpClient($baseUrl){
require_once("http.php");
$http=new http_class;
$http->follow_redirect=1;
$http->timeout=0;
$http->data_timeout=0;
$http->debug=0;
$http->html_debug=0;
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$url=$baseUrl."login/";
$error=$http->GetRequestArguments($url,$arguments);
$arguments["Headers"]["Referer"]=$baseUrl;
$arguments["RequestMethod"]="POST";
$arguments["PostValues"]=array(
'user' => 'adminuser',
'pass' => 'adminpassword',
'goto_uri' => '',
'login_theme' => 'cpanel');
$error=$http->Open($arguments);
if($error=="")
{
$error=$http->SendRequest($arguments);
if($error=="")
{
readResponse($http);
}
}
if(strlen($error))
echo "<CENTER><H2>Error: ",$error,"</H2><CENTER>\n";
echo "<p>request_headers:";
print_r($http->request_headers);
echo "</p>";
$http->Close();
return $http;
}
//-----------------------------
function createMailmanHttpClient(){
require_once("http.php");
$http=new http_class;
$http->follow_redirect=1;
$http->timeout=0;
$http->data_timeout=0;
$http->debug=0;
$http->html_debug=0;
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
return $http;
}
By the way, I was inspired to post this question by benwiggy who posted 2 years ago that he would create a PHP class to do this very thing here: http://forums.cpanel.net/f42/create-mailman-list-api-212042.html