cmds.c 140 KB

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