cmds.c 140 KB

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