cmds.c 141 KB

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