Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

msgslib.ssjs 5.17 KB
Newer Older
1
/* $Id: msgslib.ssjs,v 1.62 2018/12/21 02:32:03 rswindell Exp $ */
2

3
load("sbbsdefs.js");
4 5
load('../web/lib/template.ssjs');
load(msgsconfig);
6

7
// Use guest user if the current user is super-duper
8
if(user.number==0 && this.login!=undefined)
9 10 11
	login("Guest");	// requires v3.12b (websrvr 1.263 or later)
if(user.number==0) {
    error("Message Group access requires login");
12
	exit();
13
}
14

15
/* Flags for clean_msg_headers() */
16 17 18 19 20 21
var CLEAN_MSG_REPLY	=	(1<<0);

/* Gets for get_message_offsets() */
var GET_ALL_MESSAGES =	0;
var GET_MY_MESSAGES	 =	1;
var GET_MY_UNREAD_MESSAGES = 2;
22

23 24 25 26 27 28 29 30 31 32
http_reply.header["Pragma"]="no-cache";
http_reply.header["Expires"]="0";

var grp=http_request.query.msg_grp;
if(grp=='' || grp==null)
	grp=undefined;
var sub=http_request.query.msg_sub;
if(grp=='E-Mail')
	sub='mail';
var s=-1;
33
if(sub == 'mail' || msg_area.sub[sub] != undefined)
34 35 36 37 38 39 40 41 42 43 44 45
	var msgbase = new MsgBase(sub);
var message=http_request.query.message;
var m=parseInt(http_request.query.message);
var path=http_request.virtual_path;
var offset=parseInt(http_request.query.offset);
if (http_request.query.offset == undefined)  {
	offset=0;
}
var hdr=null;
var title=null;
var body=null;
var err=null;
46

47
function get_message_offsets(type)
48
{
49 50 51 52
	offsets=[];//new Array; // is this global or something?
//	var last_offset;
//	var idx;
//	var hdr;
53

54
//	for(last_offset=0; (idx=msgbase.get_msg_index(true,last_offset)) != null;last_offset++) {
55
	var total_msgs = msgbase.total_msgs;
56
	for (var last_offset = 0; last_offset < total_msgs; last_offset++) {
57 58
		var idx = msgbase.get_msg_index(true, last_offset);
		if (typeof idx === 'undefined' || idx === null) continue;
59
		if(idx.attr&MSG_DELETE)
60
			continue;
61
		if(sub=='mail' && idx.to!=user.number)
62
			continue;
63 64 65 66 67 68 69 70
		if(type==GET_MY_MESSAGES || type==GET_MY_UNREAD_MESSAGES) {
			if(!idx_to_user(idx))
				continue;
		}
		if(type==GET_MY_UNREAD_MESSAGES) {
			if(idx.attr&MSG_READ)
				continue;
		}
deuce's avatar
deuce committed
71
		if(idx.attr&MSG_MODERATED && !(idx.attr&MSG_VALIDATED))
72 73 74 75 76 77
			break; // pourquoi?
		// msg=new Array;
		// msg.idx=idx;
		// msg.offset=last_offset;
		// offsets.push(msg);
		offsets.push({ idx : idx, offset : last_offset });
78 79 80 81
	}
	return(offsets);
}

82 83 84 85 86
function msgs_done()
{
	if(msgbase!=undefined)
		msgbase.close();
}
87 88 89 90 91 92

function find_np_message(offset,next)
{
	/* "Next" actually means the one before this one as msgs reverses everything */
	var step=-1;
	var	idx;
93
	var last_offset;
94 95 96

	if(!next)
		step=1;
97
	for(last_offset=parseInt(offset)+step;last_offset>=0 && (idx=msgbase.get_msg_index(true,last_offset))!=null;last_offset+=step) {
98
		if(idx.attr&MSG_DELETE)
99
			continue;
deuce's avatar
deuce committed
100
		if(idx.attr&MSG_PRIVATE && !idx_to_user(idx))
101
			continue;
deuce's avatar
deuce committed
102 103 104 105 106 107
		if(idx.attr&MSG_MODERATED && !(idx.attr&MSG_VALIDATED)) {
			if(step==1)
				break;
			else
				continue;
		}
108 109
		if(sub!='mail')
			return(idx.number);
deuce's avatar
deuce committed
110
		if(!idx_to_user(idx))
111 112 113 114 115 116 117 118
			continue;
		return(idx.number);
	}
	return(undefined);
}

