cmds.c 133 KB

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