cmds.c 137 KB

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