cmds.c 137 KB

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