cmds.c 140 KB

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