cmds.c 123 KB

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