cmds.c 130 KB

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