cmds.c 123 KB

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