execfunc.cpp 12.2 KB
Newer Older
1 2 3 4
/* execfunc.cpp */

/* Hi-level command shell/module routines (functions) */

5
/* $Id: execfunc.cpp,v 1.46 2020/05/14 07:49:59 rswindell Exp $ */
6 7 8 9 10

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"
#include "cmdshell.h"

int sbbs_t::exec_function(csi_t *csi)
{
43
	char	str[256];
44
	char 	tmp[512];
45
	uchar*	p;
46
	int		s;
47 48 49
	uint 	i,j,k;
	long	l;
	node_t	node;
50
	struct	tm tm;
51
	uint8_t	cmd = *(csi->ip++);
52

53
	switch(cmd) {
54 55 56 57 58 59 60 61 62 63 64 65

		case CS_PRINTFILE_STR:
			printfile(csi->str,P_NOATCODES);
			return(0);

	/********************************/
	/* General Main Menu Type Stuff */
	/********************************/
		case CS_AUTO_MESSAGE:
			automsg();
			return(0);
		case CS_MINUTE_BANK:
66
			time_bank();
67 68
			return(0);
		case CS_CHAT_SECTION:
69
			chatsection();
70 71 72 73 74 75 76 77 78 79
			return(0);
		case CS_USER_DEFAULTS:
			maindflts(&useron);
			if(!(useron.rest&FLAG('G')))    /* not guest */
				getuserdat(&cfg,&useron);
			return(0);
		case CS_TEXT_FILE_SECTION:
			text_sec();
			return(0);
		case CS_INFO_SYSTEM:   /* System information */
80
			sys_info();
81 82 83 84 85 86 87 88 89 90 91 92 93
			return(0);
		case CS_INFO_SUBBOARD:	 /* Sub-board information */
			if(!usrgrps) return(0);
			subinfo(usrsub[curgrp][cursub[curgrp]]);
			return(0);
		case CS_INFO_DIRECTORY:   /* Sub-board information */
			if(!usrlibs) return(0);
			dirinfo(usrdir[curlib][curdir[curlib]]);
			return(0);
		case CS_INFO_VERSION:	/* Version */
			ver();
			return(0);
		case CS_INFO_USER:	 /* User's statistics */
94
			user_info();
95 96
			return(0);
		case CS_INFO_XFER_POLICY:
97
			xfer_policy();
98 99 100 101 102 103 104 105 106 107 108 109
			return(0);
		case CS_XTRN_EXEC:
			csi->logic=LOGIC_TRUE;
			for(i=0;i<cfg.total_xtrns;i++)
				if(!stricmp(cfg.xtrn[i]->code,csi->str))
					break;
			if(i<cfg.total_xtrns)
				exec_xtrn(i);
			else
				csi->logic=LOGIC_FALSE;
			return(0);
		case CS_XTRN_SECTION:
110
			xtrn_sec();
111 112
			return(0);
		case CS_LOGOFF:
113
			if(text[LogOffQ][0]==0 || !noyes(text[LogOffQ])) {
114 115 116
				if(cfg.logoff_mod[0])
					exec_bin(cfg.logoff_mod,csi);
				user_event(EVENT_LOGOFF);
117
				menu("logoff");
118
				SYNC;
119 120
				hangup(); 
			}
121 122 123 124 125 126
			return(0);
		case CS_LOGOFF_FAST:
			SYNC;
			hangup();
			return(0);
		case CS_NODELIST_ALL:
127
			nodelist();
128 129 130 131 132 133 134 135 136 137 138 139 140 141
			return(0);
		case CS_NODELIST_USERS:
			whos_online(true);
			return(0);
		case CS_USERLIST_SUB:
			userlist(UL_SUB);
			return(0);
		case CS_USERLIST_DIR:
			userlist(UL_DIR);
			return(0);
		case CS_USERLIST_ALL:
			userlist(UL_ALL);
			return(0);
		case CS_USERLIST_LOGONS:
142
			logonlist();
143 144
			return(0);
		case CS_PAGE_SYSOP:
145
			csi->logic=sysop_page() ? LOGIC_TRUE:LOGIC_FALSE;
146 147
			return(0);
		case CS_PAGE_GURU:
148
			csi->logic=guru_page() ? LOGIC_TRUE:LOGIC_FALSE;
149
			return(0);
rswindell's avatar
rswindell committed
150
		case CS_SPY:
151
			csi->logic=spy(atoi(csi->str)) ? LOGIC_TRUE:LOGIC_FALSE;
rswindell's avatar
rswindell committed
152
			return(0);
153 154 155 156 157 158 159 160 161 162 163
		case CS_PRIVATE_CHAT:
			privchat();
			return(0);
		case CS_PRIVATE_MESSAGE:
			nodemsg();
			return(0);

	/*******************/
	/* Sysop Functions */
	/*******************/
		case CS_USER_EDIT:
164
			useredit(csi->str[0] ? finduser(csi->str) : 0);
165 166 167 168 169 170 171 172 173 174 175
			return(0);


	/******************/
	/* Mail Functions */
	/******************/

		case CS_MAIL_READ:	 /* Read E-mail */
			readmail(useron.number,MAIL_YOUR);
			return(0);
		case CS_MAIL_READ_SENT: 	  /* Kill/read sent mail */
176
			readmail(useron.number,MAIL_SENT);
177 178 179 180 181 182 183
			return(0);
		case CS_MAIL_READ_ALL:
			readmail(useron.number,MAIL_ALL);
			return(0);
		case CS_MAIL_SEND:		 /* Send E-mail */
			if(strchr(csi->str,'@')) {
				i=1;
184
				netmail(csi->str); 
185
			}
186
			else if((i=finduser(csi->str))!=0 
187
				|| (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str))!=0))
