cmds.c 146 KB

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