cmds.c 142 KB

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