Browse Source

Added an example of a working connector.

- mailman specific
- has been tested to work properly for both subscribe, and unsubscribe
- uses node.js
- two stage security
  1) password is specific to connector for recognization
  2) password used by list not kept local
- ssl used for all communication
- yeah!
devel
Jonathan Rosenbaum 10 years ago
parent
commit
6aa95e1ad4
  1. 87
      examples/mailman_connector_example.js
  2. 7
      js/contact.js
  3. 10
      json/contact.php

87
examples/mailman_connector_example.js

@ -0,0 +1,87 @@
var https = require('https');
var fs = require('fs');
var querystring = require('querystring');
var password = 'fakepassword';
var secret_password = 'bikebike';
var options = {
passphrase: 'fakepassword',
key: fs.readFileSync('./ssl/privkey.pem'),
cert: fs.readFileSync('./ssl/cacert.pem')
};
var mailman = require('https');
var mailman_options = {
hostname: 'wvcompletestreets.org',
port: 443,
path: '/',
method: 'POST',
ca: fs.readFileSync('/etc/ssl/certs/demo-cert.pem')
};
var server = https.createServer(options, function (request, response) {
response.writeHead(200, { 'Content-Type': 'application/json' });
request.on('data',function(message){
var data = JSON.parse(message);
var subscribees_upload = data.first_name + ' ' + data.last_name + ' <' + data.email + '>';
var url_object;
var member_query;
if (data.subscribe === 'subscribe') {
url_object = {
subscribe_or_invite: 0,
send_welcome_msg_to_this_batch: 1,
notification_to_list_owner: 1,
adminpw: password,
subscribees_upload: subscribees_upload
};
member_query = '/mailman/admin/ybdb-devel/members/add?' + querystring.stringify(url_object);
} else {
url_object = {
send_unsub_ack_to_this_batch: 1,
send_unsub_notifications_to_list_owner: 1,
unsubscribees_upload: data.email,
adminpw: password
};
member_query = '/mailman/admin/ybdb-devel/members/remove?' + querystring.stringify(url_object);
}
mailman_options.path = member_query;
if (secret_password === data.password) {
// post to mailman server
var req = mailman.request(mailman_options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
//req.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
} // secret_password matches
response.write('ok');
});
request.on('end',function(){
response.end();
});
server.on('error', function (e) {
console.error(e);
});
}); // end email connector server
server.listen(Number(process.argv[2]));

7
js/contact.js

@ -89,7 +89,7 @@ $(function(){
if ((err0 + err1 + err2 + err3 + err4 + err5) > 0 ) {
} else {
e.preventDefault();
//e.preventDefault();
dfd.resolve("Success");
}
@ -121,8 +121,11 @@ $(function(){
// email subscribe
if (email_list == 1) {
$.post("json/contact.php", {email_list_connector: 1, email: email.val(),
$.post("json/contact.php", {email_list_connector: 'subscribe', email: email.val(),
first_name: first_name.val(), last_name: last_name.val()});
} else {
$.post("json/contact.php", {email_list_connector: 'unsubscribe', email: email.val(),
first_name: first_name.val(), last_name: last_name.val()});
}
}

10
json/contact.php

@ -49,9 +49,10 @@ $ssl_certificate = SSL_CERTIFICATE;
}
// send data to connector (local or remote)
if (isset($_POST['email_list_connector'])) {
if (isset($_POST['email_list_connector']) == 'subscribe' || isset($_POST['email_list_connector']) == 'unsubscribe' ) {
$json = array(
'subscribe' => $_POST['email_list_connector'],
'password' => $email_list_connector_password,
'email' => $_POST['email'],
'first_name' => $_POST['first_name'],
@ -73,10 +74,9 @@ $ssl_certificate = SSL_CERTIFICATE;
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
// just to test
echo $result;
curl_close($ch);
echo $result;
}

Loading…
Cancel
Save