188
				email(i);
189 190 191 192
			csi->logic=!i;
			return(0);
		case CS_MAIL_SEND_FEEDBACK: 	  /* Feedback */
			if((i=finduser(csi->str))!=0)
193
				email(i,text[ReFeedback]);
194 195 196 197
			csi->logic=!i;
			return(0);
		case CS_MAIL_SEND_NETMAIL:
		case CS_MAIL_SEND_NETFILE:
198
		{
199
			bputs(text[EnterNetMailAddress]);
200
			csi->logic=LOGIC_FALSE;
201
			if(getstr(str,60,K_LINE)) {
202
				if(netmail(str, NULL, cmd == CS_MAIL_SEND_NETFILE ? WM_FILE : WM_NONE)) {
203 204
					csi->logic=LOGIC_TRUE; 
				}
205
			}
206
			return(0);
207
		}
208 209 210
		case CS_MAIL_SEND_FILE:   /* Upload Attached File to E-mail */
			if(strchr(csi->str,'@')) {
				i=1;
211
				netmail(csi->str,NULL,WM_FILE); 
212
			}
213
			else if((i=finduser(csi->str))!=0
214
				|| (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str))!=0))
215
				email(i,NULL,NULL,WM_FILE);
216 217 218 219
			csi->logic=!i;
			return(0);
		case CS_MAIL_SEND_BULK:
			if(csi->str[0])
220
				p=arstr(NULL,csi->str, &cfg,NULL);
221
			else
222
				p=NULL;
223
			bulkmail(p);
224
			free(p);
225 226 227 228 229 230 231 232 233 234 235
			return(0);

		case CS_INC_MAIN_CMDS:
			main_cmds++;
			return(0);

		case CS_INC_FILE_CMDS:
			xfer_cmds++;
			return(0);

		case CS_SYSTEM_LOG:                 /* System log */
236
			if(!chksyspass())
237
				return(0);
238
			if(localtime_r(&now,&tm)==NULL)
239
				return(0);
240
			sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log", cfg.logs_dir
241
				,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year));
242 243 244
			printfile(str,0);
			return(0);
		case CS_SYSTEM_YLOG:                /* Yesterday's log */
245
			if(!chksyspass())
246 247
				return(0);
			now-=(ulong)60L*24L*60L;
248
			if(localtime_r(&now,&tm)==NULL)
249
				return(0);
250
			sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg.logs_dir
251
				,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year));
252 253 254
			printfile(str,0);
			return(0);
		case CS_SYSTEM_STATS:               /* System Statistics */
255
			sys_stats();
256 257
			return(0);
		case CS_NODE_STATS:              /* Node Statistics */
258
			node_stats(atoi(csi->str));
259 260
			return(0);
		case CS_CHANGE_USER:                 /* Change to another user */
261
			change_user();
262 263 264 265
			return(0);
		case CS_SHOW_MEM:
			return(0);
		case CS_ERROR_LOG:
