cmds.c 127 KB

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