cmds.c 131 KB

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