266
			sprintf(str,"%serror.log", cfg.logs_dir);
267 268 269
			if(fexist(str)) {
				bputs(text[ErrorLogHdr]);
				printfile(str,0);
270
				if(text[DeleteErrorLogQ][0] && !noyes(text[DeleteErrorLogQ]))
271 272
					remove(str); 
			}
273
			else
274
				bprintf(text[FileDoesNotExist],str);
275 276 277
			for(i=1;i<=cfg.sys_nodes;i++) {
				getnodedat(i,&node,0);
				if(node.errors)
278 279
					break; 
			}
280
			if(i<=cfg.sys_nodes || criterrs) {
281
				if(text[ClearErrCounter][0]==0 || !noyes(text[ClearErrCounter])) {
282
					for(i=1;i<=cfg.sys_nodes;i++) {
283 284 285 286 287 288 289 290
						if(getnodedat(i,&node,true)==0) {
							node.errors=0;
							putnodedat(i,&node); 
						}
					criterrs=0; 
					} 
				}
			}
291 292 293 294 295 296 297
			return(0);
		case CS_ANSI_CAPTURE:           /* Capture ANSI codes */
			sys_status^=SS_ANSCAP;
			bprintf(text[ANSICaptureIsNow]
				,sys_status&SS_ANSCAP ? text[ON] : text[OFF]);
			return(0);
		case CS_LIST_TEXT_FILE:              /* View ASCII/ANSI/Ctrl-A file */
298
			if(!chksyspass())
299 300
				return(0);
			bputs(text[Filename]);
301
			if(getstr(str,60,0))
302 303 304
				printfile(str,0);
			return(0);
		case CS_EDIT_TEXT_FILE:              /* Edit ASCII/Ctrl-A file */
305
			if(!chksyspass())
306 307
				return(0);
			bputs(text[Filename]);
308
			if(getstr(str,60,0))
309 310 311
				editfile(str);
			return(0);
		case CS_GURU_LOG:
312
			sprintf(str,"%sguru.log", cfg.logs_dir);
313 314 315
			if(fexist(str)) {
				printfile(str,0);
				CRLF;
316
				if(text[DeleteGuruLogQ][0] && !noyes(text[DeleteGuruLogQ]))
317 318
					remove(str); 
			}
319 320 321 322 323 324 325 326 327 328 329 330 331
			return(0);
		case CS_FILE_SET_ALT_PATH:
			altul=atoi(csi->str);
			if(altul>cfg.altpaths)
				altul=0;
			bprintf(text[AltULPathIsNow],altul ? cfg.altpath[altul-1] : text[OFF]);
			return(0);
		case CS_FILE_RESORT_DIRECTORY:
			for(i=1;i<=cfg.sys_nodes;i++)
				if(i!=cfg.node_num) {
					getnodedat(i,&node,0);
					if(node.status==NODE_INUSE
						|| node.status==NODE_QUIET)
332 333
						break; 
				}
334 335 336

			if(i<=cfg.sys_nodes) {
				bputs(text[ResortWarning]);
337 338
				return(0); 
			}
339 340 341 342 343

			if(!stricmp(csi->str,"ALL")) {     /* all libraries */
				for(i=0;i<usrlibs;i++)
					for(j=0;j<usrdirs[i];j++)
						resort(usrdir[i][j]);
344 345
				return(0); 
			}
346 347 348
			if(!stricmp(csi->str,"LIB")) {     /* current library */
				for(i=0;i<usrdirs[curlib];i++)
					resort(usrdir[curlib][i]);
349 350
				return(0); 
			}
351 352 353 354 355 356
			resort(usrdir[curlib][curdir[curlib]]);
			return(0);

		case CS_FILE_GET:
			if(!fexist(csi->str)) {
				bputs(text[FileNotFound]);
357 358
				return(0); 
			}
359
			if(!chksyspass())
360 361 362 363
				return(0);

		case CS_FILE_SEND:

364
			csi->logic=sendfile(csi->str) ? LOGIC_TRUE:LOGIC_FALSE;
365 366 367
			return(0);

		case CS_FILE_PUT:
rswindell's avatar
rswindell committed
368
			csi->logic=LOGIC_FALSE;
369
			if(!chksyspass())
370
				return(0);
