cmds.c 134 KB

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