cmds.c 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108
  1. /*
  2. * cmds.c -- handles:
  3. * commands from a user via dcc
  4. * (split in 3, this portion contains no-irc commands)
  5. *
  6. */
  7. #include "main.h"
  8. #include "tandem.h"
  9. #include "modules.h"
  10. #include "help.h"
  11. #include <ctype.h>
  12. #include <stdlib.h>
  13. #include <pwd.h>
  14. #include <sys/types.h>
  15. #ifdef HAVE_UNAME
  16. #include <sys/utsname.h>
  17. #endif
  18. extern struct chanset_t *chanset;
  19. extern struct dcc_t *dcc;
  20. extern struct userrec *userlist;
  21. extern tcl_timer_t *timer, *utimer;
  22. extern int dcc_total, remote_boots, backgrd,
  23. do_restart, conmask, must_be_owner,
  24. strict_host, quiet_save, cfg_count,
  25. server_lag;
  26. extern unsigned long otraffic_irc, otraffic_irc_today,
  27. itraffic_irc, itraffic_irc_today,
  28. otraffic_bn, otraffic_bn_today,
  29. itraffic_bn, itraffic_bn_today,
  30. otraffic_dcc, otraffic_dcc_today,
  31. itraffic_dcc, itraffic_dcc_today,
  32. otraffic_trans, otraffic_trans_today,
  33. itraffic_trans, itraffic_trans_today,
  34. otraffic_unknown, otraffic_unknown_today,
  35. itraffic_unknown, itraffic_unknown_today;
  36. extern Tcl_Interp *interp;
  37. extern char botnetnick[], origbotname[], ver[], network[],
  38. owner[], quit_msg[], dcc_prefix[],
  39. botname[], *binname, egg_version[];
  40. extern time_t now, online_since, buildts;
  41. extern module_entry *module_list;
  42. extern struct cfg_entry CFG_MOTD, **cfg;
  43. extern tand_t *tandbot;
  44. static char *btos(unsigned long);
  45. mycmds cmds[500]; //the list of dcc cmds for help system
  46. int cmdi = 0;
  47. #ifdef HUB
  48. static void tell_who(struct userrec *u, int idx, int chan)
  49. {
  50. int i, k, ok = 0, atr = u ? u->flags : 0;
  51. int nicklen;
  52. char format[81];
  53. char s[1024]; /* temp fix - 1.4 has a better one */
  54. if (!chan)
  55. dprintf(idx, "%s (* = %s, + = %s, @ = %s)\n",
  56. BOT_PARTYMEMBS, MISC_OWNER, MISC_MASTER, MISC_OP);
  57. else {
  58. simple_sprintf(s, "assoc %d", chan);
  59. if ((Tcl_Eval(interp, s) != TCL_OK) || !interp->result[0])
  60. dprintf(idx, "%s %s%d: (* = %s, + = %s, @ = %s)\n",
  61. BOT_PEOPLEONCHAN,
  62. (chan < GLOBAL_CHANS) ? "" : "*",
  63. chan % GLOBAL_CHANS,
  64. MISC_OWNER, MISC_MASTER, MISC_OP);
  65. else
  66. dprintf(idx, "%s '%s' (%s%d): (* = %s, + = %s, @ = %s)\n",
  67. BOT_PEOPLEONCHAN, interp->result,
  68. (chan < GLOBAL_CHANS) ? "" : "*",
  69. chan % GLOBAL_CHANS,
  70. MISC_OWNER, MISC_MASTER, MISC_OP);
  71. }
  72. /* calculate max nicklen */
  73. nicklen = 0;
  74. for (i = 0; i < dcc_total; i++) {
  75. if(strlen(dcc[i].nick) > nicklen)
  76. nicklen = strlen(dcc[i].nick);
  77. }
  78. if(nicklen < 9) nicklen = 9;
  79. for (i = 0; i < dcc_total; i++)
  80. if (dcc[i].type == &DCC_CHAT)
  81. if (dcc[i].u.chat->channel == chan) {
  82. if (atr & USER_OWNER) {
  83. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us %%s", nicklen);
  84. sprintf(s, format,
  85. dcc[i].sock, (geticon(i) == '-' ? ' ' : geticon(i)),
  86. dcc[i].nick, dcc[i].host);
  87. } else {
  88. egg_snprintf(format, sizeof format, " %%c%%-%us %%s", nicklen);
  89. sprintf(s, format,
  90. (geticon(i) == '-' ? ' ' : geticon(i)),
  91. dcc[i].nick, dcc[i].host);
  92. }
  93. if (atr & USER_MASTER) {
  94. if (dcc[i].u.chat->con_flags)
  95. sprintf(&s[strlen(s)], " (con:%s)",
  96. masktype(dcc[i].u.chat->con_flags));
  97. }
  98. if (now - dcc[i].timeval > 300) {
  99. unsigned long days, hrs, mins;
  100. days = (now - dcc[i].timeval) / 86400;
  101. hrs = ((now - dcc[i].timeval) - (days * 86400)) / 3600;
  102. mins = ((now - dcc[i].timeval) - (hrs * 3600)) / 60;
  103. if (days > 0)
  104. sprintf(&s[strlen(s)], " (idle %lud%luh)", days, hrs);
  105. else if (hrs > 0)
  106. sprintf(&s[strlen(s)], " (idle %luh%lum)", hrs, mins);
  107. else
  108. sprintf(&s[strlen(s)], " (idle %lum)", mins);
  109. }
  110. dprintf(idx, "%s\n", s);
  111. if (dcc[i].u.chat->away != NULL)
  112. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  113. }
  114. for (i = 0; i < dcc_total; i++)
  115. if (dcc[i].type == &DCC_BOT) {
  116. if (!ok) {
  117. ok = 1;
  118. dprintf(idx, STR("Bots connected:\n"));
  119. }
  120. #ifdef S_UTCTIME
  121. egg_strftime(s, 14, "%d %b %H:%M %Z", gmtime(&dcc[i].timeval));
  122. #else /* !S_UTCTIME */
  123. egg_strftime(s, 14, "%d %b %H:%M %Z", localtime(&dcc[i].timeval));
  124. #endif /* S_UTCTIME */
  125. if (atr & USER_OWNER) {
  126. egg_snprintf(format, sizeof format, " [%%.2lu] %%s%%c%%-%us (%%s) %%s\n",
  127. nicklen);
  128. dprintf(idx, format,
  129. dcc[i].sock, dcc[i].status & STAT_CALLED ? "<-" : "->",
  130. dcc[i].status & STAT_SHARE ? '+' : ' ',
  131. dcc[i].nick, s, dcc[i].u.bot->version);
  132. } else {
  133. egg_snprintf(format, sizeof format, " %%s%%c%%-%us (%%s) %%s\n", nicklen);
  134. dprintf(idx, format,
  135. dcc[i].status & STAT_CALLED ? "<-" : "->",
  136. dcc[i].status & STAT_SHARE ? '+' : ' ',
  137. dcc[i].nick, s, dcc[i].u.bot->version);
  138. }
  139. }
  140. ok = 0;
  141. for (i = 0; i < dcc_total; i++) {
  142. if ((dcc[i].type == &DCC_CHAT) && (dcc[i].u.chat->channel != chan)) {
  143. if (!ok) {
  144. ok = 1;
  145. dprintf(idx, STR("Other people on the bot:\n"));
  146. }
  147. if (atr & USER_OWNER) {
  148. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us ", nicklen);
  149. sprintf(s, format, dcc[i].sock,
  150. (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
  151. } else {
  152. egg_snprintf(format, sizeof format, " %%c%%-%us ", nicklen);
  153. sprintf(s, format,
  154. (geticon(i) == '-' ? ' ' : geticon(i)), dcc[i].nick);
  155. }
  156. if (atr & USER_MASTER) {
  157. if (dcc[i].u.chat->channel < 0)
  158. strcat(s, "(-OFF-) ");
  159. else if (!dcc[i].u.chat->channel)
  160. strcat(s, "(party) ");
  161. else
  162. sprintf(&s[strlen(s)], "(%5d) ", dcc[i].u.chat->channel);
  163. }
  164. strcat(s, dcc[i].host);
  165. if (atr & USER_MASTER) {
  166. if (dcc[i].u.chat->con_flags)
  167. sprintf(&s[strlen(s)], " (con:%s)",
  168. masktype(dcc[i].u.chat->con_flags));
  169. }
  170. if (now - dcc[i].timeval > 300) {
  171. k = (now - dcc[i].timeval) / 60;
  172. if (k < 60)
  173. sprintf(&s[strlen(s)], " (idle %dm)", k);
  174. else
  175. sprintf(&s[strlen(s)], " (idle %dh%dm)", k / 60, k % 60);
  176. }
  177. dprintf(idx, "%s\n", s);
  178. if (dcc[i].u.chat->away != NULL)
  179. dprintf(idx, " AWAY: %s\n", dcc[i].u.chat->away);
  180. }
  181. if ((atr & USER_MASTER) && (dcc[i].type->flags & DCT_SHOWWHO) &&
  182. (dcc[i].type != &DCC_CHAT)) {
  183. if (!ok) {
  184. ok = 1;
  185. dprintf(idx, STR("Other people on the bot:\n"));
  186. }
  187. if (atr & USER_OWNER) {
  188. egg_snprintf(format, sizeof format, " [%%.2lu] %%c%%-%us (files) %%s",
  189. nicklen);
  190. sprintf(s, format,
  191. dcc[i].sock, dcc[i].status & STAT_CHAT ? '+' : ' ',
  192. dcc[i].nick, dcc[i].host);
  193. } else {
  194. egg_snprintf(format, sizeof format, " %%c%%-%us (files) %%s", nicklen);
  195. sprintf(s, format,
  196. dcc[i].status & STAT_CHAT ? '+' : ' ',
  197. dcc[i].nick, dcc[i].host);
  198. }
  199. dprintf(idx, "%s\n", s);
  200. }
  201. }
  202. }
  203. static void cmd_botinfo(struct userrec *u, int idx, char *par)
  204. {
  205. char s[512], s2[32];
  206. struct chanset_t *chan;
  207. time_t now2;
  208. int hr, min;
  209. putlog(LOG_CMDS, "*", STR("#%s# botinfo"), dcc[idx].nick);
  210. now2 = now - online_since;
  211. s2[0] = 0;
  212. if (now2 > 86400) {
  213. int days = now2 / 86400;
  214. /* Days */
  215. sprintf(s2, "%d day", days);
  216. if (days >= 2)
  217. strcat(s2, "s");
  218. strcat(s2, ", ");
  219. now2 -= days * 86400;
  220. }
  221. hr = (time_t) ((int) now2 / 3600);
  222. now2 -= (hr * 3600);
  223. min = (time_t) ((int) now2 / 60);
  224. sprintf(&s2[strlen(s2)], "%02d:%02d", (int) hr, (int) min);
  225. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  226. botnet_send_infoq(-1, s);
  227. s[0] = 0;
  228. if (module_find("server", 0, 0)) {
  229. for (chan = chanset; chan; chan = chan->next) {
  230. if (!channel_secret(chan)) {
  231. if ((strlen(s) + strlen(chan->dname) + strlen(network)
  232. + strlen(botnetnick) + strlen(ver) + 1) >= 490) {
  233. strcat(s,"++ ");
  234. break; /* yeesh! */
  235. }
  236. strcat(s, chan->dname);
  237. strcat(s, ", ");
  238. }
  239. }
  240. if (s[0]) {
  241. s[strlen(s) - 2] = 0;
  242. dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
  243. ver, network, s, s2);
  244. } else
  245. dprintf(idx, "*** [%s] %s <%s> (%s) [UP %s]\n", botnetnick,
  246. ver, network, BOT_NOCHANNELS, s2);
  247. } else
  248. dprintf(idx, STR("*** [%s] %s <NO_IRC> [UP %s]\n"), botnetnick, ver, s2);
  249. }
  250. #endif /* HUB */
  251. static void cmd_whom(struct userrec *u, int idx, char *par)
  252. {
  253. if (par[0] == '*') {
  254. putlog(LOG_CMDS, "*", STR("#%s# whom %s"), dcc[idx].nick, par);
  255. answer_local_whom(idx, -1);
  256. return;
  257. } else if (dcc[idx].u.chat->channel < 0) {
  258. dprintf(idx, STR("You have chat turned off.\n"));
  259. return;
  260. }
  261. putlog(LOG_CMDS, "*", STR("#%s# whom %s"), dcc[idx].nick, par);
  262. if (!par[0]) {
  263. answer_local_whom(idx, dcc[idx].u.chat->channel);
  264. } else {
  265. int chan = -1;
  266. if ((par[0] < '0') || (par[0] > '9')) {
  267. Tcl_SetVar(interp, "chan", par, 0);
  268. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  269. interp->result[0]) {
  270. chan = atoi(interp->result);
  271. }
  272. if (chan <= 0) {
  273. dprintf(idx, STR("No such channel exists.\n"));
  274. return;
  275. }
  276. } else
  277. chan = atoi(par);
  278. if ((chan < 0) || (chan > 99999)) {
  279. dprintf(idx, STR("Channel number out of range: must be between 0 and 99999.\n"));
  280. return;
  281. }
  282. answer_local_whom(idx, chan);
  283. }
  284. }
  285. #ifdef HUB
  286. static void cmd_config(struct userrec *u, int idx, char *par)
  287. {
  288. /*
  289. .config
  290. Usage + available entry list
  291. .config name
  292. Show current value + description
  293. .config name value
  294. Set
  295. */
  296. char *name;
  297. struct cfg_entry *cfgent = NULL;
  298. int cnt, i;
  299. putlog(LOG_CMDS, "*", STR("#%s# config %s"), dcc[idx].nick, par);
  300. if (!par[0]) {
  301. char *outbuf = nmalloc(1);
  302. outbuf[0] = 0;
  303. dprintf(idx, STR("Usage: config [name [value|-]]\n"));
  304. dprintf(idx, STR("Defined config entry names:\n"));
  305. cnt = 0;
  306. for (i=0;i<cfg_count;i++) {
  307. if ((cfg[i]->flags & CFGF_GLOBAL) && (cfg[i]->describe)) {
  308. if (!cnt) {
  309. outbuf = nrealloc(outbuf, 2 + 1);
  310. sprintf(outbuf, " ");
  311. }
  312. outbuf = nrealloc(outbuf, strlen(outbuf) + strlen(cfg[i]->name) + 1 + 1);
  313. sprintf(outbuf, STR("%s%s "), outbuf, cfg[i]->name);
  314. cnt++;
  315. if (cnt == 10) {
  316. dprintf(idx, "%s\n", outbuf);
  317. cnt=0;
  318. }
  319. }
  320. }
  321. if (cnt)
  322. dprintf(idx, "%s\n", outbuf);
  323. if (outbuf)
  324. nfree(outbuf);
  325. return;
  326. }
  327. name = newsplit(&par);
  328. for (i = 0; !cfgent && (i < cfg_count); i++)
  329. if (!strcmp(cfg[i]->name, name))
  330. cfgent=cfg[i];
  331. if (!cfgent || !cfgent->describe) {
  332. dprintf(idx, STR("No such config entry\n"));
  333. return;
  334. }
  335. if (!par[0]) {
  336. cfgent->describe(cfgent, idx);
  337. if (!cfgent->gdata)
  338. dprintf(idx, STR("No current value\n"));
  339. else {
  340. dprintf(idx, STR("Currently: %s\n"), cfgent->gdata);
  341. }
  342. return;
  343. }
  344. if (strlen(par) >= 2048) {
  345. dprintf(idx, STR("Value can't be longer than 2048 chars"));
  346. return;
  347. }
  348. set_cfg_str(NULL, cfgent->name, par);
  349. if (!cfgent->gdata)
  350. dprintf(idx, STR("Now: (not set)\n"));
  351. else {
  352. dprintf(idx, STR("Now: %s\n"), cfgent->gdata);
  353. }
  354. #ifdef HUB
  355. write_userfile(idx);
  356. #endif /* HUB */
  357. }
  358. static void cmd_botconfig(struct userrec *u, int idx, char *par)
  359. {
  360. struct userrec *u2;
  361. char *p;
  362. struct xtra_key *k;
  363. struct cfg_entry *cfgent;
  364. int i, cnt;
  365. /* botconfig bot [name [value]] */
  366. putlog(LOG_CMDS, "*", STR("#%s# botconfig %s"), dcc[idx].nick, par);
  367. if (!par[0]) {
  368. dprintf(idx, STR("Usage: botconfig bot [name [value|-]]\n"));
  369. cnt=0;
  370. for (i=0; i < cfg_count; i++) {
  371. if (cfg[i]->flags & CFGF_LOCAL) {
  372. dprintf(idx, STR("%s "), cfg[i]->name);
  373. cnt++;
  374. if (cnt == 10) {
  375. dprintf(idx, "\n");
  376. cnt=0;
  377. }
  378. }
  379. }
  380. if (cnt > 0)
  381. dprintf(idx, "\n");
  382. return;
  383. }
  384. p = newsplit(&par);
  385. u2 = get_user_by_handle(userlist, p);
  386. if (!u2) {
  387. dprintf(idx, STR("No such user.\n"));
  388. return;
  389. }
  390. if (!(u2->flags & USER_BOT)) {
  391. dprintf(idx, STR("%s isn't a bot.\n"), p);
  392. return;
  393. }
  394. if (!par[0]) {
  395. for (i = 0; i < cfg_count; i++) {
  396. if ((cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe)) {
  397. k = get_user(&USERENTRY_CONFIG, u2);
  398. while (k && strcmp(k->key, cfg[i]->name))
  399. k=k->next;
  400. if (k)
  401. dprintf(idx, STR(" %s: %s\n"), k->key, k->data);
  402. else
  403. dprintf(idx, STR(" %s: (not set)\n"), cfg[i]->name);
  404. }
  405. }
  406. return;
  407. }
  408. p = newsplit(&par);
  409. cfgent=NULL;
  410. for (i = 0; !cfgent && (i < cfg_count); i++)
  411. if (!strcmp(cfg[i]->name, p) && (cfg[i]->flags & CFGF_LOCAL) && (cfg[i]->describe))
  412. cfgent=cfg[i];
  413. if (!cfgent) {
  414. dprintf(idx, STR("No such configuration value\n"));
  415. return;
  416. }
  417. if (par[0]) {
  418. char tmp[100];
  419. set_cfg_str(u2->handle, cfgent->name, (strcmp(par, "-")) ? par : NULL);
  420. snprintf(tmp, sizeof tmp, "%s %s", cfgent->name, par);
  421. update_mod(u2->handle, dcc[idx].nick, "botconfig", tmp);
  422. dprintf(idx, STR("Now: "));
  423. write_userfile(idx);
  424. } else {
  425. if (cfgent->describe)
  426. cfgent->describe(cfgent, idx);
  427. }
  428. k = get_user(&USERENTRY_CONFIG, u2);
  429. while (k && strcmp(k->key, cfgent->name))
  430. k=k->next;
  431. if (k)
  432. dprintf(idx, STR(" %s: %s\n"), k->key, k->data);
  433. else
  434. dprintf(idx, STR(" %s: (not set)\n"), cfgent->name);
  435. }
  436. #ifdef S_DCCPASS
  437. static void cmd_cmdpass(struct userrec *u, int idx, char *par)
  438. {
  439. struct tcl_bind_mask_b *hm;
  440. char *cmd = NULL, *pass = NULL;
  441. int i, l = 0;
  442. /* cmdpass [command [newpass]] */
  443. cmd = newsplit(&par);
  444. putlog(LOG_CMDS, "*", STR("#%s# cmdpass %s ..."), dcc[idx].nick, cmd[0] ? cmd : "");
  445. pass = newsplit(&par);
  446. if (!cmd[0] || par[0]) {
  447. dprintf(idx, STR("Usage: %scmdpass command [password]\n"), dcc_prefix);
  448. dprintf(idx, STR(" if no password is specified, the commands password is reset\n"));
  449. return;
  450. }
  451. for (i = 0; cmd[i]; i++)
  452. cmd[i] = tolower(cmd[i]);
  453. if (!egg_strcasecmp(cmd, "op")) l++;
  454. else if (!egg_strcasecmp(cmd, "act")) l++;
  455. else if (!egg_strcasecmp(cmd, "adduser")) l++;
  456. else if (!egg_strcasecmp(cmd, "channel")) l++;
  457. else if (!egg_strcasecmp(cmd, "deluser")) l++;
  458. else if (!egg_strcasecmp(cmd, "deop")) l++;
  459. else if (!egg_strcasecmp(cmd, "devoice")) l++;
  460. else if (!egg_strcasecmp(cmd, "getkey")) l++;
  461. else if (!egg_strcasecmp(cmd, "find")) l++;
  462. else if (!egg_strcasecmp(cmd, "invite")) l++;
  463. else if (!egg_strcasecmp(cmd, "kick")) l++;
  464. else if (!egg_strcasecmp(cmd, "kickban")) l++;
  465. else if (!egg_strcasecmp(cmd, "mdop")) l++;
  466. else if (!egg_strcasecmp(cmd, "msg")) l++;
  467. else if (!egg_strcasecmp(cmd, "reset")) l++;
  468. else if (!egg_strcasecmp(cmd, "resetbans")) l++;
  469. else if (!egg_strcasecmp(cmd, "resetexempts")) l++;
  470. else if (!egg_strcasecmp(cmd, "resetinvites")) l++;
  471. else if (!egg_strcasecmp(cmd, "say")) l++;
  472. else if (!egg_strcasecmp(cmd, "topic")) l++;
  473. else if (!egg_strcasecmp(cmd, "voice")) l++;
  474. else if (!egg_strcasecmp(cmd, "clearqueue")) l++;
  475. else if (!egg_strcasecmp(cmd, "dump")) l++;
  476. else if (!egg_strcasecmp(cmd, "jump")) l++;
  477. else if (!egg_strcasecmp(cmd, "servers")) l++;
  478. else if (!egg_strcasecmp(cmd, "authed")) l++;
  479. if (!l) {
  480. for (hm = H_dcc->first; hm; hm = hm->next)
  481. if (!egg_strcasecmp(cmd, hm->mask))
  482. break;
  483. if (!hm) {
  484. dprintf(idx, STR("No such DCC command\n"));
  485. return;
  486. }
  487. }
  488. if (pass[0]) {
  489. char epass[36], tmp[256];
  490. if (!isowner(u->handle) && has_cmd_pass(cmd)) {
  491. putlog(LOG_MISC, "*", STR("%s attempted to change command password for %s - not perm owner"), dcc[idx].nick, cmd);
  492. dprintf(idx, STR("Perm owners only.\n"));
  493. return;
  494. }
  495. encrypt_pass(pass, epass);
  496. sprintf(tmp, STR("%s %s"), cmd, epass);
  497. if (has_cmd_pass(cmd))
  498. dprintf(idx, STR("Changed command password for %s\n"), cmd);
  499. else
  500. dprintf(idx, STR("Set command password for %s\n"), cmd);
  501. set_cmd_pass(tmp, 1);
  502. } else {
  503. if (!isowner(u->handle)) {
  504. putlog(LOG_MISC, "*", STR("%s attempted to remove command password for %s - not perm owner"), dcc[idx].nick, cmd);
  505. dprintf(idx, STR("Perm owners only.\n"));
  506. return;
  507. }
  508. set_cmd_pass(cmd, 1);
  509. dprintf(idx, STR("Removed command password for %s\n"), cmd);
  510. }
  511. write_userfile(idx);
  512. }
  513. #endif /* S_DCCPASS */
  514. static void cmd_lagged(struct userrec *u, int idx, char *par)
  515. {
  516. /* Lists botnet lag to *directly connected* bots */
  517. int i;
  518. putlog(LOG_CMDS, "*", STR("#%s# lagged %s"), u->handle, par);
  519. for (i = 0; i < dcc_total; i++) {
  520. if (dcc[i].type == &DCC_BOT) {
  521. dprintf(idx, STR("%9s - %i seconds\n"), dcc[i].nick, (dcc[i].pingtime > 120) ? (now - dcc[i].pingtime) : dcc[i].pingtime);
  522. }
  523. }
  524. }
  525. #endif /* HUB */
  526. static void cmd_me(struct userrec *u, int idx, char *par)
  527. {
  528. int i;
  529. if (dcc[idx].u.chat->channel < 0) {
  530. dprintf(idx, STR("You have chat turned off.\n"));
  531. return;
  532. }
  533. if (!par[0]) {
  534. dprintf(idx, STR("Usage: me <action>\n"));
  535. return;
  536. }
  537. if (dcc[idx].u.chat->away != NULL)
  538. not_away(idx);
  539. for (i = 0; i < dcc_total; i++)
  540. if ((dcc[i].type->flags & DCT_CHAT) &&
  541. (dcc[i].u.chat->channel == dcc[idx].u.chat->channel) &&
  542. ((i != idx) || (dcc[i].status & STAT_ECHO)))
  543. dprintf(i, "* %s %s\n", dcc[idx].nick, par);
  544. botnet_send_act(idx, botnetnick, dcc[idx].nick,
  545. dcc[idx].u.chat->channel, par);
  546. check_tcl_act(dcc[idx].nick, dcc[idx].u.chat->channel, par);
  547. }
  548. static void cmd_motd(struct userrec *u, int idx, char *par)
  549. {
  550. putlog(LOG_CMDS, "*", STR("#%s# motd %s"), dcc[idx].nick, par);
  551. if (par[0] && (u->flags & USER_MASTER)) {
  552. char *s;
  553. s = nmalloc(strlen(par) + 1 + strlen(dcc[idx].nick) + 10 + 1 + 1); /* +2: ' 'x2 */
  554. sprintf(s, STR("%s %lu %s"), dcc[idx].nick, now, par);
  555. set_cfg_str(NULL, "motd", s);
  556. nfree(s);
  557. dprintf(idx, STR("Motd set\n"));
  558. } else {
  559. show_motd(idx);
  560. }
  561. }
  562. static void cmd_about(struct userrec *u, int idx, char *par)
  563. {
  564. putlog(LOG_CMDS, "*", STR("#%s# about"), dcc[idx].nick);
  565. dprintf(idx, STR("Wraith (%s) botpack by bryan, CVS date %lu"), buildts);
  566. dprintf(idx, STR("..with credits and thanks to the following:\n"), egg_version);
  567. dprintf(idx, STR("(written from a base of Eggdrop 1.6.12)\n\n"));
  568. dprintf(idx, STR("Eggdrop team for developing such a great bot to code off of.\n"));
  569. dprintf(idx, STR("Einride and ievil for taking eggdrop1.4.3 and making their very effecient botpack Ghost.\n"));
  570. dprintf(idx, STR("SFC for providing compile shells, continuous input, feature suggestions, and testing.\n"));
  571. dprintf(idx, STR("xmage for beta testing.\n"));
  572. dprintf(idx, STR("ryguy for beta testing, providing code, finding bugs, and providing input.\n"));
  573. dprintf(idx, STR("passwd for beta testing, and his dedication to finding bugs.\n"));
  574. dprintf(idx, STR("pgpkeys for suggestions.\n"));
  575. dprintf(idx, STR("qFox for providing an mIRC $md5() alias, not requiring a dll or >6.03\n"));
  576. dprintf(idx, STR("Sith_Lord helping test ipv6 on the bot (admin@elitepackets.com)\n"));
  577. dprintf(idx, STR("Excelsior for finding a bug on BSD with the ipv6.\n"));
  578. dprintf(idx, STR("syt for giving me inspiration to code a more secure bot.\n\n\n"));
  579. dprintf(idx, STR("Mystikal for finding various bugs.\n"));
  580. dprintf(idx, STR("Blackjac for helping with the bx auth script with his Sentinel script.\n"));
  581. dprintf(idx, STR("The following botpacks gave me inspiration and ideas (no code):\n"));
  582. dprintf(idx, STR("awptic by lordoptic\n"));
  583. dprintf(idx, STR("optikz by ryguy and lordoptic\n"));
  584. dprintf(idx, STR("celdrop by excelsior\n"));
  585. dprintf(idx, STR("genocide by various\n"));
  586. dprintf(idx, STR("tfbot by warknight and loslinux\n"));
  587. }
  588. static void cmd_away(struct userrec *u, int idx, char *par)
  589. {
  590. if (strlen(par) > 60)
  591. par[60] = 0;
  592. set_away(idx, par);
  593. }
  594. static void cmd_back(struct userrec *u, int idx, char *par)
  595. {
  596. not_away(idx);
  597. }
  598. static void cmd_newpass(struct userrec *u, int idx, char *par)
  599. {
  600. char *new, pass[16];
  601. putlog(LOG_CMDS, "*", STR("#%s# newpass..."), dcc[idx].nick);
  602. if (!par[0]) {
  603. dprintf(idx, STR("Usage: newpass <newpassword>\n"));
  604. return;
  605. }
  606. new = newsplit(&par);
  607. if (!strcmp(new, "rand")) {
  608. make_rand_str(pass, 15);
  609. } else {
  610. if (strlen(new) < 6) {
  611. dprintf(idx, STR("Please use at least 6 characters.\n"));
  612. return;
  613. } else {
  614. sprintf(pass, "%s", new);
  615. }
  616. }
  617. if (strlen(pass) > 15)
  618. pass[15] = 0;
  619. if (!goodpass(pass, idx, NULL))
  620. return;
  621. set_user(&USERENTRY_PASS, u, pass);
  622. dprintf(idx, STR("Changed your password to: %s\n"), pass);
  623. }
  624. static void cmd_secpass(struct userrec *u, int idx, char *par)
  625. {
  626. char *new, pass[17];
  627. putlog(LOG_CMDS, "*", STR("#%s# secpass..."), dcc[idx].nick);
  628. if (!par[0]) {
  629. dprintf(idx, STR("Usage: secpass <newsecpass>\nIf you use \"rand\" as the secpass, a random pass will be chosen.\n"));
  630. return;
  631. }
  632. new = newsplit(&par);
  633. if (!strcmp(new, "rand")) {
  634. make_rand_str(pass, 16);
  635. } else {
  636. if (strlen(new) < 6) {
  637. dprintf(idx, STR("Please use at least 6 characters.\n"));
  638. return;
  639. } else {
  640. sprintf(pass, "%s", new);
  641. }
  642. }
  643. if (strlen(pass) > 16)
  644. pass[16] = 0;
  645. set_user(&USERENTRY_SECPASS, u, pass);
  646. dprintf(idx, STR("Changed your secpass to: %s.\n"), pass);
  647. }
  648. #ifdef HUB
  649. static void cmd_bots(struct userrec *u, int idx, char *par)
  650. {
  651. putlog(LOG_CMDS, "*", STR("#%s# bots"), dcc[idx].nick);
  652. tell_bots(idx);
  653. }
  654. static void cmd_downbots(struct userrec *u, int idx, char *par)
  655. {
  656. struct userrec *u2;
  657. int cnt = 0, tot = 0;
  658. char work[128] = "";
  659. putlog(LOG_CMDS, "*", STR("#%s# downbots"), dcc[idx].nick);
  660. for (u2 = userlist; u2; u2 = u2->next) {
  661. if (u2->flags & USER_BOT) {
  662. if (egg_strcasecmp(u2->handle, botnetnick)) {
  663. if (nextbot(u2->handle) == -1) {
  664. strcat(work, u2->handle);
  665. cnt++;
  666. tot++;
  667. if (cnt == 10) {
  668. dprintf(idx, STR("Down bots: %s\n"), work);
  669. work[0] = 0;
  670. cnt = 0;
  671. } else
  672. strcat(work, " ");
  673. }
  674. }
  675. }
  676. }
  677. if (work[0])
  678. dprintf(idx, STR("Down bots: %s\n"), work);
  679. dprintf(idx, STR("(Total down: %d)\n"), tot);
  680. }
  681. static void cmd_bottree(struct userrec *u, int idx, char *par)
  682. {
  683. putlog(LOG_CMDS, "*", STR("#%s# bottree"), dcc[idx].nick);
  684. tell_bottree(idx, 0);
  685. }
  686. static void cmd_vbottree(struct userrec *u, int idx, char *par)
  687. {
  688. putlog(LOG_CMDS, "*", STR("#%s# vbottree"), dcc[idx].nick);
  689. tell_bottree(idx, 1);
  690. }
  691. #endif /* HUB */
  692. int my_cmp (const mycmds *c1, const mycmds *c2)
  693. {
  694. return strcmp (c1->name, c2->name);
  695. }
  696. static void cmd_nohelp(struct userrec *u, int idx, char *par)
  697. {
  698. int i;
  699. char *buf = nmalloc(1);
  700. buf[0] = 0;
  701. qsort(cmds, cmdi - 1, sizeof(mycmds), (int (*)()) &my_cmp);
  702. for (i = 0; i < (cmdi - 1); i++) {
  703. int o, found = 0;
  704. for (o = 0; (help[o].cmd) && (help[o].desc); o++)
  705. if (!egg_strcasecmp(help[o].cmd, cmds[i].name)) found++;
  706. if (!found) {
  707. buf = nrealloc(buf, strlen(buf) + 2 + strlen(cmds[i].name) + 1);
  708. strcat(buf, cmds[i].name);
  709. strcat(buf, ", ");
  710. }
  711. }
  712. buf[strlen(buf) - 1] = 0;
  713. dumplots(idx, "", buf);
  714. }
  715. static void cmd_help(struct userrec *u, int idx, char *par)
  716. {
  717. char flg[100];
  718. int fnd = 0, done = 0, o = 0, nowild = 0;
  719. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  720. char *fcats, temp[100], buf[2046], match[20];
  721. egg_snprintf(temp, sizeof temp, "a|- a|a n|- n|n m|- m|m mo|o m|o i|- o|o o|- p|- -|-");
  722. fcats = temp;
  723. putlog(LOG_CMDS, "*", STR("#%s# help %s"), dcc[idx].nick, par);
  724. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  725. build_flags(flg, &fr, NULL);
  726. if (!par[0]) {
  727. sprintf(match, "*");
  728. } else {
  729. if (!strchr(par, '*') && !strchr(par, '?'))
  730. nowild++;
  731. sprintf(match, "%s", newsplit(&par));
  732. }
  733. if (!nowild)
  734. dprintf(idx, STR("Showing help topics matching '%s' for flags: (%s)\n"), match, flg);
  735. o = cmdi - 1;
  736. qsort(cmds, o, sizeof(mycmds), (int (*)()) &my_cmp);
  737. buf[0] = 0;
  738. /* even if we have nowild, we loop to conserve code/space */
  739. while (!done) {
  740. int i = 0, end = 0, first = 1, n, hi;
  741. char *flag;
  742. flag = newsplit(&fcats);
  743. if (!flag[0])
  744. done = 1;
  745. for (n = 0; n < o ; n++) { /* loop each command */
  746. if (!flagrec_ok(&cmds[n].flags, &fr) || !wild_match(match,cmds[n].name))
  747. continue;
  748. fnd++;
  749. if (nowild) {
  750. dprintf(idx, STR("Showing you help for '%s':"), match);
  751. for (hi = 0; (help[hi].cmd) && (help[hi].desc); hi++) {
  752. if (!egg_strcasecmp(match, help[hi].cmd)) {
  753. showhelp(idx, &fr, help[hi].desc);
  754. }
  755. }
  756. done = 1;
  757. break;
  758. } else {
  759. flg[0] = 0;
  760. build_flags(flg, &(cmds[n].flags), NULL);
  761. if (!strcmp(flg, flag)) {
  762. if (first) {
  763. dprintf(idx, "%s\n", buf[0] ? buf : "");
  764. dprintf(idx, STR("# DCC (%s)\n"), flag);
  765. sprintf(buf, " ");
  766. }
  767. if (end && !first) {
  768. dprintf(idx, "%s\n", buf[0] ? buf : "");
  769. /* we dumped the buf to dprintf, now start a new one... */
  770. sprintf(buf, " ");
  771. }
  772. sprintf(buf, "%s%-14.14s", buf[0] ? buf : "", cmds[n].name);
  773. first = 0;
  774. end = 0;
  775. i++;
  776. }
  777. if (i >= 5) {
  778. end = 1;
  779. i = 0;
  780. }
  781. }
  782. }
  783. }
  784. dprintf(idx, "%s\n", buf[0] ? buf : "");
  785. dprintf(idx, STR("--End help listing\n"));
  786. if (!strcmp(match, "*")) {
  787. dprintf(idx, STR("For individual command help, type: %shelp <command>\n"), dcc_prefix);
  788. } else if (!fnd) {
  789. dprintf(idx, STR("No match for '%s'.\n"), match);
  790. }
  791. dprintf(idx, STR("If you have flags on a channel, type %sconsole #chan to possibly see more commands.\n"), dcc_prefix);
  792. }
  793. static void cmd_addlog(struct userrec *u, int idx, char *par)
  794. {
  795. putlog(LOG_CMDS, "*", STR("#%s# addlog %s"), dcc[idx].nick, par);
  796. putlog(LOG_MISC, "*", "%s: %s", dcc[idx].nick, par);
  797. if (!par[0]) {
  798. dprintf(idx, STR("Usage: addlog <message>\n"));
  799. return;
  800. }
  801. dprintf(idx, STR("Placed entry in the log file.\n"));
  802. }
  803. #ifdef HUB
  804. static void cmd_who(struct userrec *u, int idx, char *par)
  805. {
  806. int i;
  807. if (par[0]) {
  808. if (dcc[idx].u.chat->channel < 0) {
  809. dprintf(idx, STR("You have chat turned off.\n"));
  810. return;
  811. }
  812. putlog(LOG_CMDS, "*", STR("#%s# who %s"), dcc[idx].nick, par);
  813. if (!egg_strcasecmp(par, botnetnick))
  814. tell_who(u, idx, dcc[idx].u.chat->channel);
  815. else {
  816. i = nextbot(par);
  817. if (i < 0) {
  818. dprintf(idx, STR("That bot isn't connected.\n"));
  819. } else if (dcc[idx].u.chat->channel > 99999)
  820. dprintf(idx, STR("You are on a local channel.\n"));
  821. else {
  822. char s[40];
  823. simple_sprintf(s, "%d:%s@%s", dcc[idx].sock,
  824. dcc[idx].nick, botnetnick);
  825. botnet_send_who(i, s, par, dcc[idx].u.chat->channel);
  826. }
  827. }
  828. } else {
  829. putlog(LOG_CMDS, "*", STR("#%s# who"), dcc[idx].nick);
  830. if (dcc[idx].u.chat->channel < 0)
  831. tell_who(u, idx, 0);
  832. else
  833. tell_who(u, idx, dcc[idx].u.chat->channel);
  834. }
  835. }
  836. #endif /* HUB */
  837. static void cmd_whois(struct userrec *u, int idx, char *par)
  838. {
  839. if (!par[0]) {
  840. dprintf(idx, STR("Usage: whois <handle>\n"));
  841. return;
  842. }
  843. putlog(LOG_CMDS, "*", STR("#%s# whois %s"), dcc[idx].nick, par);
  844. tell_user_ident(idx, par, u ? (u->flags & USER_MASTER) : 0);
  845. }
  846. static void cmd_match(struct userrec *u, int idx, char *par)
  847. {
  848. int start = 1, limit = 20;
  849. char *s, *s1, *chname;
  850. if (!par[0]) {
  851. dprintf(idx, STR("Usage: match <nick/host> [[skip] count]\n"));
  852. return;
  853. }
  854. putlog(LOG_CMDS, "*", STR("#%s# match %s"), dcc[idx].nick, par);
  855. s = newsplit(&par);
  856. if (strchr(CHANMETA, par[0]) != NULL)
  857. chname = newsplit(&par);
  858. else
  859. chname = "";
  860. if (atoi(par) > 0) {
  861. s1 = newsplit(&par);
  862. if (atoi(par) > 0) {
  863. start = atoi(s1);
  864. limit = atoi(par);
  865. } else
  866. limit = atoi(s1);
  867. }
  868. tell_users_match(idx, s, start, limit, u ? (u->flags & USER_MASTER) : 0,
  869. chname);
  870. }
  871. static void cmd_update(struct userrec *u, int idx, char *par)
  872. {
  873. putlog(LOG_CMDS, "*", STR("#%s# update %s"), dcc[idx].nick, par);
  874. if (!par[0])
  875. dprintf(idx, STR("Usage: update <binname>\n"));
  876. updatebin(idx, par, 0);
  877. }
  878. static void cmd_uptime(struct userrec *u, int idx, char *par)
  879. {
  880. putlog(LOG_CMDS, "*", STR("#%s# uptime"), dcc[idx].nick);
  881. tell_verbose_uptime(idx);
  882. }
  883. static void cmd_userlist(struct userrec *u, int idx, char *par)
  884. {
  885. int cnt = 0, tt = 0;
  886. putlog(LOG_CMDS, "*", STR("#%s# userlist"), dcc[idx].nick);
  887. for (u=userlist;u;u=u->next) {
  888. if ((u->flags & USER_BOT) && (u->flags & USER_CHANHUB)) {
  889. if (cnt)
  890. dprintf(idx, ", ");
  891. else
  892. dprintf(idx, STR("Chathubs: "));
  893. dprintf(idx, u->handle);
  894. cnt++;
  895. tt++;
  896. if (cnt == 15) {
  897. dprintf(idx, "\n");
  898. cnt=0;
  899. }
  900. }
  901. }
  902. if (cnt)
  903. dprintf(idx, "\n");
  904. cnt=0;
  905. #ifdef HUB
  906. for (u=userlist;u;u=u->next) {
  907. if (!(u->flags & USER_BOT) && (u->flags & USER_ADMIN)) {
  908. if (cnt)
  909. dprintf(idx, ", ");
  910. else
  911. dprintf(idx, STR("Admins : "));
  912. dprintf(idx, u->handle);
  913. cnt++;
  914. tt++;
  915. if (cnt == 15) {
  916. dprintf(idx, "\n");
  917. cnt=0;
  918. }
  919. }
  920. }
  921. if (cnt)
  922. dprintf(idx, "\n");
  923. cnt=0;
  924. for (u=userlist;u;u=u->next) {
  925. if (!(u->flags & (USER_BOT | USER_ADMIN)) && (u->flags & USER_OWNER)) {
  926. if (cnt)
  927. dprintf(idx, ", ");
  928. else
  929. dprintf(idx, STR("Owners : "));
  930. dprintf(idx, u->handle);
  931. cnt++;
  932. tt++;
  933. if (cnt == 15) {
  934. dprintf(idx, "\n");
  935. cnt=0;
  936. }
  937. }
  938. }
  939. if (cnt)
  940. dprintf(idx, "\n");
  941. cnt=0;
  942. for (u=userlist;u;u=u->next) {
  943. if (!(u->flags & (USER_BOT | USER_OWNER)) && (u->flags & USER_MASTER)) {
  944. if (cnt)
  945. dprintf(idx, ", ");
  946. else
  947. dprintf(idx, STR("Masters : "));
  948. dprintf(idx, u->handle);
  949. cnt++;
  950. tt++;
  951. if (cnt == 15) {
  952. dprintf(idx, "\n");
  953. cnt=0;
  954. }
  955. }
  956. }
  957. if (cnt)
  958. dprintf(idx, "\n");
  959. cnt=0;
  960. #endif /* HUB */
  961. for (u=userlist;u;u=u->next) {
  962. #ifdef HUB
  963. if (!(u->flags & (USER_BOT | USER_MASTER)) && (u->flags & USER_OP)) {
  964. #else /* !HUB */
  965. if (!(u->flags & USER_BOT) && (u->flags & USER_OP)) {
  966. #endif /* HUB */
  967. if (cnt)
  968. dprintf(idx, ", ");
  969. else
  970. dprintf(idx, STR("Ops : "));
  971. dprintf(idx, u->handle);
  972. cnt++;
  973. tt++;
  974. if (cnt == 15) {
  975. dprintf(idx, "\n");
  976. cnt=0;
  977. }
  978. }
  979. }
  980. if (cnt)
  981. dprintf(idx, "\n");
  982. cnt=0;
  983. for (u=userlist;u;u=u->next) {
  984. if (!(u->flags & (USER_BOT | USER_OP))) {
  985. if (cnt)
  986. dprintf(idx, ", ");
  987. else
  988. dprintf(idx, STR("Users : "));
  989. dprintf(idx, u->handle);
  990. cnt++;
  991. tt++;
  992. if (cnt==15) {
  993. dprintf(idx, "\n");
  994. cnt=0;
  995. }
  996. }
  997. }
  998. if (cnt)
  999. dprintf(idx, "\n");
  1000. cnt=0;
  1001. dprintf(idx, STR("Total users: %d\n"), tt);
  1002. }
  1003. static void cmd_channels(struct userrec *u, int idx, char *par) {
  1004. putlog(LOG_CMDS, "*", STR("#%s# channels %s"), dcc[idx].nick, par);
  1005. if (par[0] && (u->flags & USER_MASTER)) {
  1006. struct userrec *user;
  1007. user = get_user_by_handle(userlist, par);
  1008. if (user)
  1009. show_channels(idx, par);
  1010. else
  1011. dprintf(idx, STR("There is no user by that name.\n"));
  1012. } else
  1013. show_channels(idx, NULL);
  1014. if ((u->flags & USER_MASTER))
  1015. dprintf(idx, STR("You can also %schannels <nickname>\n"), dcc_prefix);
  1016. }
  1017. static void cmd_status(struct userrec *u, int idx, char *par)
  1018. {
  1019. int atr = u ? u->flags : 0;
  1020. if (!egg_strcasecmp(par, "all")) {
  1021. if (!(atr & USER_MASTER)) {
  1022. dprintf(idx, STR("You do not have Bot Master privileges.\n"));
  1023. return;
  1024. }
  1025. putlog(LOG_CMDS, "*", STR("#%s# status all"), dcc[idx].nick);
  1026. tell_verbose_status(idx);
  1027. tell_mem_status_dcc(idx);
  1028. dprintf(idx, "\n");
  1029. tell_settings(idx);
  1030. do_module_report(idx, 1, NULL);
  1031. } else {
  1032. putlog(LOG_CMDS, "*", STR("#%s# status"), dcc[idx].nick);
  1033. tell_verbose_status(idx);
  1034. tell_mem_status_dcc(idx);
  1035. do_module_report(idx, 0, NULL);
  1036. }
  1037. }
  1038. #ifdef HUB
  1039. static void cmd_dccstat(struct userrec *u, int idx, char *par)
  1040. {
  1041. putlog(LOG_CMDS, "*", STR("#%s# dccstat"), dcc[idx].nick);
  1042. tell_dcc(idx);
  1043. }
  1044. #endif /* HUB */
  1045. static void cmd_boot(struct userrec *u, int idx, char *par)
  1046. {
  1047. int i, ok = 0;
  1048. char *who;
  1049. struct userrec *u2;
  1050. if (!par[0]) {
  1051. dprintf(idx, STR("Usage: boot nick[@bot]\n"));
  1052. return;
  1053. }
  1054. who = newsplit(&par);
  1055. if (strchr(who, '@') != NULL) {
  1056. char whonick[HANDLEN + 1];
  1057. splitcn(whonick, who, '@', HANDLEN + 1);
  1058. if (!egg_strcasecmp(who, botnetnick)) {
  1059. cmd_boot(u, idx, whonick);
  1060. return;
  1061. }
  1062. if (remote_boots > 0) {
  1063. i = nextbot(who);
  1064. if (i < 0) {
  1065. dprintf(idx, STR("No such bot connected.\n"));
  1066. return;
  1067. }
  1068. botnet_send_reject(i, dcc[idx].nick, botnetnick, whonick,
  1069. who, par[0] ? par : dcc[idx].nick);
  1070. putlog(LOG_BOTS, "*", STR("#%s# boot %s@%s (%s)"), dcc[idx].nick, whonick,
  1071. who, par[0] ? par : dcc[idx].nick);
  1072. } else
  1073. dprintf(idx, STR("Remote boots are disabled here.\n"));
  1074. return;
  1075. }
  1076. for (i = 0; i < dcc_total; i++)
  1077. if (!egg_strcasecmp(dcc[i].nick, who)
  1078. && !ok && (dcc[i].type->flags & DCT_CANBOOT)) {
  1079. u2 = get_user_by_handle(userlist, dcc[i].nick);
  1080. if (u2 && (u2->flags & USER_OWNER)
  1081. && egg_strcasecmp(dcc[idx].nick, who)) {
  1082. dprintf(idx, STR("You can't boot a bot owner.\n"));
  1083. return;
  1084. }
  1085. if (u2 && (u2->flags & USER_MASTER) && !(u && (u->flags & USER_MASTER))) {
  1086. dprintf(idx, STR("You can't boot a bot master.\n"));
  1087. return;
  1088. }
  1089. dprintf(idx, STR("Booted %s from the party line.\n"), dcc[i].nick);
  1090. putlog(LOG_CMDS, "*", STR("#%s# boot %s %s"), dcc[idx].nick, who, par);
  1091. do_boot(i, dcc[idx].nick, par);
  1092. ok = 1;
  1093. }
  1094. if (!ok)
  1095. dprintf(idx, STR("Who? No such person on the party line.\n"));
  1096. }
  1097. static void cmd_console(struct userrec *u, int idx, char *par)
  1098. {
  1099. char *nick, s[2], s1[512];
  1100. int dest = 0, i, ok = 0, pls, md;
  1101. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  1102. module_entry *me;
  1103. struct chanset_t *chan;
  1104. if (!par[0]) {
  1105. dprintf(idx, STR("Your console is %s: %s (%s).\n"),
  1106. dcc[idx].u.chat->con_chan,
  1107. masktype(dcc[idx].u.chat->con_flags),
  1108. maskname(dcc[idx].u.chat->con_flags));
  1109. return;
  1110. }
  1111. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  1112. strcpy(s1, par);
  1113. nick = newsplit(&par);
  1114. /* Don't remove '+' as someone couldn't have '+' in CHANMETA cause
  1115. * he doesn't use IRCnet ++rtc.
  1116. */
  1117. if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
  1118. for (i = 0; i < dcc_total; i++)
  1119. if (!egg_strcasecmp(nick, dcc[i].nick) &&
  1120. (dcc[i].type == &DCC_CHAT) && (!ok)) {
  1121. ok = 1;
  1122. dest = i;
  1123. }
  1124. if (!ok) {
  1125. dprintf(idx, STR("No such user on the party line!\n"));
  1126. return;
  1127. }
  1128. nick[0] = 0;
  1129. } else
  1130. dest = idx;
  1131. if (!nick[0])
  1132. nick = newsplit(&par);
  1133. /* Consider modeless channels, starting with '+' */
  1134. if ((nick [0] == '+' && findchan_by_dname(nick)) ||
  1135. (nick [0] != '+' && strchr(CHANMETA "*", nick[0]))) {
  1136. chan = findchan_by_dname(nick);
  1137. if (strcmp(nick, "*") && !chan) {
  1138. dprintf(idx, STR("Invalid console channel: %s.\n"), nick);
  1139. return;
  1140. }
  1141. get_user_flagrec(u, &fr, nick);
  1142. if (private(fr, findchan_by_dname(nick), PRIV_OP)) {
  1143. dprintf(idx, STR("Invalid console channel: %s.\n"), nick);
  1144. return;
  1145. }
  1146. if (!chk_op(fr, findchan_by_dname(nick))) {
  1147. dprintf(idx, STR("You don't have op or master access to channel %s.\n"), nick);
  1148. return;
  1149. }
  1150. strncpyz(dcc[dest].u.chat->con_chan, nick, 81);
  1151. nick[0] = 0;
  1152. if ((dest == idx) && !glob_master(fr) && !chan_master(fr))
  1153. /* Consoling to another channel for self */
  1154. dcc[dest].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_WALL);
  1155. }
  1156. if (!nick[0])
  1157. nick = newsplit(&par);
  1158. pls = 1;
  1159. if (nick[0]) {
  1160. if ((nick[0] != '+') && (nick[0] != '-'))
  1161. dcc[dest].u.chat->con_flags = 0;
  1162. for (; *nick; nick++) {
  1163. if (*nick == '+')
  1164. pls = 1;
  1165. else if (*nick == '-')
  1166. pls = 0;
  1167. else {
  1168. s[0] = *nick;
  1169. s[1] = 0;
  1170. md = logmodes(s);
  1171. if ((dest == idx) && !glob_master(fr) && pls) {
  1172. if (chan_master(fr))
  1173. md &= ~(LOG_FILES | LOG_DEBUG);
  1174. else
  1175. md &= ~(LOG_MISC | LOG_CMDS | LOG_FILES | LOG_WALL |
  1176. LOG_DEBUG);
  1177. }
  1178. if (!glob_owner(fr) && pls)
  1179. md &= ~(LOG_RAW | LOG_SRVOUT | LOG_BOTNET | LOG_BOTSHARE);
  1180. if (!glob_master(fr) && pls)
  1181. md &= ~LOG_BOTS;
  1182. if (pls)
  1183. dcc[dest].u.chat->con_flags |= md;
  1184. else
  1185. dcc[dest].u.chat->con_flags &= ~md;
  1186. }
  1187. }
  1188. }
  1189. putlog(LOG_CMDS, "*", STR("#%s# console %s"), dcc[idx].nick, s1);
  1190. if (dest == idx) {
  1191. dprintf(idx, STR("Set your console to %s: %s (%s).\n"),
  1192. dcc[idx].u.chat->con_chan,
  1193. masktype(dcc[idx].u.chat->con_flags),
  1194. maskname(dcc[idx].u.chat->con_flags));
  1195. } else {
  1196. dprintf(idx, STR("Set console of %s to %s: %s (%s).\n"), dcc[dest].nick,
  1197. dcc[dest].u.chat->con_chan,
  1198. masktype(dcc[dest].u.chat->con_flags),
  1199. maskname(dcc[dest].u.chat->con_flags));
  1200. dprintf(dest, STR("%s set your console to %s: %s (%s).\n"), dcc[idx].nick,
  1201. dcc[dest].u.chat->con_chan,
  1202. masktype(dcc[dest].u.chat->con_flags),
  1203. maskname(dcc[dest].u.chat->con_flags));
  1204. }
  1205. /* New style autosave -- drummer,07/25/1999*/
  1206. if ((me = module_find("console", 0, 0))) {
  1207. Function *func = me->funcs;
  1208. (func[CONSOLE_DOSTORE]) (dest);
  1209. }
  1210. }
  1211. static void cmd_date(struct userrec *u, int idx, char *par)
  1212. {
  1213. char date[50], utctime[50], ltime[50];
  1214. putlog(LOG_CMDS, "*", "#%s# date", dcc[idx].nick);
  1215. egg_strftime(date, sizeof date, "%c %Z", localtime(&now));
  1216. #ifndef S_UTCTIME
  1217. sprintf(ltime, "<-- This time is used on the bot.");
  1218. #endif /* !S_UTCTIME */
  1219. dprintf(idx, "%s %s\n", date, ltime[0] ? ltime : "");
  1220. egg_strftime(date, sizeof date, "%c %Z", gmtime(&now));
  1221. #ifdef S_UTCTIME
  1222. sprintf(utctime, "<-- This time is used on the bot.");
  1223. #endif /* S_UTCTIME */
  1224. dprintf(idx, "%s %s\n", date, utctime[0] ? utctime : "");
  1225. }
  1226. #ifdef HUB
  1227. static void cmd_chhandle(struct userrec *u, int idx, char *par)
  1228. {
  1229. char hand[HANDLEN + 1], newhand[HANDLEN + 1];
  1230. int i, atr = u ? u->flags : 0, atr2;
  1231. struct userrec *u2;
  1232. strncpyz(hand, newsplit(&par), sizeof hand);
  1233. strncpyz(newhand, newsplit(&par), sizeof newhand);
  1234. if (!hand[0] || !newhand[0]) {
  1235. dprintf(idx, STR("Usage: chhandle <oldhandle> <newhandle>\n"));
  1236. return;
  1237. }
  1238. for (i = 0; i < strlen(newhand); i++)
  1239. if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
  1240. newhand[i] = '?';
  1241. if (strchr(BADHANDCHARS, newhand[0]) != NULL)
  1242. dprintf(idx, STR("Bizarre quantum forces prevent nicknames from starting with '%c'.\n"),
  1243. newhand[0]);
  1244. else if (get_user_by_handle(userlist, newhand) &&
  1245. egg_strcasecmp(hand, newhand))
  1246. dprintf(idx, STR("Somebody is already using %s.\n"), newhand);
  1247. else {
  1248. u2 = get_user_by_handle(userlist, hand);
  1249. atr2 = u2 ? u2->flags : 0;
  1250. if (!(atr & USER_MASTER) && !(atr2 & USER_BOT))
  1251. dprintf(idx, STR("You can't change handles for non-bots.\n"));
  1252. else if ((bot_flags(u2) & BOT_SHARE) && !(atr & USER_OWNER))
  1253. dprintf(idx, STR("You can't change share bot's nick.\n"));
  1254. else if ((atr2 & USER_OWNER) && !(atr & USER_OWNER) &&
  1255. egg_strcasecmp(dcc[idx].nick, hand))
  1256. dprintf(idx, STR("You can't change a bot owner's handle.\n"));
  1257. else if (isowner(hand) && egg_strcasecmp(dcc[idx].nick, hand))
  1258. dprintf(idx, STR("You can't change a permanent bot owner's handle.\n"));
  1259. else if (!egg_strcasecmp(newhand, botnetnick) && (!(atr2 & USER_BOT) ||
  1260. nextbot(hand) != -1))
  1261. dprintf(idx, STR("Hey! That's MY name!\n"));
  1262. else if (change_handle(u2, newhand)) {
  1263. putlog(LOG_CMDS, "*", STR("#%s# chhandle %s %s"), dcc[idx].nick,
  1264. hand, newhand);
  1265. dprintf(idx, STR("Changed.\n"));
  1266. } else
  1267. dprintf(idx, STR("Failed.\n"));
  1268. }
  1269. }
  1270. #endif /* HUB */
  1271. static void cmd_handle(struct userrec *u, int idx, char *par)
  1272. {
  1273. char oldhandle[HANDLEN + 1], newhandle[HANDLEN + 1];
  1274. int i;
  1275. strncpyz(newhandle, newsplit(&par), sizeof newhandle);
  1276. if (!newhandle[0]) {
  1277. dprintf(idx, STR("Usage: handle <new-handle>\n"));
  1278. return;
  1279. }
  1280. for (i = 0; i < strlen(newhandle); i++)
  1281. if ((newhandle[i] <= 32) || (newhandle[i] >= 127) || (newhandle[i] == '@'))
  1282. newhandle[i] = '?';
  1283. if (strchr(BADHANDCHARS, newhandle[0]) != NULL) {
  1284. dprintf(idx, STR("Bizarre quantum forces prevent handle from starting with '%c'.\n"),
  1285. newhandle[0]);
  1286. } else if (get_user_by_handle(userlist, newhandle) &&
  1287. egg_strcasecmp(dcc[idx].nick, newhandle)) {
  1288. dprintf(idx, STR("Somebody is already using %s.\n"), newhandle);
  1289. } else if (!egg_strcasecmp(newhandle, botnetnick)) {
  1290. dprintf(idx, STR("Hey! That's MY name!\n"));
  1291. } else {
  1292. strncpyz(oldhandle, dcc[idx].nick, sizeof oldhandle);
  1293. if (change_handle(u, newhandle)) {
  1294. putlog(LOG_CMDS, "*", STR("#%s# handle %s"), oldhandle, newhandle);
  1295. dprintf(idx, STR("Okay, changed.\n"));
  1296. } else
  1297. dprintf(idx, STR("Failed.\n"));
  1298. }
  1299. }
  1300. #ifdef HUB
  1301. static void cmd_chpass(struct userrec *u, int idx, char *par)
  1302. {
  1303. char *handle, *new, pass[16];
  1304. int atr = u ? u->flags : 0, l;
  1305. if (!par[0])
  1306. dprintf(idx, STR("Usage: chpass <handle> [password]\n"));
  1307. else {
  1308. handle = newsplit(&par);
  1309. u = get_user_by_handle(userlist, handle);
  1310. if (!u)
  1311. dprintf(idx, STR("No such user.\n"));
  1312. else if (!(atr & USER_MASTER) && !(u->flags & USER_BOT))
  1313. dprintf(idx, STR("You can't change passwords for non-bots.\n"));
  1314. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  1315. dprintf(idx, STR("You can't change a share bot's password.\n"));
  1316. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  1317. egg_strcasecmp(handle, dcc[idx].nick))
  1318. dprintf(idx, STR("You can't change a bot owner's password.\n"));
  1319. else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
  1320. dprintf(idx, STR("You can't change a permanent bot owner's password.\n"));
  1321. else if (!par[0]) {
  1322. putlog(LOG_CMDS, "*", STR("#%s# chpass %s [nothing]"), dcc[idx].nick,
  1323. handle);
  1324. set_user(&USERENTRY_PASS, u, NULL);
  1325. dprintf(idx, STR("Removed password.\n"));
  1326. } else {
  1327. int good = 0;
  1328. l = strlen(new = newsplit(&par));
  1329. if (l > 15)
  1330. new[15] = 0;
  1331. if (!strcmp(new, "rand")) {
  1332. make_rand_str(pass, 15);
  1333. good = 1;
  1334. } else {
  1335. if (goodpass(new, idx, NULL)) {
  1336. sprintf(pass, "%s", new);
  1337. good = 1;
  1338. }
  1339. }
  1340. if (strlen(pass) > 15)
  1341. pass[15] = 0;
  1342. if (good) {
  1343. set_user(&USERENTRY_PASS, u, pass);
  1344. putlog(LOG_CMDS, "*", STR("#%s# chpass %s [something]"), dcc[idx].nick, handle);
  1345. dprintf(idx, STR("Password for '%s' changed to: %s\n"), handle, pass);
  1346. }
  1347. }
  1348. }
  1349. }
  1350. static void cmd_chsecpass(struct userrec *u, int idx, char *par)
  1351. {
  1352. char *handle, *new, pass[17];
  1353. int atr = u ? u->flags : 0, l;
  1354. if (!par[0])
  1355. dprintf(idx, STR("Usage: chsecpass <handle> [secpass/rand]\n"));
  1356. else {
  1357. handle = newsplit(&par);
  1358. u = get_user_by_handle(userlist, handle);
  1359. if (!u)
  1360. dprintf(idx, STR("No such user.\n"));
  1361. else if (!(atr & USER_MASTER) && !(u->flags & USER_BOT))
  1362. dprintf(idx, STR("You can't change passwords for non-bots.\n"));
  1363. else if ((bot_flags(u) & BOT_SHARE) && !(atr & USER_OWNER))
  1364. dprintf(idx, STR("You can't change a share bot's password.\n"));
  1365. else if ((u->flags & USER_OWNER) && !(atr & USER_OWNER) &&
  1366. egg_strcasecmp(handle, dcc[idx].nick))
  1367. dprintf(idx, STR("You can't change a bot owner's password.\n"));
  1368. else if (isowner(handle) && egg_strcasecmp(dcc[idx].nick, handle))
  1369. dprintf(idx, STR("You can't change a permanent bot owner's password.\n"));
  1370. else if (!par[0]) {
  1371. putlog(LOG_CMDS, "*", STR("#%s# chsecpass %s [nothing]"), dcc[idx].nick,
  1372. handle);
  1373. set_user(&USERENTRY_SECPASS, u, NULL);
  1374. dprintf(idx, STR("Removed secpass.\n"));
  1375. } else {
  1376. l = strlen(new = newsplit(&par));
  1377. if (l > 16)
  1378. new[16] = 0;
  1379. if (!strcmp(new, "rand")) {
  1380. make_rand_str(pass, 16);
  1381. } else {
  1382. if (strlen(new) < 6) {
  1383. dprintf(idx, STR("Please use at least 6 characters.\n"));
  1384. return;
  1385. } else {
  1386. sprintf(pass, "%s", new);
  1387. }
  1388. }
  1389. if (strlen(pass) > 16)
  1390. pass[16] = 0;
  1391. set_user(&USERENTRY_SECPASS, u, pass);
  1392. putlog(LOG_CMDS, "*", STR("#%s# chsecpass %s [something]"), dcc[idx].nick,
  1393. handle);
  1394. dprintf(idx, STR("Secpass for '%s' changed to: %s\n"), handle, pass);
  1395. }
  1396. }
  1397. }
  1398. static void cmd_botcmd(struct userrec *u, int idx, char *par)
  1399. {
  1400. tand_t *tbot;
  1401. int cnt = 0;
  1402. char *botm = NULL, *cmd = NULL;
  1403. botm = newsplit(&par);
  1404. cmd = newsplit(&par);
  1405. if (!botm[0] || !cmd[0]) {
  1406. dprintf(idx, STR("Usage: botcmd bot cmd params\n"));
  1407. return;
  1408. }
  1409. /* the rest of the cmd will be logged remotely */
  1410. putlog(LOG_CMDS, "*", STR("#%s# botcmd %s %s ..."), dcc[idx].nick, botm, cmd);
  1411. if (!strcmp(botm, "*") && (!strcmp(botm, "di") || !strcmp(botm, "die"))) {
  1412. dprintf(idx, STR("Not a good idea.\n"));
  1413. return;
  1414. }
  1415. for (tbot = tandbot; tbot; tbot = tbot->next) {
  1416. if (wild_match(botm, tbot->bot)) {
  1417. cnt++;
  1418. send_remote_simul(idx, tbot->bot, cmd, par ? par : "");
  1419. }
  1420. }
  1421. if (!cnt) {
  1422. dprintf(idx, STR("No bot matching '%s' linked\n"), botm);
  1423. return;
  1424. }
  1425. }
  1426. static void cmd_hublevel(struct userrec *u, int idx, char *par)
  1427. {
  1428. char *handle, *level;
  1429. struct bot_addr *bi, *obi;
  1430. struct userrec *u1;
  1431. putlog(LOG_CMDS, "*", STR("#%s# hublevel %s"), dcc[idx].nick, par);
  1432. if (!par[0]) {
  1433. dprintf(idx, STR("Usage: hublevel <botname> <level>\n"));
  1434. return;
  1435. }
  1436. handle = newsplit(&par);
  1437. level = newsplit(&par);
  1438. u1 = get_user_by_handle(userlist, handle);
  1439. if (!u1 || !(u1->flags & USER_BOT)) {
  1440. dprintf(idx, STR("Useful only for bots.\n"));
  1441. return;
  1442. }
  1443. dprintf(idx, STR("Changed bot's hublevel.\n"));
  1444. obi = get_user(&USERENTRY_BOTADDR, u1);
  1445. bi = user_malloc(sizeof(struct bot_addr));
  1446. bi->uplink = user_malloc(strlen(obi->uplink) + 1);
  1447. strcpy(bi->uplink, obi->uplink);
  1448. bi->address = user_malloc(strlen(obi->address) + 1);
  1449. strcpy(bi->address, obi->address);
  1450. bi->telnet_port = obi->telnet_port;
  1451. bi->relay_port = obi->relay_port;
  1452. bi->hublevel = atoi(level);
  1453. set_user(&USERENTRY_BOTADDR, u1, bi);
  1454. write_userfile(idx);
  1455. }
  1456. static void cmd_uplink(struct userrec *u, int idx, char *par)
  1457. {
  1458. char *handle, *uplink;
  1459. struct bot_addr *bi, *obi;
  1460. struct userrec *u1;
  1461. putlog(LOG_CMDS, "*", STR("#%s# uplink %s"), dcc[idx].nick, par);
  1462. if (!par[0]) {
  1463. dprintf(idx, STR("Usage: uplink <botname> [<uplink>]\n"));
  1464. return;
  1465. }
  1466. handle = newsplit(&par);
  1467. uplink = newsplit(&par);
  1468. if (!uplink)
  1469. uplink = "";
  1470. u1 = get_user_by_handle(userlist, handle);
  1471. if (!u1 || !(u1->flags & USER_BOT)) {
  1472. dprintf(idx, STR("Useful only for bots.\n"));
  1473. return;
  1474. }
  1475. dprintf(idx, STR("Changed bot's uplink.\n"));
  1476. obi = get_user(&USERENTRY_BOTADDR, u1);
  1477. bi = user_malloc(sizeof(struct bot_addr));
  1478. bi->uplink = user_malloc(strlen(uplink) + 1);
  1479. strcpy(bi->uplink, uplink);
  1480. bi->address = user_malloc(strlen(obi->address) + 1);
  1481. strcpy(bi->address, obi->address);
  1482. bi->telnet_port = obi->telnet_port;
  1483. bi->relay_port = obi->relay_port;
  1484. bi->hublevel = obi->hublevel;
  1485. set_user(&USERENTRY_BOTADDR, u1, bi);
  1486. }
  1487. static void cmd_chaddr(struct userrec *u, int idx, char *par)
  1488. {
  1489. int telnet_port = 3333, relay_port = 3333;
  1490. #ifdef USE_IPV6
  1491. char *handle, *addr, *p, *q, *r;
  1492. #else
  1493. char *handle, *addr, *p, *q;
  1494. #endif /* USE_IPV6 */
  1495. struct bot_addr *bi, *obi;
  1496. struct userrec *u1;
  1497. handle = newsplit(&par);
  1498. if (!par[0]) {
  1499. dprintf(idx, STR("Usage: chaddr <botname> <address[:telnet-port[/relay-port]]>\n"));
  1500. return;
  1501. }
  1502. addr = newsplit(&par);
  1503. if (strlen(addr) > UHOSTMAX)
  1504. addr[UHOSTMAX] = 0;
  1505. u1 = get_user_by_handle(userlist, handle);
  1506. if (!u1 || !(u1->flags & USER_BOT)) {
  1507. dprintf(idx, STR("This command is only useful for tandem bots.\n"));
  1508. return;
  1509. }
  1510. if ((bot_flags(u1) & BOT_SHARE) && (!u || !u->flags & USER_OWNER)) {
  1511. dprintf(idx, STR("You can't change a share bot's address.\n"));
  1512. return;
  1513. }
  1514. putlog(LOG_CMDS, "*", STR("#%s# chaddr %s %s"), dcc[idx].nick, handle, addr);
  1515. dprintf(idx, STR("Changed bot's address.\n"));
  1516. obi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
  1517. bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u1);
  1518. if (bi) {
  1519. telnet_port = bi->telnet_port;
  1520. relay_port = bi->relay_port;
  1521. }
  1522. bi = user_malloc(sizeof(struct bot_addr));
  1523. bi->uplink = user_malloc(strlen(obi->uplink) + 1);
  1524. strcpy(bi->uplink, obi->uplink);
  1525. bi->hublevel = obi->hublevel;
  1526. q = strchr(addr, ':');
  1527. if (!q) {
  1528. bi->address = user_malloc(strlen(addr) + 1);
  1529. strcpy(bi->address, addr);
  1530. bi->telnet_port = telnet_port;
  1531. bi->relay_port = relay_port;
  1532. } else {
  1533. #ifdef USE_IPV6
  1534. r = strchr(addr, '[');
  1535. if (r) { /* ipv6 notation [3ffe:80c0:225::] */
  1536. *addr++;
  1537. r = strchr(addr, ']');
  1538. bi->address = user_malloc(r - addr + 1);
  1539. strncpyz(bi->address, addr, r - addr + 1);
  1540. addr = r;
  1541. *addr++;
  1542. } else {
  1543. bi->address = user_malloc(q - addr + 1);
  1544. strncpyz(bi->address, addr, q - addr + 1);
  1545. }
  1546. q = strchr(addr, ':');
  1547. if (q) {
  1548. p = q + 1;
  1549. bi->telnet_port = atoi(p);
  1550. q = strchr(p, '/');
  1551. if (!q) {
  1552. bi->relay_port = telnet_port;
  1553. } else {
  1554. bi->relay_port = atoi(q + 1);
  1555. }
  1556. }
  1557. #else
  1558. bi->address = user_malloc(q - addr + 1);
  1559. strncpyz(bi->address, addr, q - addr + 1);
  1560. p = q + 1;
  1561. bi->telnet_port = atoi(p);
  1562. q = strchr(p, '/');
  1563. if (!q)
  1564. bi->relay_port = bi->telnet_port;
  1565. else
  1566. bi->relay_port = atoi(q + 1);
  1567. #endif /* USE_IPV6 */
  1568. }
  1569. set_user(&USERENTRY_BOTADDR, u1, bi);
  1570. }
  1571. #endif /* HUB */
  1572. static void cmd_comment(struct userrec *u, int idx, char *par)
  1573. {
  1574. char *handle;
  1575. struct userrec *u1;
  1576. handle = newsplit(&par);
  1577. if (!par[0]) {
  1578. dprintf(idx, STR("Usage: comment <handle> <newcomment/none>\n"));
  1579. return;
  1580. }
  1581. u1 = get_user_by_handle(userlist, handle);
  1582. if (!u1) {
  1583. dprintf(idx, STR("No such user!\n"));
  1584. return;
  1585. }
  1586. if ((u1->flags & USER_OWNER) && !(u && (u->flags & USER_OWNER)) &&
  1587. egg_strcasecmp(handle, dcc[idx].nick)) {
  1588. dprintf(idx, STR("You can't change comment on a bot owner.\n"));
  1589. return;
  1590. }
  1591. putlog(LOG_CMDS, "*", STR("#%s# comment %s %s"), dcc[idx].nick, handle, par);
  1592. if (!egg_strcasecmp(par, "none")) {
  1593. dprintf(idx, STR("Okay, comment blanked.\n"));
  1594. set_user(&USERENTRY_COMMENT, u1, NULL);
  1595. return;
  1596. }
  1597. dprintf(idx, STR("Changed comment.\n"));
  1598. update_mod(handle, dcc[idx].nick, "comment", NULL);
  1599. set_user(&USERENTRY_COMMENT, u1, par);
  1600. }
  1601. static void cmd_randstring(struct userrec *u, int idx, char *par)
  1602. {
  1603. int len;
  1604. char *rand;
  1605. if (!par[0])
  1606. return;
  1607. putlog(LOG_CMDS, "*", STR("#%s# randstring %s"), dcc[idx].nick, par);
  1608. len = atoi(par);
  1609. rand = nmalloc(len + 1);
  1610. make_rand_str(rand, len);
  1611. dprintf(idx, STR("string: %s\n"), rand);
  1612. nfree(rand);
  1613. }
  1614. static void cmd_restart(struct userrec *u, int idx, char *par)
  1615. {
  1616. putlog(LOG_CMDS, "*", STR("#%s# restart"), dcc[idx].nick);
  1617. dprintf(idx, STR("To restart just '%die'\n"), dcc_prefix);
  1618. }
  1619. #ifdef HUB
  1620. static void cmd_reload(struct userrec *u, int idx, char *par)
  1621. {
  1622. putlog(LOG_CMDS, "*", STR("#%s# reload"), dcc[idx].nick);
  1623. dprintf(idx, STR("Reloading user file...\n"));
  1624. reload();
  1625. }
  1626. #endif /* HUB */
  1627. static void cmd_die(struct userrec *u, int idx, char *par)
  1628. {
  1629. char s1[1024], s2[1024];
  1630. putlog(LOG_CMDS, "*", STR("#%s# die %s"), dcc[idx].nick, par);
  1631. if (par[0]) {
  1632. egg_snprintf(s1, sizeof s1, STR("BOT SHUTDOWN (%s: %s)"), dcc[idx].nick, par);
  1633. egg_snprintf(s2, sizeof s2, STR("DIE BY %s!%s (%s)"), dcc[idx].nick, dcc[idx].host, par);
  1634. strncpyz(quit_msg, par, 1024);
  1635. } else {
  1636. egg_snprintf(s1, sizeof s1, STR("BOT SHUTDOWN (Authorized by %s)"), dcc[idx].nick);
  1637. egg_snprintf(s2, sizeof s2, STR("DIE BY %s!%s (request)"), dcc[idx].nick, dcc[idx].host);
  1638. strncpyz(quit_msg, dcc[idx].nick, 1024);
  1639. }
  1640. kill_bot(s1, s2);
  1641. }
  1642. static void cmd_debug(struct userrec *u, int idx, char *par)
  1643. {
  1644. putlog(LOG_CMDS, "*", STR("#%s# debug"), dcc[idx].nick);
  1645. debug_mem_to_dcc(idx);
  1646. }
  1647. static void cmd_simul(struct userrec *u, int idx, char *par)
  1648. {
  1649. char *nick;
  1650. int i, ok = 0;
  1651. nick = newsplit(&par);
  1652. if (!par[0]) {
  1653. dprintf(idx, STR("Usage: simul <hand> <text>\n"));
  1654. return;
  1655. }
  1656. if (isowner(nick)) {
  1657. dprintf(idx, STR("Unable to '.simul' permanent owners.\n"));
  1658. return;
  1659. }
  1660. for (i = 0; i < dcc_total; i++)
  1661. if (!egg_strcasecmp(nick, dcc[i].nick) && !ok &&
  1662. (dcc[i].type->flags & DCT_SIMUL)) {
  1663. putlog(LOG_CMDS, "*", STR("#%s# simul %s %s"), dcc[idx].nick, nick, par);
  1664. if (dcc[i].type && dcc[i].type->activity) {
  1665. dcc[i].type->activity(i, par, strlen(par));
  1666. ok = 1;
  1667. }
  1668. }
  1669. if (!ok)
  1670. dprintf(idx, STR("No such user on the party line.\n"));
  1671. }
  1672. #ifdef HUB
  1673. static void cmd_link(struct userrec *u, int idx, char *par)
  1674. {
  1675. char *s;
  1676. int i;
  1677. if (!par[0]) {
  1678. dprintf(idx, STR("Usage: link [some-bot] <new-bot>\n"));
  1679. return;
  1680. }
  1681. putlog(LOG_CMDS, "*", STR("#%s# link %s"), dcc[idx].nick, par);
  1682. s = newsplit(&par);
  1683. if (!par[0] || !egg_strcasecmp(par, botnetnick))
  1684. botlink(dcc[idx].nick, idx, s);
  1685. else {
  1686. char x[40];
  1687. i = nextbot(s);
  1688. if (i < 0) {
  1689. dprintf(idx, STR("No such bot online.\n"));
  1690. return;
  1691. }
  1692. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1693. botnet_send_link(i, x, s, par);
  1694. }
  1695. }
  1696. #endif /* HUB */
  1697. static void cmd_unlink(struct userrec *u, int idx, char *par)
  1698. {
  1699. int i;
  1700. char *bot;
  1701. if (!par[0]) {
  1702. dprintf(idx, STR("Usage: unlink <bot> [reason]\n"));
  1703. return;
  1704. }
  1705. putlog(LOG_CMDS, "*", STR("#%s# unlink %s"), dcc[idx].nick, par);
  1706. bot = newsplit(&par);
  1707. i = nextbot(bot);
  1708. if (i < 0) {
  1709. botunlink(idx, bot, par);
  1710. return;
  1711. }
  1712. /* If we're directly connected to that bot, just do it
  1713. * (is nike gunna sue?)
  1714. */
  1715. if (!egg_strcasecmp(dcc[i].nick, bot))
  1716. botunlink(idx, bot, par);
  1717. else {
  1718. char x[40];
  1719. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1720. botnet_send_unlink(i, x, lastbot(bot), bot, par);
  1721. }
  1722. }
  1723. static void cmd_relay(struct userrec *u, int idx, char *par)
  1724. {
  1725. if (!par[0]) {
  1726. dprintf(idx, STR("Usage: relay <bot>\n"));
  1727. return;
  1728. }
  1729. putlog(LOG_CMDS, "*", STR("#%s# relay %s"), dcc[idx].nick, par);
  1730. tandem_relay(idx, par, 0);
  1731. }
  1732. #ifdef HUB
  1733. static void cmd_save(struct userrec *u, int idx, char *par)
  1734. {
  1735. char buf[100], i = 0;
  1736. putlog(LOG_CMDS, "*", STR("#%s# save"), dcc[idx].nick);
  1737. sprintf(buf, "Saving user file...");
  1738. i = write_userfile(-1);
  1739. if (i == 0)
  1740. strcat(buf, "success.");
  1741. else if (i == 1)
  1742. strcat(buf, "failed: No userlist.");
  1743. else if (i == 2)
  1744. strcat(buf, "failed: Cannot open userfile for writing.");
  1745. else if (i == 3)
  1746. strcat(buf, "failed: Problem writing users/chans (see debug).");
  1747. else /* This can't happen. */
  1748. strcat(buf, "failed: Unforseen error");
  1749. buf[99] = 0;
  1750. dprintf(idx, "%s\n", buf);
  1751. }
  1752. static void cmd_backup(struct userrec *u, int idx, char *par)
  1753. {
  1754. putlog(LOG_CMDS, "*", STR("#%s# backup"), dcc[idx].nick);
  1755. dprintf(idx, STR("Backing up the channel & user files...\n"));
  1756. call_hook(HOOK_BACKUP);
  1757. }
  1758. static void cmd_trace(struct userrec *u, int idx, char *par)
  1759. {
  1760. int i;
  1761. char x[NOTENAMELEN + 11], y[11];
  1762. if (!par[0]) {
  1763. dprintf(idx, STR("Usage: trace <botname>\n"));
  1764. return;
  1765. }
  1766. if (!egg_strcasecmp(par, botnetnick)) {
  1767. dprintf(idx, STR("That's me! Hiya! :)\n"));
  1768. return;
  1769. }
  1770. i = nextbot(par);
  1771. if (i < 0) {
  1772. dprintf(idx, STR("Unreachable bot.\n"));
  1773. return;
  1774. }
  1775. putlog(LOG_CMDS, "*", STR("#%s# trace %s"), dcc[idx].nick, par);
  1776. simple_sprintf(x, "%d:%s@%s", dcc[idx].sock, dcc[idx].nick, botnetnick);
  1777. simple_sprintf(y, ":%d", now);
  1778. botnet_send_trace(i, x, par, y);
  1779. }
  1780. static void cmd_binds(struct userrec *u, int idx, char *par)
  1781. {
  1782. putlog(LOG_CMDS, "*", STR("#%s# binds %s"), dcc[idx].nick, par);
  1783. tell_binds(idx, par);
  1784. }
  1785. #endif /* HUB */
  1786. /* After messing with someone's user flags, make sure the dcc-chat flags
  1787. * are set correctly.
  1788. */
  1789. int check_dcc_attrs(struct userrec *u, int oatr)
  1790. {
  1791. int i, stat;
  1792. if (!u)
  1793. return 0;
  1794. /* Make sure default owners are +a */
  1795. if (isowner(u->handle)) {
  1796. u->flags = sanity_check(u->flags | USER_ADMIN);
  1797. }
  1798. for (i = 0; i < dcc_total; i++) {
  1799. if ((dcc[i].type->flags & DCT_MASTER) &&
  1800. (!egg_strcasecmp(u->handle, dcc[i].nick))) {
  1801. stat = dcc[i].status;
  1802. if ((dcc[i].type == &DCC_CHAT) &&
  1803. ((u->flags & (USER_OP | USER_MASTER | USER_OWNER))
  1804. != (oatr & (USER_OP | USER_MASTER | USER_OWNER)))) {
  1805. botnet_send_join_idx(i, -1);
  1806. }
  1807. if ((oatr & USER_MASTER) && !(u->flags & USER_MASTER)) {
  1808. struct flag_record fr = {FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  1809. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS | LOG_RAW |
  1810. LOG_FILES | LOG_WALL | LOG_DEBUG);
  1811. get_user_flagrec(u, &fr, NULL);
  1812. if (!chan_master(fr))
  1813. dcc[i].u.chat->con_flags |= (LOG_MISC | LOG_CMDS);
  1814. dprintf(i, STR("*** POOF! ***\n"));
  1815. dprintf(i, STR("You are no longer a master on this bot.\n"));
  1816. }
  1817. if (!(oatr & USER_MASTER) && (u->flags & USER_MASTER)) {
  1818. dcc[i].u.chat->con_flags |= conmask;
  1819. dprintf(i, STR("*** POOF! ***\n"));
  1820. dprintf(i, STR("You are now a master on this bot.\n"));
  1821. }
  1822. if (!(oatr & USER_PARTY) && (u->flags & USER_PARTY) && dcc[i].u.chat->channel < 0) {
  1823. dprintf(i, "-+- POOF! -+-\n");
  1824. dprintf(i, STR("You now have party line chat access.\n"));
  1825. dprintf(i, STR("To rejoin the partyline, type: %schat on\n"), dcc_prefix);
  1826. }
  1827. if (!(oatr & USER_OWNER) && (u->flags & USER_OWNER)) {
  1828. dprintf(i, STR("@@@ POOF! @@@\n"));
  1829. dprintf(i, STR("You are now an OWNER of this bot.\n"));
  1830. }
  1831. if ((oatr & USER_OWNER) && !(u->flags & USER_OWNER)) {
  1832. dprintf(i, STR("@@@ POOF! @@@\n"));
  1833. dprintf(i, STR("You are no longer an owner of this bot.\n"));
  1834. }
  1835. if (!(u->flags & USER_PARTY) && dcc[i].u.chat->channel >= 0) { //who cares about old flags, they shouldnt be here anyway.
  1836. dprintf(i, STR("-+- POOF! -+-\n"));
  1837. dprintf(i, STR("You no longer have party line chat access.\n"));
  1838. dprintf(i, STR("Leaving chat mode...\n"));
  1839. chanout_but(-1, dcc[i].u.chat->channel, STR("*** %s left the party line - no chat access.\n"), dcc[i].nick);
  1840. if (dcc[i].u.chat->channel < 100000)
  1841. botnet_send_part_idx(i, "");
  1842. dcc[i].u.chat->channel = (-1);
  1843. }
  1844. if (!(oatr & USER_ADMIN) && (u->flags & USER_ADMIN)) {
  1845. dprintf(i, STR("^^^ POOF! ^^^\n"));
  1846. dprintf(i, STR("You are now an ADMIN of this bot.\n"));
  1847. }
  1848. if ((oatr & USER_ADMIN) && !(u->flags & USER_ADMIN)) {
  1849. dprintf(i, STR("^^^ POOF! ^^^\n"));
  1850. dprintf(i, STR("You are no longer an admin of this bot.\n"));
  1851. }
  1852. if ((stat & STAT_PARTY) && (u->flags & USER_OP))
  1853. stat &= ~STAT_PARTY;
  1854. if (!(stat & STAT_PARTY) && !(u->flags & USER_OP) &&
  1855. !(u->flags & USER_MASTER))
  1856. stat |= STAT_PARTY;
  1857. if (stat & STAT_CHAT) {
  1858. #ifdef HUB
  1859. if (!(u->flags & USER_HUBA))
  1860. stat &= ~STAT_CHAT;
  1861. #endif /* HUB */
  1862. if (ischanhub() && !(u->flags & USER_CHUBA))
  1863. stat &= ~STAT_CHAT;
  1864. }
  1865. if ((u->flags & USER_PARTY))
  1866. stat |= STAT_CHAT;
  1867. dcc[i].status = stat;
  1868. /* Check if they no longer have access to wherever they are.
  1869. */
  1870. #ifdef HUB
  1871. if (!(u->flags & (USER_HUBA))) {
  1872. /* no hub access, drop them. */
  1873. dprintf(i, STR("-+- POOF! -+-\n"));
  1874. dprintf(i, STR("You no longer have hub access.\n\n"));
  1875. do_boot(i, botnetnick, STR("No hub access.\n\n"));
  1876. }
  1877. #else /* !HUB */
  1878. if (ischanhub() && !(u->flags & (USER_CHUBA))) {
  1879. /* no chanhub access, drop them. */
  1880. dprintf(i, STR("-+- POOF! -+-\n"));
  1881. dprintf(i, STR("You no longer have chathub access.\n\n"));
  1882. do_boot(i, botnetnick, STR("No chathub access.\n\n"));
  1883. }
  1884. #endif /* HUB */
  1885. }
  1886. if (dcc[i].type == &DCC_BOT && !egg_strcasecmp(u->handle, dcc[i].nick)) {
  1887. if ((dcc[i].status & STAT_LEAF) && !(u->flags & BOT_LEAF))
  1888. dcc[i].status &= ~(STAT_LEAF | STAT_WARNED);
  1889. if (!(dcc[i].status & STAT_LEAF) && (u->flags & BOT_LEAF))
  1890. dcc[i].status |= STAT_LEAF;
  1891. }
  1892. }
  1893. return u->flags;
  1894. }
  1895. int check_dcc_chanattrs(struct userrec *u, char *chname, int chflags, int ochatr)
  1896. {
  1897. int i, found = 0, atr = u ? u->flags : 0;
  1898. struct chanset_t *chan;
  1899. if (!u)
  1900. return 0;
  1901. for (i = 0; i < dcc_total; i++) {
  1902. if ((dcc[i].type->flags & DCT_MASTER) &&
  1903. !egg_strcasecmp(u->handle, dcc[i].nick)) {
  1904. if ((dcc[i].type == &DCC_CHAT) &&
  1905. ((chflags & (USER_OP | USER_MASTER | USER_OWNER))
  1906. != (ochatr & (USER_OP | USER_MASTER | USER_OWNER))))
  1907. botnet_send_join_idx(i, -1);
  1908. if ((ochatr & USER_MASTER) && !(chflags & USER_MASTER)) {
  1909. if (!(atr & USER_MASTER))
  1910. dcc[i].u.chat->con_flags &= ~(LOG_MISC | LOG_CMDS);
  1911. dprintf(i, STR("*** POOF! ***\n"));
  1912. dprintf(i, STR("You are no longer a master on %s.\n"), chname);
  1913. }
  1914. if (!(ochatr & USER_MASTER) && (chflags & USER_MASTER)) {
  1915. dcc[i].u.chat->con_flags |= conmask;
  1916. if (!(atr & USER_MASTER))
  1917. dcc[i].u.chat->con_flags &=
  1918. ~(LOG_RAW | LOG_DEBUG | LOG_WALL | LOG_FILES | LOG_SRVOUT);
  1919. dprintf(i, STR("*** POOF! ***\n"));
  1920. dprintf(i, STR("You are now a master on %s.\n"), chname);
  1921. }
  1922. if (!(ochatr & USER_OWNER) && (chflags & USER_OWNER)) {
  1923. dprintf(i, STR("@@@ POOF! @@@\n"));
  1924. dprintf(i, STR("You are now an OWNER of %s.\n"), chname);
  1925. }
  1926. if ((ochatr & USER_OWNER) && !(chflags & USER_OWNER)) {
  1927. dprintf(i, STR("@@@ POOF! @@@\n"));
  1928. dprintf(i, STR("You are no longer an owner of %s.\n"), chname);
  1929. }
  1930. if (((ochatr & (USER_OP | USER_MASTER | USER_OWNER)) &&
  1931. (!(chflags & (USER_OP | USER_MASTER | USER_OWNER)))) ||
  1932. ((chflags & (USER_OP | USER_MASTER | USER_OWNER)) &&
  1933. (!(ochatr & (USER_OP | USER_MASTER | USER_OWNER))))) {
  1934. struct flag_record fr = {FR_CHAN, 0, 0, 0, 0, 0};
  1935. for (chan = chanset; chan && !found; chan = chan->next) {
  1936. get_user_flagrec(u, &fr, chan->dname);
  1937. if (fr.chan & (USER_OP | USER_MASTER | USER_OWNER))
  1938. found = 1;
  1939. }
  1940. if (!chan)
  1941. chan = chanset;
  1942. if (chan)
  1943. strcpy(dcc[i].u.chat->con_chan, chan->dname);
  1944. else
  1945. strcpy(dcc[i].u.chat->con_chan, "*");
  1946. }
  1947. }
  1948. }
  1949. return chflags;
  1950. }
  1951. static void cmd_chattr(struct userrec *u, int idx, char *par)
  1952. {
  1953. char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
  1954. struct chanset_t *chan = NULL;
  1955. struct userrec *u2;
  1956. struct flag_record pls = {0, 0, 0, 0, 0, 0},
  1957. mns = {0, 0, 0, 0, 0, 0},
  1958. user = {0, 0, 0, 0, 0, 0},
  1959. ouser = {0, 0, 0, 0, 0, 0};
  1960. module_entry *me;
  1961. int fl = -1, of = 0, ocf = 0;
  1962. if (!par[0]) {
  1963. dprintf(idx, STR("Usage: chattr <handle> [changes] [channel]\n"));
  1964. return;
  1965. }
  1966. hand = newsplit(&par);
  1967. u2 = get_user_by_handle(userlist, hand);
  1968. if (!u2) {
  1969. dprintf(idx, STR("No such user!\n"));
  1970. return;
  1971. }
  1972. /* Parse args */
  1973. if (par[0]) {
  1974. arg = newsplit(&par);
  1975. if (par[0]) {
  1976. /* .chattr <handle> <changes> <channel> */
  1977. chg = arg;
  1978. arg = newsplit(&par);
  1979. chan = findchan_by_dname(arg);
  1980. } else {
  1981. chan = findchan_by_dname(arg);
  1982. /* Consider modeless channels, starting with '+' */
  1983. if (!(arg[0] == '+' && chan) &&
  1984. !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
  1985. /* .chattr <handle> <changes> */
  1986. chg = arg;
  1987. chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
  1988. arg = NULL;
  1989. }
  1990. /* .chattr <handle> <channel>: nothing to do... */
  1991. }
  1992. }
  1993. /* arg: pointer to channel name, NULL if none specified
  1994. * chan: pointer to channel structure, NULL if none found or none specified
  1995. * chg: pointer to changes, NULL if none specified
  1996. */
  1997. Assert(!(!arg && chan));
  1998. if (arg && !chan) {
  1999. dprintf(idx, STR("No channel record for %s.\n"), arg);
  2000. return;
  2001. }
  2002. if (chg) {
  2003. if (!arg && strpbrk(chg, "&|")) {
  2004. /* .chattr <handle> *[&|]*: use console channel if found... */
  2005. if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
  2006. arg = NULL;
  2007. else
  2008. chan = findchan_by_dname(arg);
  2009. if (arg && !chan) {
  2010. dprintf (idx, STR("Invalid console channel %s.\n"), arg);
  2011. return;
  2012. }
  2013. } else if (arg && !strpbrk(chg, "&|")) {
  2014. tmpchg = nmalloc(strlen(chg) + 2);
  2015. strcpy(tmpchg, "|");
  2016. strcat(tmpchg, chg);
  2017. chg = tmpchg;
  2018. }
  2019. }
  2020. par = arg;
  2021. user.match = FR_GLOBAL;
  2022. if (chan)
  2023. user.match |= FR_CHAN;
  2024. get_user_flagrec(u, &user, chan ? chan->dname : 0);
  2025. get_user_flagrec(u2, &ouser, chan ? chan->dname : 0);
  2026. if (chan && !glob_master(user) && !chan_master(user)) {
  2027. dprintf(idx, STR("You do not have channel master privileges for channel %s.\n"),
  2028. par);
  2029. if (tmpchg)
  2030. nfree(tmpchg);
  2031. return;
  2032. }
  2033. if (chan && private(user, chan, PRIV_OP)) {
  2034. dprintf(idx, STR("You do not have access to change flags for %s\n"), chan->dname);
  2035. if (tmpchg)
  2036. nfree(tmpchg);
  2037. return;
  2038. }
  2039. user.match &= fl;
  2040. if (chg) {
  2041. pls.match = user.match;
  2042. break_down_flags(chg, &pls, &mns);
  2043. /* No-one can change these flags on-the-fly */
  2044. pls.global &= ~(USER_BOT);
  2045. mns.global &= ~(USER_BOT);
  2046. if ((pls.global & USER_UPDATEHUB) && (bot_hublevel(u2) == 999)) {
  2047. dprintf(idx, STR("Only a hub can be set as the updatehub.\n"));
  2048. pls.global &= ~(USER_UPDATEHUB);
  2049. }
  2050. /* strip out +p without +i or +j */
  2051. if (((pls.global & USER_PARTY) && !(pls.global & USER_CHUBA) && !(pls.global & USER_HUBA)) && (!glob_huba(ouser) && !glob_chuba(ouser))) {
  2052. dprintf(idx, "Global flag +p requires either chathub or hub access first.\n");
  2053. pls.global &= ~USER_PARTY;
  2054. }
  2055. if (!isowner(u->handle)) {
  2056. if (pls.global & USER_HUBA)
  2057. putlog(LOG_MISC, "*", STR("%s attempted to give %s hub connect access"), dcc[idx].nick, u2->handle);
  2058. if (mns.global & USER_HUBA)
  2059. putlog(LOG_MISC, "*", STR("%s attempted to take away hub connect access from %s"), dcc[idx].nick, u2->handle);
  2060. if (pls.global & USER_UPDATEHUB)
  2061. putlog(LOG_MISC, "*", STR("%s attempted to make %s the updatehub"), dcc[idx].nick, u2->handle);
  2062. if (mns.global & USER_UPDATEHUB)
  2063. putlog(LOG_MISC, "*", STR("%s attempted to take away updatehub status from %s"), dcc[idx].nick, u2->handle);
  2064. if (pls.global & USER_ADMIN)
  2065. putlog(LOG_MISC, "*", STR("%s attempted to give %s admin access"), dcc[idx].nick, u2->handle);
  2066. if (mns.global & USER_ADMIN)
  2067. putlog(LOG_MISC, "*", STR("%s attempted to take away admin access from %s"), dcc[idx].nick, u2->handle);
  2068. if (pls.global & USER_OWNER)
  2069. putlog(LOG_MISC, "*", STR("%s attempted to give owner to %s"), dcc[idx].nick, u2->handle);
  2070. if (mns.global & USER_OWNER)
  2071. putlog(LOG_MISC, "*", STR("%s attempted to take owner away from %s"), dcc[idx].nick, u2->handle);
  2072. pls.global &=~(USER_HUBA | USER_ADMIN | USER_OWNER | USER_UPDATEHUB);
  2073. mns.global &=~(USER_HUBA | USER_ADMIN | USER_OWNER | USER_UPDATEHUB);
  2074. pls.chan &= ~(USER_ADMIN | USER_UPDATEHUB);
  2075. }
  2076. if (chan) {
  2077. pls.chan &= ~(BOT_SHARE | USER_HUBA | USER_CHUBA);
  2078. mns.chan &= ~(BOT_SHARE | USER_HUBA | USER_CHUBA);
  2079. }
  2080. if (!glob_owner(user) && !isowner(u->handle)) {
  2081. pls.global &= ~(USER_CHUBA | USER_OWNER | USER_MASTER | USER_UNSHARED);
  2082. mns.global &= ~(USER_CHUBA | USER_OWNER | USER_MASTER | USER_UNSHARED);
  2083. if (chan) {
  2084. pls.chan &= ~USER_OWNER;
  2085. mns.chan &= ~USER_OWNER;
  2086. }
  2087. }
  2088. if (chan && !chan_owner(user) && !glob_owner(user) && !isowner(u->handle)) {
  2089. pls.chan &= ~USER_MASTER;
  2090. mns.chan &= ~USER_MASTER;
  2091. if (!chan_master(user) && !glob_master(user)) {
  2092. pls.chan = 0;
  2093. mns.chan = 0;
  2094. }
  2095. }
  2096. #ifdef LEAF
  2097. pls.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  2098. mns.global &=~(USER_OWNER | USER_ADMIN | USER_HUBA | USER_CHUBA);
  2099. #endif /* LEAF */
  2100. get_user_flagrec(u2, &user, par);
  2101. if (user.match & FR_GLOBAL) {
  2102. of = user.global;
  2103. user.global = sanity_check((user.global |pls.global) &~mns.global);
  2104. user.udef_global = (user.udef_global | pls.udef_global)
  2105. & ~mns.udef_global;
  2106. }
  2107. if (chan) {
  2108. ocf = user.chan;
  2109. user.chan = chan_sanity_check((user.chan | pls.chan) & ~mns.chan,
  2110. user.global);
  2111. user.udef_chan = (user.udef_chan | pls.udef_chan) & ~mns.udef_chan;
  2112. }
  2113. set_user_flagrec(u2, &user, par);
  2114. }
  2115. if (chan) {
  2116. char tmp[100];
  2117. putlog(LOG_CMDS, "*", STR("#%s# (%s) chattr %s %s"), dcc[idx].nick, chan ? chan->dname : "*", hand, chg ? chg : "");
  2118. snprintf(tmp, sizeof tmp, "chattr %s", chg);
  2119. update_mod(hand, dcc[idx].nick, tmp, chan->dname);
  2120. } else {
  2121. putlog(LOG_CMDS, "*", STR("#%s# chattr %s %s"), dcc[idx].nick, hand, chg ? chg : "");
  2122. update_mod(hand, dcc[idx].nick, "chattr", chg);
  2123. }
  2124. /* Get current flags and display them */
  2125. if (user.match & FR_GLOBAL) {
  2126. user.match = FR_GLOBAL;
  2127. if (chg)
  2128. check_dcc_attrs(u2, of);
  2129. get_user_flagrec(u2, &user, NULL);
  2130. build_flags(work, &user, NULL);
  2131. if (work[0] != '-')
  2132. dprintf(idx, STR("Global flags for %s are now +%s.\n"), hand, work);
  2133. else
  2134. dprintf(idx, STR("No global flags for %s.\n"), hand);
  2135. }
  2136. if (chan) {
  2137. user.match = FR_CHAN;
  2138. get_user_flagrec(u2, &user, par);
  2139. user.chan &= ~BOT_SHARE;
  2140. if (chg)
  2141. check_dcc_chanattrs(u2, chan->dname, user.chan, ocf);
  2142. build_flags(work, &user, NULL);
  2143. if (work[0] != '-')
  2144. dprintf(idx, STR("Channel flags for %s on %s are now +%s.\n"), hand,
  2145. chan->dname, work);
  2146. else
  2147. dprintf(idx, STR("No flags for %s on %s.\n"), hand, chan->dname);
  2148. }
  2149. if (chg && (me = module_find("irc", 0, 0))) {
  2150. Function *func = me->funcs;
  2151. (func[IRC_CHECK_THIS_USER]) (hand, 0, NULL);
  2152. }
  2153. if (tmpchg)
  2154. nfree(tmpchg);
  2155. }
  2156. static void cmd_chat(struct userrec *u, int idx, char *par)
  2157. {
  2158. char *arg;
  2159. int newchan, oldchan;
  2160. module_entry *me;
  2161. if (!(u->flags & USER_PARTY)) {
  2162. dprintf(idx, STR("You don't have partyline access\n"));
  2163. return;
  2164. }
  2165. arg = newsplit(&par);
  2166. if (!egg_strcasecmp(arg, "off")) {
  2167. /* Turn chat off */
  2168. if (dcc[idx].u.chat->channel < 0) {
  2169. dprintf(idx, STR("You weren't in chat anyway!\n"));
  2170. return;
  2171. } else {
  2172. dprintf(idx, STR("Leaving chat mode...\n"));
  2173. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock,
  2174. dcc[idx].u.chat->channel);
  2175. chanout_but(-1, dcc[idx].u.chat->channel,
  2176. "*** %s left the party line.\n",
  2177. dcc[idx].nick);
  2178. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2179. botnet_send_part_idx(idx, "");
  2180. }
  2181. dcc[idx].u.chat->channel = (-1);
  2182. } else {
  2183. if (arg[0] == '*') {
  2184. if (((arg[1] < '0') || (arg[1] > '9'))) {
  2185. if (!arg[1])
  2186. newchan = 0;
  2187. else {
  2188. Tcl_SetVar(interp, "chan", arg, 0);
  2189. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  2190. interp->result[0])
  2191. newchan = atoi(interp->result);
  2192. else
  2193. newchan = -1;
  2194. }
  2195. if (newchan < 0) {
  2196. dprintf(idx, STR("No channel exists by that name.\n"));
  2197. return;
  2198. }
  2199. } else
  2200. newchan = GLOBAL_CHANS + atoi(arg + 1);
  2201. if (newchan < GLOBAL_CHANS || newchan > 199999) {
  2202. dprintf(idx, STR("Channel number out of range: local channels must be *0-*99999.\n"));
  2203. return;
  2204. }
  2205. } else {
  2206. if (((arg[0] < '0') || (arg[0] > '9')) && (arg[0])) {
  2207. if (!egg_strcasecmp(arg, "on"))
  2208. newchan = 0;
  2209. else {
  2210. Tcl_SetVar(interp, "chan", arg, 0);
  2211. if ((Tcl_VarEval(interp, "assoc ", "$chan", NULL) == TCL_OK) &&
  2212. interp->result[0])
  2213. newchan = atoi(interp->result);
  2214. else
  2215. newchan = -1;
  2216. }
  2217. if (newchan < 0) {
  2218. dprintf(idx, STR("No channel exists by that name.\n"));
  2219. return;
  2220. }
  2221. } else
  2222. newchan = atoi(arg);
  2223. if ((newchan < 0) || (newchan > 99999)) {
  2224. dprintf(idx, STR("Channel number out of range: must be between 0 and 99999.\n"));
  2225. return;
  2226. }
  2227. }
  2228. /* If coming back from being off the party line, make sure they're
  2229. * not away.
  2230. */
  2231. if ((dcc[idx].u.chat->channel < 0) && (dcc[idx].u.chat->away != NULL))
  2232. not_away(idx);
  2233. if (dcc[idx].u.chat->channel == newchan) {
  2234. if (!newchan) {
  2235. dprintf(idx, STR("You're already on the party line!\n"));
  2236. return;
  2237. } else {
  2238. dprintf(idx, STR("You're already on channel %s%d!\n"),
  2239. (newchan < GLOBAL_CHANS) ? "" : "*", newchan % GLOBAL_CHANS);
  2240. return;
  2241. }
  2242. } else {
  2243. oldchan = dcc[idx].u.chat->channel;
  2244. if (oldchan >= 0)
  2245. check_tcl_chpt(botnetnick, dcc[idx].nick, dcc[idx].sock, oldchan);
  2246. if (!oldchan) {
  2247. chanout_but(-1, 0, "*** %s left the party line.\n", dcc[idx].nick);
  2248. } else if (oldchan > 0) {
  2249. chanout_but(-1, oldchan, "*** %s left the channel.\n", dcc[idx].nick);
  2250. }
  2251. dcc[idx].u.chat->channel = newchan;
  2252. if (!newchan) {
  2253. dprintf(idx, STR("Entering the party line...\n"));
  2254. chanout_but(-1, 0, "*** %s joined the party line.\n", dcc[idx].nick);
  2255. } else {
  2256. dprintf(idx, STR("Joining channel '%s'...\n"), arg);
  2257. chanout_but(-1, newchan, "*** %s joined the channel.\n", dcc[idx].nick);
  2258. }
  2259. check_tcl_chjn(botnetnick, dcc[idx].nick, newchan, geticon(idx),
  2260. dcc[idx].sock, dcc[idx].host);
  2261. if (newchan < GLOBAL_CHANS)
  2262. botnet_send_join_idx(idx, oldchan);
  2263. else if (oldchan < GLOBAL_CHANS)
  2264. botnet_send_part_idx(idx, "");
  2265. }
  2266. }
  2267. /* New style autosave here too -- rtc, 09/28/1999*/
  2268. if ((me = module_find("console", 0, 0))) {
  2269. Function *func = me->funcs;
  2270. (func[CONSOLE_DOSTORE]) (idx);
  2271. }
  2272. }
  2273. int exec_str(int idx, char *cmd) {
  2274. char *out, *err, *p, *np;
  2275. if (shell_exec(cmd, NULL, &out, &err)) {
  2276. if (out) {
  2277. dprintf(idx, STR("Result:\n"));
  2278. p=out;
  2279. while (p && p[0]) {
  2280. np=strchr(p, '\n');
  2281. if (np)
  2282. *np++=0;
  2283. dprintf(idx, STR("%s\n"), p);
  2284. p=np;
  2285. }
  2286. dprintf(idx, "\n");
  2287. nfree(out);
  2288. }
  2289. if (err) {
  2290. dprintf(idx, STR("Errors:\n"));
  2291. p=err;
  2292. while (p && p[0]) {
  2293. np=strchr(p, '\n');
  2294. if (np)
  2295. *np++=0;
  2296. dprintf(idx, STR("%s\n"), p);
  2297. p=np;
  2298. }
  2299. dprintf(idx, "\n");
  2300. nfree(err);
  2301. }
  2302. return 1;
  2303. }
  2304. return 0;
  2305. }
  2306. static void cmd_exec(struct userrec *u, int idx, char *par) {
  2307. putlog(LOG_CMDS, "*", STR("#%s# exec %s"), dcc[idx].nick, par);
  2308. #ifdef LEAF
  2309. if (!isowner(u->handle)) {
  2310. putlog(LOG_WARN, "*", STR("%s attempted 'exec' %s"), dcc[idx].nick, par);
  2311. dprintf(idx, STR("exec is only available to permanent owners on leaf bots\n"));
  2312. return;
  2313. }
  2314. #endif /* LEAF */
  2315. if (exec_str(idx, par))
  2316. dprintf(idx, STR("Exec completed\n"));
  2317. else
  2318. dprintf(idx, STR("Exec failed\n"));
  2319. }
  2320. static void cmd_w(struct userrec *u, int idx, char *par) {
  2321. putlog(LOG_CMDS, "*", STR("#%s# w"), dcc[idx].nick);
  2322. if (!exec_str(idx, "w"))
  2323. dprintf(idx, STR("Exec failed\n"));
  2324. }
  2325. static void cmd_ps(struct userrec *u, int idx, char *par) {
  2326. char * buf;
  2327. putlog(LOG_CMDS, "*", STR("#%s# ps %s"), dcc[idx].nick, par);
  2328. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  2329. putlog(LOG_WARN, "*", STR("%s attempted 'ps' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  2330. dprintf(idx, STR("No."));
  2331. return;
  2332. }
  2333. buf=nmalloc(strlen(par)+4);
  2334. sprintf(buf, STR("ps %s"), par);
  2335. if (!exec_str(idx, buf))
  2336. dprintf(idx, STR("Exec failed\n"));
  2337. nfree(buf);
  2338. }
  2339. static void cmd_last(struct userrec *u, int idx, char *par) {
  2340. char user[20], buf[30];
  2341. struct passwd *pw;
  2342. putlog(LOG_CMDS, "*", STR("#%s# last %s"), dcc[idx].nick, par);
  2343. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  2344. putlog(LOG_WARN, "*", STR("%s attempted 'last' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  2345. dprintf(idx, STR("No."));
  2346. return;
  2347. }
  2348. if (par[0]) {
  2349. strncpyz(user, par, sizeof(user));
  2350. } else {
  2351. pw = getpwuid(geteuid());
  2352. if (!pw)
  2353. return;
  2354. strncpyz(user, pw->pw_name, sizeof(user));
  2355. }
  2356. if (!user[0]) {
  2357. dprintf(idx, STR("Can't determine user id for process\n"));
  2358. return;
  2359. }
  2360. sprintf(buf, STR("last %s"), user);
  2361. if (!exec_str(idx, buf))
  2362. dprintf(idx, STR("Failed to execute /bin/sh last\n"));
  2363. }
  2364. static void cmd_echo(struct userrec *u, int idx, char *par)
  2365. {
  2366. module_entry *me;
  2367. if (!par[0]) {
  2368. dprintf(idx, STR("Echo is currently %s.\n"), dcc[idx].status & STAT_ECHO ?
  2369. "on" : "off");
  2370. return;
  2371. }
  2372. if (!egg_strcasecmp(par, "on")) {
  2373. dprintf(idx, STR("Echo turned on.\n"));
  2374. dcc[idx].status |= STAT_ECHO;
  2375. } else if (!egg_strcasecmp(par, "off")) {
  2376. dprintf(idx, STR("Echo turned off.\n"));
  2377. dcc[idx].status &= ~STAT_ECHO;
  2378. } else {
  2379. dprintf(idx, STR("Usage: echo <on/off>\n"));
  2380. return;
  2381. }
  2382. /* New style autosave here too -- rtc, 09/28/1999*/
  2383. if ((me = module_find("console", 0, 0))) {
  2384. Function *func = me->funcs;
  2385. (func[CONSOLE_DOSTORE]) (idx);
  2386. }
  2387. }
  2388. static void cmd_color(struct userrec *u, int idx, char *par)
  2389. {
  2390. module_entry *me;
  2391. char *type, *of;
  2392. putlog(LOG_CMDS, "*", STR("#%s# color %s"), dcc[idx].nick, par);
  2393. if (!par[0]) {
  2394. dprintf(idx, STR("Usage: color <on/off> <mIRC/ANSI>\n"));
  2395. if (dcc[idx].status & STAT_COLOR)
  2396. dprintf(idx, STR("Color is currently on (%s).\n"), dcc[idx].status & STAT_COLORM ? "mIRC" : "ANSI");
  2397. else
  2398. dprintf(idx, STR("Color is currently off.\n"));
  2399. return;
  2400. }
  2401. of = newsplit(&par);
  2402. type = newsplit(&par);
  2403. if (!egg_strcasecmp(of, "on")) {
  2404. if (!type) {
  2405. dprintf(idx, STR("Usage: color <on/off> <mIRC/ANSI>\n"));
  2406. return;
  2407. }
  2408. if (!egg_strcasecmp(type, "mirc")) {
  2409. dcc[idx].status &= ~STAT_COLORA;
  2410. dcc[idx].status |= (STAT_COLOR | STAT_COLORM);
  2411. dprintf(idx, STR("Color turned on (mIRC).\n"));
  2412. } else if (!egg_strcasecmp(type, "ansi")) {
  2413. dcc[idx].status &= ~STAT_COLORM;
  2414. dcc[idx].status |= (STAT_COLOR | STAT_COLORA);
  2415. dprintf(idx, STR("Color turned on (ANSI).\n"));
  2416. } else {
  2417. return;
  2418. }
  2419. } else if (!egg_strcasecmp(of, "off")) {
  2420. dcc[idx].status &= ~(STAT_COLOR | STAT_COLORM | STAT_COLORA);
  2421. dprintf(idx, STR("Color turned off.\n"));
  2422. } else {
  2423. return;
  2424. }
  2425. /* New style autosave here too -- rtc, 09/28/1999*/
  2426. if ((me = module_find("console", 0, 0))) {
  2427. Function *func = me->funcs;
  2428. (func[CONSOLE_DOSTORE]) (idx);
  2429. }
  2430. }
  2431. int stripmodes(char *s)
  2432. {
  2433. int res = 0;
  2434. for (; *s; s++)
  2435. switch (tolower(*s)) {
  2436. case 'b':
  2437. res |= STRIP_BOLD;
  2438. break;
  2439. case 'c':
  2440. res |= STRIP_COLOR;
  2441. break;
  2442. case 'r':
  2443. res |= STRIP_REV;
  2444. break;
  2445. case 'u':
  2446. res |= STRIP_UNDER;
  2447. break;
  2448. case 'a':
  2449. res |= STRIP_ANSI;
  2450. break;
  2451. case 'g':
  2452. res |= STRIP_BELLS;
  2453. break;
  2454. case '*':
  2455. res |= STRIP_ALL;
  2456. break;
  2457. }
  2458. return res;
  2459. }
  2460. char *stripmasktype(int x)
  2461. {
  2462. static char s[20];
  2463. char *p = s;
  2464. if (x & STRIP_BOLD)
  2465. *p++ = 'b';
  2466. if (x & STRIP_COLOR)
  2467. *p++ = 'c';
  2468. if (x & STRIP_REV)
  2469. *p++ = 'r';
  2470. if (x & STRIP_UNDER)
  2471. *p++ = 'u';
  2472. if (x & STRIP_ANSI)
  2473. *p++ = 'a';
  2474. if (x & STRIP_BELLS)
  2475. *p++ = 'g';
  2476. if (p == s)
  2477. *p++ = '-';
  2478. *p = 0;
  2479. return s;
  2480. }
  2481. static char *stripmaskname(int x)
  2482. {
  2483. static char s[161];
  2484. int i = 0;
  2485. s[i] = 0;
  2486. if (x & STRIP_BOLD)
  2487. i += my_strcpy(s + i, "bold, ");
  2488. if (x & STRIP_COLOR)
  2489. i += my_strcpy(s + i, "color, ");
  2490. if (x & STRIP_REV)
  2491. i += my_strcpy(s + i, "reverse, ");
  2492. if (x & STRIP_UNDER)
  2493. i += my_strcpy(s + i, "underline, ");
  2494. if (x & STRIP_ANSI)
  2495. i += my_strcpy(s + i, "ansi, ");
  2496. if (x & STRIP_BELLS)
  2497. i += my_strcpy(s + i, "bells, ");
  2498. if (!i)
  2499. strcpy(s, "none");
  2500. else
  2501. s[i - 2] = 0;
  2502. return s;
  2503. }
  2504. static void cmd_strip(struct userrec *u, int idx, char *par)
  2505. {
  2506. char *nick, *changes, *c, s[2];
  2507. int dest = 0, i, pls, md, ok = 0;
  2508. module_entry *me;
  2509. if (!par[0]) {
  2510. dprintf(idx, STR("Your current strip settings are: %s (%s).\n"),
  2511. stripmasktype(dcc[idx].u.chat->strip_flags),
  2512. stripmaskname(dcc[idx].u.chat->strip_flags));
  2513. return;
  2514. }
  2515. nick = newsplit(&par);
  2516. if ((nick[0] != '+') && (nick[0] != '-') && u &&
  2517. (u->flags & USER_MASTER)) {
  2518. for (i = 0; i < dcc_total; i++)
  2519. if (!egg_strcasecmp(nick, dcc[i].nick) && dcc[i].type == &DCC_CHAT &&
  2520. !ok) {
  2521. ok = 1;
  2522. dest = i;
  2523. }
  2524. if (!ok) {
  2525. dprintf(idx, STR("No such user on the party line!\n"));
  2526. return;
  2527. }
  2528. changes = par;
  2529. } else {
  2530. changes = nick;
  2531. nick = "";
  2532. dest = idx;
  2533. }
  2534. c = changes;
  2535. if ((c[0] != '+') && (c[0] != '-'))
  2536. dcc[dest].u.chat->strip_flags = 0;
  2537. s[1] = 0;
  2538. for (pls = 1; *c; c++) {
  2539. switch (*c) {
  2540. case '+':
  2541. pls = 1;
  2542. break;
  2543. case '-':
  2544. pls = 0;
  2545. break;
  2546. default:
  2547. s[0] = *c;
  2548. md = stripmodes(s);
  2549. if (pls == 1)
  2550. dcc[dest].u.chat->strip_flags |= md;
  2551. else
  2552. dcc[dest].u.chat->strip_flags &= ~md;
  2553. }
  2554. }
  2555. if (nick[0])
  2556. putlog(LOG_CMDS, "*", STR("#%s# strip %s %s"), dcc[idx].nick, nick, changes);
  2557. else
  2558. putlog(LOG_CMDS, "*", STR("#%s# strip %s"), dcc[idx].nick, changes);
  2559. if (dest == idx) {
  2560. dprintf(idx, STR("Your strip settings are: %s (%s).\n"),
  2561. stripmasktype(dcc[idx].u.chat->strip_flags),
  2562. stripmaskname(dcc[idx].u.chat->strip_flags));
  2563. } else {
  2564. dprintf(idx, STR("Strip setting for %s: %s (%s).\n"), dcc[dest].nick,
  2565. stripmasktype(dcc[dest].u.chat->strip_flags),
  2566. stripmaskname(dcc[dest].u.chat->strip_flags));
  2567. dprintf(dest, STR("%s set your strip settings to: %s (%s).\n"), dcc[idx].nick,
  2568. stripmasktype(dcc[dest].u.chat->strip_flags),
  2569. stripmaskname(dcc[dest].u.chat->strip_flags));
  2570. }
  2571. /* Set highlight flag here so user is able to control stripping of
  2572. * bold also as intended -- dw 27/12/1999
  2573. */
  2574. /* New style autosave here too -- rtc, 09/28/1999*/
  2575. if ((me = module_find("console", 0, 0))) {
  2576. Function *func = me->funcs;
  2577. (func[CONSOLE_DOSTORE]) (dest);
  2578. }
  2579. }
  2580. static void cmd_su(struct userrec *u, int idx, char *par)
  2581. {
  2582. int atr = u ? u->flags : 0;
  2583. int ok;
  2584. struct flag_record fr = {FR_ANYWH | FR_CHAN | FR_GLOBAL, 0, 0, 0, 0, 0};
  2585. u = get_user_by_handle(userlist, par);
  2586. if (!par[0])
  2587. dprintf(idx, STR("Usage: su <user>\n"));
  2588. else if (!u)
  2589. dprintf(idx, STR("No such user.\n"));
  2590. else if (u->flags & USER_BOT)
  2591. dprintf(idx, STR("You can't su to a bot... then again, why would you wanna?\n"));
  2592. else if (dcc[idx].u.chat->su_nick)
  2593. dprintf(idx, STR("You cannot currently double .su; try .su'ing directly.\n"));
  2594. else {
  2595. get_user_flagrec(u, &fr, NULL);
  2596. ok = 1;
  2597. #ifdef HUB
  2598. if (!glob_huba(fr))
  2599. ok = 0;
  2600. #else /* !HUB */
  2601. if (ischanhub() && !glob_chuba(fr))
  2602. ok = 0;
  2603. #endif /* LEAF */
  2604. if (!ok)
  2605. dprintf(idx, STR("No party line access permitted for %s.\n"), par);
  2606. else {
  2607. correct_handle(par);
  2608. putlog(LOG_CMDS, "*", STR("#%s# su %s"), dcc[idx].nick, par);
  2609. if (!(atr & USER_OWNER) ||
  2610. ((u->flags & USER_OWNER) && (isowner(par)) &&
  2611. !(isowner(dcc[idx].nick)))) {
  2612. /* This check is only important for non-owners */
  2613. if (u_pass_match(u, "-")) {
  2614. dprintf(idx, STR("No password set for user. You may not .su to them.\n"));
  2615. return;
  2616. }
  2617. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2618. botnet_send_part_idx(idx, "");
  2619. chanout_but(-1, dcc[idx].u.chat->channel,
  2620. "*** %s left the party line.\n", dcc[idx].nick);
  2621. /* Store the old nick in the away section, for weenies who can't get
  2622. * their password right ;)
  2623. */
  2624. if (dcc[idx].u.chat->away != NULL)
  2625. nfree(dcc[idx].u.chat->away);
  2626. dcc[idx].u.chat->away = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2627. strcpy(dcc[idx].u.chat->away, dcc[idx].nick);
  2628. dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2629. strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
  2630. dcc[idx].user = u;
  2631. strcpy(dcc[idx].nick, par);
  2632. /* Display password prompt and turn off echo (send IAC WILL ECHO). */
  2633. dprintf(idx, STR("Enter password for %s%s\n"), par,
  2634. (dcc[idx].status & STAT_TELNET) ? TLN_IAC_C TLN_WILL_C
  2635. TLN_ECHO_C : "");
  2636. dcc[idx].type = &DCC_CHAT_PASS;
  2637. } else if (atr & USER_OWNER) {
  2638. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  2639. botnet_send_part_idx(idx, "");
  2640. chanout_but(-1, dcc[idx].u.chat->channel,
  2641. "*** %s left the party line.\n", dcc[idx].nick);
  2642. dprintf(idx, STR("Setting your username to %s.\n"), par);
  2643. if (atr & USER_MASTER)
  2644. dcc[idx].u.chat->con_flags = conmask;
  2645. dcc[idx].u.chat->su_nick = get_data_ptr(strlen(dcc[idx].nick) + 1);
  2646. strcpy(dcc[idx].u.chat->su_nick, dcc[idx].nick);
  2647. dcc[idx].user = u;
  2648. strcpy(dcc[idx].nick, par);
  2649. dcc_chatter(idx);
  2650. }
  2651. }
  2652. }
  2653. }
  2654. static void cmd_fixcodes(struct userrec *u, int idx, char *par)
  2655. {
  2656. if (dcc[idx].status & STAT_TELNET) {
  2657. dcc[idx].status |= STAT_ECHO;
  2658. dcc[idx].status &= ~STAT_TELNET;
  2659. dprintf(idx, STR("Turned off telnet codes.\n"));
  2660. putlog(LOG_CMDS, "*", STR("#%s# fixcodes (telnet off)"), dcc[idx].nick);
  2661. } else {
  2662. dcc[idx].status |= STAT_TELNET;
  2663. dcc[idx].status &= ~STAT_ECHO;
  2664. dprintf(idx, STR("Turned on telnet codes.\n"));
  2665. putlog(LOG_CMDS, "*", STR("#%s# fixcodes (telnet on)"), dcc[idx].nick);
  2666. }
  2667. }
  2668. static void cmd_page(struct userrec *u, int idx, char *par)
  2669. {
  2670. int a;
  2671. module_entry *me;
  2672. if (!par[0]) {
  2673. if (dcc[idx].status & STAT_PAGE) {
  2674. dprintf(idx, STR("Currently paging outputs to %d lines.\n"),
  2675. dcc[idx].u.chat->max_line);
  2676. } else
  2677. dprintf(idx, STR("You don't have paging on.\n"));
  2678. return;
  2679. }
  2680. a = atoi(par);
  2681. if ((!a && !par[0]) || !egg_strcasecmp(par, "off")) {
  2682. dcc[idx].status &= ~STAT_PAGE;
  2683. dcc[idx].u.chat->max_line = 0x7ffffff; /* flush_lines needs this */
  2684. while (dcc[idx].u.chat->buffer)
  2685. flush_lines(idx, dcc[idx].u.chat);
  2686. dprintf(idx, STR("Paging turned off.\n"));
  2687. putlog(LOG_CMDS, "*", STR("#%s# page off"), dcc[idx].nick);
  2688. } else if (a > 0) {
  2689. dprintf(idx, STR("Paging turned on, stopping every %d line%s.\n"), a,
  2690. (a != 1) ? "s" : "");
  2691. dcc[idx].status |= STAT_PAGE;
  2692. dcc[idx].u.chat->max_line = a;
  2693. dcc[idx].u.chat->line_count = 0;
  2694. dcc[idx].u.chat->current_lines = 0;
  2695. putlog(LOG_CMDS, "*", STR("#%s# page %d"), dcc[idx].nick, a);
  2696. } else {
  2697. dprintf(idx, STR("Usage: page <off or #>\n"));
  2698. return;
  2699. }
  2700. /* New style autosave here too -- rtc, 09/28/1999*/
  2701. if ((me = module_find("console", 0, 0))) {
  2702. Function *func = me->funcs;
  2703. (func[CONSOLE_DOSTORE]) (idx);
  2704. }
  2705. }
  2706. /* Evaluate a Tcl command, send output to a dcc user.
  2707. */
  2708. #ifdef S_TCLCMDS
  2709. static void cmd_tcl(struct userrec *u, int idx, char *msg)
  2710. {
  2711. int code;
  2712. #ifdef S_PERMONLY
  2713. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2714. dprintf(idx, STR("What? You need '%shelp'\n"), dcc_prefix);
  2715. return;
  2716. }
  2717. #endif /* S_PERMONLY */
  2718. putlog(LOG_CMDS, "*", STR("#%s# tcl %s"), dcc[idx].nick, msg);
  2719. debug1(STR("tcl: evaluate (.tcl): %s"), msg);
  2720. code = Tcl_GlobalEval(interp, msg);
  2721. if (code == TCL_OK)
  2722. dumplots(idx, STR("Tcl: "), interp->result);
  2723. else
  2724. dumplots(idx, STR("Tcl error: "), interp->result);
  2725. }
  2726. #endif /* S_TCLCMDS */
  2727. #ifdef HUB
  2728. #ifdef S_TCLCMDS
  2729. static void cmd_nettcl(struct userrec *u, int idx, char *msg)
  2730. {
  2731. int code;
  2732. char buf[2000];
  2733. #ifdef S_PERMONLY
  2734. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2735. dprintf(idx, STR("What? You need '%shelp'\n"), dcc_prefix);
  2736. return;
  2737. }
  2738. #endif /* S_PERMONLY */
  2739. putlog(LOG_CMDS, "*", STR("#%s# nettcl %s"), dcc[idx].nick, msg);
  2740. egg_snprintf(buf, sizeof buf, "mt %d %s", idx, msg);
  2741. botnet_send_zapf_broad(-1, botnetnick, NULL, buf);
  2742. debug1(STR("tcl: evaluate (.tcl): %s"), msg);
  2743. code = Tcl_GlobalEval(interp, msg);
  2744. if (code == TCL_OK)
  2745. dumplots(idx, STR("Tcl: "), interp->result);
  2746. else
  2747. dumplots(idx, STR("Tcl error: "), interp->result);
  2748. }
  2749. #endif /* S_TCLCMDS */
  2750. static void cmd_newleaf(struct userrec *u, int idx, char *par)
  2751. {
  2752. char *handle,
  2753. *host;
  2754. struct userrec *u1;
  2755. struct bot_addr *bi;
  2756. putlog(LOG_CMDS, "*", STR("#%s# newleaf %s"), dcc[idx].nick, par);
  2757. if (!par[0]) {
  2758. dprintf(idx, STR("Usage: newleaf <handle> [host] [anotherhost]\n"));
  2759. dprintf(idx, STR(" Leafs can't link unless you specify a *!ident@ip hostmask\n"));
  2760. } else {
  2761. handle = newsplit(&par);
  2762. if (strlen(handle) > HANDLEN)
  2763. handle[HANDLEN] = 0;
  2764. if (get_user_by_handle(userlist, handle))
  2765. dprintf(idx, STR("Already got a %s user/bot\n"), handle);
  2766. else if (strchr(BADHANDCHARS, handle[0]) != NULL)
  2767. dprintf(idx, STR("You can't start a botnick with '%c'.\n"), handle[0]);
  2768. else {
  2769. userlist = adduser(userlist, handle, STR("none"), "-", USER_BOT | USER_OP);
  2770. u1 = get_user_by_handle(userlist, handle);
  2771. bi = user_malloc(sizeof(struct bot_addr));
  2772. bi->uplink = user_malloc(strlen(botnetnick) + 1);
  2773. /* strcpy(bi->uplink, botnetnick); */
  2774. strcpy(bi->uplink, "");
  2775. bi->address = user_malloc(1);
  2776. bi->address[0] = 0;
  2777. bi->telnet_port = 3333;
  2778. bi->relay_port = 3333;
  2779. bi->hublevel = 0;
  2780. set_user(&USERENTRY_BOTADDR, u1, bi);
  2781. host = newsplit(&par);
  2782. while ((host) && (host[0])) {
  2783. addhost_by_handle(handle, host);
  2784. host = newsplit(&par);
  2785. }
  2786. /* set_user(&USERENTRY_PASS, u1, SALT2); */
  2787. dprintf(idx, STR("Added new leaf: %s\n"), handle);
  2788. }
  2789. }
  2790. }
  2791. /* Perform a 'set' command
  2792. */
  2793. static void cmd_set(struct userrec *u, int idx, char *msg)
  2794. {
  2795. int code;
  2796. char s[512];
  2797. #ifdef S_PERMONLY
  2798. if (!(isowner(dcc[idx].nick)) && (must_be_owner)) {
  2799. dprintf(idx, STR("What? You need '%shelp'\n"), dcc_prefix);
  2800. return;
  2801. }
  2802. #endif /* S_PERMONLY */
  2803. putlog(LOG_CMDS, "*", STR("#%s# set %s"), dcc[idx].nick, msg);
  2804. strcpy(s, "set ");
  2805. if (!msg[0]) {
  2806. strcpy(s, "info globals");
  2807. Tcl_Eval(interp, s);
  2808. dumplots(idx, STR("Global vars: "), interp->result);
  2809. return;
  2810. }
  2811. strcpy(s + 4, msg);
  2812. code = Tcl_Eval(interp, s);
  2813. if (code == TCL_OK) {
  2814. if (!strchr(msg, ' '))
  2815. dumplots(idx, STR("Currently: "), interp->result);
  2816. else
  2817. dprintf(idx, STR("Ok, set.\n"));
  2818. } else
  2819. dprintf(idx, STR("Error: %s\n"), interp->result);
  2820. }
  2821. #endif /* HUB */
  2822. static void cmd_pls_ignore(struct userrec *u, int idx, char *par)
  2823. {
  2824. char *who;
  2825. char s[UHOSTLEN];
  2826. unsigned long int expire_time = 0;
  2827. if (!par[0]) {
  2828. dprintf(idx, STR("Usage: +ignore <hostmask> [%%<XdXhXm>] [comment]\n"));
  2829. return;
  2830. }
  2831. who = newsplit(&par);
  2832. if (par[0] == '%') {
  2833. char *p, *p_expire;
  2834. unsigned long int expire_foo;
  2835. p = newsplit(&par);
  2836. p_expire = p + 1;
  2837. while (*(++p) != 0) {
  2838. switch (tolower(*p)) {
  2839. case 'd':
  2840. *p = 0;
  2841. expire_foo = strtol(p_expire, NULL, 10);
  2842. if (expire_foo > 365)
  2843. expire_foo = 365;
  2844. expire_time += 86400 * expire_foo;
  2845. p_expire = p + 1;
  2846. break;
  2847. case 'h':
  2848. *p = 0;
  2849. expire_foo = strtol(p_expire, NULL, 10);
  2850. if (expire_foo > 8760)
  2851. expire_foo = 8760;
  2852. expire_time += 3600 * expire_foo;
  2853. p_expire = p + 1;
  2854. break;
  2855. case 'm':
  2856. *p = 0;
  2857. expire_foo = strtol(p_expire, NULL, 10);
  2858. if (expire_foo > 525600)
  2859. expire_foo = 525600;
  2860. expire_time += 60 * expire_foo;
  2861. p_expire = p + 1;
  2862. }
  2863. }
  2864. }
  2865. if (!par[0])
  2866. par = "requested";
  2867. else if (strlen(par) > 65)
  2868. par[65] = 0;
  2869. if (strlen(who) > UHOSTMAX - 4)
  2870. who[UHOSTMAX - 4] = 0;
  2871. /* Fix missing ! or @ BEFORE continuing */
  2872. if (!strchr(who, '!')) {
  2873. if (!strchr(who, '@'))
  2874. simple_sprintf(s, "%s!*@*", who);
  2875. else
  2876. simple_sprintf(s, "*!%s", who);
  2877. } else if (!strchr(who, '@'))
  2878. simple_sprintf(s, "%s@*", who);
  2879. else
  2880. strcpy(s, who);
  2881. if (match_ignore(s))
  2882. dprintf(idx, STR("That already matches an existing ignore.\n"));
  2883. else {
  2884. dprintf(idx, STR("Now ignoring: %s (%s)\n"), s, par);
  2885. addignore(s, dcc[idx].nick, par, expire_time ? now + expire_time : 0L);
  2886. putlog(LOG_CMDS, "*", STR("#%s# +ignore %s %s"), dcc[idx].nick, s, par);
  2887. }
  2888. }
  2889. static void cmd_mns_ignore(struct userrec *u, int idx, char *par)
  2890. {
  2891. char buf[UHOSTLEN];
  2892. if (!par[0]) {
  2893. dprintf(idx, STR("Usage: -ignore <hostmask | ignore #>\n"));
  2894. return;
  2895. }
  2896. strncpyz(buf, par, sizeof buf);
  2897. if (delignore(buf)) {
  2898. putlog(LOG_CMDS, "*", STR("#%s# -ignore %s"), dcc[idx].nick, buf);
  2899. dprintf(idx, STR("No longer ignoring: %s\n"), buf);
  2900. } else
  2901. dprintf(idx, STR("That ignore cannot be found.\n"));
  2902. }
  2903. static void cmd_ignores(struct userrec *u, int idx, char *par)
  2904. {
  2905. putlog(LOG_CMDS, "*", STR("#%s# ignores %s"), dcc[idx].nick, par);
  2906. tell_ignores(idx, par);
  2907. }
  2908. static void cmd_pls_user(struct userrec *u, int idx, char *par)
  2909. {
  2910. char *handle, *host;
  2911. putlog(LOG_CMDS, "*", STR("#%s# +user %s"), dcc[idx].nick, par);
  2912. if (!par[0]) {
  2913. dprintf(idx, STR("Usage: +user <handle> [hostmask]\n"));
  2914. return;
  2915. }
  2916. handle = newsplit(&par);
  2917. host = newsplit(&par);
  2918. if (strlen(handle) > HANDLEN)
  2919. handle[HANDLEN] = 0;
  2920. if (get_user_by_handle(userlist, handle))
  2921. dprintf(idx, STR("Someone already exists by that name.\n"));
  2922. else if (strchr(BADNICKCHARS, handle[0]) != NULL)
  2923. dprintf(idx, STR("You can't start a nick with '%c'.\n"), handle[0]);
  2924. else if (!egg_strcasecmp(handle, botnetnick))
  2925. dprintf(idx, STR("Hey! That's MY name!\n"));
  2926. else {
  2927. struct userrec *u2;
  2928. char tmp[50], s[16], s2[17];
  2929. userlist = adduser(userlist, handle, host, "-", USER_DEFAULT);
  2930. u2 = get_user_by_handle(userlist, handle);
  2931. sprintf(tmp, STR("%lu %s"), time(NULL), u->handle);
  2932. set_user(&USERENTRY_ADDED, u2, tmp);
  2933. dprintf(idx, STR("Added %s (%s) with no flags.\n"), handle, host);
  2934. while (par[0]) {
  2935. host=newsplit(&par);
  2936. set_user(&USERENTRY_HOSTS, u2, host);
  2937. dprintf(idx, STR("Added host %s to %s.\n"), host, handle);
  2938. }
  2939. make_rand_str(s, 15);
  2940. set_user(&USERENTRY_PASS, u2, s);
  2941. make_rand_str(s2, 16);
  2942. set_user(&USERENTRY_SECPASS, u2, s2);
  2943. dprintf(idx, STR("%s's initial password set to \002%s\002\n"), handle, s);
  2944. dprintf(idx, STR("%s's initial secpass set to \002%s\002\n"), handle, s2);
  2945. #ifdef HUB
  2946. write_userfile(idx);
  2947. #endif /* HUB */
  2948. }
  2949. }
  2950. static void cmd_mns_user(struct userrec *u, int idx, char *par)
  2951. {
  2952. int idx2;
  2953. char *handle;
  2954. struct userrec *u2;
  2955. module_entry *me;
  2956. putlog(LOG_CMDS, "*", STR("#%s# -user %s"), dcc[idx].nick, par);
  2957. if (!par[0]) {
  2958. dprintf(idx, STR("Usage: -user <hand>\n"));
  2959. return;
  2960. }
  2961. handle = newsplit(&par);
  2962. u2 = get_user_by_handle(userlist, handle);
  2963. if (!u2 || !u) {
  2964. dprintf(idx, STR("No such user!\n"));
  2965. return;
  2966. }
  2967. if (isowner(u2->handle)) {
  2968. dprintf(idx, STR("You can't remove a permanent bot owner!\n"));
  2969. return;
  2970. }
  2971. if ((u2->flags & USER_ADMIN) && !(isowner(u->handle))) {
  2972. dprintf(idx, STR("You can't remove an admin!\n"));
  2973. return;
  2974. }
  2975. if ((u2->flags & USER_OWNER) && !(u->flags & USER_OWNER)) {
  2976. dprintf(idx, STR("You can't remove a bot owner!\n"));
  2977. return;
  2978. }
  2979. if (u2->flags & USER_BOT) {
  2980. if ((bot_flags(u2) & BOT_SHARE) && !(u->flags & USER_OWNER)) {
  2981. dprintf(idx, STR("You can't remove share bots.\n"));
  2982. return;
  2983. }
  2984. for (idx2 = 0; idx2 < dcc_total; idx2++)
  2985. if (dcc[idx2].type != &DCC_RELAY && dcc[idx2].type != &DCC_FORK_BOT &&
  2986. !egg_strcasecmp(dcc[idx2].nick, handle))
  2987. break;
  2988. if (idx2 != dcc_total) {
  2989. dprintf(idx, STR("You can't remove a directly linked bot.\n"));
  2990. return;
  2991. }
  2992. }
  2993. if (!(u->flags & USER_MASTER) &&
  2994. !(u2->flags & USER_BOT)) {
  2995. dprintf(idx, STR("You can't remove users who aren't bots!\n"));
  2996. return;
  2997. }
  2998. if ((me = module_find("irc", 0, 0))) {
  2999. Function *func = me->funcs;
  3000. (func[IRC_CHECK_THIS_USER]) (handle, 1, NULL);
  3001. }
  3002. if (deluser(handle)) {
  3003. dprintf(idx, STR("Deleted %s.\n"), handle);
  3004. #ifdef HUB
  3005. write_userfile(idx);
  3006. #endif /* HUB */
  3007. } else
  3008. dprintf(idx, STR("Failed.\n"));
  3009. }
  3010. static void cmd_pls_host(struct userrec *u, int idx, char *par)
  3011. {
  3012. char *handle, *host;
  3013. struct userrec *u2;
  3014. struct list_type *q;
  3015. struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0},
  3016. fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  3017. module_entry *me;
  3018. putlog(LOG_CMDS, "*", STR("#%s# +host %s"), dcc[idx].nick, par);
  3019. if (!par[0]) {
  3020. dprintf(idx, STR("Usage: +host [handle] <newhostmask>\n"));
  3021. return;
  3022. }
  3023. handle = newsplit(&par);
  3024. if (par[0]) {
  3025. host = newsplit(&par);
  3026. u2 = get_user_by_handle(userlist, handle);
  3027. } else {
  3028. host = handle;
  3029. handle = dcc[idx].nick;
  3030. u2 = u;
  3031. }
  3032. if (!u2 || !u) {
  3033. dprintf(idx, STR("No such user.\n"));
  3034. return;
  3035. }
  3036. get_user_flagrec(u, &fr, NULL);
  3037. if (egg_strcasecmp(handle, dcc[idx].nick)) {
  3038. get_user_flagrec(u2, &fr2, NULL);
  3039. if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
  3040. dprintf(idx, STR("You can't add hostmasks to non-bots.\n"));
  3041. return;
  3042. }
  3043. if (!glob_owner(fr) && glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE)) {
  3044. dprintf(idx, STR("You can't add hostmasks to share bots.\n"));
  3045. return;
  3046. }
  3047. if (glob_admin(fr2) && !isowner(u->handle)) {
  3048. dprintf(idx, STR("You can't add hostmasks to an admin.\n"));
  3049. return;
  3050. }
  3051. if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
  3052. dprintf(idx, STR("You can't add hostmasks to a bot owner/master.\n"));
  3053. return;
  3054. }
  3055. if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
  3056. !glob_owner(fr) && !chan_owner(fr)) {
  3057. dprintf(idx, STR("You can't add hostmasks to a channel owner/master.\n"));
  3058. return;
  3059. }
  3060. if (!glob_master(fr) && !chan_master(fr)) {
  3061. dprintf(idx, STR("Permission denied.\n"));
  3062. return;
  3063. }
  3064. }
  3065. if (!chan_master(fr) && get_user_by_host(host)) {
  3066. dprintf(idx, STR("You cannot add a host matching another user!\n"));
  3067. return;
  3068. }
  3069. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next)
  3070. if (!egg_strcasecmp(q->extra, host)) {
  3071. dprintf(idx, STR("That hostmask is already there.\n"));
  3072. return;
  3073. }
  3074. addhost_by_handle(handle, host);
  3075. update_mod(handle, dcc[idx].nick, "+host", host);
  3076. dprintf(idx, STR("Added '%s' to %s.\n"), host, handle);
  3077. if ((me = module_find("irc", 0, 0))) {
  3078. Function *func = me->funcs;
  3079. (func[IRC_CHECK_THIS_USER]) (handle, 0, NULL);
  3080. }
  3081. }
  3082. static void cmd_mns_host(struct userrec *u, int idx, char *par)
  3083. {
  3084. char *handle, *host;
  3085. struct userrec *u2;
  3086. struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0},
  3087. fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  3088. module_entry *me;
  3089. putlog(LOG_CMDS, "*", STR("#%s# -host %s"), dcc[idx].nick, par);
  3090. if (!par[0]) {
  3091. dprintf(idx, STR("Usage: -host [handle] <hostmask>\n"));
  3092. return;
  3093. }
  3094. handle = newsplit(&par);
  3095. if (par[0]) {
  3096. host = newsplit(&par);
  3097. u2 = get_user_by_handle(userlist, handle);
  3098. } else {
  3099. host = handle;
  3100. handle = dcc[idx].nick;
  3101. u2 = u;
  3102. }
  3103. if (!u2 || !u) {
  3104. dprintf(idx, STR("No such user.\n"));
  3105. return;
  3106. }
  3107. get_user_flagrec(u, &fr, NULL);
  3108. get_user_flagrec(u2, &fr2, NULL);
  3109. /* check to see if user is +d or +k and don't let them remove hosts */
  3110. if (glob_deop(fr) || glob_kick(fr) || chan_deop(fr) || chan_kick (fr)) {
  3111. dprintf(idx, STR("You can't remove hostmasks while having the +d or +k flag.\n"));
  3112. return;
  3113. }
  3114. if (egg_strcasecmp(handle, dcc[idx].nick)) {
  3115. if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
  3116. dprintf(idx, STR("You can't remove hostmasks from non-bots.\n"));
  3117. return;
  3118. }
  3119. if (glob_bot(fr2) && (bot_flags(u2) & BOT_SHARE) && !glob_owner(fr)) {
  3120. dprintf(idx, STR("You can't remove hostmasks from a share bot.\n"));
  3121. return;
  3122. }
  3123. if (glob_admin(fr2) && !isowner(u->handle)) {
  3124. dprintf(idx, STR("You can't remove hostmasks from an admin.\n"));
  3125. return;
  3126. }
  3127. if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
  3128. dprintf(idx, STR("You can't remove hostmasks from a bot owner/master.\n"));
  3129. return;
  3130. }
  3131. if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
  3132. !glob_owner(fr) && !chan_owner(fr)) {
  3133. dprintf(idx, STR("You can't remove hostmasks from a channel owner/master.\n"));
  3134. return;
  3135. }
  3136. if (!glob_master(fr) && !chan_master(fr)) {
  3137. dprintf(idx, STR("Permission denied.\n"));
  3138. return;
  3139. }
  3140. }
  3141. if (delhost_by_handle(handle, host)) {
  3142. dprintf(idx, STR("Removed '%s' from %s.\n"), host, handle);
  3143. update_mod(handle, dcc[idx].nick, "-host", host);
  3144. if ((me = module_find("irc", 0, 0))) {
  3145. Function *func = me->funcs;
  3146. (func[IRC_CHECK_THIS_USER]) (handle, 2, host);
  3147. }
  3148. } else
  3149. dprintf(idx, STR("Failed.\n"));
  3150. }
  3151. /* netserver */
  3152. static void cmd_netserver(struct userrec * u, int idx, char * par) {
  3153. putlog(LOG_CMDS, "*", STR("#%s# netserver"), dcc[idx].nick);
  3154. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("cursrv"));
  3155. }
  3156. static void cmd_botserver(struct userrec * u, int idx, char * par) {
  3157. putlog(LOG_CMDS, "*", STR("#%s# botserver %s"), dcc[idx].nick, par);
  3158. if (!par || !par[0]) {
  3159. dprintf(idx, STR("Usage: botserver <botname>\n"));
  3160. return;
  3161. }
  3162. if (nextbot(par)<0) {
  3163. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3164. }
  3165. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("cursrv"));
  3166. }
  3167. void rcmd_cursrv(char * fbot, char * fhand, char * fidx) {
  3168. #ifdef LEAF
  3169. char tmp[2048], cursrvname[500];
  3170. int server_online = 0;
  3171. module_entry *me;
  3172. if ((me = module_find("server", 0, 0))) {
  3173. Function *func = me->funcs;
  3174. server_online = (*(int *)(func[25]));
  3175. sprintf(cursrvname, "%s", ((char *)(func[41])));
  3176. }
  3177. if (server_online)
  3178. sprintf(tmp, "Currently: %-40s Lag: %d", cursrvname, server_lag);
  3179. // sprintf(tmp, STR("%-20s %d)"), cursrvname, server_lag);
  3180. else
  3181. sprintf(tmp, "Currently: none");
  3182. // sprintf(tmp, STR("%-20s"), "none");
  3183. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3184. #endif /* LEAF */
  3185. }
  3186. /* netversion */
  3187. static void cmd_netversion(struct userrec * u, int idx, char * par) {
  3188. putlog(LOG_CMDS, "*", STR("#%s# netversion"), dcc[idx].nick);
  3189. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("ver"));
  3190. }
  3191. static void cmd_botversion(struct userrec * u, int idx, char * par) {
  3192. putlog(LOG_CMDS, "*", STR("#%s# botversion %s"), dcc[idx].nick, par);
  3193. if (!par || !par[0]) {
  3194. dprintf(idx, STR("Usage: botversion <botname>\n"));
  3195. return;
  3196. }
  3197. if (nextbot(par)<0) {
  3198. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3199. }
  3200. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("ver"));
  3201. }
  3202. void rcmd_ver(char * fbot, char * fhand, char * fidx) {
  3203. char tmp[2048];
  3204. #ifdef HAVE_UNAME
  3205. struct utsname un;
  3206. #endif /* HAVE_UNAME */
  3207. sprintf(tmp, STR("%s "), ver);
  3208. #ifdef HAVE_UNAME
  3209. if (uname(&un) < 0) {
  3210. #endif /* HAVE_UNAME */
  3211. strcat(tmp, STR("(unknown OS)"));
  3212. #ifdef HAVE_UNAME
  3213. } else {
  3214. sprintf(tmp + strlen(tmp), STR("%s %s (%s)"), un.sysname, un.release, un.machine);
  3215. }
  3216. #endif /* HAVE_UNAME */
  3217. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3218. }
  3219. /* netnick, botnick */
  3220. static void cmd_netnick (struct userrec *u, int idx, char *par) {
  3221. putlog(LOG_CMDS, "*", STR("#%s# netnick"), dcc[idx].nick);
  3222. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, STR("curnick"));
  3223. }
  3224. static void cmd_botnick(struct userrec * u, int idx, char * par) {
  3225. putlog(LOG_CMDS, "*", STR("#%s# botnick %s"), dcc[idx].nick, par);
  3226. if (!par || !par[0]) {
  3227. dprintf(idx, STR("Usage: botnick <botname>\n"));
  3228. return;
  3229. }
  3230. if (nextbot(par)<0) {
  3231. dprintf(idx, STR("%s isn't a linked bot\n"), par);
  3232. }
  3233. botnet_send_cmd(botnetnick, par, u->handle, idx, STR("curnick"));
  3234. }
  3235. void rcmd_curnick(char * fbot, char * fhand, char * fidx) {
  3236. #ifdef LEAF
  3237. char tmp[1024];
  3238. int server_online = 0;
  3239. module_entry *me;
  3240. if ((me = module_find("server", 0, 0))) {
  3241. Function *func = me->funcs;
  3242. server_online = (*(int *)(func[25]));
  3243. }
  3244. tmp[0] = 0;
  3245. if (strncmp(botname, origbotname, strlen(botname)))
  3246. sprintf(tmp, STR("Want: %s, "), origbotname);
  3247. if (server_online)
  3248. sprintf(tmp, STR("%sCurrently: %s "), tmp, botname);
  3249. else
  3250. sprintf(tmp, STR("%s(not online)"), tmp);
  3251. botnet_send_cmdreply(botnetnick, fbot, fhand, fidx, tmp);
  3252. #endif /* LEAF */
  3253. }
  3254. /* netmsg, botmsg */
  3255. static void cmd_botmsg(struct userrec * u, int idx, char * par) {
  3256. char * tnick, * tbot;
  3257. char tmp[1024];
  3258. putlog(LOG_CMDS, "*", STR("#%s# botmsg %s"), dcc[idx].nick, par);
  3259. tbot=newsplit(&par);
  3260. tnick=newsplit(&par);
  3261. if (!par[0]) {
  3262. dprintf(idx, STR("Usage: botmsg <botname> <nick|#channel> <message>\n"));
  3263. return;
  3264. }
  3265. if (nextbot(tbot)<0) {
  3266. dprintf(idx, STR("No such bot linked\n"));
  3267. return;
  3268. }
  3269. sprintf(tmp, STR("msg %s %s"), tnick, par);
  3270. botnet_send_cmd(botnetnick, tbot, u->handle, idx, tmp);
  3271. }
  3272. static void cmd_netmsg(struct userrec * u, int idx, char * par) {
  3273. char * tnick;
  3274. char tmp[1024];
  3275. putlog(LOG_CMDS, "*", STR("#%s# netmsg %s"), dcc[idx].nick, par);
  3276. tnick=newsplit(&par);
  3277. if (!par[0]) {
  3278. dprintf(idx, STR("Usage: netmsg <nick|#channel> <message>\n"));
  3279. return;
  3280. }
  3281. sprintf(tmp, STR("msg %s %s"), tnick, par);
  3282. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, tmp);
  3283. }
  3284. void rcmd_msg(char * tobot, char * frombot, char * fromhand, char * fromidx, char * par) {
  3285. #ifdef LEAF
  3286. char buf[1024], *nick;
  3287. nick=newsplit(&par);
  3288. dprintf(DP_SERVER, STR("PRIVMSG %s :%s\n"), nick, par);
  3289. if (!strcmp(tobot, botnetnick)) {
  3290. sprintf(buf, STR("Sent message to %s"), nick);
  3291. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, buf);
  3292. }
  3293. #endif /* LEAF */
  3294. }
  3295. /* netlag */
  3296. static void cmd_netlag(struct userrec * u, int idx, char * par) {
  3297. struct timeval tv;
  3298. time_t tm;
  3299. char tmp[64];
  3300. putlog(LOG_CMDS, "*", STR("#%s# netlag"), dcc[idx].nick);
  3301. gettimeofday(&tv, NULL);
  3302. tm = (tv.tv_sec % 10000) * 100 + (tv.tv_usec * 100) / (1000000);
  3303. sprintf(tmp, STR("ping %lu"), tm);
  3304. dprintf(idx, STR("Sent ping to all linked bots\n"));
  3305. botnet_send_cmd_broad(-1, botnetnick, u->handle, idx, tmp);
  3306. }
  3307. void rcmd_ping(char * frombot, char *fromhand, char * fromidx, char * par) {
  3308. char tmp[64];
  3309. sprintf(tmp, STR("pong %s"), par);
  3310. botnet_send_cmd(botnetnick, frombot, fromhand, atoi(fromidx), tmp);
  3311. }
  3312. void rcmd_pong(char *frombot, char *fromhand, char *fromidx, char *par) {
  3313. int i=atoi(fromidx);
  3314. if ((i>=0) && (i<dcc_total) && (dcc[i].type==&DCC_CHAT) && (!strcmp(dcc[i].nick, fromhand))) {
  3315. struct timeval tv;
  3316. time_t tm;
  3317. gettimeofday(&tv, NULL);
  3318. tm = ((tv.tv_sec % 10000) * 100 + (tv.tv_usec * 100) / (1000000)) - atoi(par);
  3319. dprintf(i, STR("Pong from %s: %i.%i seconds\n"), frombot, (tm / 100), (tm % 100));
  3320. }
  3321. }
  3322. /* exec commands */
  3323. #ifdef HUB
  3324. static void cmd_netw(struct userrec * u, int idx, char * par) {
  3325. char tmp[128];
  3326. putlog(LOG_CMDS, "*", STR("#%s# netw"), dcc[idx].nick);
  3327. strcpy(tmp, STR("exec w"));
  3328. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, tmp);
  3329. }
  3330. static void cmd_netps(struct userrec * u, int idx, char * par) {
  3331. char buf[1024];
  3332. putlog(LOG_CMDS, "*", STR("#%s# netps %s"), dcc[idx].nick, par);
  3333. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  3334. putlog(LOG_WARN, "*", STR("%s attempted 'netps' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  3335. dprintf(idx, STR("No."));
  3336. return;
  3337. }
  3338. sprintf(buf, STR("exec ps %s"), par);
  3339. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3340. }
  3341. static void cmd_netlast(struct userrec * u, int idx, char * par) {
  3342. char buf[1024];
  3343. putlog(LOG_CMDS, "*", STR("#%s# netlast %s"), dcc[idx].nick, par);
  3344. if (strchr(par, '|') || strchr(par, '<') || strchr(par, ';') || strchr(par, '>')) {
  3345. putlog(LOG_WARN, "*", STR("%s attempted 'netlast' with pipe/semicolon in parameters: %s"), dcc[idx].nick, par);
  3346. dprintf(idx, STR("No."));
  3347. return;
  3348. }
  3349. sprintf(buf, STR("exec last %s"), par);
  3350. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3351. }
  3352. #endif /* HUB */
  3353. void crontab_show(struct userrec * u, int idx) {
  3354. dprintf(idx, STR("Showing current crontab:\n"));
  3355. if (!exec_str(idx, STR("crontab -l | grep -v \"^#\"")))
  3356. dprintf(idx, STR("Exec failed"));
  3357. }
  3358. void crontab_del() {
  3359. char * tmpfile, *p, buf[2048];
  3360. tmpfile=nmalloc(strlen(binname)+100);
  3361. strcpy(tmpfile, binname);
  3362. if (!(p=strrchr(tmpfile, '/')))
  3363. return;
  3364. p++;
  3365. strcpy(p, STR(".ctb"));
  3366. sprintf(buf, STR("crontab -l | grep -v \"%s\" | grep -v \"^#\" | grep -v \"^\\$\" > %s"), binname, tmpfile);
  3367. if (shell_exec(buf, NULL, NULL, NULL)) {
  3368. sprintf(buf, STR("crontab %s"), tmpfile);
  3369. shell_exec(buf, NULL, NULL, NULL);
  3370. }
  3371. unlink(tmpfile);
  3372. }
  3373. static void cmd_crontab(struct userrec *u, int idx, char *par) {
  3374. char * code;
  3375. int i;
  3376. putlog(LOG_CMDS, "*", STR("#%s# crontab %s"), dcc[idx].nick, par);
  3377. if (!par[0]) {
  3378. dprintf(idx, STR("Usage: crontab status|delete|show|new [interval]\n"));
  3379. return;
  3380. }
  3381. code=newsplit(&par);
  3382. if (!strcmp(code, STR("status"))) {
  3383. i=crontab_exists();
  3384. if (!i)
  3385. dprintf(idx, STR("No crontab\n"));
  3386. else if (i==1)
  3387. dprintf(idx, STR("Crontabbed\n"));
  3388. else
  3389. dprintf(idx, STR("Error checking crontab status\n"));
  3390. } else if (!strcmp(code, STR("show"))) {
  3391. crontab_show(u, idx);
  3392. } else if (!strcmp(code, STR("delete"))) {
  3393. crontab_del();
  3394. i=crontab_exists();
  3395. if (!i)
  3396. dprintf(idx, STR("No crontab\n"));
  3397. else if (i==1)
  3398. dprintf(idx, STR("Crontabbed\n"));
  3399. else
  3400. dprintf(idx, STR("Error checking crontab status\n"));
  3401. } else if (!strcmp(code, STR("new"))) {
  3402. i=atoi(par);
  3403. if ((i<=0) || (i>60))
  3404. i=10;
  3405. crontab_create(i);
  3406. i=crontab_exists();
  3407. if (!i)
  3408. dprintf(idx, STR("No crontab\n"));
  3409. else if (i==1)
  3410. dprintf(idx, STR("Crontabbed\n"));
  3411. else
  3412. dprintf(idx, STR("Error checking crontab status\n"));
  3413. } else {
  3414. dprintf(idx, STR("Usage: crontab status|delete|show|new [interval]\n"));
  3415. }
  3416. }
  3417. #ifdef HUB
  3418. static void cmd_netcrontab(struct userrec * u, int idx, char * par) {
  3419. char buf[1024], *cmd;
  3420. putlog(LOG_CMDS, "*", STR("#%s# netcrontab %s"), dcc[idx].nick, par);
  3421. cmd=newsplit(&par);
  3422. if ((strcmp(cmd, STR("status")) && strcmp(cmd, STR("show")) && strcmp(cmd, STR("delete")) && strcmp(cmd, STR("new")))) {
  3423. dprintf(idx, STR("Usage: netcrontab status|delete|show|new [interval]\n"));
  3424. return;
  3425. }
  3426. egg_snprintf(buf, sizeof buf, STR("exec crontab %s %s"), cmd, par);
  3427. botnet_send_cmd_broad(-1, botnetnick, dcc[idx].nick, idx, buf);
  3428. }
  3429. #endif /* HUB */
  3430. void rcmd_exec(char * frombot, char * fromhand, char * fromidx, char * par) {
  3431. char * cmd, scmd[512], *out, *err;
  3432. struct passwd *pw;
  3433. cmd=newsplit(&par);
  3434. scmd[0]=0;
  3435. if (!strcmp(cmd, "w")) {
  3436. strcpy(scmd, "w");
  3437. } else if (!strcmp(cmd, STR("last"))) {
  3438. char user[20];
  3439. if (par[0]) {
  3440. strncpyz(user, par, sizeof(user));
  3441. } else {
  3442. pw = getpwuid(geteuid());
  3443. if (!pw) return;
  3444. strncpyz(user, pw->pw_name, sizeof(user));
  3445. }
  3446. if (!user[0]) {
  3447. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Can't determine user id for process"));
  3448. return;
  3449. }
  3450. sprintf(scmd, STR("last %s"), user);
  3451. } else if (!strcmp(cmd, STR("ps"))) {
  3452. sprintf(scmd, STR("ps %s"), par);
  3453. } else if (!strcmp(cmd, STR("raw"))) {
  3454. sprintf(scmd, STR("%s"), par);
  3455. } else if (!strcmp(cmd, STR("kill"))) {
  3456. sprintf(scmd, STR("kill %s"), par);
  3457. } else if (!strcmp(cmd, STR("crontab"))) {
  3458. char * code=newsplit(&par);
  3459. scmd[0]=0;
  3460. if (!strcmp(code, STR("show"))) {
  3461. strcpy(scmd, STR("crontab -l | grep -v \"^#\""));
  3462. } else if (!strcmp(code, STR("delete"))) {
  3463. crontab_del();
  3464. } else if (!strcmp(code, STR("new"))) {
  3465. int i=atoi(par);
  3466. if ((i<=0) || (i>60))
  3467. i=10;
  3468. crontab_create(i);
  3469. }
  3470. if (!scmd[0]) {
  3471. char s[200];
  3472. int i;
  3473. i=crontab_exists();
  3474. if (!i)
  3475. sprintf(s, STR("No crontab"));
  3476. else if (i==1)
  3477. sprintf(s, STR("Crontabbed"));
  3478. else
  3479. sprintf(s, STR("Error checking crontab status"));
  3480. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, s);
  3481. }
  3482. }
  3483. if (!scmd[0])
  3484. return;
  3485. if (shell_exec(scmd, NULL, &out, &err)) {
  3486. if (out) {
  3487. char * p, * np;
  3488. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Result:"));
  3489. p=out;
  3490. while (p && p[0]) {
  3491. np=strchr(p, '\n');
  3492. if (np)
  3493. *np++=0;
  3494. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, p);
  3495. p=np;
  3496. }
  3497. nfree(out);
  3498. }
  3499. if (err) {
  3500. char * p, * np;
  3501. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Errors:"));
  3502. p=err;
  3503. while (p && p[0]) {
  3504. np=strchr(p, '\n');
  3505. if (np)
  3506. *np++=0;
  3507. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, p);
  3508. p=np;
  3509. }
  3510. nfree(err);
  3511. }
  3512. } else {
  3513. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("exec failed"));
  3514. }
  3515. }
  3516. static void cmd_botjump(struct userrec * u, int idx, char * par) {
  3517. char *tbot, buf[1024];
  3518. putlog(LOG_CMDS, "*", STR("#%s# botjump %s"), dcc[idx].nick, par);
  3519. tbot=newsplit(&par);
  3520. if (!tbot[0]) {
  3521. dprintf(idx, STR("Usage: botjump <botname> [server [port [pass]]]\n"));
  3522. return;
  3523. }
  3524. if (nextbot(tbot)<0) {
  3525. dprintf(idx, STR("No such linked bot\n"));
  3526. return;
  3527. }
  3528. sprintf(buf, STR("jump %s"), par);
  3529. botnet_send_cmd(botnetnick, tbot, dcc[idx].nick, idx, buf);
  3530. }
  3531. void rcmd_jump(char * frombot, char * fromhand, char * fromidx, char * par) {
  3532. #ifdef LEAF
  3533. char * other;
  3534. module_entry *me;
  3535. Function *func;
  3536. int port, default_port = 0;
  3537. if (!(me = module_find("server", 0, 0)) )
  3538. return;
  3539. func = me->funcs;
  3540. default_port = (*(int *)(func[24]));
  3541. if (par[0]) {
  3542. other = newsplit(&par);
  3543. port = atoi(newsplit(&par));
  3544. if (!port)
  3545. port = default_port;
  3546. strncpyz(((char *)(func[20])), other, 120); //newserver
  3547. (*(int *)(func[21])) = port; //newserverport
  3548. strncpyz(((char *)(func[22])), par, 120); //newserverpass
  3549. }
  3550. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Jumping..."));
  3551. (*(int *)(func[23])) = 0; //cycle_time
  3552. (func[SERVER_NUKESERVER]) ("jumping...");
  3553. #endif /* LEAF */
  3554. }
  3555. /* "Remotable" commands */
  3556. void gotremotecmd (char * forbot, char * frombot, char * fromhand, char * fromidx, char * cmd) {
  3557. char * par = cmd;
  3558. cmd=newsplit(&par);
  3559. if (!strcmp(cmd, STR("exec"))) {
  3560. rcmd_exec(frombot, fromhand, fromidx, par);
  3561. } else if (!strcmp(cmd, STR("curnick"))) {
  3562. rcmd_curnick(frombot, fromhand, fromidx);
  3563. } else if (!strcmp(cmd, STR("cursrv"))) {
  3564. rcmd_cursrv(frombot, fromhand, fromidx);
  3565. } else if (!strcmp(cmd, STR("jump"))) {
  3566. rcmd_jump(frombot, fromhand, fromidx, par);
  3567. } else if (!strcmp(cmd, STR("msg"))) {
  3568. rcmd_msg(forbot, frombot, fromhand, fromidx, par);
  3569. } else if (!strcmp(cmd, STR("ver"))) {
  3570. rcmd_ver(frombot, fromhand, fromidx);
  3571. } else if (!strcmp(cmd, STR("ping"))) {
  3572. rcmd_ping(frombot, fromhand, fromidx, par);
  3573. } else if (!strcmp(cmd, STR("pong"))) {
  3574. rcmd_pong(frombot, fromhand, fromidx, par);
  3575. } else if (!strcmp(cmd, STR("die"))) {
  3576. exit(0);
  3577. } else {
  3578. botnet_send_cmdreply(botnetnick, frombot, fromhand, fromidx, STR("Unrecognized remote command"));
  3579. }
  3580. }
  3581. void gotremotereply (char *frombot, char *tohand, char *toidx, char *ln) {
  3582. int idx = atoi(toidx);
  3583. if ((idx >= 0) && (idx < dcc_total) && (dcc[idx].type == &DCC_CHAT) && (!strcmp(dcc[idx].nick, tohand))) {
  3584. char *buf = nmalloc(strlen(frombot) + 2 + 1);
  3585. sprintf(buf, "(%s)", frombot);
  3586. dprintf(idx, STR("%-13s %s\n"), buf, ln);
  3587. nfree(buf);
  3588. }
  3589. }
  3590. static void cmd_traffic(struct userrec *u, int idx, char *par)
  3591. {
  3592. unsigned long itmp, itmp2;
  3593. dprintf(idx, STR("Traffic since last restart\n"));
  3594. dprintf(idx, "==========================\n");
  3595. if (otraffic_irc > 0 || itraffic_irc > 0 || otraffic_irc_today > 0 ||
  3596. itraffic_irc_today > 0) {
  3597. dprintf(idx, "IRC:\n");
  3598. dprintf(idx, " out: %s", btos(otraffic_irc + otraffic_irc_today));
  3599. dprintf(idx, " (%s today)\n", btos(otraffic_irc_today));
  3600. dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_irc_today));
  3601. dprintf(idx, " (%s today)\n", btos(itraffic_irc_today));
  3602. }
  3603. if (otraffic_bn > 0 || itraffic_bn > 0 || otraffic_bn_today > 0 ||
  3604. itraffic_bn_today > 0) {
  3605. dprintf(idx, STR("Botnet:\n"));
  3606. dprintf(idx, " out: %s", btos(otraffic_bn + otraffic_bn_today));
  3607. dprintf(idx, " (%s today)\n", btos(otraffic_bn_today));
  3608. dprintf(idx, " in: %s", btos(itraffic_bn + itraffic_bn_today));
  3609. dprintf(idx, " (%s today)\n", btos(itraffic_bn_today));
  3610. }
  3611. if (otraffic_dcc > 0 || itraffic_dcc > 0 || otraffic_dcc_today > 0 ||
  3612. itraffic_dcc_today > 0) {
  3613. dprintf(idx, STR("Partyline:\n"));
  3614. itmp = otraffic_dcc + otraffic_dcc_today;
  3615. itmp2 = otraffic_dcc_today;
  3616. dprintf(idx, " out: %s", btos(itmp));
  3617. dprintf(idx, " (%s today)\n", btos(itmp2));
  3618. dprintf(idx, " in: %s", btos(itraffic_dcc + itraffic_dcc_today));
  3619. dprintf(idx, " (%s today)\n", btos(itraffic_dcc_today));
  3620. }
  3621. if (otraffic_trans > 0 || itraffic_trans > 0 || otraffic_trans_today > 0 ||
  3622. itraffic_trans_today > 0) {
  3623. dprintf(idx, STR("Transfer.mod:\n"));
  3624. dprintf(idx, " out: %s", btos(otraffic_trans + otraffic_trans_today));
  3625. dprintf(idx, " (%s today)\n", btos(otraffic_trans_today));
  3626. dprintf(idx, " in: %s", btos(itraffic_trans + itraffic_trans_today));
  3627. dprintf(idx, " (%s today)\n", btos(itraffic_trans_today));
  3628. }
  3629. if (otraffic_unknown > 0 || otraffic_unknown_today > 0) {
  3630. dprintf(idx, "Misc:\n");
  3631. dprintf(idx, " out: %s", btos(otraffic_unknown + otraffic_unknown_today));
  3632. dprintf(idx, " (%s today)\n", btos(otraffic_unknown_today));
  3633. dprintf(idx, " in: %s", btos(itraffic_unknown + itraffic_unknown_today));
  3634. dprintf(idx, " (%s today)\n", btos(itraffic_unknown_today));
  3635. }
  3636. dprintf(idx, "---\n");
  3637. dprintf(idx, "Total:\n");
  3638. itmp = otraffic_irc + otraffic_bn + otraffic_dcc + otraffic_trans
  3639. + otraffic_unknown + otraffic_irc_today + otraffic_bn_today
  3640. + otraffic_dcc_today + otraffic_trans_today + otraffic_unknown_today;
  3641. itmp2 = otraffic_irc_today + otraffic_bn_today + otraffic_dcc_today
  3642. + otraffic_trans_today + otraffic_unknown_today;
  3643. dprintf(idx, " out: %s", btos(itmp));
  3644. dprintf(idx, " (%s today)\n", btos(itmp2));
  3645. dprintf(idx, " in: %s", btos(itraffic_irc + itraffic_bn + itraffic_dcc
  3646. + itraffic_trans + itraffic_unknown + itraffic_irc_today
  3647. + itraffic_bn_today + itraffic_dcc_today + itraffic_trans_today
  3648. + itraffic_unknown_today));
  3649. dprintf(idx, " (%s today)\n", btos(itraffic_irc_today + itraffic_bn_today
  3650. + itraffic_dcc_today + itraffic_trans_today
  3651. + itraffic_unknown_today));
  3652. putlog(LOG_CMDS, "*", STR("#%s# traffic"), dcc[idx].nick);
  3653. }
  3654. static char traffictxt[20];
  3655. static char *btos(unsigned long bytes)
  3656. {
  3657. char unit[10];
  3658. float xbytes;
  3659. sprintf(unit, "Bytes");
  3660. xbytes = bytes;
  3661. if (xbytes > 1024.0) {
  3662. sprintf(unit, "KBytes");
  3663. xbytes = xbytes / 1024.0;
  3664. }
  3665. if (xbytes > 1024.0) {
  3666. sprintf(unit, "MBytes");
  3667. xbytes = xbytes / 1024.0;
  3668. }
  3669. if (xbytes > 1024.0) {
  3670. sprintf(unit, "GBytes");
  3671. xbytes = xbytes / 1024.0;
  3672. }
  3673. if (xbytes > 1024.0) {
  3674. sprintf(unit, "TBytes");
  3675. xbytes = xbytes / 1024.0;
  3676. }
  3677. if (bytes > 1024)
  3678. sprintf(traffictxt, "%.2f %s", xbytes, unit);
  3679. else
  3680. sprintf(traffictxt, "%lu Bytes", bytes);
  3681. return traffictxt;
  3682. }
  3683. static void cmd_whoami(struct userrec *u, int idx, char *par)
  3684. {
  3685. dprintf(idx, "You are %s@%s.\n", dcc[idx].nick, botnetnick);
  3686. putlog(LOG_CMDS, "*", STR("#%s# whoami"), dcc[idx].nick);
  3687. }
  3688. /* DCC CHAT COMMANDS
  3689. */
  3690. /* Function call should be:
  3691. * int cmd_whatever(idx,"parameters");
  3692. * As with msg commands, function is responsible for any logging.
  3693. */
  3694. cmd_t C_dcc[] =
  3695. {
  3696. {"+host", "m|m", (Function) cmd_pls_host, NULL},
  3697. {"+ignore", "m", (Function) cmd_pls_ignore, NULL},
  3698. {"+user", "m", (Function) cmd_pls_user, NULL},
  3699. #ifdef HUB
  3700. {"-bot", "a", (Function) cmd_mns_user, NULL},
  3701. #endif /* HUB */
  3702. {"-host", "", (Function) cmd_mns_host, NULL},
  3703. {"-ignore", "m", (Function) cmd_mns_ignore, NULL},
  3704. {"-user", "m", (Function) cmd_mns_user, NULL},
  3705. {"addlog", "mo|o", (Function) cmd_addlog, NULL},
  3706. /* {"putlog", "mo|o", (Function) cmd_addlog, NULL}, */
  3707. {"about", "", (Function) cmd_about, NULL},
  3708. {"away", "", (Function) cmd_away, NULL},
  3709. {"back", "", (Function) cmd_back, NULL},
  3710. #ifdef HUB
  3711. {"backup", "m|m", (Function) cmd_backup, NULL},
  3712. {"binds", "a", (Function) cmd_binds, NULL},
  3713. {"boot", "m", (Function) cmd_boot, NULL},
  3714. {"botconfig", "n", (Function) cmd_botconfig, NULL},
  3715. {"botinfo", "", (Function) cmd_botinfo, NULL},
  3716. {"bots", "m", (Function) cmd_bots, NULL},
  3717. {"downbots", "m", (Function) cmd_downbots, NULL},
  3718. {"bottree", "n", (Function) cmd_bottree, NULL},
  3719. {"chaddr", "a", (Function) cmd_chaddr, NULL},
  3720. #endif /* HUB */
  3721. {"chat", "", (Function) cmd_chat, NULL},
  3722. {"chattr", "m|m", (Function) cmd_chattr, NULL},
  3723. #ifdef HUB
  3724. {"chhandle", "m", (Function) cmd_chhandle, NULL},
  3725. {"chnick", "m", (Function) cmd_chhandle, NULL},
  3726. {"chpass", "m", (Function) cmd_chpass, NULL},
  3727. {"chsecpass", "n", (Function) cmd_chsecpass, NULL},
  3728. #ifdef S_DCCPASS
  3729. {"cmdpass", "a", (Function) cmd_cmdpass, NULL},
  3730. #endif /* S_DCCPASS */
  3731. #endif /* HUB */
  3732. {"color", "", (Function) cmd_color, NULL},
  3733. {"comment", "m|m", (Function) cmd_comment, NULL},
  3734. #ifdef HUB
  3735. {"config", "n", (Function) cmd_config, NULL},
  3736. #endif /* HUB */
  3737. {"console", "-|-", (Function) cmd_console, NULL},
  3738. {"date", "", (Function) cmd_date, NULL},
  3739. #ifdef HUB
  3740. {"dccstat", "a", (Function) cmd_dccstat, NULL},
  3741. #endif /* HUB */
  3742. {"debug", "a", (Function) cmd_debug, NULL},
  3743. {"die", "n", (Function) cmd_die, NULL},
  3744. {"echo", "", (Function) cmd_echo, NULL},
  3745. {"fixcodes", "", (Function) cmd_fixcodes, NULL},
  3746. {"handle", "", (Function) cmd_handle, NULL},
  3747. {"nohelp", "-|-", (Function) cmd_nohelp, NULL, 1},
  3748. {"help", "-|-", (Function) cmd_help, NULL},
  3749. {"ignores", "m", (Function) cmd_ignores, NULL},
  3750. #ifdef HUB
  3751. {"link", "n", (Function) cmd_link, NULL},
  3752. #endif /* HUB */
  3753. {"match", "m|m", (Function) cmd_match, NULL},
  3754. {"me", "", (Function) cmd_me, NULL},
  3755. {"motd", "", (Function) cmd_motd, NULL},
  3756. #ifdef HUB
  3757. #ifdef S_TCLCMDS
  3758. {"nettcl", "a", (Function) cmd_nettcl, NULL},
  3759. #endif /* S_TCLCMDS */
  3760. {"newleaf", "n", (Function) cmd_newleaf, NULL},
  3761. #endif /* HUB */
  3762. {"newpass", "", (Function) cmd_newpass, NULL},
  3763. {"secpass", "", (Function) cmd_secpass, NULL},
  3764. {"nick", "", (Function) cmd_handle, NULL},
  3765. {"page", "", (Function) cmd_page, NULL},
  3766. {"quit", "", (Function) NULL, NULL},
  3767. {"relay", "i", (Function) cmd_relay, NULL},
  3768. #ifdef HUB
  3769. {"reload", "m|m", (Function) cmd_reload, NULL},
  3770. #endif /* HUB */
  3771. {"restart", "m", (Function) cmd_restart, NULL},
  3772. #ifdef HUB
  3773. {"save", "m|m", (Function) cmd_save, NULL},
  3774. {"set", "a", (Function) cmd_set, NULL},
  3775. #endif /* HUB */
  3776. {"simul", "a", (Function) cmd_simul, NULL},
  3777. {"status", "m|m", (Function) cmd_status, NULL},
  3778. {"strip", "", (Function) cmd_strip, NULL},
  3779. {"su", "a", (Function) cmd_su, NULL},
  3780. #ifdef S_TCLCMDS
  3781. {"tcl", "a", (Function) cmd_tcl, NULL},
  3782. #endif /* S_TCLCMDS */
  3783. #ifdef HUB
  3784. {"trace", "n", (Function) cmd_trace, NULL},
  3785. #endif /* HUB */
  3786. {"traffic", "m", (Function) cmd_traffic, NULL},
  3787. {"unlink", "m", (Function) cmd_unlink, NULL},
  3788. {"update", "a", (Function) cmd_update, NULL},
  3789. #ifdef HUB
  3790. {"netcrontab", "a", (Function) cmd_netcrontab, NULL},
  3791. #endif /* HUB */
  3792. {"uptime", "m|m", (Function) cmd_uptime, NULL},
  3793. {"crontab", "a", (Function) cmd_crontab, NULL},
  3794. #ifdef HUB
  3795. {"vbottree", "n", (Function) cmd_vbottree, NULL},
  3796. {"who", "n", (Function) cmd_who, NULL},
  3797. #endif /* HUB */
  3798. {"whois", "", (Function) cmd_whois, NULL},
  3799. {"whom", "", (Function) cmd_whom, NULL},
  3800. {"whoami", "", (Function) cmd_whoami, NULL},
  3801. {"botjump", "n", (Function) cmd_botjump, NULL},
  3802. {"botmsg", "o", (Function) cmd_botmsg, NULL},
  3803. {"netmsg", "n", (Function) cmd_netmsg, NULL},
  3804. {"botnick", "m", (Function) cmd_botnick, NULL},
  3805. {"netnick", "m", (Function) cmd_netnick, NULL},
  3806. #ifdef HUB
  3807. {"netw", "n", (Function) cmd_netw, NULL},
  3808. {"netps", "n", (Function) cmd_netps, NULL},
  3809. {"netlast", "n", (Function) cmd_netlast, NULL},
  3810. #endif /* HUB */
  3811. {"netlag", "m", (Function) cmd_netlag, NULL},
  3812. {"botserver", "m", (Function) cmd_botserver, NULL},
  3813. {"netserver", "m", (Function) cmd_netserver, NULL},
  3814. {"botversion", "o", (Function) cmd_botversion, NULL},
  3815. {"netversion", "o", (Function) cmd_netversion, NULL},
  3816. {"userlist", "m", (Function) cmd_userlist, NULL},
  3817. {"ps", "n", (Function) cmd_ps, NULL},
  3818. {"last", "n", (Function) cmd_last, NULL},
  3819. {"exec", "a", (Function) cmd_exec, NULL},
  3820. {"w", "n", (Function) cmd_w, NULL},
  3821. {"channels", "", (Function) cmd_channels, NULL},
  3822. {"randstring", "", (Function) cmd_randstring, NULL},
  3823. #ifdef HUB
  3824. {"botcmd", "i", (Function) cmd_botcmd, NULL},
  3825. {"bc", "i", (Function) cmd_botcmd, NULL},
  3826. {"hublevel", "a", (Function) cmd_hublevel, NULL},
  3827. {"lagged", "m", (Function) cmd_lagged, NULL},
  3828. {"uplink", "a", (Function) cmd_uplink, NULL},
  3829. #endif /* HUB */
  3830. {NULL, NULL, NULL, NULL}
  3831. };