cmds.c 122 KB

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