cmds.c 135 KB

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