cmds.c 143 KB

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