cmds.c 133 KB

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