Skip to content
Snippets Groups Projects
Commit 20b53534 authored by rswindell's avatar rswindell
Browse files

Latest and greatest.

parent 528de785
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ var ini_fname = system.ctrl_dir + "listserver.ini"; ...@@ -15,7 +15,7 @@ var ini_fname = system.ctrl_dir + "listserver.ini";
ini_file = new File(ini_fname); ini_file = new File(ini_fname);
if(!ini_file.open("r")) { if(!ini_file.open("r")) {
log(LOG_ERR,format("!ERROR %s opening ini_file: %s" log(LOG_ERR,format("!ERROR %d opening ini_file: %s"
,ini_file.error, ini_fname)); ,ini_file.error, ini_fname));
exit(); exit();
} }
...@@ -31,29 +31,32 @@ if(!list_array.length) { ...@@ -31,29 +31,32 @@ if(!list_array.length) {
} }
for(var l in list_array) { for(var l in list_array) {
var list = list_array[l];
/* Set default list addresses */ /* Set default list addresses */
if(!list_array[l].address) if(!list.address)
list_array[l].address = format("%s@%s", list_array[l].name, system.inet_addr); list.address = format("%s@%s", list.name, system.inet_addr);
if(!msg_area.sub[list_array[l].sub]) { if(!msg_area.sub[list.sub]) {
log(LOG_WARNING,"!Unrecognized sub-board internal code: " + list_array[l].sub); log(LOG_WARNING,"!Unrecognized sub-board internal code: " + list.sub);
list_array[l].disabled=true; list.disabled=true;
continue; continue;
} }
if(!list_array[l].description) if(!list.description)
list_array[l].description = msg_area.sub[list_array[l].sub].description; list.description = msg_area.sub[list.sub].description;
if(list_array[l].confirm==undefined) if(list.confirm==undefined)
list_array[l].confirm=true; list.confirm=true;
var msgbase = new MsgBase(list_array[l].sub); var msgbase = new MsgBase(list.sub);
if(msgbase.open()==false) { if(msgbase.open()==false) {
log(LOG_ERR,format("%s !ERROR %s opening msgbase: %s" log(LOG_ERR,format("%s !ERROR %s opening msgbase: %s"
,list_array[l].name, msgbase.error, list_array[l].sub)); ,list.name, msgbase.error, list.sub));
continue; continue;
} }
list_array[l].msgbase_file = msgbase.file; list.msgbase_file = msgbase.file;
/* Create the user list file if it doesn't exist */ /* Create the user list file if it doesn't exist */
var user_fname = list_array[l].msgbase_file + user_list_ext; var user_fname = list.msgbase_file + user_list_ext;
if(!file_exists(user_fname)) if(!file_exists(user_fname))
file_touch(user_fname); file_touch(user_fname);
} }
...@@ -69,14 +72,14 @@ if(this.recipient_list_filename!=undefined) { ...@@ -69,14 +72,14 @@ if(this.recipient_list_filename!=undefined) {
var error_file = new File(processing_error_filename); var error_file = new File(processing_error_filename);
if(!error_file.open("w")) { if(!error_file.open("w")) {
log(LOG_ERR,format("!ERROR %s opening processing error file: %s" log(LOG_ERR,format("!ERROR %d opening processing error file: %s"
,error_file.error, processing_error_filename)); ,error_file.error, processing_error_filename));
exit(); exit();
} }
var rcptlst_file = new File(recipient_list_filename); var rcptlst_file = new File(recipient_list_filename);
if(!rcptlst_file.open("r")) { if(!rcptlst_file.open("r")) {
error_file.writeln(log(LOG_ERR,format("!ERROR %s opening recipient list: %s" error_file.writeln(log(LOG_ERR,format("!ERROR %d opening recipient list: %s"
,rcptlst_file.error, recipient_list_filename))); ,rcptlst_file.error, recipient_list_filename)));
exit(); exit();
} }
...@@ -85,7 +88,7 @@ if(this.recipient_list_filename!=undefined) { ...@@ -85,7 +88,7 @@ if(this.recipient_list_filename!=undefined) {
var msgtxt_file = new File(message_text_filename); var msgtxt_file = new File(message_text_filename);
if(!msgtxt_file.open("r")) { if(!msgtxt_file.open("r")) {
error_file.writeln(log(LOG_ERR,format("!ERROR %s opening message text: %s" error_file.writeln(log(LOG_ERR,format("!ERROR %d opening message text: %s"
,msgtxt_file.error, message_text_filename))); ,msgtxt_file.error, message_text_filename)));
exit(); exit();
} }
...@@ -123,7 +126,7 @@ if(this.recipient_list_filename!=undefined) { ...@@ -123,7 +126,7 @@ if(this.recipient_list_filename!=undefined) {
var response = process_control_msg(body); var response = process_control_msg(body);
var resp_hdr = {}; var resp_hdr = {};
resp_hdr.subject = "Synchronet ListServer Results"; resp_hdr.subject = listserver_name + " Response";
resp_hdr.to = header.from; resp_hdr.to = header.from;
resp_hdr.to_net_addr = header.from_net_addr; resp_hdr.to_net_addr = header.from_net_addr;
resp_hdr.to_net_type = NET_INTERNET; resp_hdr.to_net_type = NET_INTERNET;
...@@ -147,20 +150,21 @@ if(this.recipient_list_filename!=undefined) { ...@@ -147,20 +150,21 @@ if(this.recipient_list_filename!=undefined) {
for(r=0;r<rcpt_list.length;r++) { for(r=0;r<rcpt_list.length;r++) {
var l; var l;
for(l=0;l<list_array.length;l++) { for(l=0;l<list_array.length;l++) {
var list = list_array[l];
/** DEBUG /** DEBUG
for(var p in list_array[l]) for(var p in list)
log("list_array["+l+"]."+p+" = "+list_array[l][p]); log("list_array["+l+"]."+p+" = "+list[p]);
**/ **/
if(rcpt_list[r].Recipient.toLowerCase()==list_array[l].address.toLowerCase() if(rcpt_list[r].Recipient.toLowerCase()==list.address.toLowerCase()
&& !list_array[l].disabled && !list.disabled
&& !list_array[l].readonly) && !list.readonly)
break; break;
} }
if(l<list_array.length) { /* match found */ if(l<list_array.length) { /* match found */
log(LOG_INFO,format("ListServer Contribution message from %s to %s: %s" log(LOG_INFO,format("ListServer Contribution message from %s to %s: %s"
,header.from, rcpt_list[r].Recipient, header.subject)); ,header.from, rcpt_list[r].Recipient, header.subject));
if(!process_contribution(header, body, list_array[l])) if(!process_contribution(header, body, list))
break; break;
} }
} }
...@@ -175,21 +179,21 @@ for(var l in list_array) { ...@@ -175,21 +179,21 @@ for(var l in list_array) {
break; break;
} }
if(list_array[l].disabled) var list = list_array[l];
continue;
list_name = list_array[l].name; if(list.disabled)
continue;
msgbase = new MsgBase(list_array[l].sub); msgbase = new MsgBase(list.sub);
if(msgbase.open()==false) { if(msgbase.open()==false) {
log(LOG_ERR,format("%s !ERROR %s opening msgbase: %s" log(LOG_ERR,format("%s !ERROR %s opening msgbase: %s"
,list_name, msgbase.error, list_array[l].sub)); ,list.name, msgbase.error, list.sub));
delete msgbase; delete msgbase;
continue; continue;
} }
/* Get subscriber list */ /* Get subscriber list */
var user_list = get_user_list(list_array[l]); var user_list = get_user_list(list);
if(!user_list.length) { if(!user_list.length) {
delete msgbase; delete msgbase;
continue; continue;
...@@ -197,18 +201,18 @@ for(var l in list_array) { ...@@ -197,18 +201,18 @@ for(var l in list_array) {
/*** /***
if(!user_list.length) { if(!user_list.length) {
log(LOG_NOTICE,"No subscribers to list: " + list_name); log(LOG_NOTICE,"No subscribers to list: " + list.name);
delete msgbase; delete msgbase;
continue; continue;
} }
***/ ***/
/* Get export message pointer */ /* Get export message pointer */
ptr_fname = list_array[l].msgbase_file + ".list.ptr"; ptr_fname = list.msgbase_file + ".list.ptr";
ptr_file = new File(ptr_fname); ptr_file = new File(ptr_fname);
if(!ptr_file.open("w+")) { if(!ptr_file.open("w+")) {
log(LOG_ERR,format("%s !ERROR %s opening/creating file: %s" log(LOG_ERR,format("%s !ERROR %d opening/creating file: %s"
,list_name, ptr_file.error, ptr_fname)); ,list.name, ptr_file.error, ptr_fname));
delete msgbase; delete msgbase;
continue; continue;
} }
...@@ -224,25 +228,24 @@ for(var l in list_array) { ...@@ -224,25 +228,24 @@ for(var l in list_array) {
for(;ptr<=last_msg && !js.terminated; ptr++) { for(;ptr<=last_msg && !js.terminated; ptr++) {
hdr = msgbase.get_msg_header( hdr = msgbase.get_msg_header(
/* retrieve by offset? */ false, /* retrieve by offset? */ false,
/* message number */ ptr, /* message number */ ptr
/* regenerate msg-id? */ false
); );
if(hdr == null) { if(hdr == null) {
/** /**
log(LOG_WARNING,format("%s !ERROR %s getting msg header #%lu" log(LOG_WARNING,format("%s !ERROR %s getting msg header #%lu"
,list_name, msgbase.error, ptr)); ,list.name, msgbase.error, ptr));
**/ **/
continue; continue;
} }
if(hdr.attr&(MSG_DELETE|MSG_PRIVATE)) { /* marked for deletion */ if(hdr.attr&(MSG_DELETE|MSG_PRIVATE)) { /* marked for deletion */
log(LOG_NOTICE,format("%s Skipping %s message #%lu from %s: %s" log(LOG_NOTICE,format("%s Skipping %s message #%lu from %s: %s"
,list_name, hdr.attr&MSG_DELETE ? "deleted":"private" ,list.name, hdr.attr&MSG_DELETE ? "deleted":"private"
,ptr, hdr.from, hdr.subject)); ,ptr, hdr.from, hdr.subject));
continue; continue;
} }
if(hdr.attr&MSG_MODERATED && !(hdr.attr&MSG_VALIDATED)) { if(hdr.attr&MSG_MODERATED && !(hdr.attr&MSG_VALIDATED)) {
log(LOG_NOTICE,format("%s Stopping at unvalidated moderated message #%lu from %s: %s" log(LOG_NOTICE,format("%s Stopping at unvalidated moderated message #%lu from %s: %s"
,list_name, ptr, hdr.from, hdr.subject)); ,list.name, ptr, hdr.from, hdr.subject));
ptr--; ptr--;
break; break;
} }
...@@ -256,7 +259,7 @@ for(var l in list_array) { ...@@ -256,7 +259,7 @@ for(var l in list_array) {
); );
if(body == null) { if(body == null) {
log(LOG_ERR,format("%s !ERROR %s reading text of message #%lu" log(LOG_ERR,format("%s !ERROR %s reading text of message #%lu"
,list_name, msgbase.error, ptr)); ,list.name, msgbase.error, ptr));
continue; continue;
} }
...@@ -267,7 +270,7 @@ for(var l in list_array) { ...@@ -267,7 +270,7 @@ for(var l in list_array) {
if(user_list[u].disabled || !user_list[u].address) if(user_list[u].disabled || !user_list[u].address)
continue; continue;
log(LOG_DEBUG,format("%s Enqueing message #%lu for %s <%s>" log(LOG_DEBUG,format("%s Enqueing message #%lu for %s <%s>"
,list_name, ptr, user_list[u].name, user_list[u].address)); ,list.name, ptr, user_list[u].name, user_list[u].address));
rcpt_list.push( { to: user_list[u].name, rcpt_list.push( { to: user_list[u].name,
to_net_addr: user_list[u].address, to_net_addr: user_list[u].address,
to_net_type: NET_INTERNET to_net_type: NET_INTERNET
...@@ -278,18 +281,18 @@ for(var l in list_array) { ...@@ -278,18 +281,18 @@ for(var l in list_array) {
break; break;
} }
if(rcpt_list.length < 1) { if(rcpt_list.length < 1) {
log(LOG_NOTICE,format("%s No active subscriptions", list_name)); log(LOG_NOTICE,format("%s No active subscriptions", list.name));
continue; continue;
} }
log(LOG_INFO,format("%s Sending message #%lu from %s to %lu recipients: %s" log(LOG_INFO,format("%s Sending message #%lu from %s to %lu recipients: %s"
,list_name, ptr, hdr.from, rcpt_list.length, hdr.subject)); ,list.name, ptr, hdr.from, rcpt_list.length, hdr.subject));
hdr.replyto_net_type = NET_INTERNET; hdr.replyto_net_type = NET_INTERNET;
hdr.replyto_net_addr = list_array[l].address; hdr.replyto_net_addr = list.address;
if(!mailbase.save_msg(hdr,body,rcpt_list)) if(!mailbase.save_msg(hdr,body,rcpt_list))
log(LOG_ERR,format("%s !ERROR %s saving mail message" log(LOG_ERR,format("%s !ERROR %s saving mail message"
,list_name, mailbase.error)); ,list.name, mailbase.error));
} }
if(ptr > last_msg) if(ptr > last_msg)
...@@ -311,7 +314,7 @@ function process_control_msg(cmd_list) ...@@ -311,7 +314,7 @@ function process_control_msg(cmd_list)
{ {
var response = { body: new Array(), subject: "" }; var response = { body: new Array(), subject: "" };
response.body.push("Synchronet ListServer " +REVISION+ " Response:\r\n"); response.body.push(listserver_name + " " +REVISION+ " Response:\r\n");
for(var c in cmd_list) { for(var c in cmd_list) {
var cmd=cmd_list[c]; var cmd=cmd_list[c];
...@@ -321,19 +324,22 @@ function process_control_msg(cmd_list) ...@@ -321,19 +324,22 @@ function process_control_msg(cmd_list)
switch(token[0].toLowerCase()) { switch(token[0].toLowerCase()) {
case "lists": case "lists":
response.body.push("List of lists:"); response.body.push("List of lists:");
for(var l in list_array) for(var l in list_array) {
if(!list_array[l].disabled) var list = list_array[l];
response.body.push("\t"+list_array[l].name.toUpperCase() if(!list.disabled)
+"\t\t"+list_array[l].description); response.body.push("\t"+list.name.toUpperCase()
+"\t\t"+list.description);
}
break; break;
case "subscribe": case "subscribe":
case "unsubscribe": case "unsubscribe":
for(var l in list_array) { for(var l in list_array) {
if(list_array[l].disabled || list_array[l].closed) var list = list_array[l];
if(list.disabled || list.closed)
continue; continue;
if(list_array[l].name.toLowerCase()==token[1].toLowerCase() if(list.name.toLowerCase()==token[1].toLowerCase()
|| list_array[l].address.toLowerCase()==token[1].toLowerCase()) { || list.address.toLowerCase()==token[1].toLowerCase()) {
response.body.push(subscription_control(token[0], list_array[l], token[2])); response.body.push(subscription_control(token[0], list, token[2]));
return(response); return(response);
} }
} }
...@@ -357,16 +363,29 @@ function process_control_msg(cmd_list) ...@@ -357,16 +363,29 @@ function process_control_msg(cmd_list)
return(response); return(response);
} }
function get_user_list(list) function open_user_list(list, mode)
{ {
var user_list = new Array();
var user_fname = list.msgbase_file + user_list_ext; var user_fname = list.msgbase_file + user_list_ext;
var user_file = new File(user_fname); var user_file = new File(user_fname);
if(!user_file.open("r")) { if(!user_file.open(mode)) {
log(LOG_ERR,format("%s !ERROR %d opening file: %s" log(LOG_ERR,format("%s !ERROR %d opening file: %s"
,list.name, user_file.error, user_fname)); ,list.name, user_file.error, user_fname));
} else { return(null);
user_list = user_file.iniGetAllObjects(); }
return(user_file);
}
function read_user_list(user_file)
{
return user_file.iniGetAllObjects("address");
}
function get_user_list(list)
{
var user_list = new Array();
if((user_file = open_user_list("r")) != null) {
user_list = read_user_list(user_file);
user_file.close(); user_file.close();
} }
return user_list; return user_list;
...@@ -393,9 +412,10 @@ function write_user_list(user_list, user_file) ...@@ -393,9 +412,10 @@ function write_user_list(user_list, user_file)
user_file.rewind(); user_file.rewind();
user_file.length = 0; user_file.length = 0;
for(var u in user_list) { for(var u in user_list) {
user_file.writeln("[" + user_list[u].name + "]"); user_file.writeln("[" + user_list[u].address + "]");
for(var p in user_list[u]) for(var p in user_list[u])
user_file.writeln(p + " = " + user_list[u][p]); if(p!="address")
user_file.writeln(format("%-25s",p) + " = " + user_list[u][p]);
user_file.writeln(); user_file.writeln();
} }
} }
...@@ -409,13 +429,10 @@ function subscription_control(cmd, list, address) ...@@ -409,13 +429,10 @@ function subscription_control(cmd, list, address)
,list.name,cmd,address)); ,list.name,cmd,address));
/* Get subscriber list */ /* Get subscriber list */
var user_fname = list.msgbase_file + user_list_ext; if((user_file=open_user_list(list,"r+"))==null)
var user_file = new File(user_fname); return log(LOG_ERR,format("%s !ERROR opening subscriber list",list.name));
if(!user_file.open("r+"))
return log(LOG_ERR,format("%s !ERROR %d opening file: %s"
,list.name, user_file.error, user_fname));
user_list = user_file.iniGetAllObjects(); user_list = read_user_list(user_file);
switch(cmd.toLowerCase()) { switch(cmd.toLowerCase()) {
case "unsubscribe": case "unsubscribe":
...@@ -436,7 +453,7 @@ function subscription_control(cmd, list, address) ...@@ -436,7 +453,7 @@ function subscription_control(cmd, list, address)
,address: address ,address: address
,created: system.timestr(now) ,created: system.timestr(now)
,last_activity: system.timestr(now) ,last_activity: system.timestr(now)
,last_activity_time: format("%08lxh",now) ,last_activity_time: format("%08lx",now)
}); });
write_user_list(user_list, user_file); write_user_list(user_list, user_file);
return log(LOG_INFO,format("%s %s subscription successful" return log(LOG_INFO,format("%s %s subscription successful"
...@@ -456,6 +473,10 @@ function process_contribution(header, body, list) ...@@ -456,6 +473,10 @@ function process_contribution(header, body, list)
if(find_user(user_list, sender_address)==-1) { if(find_user(user_list, sender_address)==-1) {
error_file.writeln(log(LOG_WARNING,format("%s !ERROR %s is not a subscriber" error_file.writeln(log(LOG_WARNING,format("%s !ERROR %s is not a subscriber"
,list.name, sender_address))); ,list.name, sender_address)));
// error_file.writeln();
// error_file.writeln("To subscribe to this list, send an e-mail to "
// + listserver_address);
// error_file.writeln("with \"subscribe " + list.name + "\" in the message body.");
return(false); return(false);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment