execfunc.cpp 10.8 KB
Newer Older
1 2 3 4 5 6
/* Hi-level command shell/module routines (functions) */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *																			*
 * 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										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * 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)
{
27
	char	str[256];
28
	uchar*	p;
29
	int		s;
30 31 32
	uint 	i,j,k;
	long	l;
	node_t	node;
33
	struct	tm tm;
34
	uint8_t	cmd = *(csi->ip++);
35

36
	switch(cmd) {
37 38 39 40 41 42 43 44 45 46 47 48

		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:
49
			time_bank();
50 51
			return(0);
		case CS_CHAT_SECTION:
52
			chatsection();
53 54 55 56 57 58 59 60 61 62
			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 */
63
			sys_info();
64 65 66 67 68 69 70 71 72 73 74 75 76
			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 */
77
			user_info();
78 79
			return(0);
		case CS_INFO_XFER_POLICY:
80
			xfer_policy();
81 82 83 84 85 86 87 88 89 90 91 92
			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:
93
			xtrn_sec();
94 95
			return(0);
		case CS_LOGOFF:
96
			if(text[LogOffQ][0]==0 || !noyes(text[LogOffQ])) {
97 98 99
				if(cfg.logoff_mod[0])
					exec_bin(cfg.logoff_mod,csi);
				user_event(EVENT_LOGOFF);
100
				menu("logoff");
101
				SYNC;
102 103
				hangup(); 
			}
104 105 106 107 108 109
			return(0);
		case CS_LOGOFF_FAST:
			SYNC;
			hangup();
			return(0);
		case CS_NODELIST_ALL:
110
			nodelist();
111 112 113 114 115 116 117 118 119 120 121 122 123 124
			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:
125
			logonlist();
126 127
			return(0);
		case CS_PAGE_SYSOP:
128
			csi->logic=sysop_page() ? LOGIC_TRUE:LOGIC_FALSE;
129 130
			return(0);
		case CS_PAGE_GURU:
131
			csi->logic=guru_page() ? LOGIC_TRUE:LOGIC_FALSE;
132
			return(0);
rswindell's avatar
rswindell committed
133
		case CS_SPY:
134
			csi->logic=spy(atoi(csi->str)) ? LOGIC_TRUE:LOGIC_FALSE;
rswindell's avatar
rswindell committed
135
			return(0);
136 137 138 139 140 141 142 143 144 145 146
		case CS_PRIVATE_CHAT:
			privchat();
			return(0);
		case CS_PRIVATE_MESSAGE:
			nodemsg();
			return(0);

	/*******************/
	/* Sysop Functions */
	/*******************/
		case CS_USER_EDIT:
147
			useredit(csi->str[0] ? finduser(csi->str) : 0);
148 149 150 151 152 153 154 155 156 157 158
			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 */
159
			readmail(useron.number,MAIL_SENT);
160 161 162 163 164 165 166
			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;
167
				netmail(csi->str); 
168
			}
169
			else if((i=finduser(csi->str))!=0 
170
				|| (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str))!=0))
171
				email(i);
172 173 174 175
			csi->logic=!i;
			return(0);
		case CS_MAIL_SEND_FEEDBACK: 	  /* Feedback */
			if((i=finduser(csi->str))!=0)
176
				email(i,text[ReFeedback]);
177 178 179 180
			csi->logic=!i;
			return(0);
		case CS_MAIL_SEND_NETMAIL:
		case CS_MAIL_SEND_NETFILE:
181
		{
182
			bputs(text[EnterNetMailAddress]);
183
			csi->logic=LOGIC_FALSE;
184
			if(getstr(str,60,K_LINE)) {
185
				if(netmail(str, NULL, cmd == CS_MAIL_SEND_NETFILE ? WM_FILE : WM_NONE)) {
186 187
					csi->logic=LOGIC_TRUE; 
				}
188
			}
189
			return(0);
190
		}
191 192 193
		case CS_MAIL_SEND_FILE:   /* Upload Attached File to E-mail */
			if(strchr(csi->str,'@')) {
				i=1;
194
				netmail(csi->str,NULL,WM_FILE); 
195
			}
196
			else if((i=finduser(csi->str))!=0
197
				|| (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str))!=0))
198
				email(i,NULL,NULL,WM_FILE);
199 200 201 202
			csi->logic=!i;
			return(0);
		case CS_MAIL_SEND_BULK:
			if(csi->str[0])
203
				p=arstr(NULL,csi->str, &cfg,NULL);
204
			else
205
				p=NULL;
206
			bulkmail(p);
207
			free(p);
208 209 210 211 212 213 214 215 216 217 218
			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 */
219
			if(!chksyspass())
220
				return(0);
221
			if(localtime_r(&now,&tm)==NULL)
222
				return(0);
223
			sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log", cfg.logs_dir
224
				,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year));
225 226 227
			printfile(str,0);
			return(0);
		case CS_SYSTEM_YLOG:                /* Yesterday's log */
228
			if(!chksyspass())
229 230
				return(0);
			now-=(ulong)60L*24L*60L;
231
			if(localtime_r(&now,&tm)==NULL)
232
				return(0);
233
			sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg.logs_dir
234
				,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year));
235 236 237
			printfile(str,0);
			return(0);
		case CS_SYSTEM_STATS:               /* System Statistics */
238
			sys_stats();
239 240
			return(0);
		case CS_NODE_STATS:              /* Node Statistics */
