cmds.c 140 KB

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