cmds.c 132 KB

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