241
			node_stats(atoi(csi->str));
242 243
			return(0);
		case CS_CHANGE_USER:                 /* Change to another user */
244
			change_user();
245 246 247 248
			return(0);
		case CS_SHOW_MEM:
			return(0);
		case CS_ERROR_LOG:
249
			sprintf(str,"%serror.log", cfg.logs_dir);
250 251 252
			if(fexist(str)) {
				bputs(text[ErrorLogHdr]);
				printfile(str,0);
253
				if(text[DeleteErrorLogQ][0] && !noyes(text[DeleteErrorLogQ]))
Rob Swindell's avatar
Rob Swindell committed
254
					(void)remove(str); 
255
			}
256
			else
257
				bprintf(text[FileDoesNotExist],str);
258 259 260
			for(i=1;i<=cfg.sys_nodes;i++) {
				getnodedat(i,&node,0);
				if(node.errors)
261 262
					break; 
			}
263
			if(i<=cfg.sys_nodes || criterrs) {
264
				if(text[ClearErrCounter][0]==0 || !noyes(text[ClearErrCounter])) {
265
					for(i=1;i<=cfg.sys_nodes;i++) {
266 267 268 269 270 271 272 273
						if(getnodedat(i,&node,true)==0) {
							node.errors=0;
							putnodedat(i,&node); 
						}
					criterrs=0; 
					} 
				}
			}
274 275 276 277 278 279 280
			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 */
281
			if(!chksyspass())
282 283
				return(0);
			bputs(text[Filename]);
284
			if(getstr(str,60,0))
285 286 287
				printfile(str,0);
			return(0);
		case CS_EDIT_TEXT_FILE:              /* Edit ASCII/Ctrl-A file */
288
			if(!chksyspass())
289 290
				return(0);
			bputs(text[Filename]);
291
			if(getstr(str,60,0))
292 293 294
				editfile(str);
			return(0);
		case CS_GURU_LOG:
295
			sprintf(str,"%sguru.log", cfg.logs_dir);
296 297 298
			if(fexist(str)) {
				printfile(str,0);
				CRLF;
299
				if(text[DeleteGuruLogQ][0] && !noyes(text[DeleteGuruLogQ]))
300 301
					remove(str); 
			}
302 303
			return(0);
		case CS_FILE_SET_ALT_PATH:
304
			bprintf("Alternate Upload Paths are Unsupported\r\n");
305 306
			return(0);
		case CS_FILE_RESORT_DIRECTORY:
307 308
			lprintf(LOG_WARNING, "deprecated function: RESORT_DIRECTORY");
			return 0;
309 310 311 312

		case CS_FILE_GET:
			if(!fexist(csi->str)) {
				bputs(text[FileNotFound]);
313 314
				return(0); 
			}
315
			if(!chksyspass())
316 317 318 319
				return(0);

		case CS_FILE_SEND:

320
			csi->logic=sendfile(csi->str) ? LOGIC_TRUE:LOGIC_FALSE;
321 322 323
			return(0);

		case CS_FILE_PUT:
rswindell's avatar
rswindell committed
324
			csi->logic=LOGIC_FALSE;
325
			if(!chksyspass())
326
				return(0);
327 328

		case CS_FILE_RECEIVE:
329
			csi->logic=recvfile(csi->str) ? LOGIC_TRUE:LOGIC_FALSE;
330 331 332 333 334 335 336 337 338 339 340
			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;
341 342 343 344
						if(bulkupload(usrdir[i][j])) return(0); 
					}
				return(0); 
			}
345 346 347 348 349
			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;
350 351 352 353
					if(bulkupload(usrdir[curlib][i])) return(0); 
				}
				return(0); 
			}
354 355 356 357 358 359 360 361
			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);
362
			if(!getfilespec(str))
363 364 365 366 367 368 369 370 371 372 373 374
				return(0);
			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;
375 376
				bprintf("uploaded before %s\r\n",timestr(ns_time)); 
			}
377 378
			else if(*(csi->ip-1)==CS_FILE_FIND_OLD) { /* go by download date */
				l=FI_OLD;
379 380
				bprintf("not downloaded since %s\r\n",timestr(ns_time)); 
			}
381 382
			else if(*(csi->ip-1)==CS_FILE_FIND_OFFLINE) {
				l=FI_OFFLINE;
383 384
				bputs("not online...\r\n"); 
			}
385
			else {
386 387
				// e.g. FI_CLOSE;
				return 0;
388
			}
389 390 391 392 393 394 395
			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);
396 397 398
						else k+=s; 
					} 
			}
399 400 401 402 403 404
			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);
405 406 407
					else k+=s; 
				} 
			}
408 409 410 411
			else {
				s=listfileinfo(usrdir[curlib][curdir[curlib]],str,(char)l);
				if(s==-1)
					return(0);
412 413
				k=s; 
			}
414
			if(k>1) {
415 416 417 418
				bprintf(text[NFilesListed],k); 
			}
			return(0); 
	}
419 420 421

	if(*(csi->ip-1)>=CS_MSG_SET_AREA && *(csi->ip-1)<=CS_MSG_UNUSED1) {
		csi->ip--;
422 423
		return(exec_msg(csi)); 
	}
424

425
	if(*(csi->ip-1)>=CS_FILE_SET_AREA && *(csi->ip-1)<=CS_FILE_RECEIVE) {
426
		csi->ip--;
427 428
		return(exec_file(csi)); 
	}
429 430 431 432

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