cmds.c 122 KB

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