cmds.c 123 KB

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