cmds.c 133 KB

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