cmds.c 134 KB

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