cmds.c 134 KB

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