cmds.c 132 KB

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