cmds.c 131 KB

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