cmds.c 133 KB

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