masterdomain = $masterdomain; $this->user = $user; $this->pw = $pw; $this->maillist = $maillist; } public function add_address($new_address) { $newaddys = array(); if ( is_array($new_address) ) { $newaddys = $new_address; } else { $newaddys[] = $new_address; } $additional = '&newaddr='; $cnt = 0; foreach ($newaddys as $newaddy) { if (!preg_match('/^[a-zA-Z0-9\-\.\_\/]+\@[a-zA-Z0-9\-\.]+$/',$newaddy)) { $this->errmsg = 'New e-mail address ('.$newaddy.') invalid'; return 3; } if ($cnt > 0) { $additional .= '#'; } $additional .= $newaddy; $cnt++; } $url = 'https://'.$this->masterdomain.'/sitecontrol/?remote_addmaillist'; return $this->SCRequest($url, $additional); } public function remove_address($old_address) { $oldaddys = array(); if ( is_array($old_address) ) { $oldaddys = $old_address; } else { $oldaddys[] = $old_address; } $additional = '&oldaddr='; $cnt = 0; foreach ($oldaddys as $oldaddy) { if (!preg_match('/^[a-zA-Z0-9\-\.\_\/]+\@[a-zA-Z0-9\-\.]+$/',$oldaddy)) { $this->errmsg = 'Old e-mail address invalid'; return 3; } if ($cnt > 0) { $additional .= '#'; } $additional .= $oldaddy; $cnt++; } $url = 'https://'.$this->masterdomain.'/sitecontrol/?remote_remmaillist'; return $this->SCRequest($url, $additional); } public function add_moderator($mod_address) { if (!preg_match('/^[a-zA-Z0-9\-\.\_\/]+\@[a-zA-Z0-9\-\.]+$/',$mod_address)) { $this->errmsg = 'New e-mail address invalid'; return 3; } $url = 'https://'.$this->masterdomain.'/sitecontrol/?remote_maillist_addmod'; $additional = '&modaddr='.$mod_address; return $this->SCRequest($url, $additional); } public function remove_moderator($mod_address) { if (!preg_match('/^[a-zA-Z0-9\-\.\_\/]+\@[a-zA-Z0-9\-\.]+$/',$mod_address)) { $this->errmsg = 'Old e-mail address invalid'; return 3; } $url = 'https://'.$this->masterdomain.'/sitecontrol/?remote_maillist_remmod'; $additional = '&modaddr='.$mod_address; return $this->SCRequest($url, $additional); } public function membercnt() { $url = 'https://'.$this->masterdomain.'/sitecontrol/?remote_maillist_membercnt'; $additional = ''; return $this->SCRequest($url, $additional); } private function SCRequest($url, $additional) { $post1 = 'listaddr='.$this->maillist.'&user='.$this->user.'&password='.$this->pw; $post1 .= $additional; $content_len = strlen($post1); $url = parse_url($url); $tries = 0; do { $fp = @fsockopen('ssl://'.$url[host], 443, $sockerrno, $sockerrstr, 10); $tries++; } while(!$fp && $tries < 3); fputs($fp, "POST {$url[path]}?{$url[query]} HTTP/1.1\r\n"); fputs($fp, "Host: {$url[host]}\r\n"); fputs($fp, "User-Agent: SCMaillistAPI/1.0\r\n"); fputs($fp, "Accept: text/plain\r\n"); fputs($fp, "Keep-Alive: 300\r\n"); fputs($fp, "Connection: keep-alive\r\n"); fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-Length: ".$content_len."\r\n"); fputs($fp, "\r\n"); fputs($fp, $post1."\r\n"); while(!feof($fp)) { $add = fgets($fp, 128); if (preg_match('/retval/', $res) && !preg_match('/[^\s]/', $add)) { break; } $res .= $add; } fclose($fp); if (preg_match('/retval: (\d+)/', $res, $match)) { $retval = $match[1]; if ($retval > 0) { if (preg_match('/Error: (.+?)\n/', $res, $match)) { $this->errmsg = $match[1]; } } return $retval; } $this->errmsg = 'Site control request failed'; return 10; } } ?>