cmds.c 133 KB

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