cmds.c 137 KB

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