|
|
1.1 root 1: /* execfunc.cpp */
2:
3: /* Hi-level command shell/module routines (functions) */
4:
1.1.1.2 ! root 5: /* $Id: execfunc.cpp,v 1.32 2003/08/22 10:50:15 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39: #include "cmdshell.h"
40:
41: int sbbs_t::exec_function(csi_t *csi)
42: {
1.1.1.2 ! root 43: char str[256],ch;
1.1 root 44: char tmp[512];
45: uchar* p;
1.1.1.2 ! root 46: int s;
1.1 root 47: uint i,j,k;
48: long l;
49: node_t node;
1.1.1.2 ! root 50: struct tm tm;
1.1 root 51:
52: switch(*(csi->ip++)) {
53:
54:
55: case CS_PRINTFILE_STR:
56: printfile(csi->str,P_NOATCODES);
57: return(0);
58:
59: /********************************/
60: /* General Main Menu Type Stuff */
61: /********************************/
62: case CS_AUTO_MESSAGE:
63: automsg();
64: return(0);
65: case CS_MINUTE_BANK:
1.1.1.2 ! root 66: time_bank();
1.1 root 67: return(0);
68: case CS_CHAT_SECTION:
1.1.1.2 ! root 69: chatsection();
1.1 root 70: return(0);
71: case CS_USER_DEFAULTS:
72: maindflts(&useron);
73: if(!(useron.rest&FLAG('G'))) /* not guest */
74: getuserdat(&cfg,&useron);
75: return(0);
76: case CS_TEXT_FILE_SECTION:
77: text_sec();
78: return(0);
79: case CS_INFO_SYSTEM: /* System information */
1.1.1.2 ! root 80: sys_info();
1.1 root 81: return(0);
82: case CS_INFO_SUBBOARD: /* Sub-board information */
83: if(!usrgrps) return(0);
84: subinfo(usrsub[curgrp][cursub[curgrp]]);
85: return(0);
86: case CS_INFO_DIRECTORY: /* Sub-board information */
87: if(!usrlibs) return(0);
88: dirinfo(usrdir[curlib][curdir[curlib]]);
89: return(0);
90: case CS_INFO_VERSION: /* Version */
91: ver();
92: return(0);
93: case CS_INFO_USER: /* User's statistics */
1.1.1.2 ! root 94: user_info();
1.1 root 95: return(0);
96: case CS_INFO_XFER_POLICY:
1.1.1.2 ! root 97: xfer_policy();
1.1 root 98: return(0);
99: case CS_XTRN_EXEC:
100: csi->logic=LOGIC_TRUE;
101: for(i=0;i<cfg.total_xtrns;i++)
102: if(!stricmp(cfg.xtrn[i]->code,csi->str))
103: break;
104: if(i<cfg.total_xtrns)
105: exec_xtrn(i);
106: else
107: csi->logic=LOGIC_FALSE;
108: return(0);
109: case CS_XTRN_SECTION:
1.1.1.2 ! root 110: xtrn_sec();
1.1 root 111: return(0);
112: case CS_LOGOFF:
113: if(!noyes(text[LogOffQ])) {
114: if(cfg.logoff_mod[0])
115: exec_bin(cfg.logoff_mod,csi);
116: user_event(EVENT_LOGOFF);
117: menu("logoff");
118: SYNC;
119: hangup(); }
120: return(0);
121: case CS_LOGOFF_FAST:
122: SYNC;
123: hangup();
124: return(0);
125: case CS_NODELIST_ALL:
1.1.1.2 ! root 126: nodelist();
1.1 root 127: return(0);
128: case CS_NODELIST_USERS:
129: whos_online(true);
130: return(0);
131: case CS_USERLIST_SUB:
132: userlist(UL_SUB);
133: return(0);
134: case CS_USERLIST_DIR:
135: userlist(UL_DIR);
136: return(0);
137: case CS_USERLIST_ALL:
138: userlist(UL_ALL);
139: return(0);
140: case CS_USERLIST_LOGONS:
1.1.1.2 ! root 141: logonlist();
1.1 root 142: return(0);
143: case CS_PAGE_SYSOP:
1.1.1.2 ! root 144: csi->logic=sysop_page() ? LOGIC_TRUE:LOGIC_FALSE;
1.1 root 145: return(0);
146: case CS_PAGE_GURU:
1.1.1.2 ! root 147: csi->logic=guru_page() ? LOGIC_TRUE:LOGIC_FALSE;
1.1 root 148: return(0);
149: case CS_SPY:
1.1.1.2 ! root 150: csi->logic=spy(atoi(csi->str)) ? LOGIC_TRUE:LOGIC_FALSE;
1.1 root 151: return(0);
152: case CS_PRIVATE_CHAT:
153: privchat();
154: return(0);
155: case CS_PRIVATE_MESSAGE:
156: nodemsg();
157: return(0);
158:
159: /*******************/
160: /* Sysop Functions */
161: /*******************/
162: case CS_USER_EDIT:
1.1.1.2 ! root 163: useredit(csi->str[0] ? finduser(csi->str) : 0);
1.1 root 164: return(0);
165:
166:
167: /******************/
168: /* Mail Functions */
169: /******************/
170:
171: case CS_MAIL_READ: /* Read E-mail */
172: readmail(useron.number,MAIL_YOUR);
173: return(0);
174: case CS_MAIL_READ_SENT: /* Kill/read sent mail */
1.1.1.2 ! root 175: readmail(useron.number,MAIL_SENT);
1.1 root 176: return(0);
177: case CS_MAIL_READ_ALL:
178: readmail(useron.number,MAIL_ALL);
179: return(0);
180: case CS_MAIL_SEND: /* Send E-mail */
181: if(strchr(csi->str,'@')) {
182: i=1;
183: netmail(csi->str,nulstr,0); }
1.1.1.2 ! root 184: else if((i=finduser(csi->str))!=0
! 185: || (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str,false))!=0))
1.1 root 186: email(i,nulstr,nulstr,WM_EMAIL);
187: csi->logic=!i;
188: return(0);
189: case CS_MAIL_SEND_FEEDBACK: /* Feedback */
190: if((i=finduser(csi->str))!=0)
191: email(i,text[ReFeedback],nulstr,WM_EMAIL);
192: csi->logic=!i;
193: return(0);
194: case CS_MAIL_SEND_NETMAIL:
195: bputs(text[EnterNetMailAddress]);
196: if(getstr(str,60,K_LINE)) {
197: netmail(str,nulstr,0);
198: csi->logic=LOGIC_TRUE; }
199: else
200: csi->logic=LOGIC_FALSE;
201: return(0);
202:
203: case CS_MAIL_SEND_NETFILE:
204: bputs(text[EnterNetMailAddress]);
205: if(getstr(str,60,K_LINE)) {
206: netmail(str,nulstr,WM_FILE);
207: csi->logic=LOGIC_TRUE; }
208: else
209: csi->logic=LOGIC_FALSE;
210: return(0);
211:
212: case CS_MAIL_SEND_FILE: /* Upload Attached File to E-mail */
213: if(strchr(csi->str,'@')) {
214: i=1;
215: netmail(csi->str,nulstr,WM_FILE); }
1.1.1.2 ! root 216: else if((i=finduser(csi->str))!=0
! 217: || (cfg.msg_misc&MM_REALNAME && (i=userdatdupe(0,U_NAME,LEN_NAME,csi->str,false))!=0))
1.1 root 218: email(i,nulstr,nulstr,WM_EMAIL|WM_FILE);
219: csi->logic=!i;
220: return(0);
221: case CS_MAIL_SEND_BULK:
222: if(csi->str[0])
1.1.1.2 ! root 223: p=arstr(NULL,csi->str, &cfg);
1.1 root 224: else
225: p=(uchar *)nulstr;
226: bulkmail(p);
227: if(p && p[0])
228: FREE(p);
229: return(0);
230:
231: case CS_INC_MAIN_CMDS:
232: main_cmds++;
233: return(0);
234:
235: case CS_INC_FILE_CMDS:
236: xfer_cmds++;
237: return(0);
238:
239: case CS_SYSTEM_LOG: /* System log */
1.1.1.2 ! root 240: if(!chksyspass())
1.1 root 241: return(0);
1.1.1.2 ! root 242: if(localtime_r(&now,&tm)==NULL)
1.1 root 243: return(0);
1.1.1.2 ! root 244: sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log", cfg.logs_dir
! 245: ,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year));
1.1 root 246: printfile(str,0);
247: return(0);
248: case CS_SYSTEM_YLOG: /* Yesterday's log */
1.1.1.2 ! root 249: if(!chksyspass())
1.1 root 250: return(0);
251: now-=(ulong)60L*24L*60L;
1.1.1.2 ! root 252: if(localtime_r(&now,&tm)==NULL)
1.1 root 253: return(0);
1.1.1.2 ! root 254: sprintf(str,"%slogs/%2.2d%2.2d%2.2d.log",cfg.logs_dir
! 255: ,tm.tm_mon+1,tm.tm_mday,TM_YEAR(tm.tm_year));
1.1 root 256: printfile(str,0);
257: return(0);
258: case CS_SYSTEM_STATS: /* System Statistics */
1.1.1.2 ! root 259: sys_stats();
1.1 root 260: return(0);
261: case CS_NODE_STATS: /* Node Statistics */
1.1.1.2 ! root 262: node_stats(atoi(csi->str));
1.1 root 263: return(0);
264: case CS_CHANGE_USER: /* Change to another user */
1.1.1.2 ! root 265: change_user();
1.1 root 266: return(0);
267: case CS_SHOW_MEM:
268: #ifdef __MSDOS__
269: bprintf(text[NBytesFreeMemory],farcoreleft());
270: #endif
271: return(0);
272: case CS_ERROR_LOG:
1.1.1.2 ! root 273: sprintf(str,"%serror.log", cfg.logs_dir);
1.1 root 274: if(fexist(str)) {
275: bputs(text[ErrorLogHdr]);
276: printfile(str,0);
277: if(!noyes(text[DeleteErrorLogQ]))
278: remove(str); }
279: else
280: bputs(text[NoErrorLogExists]);
281: for(i=1;i<=cfg.sys_nodes;i++) {
282: getnodedat(i,&node,0);
283: if(node.errors)
284: break; }
285: if(i<=cfg.sys_nodes || criterrs) {
286: if(!noyes(text[ClearErrCounter])) {
287: for(i=1;i<=cfg.sys_nodes;i++) {
1.1.1.2 ! root 288: if(getnodedat(i,&node,true)==0) {
! 289: node.errors=0;
! 290: putnodedat(i,&node);
! 291: }
! 292: criterrs=0;
! 293: }
! 294: }
! 295: }
1.1 root 296: return(0);
297: case CS_ANSI_CAPTURE: /* Capture ANSI codes */
298: sys_status^=SS_ANSCAP;
299: bprintf(text[ANSICaptureIsNow]
300: ,sys_status&SS_ANSCAP ? text[ON] : text[OFF]);
301: return(0);
302: case CS_LIST_TEXT_FILE: /* View ASCII/ANSI/Ctrl-A file */
1.1.1.2 ! root 303: if(!chksyspass())
1.1 root 304: return(0);
305: bputs(text[Filename]);
306: if(getstr(str,60,0))
307: printfile(str,0);
308: return(0);
309: case CS_EDIT_TEXT_FILE: /* Edit ASCII/Ctrl-A file */
1.1.1.2 ! root 310: if(!chksyspass())
1.1 root 311: return(0);
312: bputs(text[Filename]);
313: if(getstr(str,60,0))
314: editfile(str);
315: return(0);
316: case CS_GURU_LOG:
1.1.1.2 ! root 317: sprintf(str,"%sguru.log", cfg.logs_dir);
1.1 root 318: if(fexist(str)) {
319: printfile(str,0);
320: CRLF;
321: if(!noyes(text[DeleteGuruLogQ]))
322: remove(str); }
323: return(0);
324: case CS_FILE_SET_ALT_PATH:
325: altul=atoi(csi->str);
326: if(altul>cfg.altpaths)
327: altul=0;
328: bprintf(text[AltULPathIsNow],altul ? cfg.altpath[altul-1] : text[OFF]);
329: return(0);
330: case CS_FILE_RESORT_DIRECTORY:
331: for(i=1;i<=cfg.sys_nodes;i++)
332: if(i!=cfg.node_num) {
333: getnodedat(i,&node,0);
334: if(node.status==NODE_INUSE
335: || node.status==NODE_QUIET)
336: break; }
337:
338: if(i<=cfg.sys_nodes) {
339: bputs(text[ResortWarning]);
340: return(0); }
341:
342: if(!stricmp(csi->str,"ALL")) { /* all libraries */
343: for(i=0;i<usrlibs;i++)
344: for(j=0;j<usrdirs[i];j++)
345: resort(usrdir[i][j]);
346: return(0); }
347: if(!stricmp(csi->str,"LIB")) { /* current library */
348: for(i=0;i<usrdirs[curlib];i++)
349: resort(usrdir[curlib][i]);
350: return(0); }
351: resort(usrdir[curlib][curdir[curlib]]);
352: return(0);
353:
354: case CS_FILE_GET:
355: if(!fexist(csi->str)) {
356: bputs(text[FileNotFound]);
357: return(0); }
1.1.1.2 ! root 358: if(!chksyspass())
1.1 root 359: return(0);
360:
361: case CS_FILE_SEND:
362:
1.1.1.2 ! root 363: csi->logic=LOGIC_FALSE;
! 364: xfer_prot_menu(XFER_DOWNLOAD);
1.1 root 365: mnemonics(text[ProtocolOrQuit]);
366: strcpy(str,"Q");
367: for(i=0;i<cfg.total_prots;i++)
368: if(cfg.prot[i]->dlcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
369: sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
370: strcat(str,tmp); }
371: ch=(char)getkeys(str,0);
372: if(ch=='Q' || sys_status&SS_ABORT) {
373: return(0); }
374: for(i=0;i<cfg.total_prots;i++)
375: if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron))
376: break;
377: if(i<cfg.total_prots) {
1.1.1.2 ! root 378: if(protocol(cfg.prot[i],XFER_DOWNLOAD,csi->str,csi->str,false)==0)
! 379: csi->logic=LOGIC_TRUE;
! 380: autohangup();
! 381: }
1.1 root 382: return(0);
383:
384: case CS_FILE_PUT:
1.1.1.2 ! root 385: csi->logic=LOGIC_FALSE;
! 386: if(!chksyspass())
1.1 root 387: return(0);
1.1.1.2 ! root 388:
! 389: case CS_FILE_RECEIVE:
! 390: csi->logic=LOGIC_FALSE;
! 391: xfer_prot_menu(XFER_UPLOAD);
1.1 root 392: mnemonics(text[ProtocolOrQuit]);
393: strcpy(str,"Q");
394: for(i=0;i<cfg.total_prots;i++)
395: if(cfg.prot[i]->ulcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
396: sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
397: strcat(str,tmp); }
398: ch=(char)getkeys(str,0);
399: if(ch=='Q' || sys_status&SS_ABORT) {
400: lncntr=0;
401: return(0); }
402: for(i=0;i<cfg.total_prots;i++)
403: if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron))
404: break;
405: if(i<cfg.total_prots) {
1.1.1.2 ! root 406: if(protocol(cfg.prot[i],XFER_UPLOAD,csi->str,csi->str,true)==0)
! 407: csi->logic=LOGIC_TRUE;
! 408: autohangup();
! 409: }
1.1 root 410: return(0);
411:
412: case CS_FILE_UPLOAD_BULK:
413:
414: if(!usrlibs) return(0);
415:
416: if(!stricmp(csi->str,"ALL")) { /* all libraries */
417: for(i=0;i<usrlibs;i++)
418: for(j=0;j<usrdirs[i];j++) {
419: if(cfg.lib[i]->offline_dir==usrdir[i][j])
420: continue;
421: if(bulkupload(usrdir[i][j])) return(0); }
422: return(0); }
423: if(!stricmp(csi->str,"LIB")) { /* current library */
424: for(i=0;i<usrdirs[curlib];i++) {
425: if(cfg.lib[usrlib[curlib]]->offline_dir
426: ==usrdir[curlib][i])
427: continue;
428: if(bulkupload(usrdir[curlib][i])) return(0); }
429: return(0); }
430: bulkupload(usrdir[curlib][curdir[curlib]]); /* current dir */
431: return(0);
432:
433: case CS_FILE_FIND_OLD:
434: case CS_FILE_FIND_OPEN:
435: case CS_FILE_FIND_OFFLINE:
436: case CS_FILE_FIND_OLD_UPLOADS:
437: if(!usrlibs) return(0);
438: if(!getfilespec(tmp))
439: return(0);
440: padfname(tmp,str);
441: k=0;
442: bputs("\r\nSearching ");
443: if(!stricmp(csi->str,"ALL"))
444: bputs("all libraries");
445: else if(!stricmp(csi->str,"LIB"))
446: bputs("library");
447: else
448: bputs("directory");
449: bputs(" for files ");
450: if(*(csi->ip-1)==CS_FILE_FIND_OLD_UPLOADS) {
451: l=FI_OLDUL;
452: bprintf("uploaded before %s\r\n",timestr(&ns_time)); }
453: else if(*(csi->ip-1)==CS_FILE_FIND_OLD) { /* go by download date */
454: l=FI_OLD;
455: bprintf("not downloaded since %s\r\n",timestr(&ns_time)); }
456: else if(*(csi->ip-1)==CS_FILE_FIND_OFFLINE) {
457: l=FI_OFFLINE;
458: bputs("not online...\r\n"); }
459: else {
460: l=FI_CLOSE;
461: bputs("currently open...\r\n"); }
462: if(!stricmp(csi->str,"ALL")) {
463: for(i=0;i<usrlibs;i++)
464: for(j=0;j<usrdirs[i];j++) {
465: if(cfg.lib[i]->offline_dir==usrdir[i][j])
466: continue;
467: if((s=listfileinfo(usrdir[i][j],str,(char)l))==-1)
468: return(0);
469: else k+=s; } }
470: else if(!stricmp(csi->str,"LIB")) {
471: for(i=0;i<usrdirs[curlib];i++) {
472: if(cfg.lib[usrlib[curlib]]->offline_dir==usrdir[curlib][i])
473: continue;
474: if((s=listfileinfo(usrdir[curlib][i],str,(char)l))==-1)
475: return(0);
476: else k+=s; } }
477: else {
478: s=listfileinfo(usrdir[curlib][curdir[curlib]],str,(char)l);
479: if(s==-1)
480: return(0);
481: k=s; }
482: if(k>1) {
483: bprintf(text[NFilesListed],k); }
484: return(0); }
485:
486: if(*(csi->ip-1)>=CS_MSG_SET_AREA && *(csi->ip-1)<=CS_MSG_UNUSED1) {
487: csi->ip--;
1.1.1.2 ! root 488: return(exec_msg(csi)); }
1.1 root 489:
1.1.1.2 ! root 490: if(*(csi->ip-1)>=CS_FILE_SET_AREA && *(csi->ip-1)<=CS_FILE_RECEIVE) {
1.1 root 491: csi->ip--;
1.1.1.2 ! root 492: return(exec_file(csi)); }
1.1 root 493:
494: errormsg(WHERE,ERR_CHK,"shell function",*(csi->ip-1));
495: return(0);
496: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.