cmds.c 136 KB

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