cmds.c 135 KB

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