cmds.c 146 KB

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