cmds.c 133 KB

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