cmds.c 147 KB

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