cmds.c 132 KB

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