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