cmds.c 137 KB

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