cmds.c 133 KB

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