cmds.c 134 KB

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