cmds.cc 146 KB

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