cmds.c 132 KB

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