371 372

		case CS_FILE_RECEIVE:
373
			csi->logic=recvfile(csi->str) ? LOGIC_TRUE:LOGIC_FALSE;
374 375 376 377 378 379 380 381 382 383 384
			return(0);

		case CS_FILE_UPLOAD_BULK:

			if(!usrlibs) return(0);

			if(!stricmp(csi->str,"ALL")) {     /* all libraries */
				for(i=0;i<usrlibs;i++)
					for(j=0;j<usrdirs[i];j++) {
						if(cfg.lib[i]->offline_dir==usrdir[i][j])
							continue;
385 386 387 388
						if(bulkupload(usrdir[i][j])) return(0); 
					}
				return(0); 
			}
389 390 391 392 393
			if(!stricmp(csi->str,"LIB")) {     /* current library */
				for(i=0;i<usrdirs[curlib];i++) {
					if(cfg.lib[usrlib[curlib]]->offline_dir
						==usrdir[curlib][i])
						continue;
394 395 396 397
					if(bulkupload(usrdir[curlib][i])) return(0); 
				}
				return(0); 
			}
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
			bulkupload(usrdir[curlib][curdir[curlib]]); /* current dir */
			return(0);

		case CS_FILE_FIND_OLD:
		case CS_FILE_FIND_OPEN:
		case CS_FILE_FIND_OFFLINE:
		case CS_FILE_FIND_OLD_UPLOADS:
			if(!usrlibs) return(0);
			if(!getfilespec(tmp))
				return(0);
			padfname(tmp,str);
			k=0;
			bputs("\r\nSearching ");
			if(!stricmp(csi->str,"ALL"))
				bputs("all libraries");
			else if(!stricmp(csi->str,"LIB"))
				bputs("library");
			else
				bputs("directory");
			bputs(" for files ");
			if(*(csi->ip-1)==CS_FILE_FIND_OLD_UPLOADS) {
				l=FI_OLDUL;
420 421
				bprintf("uploaded before %s\r\n",timestr(ns_time)); 
			}
422 423
			else if(*(csi->ip-1)==CS_FILE_FIND_OLD) { /* go by download date */
				l=FI_OLD;
424 425
				bprintf("not downloaded since %s\r\n",timestr(ns_time)); 
			}
426 427
			else if(*(csi->ip-1)==CS_FILE_FIND_OFFLINE) {
				l=FI_OFFLINE;
428 429
				bputs("not online...\r\n"); 
			}
430 431
			else {
				l=FI_CLOSE;
432 433
				bputs("currently open...\r\n"); 
			}
434 435 436 437 438 439 440
			if(!stricmp(csi->str,"ALL")) {
				for(i=0;i<usrlibs;i++)
					for(j=0;j<usrdirs[i];j++) {
						if(cfg.lib[i]->offline_dir==usrdir[i][j])
							continue;
						if((s=listfileinfo(usrdir[i][j],str,(char)l))==-1)
							return(0);
441 442 443
						else k+=s; 
					} 
			}
444 445 446 447 448 449
			else if(!stricmp(csi->str,"LIB")) {
				for(i=0;i<usrdirs[curlib];i++) {
					if(cfg.lib[usrlib[curlib]]->offline_dir==usrdir[curlib][i])
							continue;
					if((s=listfileinfo(usrdir[curlib][i],str,(char)l))==-1)
						return(0);
450 451 452
					else k+=s; 
				} 
			}
453 454 455 456
			else {
				s=listfileinfo(usrdir[curlib][curdir[curlib]],str,(char)l);
				if(s==-1)
					return(0);
457 458
				k=s; 
			}
459
			if(k>1) {
460 461 462 463
				bprintf(text[NFilesListed],k); 
			}
			return(0); 
	}
464 465 466

	if(*(csi->ip-1)>=CS_MSG_SET_AREA && *(csi->ip-1)<=CS_MSG_UNUSED1) {
		csi->ip--;
467 468
		return(exec_msg(csi)); 
	}
469

470
	if(*(csi->ip-1)>=CS_FILE_SET_AREA && *(csi->ip-1)<=CS_FILE_RECEIVE) {
471
		csi->ip--;
472 473
		return(exec_file(csi)); 
	}
474 475 476 477

	errormsg(WHERE,ERR_CHK,"shell function",*(csi->ip-1));
	return(0);
}