cmds.c 137 KB

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