cmds.c 133 KB

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