cmds.c 123 KB

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