cmds.c 137 KB

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