cmds.c 140 KB

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