cmds.c 133 KB

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