cmds.c 120 KB

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