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