function get_msg_offset(number)
{
deuce's avatar
deuce committed
119
	var idx;
120
	var last_offset;
deuce's avatar
deuce committed
121

122 123 124
	idx=msgbase.get_msg_index(false,number);
	if(idx!=undefined)
		return(idx.offset);
125 126
	return(undefined);
}
127 128 129 130 131 132

function can_delete(mnum)
{
	if(sub=='mail' && ((idx=msgbase.get_msg_index(false,mnum))==null || idx.to!=user.number))
		return(false);
	if(sub!='mail' && !msg_area.sub[sub].is_operator) {
133
		if(!(msg_area.sub[sub].settings&SUB_DEL))
134 135 136 137 138 139 140 141 142 143
			return(false);
		if(msg_area.sub[sub].settings&SUB_DELLAST) {
			if(msgbase.last_msg!=mnum)
				return(false);
		}
		if((hdr=msgbase.get_msg_header(false,mnum))==null || hdr.from_ext!=user.number)
			return(false);
	}
	return(true);
}
144 145 146

function clean_msg_headers(hdr,flags)
{
147 148 149 150 151 152 153 154 155 156 157
	if (hdr !== null) {

		if(hdr.subject=='')
			hdr.subject="-- No Subject --";
		if(hdr.attr&MSG_ANONYMOUS) {
			if((!(flags&CLEAN_MSG_REPLY))) {
				if(user.security.level>=90)
					hdr.from='Anonymous ('+hdr.from+')';
				else
					hdr.from="Anonymous";
			}
deuce's avatar
deuce committed
158
			else
159
				hdr.from="All";
deuce's avatar
deuce committed
160
		}
161

162
	}
deuce's avatar
deuce committed
163

164 165
	return(hdr);
}
deuce's avatar
deuce committed
166 167 168

function idx_to_user(fromidx)
{
rswindell's avatar
rswindell committed
169
	var istouser=false;
deuce's avatar
deuce committed
170 171 172 173 174 175 176 177 178 179 180 181

	if(sub=='mail') {
		if(fromidx.to==user.number)
			istouser=true;
	}
	else {
		var aliascrc=crc16_calc(user.alias.toLowerCase());
		var namecrc=crc16_calc(user.name.toLowerCase());
		var sysopcrc=crc16_calc((user.number==1?'sysop':user.name.toLowerCase()));
		if(fromidx.to==aliascrc || fromidx.to==namecrc || fromidx.to==sysopcrc) {
			/* Could be to this user */
			var fromhdr=msgbase.get_msg_header(true,fromidx.offset);
rswindell's avatar
rswindell committed
182 183
			if(!fromhdr)
				return(false);
deuce's avatar
deuce committed
184 185 186 187 188 189 190 191 192 193
			if(user.alias.toLowerCase()==fromhdr.to.toLowerCase())
				istouser=true;
			else if(user.name.toLowerCase()==fromhdr.to.toLowerCase())
				istouser=true;
			else if(user.number==1 && fromhdr.to.toLowerCase()=='sysop' && fromhdr.from_net_type==0)
				istouser=true;
		}
	}
	return(istouser);
}
194 195

function make_links(str) {
196
	str=str.replace(/(?:http|https|ftp|telnet|gopher|irc|news):\/\/[\w\-\.]+\.[a-zA-Z]+(?::[\w-+_%]*)?(?:\/(?:[\w\-._\?\,\/\\\+&;:%\$#\=~\*]*))?/gi,function(str) {
197
//					 | Protocol                                    |Hostname  |TLD     | Port        | Path									  |
deuce's avatar
deuce committed
198 199 200
		var text=str;
		var uri=str;
		var extra='';
201
		m=str.match(/^([\x00-\xff]*?)((?:&gt;|[\r\n,.\)])+)$/);
deuce's avatar
deuce committed
202 203 204
		if(m!=null) {
			text=m[1];
			uri=m[1];
205
			extra=m[2]+extra;
deuce's avatar
deuce committed
206 207 208
		}
		uri=uri.replace(/[\r\n]/g,'');
		var ret='<a href="'+uri+'" target="_blank">'+text+'</a>'+extra;
209
		return(ret);}
runemaster's avatar
runemaster committed
210
	);
deuce's avatar
deuce committed
211
	return(str);
212
}