cmds.c 118 KB

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