cmds.c 133 KB

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