cmds.c 132 KB

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