protocol_admincgi.cpp 245 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391
  1. #ifdef _WIN32
  2. #include <winsock2.h>
  3. #endif
  4. #include <stdio.h>
  5. #include "protocol_shoutcastClient.h"
  6. #include "protocol_admincgi.h"
  7. #include "protocol_HTTPStyle.h"
  8. #include "protocol_relay.h"
  9. #include "base64.h"
  10. #include "banList.h"
  11. #include "ripList.h"
  12. #include "adminList.h"
  13. #include "agentList.h"
  14. #include "uvox2Common.h"
  15. #include "w3cLog.h"
  16. #include "yp2.h"
  17. #include "updater.h"
  18. #include "aolxml/aolxml.h"
  19. #include "webNet/urlUtils.h"
  20. #include "file/fileUtils.h"
  21. #include "services/stdServiceImpl.h"
  22. #include "bandwidth.h"
  23. #include "cpucount.h"
  24. using namespace std;
  25. using namespace stringUtil;
  26. using namespace uniString;
  27. time_t last_update_check = 0;
  28. utf8 logId, logTailId, listenerId;
  29. #define DEBUG_LOG(...) do { if (gOptions.httpStyleDebug()) DLOG(__VA_ARGS__); } while (0)
  30. #define LOG_NAME "ADMINCGI"
  31. #define LOGNAME "[" LOG_NAME "] "
  32. #define HEAD_REQUEST (m_httpRequestInfo.m_request == protocol_HTTPStyle::HTTP_HEAD)
  33. #define SHRINK (m_httpRequestInfo.m_AcceptEncoding & protocol_HTTPStyle::ACCEPT_GZIP)
  34. #define COMPRESS(header, body) if (SHRINK && compressData(body)) header += "Content-Encoding:gzip\r\n"
  35. static bool sortUniqueClientDataByTime(const stats::uniqueClientData_t &a, const stats::uniqueClientData_t &b)
  36. {
  37. return (a.m_connectTime < b.m_connectTime);
  38. }
  39. utf8 getStreamAdminHeader(const streamData::streamID_t sid, const utf8& headerTitle,
  40. const int refreshRequired = 0, const bool style = false)
  41. {
  42. return "<!DOCTYPE html><html><head>"
  43. "<meta charset=\"utf-8\">"
  44. "<meta name=viewport content=\"width=device-width, initial-scale=1\">"
  45. "<title>Shoutcast Administrator</title>"
  46. "<link href=\"index.css\" rel=\"stylesheet\" type=\"text/css\">"
  47. "<link href=\"images/favicon.ico\" rel=\"shortcut icon\" type=\"" +
  48. gOptions.faviconFileMimeType() + "\">" + (abs(refreshRequired) > 0 ?
  49. "<meta http-equiv=\"refresh\"content=\"3; url=admin.cgi?sid=" + tos(sid) + "\">" : "") +
  50. (style ? "<style type=\"text/css\">"
  51. "li img{vertical-align:bottom;}li{padding-bottom:0.5em;}"
  52. "</style>" : (utf8)"") +
  53. "</head><body style=\"margin:0;\">"
  54. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>"
  55. "<td><div class=\"logo\">Shoutcast " + headerTitle + "</div></td>"
  56. "<td style=\"text-align:right;vertical-align:bottom;padding-right:0.1em;\">"
  57. "<div id=\"up\"></div><a target=\"_blank\" title=\"Built: " __DATE__"\" "
  58. "href=\"http://www.shoutcast.com\">Shoutcast Server v" +
  59. addWBR(gOptions.getVersionBuildStrings() + "/" SERV_OSNAME) + "</a></td>"
  60. "</tr><tr><td class=\"thr\" align=\"center\" colspan=\"3\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
  61. "<tr><td class=\"thr\" align=\"center\"><div id=\"hdrbox\" class=\"tnl\" "
  62. "style=\"justify-content:space-around;display:flex;flex-flow:row wrap;\">"
  63. "<div class=\"thr\"><a href=\"admin.cgi?sid=" + tos(sid) + "\">Status &amp; Listeners</a></div>"
  64. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  65. "<div class=\"thr\"><a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=history\">History&nbsp;"
  66. "<img border=\"0\" title=\"History\" alt=\"History\" style=\"vertical-align:middle\" src=\"images/history.png\"></a></div>"
  67. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  68. + (!(gOptions.read_stream_adminPassword(sid) && !gOptions.stream_adminPassword(sid).empty()) ?
  69. "<div class=\"thr\"><a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=viewlog\">Log</a> "
  70. "(<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=viewlog&amp;viewlog=tail\">Tailing</a>"
  71. " | <a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=viewlog&amp;viewlog=save\">Save</a>)</div>"
  72. "<div class=\"thr\">&nbsp;|&nbsp;</div>" : "") +
  73. /*+ utf8(info.m_radionomyID.empty() ? warningImage(false) + "&nbsp;&nbsp;<b>Please Register Your Authhash</b><br><br>" : "") +*/
  74. "<div class=\"thr\"><a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Authhash</a></div>"
  75. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  76. "<div class=\"thr\"><a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=viewban\">Ban List</a></div>"
  77. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  78. "<div class=\"thr\"><a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=viewrip\">Reserved List</a></div>"
  79. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  80. "<div class=\"thr\"><a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=viewagent\">User Agent List</a></div>"
  81. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  82. "<div class=\"thr\"><a href=\"index.html?sid=" + tos(sid) + "\">Stream Logout</a></div>"
  83. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  84. "<div class=\"thr\"><a href=\"admin.cgi\">Server Login&nbsp;"
  85. "<img border=\"0\" title=\"Server Login\nPassword Required\" alt=\"Server Login\nPassword Required"
  86. "\" style=\"vertical-align:middle\" src=\"images/lock.png\"></a></div>"
  87. "</div></td></tr></table></td></tr></table>";
  88. }
  89. utf8 getServerAdminHeader(const utf8& headerTitle, const int refreshRequired = 0,
  90. const utf8& childPage = "", const int style = 0)
  91. {
  92. return "<!DOCTYPE html><html><head>"
  93. "<meta charset=\"utf-8\">"
  94. "<meta name=viewport content=\"width=device-width, initial-scale=1\">"
  95. "<title>Shoutcast Server Administrator</title>"
  96. "<link href=\"index.css\" rel=\"stylesheet\" type=\"text/css\">"
  97. "<link href=\"images/favicon.ico\" rel=\"shortcut icon\" type=\"" +
  98. gOptions.faviconFileMimeType() + "\">" +
  99. (abs(refreshRequired) > 0 ? "<meta http-equiv=\"refresh\"content=\"" +
  100. tos(abs(refreshRequired)) + "; url=admin.cgi?sid=0" + childPage + "\">" : "") +
  101. (style ? "<style type=\"text/css\">" +
  102. (style == 1 ? ".s,.t,.st{border-style:solid;border-color:#CCCCCC;padding:0.2em 1em;text-align:center;}"
  103. ".s,.t,.st{border-width:1px;}"
  104. /* this fixes a FF quirk with some of the edges being hidden*/
  105. ".infh{position:static;}" :
  106. (style == 2 ? "li img{vertical-align:bottom;}li{padding-bottom:0.5em;}" : (utf8)"")) + "</style>" : (utf8)"") +
  107. "</head><body style=\"margin:0;\">"
  108. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>"
  109. "<td><div class=\"logo\">Shoutcast " + headerTitle + "</div></td>"
  110. "<td style=\"text-align:right;vertical-align:bottom;padding-right:0.1em;\">"
  111. "<div id=\"up\"></div><a target=\"_blank\" title=\"Built: " __DATE__"\" "
  112. "href=\"http://www.shoutcast.com\">Shoutcast Server v" +
  113. addWBR(gOptions.getVersionBuildStrings() + "/" SERV_OSNAME) + "</a></td></tr>"
  114. "<tr><td class=\"thr\" align=\"center\" colspan=\"3\">"
  115. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
  116. "<tr><td class=\"thr\" align=\"center\"><div id=\"hdrbox\" class=\"tnl\" "
  117. "style=\"justify-content:space-around;display:flex;flex-flow:row wrap;\">"
  118. "<div class=\"thr\"><a href=\"admin.cgi?mode=help\">Help &amp; Documentation</a></div>"
  119. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  120. "<div class=\"thr\"><a href=\"admin.cgi?mode=bandwidth\">Bandwidth Usage</a></div>"
  121. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  122. "<div class=\"thr\"><a href=\"admin.cgi?mode=viewlog&amp;server=" + randomId(logId) + "\">Log</a> "
  123. "(<a href=\"admin.cgi?mode=viewlog&amp;server=" + logId + "&amp;viewlog=tail\">Tailing</a> | "
  124. "<a href=\"admin.cgi?mode=viewlog&amp;server=" + logId + "&amp;viewlog=save\">Save</a>)</div>"
  125. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  126. "<div class=\"thr\"><a href=\"admin.cgi\">Summary</a></div>"
  127. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  128. "<div class=\"thr\"><a href=\"admin.cgi?mode=viewban\">Ban List</a></div>"
  129. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  130. "<div class=\"thr\"><a href=\"admin.cgi?mode=viewrip\">Reserved List</a></div>"
  131. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  132. "<div class=\"thr\"><a href=\"admin.cgi?mode=viewagent\">User Agent List</a></div>"
  133. "<div class=\"thr\">&nbsp;|&nbsp;</div>"
  134. "<div class=\"thr\"><a href=\"index.html\">Server Logout&nbsp;</a></div>"
  135. "</div></td></tr></table></td></tr></table>";
  136. }
  137. static utf8 formatSizeString(const __uint64 size)
  138. {
  139. utf8::value_type buf[128] = {0};
  140. if (size < 1024)
  141. {
  142. snprintf((char *)buf, sizeof(buf), "%llu B", size);
  143. }
  144. else if(size < 1048576)
  145. {
  146. snprintf((char *)buf, sizeof(buf), "%.02f KiB", size/1024.0f);
  147. }
  148. else if(size < 1073741824)
  149. {
  150. snprintf((char *)buf, sizeof(buf), "%.02f MiB", size/1048576.0f);
  151. }
  152. else if(size < 1099511627776LL)
  153. {
  154. snprintf((char *)buf, sizeof(buf), "%.02f GiB", size/1073741824.0f);
  155. }
  156. else
  157. {
  158. snprintf((char *)buf, sizeof(buf), "%.02f TiB", size/1099511627776.0f);
  159. }
  160. return buf;
  161. }
  162. utf8 getCheckedDuration(const size_t time)
  163. {
  164. if (time >= 60)
  165. {
  166. if (time < 3600)
  167. {
  168. size_t min = (time / 60);
  169. return (tos(min) + " minute" + (min != 1 ? "s" : "") + " ago");
  170. }
  171. else if (time < 86400)
  172. {
  173. size_t hour = (time / 3600);
  174. return (tos(hour) + " hour" + (hour != 1 ? "s" : "") + " ago");
  175. }
  176. else
  177. {
  178. size_t week = (time / 86400);
  179. return (tos(week) + " week" + (week != 1 ? "s" : "") + " ago");
  180. }
  181. }
  182. return "less than a minute ago";
  183. }
  184. utf8 niceURL(utf8 srcAddr)
  185. {
  186. if (!srcAddr.empty())
  187. {
  188. utf8::size_type pos = srcAddr.find(utf8("://"));
  189. if (pos != utf8::npos && ((pos == 4) || (pos == 5)))
  190. {
  191. srcAddr = srcAddr.substr(pos + 3);
  192. }
  193. srcAddr = aolxml::escapeXML(srcAddr);
  194. // look for a /stream/x/ path and strip off the end / so the
  195. // link goes to the admin page instead of playing the stream
  196. if (!srcAddr.empty())
  197. {
  198. utf8::size_type pos2 = srcAddr.find(utf8("/stream/")),
  199. pos3 = srcAddr.rfind(utf8("/"));
  200. if ((pos2 != utf8::npos) &&
  201. ((pos3 != utf8::npos) && (pos3 > pos2) &&
  202. (pos3 == srcAddr.size()-1)))
  203. {
  204. srcAddr = srcAddr.substr(0, pos3);
  205. }
  206. }
  207. }
  208. return srcAddr;
  209. }
  210. void restartRelay(const config::streamConfig &info) throw()
  211. {
  212. bool noEntry = false;
  213. const int relayActive = (streamData::isRelayActive(info.m_streamID, noEntry) & 12);
  214. if (!relayActive || !noEntry)
  215. {
  216. threadedRunner::scheduleRunnable(new protocol_relay(info));
  217. }
  218. }
  219. void checkVersion(const time_t t)
  220. {
  221. utf8 tempId;
  222. httpHeaderMap_t queryParameters;
  223. queryParameters["id"] = randomId(tempId);
  224. yp2::runAuthHashAction(tempId, yp2::VER_CHECK, "/yp2", queryParameters,
  225. "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
  226. "<yp version=\"2\"><cmd op=\"version\" seq=\"1\">"\
  227. "<dnas>" + gOptions.getVersionBuildStrings() + "/" SERV_OSNAME "</dnas></cmd></yp>");
  228. last_update_check = t;
  229. }
  230. utf8 getUptimeScript(const bool base = false, const bool stream = false, const time_t streamUptime = 0)
  231. {
  232. // TODO need to consider improving this to better deal with leap years, etc
  233. // used to increment the uptime value on the server admin page
  234. return (!base ? "<script type=\"text/javascript\">"
  235. "function $(id){return document.getElementById(id);}" EL : (utf8)"") +
  236. "function pad(num){return(num<10?'0':'')+num;}" EL
  237. "var i=" + tos((::time(NULL) - g_upTime)) + ";" EL
  238. "function time(t,slim){" EL
  239. "var min=parseInt(t/60);" EL
  240. "var sec=t-parseInt(min*60);" EL
  241. "var hours=parseInt(min/60);" EL
  242. "min-=parseInt(hours*60);" EL
  243. "var r=\"\";" EL
  244. "var days=parseInt(hours/24);" EL
  245. "hours-=parseInt(days*24);" EL
  246. "var weeks=parseInt(days/7);" EL
  247. "days-=parseInt(weeks*7);" EL
  248. "var years=parseInt(weeks/52);" EL
  249. "weeks-=parseInt(years*52);" EL
  250. "if(years)r+=years+\" year\"+(years!=1?\"s\":\"\")+\" \";" EL
  251. "if(weeks)r+=weeks+\" week\"+(weeks!=1?\"s\":\"\")+\" \";" EL
  252. "if(days)r+=days+\" day\"+(days!=1?\"s\":\"\")+\" \";" EL
  253. "if(slim){" EL
  254. "r+=pad(hours)+\":\"+pad(min)+\":\"+pad(sec);" EL
  255. "}else{" EL
  256. "if(hours)r+=hours+\" hour\"+(hours!=1?\"s\":\"\")+\" \";" EL
  257. "if(min)r+=min+\" minute\"+(min!=1?\"s\":\"\")+\" \";" EL
  258. "if(sec)r+=sec+\" second\"+(sec!=1?\"s\":\"\");" EL
  259. "}" EL
  260. "return r;" EL
  261. "}" EL
  262. "function count(){i++;$('up').innerHTML=\"" + (sDaemon ?
  263. #ifdef _WIN32
  264. "Service"
  265. #else
  266. "Daemon"
  267. #endif
  268. : "") + " Uptime: \"+(!i?\"Starting&hellip;\":time(i,1));}" EL
  269. "count();setInterval(count,1000);" EL +
  270. // used to increment the uptime value on the stream admin pages
  271. (stream ?
  272. "var is=" + tos(streamUptime) + ";" EL
  273. "function counts(){is++;$('up2').innerHTML=\"<b>\"+(!is?\"Starting&hellip;\":time(is,0))+\"<\\/b>\";}" EL
  274. "counts();setInterval(counts,1000);" EL : "") +
  275. (!base ? "</script>" : "");
  276. }
  277. const bool reloadConfig(const int force)
  278. {
  279. bool m_reloadRefresh = false;
  280. ILOG(gOptions.logSectionName() + "Starting stream config reload from `" + fileUtil::getFullFilePath(gOptions.confFile()) + "'");
  281. config newOptions;
  282. newOptions.load(gOptions.confFile());
  283. vector<config::streamConfig> relays;
  284. // to ease testing, especially on remote systems, will
  285. // allow toggling of the debugging options for v2.1+
  286. ILOG(gOptions.logSectionName() + "Processing global configuration settings...");
  287. if (newOptions.cdn() != gOptions.cdn())
  288. {
  289. ILOG(gOptions.logSectionName() + "Changing CDN mode from " + (!gOptions.cdn().empty() ? gOptions.cdn() : "off") +
  290. " to " + (!newOptions.cdn().empty() ? newOptions.cdn() : "off"));
  291. try
  292. {
  293. gOptions.setOption(utf8("cdn"),utf8(newOptions.cdn()));
  294. }
  295. catch(const exception &)
  296. {
  297. }
  298. }
  299. if (newOptions.maxUser() != gOptions.maxUser())
  300. {
  301. const int old_maxUser = gOptions.maxUser(),
  302. new_maxUser = newOptions.maxUser();
  303. ILOG(gOptions.logSectionName() + "Changing server maxuser from " +
  304. (old_maxUser > 0 ? tos(old_maxUser) : "unlimited") + " to " +
  305. (new_maxUser > 0 ? tos(new_maxUser) : "unlimited"));
  306. gOptions.setOption(utf8("maxuser"),utf8(tos(newOptions.maxUser())));
  307. }
  308. if (newOptions.maxBitrate() != gOptions.maxBitrate())
  309. {
  310. ILOG(gOptions.logSectionName() + "Changing server maxbitrate from " +
  311. (gOptions.maxBitrate() > 0 ? tos(gOptions.maxBitrate()) + "bps" : "unlimited") + " to " +
  312. (newOptions.maxBitrate() > 0 ? tos(newOptions.maxBitrate()) + "bps" : "unlimited"));
  313. gOptions.setOption(utf8("maxbitrate"),utf8(tos(newOptions.maxBitrate())));
  314. }
  315. if (newOptions.minBitrate() != gOptions.minBitrate())
  316. {
  317. ILOG(gOptions.logSectionName() + "Changing server minbitrate from " +
  318. (gOptions.minBitrate() > 0 ? tos(gOptions.minBitrate()) + "bps" : "unlimited") + " to " +
  319. (newOptions.minBitrate() > 0 ? tos(newOptions.minBitrate()) + "bps" : "unlimited"));
  320. gOptions.setOption(utf8("minbitrate"),utf8(tos(newOptions.minBitrate())));
  321. }
  322. bool publicChanged = false;
  323. if (newOptions.publicServer() != gOptions.publicServer())
  324. {
  325. ILOG(gOptions.logSectionName() + "Changing state of publicserver - killing sources as applicable");
  326. gOptions.setOption(utf8("publicserver"),newOptions.publicServer());
  327. publicChanged = true;
  328. }
  329. // update the server-wide hiding and redirection options
  330. if (newOptions.hideStats() != gOptions.hideStats())
  331. {
  332. ILOG(gOptions.logSectionName() + "Changing 'hidestats'");
  333. gOptions.setOption(utf8("hidestats"),utf8(newOptions.hideStats()));
  334. }
  335. if (newOptions.redirectUrl() != gOptions.redirectUrl())
  336. {
  337. ILOG(gOptions.logSectionName() + "Changing 'redirecturl'");
  338. gOptions.setOption(utf8("redirecturl"),utf8(newOptions.redirectUrl()));
  339. }
  340. if (newOptions.ripOnly() != gOptions.ripOnly())
  341. {
  342. ILOG(gOptions.logSectionName() + "Changing 'riponly'");
  343. gOptions.setOption(utf8("riponly"),utf8(tos(newOptions.ripOnly())));
  344. }
  345. if (newOptions.blockEmptyUserAgent() != gOptions.blockEmptyUserAgent())
  346. {
  347. ILOG(gOptions.logSectionName() + "Changing 'blockemptyuseragent'");
  348. gOptions.setOption(utf8("blockemptyuseragent"),utf8(tos(newOptions.blockEmptyUserAgent())));
  349. }
  350. if (newOptions.metricsMaxQueue() != gOptions.metricsMaxQueue())
  351. {
  352. ILOG(gOptions.logSectionName() + "Changing 'metricsmaxqueue'");
  353. gOptions.setOption(utf8("metricsmaxqueue"),utf8(tos(newOptions.metricsMaxQueue())));
  354. }
  355. metrics::metrics_apply(newOptions);
  356. if (newOptions.relayReconnectTime() != gOptions.relayReconnectTime())
  357. {
  358. ILOG(gOptions.logSectionName() + "Changing 'relayreconnecttime'");
  359. gOptions.setOption(utf8("relayreconnecttime"),utf8(tos(newOptions.relayReconnectTime())));
  360. }
  361. if (newOptions.relayConnectRetries() != gOptions.relayConnectRetries())
  362. {
  363. ILOG(gOptions.logSectionName() + "Changing 'relayconnectretries'");
  364. gOptions.setOption(utf8("relayconnectretries"),utf8(tos(newOptions.relayConnectRetries())));
  365. }
  366. if (newOptions.backupLoop() != gOptions.backupLoop())
  367. {
  368. ILOG(gOptions.logSectionName() + "Changing 'backuploop'");
  369. gOptions.setOption(utf8("backuploop"),utf8(tos(newOptions.backupLoop())));
  370. }
  371. if (newOptions.songHistory() != gOptions.songHistory())
  372. {
  373. ILOG(gOptions.logSectionName() + "Changing 'songhistory'");
  374. gOptions.setOption(utf8("songhistory"),utf8(tos(newOptions.songHistory())));
  375. }
  376. if (newOptions.adminFile() != gOptions.adminFile())
  377. {
  378. ILOG(gOptions.logSectionName() + "Changing 'adminfile'");
  379. gOptions.setOption(utf8("adminfile"),newOptions.adminFile());
  380. }
  381. if (newOptions.clacks() != gOptions.clacks())
  382. {
  383. ILOG(gOptions.logSectionName() + "Changing 'clacks'");
  384. gOptions.setOption(utf8("clacks"),utf8(tos(newOptions.clacks())));
  385. }
  386. if (newOptions.startInactive() != gOptions.startInactive())
  387. {
  388. ILOG(gOptions.logSectionName() + "Changing 'startinactive'");
  389. gOptions.setOption(utf8("startinactive"),utf8(tos(newOptions.startInactive())));
  390. }
  391. if (newOptions.rateLimit() != gOptions.rateLimit())
  392. {
  393. ILOG(gOptions.logSectionName() + "Changing 'rateLimit'");
  394. gOptions.setOption(utf8("ratelimit"),utf8(tos(newOptions.rateLimit())));
  395. }
  396. if (newOptions.adTestFile() != gOptions.adTestFile())
  397. {
  398. ILOG(gOptions.logSectionName() + "Changing 'adtestfile'");
  399. gOptions.setOption(utf8("adtestfile"),utf8(newOptions.adTestFile()));
  400. }
  401. if (newOptions.adTestFile2() != gOptions.adTestFile2())
  402. {
  403. ILOG(gOptions.logSectionName() + "Changing 'adtestfile2'");
  404. gOptions.setOption(utf8("adtestfile2"),utf8(newOptions.adTestFile2()));
  405. }
  406. if (newOptions.adTestFile3() != gOptions.adTestFile3())
  407. {
  408. ILOG(gOptions.logSectionName() + "Changing 'adtestfile3'");
  409. gOptions.setOption(utf8("adtestfile3"),utf8(newOptions.adTestFile3()));
  410. }
  411. if (newOptions.adTestFile4() != gOptions.adTestFile4())
  412. {
  413. ILOG(gOptions.logSectionName() + "Changing 'adtestfile4'");
  414. gOptions.setOption(utf8("adtestfile4"),utf8(newOptions.adTestFile4()));
  415. }
  416. if (newOptions.adTestFileLoop() != gOptions.adTestFileLoop())
  417. {
  418. ILOG(gOptions.logSectionName() + "Changing 'adtestfileloop'");
  419. gOptions.setOption(utf8("adtestfileloop"),utf8(tos(newOptions.adTestFileLoop())));
  420. }
  421. if (newOptions.metaInterval() != gOptions.metaInterval())
  422. {
  423. ILOG(gOptions.logSectionName() + "Changing 'metainterval'");
  424. gOptions.setOption(utf8("metainterval"),utf8(tos(newOptions.metaInterval())));
  425. }
  426. if (newOptions.useXFF() != gOptions.useXFF())
  427. {
  428. ILOG(gOptions.logSectionName() + "Changing 'usexff'");
  429. gOptions.setOption(utf8("usexff"),utf8(tos(newOptions.useXFF())));
  430. }
  431. if (newOptions.forceShortSends() != gOptions.forceShortSends())
  432. {
  433. ILOG(gOptions.logSectionName() + "Changing 'forceshortsends'");
  434. gOptions.setOption(utf8("forceshortsends"),utf8(tos(newOptions.forceShortSends())));
  435. }
  436. if (newOptions.adminNoWrap() != gOptions.adminNoWrap())
  437. {
  438. ILOG(gOptions.logSectionName() + "Changing 'adminnowrap'");
  439. gOptions.setOption(utf8("adminnowrap"),utf8(tos(newOptions.adminNoWrap())));
  440. }
  441. if (newOptions.adminCSSFile() != gOptions.adminCSSFile())
  442. {
  443. ILOG(gOptions.logSectionName() + "Changing 'admincssfile'");
  444. gOptions.setOption(utf8("admincssfile"),utf8(newOptions.adminCSSFile()));
  445. gOptions.m_styleCustomStr.clear();
  446. gOptions.m_styleCustomStrGZ.clear();
  447. gOptions.m_styleCustomHeaderTime = 0;
  448. }
  449. if (newOptions.destIP() != gOptions.destIP())
  450. {
  451. utf8 destBindAddr = metrics::metrics_verifyDestIP(newOptions, false);
  452. ILOG(gOptions.logSectionName() + "Changing 'destip'");
  453. gOptions.setOption(utf8("destip"), destBindAddr);
  454. // if we're updating then attempt to behave like it was a new load
  455. g_IPAddressForClients = destBindAddr;
  456. if (g_IPAddressForClients.empty())
  457. {
  458. char s[MAXHOSTNAMELEN] = {0};
  459. if (!::gethostname(s,MAXHOSTNAMELEN - 1))
  460. {
  461. g_IPAddressForClients = socketOps::hostNameToAddress(s,g_portForClients);
  462. }
  463. }
  464. }
  465. if (newOptions.publicIP() != gOptions.publicIP())
  466. {
  467. utf8 publicAddr = stripWhitespace(newOptions.publicIP());
  468. publicAddr = stripHTTPprefix(publicAddr);
  469. ILOG(gOptions.logSectionName() + "Changing 'publicip'");
  470. gOptions.setOption(utf8("publicip"),publicAddr);
  471. }
  472. if (newOptions.autoDumpTime() != gOptions.autoDumpTime())
  473. {
  474. ILOG(gOptions.logSectionName() + "Changing 'autodumptime'");
  475. gOptions.setOption(utf8("autodumptime"),utf8(tos(newOptions.autoDumpTime())));
  476. }
  477. if (newOptions.nameLookups() != gOptions.nameLookups())
  478. {
  479. ILOG(gOptions.logSectionName() + "Changing 'namelookups'");
  480. gOptions.setOption(utf8("namelookups"),utf8(tos(newOptions.nameLookups())));
  481. }
  482. // update the YP details (can do on fly without any actual updates)
  483. bool ypChanged = false;
  484. bool https = ((gOptions.ypAddr() == DEFAULT_YP_ADDRESS) && uniFile::fileExists(gOptions.m_certPath));
  485. utf8 oldYP = (https ? "https://" : "http://") + gOptions.ypAddr() + ":" + tos(gOptions.ypPort()) + gOptions.ypPath();
  486. if (newOptions.ypAddr() != gOptions.ypAddr())
  487. {
  488. ypChanged = true;
  489. gOptions.setOption(utf8("ypaddr"),utf8(newOptions.ypAddr()));
  490. }
  491. if (newOptions.ypPort() != gOptions.ypPort())
  492. {
  493. ypChanged = true;
  494. gOptions.setOption(utf8("ypport"),utf8(tos(newOptions.ypPort())));
  495. }
  496. if (newOptions.ypPath() != gOptions.ypPath())
  497. {
  498. ypChanged = true;
  499. gOptions.setOption(utf8("yppath"),utf8(newOptions.ypPath()));
  500. }
  501. if (ypChanged)
  502. {
  503. bool https = ((newOptions.ypAddr() == DEFAULT_YP_ADDRESS) && uniFile::fileExists(gOptions.m_certPath));
  504. utf8 newYP = (https ? "https://" : "http://") + newOptions.ypAddr() + ":" + tos(newOptions.ypPort()) + newOptions.ypPath();
  505. ILOG(gOptions.logSectionName() + "Changing YP details from " + oldYP + " to " + newYP);
  506. }
  507. gOptions.setOption(utf8("yp2debug"),utf8(newOptions.yp2Debug()?"1":"0"));
  508. gOptions.setOption(utf8("shoutcastsourcedebug"),utf8(newOptions.shoutcastSourceDebug()?"1":"0"));
  509. gOptions.setOption(utf8("uvox2sourcedebug"),utf8(newOptions.uvox2SourceDebug()?"1":"0"));
  510. gOptions.setOption(utf8("httpsourcedebug"),utf8(newOptions.HTTPSourceDebug()?"1":"0"));
  511. gOptions.setOption(utf8("shoutcast1clientdebug"),utf8(newOptions.shoutcast1ClientDebug()?"1":"0"));
  512. gOptions.setOption(utf8("shoutcast2clientdebug"),utf8(newOptions.shoutcast2ClientDebug()?"1":"0"));
  513. gOptions.setOption(utf8("httpclientdebug"),utf8(newOptions.HTTPClientDebug()?"1":"0"));
  514. gOptions.setOption(utf8("flvclientdebug"),utf8(newOptions.flvClientDebug()?"1":"0"));
  515. gOptions.setOption(utf8("m4aclientdebug"),utf8(newOptions.m4aClientDebug()?"1":"0"));
  516. gOptions.setOption(utf8("relayshoutcastdebug"),utf8(newOptions.relayShoutcastDebug()?"1":"0"));
  517. gOptions.setOption(utf8("relayuvoxdebug"),utf8(newOptions.relayUvoxDebug()?"1":"0"));
  518. gOptions.setOption(utf8("relaydebug"),utf8(newOptions.relayDebug()?"1":"0"));
  519. gOptions.setOption(utf8("streamdatadebug"),utf8(newOptions.streamDataDebug()?"1":"0"));
  520. gOptions.setOption(utf8("httpstyledebug"),utf8(newOptions.httpStyleDebug()?"1":"0"));
  521. gOptions.setOption(utf8("statsdebug"),utf8(newOptions.statsDebug()?"1":"0"));
  522. gOptions.setOption(utf8("microserverdebug"),utf8(newOptions.microServerDebug()?"1":"0"));
  523. gOptions.setOption(utf8("threadrunnerdebug"),utf8(newOptions.threadRunnerDebug()?"1":"0"));
  524. gOptions.setOption(utf8("admetricsdebug"),utf8(newOptions.adMetricsDebug()?"1":"0"));
  525. gOptions.setOption(utf8("authdebug"),utf8(newOptions.authDebug()?"1":"0"));
  526. ILOG(gOptions.logSectionName() + "Processed global configuration settings.");
  527. // test for the source password having changed this will be
  528. // applied in general though per stream changes are likely
  529. // to have been set in the earlier checks before we got here
  530. if (newOptions.password() != gOptions.password())
  531. {
  532. gOptions.setOption(utf8("password"),newOptions.password());
  533. streamData *sd = streamData::accessStream(DEFAULT_SOURCE_STREAM);
  534. if (sd)
  535. {
  536. ILOG(gOptions.logSectionName() + "Killing all stream sources due to change of relay options.");
  537. sd->killAllSources();
  538. m_reloadRefresh = true;
  539. sd->releaseStream();
  540. }
  541. }
  542. config::streams_t new_streams, old_streams;
  543. newOptions.getStreamConfigs(new_streams, false);
  544. gOptions.getStreamConfigs(old_streams, false);
  545. config::streams_t::const_iterator iNSC = new_streams.begin(), iOSC = old_streams.begin();
  546. // if no configurations found then we can just remove everything
  547. if (new_streams.empty())
  548. {
  549. // kick the source and clients as required on a removal
  550. for (; iOSC != old_streams.end(); ++iOSC)
  551. {
  552. size_t streamID = (*iOSC).second.m_streamID;
  553. streamData *sd = streamData::accessStream(streamID);
  554. if (sd)
  555. {
  556. sd->killSource(streamID, sd);
  557. m_reloadRefresh = true;
  558. }
  559. gOptions.removeStreamConfig((*iOSC).second);
  560. }
  561. }
  562. // otherwise if the same or more then we can update / add as required
  563. else if (new_streams.size() >= old_streams.size())
  564. {
  565. // if no configs specified and we're starting to add new stream configs
  566. // then we really need to kick any existing sources otherwise it'll stay
  567. // with the current details which will prevent a YP connection with extra
  568. // checks in build 21+ to make sure it only works if there was a change.
  569. if ((new_streams.size() != old_streams.size()) &&
  570. (old_streams.size() == DEFAULT_SOURCE_STREAM))
  571. {
  572. // kick the source and clients as required on a complete addition
  573. // (wouldn't have a valid config via authhash, etc so is sensible)
  574. streamData *sd = streamData::accessStream(DEFAULT_SOURCE_STREAM);
  575. if (sd)
  576. {
  577. ILOG(gOptions.logSectionName() + "Forcing stream source disconnect due to addition of stream config(s).");
  578. sd->killAllSources();
  579. m_reloadRefresh = true;
  580. sd->releaseStream();
  581. }
  582. }
  583. for (; iNSC != new_streams.end(); ++iNSC)
  584. {
  585. config::streams_t::const_iterator iOSC2 = old_streams.find((*iNSC).first);
  586. if (iOSC2 != old_streams.end())
  587. {
  588. // update required
  589. __uint64 updated = gOptions.updateStreamConfig(newOptions, (*iNSC).second);
  590. size_t streamID = (*iNSC).second.m_streamID;
  591. streamData *sd = streamData::accessStream(streamID);
  592. if (sd)
  593. {
  594. // otherwise do an in-place update as long as it is applicable
  595. bool isRelay = sd->isRelayStream(streamID);
  596. if (publicChanged || force ||
  597. (!force && (updated & RELAY_URL || updated & SOURCE_PWD ||
  598. updated & PUBLIC_SRV || (updated & ALLOW_RELAY && isRelay) ||
  599. (updated & ALLOW_PUBLIC_RELAY && isRelay) || updated & CIPHER_KEY ||
  600. updated & INTRO_FILE || updated & BACKUP_FILE ||
  601. updated & BACKUP_URL || updated & MOVED_URL)))
  602. {
  603. sd->killSource(streamID);
  604. m_reloadRefresh = true;
  605. if (!(*iNSC).second.m_relayUrl.url().empty() &&
  606. !sd->isSourceConnected(streamID) &&
  607. gOptions.stream_movedUrl(streamID).empty())
  608. {
  609. relays.push_back((*iNSC).second);
  610. }
  611. }
  612. // otherwise do an in-place update as long as it is applicable
  613. else
  614. {
  615. sd->streamUpdate(streamID, (*iNSC).second.m_authHash, (*iNSC).second.m_maxStreamUser,
  616. (*iNSC).second.m_maxStreamBitrate, (*iNSC).second.m_minStreamBitrate);
  617. }
  618. // refresh the played history size as needed
  619. if (updated & SONG_HIST)
  620. {
  621. sd->updateSongHistorySize();
  622. }
  623. if (updated & ARTWORK_FILE)
  624. {
  625. if (gOptions.read_stream_artworkFile(streamID))
  626. {
  627. gOptions.m_artworkBody[streamID] = loadLocalFile(fileUtil::getFullFilePath(gOptions.stream_artworkFile(streamID)), LOGNAME, 523872/*32 x (16384 - 6 - 6 - 1)*/);
  628. }
  629. else
  630. {
  631. gOptions.m_artworkBody[streamID].clear();
  632. sd->clearCachedArtwork(0);
  633. }
  634. }
  635. sd->releaseStream();
  636. }
  637. // otherwise if no proper update or a relay was added / is known and not connected then bump it
  638. else
  639. {
  640. // force flag a source relay kick if this is called
  641. bool noEntry = false;
  642. if ((streamData::isRelayActive(streamID, noEntry) & 12))
  643. {
  644. // if there is a relay attempt and no new one
  645. // then we need to signal it to abort trying
  646. if ((*iNSC).second.m_relayUrl.url().empty())
  647. {
  648. streamData::setRelayActiveFlags (streamID, noEntry, 2);
  649. }
  650. // otherwise we need update the relay url
  651. // which the attempt is trying to join to
  652. // which is done by the relay handling.
  653. }
  654. if (((*iOSC2).second.m_relayUrl.url() != (*iNSC).second.m_relayUrl.url() ||
  655. (updated & MOVED_URL)) && !(*iNSC).second.m_relayUrl.url().empty())
  656. {
  657. relays.push_back((*iNSC).second);
  658. m_reloadRefresh = true;
  659. }
  660. }
  661. }
  662. else
  663. {
  664. // addition required
  665. // no need to do anything else as there shouldn't be anything connected on this at the time
  666. gOptions.addStreamConfig(newOptions, (*iNSC).second);
  667. m_reloadRefresh = true;
  668. // only attempt to start a relay url if added and a relay url exists
  669. if (!(*iNSC).second.m_relayUrl.url().empty())
  670. {
  671. relays.push_back((*iNSC).second);
  672. }
  673. }
  674. }
  675. }
  676. // otherwise if there are fewer stream configurations then we can update / remove as required
  677. else
  678. {
  679. for (; iOSC != old_streams.end(); ++iOSC)
  680. {
  681. config::streams_t::const_iterator iOSC2 = new_streams.find((*iOSC).first);
  682. if (iOSC2 != new_streams.end())
  683. {
  684. // update required
  685. __uint64 updated = gOptions.updateStreamConfig(newOptions, (*iOSC2).second);
  686. size_t streamID = (*iOSC2).second.m_streamID;
  687. streamData *sd = streamData::accessStream(streamID);
  688. if (sd)
  689. {
  690. // check what has been updated and kick the source as applicable
  691. bool isRelay = sd->isRelayStream(streamID);
  692. if (publicChanged || force ||
  693. (!force && (updated & RELAY_URL || updated & SOURCE_PWD ||
  694. updated & PUBLIC_SRV || (updated & ALLOW_RELAY && isRelay) ||
  695. (updated & ALLOW_PUBLIC_RELAY && isRelay) || updated & CIPHER_KEY ||
  696. updated & INTRO_FILE || updated & BACKUP_FILE ||
  697. updated & BACKUP_URL || updated & MOVED_URL)))
  698. {
  699. sd->killSource(streamID);
  700. m_reloadRefresh = true;
  701. if (!(*iOSC2).second.m_relayUrl.url().empty() &&
  702. !sd->isSourceConnected(streamID) &&
  703. gOptions.stream_movedUrl(streamID).empty())
  704. {
  705. relays.push_back((*iOSC2).second);
  706. }
  707. }
  708. // otherwise do an in-place update as long as it is applicable
  709. else
  710. {
  711. sd->streamUpdate(streamID, (*iOSC2).second.m_authHash, (*iOSC2).second.m_maxStreamUser,
  712. (*iOSC2).second.m_maxStreamBitrate, (*iOSC2).second.m_minStreamBitrate);
  713. }
  714. // refresh the played history size as needed
  715. if (updated & SONG_HIST)
  716. {
  717. sd->updateSongHistorySize();
  718. }
  719. if (updated & ARTWORK_FILE)
  720. {
  721. if (gOptions.read_stream_artworkFile(streamID))
  722. {
  723. gOptions.m_artworkBody[streamID] = loadLocalFile(fileUtil::getFullFilePath(gOptions.stream_artworkFile(streamID)), LOGNAME, 523872/*32 x (16384 - 6 - 6 - 1)*/);
  724. }
  725. else
  726. {
  727. gOptions.m_artworkBody[streamID].clear();
  728. sd->clearCachedArtwork(0);
  729. }
  730. }
  731. sd->releaseStream();
  732. }
  733. }
  734. else
  735. {
  736. // kick the source and clients as required on a removal
  737. size_t streamID = (*iOSC).second.m_streamID;
  738. streamData *sd = streamData::accessStream(streamID);
  739. if (sd)
  740. {
  741. sd->killSource(streamID, sd);
  742. m_reloadRefresh = true;
  743. }
  744. // removal required
  745. gOptions.removeStreamConfig((*iOSC).second);
  746. }
  747. }
  748. }
  749. // test for the require stream configs having changed
  750. // only need to kick streams not known if enabled
  751. if (newOptions.requireStreamConfigs() != gOptions.requireStreamConfigs())
  752. {
  753. gOptions.setOption(utf8("requirestreamconfigs"),utf8(newOptions.requireStreamConfigs()?"1":"0"));
  754. if (newOptions.requireStreamConfigs())
  755. {
  756. size_t inc = 0;
  757. size_t sid;
  758. do
  759. {
  760. sid = streamData::enumStreams(inc);
  761. config::streams_t streams;
  762. gOptions.getStreamConfigs(streams, false);
  763. config::streams_t::const_iterator ics = streams.find(sid);
  764. if (ics == streams.end())
  765. {
  766. streamData *sd = streamData::accessStream(sid);
  767. if (sd)
  768. {
  769. ILOG(gOptions.logSectionName() + "Killing source for stream #" + tos(sid) + " as it is not in the known stream config(s).", LOG_NAME, sid);
  770. sd->killSource(sid, sd);
  771. m_reloadRefresh = true;
  772. }
  773. }
  774. ++inc;
  775. }
  776. while (sid);
  777. }
  778. }
  779. // finally we refresh the passwords so they're correct after any changes
  780. config::streams_t streams;
  781. gOptions.getStreamConfigs(streams, false);
  782. gOptions.setupPasswords(streams);
  783. // if a force was done then we really need to restart any relays
  784. if (force)
  785. {
  786. // schedule relays
  787. vector<config::streamConfig> relayList(gOptions.getRelayList());
  788. if (!relayList.empty())
  789. {
  790. for_each(relayList.begin(),relayList.end(),restartRelay);
  791. }
  792. }
  793. // otherwise only attempt to restart any which were added, changed, etc
  794. else
  795. {
  796. if (!relays.empty())
  797. {
  798. for_each(relays.begin(),relays.end(),restartRelay);
  799. }
  800. }
  801. ILOG(gOptions.logSectionName() + "Completed stream config reload from `" + fileUtil::getFullFilePath(gOptions.confFile()));
  802. return m_reloadRefresh;
  803. }
  804. void reloadBanLists()
  805. {
  806. // load up ban file
  807. int loaded = g_banList.load(gOptions.banFile(),0),
  808. count = loaded;
  809. // per-stream options
  810. config::streams_t streams;
  811. gOptions.getStreamConfigs(streams);
  812. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  813. {
  814. // load up ban file
  815. if (gOptions.read_stream_banFile((*i).first))
  816. {
  817. ++count;
  818. if (g_banList.load(gOptions.stream_banFile((*i).first),(*i).first))
  819. {
  820. ++loaded;
  821. }
  822. }
  823. }
  824. if (!count)
  825. {
  826. ILOG("[BAN] No banned lists reloaded.");
  827. }
  828. else
  829. {
  830. if (count == loaded)
  831. {
  832. ILOG("[BAN] Reloaded all banned list(s).");
  833. }
  834. else
  835. {
  836. ILOG("[BAN] Partially reloaded banned list(s) - check error messages above.");
  837. }
  838. }
  839. }
  840. void reloadRipLists()
  841. {
  842. // load up rip file
  843. int loaded = g_ripList.load(gOptions.ripFile(),0),
  844. count = loaded;
  845. // per-stream options
  846. config::streams_t streams;
  847. gOptions.getStreamConfigs(streams);
  848. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  849. {
  850. // load up rip file
  851. if (gOptions.read_stream_ripFile((*i).first))
  852. {
  853. ++count;
  854. if (g_ripList.load(gOptions.stream_ripFile((*i).first),(*i).first))
  855. {
  856. ++loaded;
  857. }
  858. }
  859. }
  860. if (!count)
  861. {
  862. ILOG("[RIP] No reserved lists reloaded.");
  863. }
  864. else
  865. {
  866. if (count == loaded)
  867. {
  868. ILOG("[RIP] Reloaded all reserved list(s).");
  869. }
  870. else
  871. {
  872. ILOG("[RIP] Partially reloaded reserved list(s) - check error messages above.");
  873. }
  874. }
  875. }
  876. void reloadAdminAccessList()
  877. {
  878. // load up admin access file
  879. g_adminList.load(gOptions.adminFile());
  880. ILOG("[ADMINCGI] Reloaded admin access list.");
  881. }
  882. void reloadAgentLists()
  883. {
  884. // load up agent file
  885. int loaded = g_agentList.load(gOptions.agentFile(),0),
  886. count = loaded;
  887. // per-stream options
  888. config::streams_t streams;
  889. gOptions.getStreamConfigs(streams);
  890. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  891. {
  892. // load up agent file
  893. if (gOptions.read_stream_agentFile((*i).first))
  894. {
  895. ++count;
  896. if (g_agentList.load(gOptions.stream_agentFile((*i).first),(*i).first))
  897. {
  898. ++loaded;
  899. }
  900. }
  901. }
  902. if (!count)
  903. {
  904. ILOG("[AGENT] No user agent lists reloaded.");
  905. }
  906. else
  907. {
  908. if (count == loaded)
  909. {
  910. ILOG("[AGENT] Reloaded all user agent list(s).");
  911. }
  912. else
  913. {
  914. ILOG("[AGENT] Partially reloaded user agent list(s) - check error messages above.");
  915. }
  916. }
  917. }
  918. void printUpdateMessage()
  919. {
  920. // display update message where applicable
  921. updater::verInfo ver;
  922. if (updater::getNewVersion(ver))
  923. {
  924. ULOG(string(YP2_LOGNAME) + "A new DNAS version is now available: " + ver.ver);
  925. ULOG(string(YP2_LOGNAME) + "The suggested download for your setup is: " + ver.url);
  926. ULOG(string(YP2_LOGNAME) + "See " + ver.log + " for more information about this update and alternative download links");
  927. }
  928. }
  929. utf8 warningImage(const bool right = true)
  930. {
  931. return utf8(right ? "&nbsp;" : "") + "<img border=\"0\" src=\"images/warn.png\" style=\"float:" +
  932. utf8(right ? "right" : "left") + "\" "
  933. "alt=\"" + (right ? "Possible Stream Ripper" : "Please Register Your Authhash") +
  934. "\" title=\"" + (right ? "Possible Stream Ripper" : "Please Register Your Authhash") + "\">";
  935. }
  936. utf8 baseImage(const utf8& image, const utf8& title, const bool left = false, const bool prefix = true)
  937. {
  938. return (prefix ? "&nbsp;" : (utf8)"") + "<img border=\"0\" src=\"images/" +
  939. (!image.empty() ? (image + ".png") : "favicon.ico") + "\" " +
  940. (left ? "style=\"float:left\" " : "") + "alt=\"" + title + "\" title=\"" + title + "\">";
  941. }
  942. #define xffImage() baseImage("xff", "XFF", true)
  943. #define mplayerImage() baseImage("mplayer", "MPlayer Client")
  944. #define psImage() baseImage("ps", "PlayStation Client")
  945. #define radioToolboxImage() baseImage("rtb", "Radio Toolbox Monitor / Player")
  946. #define v1Image() baseImage("v1", "v1 Client")
  947. #define v2Image() baseImage("v2", "v2 Client")
  948. #define relayImage() baseImage("relay", "Relay Connection", false, false)
  949. #define html5Image() baseImage("html5", "HTTP / HTML5 Client")
  950. #define flashImage() baseImage("flash", "Flash Client")
  951. #define icecastImage() baseImage("icecast", "Icecast Client / Relay")
  952. #define vlcImage() baseImage("vlc", "VLC Client")
  953. #define waImage() baseImage("wa", "Winamp Client")
  954. #define scImage() baseImage("", "Shoutcast Client / Relay")
  955. #define iOSImage() baseImage("", "iOS Client")
  956. #define curlImage() baseImage("curl", "cURL / libcurl Based Client")
  957. #define radionomyImage() baseImage("radionomy", "Radionomy Stats Collector")
  958. #define fb2kImage() baseImage("fb2k", "Foobar2000 Client")
  959. #define rokuImage() baseImage("roku", "Roku Streaming Player")
  960. #define WiiMCImage() baseImage("v1", "Wii Media Centre Player")
  961. #define synologyImage() baseImage("synology", "Audio Station (Synology) Player")
  962. #define appleImage() baseImage("apple", "Apple Device / OS / Client")
  963. #define iTunesImage() baseImage("itunes", "iTunes Client")
  964. #define wmpImage() baseImage("wmp", "Windows Media Player Client")
  965. #define chromeImage() baseImage("chrome", "Chrome Web Browser")
  966. #define safariImage() baseImage("safari", "Safari Web Browser")
  967. #define ieImage() baseImage("ie", "Internet Explorer Web Browser")
  968. #define firefoxImage() baseImage("firefox", "Firefox Web Browser")
  969. utf8 advertImage(const streamData::streamID_t sid, const int group, const size_t count)
  970. {
  971. if (streamData::knownAdvertGroup(sid, group))
  972. {
  973. if (count > 0)
  974. {
  975. return baseImage("adplayed", (tos(count) + " Advert Breaks Have Been Played\nAdvert Group: " + tos(group)), false, false);
  976. }
  977. return baseImage("adavail", ("Waiting For First Advert Break To Play\nAdvert Group: " + tos(group)), false, false);
  978. }
  979. if (count > 0)
  980. {
  981. return baseImage("", (tos(count) + " Advert Breaks Have Been Played\nNo Applicable "
  982. "Adverts Currently Available\nAdvert Group: " + tos(group)), false, false);
  983. }
  984. return baseImage("noadavail", ("No Applicable Adverts Available\nAdvert Group: " + tos(group)), false, false);
  985. }
  986. utf8 getClientImage(const streamData::source_t type)
  987. {
  988. return ((type & streamData::RADIONOMY) ? radionomyImage() :
  989. ((type & streamData::FLV) ? flashImage() :
  990. ((type & streamData::CURL_TOOL) ? curlImage() :
  991. ((type & streamData::HTTP) ? html5Image() :
  992. //((type & streamData::M4A) ? m4aImage() :
  993. ((type & streamData::SHOUTCAST2) ? ((type & streamData::RELAY) ? scImage() : waImage()) :
  994. ((type & streamData::ICECAST) ? icecastImage() :
  995. ((type & streamData::VLC) ? vlcImage() :
  996. ((type & streamData::WINAMP) ? waImage() :
  997. ((type & streamData::APPLE) ? appleImage() :
  998. ((type & streamData::ITUNES) ? iTunesImage() :
  999. ((type & streamData::WMP) ? wmpImage() :
  1000. ((type & streamData::ROKU) ? rokuImage() :
  1001. ((type & streamData::WIIMC) ? WiiMCImage() :
  1002. ((type & streamData::SYNOLOGY) ? synologyImage() :
  1003. ((type & streamData::CHROME) ? chromeImage() :
  1004. ((type & streamData::SAFARI) ? safariImage() :
  1005. ((type & streamData::IE) ? ieImage() :
  1006. ((type & streamData::FIREFOX) ? firefoxImage() :
  1007. ((type & streamData::MPLAYER) ? mplayerImage() :
  1008. ((type & streamData::PS) ? psImage() :
  1009. ((type & streamData::RADIO_TOOLBOX) ? radioToolboxImage() :
  1010. ((type & streamData::HTML5) ? html5Image() :
  1011. ((type & streamData::WARNING) ? warningImage() :
  1012. ((type & streamData::SC_IRADIO) ? iOSImage() :
  1013. ((type & streamData::FB2K) ? fb2kImage() : v1Image()
  1014. ))))))))))))))))))))))))) +
  1015. ((type & streamData::RELAY) ? relayImage() : "");
  1016. }
  1017. /*
  1018. Handles all HTTP requests to admin.cgi
  1019. */
  1020. protocol_admincgi::protocol_admincgi(const socketOps::tSOCKET s, const streamData::streamID_t sid, const bool no_sid,
  1021. const bool zero_sid, const utf8 &clientLogString,
  1022. const uniString::utf8 &password, const uniString::utf8 &referer,
  1023. const uniString::utf8 &hostIP, const uniString::utf8 &userAgent,
  1024. const protocol_HTTPStyle::HTTPRequestInfo &httpRequestInfo) throw(std::exception)
  1025. : runnable(s), m_noSID(no_sid), m_zeroSID(zero_sid),
  1026. m_saveLogFile(0), m_clientLogString(clientLogString),
  1027. m_httpRequestInfo(httpRequestInfo), m_password(password),
  1028. m_referer(referer), m_hostIP(hostIP), m_userAgent(userAgent),
  1029. m_sid(sid), m_state(&protocol_admincgi::state_ConfirmPassword),
  1030. m_nextState(0), m_outBuffer(0), m_outBufferSize(0),
  1031. m_tailLogFile(false), lastChar(-1), inMsg(false),
  1032. first(false), m_logFile(0)
  1033. {
  1034. memset(&m_stream, 0, sizeof(m_stream));
  1035. // check for updates weekly from the last update
  1036. // so we're taking into account manual checks...
  1037. if ((m_lastActivityTime - last_update_check) > 604800)
  1038. {
  1039. checkVersion(m_lastActivityTime);
  1040. }
  1041. DEBUG_LOG(utf8(LOGNAME) + __FUNCTION__);
  1042. }
  1043. protocol_admincgi::~protocol_admincgi() throw()
  1044. {
  1045. DEBUG_LOG(utf8(LOGNAME) + __FUNCTION__);
  1046. socketOps::forgetTCPSocket(m_socket);
  1047. if (m_logFile)
  1048. {
  1049. ::fclose(m_logFile);
  1050. m_logFile = 0;
  1051. }
  1052. }
  1053. void protocol_admincgi::timeSlice() throw(exception)
  1054. {
  1055. (this->*m_state)();
  1056. }
  1057. void protocol_admincgi::state_Close() throw(exception)
  1058. {
  1059. m_result.done();
  1060. }
  1061. // send buffer text
  1062. void protocol_admincgi::state_Send() throw(exception)
  1063. {
  1064. if (sendDataBuffer(DEFAULT_CLIENT_STREAM_ID, m_outBuffer, m_outBufferSize, m_clientLogString))
  1065. {
  1066. m_state = m_nextState;
  1067. }
  1068. }
  1069. void protocol_admincgi::sendMessageAndClose(const utf8 &msg) throw()
  1070. {
  1071. m_outMsg = msg;
  1072. m_outBuffer = m_outMsg.c_str();
  1073. bandWidth::updateAmount(bandWidth::PRIVATE_WEB, (m_outBufferSize = (int)m_outMsg.size()));
  1074. m_state = &protocol_admincgi::state_Send;
  1075. m_nextState = &protocol_admincgi::state_Close;
  1076. m_result.write();
  1077. m_result.run();
  1078. }
  1079. /// update the metatdata in the shoutcast ring buffer
  1080. void protocol_admincgi::state_UpdateMetadata() throw(exception)
  1081. {
  1082. DEBUG_LOG(utf8(LOGNAME) + __FUNCTION__);
  1083. streamData::streamInfo info;
  1084. streamData::extraInfo extra;
  1085. streamData::getStreamInfo(m_sid, info, extra);
  1086. utf8 titleMsg, urlMsg, djMsg, nextMsg;
  1087. if (!m_updinfoSong.empty())
  1088. {
  1089. // use this as a way to try to ensure we've got a utf-8
  1090. // encoded title to improve legacy source title support
  1091. if (!m_updinfoSong.isValid())
  1092. {
  1093. m_updinfoSong = asciiToUtf8(m_updinfoSong.toANSI(true));
  1094. }
  1095. if (streamData::validateTitle(m_updinfoSong))
  1096. {
  1097. titleMsg = ("[ADMINCGI sid=" + tos(m_sid) + "] Title updated [" + m_updinfoSong + "]");
  1098. }
  1099. else
  1100. {
  1101. WLOG("Title update rejected - value not allowed: " + m_updinfoSong, LOG_NAME, m_sid);
  1102. m_updinfoSong = info.m_currentSong;
  1103. }
  1104. }
  1105. else
  1106. {
  1107. if (!info.m_currentSong.empty())
  1108. {
  1109. titleMsg = ("[ADMINCGI sid=" + tos(m_sid) + "] Title cleared");
  1110. }
  1111. }
  1112. if (!m_updinfoURL.empty())
  1113. {
  1114. urlMsg = ("[ADMINCGI sid=" + tos(m_sid) + "] Song url updated [" + m_updinfoURL + "]");
  1115. }
  1116. else
  1117. {
  1118. if (!info.m_currentURL.empty())
  1119. {
  1120. // TODO if there's a custom image then indicate using it or do not show this
  1121. urlMsg = ("[ADMINCGI sid=" + tos(m_sid) + "] Song url cleared");
  1122. }
  1123. }
  1124. if (!m_updinfoDJ.empty())
  1125. {
  1126. djMsg = ("[ADMINCGI sid=" + tos(m_sid) + "] DJ name updated [" + m_updinfoDJ + "]");
  1127. }
  1128. else
  1129. {
  1130. if (!info.m_streamUser.empty())
  1131. {
  1132. djMsg = ("[ADMINCGI sid=" + tos(m_sid) + "] DJ name cleared");
  1133. }
  1134. }
  1135. if (!m_updinfoNext.empty())
  1136. {
  1137. // use this as a way to try to ensure we've got a utf-8
  1138. // encoded title to improve legacy source title support
  1139. if (!m_updinfoNext.isValid())
  1140. {
  1141. m_updinfoNext = asciiToUtf8(m_updinfoNext.toANSI(true));
  1142. }
  1143. if (streamData::validateTitle(m_updinfoNext))
  1144. {
  1145. titleMsg = ("[ADMINCGI sid=" + tos(m_sid) + "] Next title updated [" + m_updinfoNext + "]");
  1146. }
  1147. else
  1148. {
  1149. WLOG("[ADMINCGI sid=" + tos(m_sid) + "] Next title update rejected - value not allowed: " + m_updinfoNext);
  1150. m_updinfoNext = info.m_comingSoon;
  1151. }
  1152. }
  1153. else
  1154. {
  1155. if (!info.m_comingSoon.empty())
  1156. {
  1157. nextMsg = ("[ADMINCGI sid=" + tos(m_sid) + "] Next title cleared");
  1158. }
  1159. }
  1160. streamData *sd = streamData::accessStream(m_sid);
  1161. if (sd)
  1162. {
  1163. utf8 sourceIdent = (!m_userAgent.empty() ? m_userAgent : utf8("Legacy / Unknown"));
  1164. sd->updateSourceIdent(sourceIdent, sd->isRelayStream(m_sid));
  1165. sd->addSc1MetadataAtCurrentPosition(LOGNAME, m_updinfoSong, m_updinfoURL, m_updinfoNext);
  1166. sd->updateStreamUser(m_updinfoDJ);
  1167. // this will call streamData::releaseStream(..)
  1168. streamData::streamClientLost(LOGNAME, sd, m_sid);
  1169. // we'll output any earlier generated messages now that we've sent
  1170. // the details to be used as otherwise they were being reported as
  1171. // ok which if there was an issue (e.g. bad sid#) was confusing
  1172. if (!titleMsg.empty())
  1173. {
  1174. ILOG(titleMsg, LOG_NAME, m_sid);
  1175. }
  1176. if (!nextMsg.empty())
  1177. {
  1178. ILOG(nextMsg, LOG_NAME, m_sid);
  1179. }
  1180. if (!urlMsg.empty())
  1181. {
  1182. ILOG(urlMsg, LOG_NAME, m_sid);
  1183. }
  1184. if (!djMsg.empty())
  1185. {
  1186. ILOG(djMsg, LOG_NAME, m_sid);
  1187. }
  1188. }
  1189. else
  1190. {
  1191. WLOG("[ADMINCGI sid=" + tos(m_sid) + "] Metadata update rejected as the stream does not exist", LOG_NAME, m_sid);
  1192. }
  1193. m_updinfoSong.clear();
  1194. m_updinfoURL.clear();
  1195. m_updinfoDJ.clear();
  1196. sendMessageAndClose(MSG_200);
  1197. }
  1198. /// update the metatdata in the shoutcast ring buffer
  1199. void protocol_admincgi::state_UpdateXMLMetadata() throw(exception)
  1200. {
  1201. DEBUG_LOG(utf8(LOGNAME) + __FUNCTION__);
  1202. if (!m_updinfoSong.empty())
  1203. {
  1204. ILOG("XML title update [" + m_updinfoSong + "]", LOG_NAME, m_sid);
  1205. streamData *sd = streamData::accessStream(m_sid);
  1206. if (sd)
  1207. {
  1208. vector<__uint8> assembledData;
  1209. assembledData.insert(assembledData.end(), m_updinfoSong.begin(), m_updinfoSong.end());
  1210. utf8 sourceIdent = (!m_userAgent.empty() ? m_userAgent : utf8("Legacy / Unknown"));
  1211. sd->updateSourceIdent(sourceIdent);
  1212. sd->addUvoxMetadataAtCurrentPosition(MSG_METADATA_XML_NEW, assembledData);
  1213. // this will call streamData::releaseStream(..)
  1214. streamData::streamClientLost(LOGNAME, sd, m_sid);
  1215. }
  1216. else
  1217. {
  1218. WLOG("XML title update rejected as stream #" + tos(m_sid) + " does not exist", LOG_NAME, m_sid);
  1219. }
  1220. m_updinfoSong.clear();
  1221. m_updinfoURL.clear();
  1222. }
  1223. sendMessageAndClose(MSG_200);
  1224. }
  1225. void protocol_admincgi::state_ConfirmPassword() throw(std::exception)
  1226. {
  1227. DEBUG_LOG(utf8(LOGNAME) + __FUNCTION__);
  1228. // this will see if we've been refered from the base admin.cgi and will allow through
  1229. // if the password / auth matches with the key admin account so the page is useable.
  1230. utf8::size_type pos;
  1231. if ((pos = m_referer.rfind(utf8("admin.cgi"))) != utf8::npos)
  1232. {
  1233. m_referer = m_referer.substr(pos);
  1234. }
  1235. const utf8& mode = mapGet(m_httpRequestInfo.m_QueryParameters, "mode", (utf8)"");
  1236. const bool updinfo = (mode == "updinfo");
  1237. const bool viewxml = (mode == "viewxml");
  1238. const bool viewjson = (mode == "viewjson");
  1239. const bool _register = (mode == "register");
  1240. // on the root admin summary page we can only allow referer admin through if looking at the stats
  1241. const bool adminRefer = (m_referer.find(utf8("admin.cgi")) == 0 || m_referer.find(utf8("admin.cgi?sid=0")) == 0);
  1242. int okReferer = (adminRefer && (viewxml || viewjson || _register));
  1243. // on the root admin summary page we can check if it's an authhash action and allow
  1244. // through if things match up + also allow updinfo (not ideal but maintains legacy)
  1245. if ((!okReferer && ((mode == "manualauthhash") || _register)) || updinfo)
  1246. {
  1247. if (!m_referer.empty())
  1248. {
  1249. okReferer = (m_referer.find(utf8("admin.cgi?sid=" + tos(m_sid) + "&mode=")) != utf8::npos);
  1250. }
  1251. }
  1252. DEBUG_LOG(LOGNAME "Referrer status: " + tos(okReferer));
  1253. // fixed in Build 18 to revert to the master passwords if there's nothing for the stream
  1254. utf8 streamPassword = gOptions.stream_password(m_sid);
  1255. if (!gOptions.read_stream_password(m_sid) && streamPassword.empty())
  1256. {
  1257. streamPassword = gOptions.password();
  1258. }
  1259. utf8 streamAdminPassword = gOptions.stream_adminPassword(m_sid);
  1260. if (!gOptions.read_stream_adminPassword(m_sid) && streamAdminPassword.empty())
  1261. {
  1262. streamAdminPassword = gOptions.adminPassword();
  1263. }
  1264. // this is so we can allow source password connections access to the
  1265. // mode=viewxml&page=1 (/stats) and mode=viewxml&page=4 (/played) so
  1266. // we maintain compatibility with 1.x DNAS which only had these ones
  1267. int page = 0;
  1268. bool compat_mode = false;
  1269. if (viewxml || viewjson)
  1270. {
  1271. page = mapGet(m_httpRequestInfo.m_QueryParameters, "page", (int)page);
  1272. // this will act like /stats or / played (or both
  1273. // if page=0)so as to better emulate the 1.x DNAS
  1274. if ((page == 0) || (page == 1) || (page == 4))
  1275. {
  1276. compat_mode = true;
  1277. }
  1278. }
  1279. bool proceed = (((!streamPassword.empty() && (updinfo || compat_mode) && (m_password == streamPassword)) ||
  1280. (!streamAdminPassword.empty() && (m_password == streamAdminPassword)) ||
  1281. (!gOptions.adminPassword().empty() && (m_password == gOptions.adminPassword()))));
  1282. DEBUG_LOG(LOGNAME "Password status: " + tos(proceed));
  1283. if (proceed)
  1284. {
  1285. const streamData::streamID_t this_sid = (m_zeroSID || m_noSID ? 0 : m_sid);
  1286. const utf8& p1 = mapGet(m_httpRequestInfo.m_QueryParameters, mode, (utf8)"");
  1287. DEBUG_LOG(LOGNAME "Requested mode: " + (!mode.empty() ? mode : "Not Specified"));
  1288. if (updinfo)
  1289. {
  1290. m_updinfoSong = stripWhitespace(mapGet(m_httpRequestInfo.m_QueryParameters, "song", (utf8)""));
  1291. m_updinfoURL = stripWhitespace(mapGet(m_httpRequestInfo.m_QueryParameters, "url", (utf8)""));
  1292. m_updinfoDJ = stripWhitespace(mapGet(m_httpRequestInfo.m_QueryParameters, "dj", (utf8)""));
  1293. m_updinfoNext = stripWhitespace(mapGet(m_httpRequestInfo.m_QueryParameters, "next", (utf8)""));
  1294. m_state = ((m_updinfoSong.find(utf8("<?xml ")) != utf8::npos) ? &protocol_admincgi::state_UpdateXMLMetadata : &protocol_admincgi::state_UpdateMetadata);
  1295. m_result.run();
  1296. }
  1297. else if (viewxml)
  1298. {
  1299. if (m_noSID)
  1300. {
  1301. sendMessageAndClose(redirect("index.html", SHRINK));
  1302. }
  1303. else
  1304. {
  1305. const bool iponly = mapGet(m_httpRequestInfo.m_QueryParameters, "iponly", (bool)false);
  1306. const bool ipcount = mapGet(m_httpRequestInfo.m_QueryParameters, "ipcount", (bool)false);
  1307. mode_viewxml(m_sid, page, iponly, ipcount);
  1308. }
  1309. }
  1310. else if (viewjson)
  1311. {
  1312. if (m_noSID)
  1313. {
  1314. sendMessageAndClose(redirect("index.html", SHRINK));
  1315. }
  1316. else
  1317. {
  1318. const bool iponly = mapGet(m_httpRequestInfo.m_QueryParameters, "iponly", (bool)false);
  1319. const bool ipcount = mapGet(m_httpRequestInfo.m_QueryParameters, "ipcount", (bool)false);
  1320. const utf8 &callback = mapGet(m_httpRequestInfo.m_QueryParameters, "callback", (utf8)"");
  1321. mode_viewjson(m_sid, page, iponly, ipcount, callback);
  1322. }
  1323. }
  1324. else if (_register)
  1325. {
  1326. if (m_noSID)
  1327. {
  1328. // do a sanity check so that we're only accessing this with the true adminpassword
  1329. if (m_zeroSID)
  1330. {
  1331. mode_summary(0);
  1332. }
  1333. // not matching the master password so show the simple summary
  1334. else
  1335. {
  1336. sendMessageAndClose(redirect("index.html", SHRINK));
  1337. }
  1338. }
  1339. else
  1340. {
  1341. // see if connected otherwise block any access to the pages
  1342. bool connected = false;
  1343. if (p1 == "clear")
  1344. {
  1345. bool handled = false, idHandled = false;
  1346. // if we get a clear then just remove from the config and reload the page
  1347. if (gOptions.editConfigFileEntry(m_sid, gOptions.confFile(), "", "",
  1348. true, handled, idHandled, true) == false)
  1349. {
  1350. handled = false;
  1351. }
  1352. // now attempt to update internal states as appropriate if all went ok
  1353. if (handled == true)
  1354. {
  1355. gOptions.setOption(utf8("streamauthhash_" + tos(m_sid)), (utf8)"");
  1356. streamData *sd = streamData::accessStream(m_sid);
  1357. if (sd)
  1358. {
  1359. sd->streamUpdate(m_sid, (utf8)"", sd->streamMaxUser(),
  1360. sd->streamMaxBitrate(), sd->streamMinBitrate());
  1361. sd->releaseStream();
  1362. }
  1363. }
  1364. }
  1365. else
  1366. {
  1367. connected = true;
  1368. // sanity checks to ensure that we're not re-adding when there is one, etc
  1369. streamData::streamInfo info;
  1370. streamData::extraInfo extra;
  1371. if (!streamData::getStreamInfo(m_sid, info, extra))
  1372. {
  1373. info.m_authHash = gOptions.stream_authHash(m_sid);
  1374. }
  1375. if (connected == true || extra.isRelay)
  1376. {
  1377. mode_register(m_sid, info);
  1378. }
  1379. }
  1380. if (connected == false)
  1381. {
  1382. sendMessageAndClose(redirect("admin.cgi?sid=" + tos(this_sid), SHRINK));
  1383. }
  1384. }
  1385. }
  1386. else if (mode == "listeners")
  1387. {
  1388. mode_listeners(this_sid);
  1389. }
  1390. else if (mode == "kicksrc")
  1391. {
  1392. if (m_noSID)
  1393. {
  1394. if (adminRefer)
  1395. {
  1396. sendMessageAndClose(redirect("index.html", SHRINK));
  1397. }
  1398. else
  1399. {
  1400. sendMessageAndClose(MSG_200);
  1401. }
  1402. }
  1403. else
  1404. {
  1405. // kick source off system
  1406. streamData::killStreamSource(m_sid);
  1407. if (!m_referer.empty())
  1408. {
  1409. utf8 check = ("admin.cgi?sid=" + tos(m_sid));
  1410. // if the referer is the server summary page then we need to go back to it
  1411. sendMessageAndClose(redirect((m_referer == check ? check : "admin.cgi?sid=0"), SHRINK));
  1412. }
  1413. else
  1414. {
  1415. sendMessageAndClose(MSG_200);
  1416. }
  1417. }
  1418. }
  1419. else if (mode == "kickdst" && (!p1.empty()))
  1420. {
  1421. if (m_noSID)
  1422. {
  1423. if (adminRefer)
  1424. {
  1425. sendMessageAndClose(redirect("index.html", SHRINK));
  1426. }
  1427. else
  1428. {
  1429. sendMessageAndClose(MSG_200);
  1430. }
  1431. }
  1432. else
  1433. {
  1434. mode_kickdst(m_sid, p1);
  1435. }
  1436. }
  1437. else if (mode == "viewban")
  1438. {
  1439. mode_viewban(this_sid);
  1440. }
  1441. else if (mode == "bandst" && (!p1.empty()))
  1442. {
  1443. const int mask = mapGet(m_httpRequestInfo.m_QueryParameters, "banmsk", (int)255);
  1444. mode_ban(this_sid, p1, mask);
  1445. }
  1446. else if (mode == "banip")
  1447. {
  1448. const utf8 &ip1 = mapGet(m_httpRequestInfo.m_QueryParameters, "ip1", (utf8)""),
  1449. &ip2 = mapGet(m_httpRequestInfo.m_QueryParameters, "ip2", (utf8)""),
  1450. &ip3 = mapGet(m_httpRequestInfo.m_QueryParameters, "ip3", (utf8)""),
  1451. &ip4 = mapGet(m_httpRequestInfo.m_QueryParameters, "ip4", (utf8)""),
  1452. &mask = mapGet(m_httpRequestInfo.m_QueryParameters, "banmsk", (utf8)"");
  1453. if (ip1.empty() || ip2.empty() || ip3.empty() || ip4.empty() || mask.empty())
  1454. {
  1455. if ((m_referer != utf8("admin.cgi?sid=" + tos(this_sid) + "&mode=viewban")) &&
  1456. (m_referer != utf8("admin.cgi?mode=viewban")))
  1457. {
  1458. sendMessageAndClose(MSG_STD200 + utf8(!HEAD_REQUEST ? "<html><head>"
  1459. "<title>Shoutcast Server</title></head><body>"
  1460. "Invalid resource</body></html>" : ""));
  1461. }
  1462. else
  1463. {
  1464. if (!m_referer.empty())
  1465. {
  1466. sendMessageAndClose(redirect("admin.cgi?sid=" + tos(this_sid) + "&mode=viewban", SHRINK));
  1467. }
  1468. else
  1469. {
  1470. sendMessageAndClose(MSG_200);
  1471. }
  1472. }
  1473. }
  1474. else
  1475. {
  1476. mode_ban(this_sid, (ip1 + "." + ip2 + "." + ip3 + "." + ip4), strtol((const char *)mask.c_str(),0,10));
  1477. }
  1478. }
  1479. else if (mode == "unbandst")
  1480. {
  1481. const utf8 &ip = mapGet(m_httpRequestInfo.m_QueryParameters, "bandst", (utf8)""),
  1482. &mask = mapGet(m_httpRequestInfo.m_QueryParameters, "banmsk", (utf8)"");
  1483. if (ip.empty() || mask.empty())
  1484. {
  1485. if ((m_referer != utf8("admin.cgi?sid=" + tos(this_sid) + "&mode=viewban")) &&
  1486. (m_referer != utf8("admin.cgi?mode=viewban")))
  1487. {
  1488. sendMessageAndClose(MSG_STD200 + utf8(!HEAD_REQUEST ? "<html><head>"
  1489. "<title>Shoutcast Server</title></head><body>"
  1490. "Invalid resource</body></html>" : ""));
  1491. }
  1492. else
  1493. {
  1494. if (!m_referer.empty())
  1495. {
  1496. sendMessageAndClose(redirect("admin.cgi?sid=" + tos(this_sid) + "&mode=viewban", SHRINK));
  1497. }
  1498. else
  1499. {
  1500. sendMessageAndClose(MSG_200);
  1501. }
  1502. }
  1503. }
  1504. else
  1505. {
  1506. mode_unban(this_sid, ip, strtol((const char *)mask.c_str(), 0, 10));
  1507. }
  1508. }
  1509. else if (mode == "viewrip")
  1510. {
  1511. mode_viewrip(this_sid);
  1512. }
  1513. else if (mode == "ripip")
  1514. {
  1515. const utf8 &ip1 = mapGet(m_httpRequestInfo.m_QueryParameters, "ip1", (utf8)""),
  1516. &ip2 = mapGet(m_httpRequestInfo.m_QueryParameters, "ip2", (utf8)""),
  1517. &ip3 = mapGet(m_httpRequestInfo.m_QueryParameters, "ip3", (utf8)""),
  1518. &ip4 = mapGet(m_httpRequestInfo.m_QueryParameters, "ip4", (utf8)"");
  1519. if (ip1.empty() || ip2.empty() || ip3.empty() || ip4.empty())
  1520. {
  1521. // see if we've got a host add attempt and handle as appropriately
  1522. if (m_hostIP.empty())
  1523. {
  1524. if ((m_referer != utf8("admin.cgi?sid=" + tos(m_sid) + "&mode=viewrip")) &&
  1525. (m_referer != utf8("admin.cgi?mode=viewrip")))
  1526. {
  1527. sendMessageAndClose(MSG_STD200 + utf8(!HEAD_REQUEST ? "<html><head>"
  1528. "<title>Shoutcast Server</title></head><body>"
  1529. "Invalid resource</body></html>" : ""));
  1530. }
  1531. else
  1532. {
  1533. if (!m_referer.empty())
  1534. {
  1535. sendMessageAndClose(redirect("admin.cgi?sid=" + tos(m_sid) + "&mode=viewrip", SHRINK));
  1536. }
  1537. else
  1538. {
  1539. sendMessageAndClose(MSG_200);
  1540. }
  1541. }
  1542. }
  1543. else
  1544. {
  1545. const utf8 &raw = mapGet(m_httpRequestInfo.m_QueryParameters, "ripdstraw", (utf8)"");
  1546. mode_rip(this_sid, m_hostIP, raw);
  1547. }
  1548. }
  1549. else
  1550. {
  1551. const utf8 &raw = mapGet(m_httpRequestInfo.m_QueryParameters, "ripdstraw", (utf8)"");
  1552. mode_rip(this_sid, (ip1 + "." + ip2 + "." + ip3 + "." + ip4), raw);
  1553. }
  1554. }
  1555. else if (mode == "unripdst")
  1556. {
  1557. const utf8 &ip = mapGet(m_httpRequestInfo.m_QueryParameters, "ripdst", (utf8)""),
  1558. &raw = mapGet(m_httpRequestInfo.m_QueryParameters, "ripdstraw", (utf8)"");
  1559. if (!isAddress(ip))
  1560. {
  1561. if ((m_referer != utf8("admin.cgi?sid=" + tos(m_sid) + "&mode=viewrip")) &&
  1562. (m_referer != utf8("admin.cgi?mode=viewrip")))
  1563. {
  1564. sendMessageAndClose(MSG_STD200 + utf8(!HEAD_REQUEST ? "<html><head>"
  1565. "<title>Shoutcast Server</title></head><body>"
  1566. "Invalid resource</body></html>" : ""));
  1567. }
  1568. else
  1569. {
  1570. if (!m_referer.empty())
  1571. {
  1572. sendMessageAndClose(redirect("admin.cgi?sid=" + tos(m_sid) + "&mode=viewrip", SHRINK));
  1573. }
  1574. else
  1575. {
  1576. sendMessageAndClose(MSG_200);
  1577. }
  1578. }
  1579. }
  1580. else
  1581. {
  1582. mode_unrip(this_sid, ip, raw);
  1583. }
  1584. }
  1585. else if (mode == "ripdst" && (!p1.empty()))
  1586. {
  1587. const utf8 &raw = mapGet(m_httpRequestInfo.m_QueryParameters, "ripdstraw", (utf8)"");
  1588. mode_rip(this_sid, p1, raw);
  1589. }
  1590. else if (mode == "viewagent")
  1591. {
  1592. mode_viewagent(this_sid);
  1593. }
  1594. else if (mode == "unagent")
  1595. {
  1596. const utf8 &agent = mapGet(m_httpRequestInfo.m_QueryParameters, "agent", (utf8)"");
  1597. if (agent.empty())
  1598. {
  1599. if ((m_referer != utf8("admin.cgi?sid=" + tos(m_sid) + "&mode=viewagent")) &&
  1600. (m_referer != utf8("admin.cgi?mode=viewagent")))
  1601. {
  1602. sendMessageAndClose(MSG_STD200 + utf8(!HEAD_REQUEST ? "<html><head>"
  1603. "<title>Shoutcast Server</title></head><body>"
  1604. "Invalid resource</body></html>" : ""));
  1605. }
  1606. else
  1607. {
  1608. sendMessageAndClose(redirect("admin.cgi?sid=" + tos(m_sid) + "&mode=viewagent", SHRINK));
  1609. }
  1610. }
  1611. else
  1612. {
  1613. mode_unagent(this_sid, agent);
  1614. }
  1615. }
  1616. else if (mode == "agent")
  1617. {
  1618. const utf8 &agent = mapGet(m_httpRequestInfo.m_QueryParameters, "agent", (utf8)"");
  1619. mode_agent(this_sid, agent);
  1620. }
  1621. else if (mode == "resetxml")
  1622. {
  1623. if (m_noSID)
  1624. {
  1625. if (adminRefer)
  1626. {
  1627. sendMessageAndClose(redirect("index.html", SHRINK));
  1628. }
  1629. else
  1630. {
  1631. sendMessageAndClose(MSG_200);
  1632. }
  1633. }
  1634. else
  1635. {
  1636. stats::resetStats(m_sid);
  1637. if (!m_referer.empty())
  1638. {
  1639. sendMessageAndClose(redirect("admin.cgi?sid=" + tos(m_sid), SHRINK));
  1640. }
  1641. else
  1642. {
  1643. sendMessageAndClose(MSG_200);
  1644. }
  1645. }
  1646. }
  1647. else if (mode == "clearcache")
  1648. {
  1649. // TODO consider clearing out the intro / backup files as ell as part of this...
  1650. // clear out all cached resource copies
  1651. gOptions.m_crossdomainStr.clear();
  1652. gOptions.m_crossdomainStrGZ.clear();
  1653. gOptions.m_shoutcastSWFStr.clear();
  1654. gOptions.m_shoutcastSWFStrGZ.clear();
  1655. gOptions.m_robotsTxtBody.clear();
  1656. gOptions.m_robotsTxtBodyGZ.clear();
  1657. gOptions.m_faviconBody.clear();
  1658. gOptions.m_faviconBodyGZ.clear();
  1659. gOptions.m_favIconTime = 0;
  1660. gOptions.m_styleCustomStr.clear();
  1661. gOptions.m_styleCustomStrGZ.clear();
  1662. gOptions.m_styleCustomHeaderTime = 0;
  1663. DeleteAllCaches();
  1664. last_update_check = 0;
  1665. ILOG(LOGNAME "Cleared resource cache(s).");
  1666. if (adminRefer)
  1667. {
  1668. sendMessageAndClose(redirect("admin.cgi", SHRINK));
  1669. }
  1670. else
  1671. {
  1672. sendMessageAndClose(MSG_200);
  1673. }
  1674. }
  1675. else if (mode == "bannedlist")
  1676. {
  1677. reloadBanLists();
  1678. if (adminRefer)
  1679. {
  1680. sendMessageAndClose(redirect("admin.cgi", SHRINK));
  1681. }
  1682. else
  1683. {
  1684. sendMessageAndClose(MSG_200);
  1685. }
  1686. }
  1687. else if (mode == "reservelist")
  1688. {
  1689. reloadRipLists();
  1690. if (adminRefer)
  1691. {
  1692. sendMessageAndClose(redirect("admin.cgi", SHRINK));
  1693. }
  1694. else
  1695. {
  1696. sendMessageAndClose(MSG_200);
  1697. }
  1698. }
  1699. else if (mode == "adminlist")
  1700. {
  1701. reloadAdminAccessList();
  1702. if (adminRefer)
  1703. {
  1704. sendMessageAndClose(redirect("admin.cgi", SHRINK));
  1705. }
  1706. else
  1707. {
  1708. sendMessageAndClose(MSG_200);
  1709. }
  1710. }
  1711. else if (mode == "useragentlist")
  1712. {
  1713. reloadAgentLists();
  1714. if (adminRefer)
  1715. {
  1716. sendMessageAndClose(redirect("admin.cgi", SHRINK));
  1717. }
  1718. else
  1719. {
  1720. sendMessageAndClose(MSG_200);
  1721. }
  1722. }
  1723. else if (mode == "reload")
  1724. {
  1725. const int force = mapGet(m_httpRequestInfo.m_QueryParameters, "force", (int)0);
  1726. if (adminRefer)
  1727. {
  1728. sendMessageAndClose(redirect((reloadConfig(force) == true ? "admin.cgi?sid=0&refresh=3" : "admin.cgi?sid=0"), SHRINK));
  1729. }
  1730. else
  1731. {
  1732. reloadConfig(force);
  1733. sendMessageAndClose(MSG_200);
  1734. }
  1735. }
  1736. else if (mode == "viewlog")
  1737. {
  1738. if (m_noSID)
  1739. {
  1740. const utf8 &server = mapGet(m_httpRequestInfo.m_QueryParameters, "server", (utf8)"");
  1741. if (!server.empty() && ((server == logId) || (server == logTailId)))
  1742. {
  1743. mode_viewlog(m_sid, (p1 == "tail"), (p1 == "save"), true);
  1744. }
  1745. else
  1746. {
  1747. sendMessageAndClose(redirect("index.html", SHRINK));
  1748. }
  1749. }
  1750. else
  1751. {
  1752. mode_viewlog(m_sid, (p1 == "tail"), (p1 == "save"), false);
  1753. }
  1754. }
  1755. else if (mode == "history")
  1756. {
  1757. if (m_noSID)
  1758. {
  1759. if (adminRefer)
  1760. {
  1761. sendMessageAndClose(redirect("index.html", SHRINK));
  1762. }
  1763. else
  1764. {
  1765. sendMessageAndClose(MSG_200);
  1766. }
  1767. }
  1768. else
  1769. {
  1770. const utf8 &type = mapGet(m_httpRequestInfo.m_QueryParameters, "type", (utf8)"");
  1771. const bool json = (type == "json"), xml = (type == "xml");
  1772. if (!json && !xml)
  1773. {
  1774. mode_history(m_sid);
  1775. }
  1776. else
  1777. {
  1778. utf8 header, body;
  1779. if (json)
  1780. {
  1781. const utf8& callback = mapGet(m_httpRequestInfo.m_QueryParameters, "callback", (utf8)"");
  1782. body = protocol_HTTPStyle::getPlayedJSON(m_sid, header, callback, true);
  1783. }
  1784. else
  1785. {
  1786. body = protocol_HTTPStyle::getPlayedXML(m_sid, header, true);
  1787. }
  1788. COMPRESS(header, body);
  1789. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  1790. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  1791. }
  1792. }
  1793. }
  1794. else if (mode == "art")
  1795. {
  1796. if (m_noSID)
  1797. {
  1798. if (adminRefer)
  1799. {
  1800. sendMessageAndClose(redirect("index.html", SHRINK));
  1801. }
  1802. else
  1803. {
  1804. sendMessageAndClose(MSG_200);
  1805. }
  1806. }
  1807. else
  1808. {
  1809. mode_art(m_sid, (p1 == "playing"));
  1810. }
  1811. }
  1812. else if (mode == "manualauthhash")
  1813. {
  1814. bool handled = false;
  1815. const utf8 &authhash = mapGet(m_httpRequestInfo.m_QueryParameters, "authhash", (utf8)"");
  1816. // make sure that we're only allow valid values
  1817. if (authhash.empty() || yp2::isValidAuthhash(authhash))
  1818. {
  1819. bool idHandled = false;
  1820. if (gOptions.editConfigFileEntry(m_sid, gOptions.confFile(), authhash, "",
  1821. true, handled, idHandled, true) == false)
  1822. {
  1823. handled = false;
  1824. }
  1825. // changed in b69 to force the change through even if there is a config saving issue
  1826. // as there are cases where the authhash is gone but only updating on success would
  1827. // end up in the inability to start things over again e.g. with CentroCast v3 quirks
  1828. gOptions.setOption(utf8("streamauthhash_" + tos(m_sid)), authhash);
  1829. }
  1830. streamData *sd = streamData::accessStream(m_sid);
  1831. if (sd)
  1832. {
  1833. if (sd->isSourceConnected(m_sid))
  1834. {
  1835. utf8 oldAuthhash = sd->streamAuthhash();
  1836. sd->streamUpdate(m_sid, authhash, sd->streamMaxUser(),
  1837. sd->streamMaxBitrate(), sd->streamMinBitrate());
  1838. ILOG(gOptions.logSectionName() + "Changed authhash for stream #" +
  1839. tos(m_sid) + " to " + (authhash.empty() ? "empty" : authhash) +
  1840. " [was " + (oldAuthhash.empty() ? "empty" : oldAuthhash) + "]");
  1841. }
  1842. sd->releaseStream();
  1843. }
  1844. // now attempt to update internal states as appropriate if all went ok
  1845. if (handled == true)
  1846. {
  1847. sendMessageAndClose("HTTP/1.1 200 OK\r\n"
  1848. "Content-Type:text/plain\r\n"
  1849. "Content-Length:5\r\n"
  1850. "Cache-Control:no-cache\r\n"
  1851. "Access-Control-Allow-Origin:*\r\n"
  1852. "Connection:close\r\n\r\n200\r\n");
  1853. }
  1854. else
  1855. {
  1856. utf8 message = "Error saving changes to the configuration file.<br>"
  1857. "Check that you have write access and the<br>"
  1858. "specified configuration file still exists.<br><br>"
  1859. "The requested authhash change was applied.";
  1860. utf8 header = "HTTP/1.1 667\r\n"
  1861. "Content-Type:text/plain\r\n"
  1862. "Access-Control-Allow-Origin:*\r\n"
  1863. "Connection:close\r\n";
  1864. COMPRESS(header, message);
  1865. header += "Content-Length:" + tos(message.size()) + "\r\n\r\n";
  1866. sendMessageAndClose(header + (!HEAD_REQUEST ? message : ""));
  1867. }
  1868. }
  1869. else if (mode == "rotate")
  1870. {
  1871. const utf8 &files = mapGet(m_httpRequestInfo.m_QueryParameters, "files", (utf8)""),
  1872. &rotateType = (!(files == "log" || files == "w3c") ? "all " : (files == "log" ? "": "W3C "));
  1873. ILOG(LOGNAME "Rotating " + rotateType + "log file(s)");
  1874. if ((files == "log") || (files == ""))
  1875. {
  1876. ROTATE;
  1877. printUpdateMessage();
  1878. if (m_logFile)
  1879. {
  1880. ::fclose(m_logFile);
  1881. m_logFile = 0;
  1882. }
  1883. }
  1884. // and now rotate the w3c logs (going upto the configured number of old copies to be like the log rotate)
  1885. rotatew3cFiles(files);
  1886. ILOG(LOGNAME "Rotated " + rotateType + "log file(s) [PID: " + tos(getpid()) + "]");
  1887. if (adminRefer)
  1888. {
  1889. sendMessageAndClose(redirect("admin.cgi", SHRINK));
  1890. }
  1891. else
  1892. {
  1893. sendMessageAndClose(MSG_200);
  1894. }
  1895. }
  1896. else if (mode == "startrelay")
  1897. {
  1898. if (m_noSID)
  1899. {
  1900. if (adminRefer)
  1901. {
  1902. sendMessageAndClose(redirect("index.html", SHRINK));
  1903. }
  1904. else
  1905. {
  1906. sendMessageAndClose(MSG_200);
  1907. }
  1908. }
  1909. else
  1910. {
  1911. // only attempt a source relay connection if it is not signaled
  1912. // as active or pending to prevent multiple attempts being run.
  1913. bool noEntry = false, active = (streamData::isRelayActive(m_sid, noEntry) == 1);
  1914. if (!active)
  1915. {
  1916. config::streamConfig stream;
  1917. if (gOptions.getStreamConfig(stream, m_sid))
  1918. {
  1919. restartRelay(stream);
  1920. }
  1921. }
  1922. if (!m_referer.empty())
  1923. {
  1924. utf8 check = ("admin.cgi?sid=" + tos(m_sid));
  1925. // if the referer is the server summary page then we need to go back to it
  1926. sendMessageAndClose(redirect((m_referer == check ? check : "admin.cgi?sid=0") +
  1927. (!active ? "&refresh=3" : ""), SHRINK));
  1928. }
  1929. else
  1930. {
  1931. sendMessageAndClose(MSG_200);
  1932. }
  1933. }
  1934. }
  1935. else if (mode == "startrelays")
  1936. {
  1937. bool refresh = false;
  1938. config::streams_t streams;
  1939. gOptions.getStreamConfigs(streams);
  1940. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  1941. {
  1942. if (!(*i).second.m_relayUrl.url().empty() && !streamData::isSourceConnected((*i).first))
  1943. {
  1944. // only attempt a source relay connection if it is not signaled
  1945. // as active or pending to prevent multiple attempts being run.
  1946. bool noEntry = false, active = (streamData::isRelayActive((*i).first, noEntry) == 1);
  1947. if (!active)
  1948. {
  1949. ILOG(gOptions.logSectionName() + "Starting source for stream #" + tos((*i).first) + ".");
  1950. restartRelay((*i).second);
  1951. refresh = true;
  1952. }
  1953. }
  1954. }
  1955. if (adminRefer)
  1956. {
  1957. sendMessageAndClose(redirect("admin.cgi?sid=0" + (refresh ? "&refresh=3" : (utf8)""), SHRINK));
  1958. }
  1959. else
  1960. {
  1961. sendMessageAndClose(MSG_200);
  1962. }
  1963. }
  1964. else if (mode == "kicksources")
  1965. {
  1966. bool refresh = false;
  1967. streamData::streamIDs_t streamIds = streamData::getStreamIds(true);
  1968. if (!streamIds.empty())
  1969. {
  1970. for (streamData::streamIDs_t::const_iterator i = streamIds.begin(); i != streamIds.end(); ++i)
  1971. {
  1972. // kick source off system
  1973. streamData::killStreamSource((*i));
  1974. refresh = true;
  1975. }
  1976. }
  1977. if (adminRefer)
  1978. {
  1979. sendMessageAndClose(redirect("admin.cgi?sid=0" + (refresh ? "&refresh=1" : (utf8)""), SHRINK));
  1980. }
  1981. else
  1982. {
  1983. sendMessageAndClose(MSG_200);
  1984. }
  1985. }
  1986. else if(mode == "bandwidth")
  1987. {
  1988. const utf8 &type = mapGet(m_httpRequestInfo.m_QueryParameters, "type", (utf8)"");
  1989. const bool json = (type == "json"), xml = (type == "xml");
  1990. if (!json && !xml)
  1991. {
  1992. const int refresh = mapGet(m_httpRequestInfo.m_QueryParameters, "refresh", 0);
  1993. mode_bandwidth_html(refresh);
  1994. }
  1995. else
  1996. {
  1997. if (json)
  1998. {
  1999. const utf8 &callback = mapGet(m_httpRequestInfo.m_QueryParameters, "callback", (utf8)"");
  2000. mode_bandwidth_json(callback);
  2001. }
  2002. else
  2003. {
  2004. mode_bandwidth_xml();
  2005. }
  2006. }
  2007. }
  2008. else if (mode == "ypstatus")
  2009. {
  2010. const utf8 &type = mapGet(m_httpRequestInfo.m_QueryParameters, "type", (utf8)"");
  2011. if ((type == "json"))
  2012. {
  2013. const utf8 &callback = mapGet(m_httpRequestInfo.m_QueryParameters, "callback", (utf8)"");
  2014. mode_ypstatus_json(callback);
  2015. }
  2016. else
  2017. {
  2018. mode_ypstatus_xml();
  2019. }
  2020. }
  2021. else if (mode == "sources")
  2022. {
  2023. mode_sources(m_hostIP);
  2024. }
  2025. else if (mode == "adgroups")
  2026. {
  2027. mode_adgroups();
  2028. }
  2029. else if (mode == "debug")
  2030. {
  2031. const utf8 &option = mapGet(m_httpRequestInfo.m_QueryParameters, "option", (utf8)"");
  2032. if (!option.empty() && !adminRefer)
  2033. {
  2034. // prevent direct access to being able to edit this
  2035. // and force a redirection to the non-param version
  2036. sendMessageAndClose(redirect("admin.cgi?mode=debug", SHRINK));
  2037. return;
  2038. }
  2039. const utf8 &on_off = mapGet(m_httpRequestInfo.m_QueryParameters, "on", (utf8)"");
  2040. mode_debug(option, (on_off == "true"), adminRefer);
  2041. }
  2042. else if (mode == "help")
  2043. {
  2044. mode_help();
  2045. }
  2046. else if (mode == "config")
  2047. {
  2048. mode_config();
  2049. }
  2050. #if 0
  2051. else if (mode == "logs")
  2052. {
  2053. mode_logs(result);
  2054. }
  2055. #endif
  2056. else if (mode == "version")
  2057. {
  2058. // only allow from the admin page to avoid possible spamming sttempts
  2059. if (adminRefer)
  2060. {
  2061. checkVersion(m_lastActivityTime);
  2062. sendMessageAndClose(redirect("admin.cgi?sid=0&refresh=-3", SHRINK));
  2063. }
  2064. else
  2065. {
  2066. sendMessageAndClose(MSG_200);
  2067. }
  2068. }
  2069. else
  2070. {
  2071. if (m_noSID)
  2072. {
  2073. // do a sanity check so that we're only accessing this with the true adminpassword
  2074. if (m_zeroSID)
  2075. {
  2076. mode_summary(mapGet(m_httpRequestInfo.m_QueryParameters, "refresh", 0));
  2077. }
  2078. // not matching the master password so show the simple summary
  2079. else
  2080. {
  2081. sendMessageAndClose(redirect("index.html", SHRINK));
  2082. }
  2083. }
  2084. else
  2085. {
  2086. const int refresh = mapGet(m_httpRequestInfo.m_QueryParameters, "refresh", 0);
  2087. mode_none(m_sid, refresh);
  2088. }
  2089. }
  2090. }
  2091. else
  2092. {
  2093. sendMessageAndClose(MSG_AUTHFAILURE401 + utf8(!HEAD_REQUEST ?
  2094. "<html><head>Unauthorized<title>Shoutcast "
  2095. "Administrator</title></head></html>" : ""));
  2096. }
  2097. }
  2098. void protocol_admincgi::state_SendFileHeader() throw(std::exception)
  2099. {
  2100. if ((!m_saveLogFile && SHRINK) &&
  2101. compressDataStart(m_logFileBodyPrefix, &m_stream, (Bytef*)"sc_serv.log\0", false))
  2102. {
  2103. m_logFileHeader += "Content-Encoding:gzip\r\n";
  2104. }
  2105. m_logFileHeader += "\r\n";
  2106. m_outMsg = m_logFileHeader + (!m_saveLogFile ? tohex(m_logFileBodyPrefix.size()) + "\r\n" + m_logFileBodyPrefix + "\r\n" : "");
  2107. m_outBuffer = m_outMsg.c_str();
  2108. bandWidth::updateAmount(bandWidth::PRIVATE_WEB, (m_outBufferSize = (int)m_outMsg.size()));
  2109. m_state = &protocol_admincgi::state_Send;
  2110. m_nextState = &protocol_admincgi::state_SendFileContents;
  2111. m_result.write();
  2112. if (m_tailLogFile)
  2113. {
  2114. m_result.read(fileno(m_logFile));
  2115. }
  2116. }
  2117. void protocol_admincgi::state_SendFileFooter() throw(std::exception)
  2118. {
  2119. if (SHRINK)
  2120. {
  2121. compressDataCont(m_logFileBodyFooter, &m_stream);
  2122. }
  2123. m_logFileBodyFooter = tohex(m_logFileBodyFooter.size()) + "\r\n" + m_logFileBodyFooter + "\r\n";
  2124. m_outBuffer = m_logFileBodyFooter.c_str();
  2125. bandWidth::updateAmount(bandWidth::PRIVATE_WEB, (m_outBufferSize = (int)m_logFileBodyFooter.size()));
  2126. m_state = &protocol_admincgi::state_Send;
  2127. m_nextState = &protocol_admincgi::state_SendFileEnd;
  2128. m_result.write();
  2129. }
  2130. void protocol_admincgi::state_SendFileEnd() throw(std::exception)
  2131. {
  2132. strncpy((char*)&(m_logFileBuffer[0]), "0\r\n\r\n", 1024);
  2133. m_outBuffer = &(m_logFileBuffer[0]);
  2134. m_outBufferSize = 5;
  2135. m_nextState = &protocol_admincgi::state_Close;
  2136. bandWidth::updateAmount(bandWidth::PRIVATE_WEB, m_outBufferSize);
  2137. compressDataEnd(&m_stream);
  2138. m_state = &protocol_admincgi::state_Send;
  2139. m_nextState = &protocol_admincgi::state_Close;
  2140. m_result.write();
  2141. }
  2142. // this will only be receiving an already converted
  2143. // string so no need to do the commented part again
  2144. utf8 protocol_admincgi::escapeText(const std::vector<uniString::utf8::value_type> &s) throw()
  2145. {
  2146. utf8 result;
  2147. result.resize(0);
  2148. bool inHead = false;
  2149. int headCount = 0;
  2150. const size_t amt = s.size();
  2151. for (size_t x = 0; x < amt; ++x)
  2152. {
  2153. if ((s[x] == '*') && (((x + 1) < amt) && (s[x + 1] == '*')))
  2154. {
  2155. inHead = true;
  2156. }
  2157. else if (s[x] == '\n')
  2158. {
  2159. if (!inHead)
  2160. {
  2161. if ((((x + 1) < amt) && isdigit(s[x + 1])))
  2162. {
  2163. if (inMsg)
  2164. {
  2165. result += "</b>";
  2166. }
  2167. result += "\n";
  2168. inMsg = false;
  2169. }
  2170. else
  2171. {
  2172. if (((x + 1) == amt))
  2173. {
  2174. if (inMsg)
  2175. {
  2176. result += "</b>";
  2177. }
  2178. result += "\n";
  2179. inMsg = false;
  2180. }
  2181. else
  2182. {
  2183. result += "\n\t\t\t";
  2184. }
  2185. }
  2186. }
  2187. else
  2188. {
  2189. ++headCount;
  2190. }
  2191. }
  2192. else if ((s[x] == 'D') &&
  2193. (((x > 0) && (s[x - 1] == '\t')) ||
  2194. (!x && (lastChar == '\t'))))
  2195. {
  2196. result += "<b class=\"d\">D";
  2197. inMsg = true;
  2198. }
  2199. else if ((s[x] == 'E') &&
  2200. (((x > 0) && (s[x - 1] == '\t')) ||
  2201. (!x && (lastChar == '\t'))))
  2202. {
  2203. result += "<b class=\"e\">E";
  2204. inMsg = true;
  2205. }
  2206. else if ((s[x] == 'W') &&
  2207. (((x > 0) && (s[x - 1] == '\t')) ||
  2208. (!x && (lastChar == '\t'))))
  2209. {
  2210. result += "<b class=\"w\">W";
  2211. inMsg = true;
  2212. }
  2213. else if ((s[x] == 'U') &&
  2214. (((x > 0) && (s[x-1] == '\t')) ||
  2215. (!x && (lastChar == '\t'))))
  2216. {
  2217. result += "<b class=\"u\">U";
  2218. inMsg = true;
  2219. }
  2220. else if ((s[x] == 'I') &&
  2221. (((x > 0) && (s[x-1] == '\t')) ||
  2222. (!x && (lastChar == '\t'))))
  2223. {
  2224. if (!inHead)
  2225. {
  2226. result += "<b class=\"i\">I";
  2227. inMsg = true;
  2228. }
  2229. }
  2230. else
  2231. {
  2232. if (!inHead)
  2233. {
  2234. if (s[x] == '<')
  2235. {
  2236. result += "&lt;";
  2237. }
  2238. else if (s[x] == '>')
  2239. {
  2240. result += "&gt;";
  2241. }
  2242. else if (s[x] == '&')
  2243. {
  2244. result += "&amp;";
  2245. }
  2246. else if (s[x] == '\'')
  2247. {
  2248. result += "&apos;";
  2249. }
  2250. else if (s[x] == '"')
  2251. {
  2252. result += "&quot;";
  2253. }
  2254. else
  2255. {
  2256. result += s[x];
  2257. }
  2258. }
  2259. else
  2260. {
  2261. if (inHead && (headCount > 3) && (s[x] == '\t'))
  2262. {
  2263. inHead = false;
  2264. headCount = 0;
  2265. x += 5;
  2266. }
  2267. }
  2268. }
  2269. if (!s[x])
  2270. {
  2271. break;
  2272. }
  2273. }
  2274. lastChar = s[amt - 1];
  2275. return result;
  2276. }
  2277. void protocol_admincgi::state_SendFileContents() throw(std::exception)
  2278. {
  2279. m_logFileBuffer.clear();
  2280. m_logFileBuffer.resize(SEND_SIZE);
  2281. const size_t amt = fread(&(m_logFileBuffer[0]), 1, (SEND_SIZE - 1), m_logFile);
  2282. if (amt > 0)
  2283. {
  2284. static utf8 out;
  2285. out.clear();
  2286. if (!m_saveLogFile)
  2287. {
  2288. m_logFileBuffer.resize(amt);
  2289. out = escapeText(m_logFileBuffer);
  2290. }
  2291. else
  2292. {
  2293. out = utf8(&(m_logFileBuffer[0]), amt);
  2294. }
  2295. if (!out.empty())
  2296. {
  2297. if (m_saveLogFile || (SHRINK))
  2298. {
  2299. if (m_saveLogFile == 1)
  2300. {
  2301. if (compressDataStart(out, &m_stream, (Bytef*)m_logFileName.c_str()))
  2302. {
  2303. m_saveLogFile = 2;
  2304. }
  2305. }
  2306. else
  2307. {
  2308. compressDataCont(out, &m_stream);
  2309. }
  2310. }
  2311. out = tohex(out.size()) + "\r\n" + out + "\r\n";
  2312. m_outBuffer = out.c_str();
  2313. bandWidth::updateAmount(bandWidth::PRIVATE_WEB, (m_outBufferSize = (int)out.size()));
  2314. m_nextState = &protocol_admincgi::state_SendFileContents;
  2315. }
  2316. else
  2317. {
  2318. m_nextState = (m_saveLogFile ? &protocol_admincgi::state_SendFileEnd : &protocol_admincgi::state_SendFileFooter);
  2319. }
  2320. m_state = &protocol_admincgi::state_Send;
  2321. m_result.write();
  2322. if (m_tailLogFile)
  2323. {
  2324. m_result.timeout(1);
  2325. m_result.read(fileno(m_logFile));
  2326. }
  2327. }
  2328. else if (ferror(m_logFile) || !m_logFile)
  2329. {
  2330. m_state = &protocol_admincgi::state_Close;
  2331. m_result.run();
  2332. }
  2333. else if (feof(m_logFile) && (!m_tailLogFile))
  2334. {
  2335. if (m_saveLogFile)
  2336. {
  2337. static utf8 out;
  2338. out.clear();
  2339. compressDataFinish(out, &m_stream);
  2340. out = tohex(out.size()) + "\r\n" + out + "\r\n";
  2341. m_outBuffer = out.c_str();
  2342. bandWidth::updateAmount(bandWidth::PRIVATE_WEB, (m_outBufferSize = (int)out.size()));
  2343. m_state = &protocol_admincgi::state_Send;
  2344. m_nextState = &protocol_admincgi::state_SendFileEnd;
  2345. }
  2346. else
  2347. {
  2348. m_state = &protocol_admincgi::state_SendFileFooter;
  2349. }
  2350. m_result.write();
  2351. m_result.run();
  2352. }
  2353. else
  2354. {
  2355. m_result.timeout(10);
  2356. }
  2357. }
  2358. // display log
  2359. void protocol_admincgi::mode_viewlog(const streamData::streamID_t sid, const bool tail, const bool save, const bool server) throw()
  2360. {
  2361. if (!save)
  2362. {
  2363. utf8 headerTitle = utf8(utf8("Server Log") + (tail ? " (Tailing)":""));
  2364. m_logFileHeader = MSG_NO_CLOSE_200;
  2365. m_logFileBodyPrefix += (server ? getServerAdminHeader(headerTitle) :
  2366. getStreamAdminHeader(sid, headerTitle)) + getUptimeScript() +
  2367. (tail ? "<div style=\"padding:1em;\"><b>Showing log output from the current log "
  2368. "position and onwards. Click <a href=\"admin.cgi?mode=viewlog&amp;server=" +
  2369. randomId(logTailId) + "\">here</a> to view the complete log output or <a "
  2370. "href=\"admin.cgi?mode=viewlog&amp;server=" + logId + "&amp;viewlog=save\">here</a> "
  2371. "to save the complete log output. When tailing the log output, there may be "
  2372. "a delay before any new log output will appear and it may also stop updating if "
  2373. "there is no log activity depending on configured timeouts. Reload the page if this "
  2374. "should happens.</b></div>" : "") + getIEFlexFix() +
  2375. "<pre id=\"log\" style=\"tab-size:16;-moz-tab-size:16;-o-tab-size:16;\"><font class=\"t\">";
  2376. // doing to just make sure that the end of the output should be correct
  2377. m_logFileBodyFooter = "</font>\n</pre>" + getfooterStr();
  2378. m_tailLogFile = tail;
  2379. if (server || !(gOptions.read_stream_adminPassword(sid) && !gOptions.stream_adminPassword(sid).empty()))
  2380. {
  2381. const utf8 &file = mapGet(m_httpRequestInfo.m_QueryParameters, "file", gOptions.realLogFile());
  2382. m_logFile = uniFile::fopen(file, "r");
  2383. if (m_logFile)
  2384. {
  2385. m_logFileName = fileUtil::stripPath(file);
  2386. m_logFileName.push_back('\0');
  2387. if (m_tailLogFile)
  2388. {
  2389. ::fseek(m_logFile, 0, SEEK_END);
  2390. }
  2391. }
  2392. }
  2393. else
  2394. {
  2395. utf8 body = m_logFileBodyPrefix + "Viewing Not Allowed With Current Permissions</pre>" + m_logFileBodyFooter;
  2396. COMPRESS(m_logFileHeader, body);
  2397. m_logFileHeader += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  2398. sendMessageAndClose(m_logFileHeader + (!HEAD_REQUEST ? body : ""));
  2399. return;
  2400. }
  2401. if (!m_logFile)
  2402. {
  2403. utf8 body = m_logFileBodyPrefix + "Log File Not Found (" +
  2404. stripWhitespace(errMessage()) + ")</pre>" +
  2405. m_logFileBodyFooter;
  2406. COMPRESS(m_logFileHeader, body);
  2407. m_logFileHeader += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  2408. sendMessageAndClose(m_logFileHeader + (!HEAD_REQUEST ? body : ""));
  2409. }
  2410. else
  2411. {
  2412. m_logFileHeader += "Transfer-Encoding:chunked\r\n";
  2413. m_state = &protocol_admincgi::state_SendFileHeader;
  2414. m_result.run();
  2415. }
  2416. }
  2417. else
  2418. {
  2419. if (server || !(gOptions.read_stream_adminPassword(sid) && !gOptions.stream_adminPassword(sid).empty()))
  2420. {
  2421. const utf8 &file = mapGet(m_httpRequestInfo.m_QueryParameters, "file", gOptions.realLogFile());
  2422. m_logFile = uniFile::fopen(file, "r");
  2423. if (m_logFile)
  2424. {
  2425. m_logFileName = fileUtil::stripPath(file);
  2426. m_logFileHeader = "HTTP/1.1 200 OK\r\n"
  2427. "Content-Type:application/x-gzip-compressed\r\n"
  2428. "Content-Disposition:attachment;filename=\"" +
  2429. m_logFileName + ".gz\"\r\n";
  2430. m_saveLogFile = true;
  2431. }
  2432. }
  2433. else
  2434. {
  2435. sendMessageAndClose(MSG_HTTP403);
  2436. return;
  2437. }
  2438. if (!m_logFile)
  2439. {
  2440. sendMessageAndClose(MSG_HTTP404);
  2441. }
  2442. else
  2443. {
  2444. m_logFileHeader += "Transfer-Encoding:chunked\r\n";
  2445. m_state = &protocol_admincgi::state_SendFileHeader;
  2446. m_result.run();
  2447. }
  2448. }
  2449. }
  2450. // shown played history (as is also shown on the public pages if enabled)
  2451. void protocol_admincgi::mode_history(const streamData::streamID_t sid) throw()
  2452. {
  2453. utf8 header = MSG_NO_CLOSE_200,
  2454. body = getStreamAdminHeader(sid, "Stream History") +
  2455. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" "
  2456. "cellspacing=\"0\"><tr valign=\"top\"><td>" +
  2457. protocol_HTTPStyle::getPlayedBody(sid) + "</table>" +
  2458. getUptimeScript() + getIEFlexFix() + getfooterStr();
  2459. COMPRESS(header, body);
  2460. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  2461. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  2462. }
  2463. // remove an IP from the rip list
  2464. void protocol_admincgi::mode_unrip(const streamData::streamID_t sid, const utf8 &ripAddr, const utf8 &rawIpAddr) throw()
  2465. {
  2466. utf8 msg;
  2467. try
  2468. {
  2469. size_t stream_ID = ((gOptions.read_stream_ripFile(sid) && !gOptions.stream_ripFile(sid).empty()) ? sid : 0);
  2470. if (isAddress(ripAddr))
  2471. {
  2472. bool ret = g_ripList.remove(ripAddr,stream_ID,false), usingRaw = false;
  2473. if (!ret && !rawIpAddr.empty())
  2474. {
  2475. ret = g_ripList.remove(rawIpAddr,stream_ID,false);
  2476. if (ret) usingRaw = true;
  2477. }
  2478. if (ret)
  2479. {
  2480. ILOG("[RIP] Removed `" + (!usingRaw ? ripAddr : rawIpAddr) + "' from " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " rip list");
  2481. if (gOptions.saveRipListOnExit())
  2482. {
  2483. if (stream_ID && gOptions.read_stream_ripFile(stream_ID) && !gOptions.stream_ripFile(stream_ID).empty())
  2484. {
  2485. g_ripList.save(gOptions.stream_ripFile(stream_ID),stream_ID);
  2486. }
  2487. else
  2488. {
  2489. g_ripList.save(gOptions.ripFile(),0);
  2490. }
  2491. }
  2492. stats::updateRipClients(stream_ID, (!usingRaw ? ripAddr : rawIpAddr), false);
  2493. }
  2494. else
  2495. {
  2496. ILOG("[RIP] Unable to remove `" + ripAddr + "' from " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " rip list");
  2497. }
  2498. }
  2499. else
  2500. {
  2501. ILOG("[RIP] `" + ripAddr + "' is not a valid value. Skipping removing from the " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " rip list");
  2502. }
  2503. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer == "admin.cgi?sid=" + tos(sid) ? "" : "&mode=viewrip"), SHRINK) : MSG_200);
  2504. }
  2505. catch(const exception &ex)
  2506. {
  2507. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer != utf8("admin.cgi?sid=" + tos(sid) + "&mode=viewrip") ? "" : "&mode=viewrip"), SHRINK) : MSG_200);
  2508. ELOG(ex.what());
  2509. }
  2510. sendMessageAndClose(msg);
  2511. }
  2512. // add an IP / hostname to the rip list
  2513. void protocol_admincgi::mode_rip(const streamData::streamID_t sid, const utf8 &ripAddr, const utf8 &rawIpAddr) throw()
  2514. {
  2515. utf8 msg;
  2516. try
  2517. {
  2518. const size_t stream_ID = ((gOptions.read_stream_ripFile(sid) && !gOptions.stream_ripFile(sid).empty()) ? sid : 0);
  2519. if (isAddress(ripAddr))
  2520. {
  2521. if (!g_ripList.find(ripAddr,stream_ID))
  2522. {
  2523. bool added = g_ripList.add(ripAddr,stream_ID, true), usingRaw = false;
  2524. if (!added && !rawIpAddr.empty())
  2525. {
  2526. if (g_ripList.add(rawIpAddr,stream_ID, false))
  2527. {
  2528. usingRaw = true;
  2529. }
  2530. }
  2531. ILOG("[RIP] Added `" + (!usingRaw ? ripAddr : rawIpAddr) + "' to " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " rip list");
  2532. if (gOptions.saveRipListOnExit())
  2533. {
  2534. if (stream_ID && gOptions.read_stream_ripFile(stream_ID) && !gOptions.stream_ripFile(stream_ID).empty())
  2535. {
  2536. g_ripList.save(gOptions.stream_ripFile(stream_ID),stream_ID);
  2537. }
  2538. else
  2539. {
  2540. g_ripList.save(gOptions.ripFile(),0);
  2541. }
  2542. }
  2543. stats::updateRipClients(stream_ID, (!usingRaw ? ripAddr : rawIpAddr), true);
  2544. }
  2545. else
  2546. {
  2547. ILOG("[RIP] `" + ripAddr + "' already in the " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " rip list");
  2548. }
  2549. }
  2550. else
  2551. {
  2552. ILOG("[RIP] `" + ripAddr + "' is not a valid value. Skipping adding to the " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " rip list");
  2553. }
  2554. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer == "admin.cgi?sid=" + tos(sid) ? "" : "&mode=viewrip"), SHRINK) : MSG_200);
  2555. }
  2556. catch(const exception &ex)
  2557. {
  2558. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer != utf8("admin.cgi?sid=" + tos(sid) + "&mode=viewrip") ? "" : "&mode=viewrip"), SHRINK) : MSG_200);
  2559. ELOG(ex.what());
  2560. }
  2561. sendMessageAndClose(msg);
  2562. }
  2563. // show rip list
  2564. void protocol_admincgi::mode_viewrip(const streamData::streamID_t sid) throw()
  2565. {
  2566. vector<ripList::rip_t> rip_list;
  2567. g_ripList.get(rip_list,((gOptions.read_stream_ripFile(sid) && !gOptions.stream_ripFile(sid).empty()) ? sid : 0));
  2568. utf8 header = MSG_NO_CLOSE_200,
  2569. headerTitle = (!sid ? "Server Reserved List" : "Stream Reserved List"),
  2570. body = (!sid ? getServerAdminHeader(headerTitle) : getStreamAdminHeader(sid, headerTitle)) +
  2571. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"top\"><td>";
  2572. if (rip_list.empty())
  2573. {
  2574. body += "<b>&nbsp;No Reserved Entries</b><br>";
  2575. }
  2576. else
  2577. {
  2578. body += "<b>&nbsp;Reserved Entry List:</b><ol>";
  2579. for (vector<ripList::rip_t>::const_iterator i = rip_list.begin(); i != rip_list.end(); ++i)
  2580. {
  2581. body += "<li><b>" + aolxml::escapeXML((*i).m_numericIP) + "</b>" +
  2582. (!(*i).m_hostIP.empty() ? " (" + aolxml::escapeXML((*i).m_hostIP) + ")" : "") +
  2583. " - <a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=unripdst&amp;ripdst=" +
  2584. urlUtils::escapeURI_RFC3986((*i).m_numericIP) + "\">remove</a>";
  2585. }
  2586. body += "</ol>";
  2587. }
  2588. body +=
  2589. "</td><td style=\"padding:0 1em 0 1em;\"><br>"
  2590. "<table class=\"ent\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" align=\"right\">"
  2591. "<tr class=\"ent\">"
  2592. "<td class=\"inp\" align=\"center\">Reserve&nbsp;Connection Slot by IP</td>"
  2593. "</tr>"
  2594. "<form method=\"url\" action=\"admin.cgi\">"
  2595. "<tr>"
  2596. "<td><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\">"
  2597. "<tr>"
  2598. "<td align=\"center\">Enter the IP address:<br><i>(example: 127.0.0.1)</i></td>"
  2599. "</tr>"
  2600. "<tr>"
  2601. "<td align=\"center\">"
  2602. "<input name=\"mode\" value=\"ripip\" type=\"hidden\">"
  2603. "<input name=\"sid\" value=\"" + tos(sid) + "\" type=\"hidden\">"
  2604. "<input name=\"ip1\" size=\"3\" maxlength=\"3\">."
  2605. "<input name=\"ip2\" size=\"3\" maxlength=\"3\">."
  2606. "<input name=\"ip3\" size=\"3\" maxlength=\"3\">."
  2607. "<input name=\"ip4\" size=\"3\" maxlength=\"3\">"
  2608. "</td>"
  2609. "</tr>"
  2610. "<tr>"
  2611. "<td colspan=\"2\" align=\"center\"><input class=\"submit\" type=\"submit\" value=\"Reserve IP\">"
  2612. "&nbsp;<input class=\"submit\" value=\"Clear\" type=\"Reset\"></td>"
  2613. "</tr>"
  2614. "</table>"
  2615. "</td>"
  2616. "</tr>"
  2617. "</table>"
  2618. "</td>"
  2619. "<td style=\"padding: 0 1em 0 0;\"><br>"
  2620. "<table class=\"ent\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" align=\"left\">"
  2621. "<tr class=\"ent\">"
  2622. "<td class=\"inp\" align=\"center\">Reserve Connection Slot by Host</td>"
  2623. "</tr>"
  2624. "<form method=\"url\" action=\"admin.cgi\">"
  2625. "<tr>"
  2626. "<td><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\">"
  2627. "<tr>"
  2628. "<td align=\"center\">Enter the hostname:<br><i>(example: my.example.com)</i></td>"
  2629. "</tr>"
  2630. "<tr>"
  2631. "<td align=\"center\">"
  2632. "<input name=\"mode\" value=\"ripip\" type=\"hidden\">"
  2633. "<input name=\"sid\" value=\"" + tos(sid) + "\" type=\"hidden\">"
  2634. "<input name=\"ripdstraw\" size=\"30\" maxlength=\"256\">"
  2635. "</td>"
  2636. "</tr>"
  2637. "<tr>"
  2638. "<td colspan=\"2\" align=\"center\"><input class=\"submit\" type=\"submit\" value=\"Reserve Host\">"
  2639. "&nbsp;<input class=\"submit\" value=\"Clear\" type=\"Reset\"></td>"
  2640. "</tr>"
  2641. "</table>"
  2642. "</td>"
  2643. "</tr>"
  2644. "</table>"
  2645. "</td>"
  2646. "</tr>"
  2647. "</form>"
  2648. "</table>" +
  2649. getUptimeScript() +
  2650. getfooterStr();
  2651. COMPRESS(header, body);
  2652. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  2653. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  2654. }
  2655. // show ban lists
  2656. void protocol_admincgi::mode_viewban(const streamData::streamID_t sid) throw()
  2657. {
  2658. vector<banList::ban_t> ban_list;
  2659. g_banList.get(ban_list,((gOptions.read_stream_banFile(sid) && !gOptions.stream_banFile(sid).empty()) ? sid : 0));
  2660. utf8 header = MSG_NO_CLOSE_200,
  2661. headerTitle = (!sid ? "Server Ban List" : "Stream Ban List"),
  2662. body = (!sid ? getServerAdminHeader(headerTitle) : getStreamAdminHeader(sid, headerTitle)) +
  2663. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"top\"><td>";
  2664. if (ban_list.empty())
  2665. {
  2666. body += "<b>&nbsp;No Banned Entries</b><br>";
  2667. }
  2668. else
  2669. {
  2670. body += "<b>&nbsp;Ban Entry List:</b><ol>";
  2671. for (vector<banList::ban_t>::const_iterator i = ban_list.begin(); i != ban_list.end(); ++i)
  2672. {
  2673. body += "<li><b>" + aolxml::escapeXML((*i).m_numericIP) + "</b>" +
  2674. (!(*i).m_comment.empty() ? " : <b>" + aolxml::escapeXML((*i).m_comment) + "</b>" : "") +
  2675. " - " + ((*i).m_mask == 255 ? "Single&nbsp;IP" : "Subnet") + "&nbsp;ban&nbsp;-&nbsp;"
  2676. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=unbandst&amp;bandst=" +
  2677. urlUtils::escapeURI_RFC3986((*i).m_numericIP) + "&amp;banmsk=" + tos((*i).m_mask) + "\">remove</a>";
  2678. }
  2679. body += "</ol>";
  2680. }
  2681. body +=
  2682. "</td><td style=\"padding:0 1em 0 1em;\"><br>"
  2683. "<table class=\"ent\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" align=\"right\">"
  2684. "<tr class=\"ent\">"
  2685. "<td class=\"inp\" align=\"center\">Ban a Single IP</td>"
  2686. "</tr>"
  2687. "<form method=\"url\" action=\"admin.cgi\">"
  2688. "<tr>"
  2689. "<td><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\">"
  2690. "<tr>"
  2691. "<td align=\"center\">Enter&nbsp;the&nbsp;IP&nbsp;address:<br><i>(example: 127.0.0.1)</i></td>"
  2692. "</tr>"
  2693. "<tr>"
  2694. "<td align=\"center\">"
  2695. "<input name=\"mode\" value=\"banip\" type=\"hidden\">"
  2696. "<input name=\"sid\" value=\"" + tos(sid) + "\" type=\"hidden\">"
  2697. "<input name=\"ip1\" size=\"3\" maxlength=\"3\">."
  2698. "<input name=\"ip2\" size=\"3\" maxlength=\"3\">."
  2699. "<input name=\"ip3\" size=\"3\" maxlength=\"3\">."
  2700. "<input name=\"ip4\" size=\"3\" maxlength=\"3\">"
  2701. "<input type=\"hidden\" name=\"banmsk\" value=\"255\"></td>"
  2702. "</tr>"
  2703. "<tr>"
  2704. "<td colspan=\"2\" align=\"center\"><input class=\"submit\" type=\"submit\" value=\"Ban Single IP\">"
  2705. "&nbsp;<input class=\"submit\" value=\"Clear\" type=\"Reset\"></td>"
  2706. "</tr>"
  2707. "</table>"
  2708. "</td>"
  2709. "</tr>"
  2710. "</form>"
  2711. "</table>"
  2712. "</td>"
  2713. "<td style=\"padding: 0 1em 0 0;\"><br>"
  2714. "<table class=\"ent\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" align=\"left\">"
  2715. "<tr class=\"ent\">"
  2716. "<td class=\"inp\" align=\"center\">Ban an Entire Subnet</td>"
  2717. "</tr>"
  2718. "<form method=\"url\" action=\"admin.cgi\">"
  2719. "<tr>"
  2720. "<td><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\">"
  2721. "<tr>"
  2722. "<td align=\"center\">Enter the Subnet address:<br><i>(example: 255.255.255)</i></td>"
  2723. "</tr>"
  2724. "<tr>"
  2725. "<td align=\"center\">"
  2726. "<input name=\"mode\" value=\"banip\" type=\"hidden\">"
  2727. "<input name=\"sid\" value=\"" + tos(sid) + "\" type=\"hidden\">"
  2728. "<input name=\"ip1\" size=\"1\" maxlength=\"3\">."
  2729. "<input name=\"ip2\" size=\"1\" maxlength=\"3\">."
  2730. "<input name=\"ip3\" size=\"1\" maxlength=\"3\">.0-255"
  2731. "<input name=\"ip4\" value=\"0\" type=\"hidden\">"
  2732. "<input type=\"hidden\" name=\"banmsk\" value=\"0\"></td>"
  2733. "</tr>"
  2734. "<tr>"
  2735. "<td colspan=\"2\" align=\"center\"><input class=\"submit\" type=\"submit\" value=\"Ban Whole Subnet\">"
  2736. "&nbsp;<input class=\"submit\" value=\"Clear\" type=\"Reset\"></td>"
  2737. "</tr>"
  2738. "</table>"
  2739. "</td>"
  2740. "</tr>"
  2741. "</table>"
  2742. "</td>"
  2743. "</tr>"
  2744. "</form>"
  2745. "</table>" +
  2746. getUptimeScript() +
  2747. getIEFlexFix() +
  2748. getfooterStr();
  2749. COMPRESS(header, body);
  2750. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  2751. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  2752. }
  2753. // remove an IP and mask from the ban list
  2754. void protocol_admincgi::mode_unban(const streamData::streamID_t sid, const utf8 &banAddr, const int banMask) throw()
  2755. {
  2756. utf8 msg;
  2757. try
  2758. {
  2759. const size_t stream_ID = ((gOptions.read_stream_banFile(sid) && !gOptions.stream_banFile(sid).empty()) ? sid : 0);
  2760. if (isAddress(banAddr))
  2761. {
  2762. if (g_banList.remove(banAddr,banMask,stream_ID,false))
  2763. {
  2764. ILOG("[BAN] Removed `" + banAddr + "/" + tos(banMask) + "' from " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " ban list");
  2765. if (gOptions.saveBanListOnExit())
  2766. {
  2767. if (stream_ID && gOptions.read_stream_banFile(stream_ID) && !gOptions.stream_banFile(stream_ID).empty())
  2768. {
  2769. g_banList.save(gOptions.stream_banFile(stream_ID),stream_ID);
  2770. }
  2771. else
  2772. {
  2773. g_banList.save(gOptions.banFile(),0);
  2774. }
  2775. }
  2776. }
  2777. else
  2778. {
  2779. ILOG("[BAN] Unable to remove `" + banAddr + "' from " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " ban list");
  2780. }
  2781. }
  2782. else
  2783. {
  2784. ILOG("[BAN] `" + banAddr + "' is not a valid value. Skipping removing from the " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " ban list");
  2785. }
  2786. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer == "admin.cgi?sid=" + tos(sid) ? "" : "&mode=viewban"), SHRINK) : MSG_200);
  2787. }
  2788. catch(const exception &ex)
  2789. {
  2790. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer != utf8("admin.cgi?sid=" + tos(sid) + "&mode=viewban") ? "" : "&mode=viewban"), SHRINK) : MSG_200);
  2791. ELOG(ex.what());
  2792. }
  2793. sendMessageAndClose(msg);
  2794. }
  2795. // add an IP and mask to the ban list
  2796. void protocol_admincgi::mode_ban(const streamData::streamID_t sid, const utf8 &banAddrs, const int banMask) throw()
  2797. {
  2798. utf8 msg;
  2799. try
  2800. {
  2801. const size_t stream_ID = ((gOptions.read_stream_banFile(sid) && !gOptions.stream_banFile(sid).empty()) ? sid : 0);
  2802. if (!g_banList.find(banAddrs,banMask,stream_ID))
  2803. {
  2804. g_banList.add(banAddrs,banMask,"",stream_ID);
  2805. ILOG("[BAN] Added `" + banAddrs + "/" + tos(banMask) + "' to " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " ban list");
  2806. if (gOptions.saveBanListOnExit())
  2807. {
  2808. if (stream_ID && gOptions.read_stream_banFile(stream_ID) && !gOptions.stream_banFile(stream_ID).empty())
  2809. {
  2810. g_banList.save(gOptions.stream_banFile(stream_ID),stream_ID);
  2811. }
  2812. else
  2813. {
  2814. g_banList.save(gOptions.banFile(),0);
  2815. }
  2816. }
  2817. }
  2818. else
  2819. {
  2820. ILOG("[BAN] `" + banAddrs + "' already in the " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " ban list");
  2821. }
  2822. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer == "admin.cgi?sid=" + tos(sid) ? "" : "&mode=viewban"), SHRINK) : MSG_200);
  2823. }
  2824. catch(const exception &ex)
  2825. {
  2826. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer != utf8("admin.cgi?sid=" + tos(sid) + "&mode=viewban") ? "" : "&mode=viewban"), SHRINK) : MSG_200);
  2827. ELOG(ex.what());
  2828. }
  2829. // additionally when a ban happens then we attempt to kick the client(s) at the same time
  2830. const utf8 &p1 = mapGet(m_httpRequestInfo.m_QueryParameters, "kickdst", (utf8)"");
  2831. if (!p1.empty())
  2832. {
  2833. // split out multiple clients to kick (split by a ,)
  2834. std::vector<uniString::utf8> addrs = tokenizer(p1, ',');
  2835. for (vector<uniString::utf8>::const_iterator i = addrs.begin(); i != addrs.end(); ++i)
  2836. {
  2837. if ((*i).find(utf8(".")) == utf8::npos)
  2838. {
  2839. stats::kickClient(sid, atoi((*i).hideAsString().c_str()));
  2840. }
  2841. else
  2842. {
  2843. stats::kickClient(sid, (*i));
  2844. }
  2845. }
  2846. }
  2847. sendMessageAndClose(msg);
  2848. }
  2849. // remove an agent from the agent list
  2850. void protocol_admincgi::mode_unagent(const streamData::streamID_t sid, const utf8 &agent) throw()
  2851. {
  2852. utf8 msg;
  2853. try
  2854. {
  2855. const size_t stream_ID = ((gOptions.read_stream_agentFile(sid) && !gOptions.stream_agentFile(sid).empty()) ? sid : 0);
  2856. bool ret = g_agentList.remove(agent,stream_ID,false);
  2857. if (!ret && !agent.empty())
  2858. {
  2859. ret = g_agentList.remove(agent,stream_ID,false);
  2860. }
  2861. if (ret)
  2862. {
  2863. ILOG("[AGENT] Removed `" + agent + "' from " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " user agent list");
  2864. if (gOptions.saveAgentListOnExit())
  2865. {
  2866. if (stream_ID && gOptions.read_stream_agentFile(stream_ID) && !gOptions.stream_agentFile(stream_ID).empty())
  2867. {
  2868. g_agentList.save(gOptions.stream_agentFile(stream_ID),stream_ID);
  2869. }
  2870. else
  2871. {
  2872. g_agentList.save(gOptions.agentFile(),0);
  2873. }
  2874. }
  2875. }
  2876. else
  2877. {
  2878. ILOG("[AGENT] Unable to remove `" + agent + "' from " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " user agent list");
  2879. }
  2880. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer == "admin.cgi?sid=" + tos(sid) ? "" : "&mode=viewagent"), SHRINK) : MSG_200);
  2881. }
  2882. catch(const exception &ex)
  2883. {
  2884. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer != utf8("admin.cgi?sid=" + tos(sid) + "&mode=viewagent") ? "" : "&mode=viewagent"), SHRINK) : MSG_200);
  2885. ELOG(ex.what());
  2886. }
  2887. sendMessageAndClose(msg);
  2888. }
  2889. // add an IP / hostname to the user agent list
  2890. void protocol_admincgi::mode_agent(const streamData::streamID_t sid, const utf8 &agent) throw()
  2891. {
  2892. utf8 msg;
  2893. try
  2894. {
  2895. const size_t stream_ID = ((gOptions.read_stream_agentFile(sid) && !gOptions.stream_agentFile(sid).empty()) ? sid : 0);
  2896. if (!g_agentList.find(agent,stream_ID))
  2897. {
  2898. if (g_agentList.add(agent, stream_ID, true))
  2899. {
  2900. ILOG("[AGENT] Added `" + agent + "' to " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " user agent list");
  2901. }
  2902. stats::kickClientList_t kick_data;
  2903. stats::getClientDataForKicking(stream_ID, kick_data);
  2904. for (stats::kickClientList_t::const_iterator i = kick_data.begin(); i != kick_data.end(); ++i)
  2905. {
  2906. if (!(*i)->m_kicked && ((*i)->m_userAgent == agent))
  2907. {
  2908. stats::kickClient(sid, (*i)->m_unique);
  2909. }
  2910. delete (*i);
  2911. }
  2912. if (gOptions.saveAgentListOnExit())
  2913. {
  2914. if (stream_ID && gOptions.read_stream_agentFile(stream_ID) && !gOptions.stream_agentFile(stream_ID).empty())
  2915. {
  2916. g_agentList.save(gOptions.stream_agentFile(stream_ID),stream_ID);
  2917. }
  2918. else
  2919. {
  2920. g_agentList.save(gOptions.agentFile(),0);
  2921. }
  2922. }
  2923. }
  2924. else
  2925. {
  2926. ILOG("[AGENT] `" + agent + "' already in the " + (!stream_ID ? "global" : "sid=" + tos(stream_ID)) + " user agent list");
  2927. }
  2928. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer == "admin.cgi?sid=" + tos(sid) ? "" : "&mode=viewagent"), SHRINK) : MSG_200);
  2929. }
  2930. catch(const exception &ex)
  2931. {
  2932. msg = (!m_referer.empty() ? redirect("admin.cgi?sid=" + tos(sid) + (m_referer != utf8("admin.cgi?sid=" + tos(sid) + "&mode=viewagent") ? "" : "&mode=viewagent"), SHRINK) : MSG_200);
  2933. ELOG(ex.what());
  2934. }
  2935. sendMessageAndClose(msg);
  2936. }
  2937. // show agent list
  2938. void protocol_admincgi::mode_viewagent(const streamData::streamID_t sid) throw()
  2939. {
  2940. vector<agentList::agent_t> agent_list;
  2941. g_agentList.get(agent_list,((gOptions.read_stream_agentFile(sid) && !gOptions.stream_agentFile(sid).empty()) ? sid : 0));
  2942. utf8 header = MSG_NO_CLOSE_200,
  2943. headerTitle = (!sid ? "Server Blocked User Agent List" :
  2944. "Stream Blocked User Agent List"),
  2945. body = (!sid ? getServerAdminHeader(headerTitle, 0, "", 2) : getStreamAdminHeader(sid, headerTitle, 0, true)) +
  2946. "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"top\"><td>";
  2947. if (agent_list.empty())
  2948. {
  2949. body += "<b>&nbsp;No Blocked User Agents</b><br>";
  2950. }
  2951. else
  2952. {
  2953. body += "<b>&nbsp;Blocked User Agent List:</b><ol>";
  2954. for (vector<agentList::agent_t>::const_iterator i = agent_list.begin(); i != agent_list.end(); ++i)
  2955. {
  2956. const streamData::source_t clientType = ((streamData::source_t)streamData::UNKNOWN);
  2957. body += "<li>" + getClientImage(streamData::getClientType(clientType, stringUtil::toLower((*i).m_agent))) +
  2958. " <b>" + aolxml::escapeXML((*i).m_agent) + "</b> - <a href=\"admin.cgi?sid=" + tos(sid) +
  2959. "&amp;mode=unagent&amp;agent=" + urlUtils::escapeURI_RFC3986((*i).m_agent) + "\">remove</a>";
  2960. }
  2961. body += "</ol>";
  2962. }
  2963. body +=
  2964. "</td>"
  2965. "<td style=\"padding: 0 1em 0 0;\"><br>"
  2966. "<table class=\"ent\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" align=\"left\">"
  2967. "<tr class=\"ent\">"
  2968. "<td class=\"inp\" align=\"center\">Block User Agent</td>"
  2969. "</tr>"
  2970. "<form method=\"url\" action=\"admin.cgi\">"
  2971. "<tr>"
  2972. "<td><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\">"
  2973. "<tr>"
  2974. "<td align=\"center\">Enter the user agent:<br><i>(example: streamripper)</i></td>"
  2975. "</tr>"
  2976. "<tr>"
  2977. "<td align=\"center\">"
  2978. "<input name=\"mode\" value=\"agent\" type=\"hidden\">"
  2979. "<input name=\"sid\" value=\"" + tos(sid) + "\" type=\"hidden\">"
  2980. "<input name=\"agent\" size=\"30\" maxlength=\"256\">"
  2981. "</td>"
  2982. "</tr>"
  2983. "<tr>"
  2984. "<td colspan=\"2\" align=\"center\"><input class=\"submit\" type=\"submit\" value=\"Block User Agent\">"
  2985. "&nbsp;<input class=\"submit\" value=\"Clear\" type=\"Reset\"></td>"
  2986. "</tr>"
  2987. "</table>"
  2988. "</td>"
  2989. "</tr>"
  2990. "</table>"
  2991. "</td>"
  2992. "</tr>"
  2993. "</form>"
  2994. "</table>" +
  2995. getUptimeScript() +
  2996. getIEFlexFix() +
  2997. getfooterStr();
  2998. COMPRESS(header, body);
  2999. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  3000. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  3001. }
  3002. // kick client(s)
  3003. void protocol_admincgi::mode_kickdst(const streamData::streamID_t sid, const utf8 &kickAddrs) throw()
  3004. {
  3005. bool refresh = false;
  3006. if (kickAddrs == "all")
  3007. {
  3008. // check if this is set to kick all
  3009. refresh = stats::kickAllClients(sid);
  3010. }
  3011. else if (kickAddrs == "duplicates")
  3012. {
  3013. // check if this is set to kick all
  3014. // duplicates (doing oldest first).
  3015. refresh = stats::kickDuplicateClients(sid);
  3016. }
  3017. else
  3018. {
  3019. // split out multiple clients to kick (split by a ,)
  3020. std::vector<uniString::utf8> addrs = tokenizer(kickAddrs,',');
  3021. for (vector<uniString::utf8>::const_iterator i = addrs.begin(); i != addrs.end(); ++i)
  3022. {
  3023. if ((*i).find(utf8(".")) == utf8::npos)
  3024. {
  3025. stats::kickClient(sid, atoi((*i).hideAsString().c_str()));
  3026. }
  3027. else
  3028. {
  3029. stats::kickClient(sid,(*i));
  3030. }
  3031. }
  3032. }
  3033. if (!m_referer.empty())
  3034. {
  3035. const utf8 check = ("admin.cgi?sid=" + tos(sid));
  3036. // if the referer is the server summary page then we need to go back to it
  3037. sendMessageAndClose(redirect((m_referer == check ? check : "admin.cgi?sid=0") + (refresh ? "&refresh=1" : ""), SHRINK));
  3038. }
  3039. else
  3040. {
  3041. sendMessageAndClose(MSG_200);
  3042. }
  3043. }
  3044. void protocol_admincgi::mode_art(const streamData::streamID_t sid, const int mode) throw()
  3045. {
  3046. utf8 header = "HTTP/1.1 200 OK\r\n", body;
  3047. streamData *sd = streamData::accessStream(sid);
  3048. if (sd)
  3049. {
  3050. vector<__uint8> sc21_albumart = (mode == 0 ? sd->streamAlbumArt() : sd->streamPlayingAlbumArt());
  3051. if (!sc21_albumart.empty())
  3052. {
  3053. utf8 mimeType[] = {
  3054. "image/jpeg",
  3055. "image/png",
  3056. "image/bmp",
  3057. "image/gif"
  3058. };
  3059. const size_t mime = (mode == 0 ? sd->streamAlbumArtMime() : sd->streamPlayingAlbumArtMime());
  3060. // if not in the valid range then don't report the mime type in the generated response
  3061. if (mime < 4)
  3062. {
  3063. header += "Content-Type:" + mimeType[mime] + "\r\n";
  3064. }
  3065. body += utf8(&sc21_albumart[0],sc21_albumart.size());
  3066. }
  3067. sd->releaseStream();
  3068. }
  3069. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  3070. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  3071. }
  3072. void protocol_admincgi::mode_register(const streamData::streamID_t sid, const streamData::streamInfo &info) throw()
  3073. {
  3074. // construct a temp id for this action
  3075. utf8 tempId = "";
  3076. randomId(tempId);
  3077. bool loaded = false;
  3078. streamData *sd = streamData::accessStream(sid);
  3079. if (sd)
  3080. {
  3081. int addFailIgnore = 0, errorCode = 0;
  3082. loaded = sd->YP2_addSuccessful(addFailIgnore, errorCode);
  3083. sd->releaseStream();
  3084. }
  3085. utf8 header = "HTTP/1.1 200 OK\r\n"
  3086. "Content-Type:text/html;charset=utf-8\r\n"
  3087. "Cache-Control:no-cache\r\n",
  3088. authhash = (!info.m_authHash.empty() ? info.m_authHash.substr(0, 36) : (utf8)""),
  3089. body = getStreamAdminHeader(sid, "Stream Authhash") + "<br>"
  3090. "<form id=\"processing\" method=\"GET\" autocomplete=\"off\" onsubmit=\"return validateForm();\">"
  3091. "<div style=\"display:table;width:100%;\">"
  3092. "<div style=\"padding:0 1em;display:inline-block;float:left;max-width:15em;\">"
  3093. "<table class=\"ent\" cellpadding=\"15px\"><tr><td valign=\"top\">"
  3094. "<div align=\"center\" class=\"infh\"><b>Information</b></div><div id=\"info\">"
  3095. "This page allows you to enter or amend the authhash to be used for this stream."
  3096. "<br><br><hr><br>Authhash information is now managed online. "
  3097. "<a target=\"blank\" href=\"https://radiomanager.shoutcast.com\"><b>Login</b></a> "
  3098. "to create an authhash or update the details of an existing authhash."
  3099. "<br><br><hr><br>The same authhash should be used for all stream instances of a station "
  3100. "(e.g. 128kbps MP3 and 64kbps AAC streams for 'Super Awesome Radio').<br><br>This also includes all DNAS "
  3101. "providing the stream(s) for a station to ensure the correct listing of all stream instances."
  3102. // TODO need to have a link to the account page...
  3103. "<br><br><hr><br>If you remove an authhash by mistake then you can either recover it from your "
  3104. "<a href=\"https://radiomanager.shoutcast.com\" target=\"_blank\"><b>Shoutcast account</b></a> or you will need "
  3105. "to contact <a href=\"mailto:support@shoutcast.com?subject=Shoutcast%20Support\"><b>support</b></a> directly for "
  3106. "assistance.</div></td></tr></table><br></div>"
  3107. // TODO need to consider customising some of this ?? or just above ??
  3108. "<div align=\"left\" id=\"page_info\" style=\"display:inline-block;max-width:25em;padding:0 1em;\">"
  3109. "<div align=\"left\" id=\"header\"></div>"
  3110. "<table id=\"details\" style=\"width:100%;\" align=\"left\" border=\"0\">"
  3111. "<tr id=\"hide\" valign=\"top\"><td colspan=\"2\">" + utf8(!authhash.empty() &&
  3112. loaded && (info.m_streamSampleRate > 0) && info.m_radionomyID.empty() ?
  3113. warningImage(false) + "&nbsp;&nbsp;<b>Please Register Your Authhash</b><br><br>" : "") +
  3114. "<div style=\"float:right;padding:0 1em;\">"
  3115. "<input style=\"white-space:normal;width:6em;\" id=\"register\" class=\"submit\" type=\"button\" "
  3116. "onclick=\"window.open('https://radiomanager.shoutcast.com','_blank','')\" value=\"" +
  3117. (!authhash.empty() ? "Manage Authhash\"></div>"
  3118. "The authhash currently configured for this stream is <b>" + authhash + "</b><br><br><br>"
  3119. "To change the authhash, enter it below and click 'Save'." :
  3120. "Create Authhash\"></div>"
  3121. "An authhash needs to be created for this stream.<br><br><br>"
  3122. "If you have just created an authhash via your "
  3123. "<a target=\"blank\" href=\"https://radiomanager.shoutcast.com\"><b>account</b></a> "
  3124. "or have an existing one for the stream, please enter it below and click 'Save'.") +
  3125. "<br><br></td></tr>"
  3126. "<tr id=\"hide\">"
  3127. "<td style=\"width:25%;\" align=\"right\">Authhash:</td>"
  3128. "<td colspan=\"2\"><input type=\"text\" style=\"width:15em;\" name=\"authhash\" id=\"authhash\" maxlength=\"36\" value=\"" + authhash + "\"></td>"
  3129. "</tr>"
  3130. "<tr>"
  3131. "<td id=\"status\" align=\"center\" colspan=\"3\"><br>"
  3132. "<input id=\"submit\" class=\"submit\" type=\"submit\" value=\"Save\">&nbsp;&nbsp;"
  3133. "<input id=\"clear\" class=\"submit\" value=\"Clear\" type=\"button\" "
  3134. "onclick=\"if(confirm('Clear the authhash and save the change now?"
  3135. "\\n\\nChoose Cancel to just clear the field.')){window.location='admin.cgi?sid=" + tos(sid) +
  3136. "&amp;mode=register&amp;register=clear';}else{$('authhash').value = '';authhashChange();}\">&nbsp;&nbsp;"
  3137. "<input class=\"submit\" value=\"Cancel\" type=\"button\" onclick=\"window.location='admin.cgi?sid=" + tos(sid) + "';\"></td>"
  3138. "</tr>"
  3139. "</table>"
  3140. "</div>"
  3141. "</div>"
  3142. "</form>"
  3143. "<script type=\"text/javascript\">"
  3144. "var original = \"" + /*(((mode == 3) && (auth_enabled != 1)) ?*/ info.m_authHash.substr(0, 36) /*: (utf8)"")*/ + "\";" EL
  3145. "var timeout, response;" EL
  3146. "function $(id){return document.getElementById(id);}" EL
  3147. "function trimString(str){return str.replace(/^\\s+|\\s+$/g,'');}" EL
  3148. + utf8(!authhash.empty() ?
  3149. "function changeExisting(){" EL
  3150. "if($('existing').value != \"select\"){" EL
  3151. "$('authhash').value = $('existing').value;" EL
  3152. "}" EL
  3153. "authhashChange();" EL
  3154. "}" EL
  3155. : "")
  3156. +
  3157. "function getHTTP(){" EL
  3158. "if(window.XDomainRequest){" EL
  3159. "return new XDomainRequest();" EL
  3160. "}else if(window.XMLHttpRequest){" EL
  3161. "return new XMLHttpRequest();" EL
  3162. "}else{" EL
  3163. "return new ActiveXObject(\"Microsoft.XMLHTTP\");" EL
  3164. "}" EL
  3165. "}" EL
  3166. "function isValidAuthhash(str){" EL
  3167. "var regexp = /^[-a-fA-F\\d]+$/;" EL
  3168. "if(str != ''){" EL
  3169. "return regexp.test(str);" EL
  3170. "}" EL
  3171. "return true;" EL
  3172. "}" EL
  3173. "function authhashChange(){" EL
  3174. "var str = trimString($('authhash').value);" EL
  3175. "var valid = isValidAuthhash(str);" EL
  3176. "$('authhash').style.borderColor = (!(str.length == 0 || str.length > 36 && valid)?\"red\":\"\");" EL
  3177. "$('submit').disabled = (!((str.length == 0 || str.length == 36) && (original != $('authhash').value) && valid));" EL
  3178. "}" EL
  3179. "function validateForm(){" EL
  3180. "while($('hide') != null){" EL
  3181. "$('hide').style.display = \"none\";" EL
  3182. "$('hide').removeAttribute(\"id\");" EL
  3183. "}" EL
  3184. "$('status').setAttribute(\"colspan\",\"3\");" EL
  3185. "$('status').setAttribute(\"align\",\"left\");" EL
  3186. "$('status').setAttribute(\"valign\",\"middle\");" EL
  3187. "$('status').innerHTML = \"</td><td><b>Processing</b><br><br>This may take a while.</td>\";" EL
  3188. "var f = $('processing');" EL
  3189. "var params=\"\";" EL
  3190. "for(var i = 0; i < f.elements.length; i++ ){" EL
  3191. "if(f.elements[i].name != \"\"){" EL
  3192. "if(f.elements[i].name != \"private\" || (f.elements[i].name == \"private\" && f.elements[i].value == \"1\")){" EL
  3193. "params += (i != 0 ? \"&\" : \"\") + f.elements[i].name + \"=\" + encodeURIComponent(f.elements[i].value);" EL
  3194. "}" EL
  3195. "}" EL
  3196. "}" EL
  3197. "if(params==\"\"){" EL
  3198. "$('status').setAttribute(\"colspan\",\"3\");" EL
  3199. "$('status').setAttribute(\"align\",\"center\");" EL
  3200. "$('status').setAttribute(\"valign\",\"middle\");" EL
  3201. "$('status').innerHTML=\"Critical error in processing request."
  3202. "<br><br><b><a href=\\\"admin.cgi?sid=" + tos(sid) + "\\\">Click here to return to the Server Summary.</a></b>\";"
  3203. "return false;"
  3204. "}" EL
  3205. "var xmlhttp = getHTTP();" EL
  3206. "xmlhttp.open(\"GET\",\"admin.cgi?sid=" + tos(sid) + "&pass=" + gOptions.adminPassword() +
  3207. "&mode=manualauthhash&tempid=" + tempId + "&\"+params,true);" EL
  3208. "if(window.XDomainRequest){" EL
  3209. "xmlhttp.onerror=xmlhttp.onload=function(){" EL
  3210. "var code = parseInt((xmlhttp.responseText!=\"\"?xmlhttp.responseText:\"200\"));" EL
  3211. "if(code!=200){" EL
  3212. "clearInterval(timeout);" EL
  3213. "$('status').setAttribute(\"align\",\"center\");" EL
  3214. "$('status').setAttribute(\"colspan\",\"2\");" EL
  3215. "if(code==0){" EL
  3216. "$('status').innerHTML = \"</td><td>"
  3217. "<b><br>Error Code: \"+code+\".<br>Check the DNAS is running and there is a working network connection.<br>"
  3218. "<br><a href=\\\"admin.cgi?sid=" + tos(sid) + "\\\">Click here to return to the Server Summary.</a></b>"
  3219. "</td>\";" EL
  3220. "}else{" EL
  3221. "$('status').innerHTML = \"</td><td>"
  3222. "<b><br>Error Code: \"+code+\".<br>\"+xmlhttp.responseText.substring(5,xmlhttp.responseText.length)+\"<br>"
  3223. "<br><a href=\\\"admin.cgi?sid=" + tos(sid) + "\\\">Click here to return to the Server Summary.</a></b>"
  3224. "</td>\";" EL
  3225. "}" EL
  3226. "}else{" EL
  3227. "clearInterval(timeout);" EL
  3228. "$('status').setAttribute(\"align\",\"center\");" EL
  3229. "$('status').innerHTML = \"</td><td>"
  3230. "Authhash was changed and saved to the configuration file. The stream will now be updated with the change.<br>"
  3231. "<br><a href=\\\"admin.cgi?sid=" + tos(sid) + "\\\"><b>Click here to return to the stream summary.</b></a></td>\";" EL
  3232. "}" EL
  3233. "};" EL
  3234. "}else{" EL
  3235. "xmlhttp.onreadystatechange=function(){" EL
  3236. "if(xmlhttp.readyState==4){" EL
  3237. "var code = parseInt((xmlhttp.responseText!=\"\"?xmlhttp.responseText:\"200\"));" EL
  3238. "if(code!=200){" EL
  3239. "clearInterval(timeout);" EL
  3240. "$('status').setAttribute(\"align\",\"center\");" EL
  3241. "$('status').setAttribute(\"colspan\",\"2\");" EL
  3242. "if(code==0){" EL
  3243. "$('status').innerHTML = \"</td><td>"
  3244. "<b><br>Error Code: \"+code+\".<br>Check the DNAS is running and there is a working network connection.<br>"
  3245. "<br><a href=\\\"admin.cgi?sid=" + tos(sid) + "\\\">Click here to return to the Server Summary.</a></b>"
  3246. "</td>\";" EL
  3247. "}else{" EL
  3248. "$('status').innerHTML = \"</td><td>"
  3249. "<b><br>Error Code: \"+code+\".<br>\"+xmlhttp.responseText.substring(5,xmlhttp.responseText.length)+\"<br>"
  3250. "<br><a href=\\\"admin.cgi?sid=" + tos(sid) + "\\\">Click here to return to the Server Summary.</a></b>"
  3251. "</td>\";" EL
  3252. "}" EL
  3253. "}" EL
  3254. "}else{" EL
  3255. "clearInterval(timeout);" EL
  3256. "$('status').setAttribute(\"align\",\"center\");" EL
  3257. "$('status').innerHTML = \"</td><td>"
  3258. "Authhash was changed and saved to the configuration file. The stream will now be updated with the change.<br>"
  3259. "<br><a href=\\\"admin.cgi?sid=" + tos(sid) + "\\\"><b>Click here to return to the stream summary.</b></a></td>\";" EL
  3260. "}" EL
  3261. "};" EL
  3262. "}" EL
  3263. "xmlhttp.send(null);" EL
  3264. "timeout = setInterval(countDown,250);" EL
  3265. "return false;" EL
  3266. "}" EL
  3267. "var counter=0;" EL
  3268. "function countDown(){" EL
  3269. "counter++;" EL
  3270. "if(counter>=5){" EL
  3271. "counter=0;" EL
  3272. "}" EL
  3273. "if(counter<5){" EL
  3274. "$('status').setAttribute(\"colspan\",\"3\");" EL
  3275. "$('status').setAttribute(\"align\",\"left\");" EL
  3276. "$('status').setAttribute(\"valign\",\"middle\");" EL
  3277. "$('status').innerHTML = \"<b>Processing\"+Array(counter).join(\".\")+\"</b><br><br>This may take a while.\";" EL
  3278. "}" EL
  3279. "}" EL
  3280. "function runUrlGetError(){" EL
  3281. "}" EL
  3282. "function runUrlGet(urlString,callback){" EL
  3283. "var xmlhttp = getHTTP();" EL
  3284. "try{" EL
  3285. "xmlhttp.open(\"GET\",(urlString==document.location?urlString:\"http://" +
  3286. gOptions.ypAddr() + ":" + tos(gOptions.ypPort()) +
  3287. ((gOptions.ypPath() != utf8("/yp2")) ? "/yp" : "") +
  3288. "/\"+urlString),true);" EL
  3289. "if(window.XDomainRequest){" EL
  3290. "xmlhttp.onload=callback;" EL
  3291. "xmlhttp.onerror=runUrlGetError;" EL
  3292. "}else{" EL
  3293. "xmlhttp.onreadystatechange=callback;" EL
  3294. "}" EL
  3295. "response=xmlhttp;" EL
  3296. "xmlhttp.send(null);" EL
  3297. "}" EL
  3298. "catch(e){" EL
  3299. "}" EL
  3300. "}" EL
  3301. "function getAuthInfo(){" EL
  3302. "if(response.readyState == null || response.readyState==4 && response.status==200){" EL
  3303. "$('header').innerHTML = response.responseText;" EL
  3304. "}" EL
  3305. "}" EL
  3306. "var registerOnWindowLoad = function(callback){" EL
  3307. "if(window.addEventListener){" EL
  3308. "window.addEventListener('load',callback,false);" EL
  3309. "}else{" EL
  3310. "window.attachEvent('onload',callback);" EL
  3311. "}" EL
  3312. "}" EL
  3313. "registerOnWindowLoad(function(){" EL
  3314. "runUrlGet(\"authinfo_" + (authhash.empty() ? "create" : "update") +
  3315. "?v=" + urlUtils::escapeURI_RFC3986(gOptions.getVersionBuildStrings()) +
  3316. "&os=" + urlUtils::escapeURI_RFC3986(SERV_OSNAME) + "\",getAuthInfo);" EL
  3317. "if($('existing')!=null){" EL
  3318. "$('existing').onkeyup=changeExisting;" EL
  3319. "$('existing').onchange=changeExisting;" EL
  3320. "}" EL
  3321. "if($('authhash')!=null){" EL
  3322. "$('authhash').onkeyup=authhashChange;" EL
  3323. "$('authhash').onchange=authhashChange;" EL
  3324. "}" EL
  3325. "authhashChange();" EL
  3326. "});" EL
  3327. "</script>" +
  3328. getUptimeScript() +
  3329. getIEFlexFix() +
  3330. getfooterStr();
  3331. COMPRESS(header, body);
  3332. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  3333. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  3334. }
  3335. void protocol_admincgi::mode_listeners(const streamData::streamID_t sid) throw()
  3336. {
  3337. utf8 header = MSG_NO_CLOSE_200, body;
  3338. // just to make sure we came from an appropriate page
  3339. const utf8 &server = mapGet(m_httpRequestInfo.m_QueryParameters, "server", (utf8)""),
  3340. &check = ("admin.cgi?sid=" + tos(sid));
  3341. const bool nowrap = mapGet(m_httpRequestInfo.m_QueryParameters, "nw", (bool)gOptions.adminNoWrap());
  3342. const int fh = mapGet(m_httpRequestInfo.m_QueryParameters, "fh", (int)0);
  3343. if ((sid > 0) && (m_referer.find(check) == 0) && !server.empty() && (listenerId == server))
  3344. {
  3345. stats::currentClientList_t client_data;
  3346. stats::getClientDataForStream(sid, client_data);
  3347. if (!client_data.empty())
  3348. {
  3349. streamData::streamInfo info;
  3350. streamData::extraInfo extra;
  3351. streamData::getStreamInfo(sid, info, extra);
  3352. stats::statsData_t data;
  3353. stats::getStats(sid, data);
  3354. utf8 clientsBody = "<div style=\"overflow:auto;" + (!fh ? "max-height:500px;" : (utf8)"") + "\">"
  3355. "<table class=\"ls\" style=\"border:0;text-align:center;" +
  3356. (nowrap ? "white-space:nowrap;" : "") + "\" "
  3357. "cellpadding=\"5\" cellspacing=\"0\" width=\"100%\" align=\"center\">"
  3358. "<col width=\"15%\"><col width=\"50%\"><col width=\"20%\">"
  3359. "<tr><td colspan=\"10\" class=\"inp\">Current Listeners</td></tr>"
  3360. "<tr class=\"tll\"><td>Listener Address<br>(Host Address)</td>"
  3361. "<td>User Agent</td><td>Connected<br>Duration</td>" + utf8(!info.m_radionomyID.empty() ?
  3362. "<td>" + baseImage("adavail", "Advert Status", false, false) + "</td>" : "") +
  3363. (data.connectedListeners != data.uniqueListeners ? "<td>Kick<br>Client</td>" : (utf8)"") +
  3364. "<td>Kick<br>IP</td><td>Ban<br>IP</td><td>Ban<br>Subnet</td>"
  3365. "<td>Reserve<br>Listener</td><td>Block<br>User Agent</td></tr>";
  3366. const time_t t = ::time(NULL);
  3367. size_t rowCount = 0;
  3368. // if we have non-unique clients then we need to process the list differently so as to group
  3369. // them together and then re-sort the output by client listener duration on the first match
  3370. // otherwise we revert the code back to the original un-grouped method to not waste resources
  3371. if (data.connectedListeners != data.uniqueListeners)
  3372. {
  3373. map<utf8,stats::uniqueClientData_t> unique_clients;
  3374. for (stats::currentClientList_t::const_iterator i = client_data.begin(); i != client_data.end(); ++i)
  3375. {
  3376. // if set to kicked then no need to show those (since they may re-appear if in-progress)
  3377. if (!(*i)->m_kicked)
  3378. {
  3379. stats::uniqueClientData_t client;
  3380. const bool localhost = ((*i)->m_ipAddr.find(utf8("127.")) == 0);
  3381. // look for existing instances and append the new details to the existing details
  3382. const map<utf8,stats::uniqueClientData_t>::const_iterator im = unique_clients.find((*i)->m_ipAddr);
  3383. if (im != unique_clients.end())
  3384. {
  3385. client = (*im).second;
  3386. client.m_userAgent += "</tr><tr" + ((*i)->m_ripClient || localhost ? utf8(" style=\"font-style:italic;\"") : "") + ">";
  3387. client.m_unique += ",";
  3388. ++client.m_total;
  3389. }
  3390. else
  3391. {
  3392. client.m_connectTime = (*i)->m_startTime;
  3393. client.m_ipAddr = (*i)->m_ipAddr;
  3394. client.m_hostName = (*i)->m_hostName;
  3395. client.m_XFF = (*i)->m_XFF;
  3396. client.m_total = 1;
  3397. }
  3398. const int slave = ((*i)->m_clientType & streamData::SC_CDN_SLAVE);
  3399. client.m_userAgent += "<td " + (!client.m_XFF.empty() ? "title=\"XFF: " + aolxml::escapeXML(client.m_XFF) +
  3400. "\" " : "") + "style=\"" + (!nowrap ? "" : "white-space:nowrap;") + "\"" +
  3401. utf8(slave ? " class=\"thr\"" : "") + ">" + (((*i)->m_clientType & streamData::RADIONOMY) ?
  3402. "Radionomy Stats Collector" : (!nowrap ? addWBR((*i)->m_userAgent) : "<div style=\"float:left;\">" +
  3403. aolxml::escapeXML((*i)->m_userAgent)) + "</div>") + " <div style=\"float:right;\">" +
  3404. getClientImage((*i)->m_clientType) + "</div></td>";
  3405. if ((*i)->m_ripClient)
  3406. {
  3407. client.m_ripAddr = true;
  3408. }
  3409. const time_t connected = (t - (*i)->m_startTime);
  3410. utf8 timer = timeString(connected, true), timerTip;
  3411. if (timer.empty())
  3412. {
  3413. timer = "Starting...";
  3414. }
  3415. else
  3416. {
  3417. timerTip = timeString(connected);
  3418. }
  3419. client.m_userAgent += "<td" + utf8(slave ? " class=\"thr\"" : "") + " title=\"" +
  3420. timerTip + "\">" + aolxml::escapeXML(timer) + "</td>";
  3421. client.m_unique = (*i)->m_ipAddr;
  3422. if (!info.m_radionomyID.empty())
  3423. {
  3424. client.m_userAgent += "<td" + utf8(slave ? " class=\"thr\"" : "") + ">" + (((*i)->m_group > 0) ||
  3425. (*i)->m_triggers ? advertImage(sid, (*i)->m_group, (*i)->m_triggers) :
  3426. "<div title=\"Not Recognised For Adverts\">N/A</div>") + "</td>";
  3427. }
  3428. client.m_userAgent += "<td^" + utf8(slave ? " class=\"thr\"" : "") + "><a href=\"admin.cgi?sid=" +
  3429. tos(sid) + "&amp;mode=kickdst&amp;kickdst=" + tos((*i)->m_unique) + "\">Kick</a>" +
  3430. (client.m_total == 1 ? "</td^>" : "</td>") + "<td" + utf8(slave ? " class=\"thr\"" : "") +
  3431. ">" + ((*i)->m_userAgent.empty() || ((*i)->m_userAgent == EMPTY_AGENT) ? "N/A" :
  3432. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=agent&amp;agent=" +
  3433. urlUtils::escapeURI_RFC3986((*i)->m_userAgent) + "\">Block</a>") + "</td>";
  3434. unique_clients[(*i)->m_ipAddr] = client;
  3435. }
  3436. delete (*i);
  3437. }
  3438. // take the map and convert to a vector so we can then re-sort the list back into longest to least duration
  3439. vector<stats::uniqueClientData_t> clients;
  3440. for (map<utf8,stats::uniqueClientData_t>::const_iterator i = unique_clients.begin(); i != unique_clients.end(); ++i)
  3441. {
  3442. clients.push_back((*i).second);
  3443. }
  3444. std::sort(clients.begin(), clients.end(), sortUniqueClientDataByTime);
  3445. // and now we dump the generated list
  3446. for (vector<stats::uniqueClientData_t>::const_iterator i = clients.begin(); i != clients.end(); ++i)
  3447. {
  3448. const utf8 host = ((*i).m_hostName != (*i).m_ipAddr ? aolxml::escapeXML((*i).m_hostName) + " (" + (*i).m_ipAddr + ")" : (*i).m_ipAddr);
  3449. const bool localhost = ((*i).m_ipAddr.find(utf8("127.")) == 0);
  3450. // if we have a multiple client block then re-process so the relevant parts can
  3451. // be listed individually with adjustment of some of the visual styles as needed
  3452. utf8 multiBlock = (*i).m_userAgent;
  3453. uniString::utf8::size_type tpos = multiBlock.find(utf8("<td^"));
  3454. if (tpos != uniString::utf8::npos)
  3455. {
  3456. while (tpos != uniString::utf8::npos)
  3457. {
  3458. multiBlock.replace(tpos, 4, utf8(((*i).m_total > 1 ? "<td" : "<td colspan=\"2\"")));
  3459. tpos = multiBlock.find(utf8("<td^"));
  3460. }
  3461. }
  3462. tpos = multiBlock.find(utf8("</td^>"));
  3463. if (tpos != uniString::utf8::npos)
  3464. {
  3465. const bool hasHostName = ((*i).m_hostName != (*i).m_ipAddr);
  3466. utf8 endBlock = "<td" + ((*i).m_total > 1 ? " rowspan=\"" + tos((*i).m_total) + "\"" : (utf8)"") + ">" +
  3467. (!localhost ? "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=bandst&amp;bandst=" +
  3468. urlUtils::escapeURI_RFC3986((*i).m_ipAddr) + "&amp;banmsk=255" + "&amp;kickdst=" +
  3469. (*i).m_unique + "\">Ban</a>" : "N/A") + "</td><td" + ((*i).m_total > 1 ? " rowspan=\"" +
  3470. tos((*i).m_total) + "\"" : (utf8)"") + ">" + (!localhost ? "<a href=\"admin.cgi?sid=" +
  3471. tos(sid) + "&amp;mode=bandst&amp;bandst=" + urlUtils::escapeURI_RFC3986((*i).m_ipAddr) +
  3472. "&amp;banmsk=0" + "&amp;kickdst=" + (*i).m_unique + "\">Ban </a>" : "N/A") + "</td>"
  3473. "<td" + ((*i).m_total > 1 ? " rowspan=\"" + tos((*i).m_total) + "\"" : (utf8)"") + ">" +
  3474. (!localhost ? "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=" +
  3475. ((*i).m_ripAddr ? "unripdst" : "ripdst") + "&amp;ripdst=" +
  3476. urlUtils::escapeURI_RFC3986((hasHostName ? (*i).m_hostName : (*i).m_ipAddr)) +
  3477. (hasHostName ? "&amp;ripdstraw=" + urlUtils::escapeURI_RFC3986((*i).m_ipAddr) : "") +
  3478. "\">" + ((*i).m_ripAddr ? "Remove" : "Add") + "</a>" : "N/A") + "</td>";
  3479. multiBlock.replace(tpos, 6, utf8(((*i).m_total > 1 ?
  3480. "</td><td rowspan=\"" + tos((*i).m_total) +
  3481. "\"><a href=\"admin.cgi?sid=" + tos(sid) +
  3482. "&amp;mode=kickdst&amp;kickdst=" +
  3483. (*i).m_unique + "\">Kick</a></td>" +
  3484. endBlock : "</td>" + endBlock)));
  3485. }
  3486. rowCount += (*i).m_total;
  3487. clientsBody += "<tr" + ((*i).m_ripAddr || localhost ? utf8(" style=\"font-style:italic;\"") : "") + ">"
  3488. "<td" + ((*i).m_total > 1 ? " rowspan=\"" + tos((*i).m_total) + "\"" : "") + ">" +
  3489. (gOptions.useXFF() && !(*i).m_XFF.empty() ? xffImage() + " " : "") + host + "</td>" + multiBlock;
  3490. }
  3491. }
  3492. else
  3493. {
  3494. for (stats::currentClientList_t::const_iterator i = client_data.begin(); i != client_data.end(); ++i)
  3495. {
  3496. // if set to kicked then no need to show those (since they may re-appear if in-progress)
  3497. if (!(*i)->m_kicked)
  3498. {
  3499. const time_t connected = (::time(NULL) - (*i)->m_startTime);
  3500. utf8 timer = timeString(connected, true), timerTip;
  3501. if (timer.empty())
  3502. {
  3503. timer = "Starting...";
  3504. }
  3505. else
  3506. {
  3507. timerTip = timeString(connected);
  3508. }
  3509. const utf8 host = ((*i)->m_hostName != (*i)->m_ipAddr ? aolxml::escapeXML((*i)->m_hostName) +
  3510. " (" + (*i)->m_ipAddr + ")" : (*i)->m_ipAddr);
  3511. const bool localhost = ((*i)->m_ipAddr.find(utf8("127.")) == 0);
  3512. const bool hasHostName = ((*i)->m_hostName != (*i)->m_ipAddr);
  3513. ++rowCount;
  3514. const int slave = ((*i)->m_clientType & streamData::SC_CDN_SLAVE);
  3515. clientsBody += "<tr" + ((*i)->m_ripClient || localhost ? utf8(" style=\"font-style:italic;\"") : "") + ">"
  3516. "<td " + (gOptions.useXFF() && !(*i)->m_XFF.empty() ? "title=\"XFF: " +
  3517. aolxml::escapeXML((*i)->m_XFF) + "\">" + xffImage() + " " : ">") + host + "</td><td " +
  3518. (!(*i)->m_XFF.empty() ? "title=\"XFF: " + aolxml::escapeXML((*i)->m_XFF) + "\" " : "") +
  3519. "style=\"" + (!nowrap ? "" : "white-space:nowrap;") + "\"" + utf8(slave ? " class=\"thr\"" :
  3520. "") + ">" + (((*i)->m_clientType & streamData::RADIONOMY) ? "Radionomy Stats Collector" :
  3521. (!nowrap ? addWBR((*i)->m_userAgent) : "<div style=\"float:left;\">" +
  3522. aolxml::escapeXML((*i)->m_userAgent)) + "</div>") + " <div style=\"float:right;\">" +
  3523. getClientImage((*i)->m_clientType) + "</div>" + "</td><td" + utf8(slave ? " class=\"thr\"" : "") +
  3524. " title=\"" + timerTip + "\">" + aolxml::escapeXML(timer) + "</td>";
  3525. if (!info.m_radionomyID.empty())
  3526. {
  3527. clientsBody += "<td" + utf8(slave ? " class=\"thr\"" : "") + ">" + (((*i)->m_group > 0) ||
  3528. (*i)->m_triggers ? advertImage(sid, (*i)->m_group, (*i)->m_triggers) :
  3529. "<div title=\"Not Recognised For Adverts\">N/A</div>") + "</td>";
  3530. }
  3531. const utf8 unique = tos((*i)->m_unique);
  3532. clientsBody += "<td" + utf8(slave ? " class=\"thr\"" : "") + "><a href=\"admin.cgi?sid=" +
  3533. tos(sid) + "&amp;mode=kickdst&amp;kickdst=" + unique + "\">Kick</a></td><td>" +
  3534. (!localhost ? "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=bandst&amp;bandst=" +
  3535. urlUtils::escapeURI_RFC3986((*i)->m_ipAddr) + "&amp;banmsk=255" + "&amp;kickdst=" + unique +
  3536. "\">Ban</a>" : "N/A") + "</td><td>" + (!localhost ? "<a href=\"admin.cgi?sid=" + tos(sid) +
  3537. "&amp;mode=bandst&amp;bandst=" + urlUtils::escapeURI_RFC3986((*i)->m_ipAddr) + "&amp;banmsk=0"
  3538. "&amp;kickdst=" + unique + "\">Ban </a>" : "N/A") + "</td><td>" + (!localhost ?
  3539. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=" + ((*i)->m_ripClient ?
  3540. "unripdst" : "ripdst") + "&amp;ripdst=" + urlUtils::escapeURI_RFC3986((hasHostName ?
  3541. (*i)->m_hostName : (*i)->m_ipAddr)) + (hasHostName ? "&amp;ripdstraw=" +
  3542. urlUtils::escapeURI_RFC3986((*i)->m_ipAddr) : "") + "\">" + ((*i)->m_ripClient ?
  3543. "Remove" : "Add") + "</a>" : "N/A") + "</td><td" + utf8(slave ? " class=\"thr\"" : "") +
  3544. ">" + ((*i)->m_userAgent.empty() || ((*i)->m_userAgent == EMPTY_AGENT) ? "N/A" :
  3545. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=agent&amp;agent=" +
  3546. urlUtils::escapeURI_RFC3986((*i)->m_userAgent) + "\">Block</a>") + "</td></tr>";
  3547. }
  3548. delete (*i);
  3549. }
  3550. }
  3551. if (rowCount > 0)
  3552. {
  3553. if (rowCount > 1)
  3554. {
  3555. clientsBody += "<tr><td style=\"border:0;\"></td><td style=\"padding:0;\"><a href=\"admin.cgi?sid=" +
  3556. tos(sid) + "&amp;mode=kickdst&amp;kickdst=duplicates\" title=\"Kick all duplicate "
  3557. "listeners (based on oldest first by user-agent for the same address)\"><b>Kick Duplicates</b>"
  3558. "</a></td><td>" + timeString(data.avgUserListenTime, true) + "</td><td style=\"padding:0;\" "
  3559. "colspan=\"" + utf8(data.connectedListeners != data.uniqueListeners ? "4" : "3") +
  3560. "\"><a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=kickdst&amp;kickdst=all\" "
  3561. "title=\"Kick all currently connected listeners\"><b>Kick All</b></a></td></tr>";
  3562. }
  3563. // only output the table if we actually had clients to show
  3564. body += clientsBody + "</table></div>";
  3565. }
  3566. }
  3567. }
  3568. else
  3569. {
  3570. body = "<div style=\"padding:1em;text-align:center;\"><b><img "
  3571. "border=\"0\" src=\"images/warn.png\"> The current "
  3572. "listener list could not be loaded. <img border=\"0\" "
  3573. "src=\"images/warn.png\"><br><a href=\"admin.cgi?sid=" +
  3574. tos(sid) + "&nw=" + tos(nowrap) + "&fh=" + tos(fh) +
  3575. "\">Click here to reload this page</a>. If this issue "
  3576. "<br>persists, try logging out and back in again.</b></div>";
  3577. }
  3578. COMPRESS(header, body);
  3579. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  3580. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  3581. }
  3582. const utf8 protocol_admincgi::getClientIP(const bool streamPublic, const utf8 &publicIP) throw()
  3583. {
  3584. // test for potentially invalid IPs or ones that will cause the playlist link generation to fail
  3585. // attempting to use the server path provided by the YP if in public mode, otherwise uses 'host'
  3586. return (!streamPublic || publicIP.empty() ?
  3587. ((g_IPAddressForClients.find(utf8("0.")) == 0 ||
  3588. // allow localhost / loopback connections through for admin access
  3589. ((!g_IPAddressForClients.empty() && g_IPAddressForClients.find(utf8("127.")) == 0)) ||
  3590. g_IPAddressForClients.empty()) && !m_hostIP.empty() ?
  3591. m_hostIP : (!m_hostIP.empty() ? m_hostIP : g_IPAddressForClients)) : publicIP);
  3592. }
  3593. void protocol_admincgi::mode_none(const streamData::streamID_t sid, const int refreshRequired) throw()
  3594. {
  3595. utf8 header = MSG_NO_CLOSE_200,
  3596. body = getStreamAdminHeader(sid, "Stream Status &amp; Listeners", refreshRequired);
  3597. time_t streamUptime = 0;
  3598. bool hasListeners = false, isConnected = false;
  3599. if (refreshRequired > 0)
  3600. {
  3601. body += "<br><table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"100%\">"
  3602. "<tr><td align=\"center\" id=\"counter\">"
  3603. "<br>Waiting " + tos(refreshRequired) + " second" + ((refreshRequired > 1) ? "s" : (utf8)"") +
  3604. " for any configuration changes to take effect.<br>"
  3605. "If not automatically redirected or do not want to wait, "
  3606. "<a href=\"admin.cgi?sid="+tos(sid)+"\">click here.</a>"
  3607. "<br><br></td></tr></table></tr></table></td></tr></table>";
  3608. }
  3609. else
  3610. {
  3611. streamData::streamInfo info;
  3612. streamData::extraInfo extra;
  3613. streamData::getStreamInfo(sid, info, extra);
  3614. stats::statsData_t data;
  3615. stats::getStats(sid, data);
  3616. isConnected = extra.isConnected;
  3617. hasListeners = (data.connectedListeners > 0);
  3618. // this is a placeholder for the listener details which we grab asynchronously for speed since #615
  3619. body += "<div id=\"listeners\">" + (data.connectedListeners > 0 ?
  3620. "<div style=\"padding:1em;text-align:center;\"><b>Loading current "
  3621. "listener list...</b></div>" : (utf8)"") + "</div><table cellpadding=\"5\" "
  3622. "cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"tsp\" "
  3623. "align=\"center\">Current Stream Information</td></tr></table>";
  3624. utf8 detailsBody = "";
  3625. bool showing = false;
  3626. if (!(gOptions.read_stream_adminPassword(sid) && !gOptions.stream_adminPassword(sid).empty()))
  3627. {
  3628. utf8 log = gOptions.realLogFile();
  3629. utf8::size_type pos = log.rfind(fileUtil::getFilePathDelimiter());
  3630. if ((pos != utf8::npos))
  3631. {
  3632. log = log.substr(pos + 1);
  3633. }
  3634. utf8 conf = gOptions.confFile();
  3635. pos = conf.rfind(fileUtil::getFilePathDelimiter());
  3636. if ((pos != utf8::npos))
  3637. {
  3638. conf = conf.substr(pos + 1);
  3639. }
  3640. // trim down the file paths shown to make things less cluttered on hosted setups
  3641. // places the full path in the 'title' so it can still be found if required, etc
  3642. detailsBody += "Log file: <b title=\"" +
  3643. aolxml::escapeXML(fileUtil::getFullFilePath(gOptions.realLogFile())) +
  3644. "\">" + aolxml::escapeXML(fileUtil::stripPath(log)) + "</b><br>"
  3645. "Configuration file: <b title=\"" +
  3646. aolxml::escapeXML(fileUtil::getFullFilePath(gOptions.confFile())) +
  3647. "\">" + aolxml::escapeXML(fileUtil::stripPath(conf)) + "</b><br>";
  3648. showing = true;
  3649. }
  3650. utf8 introFile = gOptions.stream_introFile(sid);
  3651. if (!gOptions.read_stream_introFile(sid))
  3652. {
  3653. introFile = gOptions.introFile();
  3654. }
  3655. utf8 backupFile = gOptions.stream_backupFile(sid);
  3656. if (!gOptions.read_stream_backupFile(sid))
  3657. {
  3658. backupFile = gOptions.backupFile();
  3659. }
  3660. utf8 backupTitle = gOptions.stream_backupTitle(sid);
  3661. if (!gOptions.read_stream_backupTitle(sid))
  3662. {
  3663. backupTitle = gOptions.backupTitle();
  3664. }
  3665. streamData *sd = streamData::accessStream(sid);
  3666. detailsBody += utf8(showing ? "<br><hr><br>" : "") + "Intro file is <b title=\"" +
  3667. ((!introFile.empty() || (sd && sd->getIntroFile().gotData()) ? (!introFile.empty() ?
  3668. fileUtil::getFullFilePath(introFile) : (utf8)"") : (utf8)"") + "\">" +
  3669. aolxml::escapeXML((!introFile.empty() || (sd && sd->getIntroFile().gotData()) ? (!introFile.empty() ?
  3670. fileUtil::stripPath(introFile) : "from source") : "empty")) + "</b><br>Backup file is <b title=\"" +
  3671. ((!backupFile.empty() || (sd && sd->getBackupFile().gotData())) ? (!backupFile.empty() ?
  3672. fileUtil::getFullFilePath(backupFile) : (utf8)"") : (utf8)"") + "\">" +
  3673. aolxml::escapeXML((!backupFile.empty() || (sd && sd->getBackupFile().gotData())) ?
  3674. (!backupFile.empty() ? fileUtil::stripPath(backupFile) : "from source") : "empty")) + "</b><br>";
  3675. if (!backupTitle.empty() && !backupFile.empty() && !extra.isConnected)
  3676. {
  3677. detailsBody += "Backup title is: <b>" + aolxml::escapeXML(backupTitle) + "</b><br>";
  3678. }
  3679. detailsBody += "<br><hr><br>Idle timeouts are <b>" + tos(gOptions.getAutoDumpTime(sid)) + "s</b><br>";
  3680. if (extra.isConnected)
  3681. {
  3682. detailsBody += "<br><hr><br>Source connection type: <b>" +
  3683. utf8(info.m_sourceType == streamData::SHOUTCAST1 ? "v1" :
  3684. (info.m_sourceType == streamData::SHOUTCAST2 ? "v2" : "HTTP")) +
  3685. (extra.isRelay ? " relay" + (extra.isBackup ? utf8("&nbsp;backup") : "") :
  3686. (extra.isBackup ? utf8("&nbsp;backup") : "")) + "</b><br><div "
  3687. "style=\"max-width:15em;\">Source user agent: <b>" +
  3688. addWBR((!info.m_sourceIdent.empty() ? info.m_sourceIdent :
  3689. "Legacy / Unknown")) + "</b>""</div>";
  3690. }
  3691. if (sd)
  3692. {
  3693. detailsBody += (extra.isConnected ? "<br><hr><br>" : "<br>");
  3694. if (sd->streamAlbumArt().empty())
  3695. {
  3696. detailsBody += "Stream artwork <b>not available</b>";
  3697. }
  3698. else
  3699. {
  3700. detailsBody += "Stream artwork <b>available</b> [&nbsp;<a href=\"/streamart?sid=" + tos(sid) + "\">view</a>&nbsp;]</b>";
  3701. }
  3702. detailsBody += "<br>";
  3703. if (sd->streamPlayingAlbumArt().empty())
  3704. {
  3705. detailsBody += "Playing artwork <b>not available</b>";
  3706. }
  3707. else
  3708. {
  3709. detailsBody += "Playing artwork <b>available</b> [&nbsp;<a href=\"/playingart?sid=" + tos(sid) + "\">view</a>&nbsp;]</b>";
  3710. }
  3711. if (!info.m_currentURL.empty() && (info.m_currentURL.find(utf8("DNAS/")) == utf8::npos))
  3712. {
  3713. detailsBody += "<br><br><hr><br>Song url from source [&nbsp;<a href=\"" +
  3714. utf8((info.m_currentURL.find(utf8("://")) == utf8::npos) &&
  3715. (info.m_currentURL.find(utf8("&")) != 0) ? "//" : "") +
  3716. info.m_currentURL + "\">view</a>&nbsp;]<br>"
  3717. "<div style=\"max-width:15em;\"><b>Note:</b> "
  3718. "This may not be a valid url and is intended for internal use.</div>";
  3719. }
  3720. sd->releaseStream();
  3721. }
  3722. const utf8& message = streamData::getStreamMessage(sid);
  3723. if (!message.empty())
  3724. {
  3725. detailsBody += "<tr><td style=\"border:0;padding:0;\"><br></td></tr>"
  3726. "<tr><td align=\"center\" valign=\"top\" "
  3727. "style=\"display:block;max-width:15em;padding-top:1px;\"><br>"
  3728. "<div align=\"center\" class=\"infh\">"
  3729. "<b>Official Message Received</b></div>" + message + "</td></tr>";
  3730. }
  3731. body += "<div style=\"padding:0 1em;\"><br></div>"
  3732. "<table width=\"100%\" align=\"center\"><tr valign=\"top\">";
  3733. const utf8 movedUrl = gOptions.stream_movedUrl(sid);
  3734. if (movedUrl.empty())
  3735. {
  3736. body += "<td><table class=\"en\" cellpadding=\"15px\" "
  3737. "style=\"border:0;margin-left:1em;\"><tr>"
  3738. "<td valign=\"top\"><div align=\"center\" "
  3739. "class=\"infh\"><b>Stream Details</b></div>" +
  3740. detailsBody + "</td></tr></table></td>";
  3741. }
  3742. const int maxUsers = ((info.m_streamMaxUser > 0) && (info.m_streamMaxUser < gOptions.maxUser()) ? info.m_streamMaxUser : gOptions.maxUser());
  3743. if (extra.isConnected)
  3744. {
  3745. const bool isListable = streamData::isAllowedType(info.m_uvoxDataType);
  3746. utf8 listenLink = "<a href=\"listen.pls?sid=" + tos(sid) + "\"><img border=\"0\" title=\"Listen to Stream\" "
  3747. "alt=\"Listen to Stream\" style=\"vertical-align:middle\" src=\"images/listen.png\"></a>" +
  3748. (sd && !sd->radionomyID().empty() && sd->streamAdvertMode() ?
  3749. "<img border=\"0\" title=\"Active DNAS+ Stream\nMonetisation Enabled\" "
  3750. "alt=\"Active DNAS+ Stream\nMonetisation Enabled\" style=\"vertical-align:middle\" "
  3751. "src=\"images/adavail.png\">&nbsp;" : (utf8)"");
  3752. body += "<td><table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" style=\"padding-left:1em;\">"
  3753. "<tr valign=\"top\"><td colspan=\"2\">" + getNewVersionMessage() + "<td></tr>"
  3754. "<tr valign=\"top\"><td>Listing Status: </td><td><b>Stream is currently up " +
  3755. (info.m_streamPublic && isListable ? (extra.ypConnected != 1 ? "" : utf8("and public") + listenLink) : utf8("and private (not listed)") + listenLink) +
  3756. (info.m_streamPublic && isListable ? (extra.ypConnected != 1 ? (!yp2::isValidAuthhash(info.m_authHash) ?
  3757. string(info.m_authHash.empty() ? "but requires <a href=\"admin.cgi?sid=" + tos(sid) +
  3758. "&amp;mode=register\">registration</a> in the Shoutcast Directory.<br>" :
  3759. "but not listed due to an invalid authhash.<br>") +
  3760. (info.m_authHash.empty() ? "Listeners are allowed and the stream will act like it is private until resolved."
  3761. "<br><br>To create an authhash you will need to <a href=\"admin.cgi?sid=" + tos(sid) +
  3762. "&amp;mode=register\">register</a> the stream with us.<br>If you already have an existing authhash "
  3763. "then you can enter it <a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">here</a>.<br><br>" :
  3764. "Listeners are allowed and the stream will act like it is private until resolved.") :
  3765. (extra.ypErrorCode == 200 ? "waiting on a Directory response." :
  3766. (extra.ypErrorCode == YP_COMMS_FAILURE ? "unable to access the Directory.<br>Listeners are allowed and the stream will act like it is private until resolved." :
  3767. (extra.ypErrorCode == YP_MAINTENANCE_CODE ? "received a Directory maintenance notification: <a target=\"_blank\" href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2#YP_Server_Errors\">" + tos(extra.ypErrorCode) +
  3768. "</a><br>Listeners will be allowed though the stream will not be listed in the Directory." :
  3769. "received Directory error code: <a target=\"_blank\" href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2#YP_Server_Errors\">" + tos(extra.ypErrorCode) + "</a><br>" +
  3770. (extra.ypConnected != 2 ? "" :
  3771. "during a listing update. The stream may no longer appear.") +
  3772. "<br>Check the server log and / or contact the server administrator.")))) : "") : "") + "</b></td></tr>"
  3773. "<tr valign=\"top\"><td>Stream Status: </td>"
  3774. "<td><b>Stream is up (" + streamData::getContentType(info) + " @ " +
  3775. (info.m_streamBitrate > 0 ? tos(info.m_streamBitrate) : "unknown") +
  3776. " kbps" + (info.m_vbr ? " (VBR)" : "") + ", " +
  3777. sampleRateStr(info.m_streamSampleRate) + ") with " +
  3778. tos(data.connectedListeners) + (maxUsers > 0 ? " of " +
  3779. tos(maxUsers) : "") + " listeners" + (!maxUsers ? " (unlimited)" : "") +
  3780. (data.connectedListeners != data.uniqueListeners ? (" (" +
  3781. tos(data.uniqueListeners) + " unique)") : "") + "</b></td></tr>";
  3782. if (data.peakListeners > 0)
  3783. {
  3784. body += "<tr valign=\"top\"><td>Listener Peak: </td><td><b>" +
  3785. tos(data.peakListeners) + "</b></td></tr>";
  3786. }
  3787. const utf8 avgTime = timeString(data.avgUserListenTime);
  3788. if (!avgTime.empty())
  3789. {
  3790. body += "<tr valign=\"top\"><td>Avg. Play Time: </td>"
  3791. "<td><b>" + avgTime + "</b></td></tr>";
  3792. }
  3793. body += "<tr valign=\"top\"><td>Stream Name: </td><td><b>" +
  3794. (info.m_streamPublic && extra.ypConnected ? "<a target=\"_blank\" href=\"http://directory.shoutcast.com/Search?query=" +
  3795. urlUtils::escapeURI_RFC3986(info.m_streamName) + "\">" + aolxml::escapeXML(info.m_streamName) + "</a>" :
  3796. aolxml::escapeXML(info.m_streamName)) + "</b></td></tr>" +
  3797. (info.m_streamPublic && extra.ypConnected ? "<tr valign=\"top\"><td alt=\"Shoutcast Directory ID\" "
  3798. "title=\"Shoutcast Directory ID\"><img border=\"0\" "
  3799. "src=\"images/favicon.ico\" style=\"vertical-align:bottom\">"
  3800. " ID: </td><td><b><a title=\"Shoutcast Directory ID\" href=\"http://" +
  3801. gOptions.ypAddr().hideAsString() + ":" + tos(gOptions.ypPort()) + ((gOptions.ypPath() != utf8("/yp2")) ? "/yp" : "") +
  3802. "/sbin/tunein-station.pls?id="+info.m_stationID+"\">"+info.m_stationID+"</a></b></td></tr>" : "");
  3803. if (!info.m_streamGenre[0].empty())
  3804. {
  3805. body += "<tr valign=\"top\"><td>Stream Genre(s): </td>"
  3806. "<td><b>" + (info.m_streamPublic && extra.ypConnected ?
  3807. "<a target=\"_blank\" href=\"http://directory.shoutcast.com/Genre?name=" +
  3808. urlUtils::escapeURI_RFC3986(info.m_streamGenre[0]) + "\">" +
  3809. aolxml::escapeXML(info.m_streamGenre[0]) + "</a>" :
  3810. aolxml::escapeXML(info.m_streamGenre[0])) + "</b>";
  3811. for (int i = 1; i < 5; i++)
  3812. {
  3813. if (!info.m_streamGenre[i].empty())
  3814. {
  3815. body += " , <b>" + (info.m_streamPublic && extra.ypConnected ? "<a target=\"_blank\" href=\"http://directory.shoutcast.com/Genre?name=" +
  3816. urlUtils::escapeURI_RFC3986(info.m_streamGenre[i]) + "\">" + aolxml::escapeXML(info.m_streamGenre[i]) + "</a>" :
  3817. aolxml::escapeXML(info.m_streamGenre[i])) + "</b>";
  3818. }
  3819. }
  3820. body += "</td></tr>";
  3821. }
  3822. if (!info.m_streamUser.empty())
  3823. {
  3824. body += "<tr valign=\"top\"><td>Stream DJ: </td>"
  3825. "<td><b>" + aolxml::escapeXML(info.m_streamUser) + "</b></td></tr>";
  3826. }
  3827. if (!info.m_streamURL.empty())
  3828. {
  3829. body += "<tr valign=\"top\"><td>Stream Website: </td>"
  3830. "<td><b>" + urlLink(info.m_streamURL) + "</b></td></tr>";
  3831. }
  3832. if (!info.m_currentSong.empty())
  3833. {
  3834. body += "<tr valign=\"top\"><td>Playing Now: </td>"
  3835. "<td><b><a href=\"currentsong?sid=" + tos(sid) + "\">" +
  3836. getCurrentSong(info.m_currentSong) + "</a></b></td></tr>";
  3837. // only show if we have a valid current song
  3838. if (!info.m_comingSoon.empty())
  3839. {
  3840. body += "<tr valign=\"top\"><td>Playing Next: </td>"
  3841. "<td><b><a href=\"nextsong?sid=" + tos(sid) + "\">" +
  3842. aolxml::escapeXML(info.m_comingSoon) + "</a></b></td></tr>";
  3843. }
  3844. }
  3845. // strip down the source address for display output to an appropriate output based on settings
  3846. utf8 srcAddr = niceURL(extra.isBackup ? info.m_backupURL : (extra.isRelay ? info.m_relayURL : info.m_srcAddr));
  3847. if (gOptions.nameLookups())
  3848. {
  3849. if (!extra.isBackup && !extra.isRelay)
  3850. {
  3851. u_short port = 0;
  3852. string addr, hostName;
  3853. socketOps::getpeername(m_socket, addr, port);
  3854. string src = (extra.isBackup ? info.m_backupURL : (extra.isRelay ? info.m_relayURL : info.m_srcAddr)).hideAsString();
  3855. hostName = src;
  3856. if (!socketOps::addressToHostName(addr,port,hostName))
  3857. {
  3858. srcAddr = hostName + " (" + niceURL(src) + ")";
  3859. }
  3860. }
  3861. }
  3862. body += "<tr valign=\"top\"><td>Stream Source: </td>"
  3863. "<td><b>" + (extra.isRelay || extra.isBackup ? urlLink(srcAddr) : srcAddr) + " " +
  3864. (extra.isRelay ? "(relaying" + (extra.isBackup ? utf8(" backup") : "") + ") " : (extra.isBackup ? "(backup) " : "")) + "</b>"
  3865. "[&nbsp;<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=kicksrc\">" + (extra.isRelay || extra.isBackup ? "stop" : "kick") +
  3866. "</a>&nbsp;]</td></tr><tr valign=\"top\"><td>Stream Uptime: </td>"
  3867. "<td id=\"up2\"><b>" + timeString((streamUptime = ::time(NULL) - streamData::getStreamUptime(sid))) + "</b></td></tr>";
  3868. if (!info.m_contentType.empty() && (info.m_uvoxDataType == MP3_DATA))
  3869. {
  3870. body += streamData::getHTML5Player(sid);
  3871. }
  3872. body += "</table>";
  3873. }
  3874. else
  3875. {
  3876. body += "<td" + (movedUrl.empty() ? (utf8)"" : " align=\"center\"") + ">"
  3877. "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\">"
  3878. "<tr valign=\"top\"><td colspan=\"2\">" + getNewVersionMessage("<br>") + "<td></tr>"
  3879. "<tr valign=\"top\"><td>Stream Status: </td><td><b>";
  3880. if (movedUrl.empty())
  3881. {
  3882. body += "Stream is currently down" + (data.connectedListeners > 0 ?
  3883. " with " + tos(data.connectedListeners) + (maxUsers > 0 ? " of " +
  3884. tos(maxUsers) : "") + " listeners" + (!maxUsers ? " (unlimited)" : "") +
  3885. (data.connectedListeners != data.uniqueListeners ? (" (" +
  3886. tos(data.uniqueListeners) + " unique)") : "") : ".") + "<br>There is no "
  3887. "source connected or no stream is configured for stream #" + tos(sid) + ".";
  3888. }
  3889. else
  3890. {
  3891. body += "Stream has been moved to " + urlLink(movedUrl) + "<br>No source connections will be allowed for this stream.";
  3892. }
  3893. body += "</b></td></tr>";
  3894. if (data.peakListeners > 0)
  3895. {
  3896. body += "<tr valign=\"top\"><td>Listener Peak: </td><td><b>" +
  3897. tos(data.peakListeners) + "</b></td></tr>";
  3898. }
  3899. utf8 avgTime = timeString(data.avgUserListenTime);
  3900. if (!avgTime.empty())
  3901. {
  3902. body += "<tr valign=\"top\"><td>Avg. Play Time: </td>"
  3903. "<td><b>" + avgTime + "</b></td></tr>";
  3904. }
  3905. // add in an option to restart a relay url...
  3906. if (!gOptions.stream_relayURL(sid).empty() && movedUrl.empty())
  3907. {
  3908. // strip down the source address for display output
  3909. utf8 srcAddr = niceURL(gOptions.stream_relayURL(sid));
  3910. // make sure we're not exposing the option to try re-connecting to a pending source relay
  3911. bool noEntry = false;
  3912. if (!(streamData::isRelayActive(sid, noEntry) == 1))
  3913. {
  3914. body += "<tr><td><br>Start Relay:</td><td><br><b>" + urlLink(srcAddr) + "</b> "
  3915. "[ <a href=\"admin.cgi?sid="+tos(sid)+"&amp;mode=startrelay\">start relay</a> ]</td></tr>";
  3916. }
  3917. else
  3918. {
  3919. body += "<tr><td><br>Starting Relay:</td><td><br><b>Connection pending to " +
  3920. urlLink(srcAddr) + "</b> [ <a href=\"admin.cgi?sid=" + tos(sid) +
  3921. "&amp;mode=kicksrc\">abort</a> ]</td></tr>";
  3922. }
  3923. }
  3924. body += "</table>";
  3925. }
  3926. body += "</td></tr></table>";
  3927. }
  3928. // for a refresh, we'll show a countdown so it's obvious that something is happening
  3929. if (refreshRequired)
  3930. {
  3931. body += "<script type=\"text/javascript\">"
  3932. "function $(id){return document.getElementById(id);}" EL
  3933. "var c = " + tos(abs(refreshRequired)) + ";" EL
  3934. "function countDown(){" EL
  3935. "c--;" EL
  3936. "if(c > 0){" EL
  3937. "$('counter').innerHTML = \"<br>Waiting \"+c+\" second\" + (c > 1 ? \"s\" : \"\") + \" for any configuration changes to take effect.<br>"
  3938. "If not automatically redirected or do not want to wait, <a href=\\\"admin.cgi?sid="+tos(sid)+"\\\">click here.</a><br><br>\";" EL
  3939. "}" EL
  3940. "}" EL
  3941. "setInterval(countDown,1000);" EL
  3942. "</script>";
  3943. }
  3944. body += getUptimeScript(false, isConnected, streamUptime) + getIEFlexFix() +
  3945. getHTML5Remover() + (!refreshRequired && hasListeners ?
  3946. getStreamListeners(sid, mapGet(m_httpRequestInfo.m_QueryParameters, "nw", (bool)gOptions.adminNoWrap()),
  3947. mapGet(m_httpRequestInfo.m_QueryParameters, "fh", (int)0)) : "") + getfooterStr();
  3948. COMPRESS(header, body);
  3949. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  3950. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  3951. }
  3952. utf8 getCDNMessage(const bool master, const bool slave)
  3953. {
  3954. if (slave && !master)
  3955. {
  3956. return "Configured as a CDN slave<br>Authhash inheritance enabled from master";
  3957. }
  3958. else if (master && !slave)
  3959. {
  3960. return "Configured as a CDN master<br>Authhash inheritance enabled for slaves";
  3961. }
  3962. return "Configured as a CDN intermediary<br>Authhash inheritance enabled both ways";
  3963. }
  3964. utf8 getBadAuthhashMessage(const streamData::streamID_t sid, const utf8 &authHash)
  3965. {
  3966. return "<div class=\"en\" style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">"
  3967. "<b>Invalid Authhash Detected</b>&nbsp;&nbsp;&nbsp;<input class=\"submit\" type=\"button\" "
  3968. "onclick=\"alert('An incorrect authhash is entered for this stream: " + authHash + "\\n\\n"
  3969. "Use the [ Clear ] option and re-enter a valid authhash or\\nregister your stream to be "
  3970. "listed in the Shoutcast directory.\\n\\nIf you think this is a valid authhash then please "
  3971. "contact\\nsupport including the authhash at support@shoutcast.com.')\" value=\"?\"><br><br>"
  3972. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register&amp;register=clear\">Clear Authhash</a>"
  3973. "&nbsp; | &nbsp;<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Manage Authhash</a></div>";
  3974. }
  3975. void protocol_admincgi::mode_summary(const int refreshRequired) throw()
  3976. {
  3977. utf8 header = MSG_NO_CLOSE_200,
  3978. streams = "",
  3979. body = getServerAdminHeader("Server Summary", refreshRequired);
  3980. size_t totalListeners = 0,
  3981. totalPeakListeners = 0,
  3982. streamTotal = 0,
  3983. movedTotal = 0;
  3984. map<size_t,uniString::utf8> streamBlocks;
  3985. if (refreshRequired == 0)
  3986. {
  3987. size_t inc = 0, sid = DEFAULT_SOURCE_STREAM;
  3988. do
  3989. {
  3990. utf8 streamBody = "";
  3991. sid = streamData::enumStreams(inc);
  3992. // check if we have an active source and valid sid before attempting to add
  3993. if (sid >= DEFAULT_SOURCE_STREAM)
  3994. {
  3995. streamData::streamInfo info;
  3996. streamData::extraInfo extra;
  3997. if (streamData::getStreamInfo(sid, info, extra))
  3998. {
  3999. stats::statsData_t data;
  4000. stats::getStats(sid, data);
  4001. // increment our stream total now that we know we have one
  4002. totalListeners += data.connectedListeners;
  4003. totalPeakListeners += data.peakListeners;
  4004. utf8 streamBody2 = "<tr><td align=\"center\">";
  4005. const bool slave = isCDNSlave(sid);
  4006. const bool master = isCDNMaster(sid);
  4007. if (master || slave)
  4008. {
  4009. streamBody2 += "<b><div class=\"en\" style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">" +
  4010. getCDNMessage(master, slave) + "</div></b><br><br>";
  4011. }
  4012. const bool isListable = streamData::isAllowedType(info.m_uvoxDataType);
  4013. if (!isListable)
  4014. {
  4015. streamBody2 += "<b><div class=\"en\" style=\"padding:1em;margin-bottom:1em;display:inline-block;border-radius:0.5em;\">" +
  4016. (info.m_uvoxDataType == OGG_DATA ? "OGG Vorbis based streams are not fully supported<br>and will not" :
  4017. utf8("NSV based streams are no longer able<br>to ")) +
  4018. " be listed in the Shoutcast Directory.</div></b><br>";
  4019. }
  4020. /*else if (!info.m_streamPublic && gOptions.cdn().empty() && !slave && !master)
  4021. {
  4022. streamBody2 += "<b><div class=\"en\" style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">"
  4023. "An authhash is not required for private streams.</div></b><br><br>";
  4024. }*/
  4025. if (isListable)
  4026. {
  4027. if (info.m_authHash.empty())
  4028. {
  4029. streamBody2 += "<div class=\"en\" style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">"
  4030. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Create Authhash</a>"
  4031. "&nbsp; | &nbsp;<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Manage Authhash</a></div>";
  4032. }
  4033. else
  4034. {
  4035. // check that the authhash is a valid length
  4036. if (!yp2::isValidAuthhash(info.m_authHash))
  4037. {
  4038. streamBody2 += getBadAuthhashMessage(sid, info.m_authHash);
  4039. }
  4040. else
  4041. {
  4042. streamBody2 += "<div class=\"en\" style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">"
  4043. + utf8((master || slave || info.m_streamPublic) && (info.m_streamSampleRate > 0) &&
  4044. info.m_radionomyID.empty() && ((extra.ypErrorCode != YP_NOT_VISIBLE) &&
  4045. (extra.ypErrorCode != YP_AUTH_ISSUE_CODE) && (extra.ypErrorCode != -1)) ?
  4046. warningImage(false) + "&nbsp;&nbsp;<b>Please Register Your Authhash</b><br><br>" : "") +
  4047. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Update Authhash</a>&nbsp; | "
  4048. "&nbsp;<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Manage Authhash</a></div>";
  4049. }
  4050. }
  4051. }
  4052. else
  4053. {
  4054. streamBody2 += "<div class=\"en\" style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">"
  4055. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Manage Authhash</a></div>";
  4056. }
  4057. streamBody2 += "</td></tr>";
  4058. streamData *sd = streamData::accessStream(sid);
  4059. streamBody += "<tr><td align=\"center\" class=\"tnl\">" +
  4060. (sd && !sd->radionomyID().empty() && sd->streamAdvertMode() ?
  4061. "<img border=\"0\" title=\"Active DNAS+ Stream\nMonetisation Enabled\" "
  4062. "alt=\"Active DNAS+ Stream\nMonetisation Enabled\" style=\"vertical-align:middle\" "
  4063. "src=\"images/adavail.png\">&nbsp;" : (utf8)"") +
  4064. "<a href=\"index.html?sid=" + tos(sid) + "\">Stream #" + tos(sid) + "</a> "
  4065. "<a href=\"admin.cgi?sid=" + tos(sid) + "\">(Stream Login)</a>" +
  4066. " <a href=\"listen.pls?sid=" + tos(sid) + "\"><img border=\"0\" title=\"Listen to Stream\" "
  4067. "alt=\"Listen to Stream\" style=\"vertical-align:middle\" src=\"images/listen.png\"></a>" +
  4068. (sd && !sd->streamAlbumArt().empty() ? " <a href=\"/streamart?sid=" + tos(sid) + "\">"
  4069. "<img border=\"0\" title=\"View Stream Artwork\" alt=\"View Stream Artwork\" "
  4070. "style=\"vertical-align:middle;padding-left:0.5em;\" src=\"images/streamart.png\"></a>" : "") +
  4071. (sd && !sd->streamPlayingAlbumArt().empty() ? " <a href=\"/playingart?sid=" + tos(sid) + "\">"
  4072. "<img border=\"0\" title=\"View Playing Artwork\" alt=\"View Playing Artwork\" "
  4073. "style=\"vertical-align:middle;padding-left:0.5em;\" src=\"images/playingart.png\"></a>" : "") +
  4074. "</td></tr>" +
  4075. (!info.m_contentType.empty() && (info.m_uvoxDataType == MP3_DATA) ?
  4076. streamData::getHTML5Player(sid) : "") + streamBody2;
  4077. utf8 content = streamData::getContentType(info);
  4078. if (!info.m_streamUser.empty())
  4079. {
  4080. content = info.m_streamUser + " - " + content;
  4081. }
  4082. const int maxUsers = ((info.m_streamMaxUser > 0) && (info.m_streamMaxUser < gOptions.maxUser()) ? info.m_streamMaxUser : gOptions.maxUser());
  4083. const utf8 listeners = (data.connectedListeners ? (tos(data.connectedListeners) +
  4084. (data.connectedListeners != data.uniqueListeners ?
  4085. (" (" + tos(data.uniqueListeners) + " unique)") : "")) : "0") +
  4086. (maxUsers > 0 ? " of " + tos(maxUsers) : " (unlimited)");
  4087. const utf8 listenLink = "<a href=\"listen.pls?sid=" + tos(sid) + "\"><img border=\"0\" title=\"Listen to Stream\" "
  4088. "alt=\"Listen to Stream\" style=\"vertical-align:middle\" src=\"images/listen.png\"></a>";
  4089. streamBody += "<tr><td align=\"center\">" +
  4090. (info.m_streamPublic && extra.ypConnected ? "<a target=\"_blank\" href=\"http://directory.shoutcast.com/Search?query=" +
  4091. urlUtils::escapeURI_RFC3986(info.m_streamName) + "\">" + aolxml::escapeXML(info.m_streamName) + "</a>" :
  4092. aolxml::escapeXML(info.m_streamName)) + " (" + content + "&nbsp;@&nbsp;" +
  4093. (info.m_streamBitrate > 0 ? tos(info.m_streamBitrate) : "unknown") +
  4094. "&nbsp;kbps" + (info.m_vbr ? " (VBR)" : "") + ", " +
  4095. sampleRateStr(info.m_streamSampleRate) + ")</td></tr>" +
  4096. (!info.m_currentSong.empty() ? "<tr><td align=\"center\" style=\"padding-bottom:0;\">Playing: <b>"
  4097. "<a href=\"currentsong?sid=" + tos(sid) + "\">" +
  4098. aolxml::escapeXML(info.m_currentSong) + "</a></b></td></tr>" +
  4099. (!info.m_comingSoon.empty() ? "<tr><td align=\"center\" style=\"padding-top:0;\">Coming: <b>"
  4100. "<a href=\"currentsong?sid=" + tos(sid) + "\">" +
  4101. aolxml::escapeXML(info.m_comingSoon) + "</a></b></td></tr>" : "") : "") +
  4102. "<tr><td><table align=\"center\"><tr valign=\"top\"><td align=\"center\">"
  4103. "<div style=\"text-align:left;\">Listeners: <b>" + listeners + "</b>" +
  4104. (data.peakListeners > 0 ? "<br>Peak: <b>" + tos(data.peakListeners) + "</b>" : "") +
  4105. (data.connectedListeners > 0 ? " [&nbsp;<a href=\"admin.cgi?sid=" +
  4106. tos(sid) + "&amp;mode=kickdst&amp;kickdst=all\">kick all</a>&nbsp;]" : "") +
  4107. "</div></td><td>&nbsp;&nbsp;&nbsp;</td><td align=\"center\">Status: <b>" +
  4108. string(info.m_streamPublic && isListable ? (extra.ypConnected != 1 ? "" : string("Public</b><br>"
  4109. "<div title=\"Shoutcast Directory ID\" alt=\"Shoutcast Directory ID\">"
  4110. "<img border=\"0\" title=\"Shoutcast Directory ID\" alt=\"Shoutcast Directory ID\" style=\"vertical-align:bottom\" "
  4111. "src=\"images/favicon.ico\"> ID: <b><a title=\"Shoutcast Directory ID\" href=\"http://" +
  4112. gOptions.ypAddr().hideAsString() + ":" + tos(gOptions.ypPort()) + ((gOptions.ypPath() != utf8("/yp2")) ? "/yp" : "") +
  4113. "/sbin/tunein-station.pls?id=" + info.m_stationID.hideAsString() + "\">" + info.m_stationID.hideAsString() + "</a></b></div>")) +
  4114. (extra.ypConnected != 1 ? (!yp2::isValidAuthhash(info.m_authHash) ?
  4115. " Not Listed - " + string(info.m_authHash.empty() ? "Empty" : "Invalid") + " Authhash" :
  4116. (extra.ypErrorCode == 200 ? " Waiting on a Directory response" :
  4117. (extra.ypErrorCode == -1 ? "Unable to access the Directory.<br>Check the server log for more details.<br>The stream will behave like it is private." :
  4118. (extra.ypErrorCode == YP_MAINTENANCE_CODE ? "Directory is down for maintenance: <a target=\"_blank\" href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2#YP_Server_Errors\">" +
  4119. tos(extra.ypErrorCode) + "</a><br>Listeners are allowed, stream will not be listed" :
  4120. (extra.ypErrorCode == YP_AUTH_ISSUE_CODE ? " Please contact support as there is an issue with the authhash" : " Directory returned error code: <a target=\"_blank\" href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2#YP_Server_Errors\">" + tos(extra.ypErrorCode) + "</a><br>" +
  4121. (extra.ypConnected != 2 ? "" : "during a listing update. The stream may not<br>appear in the Directory due to the error. The<br> server will attempt to re-list the stream.")))))) : "") :
  4122. "Private") + "</td><td>&nbsp;&nbsp;&nbsp;</td>"
  4123. "<td title=\"Source User Agent: " + addWBR((!info.m_sourceIdent.empty() ?
  4124. info.m_sourceIdent : "Legacy / Unknown")) + "\">Source: <b>" +
  4125. utf8(info.m_sourceType == streamData::SHOUTCAST1 ? "v1" :
  4126. (info.m_sourceType == streamData::SHOUTCAST2 ? "v2" : "HTTP")) +
  4127. (extra.isRelay ? " relay" + (extra.isBackup ? utf8("&nbsp;backup") : "") :
  4128. (extra.isBackup ? "&nbsp;backup" : "")) + "</b> [&nbsp;<a href=\"admin.cgi?sid=" +
  4129. tos(sid) + "&amp;mode=kicksrc\">" + (extra.isRelay || extra.isBackup ? "stop" : "kick") +
  4130. "</a>&nbsp;]</td></tr></table></td></tr>"
  4131. "<tr><td align=\"center\">"
  4132. "<div style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\" class=\"en\">"
  4133. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=viewxml\">Summary</a>&nbsp; | &nbsp;"
  4134. "<div style=\"display:inline-block;\"><a href=\"admin.cgi?sid=" +
  4135. tos(sid) + "&amp;mode=viewxml&amp;page=3\">Listeners</a> [ <a href=\"admin.cgi?sid=" +
  4136. tos(sid) + "&amp;mode=viewxml&amp;page=3&amp;ipcount=1\">Counts</a> ]</div>&nbsp; | &nbsp;"
  4137. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=viewxml&amp;page=4\">History</a>&nbsp; | &nbsp;"
  4138. "<a href=\"currentmetadata?sid=" + tos(sid) + "\">Metadata</a>&nbsp; | &nbsp;"
  4139. "<a href=\"stats?sid=" + tos(sid) + "\">Statistics</a>&nbsp;"
  4140. "<a href=\"7?sid=" + tos(sid) + "\">&hellip;</a></div></td></tr>";
  4141. if (sd)
  4142. {
  4143. sd->releaseStream();
  4144. }
  4145. const utf8& message = streamData::getStreamMessage(sid);
  4146. if (!message.empty())
  4147. {
  4148. streamBody += "<tr><td align=\"center\" width=\"100%\"><table cellspacing=\"0\" cellpadding=\"15px;\" class=\"ent\" width=\"85%\">"
  4149. "<tr><td valign=\"top\" align=\"center\" style=\"border:1px;display:block;\"><br>"
  4150. "<div align=\"center\" class=\"infh\" style=\"margin-left:-15px;margin-right:-15px;margin-top:-14px;\">"
  4151. "<b>Official Message Received</b></div>" + message + "</td></tr></table></td></tr>";
  4152. }
  4153. streamBlocks[sid] = streamBody;
  4154. }
  4155. }
  4156. ++inc;
  4157. }
  4158. while (sid);
  4159. // now we check through for any known but inactive relays and then get them listed as well
  4160. vector<config::streamConfig> relayList(gOptions.getRelayList());
  4161. if (!relayList.empty())
  4162. {
  4163. for (vector<config::streamConfig>::const_iterator i = relayList.begin(); i != relayList.end(); ++i)
  4164. {
  4165. sid = (*i).m_streamID;
  4166. const bool exists = !(*i).m_relayUrl.url().empty();
  4167. if (exists && !streamData::isSourceConnected(sid))
  4168. {
  4169. stats::statsData_t data;
  4170. stats::getStats(sid, data);
  4171. // increment our stream total now that we know we have one
  4172. totalListeners += data.connectedListeners;
  4173. totalPeakListeners += data.peakListeners;
  4174. streamData::streamInfo info;
  4175. streamData::extraInfo extra;
  4176. streamData::getStreamInfo(sid, info, extra);
  4177. utf8 listeners, content, streamBody2,
  4178. streamBody = "<tr align=\"center\" class=\"tnl\"><td>"
  4179. "<a href=\"index.html?sid=" + tos(sid) + "\">Stream #" + tos(sid) + "</a> "
  4180. "<a href=\"admin.cgi?sid=" + tos(sid) + "\">(Stream Login)</a></td></tr>";
  4181. const utf8 movedUrl = gOptions.stream_movedUrl(sid);
  4182. if (movedUrl.empty())
  4183. {
  4184. const bool slave = isCDNSlave(sid);
  4185. const bool master = isCDNMaster(sid);
  4186. if (master || slave)
  4187. {
  4188. streamBody2 = "<div class=\"en\" style=\"padding:1emx;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">" +
  4189. getCDNMessage(master, slave) + "</div><br><br>";
  4190. }
  4191. else
  4192. {
  4193. if ((*i).m_authHash.empty())
  4194. {
  4195. streamBody2 += "<div class=\"en\" style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">"
  4196. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Create Authhash</a>"
  4197. "&nbsp; | &nbsp;<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Manage Authhash</a></div>";
  4198. }
  4199. else
  4200. {
  4201. // check that the authhash is a valid length
  4202. if (!yp2::isValidAuthhash((*i).m_authHash))
  4203. {
  4204. streamBody2 += getBadAuthhashMessage(sid, info.m_authHash);
  4205. }
  4206. else
  4207. {
  4208. streamBody2 += "<div class=\"en\" style=\"padding:1em;margin-bottom:0.5em;display:inline-block;border-radius:0.5em;\">"
  4209. + utf8((master || slave || info.m_streamPublic) && (info.m_streamSampleRate > 0) &&
  4210. info.m_radionomyID.empty() && ((extra.ypErrorCode != YP_NOT_VISIBLE) &&
  4211. (extra.ypErrorCode != YP_AUTH_ISSUE_CODE) && (extra.ypErrorCode != -1)) ?
  4212. warningImage(false) + "&nbsp;&nbsp;<b>Please Register Your Authhash</b><br><br>" : "") +
  4213. "<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Update Authhash</a>&nbsp; | "
  4214. "&nbsp;<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=register\">Manage Authhash</a></div>";
  4215. }
  4216. }
  4217. if (!streamBody2.empty())
  4218. {
  4219. streamBody2 += "<br>";
  4220. }
  4221. }
  4222. }
  4223. else
  4224. {
  4225. streamBody2 = "<b>This stream is configured as having been moved or retired.<br>"
  4226. "No source connections will be allowed for this stream.<br><br>"
  4227. "All client connections received will be redirected to:<br>" +
  4228. urlLink(movedUrl) + "</b>";
  4229. ++movedTotal;
  4230. }
  4231. if (!streamBody2.empty())
  4232. {
  4233. streamBody += "<tr><td align=\"center\">" + streamBody2 + "</td></tr>";
  4234. }
  4235. // strip down the source address for display output
  4236. const utf8 srcAddr = niceURL(gOptions.stream_relayURL(sid));
  4237. if (movedUrl.empty())
  4238. {
  4239. bool noEntry = false;
  4240. const bool isListable = streamData::isAllowedType(info.m_uvoxDataType);
  4241. streamBody += "<tr><td><table align=\"center\"><tr valign=\"top\">"
  4242. "<td" + (!extra.isConnected ? " rowspan=\"2\"" : (utf8)"") +
  4243. " align=\"right\">Status: <b>" + string(info.m_streamPublic && isListable ? (extra.ypConnected != 1 ? "" : string("Public")) +
  4244. (extra.ypConnected != 1 ? (!yp2::isValidAuthhash(info.m_authHash) ?
  4245. " Not Listed - " + string(info.m_authHash.empty() ? "Empty" : "Invalid") + " Authhash" :
  4246. (extra.ypErrorCode == 200 ? " Waiting on a Directory response" :
  4247. (extra.ypErrorCode == -1 ? "Unable to access the Directory.<br>Check the error server for more details.<br>The stream will behave like it is private." :
  4248. (extra.ypErrorCode == YP_MAINTENANCE_CODE ? "Directory is down for maintenance: <a target=\"_blank\" "
  4249. "href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2#YP_Server_Errors\">" +
  4250. tos(extra.ypErrorCode) + "</a><br>Listeners are allowed, stream will not be listed" :
  4251. (extra.ypErrorCode == YP_AUTH_ISSUE_CODE ? " Please contact support as there is an issue with the authhash" : " Directory returned "
  4252. "error code: <a target=\"_blank\" href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2#YP_Server_Errors\">" + tos(extra.ypErrorCode) + "</a><br>" +
  4253. (extra.ypConnected != 2 ? "" : "during a listing update. The stream may not<br>appear in the Directory due to the error. The<br> server will attempt to re-list the stream.")))))) : "") :
  4254. "Private") + "</b></td><td" + (!extra.isConnected ? " rowspan=\"2\"" : (utf8)"") + ">&nbsp;&nbsp;&nbsp;</td>"
  4255. "<td title=\"Source User Agent: " + addWBR((!info.m_sourceIdent.empty() ? info.m_sourceIdent : "Legacy / Unknown")) + "\">"
  4256. "Source: <b>" + (!(streamData::isRelayActive(sid, noEntry) == 1) ?
  4257. "Inactive relay</b> [&nbsp;<a href=\"admin.cgi?sid=" + tos(sid) +
  4258. "&amp;mode=startrelay\">start relay</a>&nbsp;]<br>Using: <b>" + urlLink(srcAddr) + "</b>" :
  4259. "Connection pending to " + urlLink(srcAddr) + "</b>"
  4260. " [&nbsp;<a href=\"admin.cgi?sid=" + tos(sid) + "&amp;mode=kicksrc\">abort</a>&nbsp;]") +
  4261. // if it's an inactive stream then we also want to show any remaining connections
  4262. "</td></tr>" + (data.connectedListeners > 0 ? "<tr valign=\"top\">"
  4263. "<td align=\"center\"><div style=\"text-align:left;padding-top:0.5em;\">Listeners: <b>" +
  4264. tos(data.connectedListeners) + "</b>" + (data.peakListeners > 0 ? " &nbsp;|&nbsp; Peak: <b>" +
  4265. tos(data.peakListeners) + "</b>" : "") + " [&nbsp;<a href=\"admin.cgi?sid=" + tos(sid) +
  4266. "&amp;mode=kickdst&amp;kickdst=all\">kick all</a>&nbsp;]" + "</div></td></tr>" : "") +
  4267. "</table></td></tr>";
  4268. }
  4269. streamBlocks[sid] = streamBody;
  4270. }
  4271. }
  4272. }
  4273. // now we check through for any known but in-active sources & then get them listed as well
  4274. // new to build 70 but for fire builds makes it easier to see if a feed stream is inactive
  4275. config::streams_t stream_configs;
  4276. gOptions.getStreamConfigs(stream_configs);
  4277. if (!stream_configs.empty())
  4278. {
  4279. for (config::streams_t::const_iterator i = stream_configs.begin(); i != stream_configs.end(); ++i)
  4280. {
  4281. if (streamBlocks.find((*i).first) == streamBlocks.end())
  4282. {
  4283. stats::statsData_t data;
  4284. stats::getStats((*i).first, data);
  4285. // increment our stream total now that we know we have one
  4286. totalListeners += data.connectedListeners;
  4287. totalPeakListeners += data.peakListeners;
  4288. utf8 streamBody = "<tr><td align=\"center\" class=\"tnl\">"
  4289. "<a href=\"index.html?sid=" + tos((*i).first) + "\">Stream #" + tos((*i).first) + "</a> "
  4290. "<a href=\"admin.cgi?sid=" + tos((*i).first) + "\">(Stream Login)</a></td></tr>",
  4291. streamBody2;
  4292. const utf8 movedUrl = gOptions.stream_movedUrl((*i).first);
  4293. if (movedUrl.empty())
  4294. {
  4295. utf8 authhash = (*i).second.m_authHash;
  4296. if (authhash.empty())
  4297. {
  4298. authhash = gOptions.stream_authHash((*i).first);
  4299. }
  4300. if (authhash.empty())
  4301. {
  4302. streamBody2 += "<div class=\"en\" style=\"padding:1em;margin-bottom:1em;display:inline-block;border-radius:0.5em;\">"
  4303. "<a href=\"admin.cgi?sid=" + tos((*i).first) + "&amp;mode=register\">Create Authhash</a>"
  4304. "&nbsp; | &nbsp;<a href=\"admin.cgi?sid=" + tos((*i).first) + "&amp;mode=register\">Manage Authhash</a></div>";
  4305. }
  4306. else
  4307. {
  4308. // check that the authhash is a valid length
  4309. if (!yp2::isValidAuthhash(authhash))
  4310. {
  4311. streamBody2 += getBadAuthhashMessage((*i).first, authhash);
  4312. }
  4313. else
  4314. {
  4315. streamBody2 += "<div class=\"en\" style=\"padding:1em;margin-bottom:1em;display:inline-block;border-radius:0.5em;\">"
  4316. // TODO if the stream is not active then we don't know the admode
  4317. // status and so it's easier to not show the warning until
  4318. // we've got something that will allow us to check authhash.
  4319. //+ utf8(info.m_radionomyID.empty() ? warningImage(false) + "&nbsp;&nbsp;<b>Please Register Your Authhash</b><br><br>" : "") +
  4320. "<a href=\"admin.cgi?sid=" + tos((*i).first) + "&amp;mode=register\">Update Authhash</a>"
  4321. "&nbsp; |&nbsp;<a href=\"admin.cgi?sid=" + tos((*i).first) + "&amp;mode=register\">Manage Authhash</a></div>";
  4322. }
  4323. }
  4324. if (!streamBody2.empty())
  4325. {
  4326. streamBody2 += "<br>";
  4327. }
  4328. streamBody2 += "<b>This stream is configured but has no source connected.</b>" +
  4329. (data.connectedListeners > 0 ? "<div style=\"text-align:center;padding-top:0.5em;\">Listeners: "
  4330. "<b>" + tos(data.connectedListeners) + "</b>" + (data.peakListeners > 0 ? " &nbsp;|&nbsp; "
  4331. "Peak: <b>" + tos(data.peakListeners) + "</b>" : "") + " [&nbsp;<a href=\"admin.cgi?sid=" +
  4332. tos(sid) + "&amp;mode=kickdst&amp;kickdst=all\">kick all</a>&nbsp;]" + "</div>" : "");
  4333. }
  4334. else
  4335. {
  4336. streamBody2 += "<b>This stream is configured as having been moved or retired.<br>"
  4337. "No source connections will be allowed for this stream.<br><br>"
  4338. "All client connections received will be redirected to:<br>" +
  4339. urlLink(movedUrl) + "</b>";
  4340. ++movedTotal;
  4341. }
  4342. if (!streamBody2.empty())
  4343. {
  4344. streamBody += "<tr><td align=\"center\">" + streamBody2 + "</td></tr>";
  4345. }
  4346. streamBlocks[(*i).first] = streamBody;
  4347. }
  4348. }
  4349. }
  4350. // this will now do a final check for any listeners which are on
  4351. // an un-confiured stream but are being provided a 'backupfile'.
  4352. const streamData::streamIDs_t activeIds = stats::getActiveStreamIds();
  4353. if (!activeIds.empty())
  4354. {
  4355. for (streamData::streamIDs_t::const_iterator i = activeIds.begin(); i != activeIds.end(); ++i)
  4356. {
  4357. if (streamBlocks.find((*i)) == streamBlocks.end())
  4358. {
  4359. stats::statsData_t data;
  4360. stats::getStats((*i), data);
  4361. // increment our stream total now that we know we have one
  4362. totalListeners += data.connectedListeners;
  4363. totalPeakListeners += data.peakListeners;
  4364. utf8 streamBody = "<tr><td align=\"center\" class=\"tnl\">"
  4365. "<a href=\"index.html?sid=" + tos((*i)) + "\">Stream #" + tos((*i)) + "</a> "
  4366. "<a href=\"admin.cgi?sid=" + tos((*i)) + "\">(Stream Login)</a></td></tr>",
  4367. streamBody2;
  4368. streamBody2 += "<b>This stream is not configured and has no source connected.</b>" +
  4369. (data.connectedListeners > 0 ? "<div style=\"text-align:center;padding-top:0.5em;\">Listeners: "
  4370. "<b>" + tos(data.connectedListeners) + "</b>" + (data.peakListeners > 0 ? " &nbsp;|&nbsp; "
  4371. "Peak: <b>" + tos(data.peakListeners) + "</b>" : "") + " [&nbsp;<a href=\"admin.cgi?sid=" +
  4372. tos(sid) + "&amp;mode=kickdst&amp;kickdst=all\">kick all</a>&nbsp;]" + "</div>" : "");
  4373. if (!streamBody2.empty())
  4374. {
  4375. streamBody += "<tr><td align=\"center\">" + streamBody2 + "</td></tr>";
  4376. }
  4377. streamBlocks[(*i)] = streamBody;
  4378. }
  4379. }
  4380. }
  4381. // now build up the output since if we've factored in inactive relay connections
  4382. // then we could otherwise be showing the streams in an out of order manner
  4383. for (map<size_t,uniString::utf8>::const_iterator i = streamBlocks.begin(); i != streamBlocks.end(); ++i)
  4384. {
  4385. if (!(*i).second.empty())
  4386. {
  4387. if (streamTotal > 0)
  4388. {
  4389. streams += "<tr><td align=\"center\"><br><hr><br></td></tr>";
  4390. }
  4391. streams += (*i).second;
  4392. ++streamTotal;
  4393. }
  4394. }
  4395. // output a refresh option if there were no active streams found
  4396. if (!streamTotal)
  4397. {
  4398. if (isPostSetup() && isPostSetup() <= 2)
  4399. {
  4400. streams += "<tr><td align=\"center\">"
  4401. "<br><div align=\"center\" class=\"infh\" style=\"border-bottom:0;top:-19px;\">"
  4402. "Setup Successfully Completed</div></td></tr><tr><td align=\"center\">"
  4403. "No stream sources are currently connected.<br>"
  4404. "To find newly connected sources, <a href=\"admin.cgi?sid=0\">click here.</a></td></tr>";
  4405. setPostSetup(isPostSetup() + 1);
  4406. }
  4407. else
  4408. {
  4409. streams += "<tr><td align=\"center\">No stream sources are currently connected.<br>"
  4410. "To find newly connected sources, <a href=\"admin.cgi?sid=0\">click here.</a><br><br></td></tr>";
  4411. }
  4412. }
  4413. else
  4414. {
  4415. setPostSetup(0);
  4416. }
  4417. }
  4418. else if (refreshRequired > 0)
  4419. {
  4420. streams += "<tr><td align=\"center\" id=\"counter\">"
  4421. "Waiting " + tos(refreshRequired) + " second" + ((refreshRequired > 1) ? "s" : (utf8)"") +
  4422. " for any configuration changes to take effect.<br>"
  4423. "If not automatically redirected or do not want to wait, "
  4424. "<a href=\"admin.cgi?sid=0\">click here.</a><br><br></td></tr>";
  4425. }
  4426. else if (refreshRequired < 0)
  4427. {
  4428. streams += "<tr><td align=\"center\" id=\"counter\">"
  4429. "Waiting " + tos(abs(refreshRequired)) + " second" + ((abs(refreshRequired) > 1) ? "s" : (utf8)"") +
  4430. " whilst checking for any DNAS updates.<br>If not automatically redirected or do not want to wait, "
  4431. "<a href=\"admin.cgi?sid=0\">click here.</a><br><br></td></tr>";
  4432. }
  4433. utf8 log = gOptions.realLogFile();
  4434. utf8::size_type pos = log.rfind(fileUtil::getFilePathDelimiter());
  4435. if ((pos != utf8::npos))
  4436. {
  4437. log = log.substr(pos + 1);
  4438. }
  4439. utf8 conf = gOptions.confFile();
  4440. pos = conf.rfind(fileUtil::getFilePathDelimiter());
  4441. if ((pos != utf8::npos))
  4442. {
  4443. conf = conf.substr(pos + 1);
  4444. }
  4445. const bool requires = gOptions.requireStreamConfigs();
  4446. body += "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"100%\">"
  4447. "<tr><td class=\"tsp\" align=\"center\">"
  4448. "Available Streams: " + tos(streamTotal - movedTotal) +
  4449. "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;"
  4450. "Server Listeners: " + tos(totalListeners) +
  4451. "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;"
  4452. "Peak Server Listeners: " + tos(totalPeakListeners) +
  4453. "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;"
  4454. "Unique Listeners: " + tos(stats::getTotalUniqueListeners()) +
  4455. "</td></tr></table>"
  4456. "<div style=\"padding:0 1em;\">"
  4457. "<br><table width=\"100%\" align=\"center\"><tr valign=\"top\"><td>"
  4458. "<table class=\"en\" cellpadding=\"15px\" style=\"border:0;display:block;padding-right:1em;\"><tr>"
  4459. "<td valign=\"top\" style=\"max-width:20em;\">"
  4460. "<div align=\"center\" class=\"infh\"><b>Server Management</b></div>"
  4461. "Rotate Log File(s):"
  4462. " [&nbsp;<a href=\"admin.cgi?mode=rotate\">All</a>&nbsp;]"
  4463. "&nbsp; [&nbsp;<a href=\"admin.cgi?mode=rotate&amp;files=log\">Log</a>&nbsp;]"
  4464. "&nbsp; [&nbsp;<a href=\"admin.cgi?mode=rotate&amp;files=w3c\">W3C</a>&nbsp;]"
  4465. "<br><br>"
  4466. // trim down the file paths shown to make things less cluttered on hosted setups
  4467. // places the full path in the 'title' so it can still be found if required, etc
  4468. "Log File: <b title=\"" +
  4469. aolxml::escapeXML(fileUtil::getFullFilePath(gOptions.realLogFile())) +
  4470. "\">" + aolxml::escapeXML(fileUtil::stripPath(log)) + "</b><br><br>"
  4471. "Configuration File: <b title=\"" +
  4472. aolxml::escapeXML(fileUtil::getFullFilePath(gOptions.confFile())) +
  4473. "\">" + aolxml::escapeXML(fileUtil::stripPath(conf)) + "</b><br>"
  4474. "[&nbsp;<a href=\"admin.cgi?mode=config\">View</a>&nbsp;]"
  4475. "&nbsp; [&nbsp;<a href=\"admin.cgi?mode=reload\">Update</a>&nbsp;]"
  4476. "&nbsp; [&nbsp;<a href=\"admin.cgi?mode=reload&amp;force=1\">Forced</a>&nbsp;]"
  4477. "<br><br><hr><br>Source Connection Details:"
  4478. " [&nbsp;<a href=\"admin.cgi?mode=sources\">View</a>&nbsp;]<br>" +
  4479. (requires ? "<br><b>Note:</b> Only pre-configured streams are "
  4480. "allowed to connect / be run on this server.<br>" : "") +
  4481. "<br>Advert Group Details:"
  4482. " [&nbsp;<a href=\"admin.cgi?mode=adgroups\">View</a>&nbsp;]<br>"
  4483. "<br><hr><br>Stream Configuration(s):"
  4484. " [&nbsp;<a href=\"admin.cgi?sid=1&amp;mode=viewjson&amp;page=6\">JSON</a>&nbsp;]"
  4485. " &nbsp;[&nbsp;<a href=\"admin.cgi?sid=1&amp;mode=viewxml&amp;page=6\">XML</a>&nbsp;]<br>"
  4486. "<br>View Stream Statistics:"
  4487. " [&nbsp;<a href=\"statistics?json=1\">JSON</a>&nbsp;]"
  4488. "&nbsp; [&nbsp;<a href=\"statistics\">XML</a>&nbsp;]<br>"
  4489. "<br><hr><br>Manage Stream Source(s):<br>"
  4490. "[&nbsp;<a href=\"admin.cgi?mode=startrelays\">Start Relays</a>&nbsp;]"
  4491. "&nbsp; [&nbsp;<a href=\"admin.cgi?mode=kicksources\">Kick / Stop All</a>&nbsp;]<br>"
  4492. "<br><hr><br>Reload Banned List(s):"
  4493. " [&nbsp;<a href=\"admin.cgi?mode=bannedlist\">Update</a>&nbsp;]<br>"
  4494. "<br>Reload Reserved List(s):"
  4495. " [&nbsp;<a href=\"admin.cgi?mode=reservelist\">Update</a>&nbsp;]<br>"
  4496. "<br>Reload User Agent List(s):"
  4497. " [&nbsp;<a href=\"admin.cgi?mode=useragentlist\">Update</a>&nbsp;]<br>"
  4498. "<br>Reload Admin Access List:"
  4499. " [&nbsp;<a href=\"admin.cgi?mode=adminlist\">Update</a>&nbsp;]<br>"
  4500. "<br>Clear Resource / Page Cache:"
  4501. " [&nbsp;<a href=\"admin.cgi?mode=clearcache\">Clear</a>&nbsp;]<br>"
  4502. "<br><hr><br>Debugging Options:<br>"
  4503. "[&nbsp;<a href=\"admin.cgi?mode=debug&amp;option=all&amp;on=true\">Enable&nbsp;All</a>&nbsp;]"
  4504. "&nbsp; [&nbsp;<a href=\"admin.cgi?mode=debug&amp;option=all&amp;on=false\">Disable&nbsp;All</a>&nbsp;]"
  4505. "&nbsp; [&nbsp;<a href=\"admin.cgi?mode=debug\">Edit</a>&nbsp;]"
  4506. "<br><br><hr><br>New DNAS Release: [&nbsp;<a href=\"admin.cgi?mode=version\">Check</a>&nbsp;]<br>"
  4507. "Last checked: <b>" + getCheckedDuration((size_t)(m_lastActivityTime - last_update_check)) + "</b>"
  4508. "</td></tr></table></td><td>";
  4509. // display update message where applicable
  4510. updater::verInfo ver;
  4511. utf8 update_msg;
  4512. if (updater::getNewVersion(ver))
  4513. {
  4514. update_msg += "<tr><td align=\"center\" class=\"tnl\">"
  4515. "<table cellspacing=\"0\" cellpadding=\"5\"><tr><td align=\"center\" class=\"infb\">"
  4516. "<div align=\"center\" class=\"infh\"><b>New DNAS Version Available</b></div>A new version of the DNAS is now available:"
  4517. " <b>" + ver.ver + "</b><br><br>" +
  4518. (!ver.url.empty() ?
  4519. ((ver.downloaded && !ver.fn.empty()) ? "The new version has been automatically downloaded to:<br><br><b>" + aolxml::escapeXML(ver.fn) + "</b><br><br>"
  4520. "Please install this update as soon as possible, thank you.<br><br>"
  4521. "Specific changes for this version can be found <a href=\"" + aolxml::escapeXML(ver.info) + "\"><b>here</b></a>."
  4522. :
  4523. "Click <a href=\"" + aolxml::escapeXML(ver.url) + "\"><b>here</b></a> to download the new version of the DNAS.<br><br>"
  4524. "Please install this update as soon as possible, thank you.<br><br>"
  4525. "Specific changes for this version can be found <a href=\"" + aolxml::escapeXML(ver.info) + "\"><b>here</b></a>.") : "") +
  4526. (!ver.message.empty() ? "<br>" + ver.message :
  4527. (!ver.log.empty() ? "<br>For more details of the changes in this version see <a target=\"_blank\" href=\"" + aolxml::escapeXML(ver.log) + "\">" +
  4528. "<b>here</b></a>." : "")) + "</td></tr></table><br></td></tr>"
  4529. "<tr><td align=\"center\"><hr><br></td></tr>";
  4530. }
  4531. body += "<table cellspacing=\"0\" cellpadding=\"5\" border=\"0\">" +
  4532. update_msg + streams + "</table></td></tr></table></div>" +
  4533. "<script type=\"text/javascript\">"
  4534. "function $(id){return document.getElementById(id);}" EL;
  4535. // for a refresh, we'll show a countdown so it's obvious that something is happening
  4536. if (refreshRequired > 0)
  4537. {
  4538. body += "var c = " + tos(refreshRequired) + ";" EL
  4539. "function counter(){" EL
  4540. "c--;" EL
  4541. "if(c>0){" EL
  4542. "$('counter').innerHTML=\"Waiting \"+c+\" second\" + (c > 1 ? \"s\" : \"\") + \" for any configuration changes to take effect.<br>"
  4543. "If not automatically redirected or do not want to wait, <a href=\\\"admin.cgi\\\">click here.</a><br><br>\";" EL
  4544. "}" EL
  4545. "}" EL
  4546. "setInterval(counter,1000);" EL;
  4547. }
  4548. else if (refreshRequired < 0)
  4549. {
  4550. body += "var c = " + tos(abs(refreshRequired)) + ";" EL
  4551. "function counter(){" EL
  4552. "c--;" EL
  4553. "if(c>0){" EL
  4554. "$('counter').innerHTML=\"Waiting \"+c+\" second\" + (c > 1 ? \"s\" : \"\") + \" whilst checking for any DNAS updates.<br>"
  4555. "If not automatically redirected or do not want to wait, <a href=\\\"admin.cgi\\\">click here.</a><br><br>\";" EL
  4556. "}" EL
  4557. "}" EL
  4558. "setInterval(counter,1000);" EL;
  4559. }
  4560. body += getUptimeScript(true) + "</script>" +
  4561. getIEFlexFix() + getHTML5Remover() + getfooterStr();
  4562. COMPRESS(header, body);
  4563. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  4564. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  4565. }
  4566. void protocol_admincgi::mode_bandwidth_html(const int refreshRequired) throw()
  4567. {
  4568. const __uint64 all = bandWidth::getAmount(bandWidth::ALL),
  4569. sent = bandWidth::getAmount(bandWidth::ALL_SENT),
  4570. recv = bandWidth::getAmount(bandWidth::ALL_RECV);
  4571. const time_t running = (::time(NULL) - g_upTime);
  4572. utf8 header = MSG_NO_CLOSE_200,
  4573. body = getServerAdminHeader("Server Bandwidth Usage", refreshRequired, "&amp;mode=bandwidth&amp;refresh=" + tos(abs(refreshRequired)), 1) +
  4574. "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"100%\">"
  4575. "<tr><td class=\"tsp\" align=\"center\">"
  4576. "Total: <b>" + formatSizeString(all) + (all > 0 ? " (~" + formatSizeString((all / running) * 86400) + " / day)" : "") + "</b>"
  4577. "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;"
  4578. "Sent: <b>" + formatSizeString(sent) + (sent > 0 ? " (~" + formatSizeString((sent / running) * 86400) + " / day)" : "") + "</b>"
  4579. "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;"
  4580. "Received: <b>" + formatSizeString(recv) + (recv > 0 ? " (~" + formatSizeString((recv / running) * 86400) + " / day)" : "") + "</b>"
  4581. "</td></tr></table><div><br>"
  4582. "<table align=\"center\" class=\"en\" cellspacing=\"0\" cellpadding=\"3\" style=\"border:0;\">"
  4583. "<tr class=\"infh\"><td class=\"t\">&nbsp;Total Client Data Sent</td>"
  4584. "<td class=\"st\"><b>" + formatSizeString(bandWidth::getAmount(bandWidth::ALL_CLIENT_SENT)) + "</b></td></tr>"
  4585. "<tr class=\"t\"><td>v2 Client(s)</td>"
  4586. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::CLIENT_V2_SENT)) + "</td></tr>"
  4587. "<tr class=\"t\"><td>v1 Client(s)</td>"
  4588. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::CLIENT_V1_SENT)) + "</td></tr>"
  4589. "<tr class=\"t\"><td>HTTP Client(s)</td>"
  4590. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::CLIENT_HTTP_SENT)) + "</td></tr>"
  4591. "<tr class=\"t\"><td>FLV Client(s)</td>"
  4592. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::CLIENT_FLV_SENT)) + "</td></tr>"
  4593. #if 0
  4594. "<tr class=\"t\"><td>M4A Client(s)</td>"
  4595. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::CLIENT_M4A_SENT)) + "</td></tr>"
  4596. #endif
  4597. "<tr><td style=\"border:0;\">&nbsp;</td></tr>"
  4598. "<tr class=\"infh\"><td class=\"t\">&nbsp;Total Source Data Received</td>"
  4599. "<td class=\"st\"><b>" + formatSizeString(bandWidth::getAmount(bandWidth::ALL_SOURCE_RECV)) + "</b></td></tr>"
  4600. "<tr class=\"t\"><td>v2 Source(s)</td>"
  4601. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::SOURCE_V2_RECV)) + "</td></tr>"
  4602. "<tr class=\"t\"><td>v1 Source(s)</td>"
  4603. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::SOURCE_V1_RECV)) + "</td></tr>"
  4604. "<tr><td style=\"border:0;\">&nbsp;</td></tr>"
  4605. "<tr class=\"infh\"><td class=\"t\">&nbsp;Total Source Data Sent</td>"
  4606. "<td class=\"st\"><b>" + formatSizeString(bandWidth::getAmount(bandWidth::ALL_SOURCE_SENT)) + "</b></td></tr>"
  4607. "<tr class=\"t\"><td>v2 Source(s)</td>"
  4608. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::SOURCE_V2_SENT)) + "</td></tr>"
  4609. "<tr class=\"t\"><td>v1 Source(s)</td>"
  4610. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::SOURCE_V1_SENT)) + "</td></tr>"
  4611. "<tr><td style=\"border:0;\">&nbsp;</td></tr>"
  4612. "<tr class=\"infh\"><td class=\"t\">&nbsp;Total Relay Data Received</td>"
  4613. "<td class=\"st\"><b>" + formatSizeString(bandWidth::getAmount(bandWidth::ALL_RELAY_RECV)) + "</b></td></tr>"
  4614. "<tr class=\"t\"><td>Handshaking</td>"
  4615. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::RELAY_MISC_RECV)) + "</td></tr>"
  4616. "<tr class=\"t\"><td>v2 Relay(s)</td>"
  4617. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::RELAY_V2_RECV)) + "</td></tr>"
  4618. "<tr class=\"t\"><td>v1 Relay(s)</td>"
  4619. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::RELAY_V1_RECV)) + "</td></tr>"
  4620. "<tr><td style=\"border:0;\">&nbsp;</td></tr>"
  4621. "<tr class=\"infh\"><td class=\"t\">&nbsp;Total Web Page, XML and Resoures&nbsp;&nbsp;</td>"
  4622. "<td class=\"st\"><b>" + formatSizeString(bandWidth::getAmount(bandWidth::ALL_WEB)) + "</b></td></tr>"
  4623. "<tr class=\"t\"><td>Public (e.g. /stats or index.html)</td>"
  4624. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::PUBLIC_WEB)) + "</td></tr>"
  4625. "<tr class=\"t\"><td>Private (e.g. /admin.cgi pages)</td>"
  4626. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::PRIVATE_WEB)) + "</td></tr>"
  4627. "<tr><td style=\"border:0;\">&nbsp;</td></tr>"
  4628. "<tr class=\"infh\"><td class=\"t\">&nbsp;Total Other Data</td>"
  4629. "<td class=\"st\"><b>" + formatSizeString(bandWidth::getAmount(bandWidth::ALL_OTHER)) + "</b></td></tr>"
  4630. "<tr class=\"t\"><td>Flash Policy Server</td>"
  4631. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::FLASH_POLICY)) + "</td></tr>"
  4632. "<tr class=\"t\"><td>v2 Relay(s) Sent</td>"
  4633. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::RELAY_V2_SENT)) + "</td></tr>"
  4634. "<tr class=\"t\"><td>YP Sent</td>"
  4635. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::YP_SENT)) + "</td></tr>"
  4636. "<tr class=\"t\"><td>YP Received</td>"
  4637. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::YP_RECV)) + "</td></tr>"
  4638. "<tr class=\"t\"><td>Listener Authentication and Metrics</td>"
  4639. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::AUTH_AND_METRICS)) + "</td></tr>"
  4640. "<tr class=\"t\"><td>Advert Retrieval</td>"
  4641. "<td class=\"s\">" + formatSizeString(bandWidth::getAmount(bandWidth::ADVERTS)) + "</td></tr>"
  4642. "</table></div>" + getUptimeScript() + getIEFlexFix() + getfooterStr();
  4643. COMPRESS(header, body);
  4644. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  4645. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  4646. }
  4647. void protocol_admincgi::mode_bandwidth_xml() throw()
  4648. {
  4649. utf8 header = "HTTP/1.1 200 OK\r\nContent-Type:text/xml\r\n",
  4650. body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
  4651. "<SHOUTCASTSERVER>"
  4652. "<TOTAL>" + tos(bandWidth::getAmount(bandWidth::ALL)) + "</TOTAL>"
  4653. "<SENT>" + tos(bandWidth::getAmount(bandWidth::ALL_SENT)) + "</SENT>"
  4654. "<RECV>" + tos(bandWidth::getAmount(bandWidth::ALL_RECV)) + "</RECV>"
  4655. "<TIME>" + tos((::time(NULL) - g_upTime)) + "</TIME>"
  4656. "<CLIENTSENT>"
  4657. "<TOTAL>" + tos(bandWidth::getAmount(bandWidth::ALL_CLIENT_SENT)) + "</TOTAL>"
  4658. "<V2>" + tos(bandWidth::getAmount(bandWidth::CLIENT_V2_SENT)) + "</V2>"
  4659. "<V1>" + tos(bandWidth::getAmount(bandWidth::CLIENT_V1_SENT)) + "</V1>"
  4660. "<HTTP>" + tos(bandWidth::getAmount(bandWidth::CLIENT_HTTP_SENT)) + "</HTTP>"
  4661. "<FLV>" + tos(bandWidth::getAmount(bandWidth::CLIENT_FLV_SENT)) + "</FLV>"
  4662. #if 0
  4663. "<M4A>" + tos(bandWidth::getAmount(bandWidth::CLIENT_M4A_SENT)) + "</M4A>"
  4664. #endif
  4665. "</CLIENTSENT>"
  4666. "<SOURCERECV>"
  4667. "<TOTAL>" + tos(bandWidth::getAmount(bandWidth::ALL_SOURCE_RECV)) + "</TOTAL>"
  4668. "<V2>" + tos(bandWidth::getAmount(bandWidth::SOURCE_V2_RECV)) + "</V2>"
  4669. "<V1>" + tos(bandWidth::getAmount(bandWidth::SOURCE_V1_RECV)) + "</V1>"
  4670. "</SOURCERECV>"
  4671. "<SOURCESENT>"
  4672. "<TOTAL>" + tos(bandWidth::getAmount(bandWidth::ALL_SOURCE_SENT)) + "</TOTAL>"
  4673. "<V2>" + tos(bandWidth::getAmount(bandWidth::SOURCE_V2_SENT)) + "</V2>"
  4674. "<V1>" + tos(bandWidth::getAmount(bandWidth::SOURCE_V1_SENT)) + "</V1>"
  4675. "</SOURCESENT>"
  4676. "<RELAYRECV>"
  4677. "<TOTAL>" + tos(bandWidth::getAmount(bandWidth::ALL_RELAY_RECV)) + "</TOTAL>"
  4678. "<MISC>" + tos(bandWidth::getAmount(bandWidth::RELAY_MISC_RECV)) + "</MISC>"
  4679. "<V2>" + tos(bandWidth::getAmount(bandWidth::RELAY_V2_RECV)) + "</V2>"
  4680. "<V1>" + tos(bandWidth::getAmount(bandWidth::RELAY_V1_RECV)) + "</V1>"
  4681. "</RELAYRECV>"
  4682. "<WEBPAGES>"
  4683. "<TOTAL>" + tos(bandWidth::getAmount(bandWidth::ALL_WEB)) + "</TOTAL>"
  4684. "<PUBLIC>" + tos(bandWidth::getAmount(bandWidth::PUBLIC_WEB)) + "</PUBLIC>"
  4685. "<PRIVATE>" + tos(bandWidth::getAmount(bandWidth::PRIVATE_WEB)) + "</PRIVATE>"
  4686. "</WEBPAGES>"
  4687. "<OTHER>"
  4688. "<TOTAL>" + tos(bandWidth::getAmount(bandWidth::ALL_OTHER)) + "</TOTAL>"
  4689. "<FLASH>" + tos(bandWidth::getAmount(bandWidth::FLASH_POLICY)) + "</FLASH>"
  4690. "<RELAYSENTV2>" + tos(bandWidth::getAmount(bandWidth::RELAY_V2_SENT)) + "</RELAYSENTV2>"
  4691. "<YPSENT>" + tos(bandWidth::getAmount(bandWidth::YP_SENT)) + "</YPSENT>"
  4692. "<YPRECV>" + tos(bandWidth::getAmount(bandWidth::YP_RECV)) + "</YPRECV>"
  4693. "<AUTH_METRICS>" + tos(bandWidth::getAmount(bandWidth::AUTH_AND_METRICS)) + "</AUTH_METRICS>"
  4694. "<ADVERTS>" + tos(bandWidth::getAmount(bandWidth::ADVERTS)) + "</ADVERTS>"
  4695. "</OTHER>"
  4696. "</SHOUTCASTSERVER>";
  4697. COMPRESS(header, body);
  4698. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  4699. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  4700. }
  4701. void protocol_admincgi::mode_bandwidth_json(const uniString::utf8& callback) throw()
  4702. {
  4703. const bool jsonp = !callback.empty();
  4704. utf8 header = "HTTP/1.1 200 OK\r\nContent-Type:application/json;charset=utf-8\r\n",
  4705. body = (jsonp ? callback + "(" : "") +
  4706. "{"
  4707. "\"total\":" + tos(bandWidth::getAmount(bandWidth::ALL)) + ","
  4708. "\"sent\":" + tos(bandWidth::getAmount(bandWidth::ALL_SENT)) + ","
  4709. "\"recv\":" + tos(bandWidth::getAmount(bandWidth::ALL_RECV)) + ","
  4710. "\"time\":" + tos((::time(NULL) - g_upTime)) + ","
  4711. "\"clientsent\":{"
  4712. "\"total\":" + tos(bandWidth::getAmount(bandWidth::ALL_CLIENT_SENT)) + ","
  4713. "\"v2\":" + tos(bandWidth::getAmount(bandWidth::CLIENT_V2_SENT)) + ","
  4714. "\"v1\":" + tos(bandWidth::getAmount(bandWidth::CLIENT_V1_SENT)) + ","
  4715. "\"http\":" + tos(bandWidth::getAmount(bandWidth::CLIENT_HTTP_SENT)) + ","
  4716. "\"flv\":" + tos(bandWidth::getAmount(bandWidth::CLIENT_FLV_SENT)) +
  4717. #if 0
  4718. ","
  4719. "\"m4a\":" + tos(bandWidth::getAmount(bandWidth::CLIENT_M4A_SENT)) +
  4720. #endif
  4721. "},\"sourcerecv\":{"
  4722. "\"total\":" + tos(bandWidth::getAmount(bandWidth::ALL_SOURCE_RECV)) + ","
  4723. "\"v2\":" + tos(bandWidth::getAmount(bandWidth::SOURCE_V2_RECV)) + ","
  4724. "\"v1\":" + tos(bandWidth::getAmount(bandWidth::SOURCE_V1_RECV)) +
  4725. "},\"sourcesent\":{"
  4726. "\"total\":" + tos(bandWidth::getAmount(bandWidth::ALL_SOURCE_SENT)) + ","
  4727. "\"v2\":" + tos(bandWidth::getAmount(bandWidth::SOURCE_V2_SENT)) + ","
  4728. "\"v1\":" + tos(bandWidth::getAmount(bandWidth::SOURCE_V2_SENT)) +
  4729. "},\"relayrecv\":{"
  4730. "\"total\":" + tos(bandWidth::getAmount(bandWidth::ALL_SOURCE_RECV)) + ","
  4731. "\"misc\":" + tos(bandWidth::getAmount(bandWidth::RELAY_MISC_RECV)) + ","
  4732. "\"v2\":" + tos(bandWidth::getAmount(bandWidth::RELAY_V2_RECV)) + ","
  4733. "\"v1\":" + tos(bandWidth::getAmount(bandWidth::RELAY_V1_RECV)) +
  4734. "},\"webpages\":{"
  4735. "\"total\":" + tos(bandWidth::getAmount(bandWidth::ALL_WEB)) + ","
  4736. "\"public\":" + tos(bandWidth::getAmount(bandWidth::PUBLIC_WEB)) + ","
  4737. "\"private\":" + tos(bandWidth::getAmount(bandWidth::PRIVATE_WEB)) +
  4738. "},\"other\":{"
  4739. "\"total\":" + tos(bandWidth::getAmount(bandWidth::ALL_OTHER)) + ","
  4740. "\"flash\":" + tos(bandWidth::getAmount(bandWidth::FLASH_POLICY)) + ","
  4741. "\"relaysentv2\":" + tos(bandWidth::getAmount(bandWidth::RELAY_V2_SENT)) + ","
  4742. "\"ypsent\":" + tos(bandWidth::getAmount(bandWidth::YP_SENT)) + "," +
  4743. "\"yprecv\":" + tos(bandWidth::getAmount(bandWidth::YP_RECV)) + "," +
  4744. "\"auth_metrics\":" + tos(bandWidth::getAmount(bandWidth::AUTH_AND_METRICS)) + "," +
  4745. "\"adverts\":" + tos(bandWidth::getAmount(bandWidth::ADVERTS)) +
  4746. "}}" + (jsonp ? utf8(")") : "");
  4747. COMPRESS(header, body);
  4748. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  4749. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  4750. }
  4751. void protocol_admincgi::mode_ypstatus_xml() throw()
  4752. {
  4753. utf8 header = "HTTP/1.1 200 OK\r\nContent-Type:text/xml\r\n",
  4754. body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
  4755. "<SHOUTCASTSERVER>";
  4756. streamData::streamIDs_t streamIds = streamData::getStreamIds();
  4757. config::streams_t streams;
  4758. gOptions.getStreamConfigs(streams);
  4759. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  4760. {
  4761. if ((*i).second.m_streamID)
  4762. {
  4763. streamIds.insert((*i).second.m_streamID);
  4764. }
  4765. }
  4766. for (streamData::streamIDs_t::const_iterator i = streamIds.begin(); i != streamIds.end(); ++i)
  4767. {
  4768. streamData::streamInfo info;
  4769. streamData::extraInfo extra;
  4770. streamData::getStreamInfo((*i), info, extra);
  4771. const utf8 movedUrl = gOptions.stream_movedUrl((*i));
  4772. if (movedUrl.empty())
  4773. {
  4774. body += "<STREAM id=\"" + tos((*i)) + "\">" +
  4775. (!extra.isConnected ? "<STATUS>NOSOURCE</STATUS>" :
  4776. (info.m_streamPublic ? (extra.ypConnected != 1 ? (!yp2::isValidAuthhash(info.m_authHash) ?
  4777. (info.m_authHash.empty() ? "<STATUS>EMPTY_AUTHHASH</STATUS>" : "<STATUS>INVALID_AUTHHASH</STATUS>") :
  4778. (extra.ypErrorCode == 200 ? "<STATUS>WAITING</STATUS>" :
  4779. (extra.ypErrorCode == YP_COMMS_FAILURE ? "<STATUS>YP_NOT_FOUND</STATUS>" :
  4780. (extra.ypErrorCode == YP_MAINTENANCE_CODE ? "<STATUS>YP_MAINTENANCE</STATUS>" :
  4781. "<STATUS>ERROR</STATUS><CODE>" + tos(extra.ypErrorCode) + "</CODE>")))) :
  4782. "<STATUS>PUBLIC</STATUS><STNID>" + info.m_stationID + "</STNID>") :
  4783. "<STATUS>PRIVATE</STATUS>")) + "</STREAM>";
  4784. }
  4785. else
  4786. {
  4787. body += "<STREAM id=\"" + tos((*i)) + "\"><STATUS>MOVED</STATUS></STREAM>";
  4788. }
  4789. }
  4790. body += "</SHOUTCASTSERVER>";
  4791. COMPRESS(header, body);
  4792. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  4793. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  4794. }
  4795. void protocol_admincgi::mode_ypstatus_json(const uniString::utf8& callback) throw()
  4796. {
  4797. utf8 header = "HTTP/1.1 200 OK\r\nContent-Type:application/json;charset=utf-8\r\n";
  4798. streamData::streamIDs_t streamIds = streamData::getStreamIds();
  4799. config::streams_t streams;
  4800. gOptions.getStreamConfigs(streams);
  4801. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  4802. {
  4803. if ((*i).second.m_streamID)
  4804. {
  4805. streamIds.insert((*i).second.m_streamID);
  4806. }
  4807. }
  4808. const bool jsonp = !callback.empty();
  4809. utf8 body = (jsonp ? callback + "(" : "") + "{" +
  4810. (!streamIds.empty() ? "\"streams\":[" : "");
  4811. bool read = false;
  4812. for (streamData::streamIDs_t::const_iterator i = streamIds.begin(); i != streamIds.end(); ++i)
  4813. {
  4814. streamData::streamInfo info;
  4815. streamData::extraInfo extra;
  4816. streamData::getStreamInfo((*i), info, extra);
  4817. const utf8 movedUrl = gOptions.stream_movedUrl((*i));
  4818. if (movedUrl.empty())
  4819. {
  4820. body += (read ? utf8(",") : "") +
  4821. "{"
  4822. "\"id\":" + tos((*i)) + "," +
  4823. (!extra.isConnected ? "\"status\":\"" + escapeJSON("nosource") + "\"" :
  4824. (info.m_streamPublic ? (extra.ypConnected != 1 ? (!yp2::isValidAuthhash(info.m_authHash) ?
  4825. (info.m_authHash.empty() ? "\"status\":\"" + escapeJSON("empty_authhash") + "\"" :
  4826. "\"status\":\"" + escapeJSON("invalid_authhash") + "\"") :
  4827. (extra.ypErrorCode == 200 ? "\"status\":\"" + escapeJSON("waiting") + "\"" :
  4828. (extra.ypErrorCode == YP_COMMS_FAILURE ? "\"status\":\"" + escapeJSON("yp_not_found") + "\"" :
  4829. (extra.ypErrorCode == YP_MAINTENANCE_CODE ? "\"status\":\"" + escapeJSON("yp_maintenance") + "\"" :
  4830. "\"status\":\"" + escapeJSON("error") + "\",\"code\":" + tos(extra.ypErrorCode))))) :
  4831. "\"status\":\"" + escapeJSON("public") + "\",\"stnid\":" + info.m_stationID) :
  4832. "\"status\":\"" + escapeJSON("private") + "\"")) + "}";
  4833. }
  4834. else
  4835. {
  4836. body += (read ? utf8(",") : "") + "{\"id\":" + tos((*i)) + ","
  4837. "\"status\":\"" + escapeJSON("moved") + "\"}";
  4838. }
  4839. read = true;
  4840. }
  4841. body += (!streamIds.empty() ? utf8("]") : "") + "}" + (jsonp ? utf8(")") : "");
  4842. COMPRESS(header, body);
  4843. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  4844. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  4845. }
  4846. void protocol_admincgi::mode_viewxml(const streamData::streamID_t sid, int page,
  4847. const bool iponly, const bool ipcount) throw()
  4848. {
  4849. // abort as there's nothing generated for this now
  4850. if (page == 2)
  4851. {
  4852. sendMessageAndClose("HTTP/1.1 200 OK\r\nContent-Type:text/xml\r\n\r\n");
  4853. return;
  4854. }
  4855. if ((page > 6) || (page < 0))
  4856. {
  4857. page = 0;
  4858. }
  4859. utf8 header = "HTTP/1.1 200 OK\r\nContent-Type:text/xml\r\n",
  4860. body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><SHOUTCASTSERVER>";
  4861. if (page < 2)
  4862. {
  4863. stats::statsData_t data;
  4864. body += protocol_HTTPStyle::getStatsXMLBody(sid, true, true, m_socket, data);
  4865. }
  4866. if ((page == 0) || (page == 3))
  4867. {
  4868. time_t t = ::time(NULL);
  4869. body += "<LISTENERS>";
  4870. stats::currentClientList_t client_data;
  4871. stats::getClientDataForStream(sid, client_data);
  4872. map<utf8, size_t> ip_counts;
  4873. for (stats::currentClientList_t::const_iterator i = client_data.begin(); i != client_data.end(); ++i)
  4874. {
  4875. const utf8& host = ((*i)->m_hostName != (*i)->m_ipAddr ? (*i)->m_hostName : (*i)->m_ipAddr);
  4876. if (!ipcount)
  4877. {
  4878. if (!iponly)
  4879. {
  4880. body += "<LISTENER>"
  4881. "<HOSTNAME>" + aolxml::escapeXML(host) + "</HOSTNAME>"
  4882. "<USERAGENT>" + aolxml::escapeXML((*i)->m_userAgent) + "</USERAGENT>"
  4883. "<CONNECTTIME>" + tos(t - (*i)->m_startTime) + "</CONNECTTIME>"
  4884. "<UID>" + tos((*i)->m_unique) + "</UID>"
  4885. "<TYPE>" + tos((*i)->m_clientType) + "</TYPE>"
  4886. "<REFERER>" + aolxml::escapeXML((*i)->m_referer) + "</REFERER>"
  4887. "<XFF>" + aolxml::escapeXML((*i)->m_XFF) + "</XFF>"
  4888. "<GRID>" + tos((*i)->m_group) + "</GRID>"
  4889. "<TRIGGERS>" + tos((*i)->m_triggers) + "</TRIGGERS>"
  4890. "</LISTENER>";
  4891. }
  4892. else
  4893. {
  4894. body += "<LISTENER>"
  4895. "<HOSTNAME>" + aolxml::escapeXML(host) + "</HOSTNAME>"
  4896. "</LISTENER>";
  4897. }
  4898. }
  4899. else
  4900. {
  4901. ++ip_counts[host];
  4902. }
  4903. delete (*i);
  4904. }
  4905. if (ipcount)
  4906. {
  4907. for (map<utf8, size_t>::const_iterator i = ip_counts.begin(); i != ip_counts.end(); ++i)
  4908. {
  4909. body += "<LISTENER>"
  4910. "<HOSTNAME>" + aolxml::escapeXML((*i).first) + "</HOSTNAME>"
  4911. "<TOTAL>" + tos((*i).second) + "</TOTAL>"
  4912. "</LISTENER>";
  4913. }
  4914. }
  4915. body += "</LISTENERS>";
  4916. }
  4917. if ((page == 0) || (page == 4) || (page == 5))
  4918. {
  4919. streamData::streamHistory_t songHistory;
  4920. streamData::getStreamSongHistory(sid, songHistory);
  4921. // only provide this as an option feature so as not to bloat the main xml stats unnecessarily
  4922. if (!(page == 5))
  4923. {
  4924. body += "<SONGHISTORY>";
  4925. for (streamData::streamHistory_t::const_iterator i = songHistory.begin(); i != songHistory.end(); ++i)
  4926. {
  4927. body += "<SONG><PLAYEDAT>" + tos((*i).m_when) + "</PLAYEDAT>"
  4928. "<TITLE>" + aolxml::escapeXML((*i).m_title) + "</TITLE>" +
  4929. protocol_HTTPStyle::getCurrentXMLMetadataBody(true, (*i).m_metadata) + "</SONG>";
  4930. }
  4931. body += "</SONGHISTORY>";
  4932. }
  4933. else
  4934. {
  4935. body += protocol_HTTPStyle::getCurrentXMLMetadataBody(false, (!songHistory.empty() ? songHistory[0].m_metadata : ""));
  4936. }
  4937. }
  4938. if (page == 6)
  4939. {
  4940. const int maxUsers = gOptions.maxUser();
  4941. body += "<STREAMCONFIGS>"
  4942. "<REQUIRECONFIGS>" + tos(gOptions.requireStreamConfigs()) + "</REQUIRECONFIGS>"
  4943. "<SERVERMAXLISTENERS>" + (maxUsers > 0 ? tos(maxUsers) : "UNLIMITED") + "</SERVERMAXLISTENERS>"
  4944. "<SERVERMINBITRATE>" + tos(gOptions.minBitrate()) + "</SERVERMINBITRATE>"
  4945. "<SERVERMAXBITRATE>" + tos(gOptions.maxBitrate()) + "</SERVERMAXBITRATE>"
  4946. "<TOTALCONFIGS>";
  4947. config::streams_t streams;
  4948. gOptions.getStreamConfigs(streams);
  4949. utf8 block = "";
  4950. size_t moved = 0;
  4951. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  4952. {
  4953. const utf8 movedUrl = gOptions.stream_movedUrl((*i).second.m_streamID);
  4954. if (movedUrl.empty())
  4955. {
  4956. utf8 streamTag = ((*i).second.m_streamID > 1 ? "/stream/" + tos((*i).second.m_streamID) + "/" : "/");
  4957. if (!(*i).second.m_urlPath.empty())
  4958. {
  4959. streamTag = (*i).second.m_urlPath;
  4960. }
  4961. const utf8& authhash = (*i).second.m_authHash;
  4962. block += "<STREAMCONFIG id=\"" + tos((*i).second.m_streamID) + "\">"
  4963. "<STREAMAUTHHASH>" + aolxml::escapeXML(authhash.empty() ? "EMPTY" : !yp2::isValidAuthhash(authhash) ? "INVALID" : authhash) + "</STREAMAUTHHASH>"
  4964. "<STREAMPATH>" + aolxml::escapeXML(streamTag) + "</STREAMPATH>"
  4965. "<STREAMRELAYURL>" + aolxml::escapeXML((*i).second.m_relayUrl.url()) + "</STREAMRELAYURL>"
  4966. "<STREAMBACKUPURL>" + aolxml::escapeXML((*i).second.m_backupUrl.url()) + "</STREAMBACKUPURL>"
  4967. "<STREAMMAXLISTENERS>" + ((*i).second.m_maxStreamUser > 0 && (*i).second.m_maxStreamUser < gOptions.maxUser() ? tos((*i).second.m_maxStreamUser) : "SERVERMAXLISTENERS") + "</STREAMMAXLISTENERS>"
  4968. "<STREAMMINBITRATE>" + ((*i).second.m_minStreamBitrate > 0 ? tos((*i).second.m_minStreamBitrate) : "SERVERMINBITRATE") + "</STREAMMINBITRATE>"
  4969. "<STREAMMAXBITRATE>" + ((*i).second.m_maxStreamBitrate > 0 ? tos((*i).second.m_maxStreamBitrate) : "SERVERMAXBITRATE") + "</STREAMMAXBITRATE>"
  4970. "<STREAMPUBLIC>" + aolxml::escapeXML((*i).second.m_publicServer) + "</STREAMPUBLIC>"
  4971. "<STREAMALLOWRELAY>" + tos((*i).second.m_allowRelay) + "</STREAMALLOWRELAY>"
  4972. "<STREAMPUBLICRELAY>" + tos((*i).second.m_allowPublicRelay) + "</STREAMPUBLICRELAY>"
  4973. "</STREAMCONFIG>";
  4974. }
  4975. else
  4976. {
  4977. ++moved;
  4978. }
  4979. }
  4980. body += tos((streams.size() - moved)) + "</TOTALCONFIGS>" + block + "</STREAMCONFIGS>";
  4981. }
  4982. body += "</SHOUTCASTSERVER>";
  4983. COMPRESS(header, body);
  4984. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  4985. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  4986. }
  4987. void protocol_admincgi::mode_viewjson(const streamData::streamID_t sid, int page,
  4988. const bool iponly, const bool ipcount,
  4989. const uniString::utf8& callback) throw()
  4990. {
  4991. // abort as there's nothing generated for this now
  4992. if (page == 2)
  4993. {
  4994. sendMessageAndClose("HTTP/1.1 200 OK\r\nContent-Type:application/json;charset=utf-8\r\n\r\n");
  4995. return;
  4996. }
  4997. if (page > 6 || page < 0)
  4998. {
  4999. page = 0;
  5000. }
  5001. const bool jsonp = !callback.empty();
  5002. utf8 header = "HTTP/1.1 200 OK\r\nContent-Type:application/json;charset=utf-8\r\n",
  5003. body = (jsonp ? callback + "(" : "") + (page < 2 ? "{" : "");
  5004. if (page < 2)
  5005. {
  5006. stats::statsData_t data;
  5007. body += protocol_HTTPStyle::getStatsJSONBody(sid, true, true, m_socket, data);
  5008. }
  5009. if ((page == 0) || (page == 3))
  5010. {
  5011. time_t t = ::time(NULL);
  5012. body += (!page ? utf8(",\"listeners\":[") : "[");
  5013. stats::currentClientList_t client_data;
  5014. stats::getClientDataForStream(sid, client_data);
  5015. map<utf8, size_t> ip_counts;
  5016. for (stats::currentClientList_t::const_iterator i = client_data.begin(); i != client_data.end(); ++i)
  5017. {
  5018. const utf8& host = ((*i)->m_hostName != (*i)->m_ipAddr ? (*i)->m_hostName : (*i)->m_ipAddr);
  5019. if (!ipcount)
  5020. {
  5021. if (!iponly)
  5022. {
  5023. body += (i != client_data.begin() ? utf8(",") : "") +
  5024. "{"
  5025. "\"hostname\":\"" + escapeJSON(host) + "\","
  5026. "\"useragent\":\"" + escapeJSON((*i)->m_userAgent) + "\","
  5027. "\"connecttime\":" + tos(t - (*i)->m_startTime) + ","
  5028. "\"uid\":" + tos((*i)->m_unique) + ","
  5029. "\"type\":" + tos((*i)->m_clientType) + ","
  5030. "\"referer\":\"" + escapeJSON((*i)->m_referer) + "\","
  5031. "\"xff\":\"" + escapeJSON((*i)->m_XFF) + "\","
  5032. "\"grid\":" + tos((*i)->m_group) + ","
  5033. "\"triggers\":" + tos((*i)->m_triggers) + ""
  5034. "}";
  5035. }
  5036. else
  5037. {
  5038. body += (i != client_data.begin() ? utf8(",") : "") +
  5039. "{"
  5040. "\"hostname\":\"" + escapeJSON(host) + "\""
  5041. "}";
  5042. }
  5043. }
  5044. else
  5045. {
  5046. ++ip_counts[host];
  5047. }
  5048. delete (*i);
  5049. }
  5050. if (ipcount)
  5051. {
  5052. for (map<utf8, size_t>::const_iterator i = ip_counts.begin(); i != ip_counts.end(); ++i)
  5053. {
  5054. body += (i != ip_counts.begin() ? utf8(",") : "") +
  5055. "{"
  5056. "\"hostname\":\"" + escapeJSON((*i).first) + "\","
  5057. "\"total\":" + tos((*i).second) + ""
  5058. "}";
  5059. }
  5060. }
  5061. body += "]";
  5062. }
  5063. if ((page == 0) || (page == 4) || (page == 5))
  5064. {
  5065. streamData::streamHistory_t songHistory;
  5066. streamData::getStreamSongHistory(sid, songHistory);
  5067. // only provide this as an option feature so as not to bloat the main xml stats unnecessarily
  5068. if (!(page == 5))
  5069. {
  5070. bool first = true;
  5071. body += (!page ? utf8(",\"songs\":[") : "[");
  5072. for (streamData::streamHistory_t::const_iterator i = songHistory.begin(); i != songHistory.end(); ++i)
  5073. {
  5074. body += (!first ? utf8(",") : "") + "{\"playedat\":" +
  5075. tos((*i).m_when) + "," "\"title\":\"" +
  5076. escapeJSON((*i).m_title) + "\",\"metadata\":" +
  5077. protocol_HTTPStyle::getCurrentJSONMetadataBody((*i).m_metadata) + "}";
  5078. first = false;
  5079. }
  5080. body += "]";
  5081. }
  5082. else
  5083. {
  5084. body += protocol_HTTPStyle::getCurrentJSONMetadataBody((!songHistory.empty() ? songHistory[0].m_metadata : ""));
  5085. }
  5086. }
  5087. if (page == 6)
  5088. {
  5089. const int maxUsers = gOptions.maxUser();
  5090. body += "{"
  5091. "\"requireconfigs\":" + tos(gOptions.requireStreamConfigs()) + ","
  5092. "\"maxlisteners\":" + (maxUsers > 0 ? tos(maxUsers) : "\"unlimited\"") + ","
  5093. "\"minbitrate\":" + tos(gOptions.minBitrate()) + ","
  5094. "\"maxbitrate\":" + tos(gOptions.maxBitrate()) + ",";
  5095. config::streams_t streams;
  5096. gOptions.getStreamConfigs(streams);
  5097. bool read = false;
  5098. utf8 block = "";
  5099. size_t moved = 0;
  5100. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  5101. {
  5102. const utf8 movedUrl = gOptions.stream_movedUrl((*i).second.m_streamID);
  5103. if (movedUrl.empty())
  5104. {
  5105. utf8 streamTag = ((*i).second.m_streamID > 1 ? "/stream/" + tos((*i).second.m_streamID) + "/" : "/");
  5106. if (!(*i).second.m_urlPath.empty())
  5107. {
  5108. streamTag = (*i).second.m_urlPath;
  5109. }
  5110. utf8 authhash = (*i).second.m_authHash;
  5111. block += (read ? utf8(",") : "") +
  5112. "{"
  5113. "\"id\":" + tos((*i).second.m_streamID) + ","
  5114. "\"authhash\":\"" + escapeJSON(authhash.empty() ? "empty" : !yp2::isValidAuthhash(authhash) ? "invalid" : authhash) + "\","
  5115. "\"path\":\"" + escapeJSON(streamTag) + "\","
  5116. "\"relayurl\":\"" + escapeJSON((*i).second.m_relayUrl.url()) + "\","
  5117. "\"backupurl\":\"" + escapeJSON((*i).second.m_backupUrl.url()) + "\","
  5118. "\"maxlisteners\":\"" + escapeJSON(((*i).second.m_maxStreamUser > 0) && ((*i).second.m_maxStreamUser < gOptions.maxUser()) ? tos((*i).second.m_maxStreamUser) : escapeJSON("maxlisteners")) + "\","
  5119. "\"minbitrate\":\"" + escapeJSON((*i).second.m_minStreamBitrate > 0 ? tos((*i).second.m_minStreamBitrate) : escapeJSON("minbitrate")) + "\","
  5120. "\"maxbitrate\":\"" + escapeJSON((*i).second.m_maxStreamBitrate > 0 ? tos((*i).second.m_maxStreamBitrate) : escapeJSON("maxbitrate")) + "\","
  5121. "\"public\":\"" + escapeJSON((*i).second.m_publicServer) + "\","
  5122. "\"allowrelay\":\"" + tos((*i).second.m_allowRelay) + "\","
  5123. "\"publicrelay\":\"" + tos((*i).second.m_allowPublicRelay) + "\""
  5124. "}";
  5125. read = true;
  5126. }
  5127. else
  5128. {
  5129. ++moved;
  5130. }
  5131. }
  5132. const size_t total = (streams.size() - moved);
  5133. body += "\"total\":\"" + tos(total) + "\"" +
  5134. (total > 0 ? ",\"streams\":[" : "") + block +
  5135. (total > 0 ? utf8("]") : "") + "}";
  5136. }
  5137. body += (page < 2 ? utf8("}") : "") + (jsonp ? ")" : "");
  5138. COMPRESS(header, body);
  5139. header += "Content-Length:" + tos(body.size()) + "\r\n\r\n";
  5140. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  5141. }
  5142. void protocol_admincgi::mode_sources(const uniString::utf8& host) throw()
  5143. {
  5144. utf8 header = MSG_NO_CLOSE_200,
  5145. body = getServerAdminHeader("Server Source Connection Details") +
  5146. "<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" width=\"100%\">"
  5147. "<tr><td class=\"tsp\" align=\"center\">" +
  5148. utf8(gOptions.requireStreamConfigs() ? "Sources are only able to connect on the configured streams shown" :
  5149. "Sources are able to connect on any \"Stream ID\" (using the appropriate details)") +
  5150. "</td></tr></table>"
  5151. "<div><br>"
  5152. "<div style=\"width:19.5em;margin: 0 0 1em 1em;\" class=\"infb\">"
  5153. "<div align=\"center\" class=\"infh\"><b>Information</b></div>"
  5154. "Here are the login details to enter in your chosen source software so it can then be used to connect to the server.<br><br>"
  5155. "<b>Note:</b> Names of options in the source software may vary from those shown.<br><br>"
  5156. "<b><font color=\"red\">*</font></b> This may not be correct and is a best guess from the current connection.<br><br><hr><br>"
  5157. "The '<b>Legacy Password</b>' is for use with legacy sources (which are sources that are not able to directly specify the "
  5158. "desired stream number).<br><br>This allows for use of any Shoutcast compatible source on any of the currently configured streams.<br><br>"
  5159. "If connecting a legacy source to stream #1, the '<b>Password</b>' value can be used.<br><br><hr><br>"
  5160. "The example JSON-P response uses callback=func which can be changed to a custom value as required for usage.<br><br><hr><br>"
  5161. "For further information on connecting sources to the server, as well as ensuring that all of the required ports have been opened, "
  5162. "see <a target=\"_blank\" href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_Server_Source_Support\"><b>this wiki page</b></a>.<br><br></div>";
  5163. config::streams_t streams;
  5164. gOptions.getStreamConfigs(streams);
  5165. utf8 ids = "";
  5166. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  5167. {
  5168. ids += (i != streams.begin() ? ", ": "") + tos((*i).second.m_streamID);
  5169. // skip over moved streams as they cannot be used, though we include the
  5170. // streamid above (whether or not that'll confuse people i do not know).
  5171. const utf8 movedUrl = gOptions.stream_movedUrl((*i).second.m_streamID);
  5172. if (movedUrl.empty())
  5173. {
  5174. int maxbitrate = ((*i).second.m_maxStreamBitrate > 0 ? (*i).second.m_maxStreamBitrate : gOptions.maxBitrate()),
  5175. minbitrate = ((*i).second.m_minStreamBitrate > 0 ? (*i).second.m_minStreamBitrate : gOptions.minBitrate());
  5176. // test for being a relay which is active - if so then we need to not show
  5177. // direct source login details as they will not be able to connect anyway
  5178. bool noEntry = false, isRelay = (*i).second.m_relayUrl.isSet();
  5179. if (isRelay && streamData::isRelayActive((*i).second.m_streamID, noEntry))
  5180. {
  5181. body += "<div class=\"infb\" style=\"width:19.5em;word-wrap:break-word;margin: 0 0 1em 1em;\">"
  5182. "<div align=\"center\" class=\"infh\">"
  5183. "<b>Stream #" + tos((*i).second.m_streamID) + "</b></div>"
  5184. "This stream has been configured for use as a relay which is currently active.<br><br>"
  5185. "Any source connections attempted will be blocked whilst the relay is active.<br><br>"
  5186. "Password: <b>" + aolxml::escapeXML((*i).second.m_password) + "</b><br>"
  5187. "Source: <b>" + urlLink(niceURL((*i).second.m_relayUrl.url())) + "</b><br>" +
  5188. (!(*i).second.m_backupUrl.url().empty() ? "Backup Source: <b>" +
  5189. urlLink(niceURL((*i).second.m_backupUrl.url())) + "</b><br>" : "");
  5190. }
  5191. // otherwise show direct source login details for specific as well as generic stream
  5192. // logins (even if configured to be a relay as long as it is inactive at the time)
  5193. else
  5194. {
  5195. body += "<div class=\"infb\" style=\"width:19.5em;word-wrap:break-word;margin: 0 0 1em 1em;\">"
  5196. "<div align=\"center\" class=\"infh\"><b>Stream #" + tos((*i).second.m_streamID) + "</b></div>" +
  5197. (isRelay ? "<b>Note:</b> Configured as a relay to use:<br><b>" +
  5198. niceURL((*i).second.m_relayUrl.url()) + "</b><br><br>" : "") +
  5199. "Stream ID: <b>" + tos((*i).second.m_streamID) + "</b><br>"
  5200. "Server Address: <b>" + (!host.empty() ? host : "<enter_server_address>") + "</b> <b>(<font color=\"red\">*</font>)</b><br>"
  5201. "Source Port: <b>" + tos(gOptions.portBase()) + "</b><br><br>" +
  5202. "Password: <b>" + aolxml::escapeXML((*i).second.m_password) + "</b><br>" +
  5203. ((*i).second.m_streamID > 1 && (g_legacyPort > 0) ? "Legacy Password: <b>" +
  5204. aolxml::escapeXML((*i).second.m_password) + ":#" + tos((*i).second.m_streamID) + "</b><br><br>" : "<br>") +
  5205. "Min Bitrate Allowed: <b>" + (!minbitrate ? "Unlimited" : tos(minbitrate / 1000) + " kbps") + "</b><br>"
  5206. "Max Bitrate Allowed: <b>" + (!maxbitrate ? "Unlimited" : tos(maxbitrate / 1000) + " kbps") + "</b><br><br>"
  5207. "Protocol Mode: <b>" + ((g_legacyPort > 0) ? "v2, v1" : "v2") + "</b><br>";
  5208. }
  5209. const utf8 address = "http://" + ((!host.empty() ? host : "<enter_server_address>") + ":" + tos(gOptions.portBase())),
  5210. params = "?sid=" + tos((*i).second.m_streamID) + "&amp;pass=" + aolxml::escapeXML((*i).second.m_password);
  5211. body += "<br><hr><br>Listener Playlist(s):<br><b>"
  5212. "<a href=\"" + address + "/listen.pls?sid=" + tos((*i).second.m_streamID) + "\">PLS</a>,&nbsp;&nbsp;"
  5213. "<a href=\"" + address + "/listen.m3u?sid=" + tos((*i).second.m_streamID) + "\">M3U</a>,&nbsp;&nbsp;"
  5214. "<a href=\"" + address + "/listen.asx?sid=" + tos((*i).second.m_streamID) + "\">ASX</a>,&nbsp;&nbsp;"
  5215. "<a href=\"" + address + "/listen.xspf?sid=" + tos((*i).second.m_streamID) + "\">XSPF</a>,&nbsp;&nbsp;"
  5216. "<a href=\"" + address + "/listen.qtl?sid=" + tos((*i).second.m_streamID) + "\">QTL</a></b>"
  5217. "<br><br>Direct Stream URL(s):<br><b>"
  5218. "<a title=\"Flash\" alt=\"Flash\" "
  5219. "href=\"" + address + getStreamPath((*i).second.m_streamID) + "?type=.flv\">"
  5220. "<img border=\"0\" style=\"vertical-align:bottom\" src=\"images/flash.png\"> FLV</a>,&nbsp;&nbsp;"
  5221. "<a title=\"HTTP / HTML5\" alt=\"HTTP / HTML5\" "
  5222. "href=\"" + address + getStreamPath((*i).second.m_streamID) + "?type=http\">"
  5223. "<img border=\"0\" style=\"vertical-align:bottom\" src=\"images/html5.png\"> HTTP</a>,&nbsp;&nbsp;"
  5224. "<a title=\"Shoutcast 1.x\" alt=\"Shoutcast 1.x\" "
  5225. "href=\"" + address + getStreamPath((*i).second.m_streamID) + "?type=sc1\">"
  5226. "<img border=\"0\" style=\"vertical-align:bottom\" src=\"images/favicon.ico\"> 1.x</a>,&nbsp;&nbsp;"
  5227. "<a title=\"Shoutcast 2.x\" alt=\"Shoutcast 2.x\" "
  5228. "href=\"" + address + getStreamPath((*i).second.m_streamID) + "?type=sc2\">"
  5229. "<img border=\"0\" style=\"vertical-align:bottom\" src=\"images/favicon.ico\"> 2.x</a></b>"
  5230. "<br><br>History:<br><b>"
  5231. "<a href=\"" + address + "/played" + params + "&amp;type=xml\">XML</a>,&nbsp;&nbsp;"
  5232. "<a href=\"" + address + "/played" + params + "&amp;type=json\">JSON</a>,&nbsp;&nbsp;"
  5233. "<a href=\"" + address + "/played" + params + "&amp;type=json&amp;callback=func\">JSON-P</a></b>"
  5234. "<br><br>Stream Statistics:<br><b>"
  5235. "<a href=\"" + address + "/stats" + params + "\">XML</a>,&nbsp;&nbsp;"
  5236. "<a href=\"" + address + "/stats" + params + "&amp;json=1\">JSON</a>,&nbsp;&nbsp;"
  5237. "<a href=\"" + address + "/stats" + params + "&amp;json=1&amp;callback=func\">JSON-P</a></b><br></div>";
  5238. }
  5239. }
  5240. if (!gOptions.requireStreamConfigs())
  5241. {
  5242. const int minbitrate = gOptions.minBitrate(), maxbitrate = gOptions.maxBitrate();
  5243. body += "<div class=\"infb\" style=\"width:19.5em;word-wrap:break-word;margin: 0 0 1em 1em;\">"
  5244. "<div align=\"center\" class=\"infh\"><b>All" + (!ids.empty() ? " Other" : (utf8)"") + " Streams</b></div>"
  5245. "Stream ID: <b>&lt;any value" + (!ids.empty() ? " other than " + ids : "") + "&gt;</b><br>"
  5246. "Server Address: <b>" + aolxml::escapeXML(!host.empty() ? host : "<enter_server_address>") + "</b> <b>(<font color=\"red\">*</font>)</b><br>"
  5247. "Server Port: <b>" + tos(gOptions.portBase()) + "</b><br><br>" +
  5248. "Password: <b>" + aolxml::escapeXML(gOptions.password()) + "</b><br>" +
  5249. ((g_legacyPort > 0) ? "Legacy Password: <b>" + aolxml::escapeXML(gOptions.password()) + ":#xx</b><br><br>" : "<br>") +
  5250. "Min Bitrate Allowed: <b>" + (!minbitrate ? "Unlimited" : tos(minbitrate / 1000) + " kbps") + "</b><br>"
  5251. "Max Bitrate Allowed: <b>" + (!maxbitrate ? "Unlimited" : tos(maxbitrate / 1000) + " kbps") + "</b><br><br>"
  5252. "Protocol Mode: <b>" + ((g_legacyPort > 0) ? "v2, v1" : "v2") + "</b><br>";
  5253. const utf8 address = "http://" + ((!host.empty() ? host : "<enter_server_address>") + ":" + tos(gOptions.portBase())),
  5254. params = "?sid=xx&amp;pass=" + aolxml::escapeXML(gOptions.password());
  5255. body += "<br><hr><br>Listener Playlist(s):<br><b>"
  5256. "<a href=\"" + address + "/listen.pls?sid=xx\">PLS</a>,&nbsp;&nbsp;"
  5257. "<a href=\"" + address + "/listen.m3u?sid=xx\">M3U</a>,&nbsp;&nbsp;"
  5258. "<a href=\"" + address + "/listen.asx?sid=xx\">ASX</a>,&nbsp;&nbsp;"
  5259. "<a href=\"" + address + "/listen.xspf?sid=xx\">XSPF</a>,&nbsp;&nbsp;"
  5260. "<a href=\"" + address + "/listen.qtl?sid=xx\">QTL</a></b>"
  5261. "<br><br>History:<br><b>"
  5262. "<a href=\"" + address + "/played" + params + "&amp;type=xml\">XML</a>,&nbsp;&nbsp;"
  5263. "<a href=\"" + address + "/played" + params + "&amp;type=json\">JSON</a>,&nbsp;&nbsp;"
  5264. "<a href=\"" + address + "/played" + params + "&amp;type=json&amp;callback=func\">JSON-P</a></b>"
  5265. "<br><br>Stream Statistics:<br><b>"
  5266. "<a href=\"" + address + "/stats" + params + "\">XML</a>,&nbsp;&nbsp;"
  5267. "<a href=\"" + address + "/stats" + params + "&amp;json=1\">JSON</a>,&nbsp;&nbsp;"
  5268. "<a href=\"" + address + "/stats" + params + "&amp;json=1&amp;callback=func\">JSON-P</a></b>"
  5269. "<br><br><b>Note:</b> Replace the '<b>xx</b>' in '<b>sid=xx</b>' in all of the example links "
  5270. "and in the '<b>Legacy Password</b>' with the stream number.<br></div>";
  5271. }
  5272. body += "</div>" + getUptimeScript() + getIEFlexFix() + getfooterStr();
  5273. COMPRESS(header, body);
  5274. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  5275. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  5276. }
  5277. void protocol_admincgi::mode_adgroups() throw()
  5278. {
  5279. utf8 header = MSG_NO_CLOSE_200,
  5280. body = getServerAdminHeader("Server Advert Group Details") +
  5281. "<div style=\"padding-right:1em;\"><br>"
  5282. "<table align=\"center\" width=\"100%\"><tr valign=\"top\">"
  5283. "<td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
  5284. "<tr><td valign=\"top\">"
  5285. "<div style=\"width:13em;\" class=\"infb\">"
  5286. "<div align=\"center\" class=\"infh\"><b>Information</b></div>"
  5287. "Here you can see which active stream(s) have adverts enabled and their status of obtaining the advert details."
  5288. "<br><br>This can help to see if a listener should be receiving adverts or not by "
  5289. "checking for the listener's group id with the group ids shown for the required stream.<br><br></div>"
  5290. "</td><td valign=\"top\" width=\"100%\">"
  5291. "<table class=\"en\" style=\"border:0;text-align:center;word-wrap:break-word;\" "
  5292. "cellpadding=\"3\" cellspacing=\"0\" width=\"100%\" align=\"center\">";
  5293. const streamData::streamIDs_t streamIds = streamData::getStreamIds();
  5294. if (!streamIds.empty())
  5295. {
  5296. body += "<colgroup><col width=\"15%\"></colgroup>"
  5297. "<tr class=\"tll\"><td>Stream #</td><td>Advert Group(s)</td></tr>";
  5298. for (streamData::streamIDs_t::const_iterator i = streamIds.begin(); i != streamIds.end(); ++i)
  5299. {
  5300. streamData *sd = streamData::accessStream((*i));
  5301. if (sd)
  5302. {
  5303. if (sd->isSourceConnected((*i)))
  5304. {
  5305. body += "<tr><td><b>" + tos((*i)) + "</b></td>"
  5306. "<td style=\"max-width:0;text-align:left;\">" +
  5307. sd->getAdvertGroup() + "</td></tr>";
  5308. }
  5309. sd->releaseStream();
  5310. }
  5311. }
  5312. }
  5313. else
  5314. {
  5315. body += "<tr><td style=\"border:0\">There are no active streams.</b></td></tr>";
  5316. }
  5317. body += "</table></td></tr></table></td></tr></table></div>" +
  5318. getUptimeScript() + getIEFlexFix() + getfooterStr();
  5319. COMPRESS(header, body);
  5320. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  5321. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  5322. }
  5323. void protocol_admincgi::mode_debug(const uniString::utf8& option, const int on_off, const bool adminRefer) throw()
  5324. {
  5325. struct debug_options {
  5326. utf8 option;
  5327. utf8 desc;
  5328. utf8 msg;
  5329. bool value;
  5330. };
  5331. debug_options debug[] = {
  5332. {"Listener Connections", "", ""},
  5333. {"shoutcast1clientdebug", "Shoutcast 1.x Listener Connections", "Used to diagnose connection issues with listener connections using the legacy Shoutcast 1.x protocol"
  5334. "<br>(e.g. HTTP connections indicating they support icy-metadata).", gOptions.shoutcast1ClientDebug()},
  5335. {"shoutcast2clientdebug", "Shoutcast 2.x Listener Connections", "Used to diagnose connection issues with listener connections using the Shoutcast 2.x protocol.", gOptions.shoutcast2ClientDebug()},
  5336. {"httpclientdebug", "HTTP Listener Connections", "Used to diagnose connection issues with listener connections using the HTTP protocol.", gOptions.HTTPClientDebug()},
  5337. {"flvclientdebug", "FLV Listener Connections", "Used to diagnose connection issues with listener connections using the FLV encapsulation.", gOptions.flvClientDebug()},
  5338. #if 0
  5339. {"m4aclientdebug", "M4A Listener Connections", "Used to diagnose connection issues with listener connections using the M4A encapsulation.", gOptions.m4aClientDebug()},
  5340. #endif
  5341. {"Direct Source Connections", "", ""},
  5342. {"shoutcastsourcedebug", "Shoutcast 1.x Source Connections", "Used to diagnose connection issues with source connections using the legacy Shoutcast 1.x protocol.", gOptions.shoutcastSourceDebug()},
  5343. {"uvox2sourcedebug", "Shoutcast 2.x Source Connections", "Used to diagnose connection issues with source connections using the Shoutcast 2.x protocol.", gOptions.uvox2SourceDebug()},
  5344. {"httpsourcedebug", "HTTP Source Connections", "Used to diagnose connection issues with source connections using HTTP PUT protocol (e.g. Icecast sources).", gOptions.HTTPSourceDebug()},
  5345. {"Relay Source Connections", "", ""},
  5346. {"relayshoutcastdebug", "Shoutcast 1.x Relay Connections", "Used to diagnose connection issues with relay connections using the legacy Shoutcast 1.x protocol.", gOptions.relayShoutcastDebug()},
  5347. {"relayuvoxdebug", "Shoutcast 2.x Relay Connections", "Used to diagnose connection issues with relay connections using the Shoutcast 2.x protocol.", gOptions.relayUvoxDebug()},
  5348. {"relaydebug", "Common Relay Handling", "Used to diagnose issues with general relay handling when a relay connection begins (non-protcool specific).", gOptions.relayDebug()},
  5349. {"HTTP Connections", "", ""},
  5350. {"httpstyledebug", "HTTP Requests", "Used to inspect HTTP requests made to the server (e.g. listener or statistic requests).", gOptions.httpStyleDebug()},
  5351. {"webclientdebug", "HTTP Connections", "Used to inspect and diagnose issues with HTTP connections issued by the server.", gOptions.webClientDebug()},
  5352. {"Shoutcast Services", "", ""},
  5353. {"admetricsdebug", "Advert & Metrics Handling", "Used to inspect and diagnose issues with the advert and metric activity for client connections.", gOptions.adMetricsDebug()},
  5354. {"yp2debug", "YP / Directory Connections", "Used to diagnose failures to connect to the Directory servers or to be listed.", gOptions.yp2Debug()},
  5355. #if defined(_DEBUG) || defined(DEBUG)
  5356. // this is not enabled as we don't really want to promote the existence of this
  5357. {"authdebug", "Listener Auth Handling", "Used to diagnose issues with the client auth handling when clients connect to the stream.", gOptions.authDebug()},
  5358. #endif
  5359. {"Miscellaneous", "", ""},
  5360. {"streamdatadebug", "Common Stream Handling", "Used to diagnose issues with general streaming code (non-protcool specific).", gOptions.streamDataDebug()},
  5361. {"statsdebug", "Client Statistics", "Used to inspect client statistics tracked by the server.", gOptions.statsDebug()},
  5362. {"microserverdebug", "Common Server Activity", "Used to diagnose and track common server activity.", gOptions.microServerDebug()},
  5363. {"threadrunnerdebug", "Thread Manager", "Used to diagnose and track the processing of threads by the thread manager.", gOptions.threadRunnerDebug()},
  5364. };
  5365. if (option.empty())
  5366. {
  5367. utf8 header = "HTTP/1.1 200 OK\r\n"
  5368. "Cache-Control:no-cache\r\n"
  5369. "Content-Type:text/html;charset=utf-8\r\n",
  5370. body = getServerAdminHeader("Server Debugging Options") +
  5371. "<div><br>"
  5372. "<table align=\"center\" width=\"100%\"><tr valign=\"top\">"
  5373. "<td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
  5374. "<tr valign=\"top\"><td>"
  5375. "<div style=\"max-width:15em;\" class=\"infb\">"
  5376. "<div align=\"center\" class=\"infh\"><b>Information</b></div>"
  5377. "Here you can find are all debugging options provided by the "
  5378. "DNAS server.<br><br>Changing the debugging options will update "
  5379. "the value saved in the DNAS server configuration file(s) as "
  5380. "needed.<br><br>Any changes are applied immediately.<br><br><hr><br>"
  5381. "<div align=\"left\"><b>All Options</b><br><br></div>"
  5382. "<input class=\"submit\" type=\"button\" onclick=\"toggle('all','true',1);\" name=\"all\" id=\"all\" value=\"Enable\">"
  5383. "&nbsp;&nbsp;&nbsp;<input class=\"submit\" type=\"button\" onclick=\"toggle('all','false',1);\" name=\"all\" id=\"all\" value=\"Disable\">"
  5384. "<br><br><hr><br>"
  5385. "<div align=\"left\"><b>Listener Options</b><br><br></div>"
  5386. "<input class=\"submit\" type=\"button\" onclick=\"toggle('listener','true',2);\" name=\"listener\" id=\"listener\" value=\"Enable\">"
  5387. "&nbsp;&nbsp;&nbsp;<input class=\"submit\" type=\"button\" onclick=\"toggle('listener','false',2);\" name=\"listener\" id=\"listener\" value=\"Disable\">"
  5388. "<br><br><hr><br>"
  5389. "<div align=\"left\"><b>Source Options</b><br><br></div>"
  5390. "<input class=\"submit\" type=\"button\" onclick=\"toggle('source','true',3);\" name=\"source\" id=\"sources\" value=\"Enable\">"
  5391. "&nbsp;&nbsp;&nbsp;<input class=\"submit\" type=\"button\" onclick=\"toggle('source','false',3);\" name=\"source\" id=\"source\" value=\"Disable\">"
  5392. "<br><br><hr><br>"
  5393. "<div align=\"left\"><b>Force Short Sends</b> <div id=\"forceshortsendsval\" "
  5394. "style=\"display:inline-block\">[" + (gOptions.forceShortSends() ? "Enabled" :
  5395. "Disabled") + "]</div><br><br>This inserts delays into sending stream(s)"
  5396. "to replicate network limiting and bandwidth issues (Default: <b>Disabled</b>).<br><br></div>"
  5397. "<input class=\"submit\" type=\"button\" onclick=\"toggle('forceshortsends','true',4);\" name=\"forceshortsends\" id=\"forceshortsends\" value=\"Enable\">"
  5398. "&nbsp;&nbsp;&nbsp;<input class=\"submit\" type=\"button\" onclick=\"toggle('forceshortsends','false',4);\" name=\"forceshortsends\" id=\"forceshortsends\" value=\"Disable\">"
  5399. "<br><br><hr><br>"
  5400. "<div align=\"left\"><b>Rate Limiting</b> <div "
  5401. "id=\"ratelimitval\" style=\"display:inline-block\">"
  5402. "[" + (gOptions.rateLimit() ? "Enabled" : "Disabled") +
  5403. "]</div><br><br>Controls the rate of output to even "
  5404. "it out and prefer sending larger blocks in one go instead of "
  5405. "doing smaller blocks more often (Default: <b>Enabled</b>).<br><br></div>"
  5406. "<input class=\"submit\" type=\"button\" onclick=\"toggle('ratelimit','true',5);\" name=\"ratelimit\" id=\"ratelimit\" value=\"Enable\">"
  5407. "&nbsp;&nbsp;&nbsp;<input class=\"submit\" type=\"button\" onclick=\"toggle('ratelimit','false',5);\" name=\"ratelimit\" id=\"ratelimit\" value=\"Disable\">"
  5408. "</div><td>";
  5409. for (size_t i = 0; i < sizeof(debug) / sizeof(debug[0]); i++)
  5410. {
  5411. if (!debug[i].desc.empty())
  5412. {
  5413. body += "<input autocomplete=\"off\" type=\"checkbox\" onclick=\"toggle('" +
  5414. debug[i].option + "',$('" + debug[i].option +
  5415. "').checked,0)\" name=\"" + debug[i].option +
  5416. "\" id=\"" + debug[i].option + "\"" +
  5417. (debug[i].value ? " checked=\"true\"" : " ") + " value=\"" +
  5418. (debug[i].value ? "1" : "0") + "\">" "<label for=\"" +
  5419. debug[i].option + "\" title=\"" + debug[i].option +
  5420. "\" style=\"padding-left: 7px;\"><b>" + debug[i].desc + "</b></label>"
  5421. "<div style=\"padding:5px 0 0 27px;\">" + debug[i].msg + "</div><br>";
  5422. }
  5423. else
  5424. {
  5425. body += (i ? "<br>" : (utf8)"") + "<b><u>" + debug[i].option + "</u>:</b><br><br>";
  5426. }
  5427. }
  5428. body += "</td></tr></table></td></tr></table></div>"
  5429. + getUptimeScript() +
  5430. "<script type=\"text/javascript\">" EL
  5431. "function toggle(opt, on, mode) {" EL
  5432. "if(window.XMLHttpRequest){" EL
  5433. "xmlhttp=new XMLHttpRequest();" EL
  5434. "}else{" EL
  5435. "xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");" EL
  5436. "}" EL
  5437. "xmlhttp.open(\"GET\",\"admin.cgi?pass="+gOptions.adminPassword()+"&mode=debug&option=\"+opt+\"&on=\"+on,true);" EL
  5438. "xmlhttp.send(null);" EL
  5439. "if(mode == 1){" EL
  5440. "var labels = document.getElementsByTagName('LAB EL');" EL
  5441. "for (var i = 0; i < labels.length; i++) {" EL
  5442. "if (labels[i].htmlFor != '') {" EL
  5443. "$(labels[i].htmlFor).checked=(on=='true'?'true':'');"
  5444. "}" EL
  5445. "}" EL
  5446. "}" EL
  5447. "else if(mode == 2){" EL
  5448. "var labels = ['shoutcast1clientdebug', 'shoutcast2clientdebug', 'httpclientdebug', 'flvclientdebug'/*, 'm4aclientdebug'*/];" EL
  5449. "for (var i = 0; i < labels.length; i++) {" EL
  5450. "$(labels[i]).checked=(on=='true'?'true':'');"
  5451. "}" EL
  5452. "}" EL
  5453. "else if(mode == 3){" EL
  5454. "var labels = ['shoutcastsourcedebug', 'uvox2sourcedebug', 'httpsourcedebug', 'relayshoutcastdebug', 'relayuvoxdebug', 'relaydebug'];" EL
  5455. "for (var i = 0; i < labels.length; i++) {" EL
  5456. "$(labels[i]).checked=(on=='true'?'true':'');"
  5457. "}" EL
  5458. "}" EL
  5459. "else if(mode == 4){" EL
  5460. "$('forceshortsendsval').innerHTML=(on=='true'?'[Enabled]':'[Disabled]');" EL
  5461. "}" EL
  5462. "else if(mode == 5){" EL
  5463. "$('ratelimitval').innerHTML=(on=='true'?'[Enabled]':'[Disabled]');" EL
  5464. "}" EL
  5465. "}</script>" + getIEFlexFix() + getfooterStr();
  5466. COMPRESS(header, body);
  5467. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  5468. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  5469. }
  5470. else
  5471. {
  5472. if (option == "all")
  5473. {
  5474. ILOG(LOGNAME + utf8(on_off ? "Enabling" : "Disabling") + " all debugging options");
  5475. for (size_t i = 0; i < sizeof(debug) / sizeof(debug[0]); i++)
  5476. {
  5477. if (!debug[i].desc.empty())
  5478. {
  5479. // always set even if the saving fails so we've got something working
  5480. try
  5481. {
  5482. gOptions.setOption(debug[i].option, utf8(tos(on_off)));
  5483. }
  5484. catch(const exception &)
  5485. {
  5486. }
  5487. bool handled = false, idHandled = false;
  5488. // if we get a clear then just remove from the config and reload the page
  5489. if (gOptions.editConfigFileEntry(0, gOptions.confFile(), debug[i].option, tos(on_off),
  5490. true, handled, idHandled, true) == false)
  5491. {
  5492. ELOG(LOGNAME "Error saving debug option: `" + debug[i].option + "'");
  5493. }
  5494. }
  5495. }
  5496. }
  5497. else if (option == "listener")
  5498. {
  5499. ILOG(LOGNAME + utf8(on_off ? "Enabling" : "Disabling") + " all listener debugging options");
  5500. const utf8 options[] = {"shoutcast1clientdebug", "shoutcast2clientdebug", "httpclientdebug", "flvclientdebug"/*, "m4aclientdebug"*/};
  5501. for (size_t i = 0; i < sizeof(options) / sizeof(options[0]); i++)
  5502. {
  5503. // always set even if the saving fails so we've got something working
  5504. try
  5505. {
  5506. gOptions.setOption(options[i], utf8(tos(on_off)));
  5507. }
  5508. catch(const exception &)
  5509. {
  5510. }
  5511. bool handled = false, idHandled = false;
  5512. // if we get a clear then just remove from the config and reload the page
  5513. if (gOptions.editConfigFileEntry(0, gOptions.confFile(), options[i], tos(on_off),
  5514. true, handled, idHandled, true) == false)
  5515. {
  5516. ELOG(LOGNAME "Error saving debug option: `" + options[i] + "'");
  5517. }
  5518. }
  5519. }
  5520. else if (option == "source")
  5521. {
  5522. ILOG(LOGNAME + utf8(on_off ? "Enabling" : "Disabling") + " all source debugging options");
  5523. const utf8 options[] = {"shoutcastsourcedebug", "uvox2sourcedebug", "httpsourcedebug",
  5524. "relayshoutcastdebug", "relayuvoxdebug", "relaydebug"};
  5525. for (size_t i = 0; i < sizeof(options) / sizeof(options[0]); i++)
  5526. {
  5527. // always set even if the saving fails so we've got something working
  5528. try
  5529. {
  5530. gOptions.setOption(options[i], utf8(tos(on_off)));
  5531. }
  5532. catch(const exception &)
  5533. {
  5534. }
  5535. bool handled = false, idHandled = false;
  5536. // if we get a clear then just remove from the config and reload the page
  5537. if (gOptions.editConfigFileEntry(0, gOptions.confFile(), options[i], tos(on_off),
  5538. true, handled, idHandled, true) == false)
  5539. {
  5540. ELOG(LOGNAME "Error saving debug option: `" + options[i] + "'");
  5541. }
  5542. }
  5543. }
  5544. else
  5545. {
  5546. ILOG(LOGNAME + utf8(on_off ? "Enabling" : "Disabling") + " the `" + option + "' debugging options");
  5547. // always set even if the saving fails so we've got something working
  5548. gOptions.setOption(option, utf8(tos(on_off)));
  5549. bool handled = false, idHandled = false;
  5550. // if we get a clear then just remove from the config and reload the page
  5551. if (gOptions.editConfigFileEntry(0, gOptions.confFile(), option, tos(on_off),
  5552. true, handled, idHandled, true) == false)
  5553. {
  5554. ELOG(LOGNAME "Error saving debug option: `" + option + "'");
  5555. }
  5556. }
  5557. if (adminRefer)
  5558. {
  5559. sendMessageAndClose(redirect("admin.cgi", SHRINK));
  5560. }
  5561. else
  5562. {
  5563. sendMessageAndClose(MSG_200);
  5564. }
  5565. }
  5566. }
  5567. void protocol_admincgi::mode_help() throw()
  5568. {
  5569. utf8 libs = "<u>Supporting Libraries</u>:<br><br>";
  5570. std::vector<uniString::utf8> parts = tokenizer(utf8(curl_version()), ' ');
  5571. for (vector<uniString::utf8>::const_iterator i = parts.begin(); i != parts.end(); ++i)
  5572. {
  5573. utf8::size_type pos = (*i).find('/');
  5574. if (pos != utf8::npos)
  5575. {
  5576. libs += (*i).substr(0, pos) + utf8(": <b>") + (*i).substr(pos + 1) + utf8("</b>");
  5577. }
  5578. else
  5579. {
  5580. libs += "<b>" + (*i) + "</b>";
  5581. }
  5582. if ((*i).find((utf8)"libcurl") != utf8::npos)
  5583. {
  5584. libs += " (<a target=\"_blank\" href=\"http://curl.haxx.se/\"><b>site</b></a>)";
  5585. }
  5586. else if ((*i).find((utf8)"OpenSSL") != utf8::npos)
  5587. {
  5588. libs += " (<a target=\"_blank\" href=\"http://www.openssl.org/\"><b>site</b></a>)";
  5589. }
  5590. else if ((*i).find((utf8)"zlib") != utf8::npos)
  5591. {
  5592. libs += " (<a target=\"_blank\" href=\"http://www.zlib.net/\"><b>site</b></a>)";
  5593. }
  5594. libs += "<br>";
  5595. }
  5596. const int cpu_count = gOptions.getCPUCount();
  5597. const utf8 cpu = "CPU Count: <b>" + tos(cpucount()) + "</b> -> " +
  5598. (cpu_count == cpucount() ? "using " + utf8(cpu_count > 1 ? "all" : "the") +
  5599. " available CPU" + (cpu_count > 1 ? "s" : "") : tos(cpu_count) +
  5600. " specified to be used") + "<br><br>";
  5601. XML_Expat_Version expat = XML_ExpatVersionInfo();
  5602. utf8 header = MSG_NO_CLOSE_200,
  5603. body = getServerAdminHeader("Server Help &amp; Documentation") +
  5604. "<div><br>"
  5605. "<div style=\"width:19em;margin: 0 0 1em 1em;\" class=\"infb\">"
  5606. "<div align=\"center\" class=\"infh\"><b>Help</b></div>"
  5607. "If you are having issues, you should first try to contact your "
  5608. "hosting provider.<br><br>If running the DNAS server yourself (or if instructed "
  5609. "to do so), then you can use our <a target=\"_blank\" "
  5610. "href=\"http://forums.shoutcast.com/forumdisplay.php?f=140\"><b>forum</b></a> "
  5611. "or you can contact <a href=\"mailto:support@shoutcast.com?subject=Shoutcast%20Support\">"
  5612. "<b>Shoutcast support</b></a> directly (e.g. if the issue relates to an "
  5613. "account / authhash issue).<br><br><b>Note:</b> If using the <a target=\"_blank\" "
  5614. "href=\"http://forums.shoutcast.com/forumdisplay.php?f=140\"><b>forum</b></a>, "
  5615. "do not post any information which could be used to compromise "
  5616. "your account / authhash / etc (e.g. passwords and authhash(s)).<br><br></div>"
  5617. "<div style=\"width:19em;margin: 0 0 1em 1em;\" class=\"infb\">"
  5618. "<div align=\"center\" class=\"infh\"><b>Documentation</b></div>"
  5619. "Supporting documentation for using the DNAS server from setup "
  5620. "to getting statistics from the server are <a target=\"_blank\" "
  5621. "href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_Broadcaster\"><b>online</b></a>.<br><br>"
  5622. "Otherwise a local copy can usually be found on the host machine at:<br><br>"
  5623. "<div style=\"word-break:break-all;\"><b>" + aolxml::escapeXML(gStartupDirectory) +
  5624. "</b></div><br><b>Note:</b> The local copy is usually correct for the version being "
  5625. "used and the <a target=\"_blank\" href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_Broadcaster\">"
  5626. "<b>online</b></a> version will be for the most recent release.<br><br></div>"
  5627. "<div style=\"width:19em;margin: 0 0 1em 1em;\" class=\"infb\">"
  5628. "<div align=\"center\" class=\"infh\"><b>About</b></div>"
  5629. "Information about the DNAS server and the supporting libraries currently used.<br><br>"
  5630. "Version: <b>" + addWBR(gOptions.getVersionBuildStrings()) + "</b><br>"
  5631. "Platform: <b>" + SERV_OSNAME "</b><br>"
  5632. "Built: <b>" __DATE__"</b><br><br>"
  5633. + libs + // libcurl, openssl, zlib
  5634. "expat: <b>" + tos(expat.major) + "." + tos(expat.minor) + "." + tos(expat.micro) + "</b>"
  5635. " (<a target=\"_blank\" href=\"http://www.libexpat.org/\"><b>site</b></a>)"
  5636. //#ifdef _WIN32
  5637. //"<br>pthread-win32: <b>" PTW32_VERSION_STR "-mod</b>"
  5638. //" (<a target=\"_blank\" href=\"https://github.com/GerHobbelt/pthread-win32\"><b>site</b></a>)"
  5639. //#endif
  5640. "<br><br></div></div>"
  5641. "<div style=\"width:19em;margin: 0 0 1em 1em;\" class=\"infb\"><div "
  5642. "align=\"center\" class=\"infh\"><b>Diagnostics</b></div>" + cpu +
  5643. "<u>Current thread &amp; runner usage</u>:<br><br>" +
  5644. threadedRunner::getRunnabledetails() + "<br></div></div>"
  5645. + getUptimeScript() + getIEFlexFix() + getfooterStr();
  5646. COMPRESS(header, body);
  5647. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  5648. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  5649. }
  5650. void protocol_admincgi::mode_config() throw()
  5651. {
  5652. utf8 conf = gOptions.confFile();
  5653. utf8::size_type pos = conf.rfind(fileUtil::getFilePathDelimiter());
  5654. if ((pos != utf8::npos))
  5655. {
  5656. conf = conf.substr(pos + 1);
  5657. }
  5658. utf8 header = MSG_NO_CLOSE_200,
  5659. body = getServerAdminHeader("Server Configuration Settings") +
  5660. "<div><div style=\"padding:1em;\"><b>This page shows the custom configuration settings "
  5661. "that this DNAS server is currently using. (Settings which match DNAS server defaults "
  5662. "may not be shown.)<br><br><u>Note #1:</u> To change these values, you will need to edit the "
  5663. "<u title=\"" + aolxml::escapeXML(fileUtil::getFullFilePath(gOptions.confFile())) + "\">" +
  5664. (!conf.empty() ? conf : "sc_serv.conf") + "</u> file on your server. See <a target=\"_blank\" "
  5665. "href=\"http://wiki.shoutcast.com/wiki/SHOUTcast_DNAS_Server_2#Configuration_File\">here</a> "
  5666. "for more information.<br><br><u>Note #2:</u> This is not the same as the actual configuration file "
  5667. "(i.e. the structure of the configuration file(s) being used is not shown)</b></div>" +
  5668. gOptions.dumpConfigFile() + "<br></div>" + getUptimeScript() + getIEFlexFix() + getfooterStr();
  5669. COMPRESS(header, body);
  5670. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  5671. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  5672. }
  5673. #if 0
  5674. void protocol_admincgi::mode_logs() throw()
  5675. {
  5676. utf8 header = "HTTP/1.1 200 OK\r\n"
  5677. "Cache-Control:no-cache\r\n"
  5678. "Content-Type:text/html;charset=utf-8\r\n",
  5679. headerTitle = "Server Log Management", childPage = "";
  5680. bool bwstyle = false;
  5681. int refreshRequired = 0;
  5682. utf8 body = s_serverAdminHeading;
  5683. body += "<div style=\"padding:0 1em;\"><br>"
  5684. "<table align=\"center\" width=\"100%\"><tr valign=\"top\">"
  5685. "<td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding-left:1em;\">"
  5686. "<tr valign=\"top\"><td>"
  5687. "<div style=\"width:215px;\" class=\"infb\">"
  5688. "<div align=\"center\" class=\"infh\"><b>Information</b></div>"
  5689. "Here you can find are all debugging options provided by the DNAS server.<br><br>Changing the debugging "
  5690. "options will update the value saved in the DNAS server configuration file(s) as needed.<br><br>"
  5691. "Any changes are applied immediately.<br><br></div>"
  5692. "<td>";
  5693. utf8 logfile = gOptions.realLogFile();
  5694. body += "<div style=\"padding-bottom:5px;\">Current log file:</div>";
  5695. body += "<div class=\"en\" style=\"padding-left:27px;padding:10px;margin-bottom:1em;"
  5696. "display:inline-block;border-radius:5px;\"><b>" +
  5697. aolxml::escapeXML(fileUtil::stripPath(logfile)) + "</b>"
  5698. "&nbsp;&nbsp;&nbsp;<a href=\"admin.cgi?mode=viewlog&amp;server=1\">View</a>"
  5699. "&nbsp;&nbsp;&nbsp;<a href=\"admin.cgi?mode=viewlog&amp;server=1&amp;viewlog=save\">Save</a>"
  5700. "<br>Size: <b>" + formatSizeString(uniFile::fileSize(logfile)) + "</b></div><br>";
  5701. utf8 rotated = fileUtil::stripSuffix(logfile) + "_*." + fileUtil::getSuffix(logfile);
  5702. body += "<div style=\"padding-bottom:5px;\">Older log file(s):</div>";
  5703. body += "<div>";
  5704. #ifdef _WIN32
  5705. vector<wstring> fileList = fileUtil::directoryFileList(utf8(fileUtil::getFullFilePath(rotated)).toWString(), L"", true, true);
  5706. #else
  5707. vector<string> fileList = fileUtil::directoryFileList(fileUtil::getFullFilePath(rotated), "");
  5708. #endif
  5709. if (!fileList.empty())
  5710. {
  5711. #ifdef _WIN32
  5712. for (vector<wstring>::const_iterator i = fileList.begin(); i != fileList.end(); ++i)
  5713. #else
  5714. for (vector<string>::const_iterator i = fileList.begin(); i != fileList.end(); ++i)
  5715. #endif
  5716. {
  5717. #ifdef _WIN32
  5718. utf32 u32file(*i);
  5719. utf8 u8f(u32file.toUtf8());
  5720. body += "<div class=\"en\" style=\"padding-left:27px;padding:10px;margin-bottom:1em;"
  5721. "display:inline-block;border-radius:5px;\"><b>" + fileUtil::stripPath(u8f) + "</b>"
  5722. "<div style=\"float:right;\">&nbsp;&nbsp;&nbsp;<a href=\"admin.cgi?mode=viewlog&amp;server=1&amp;file=" +
  5723. urlUtils::escapeURI_RFC3986(u8f) + "\">View</a>&nbsp;&nbsp;&nbsp;"
  5724. "<a href=\"admin.cgi?mode=viewlog&amp;server=1&amp;viewlog=save&amp;file=" +
  5725. urlUtils::escapeURI_RFC3986(u8f) + "\">Save</a></div><br>Size: <b>" +
  5726. formatSizeString(uniFile::fileSize(u8f)) + "</b>"
  5727. "<br>Last Modified: <b>" + getRFCDate(uniFile::fileTime(u8f)) + "</b></div><br>";
  5728. #else
  5729. body += "<div style=\"padding-left:27px;\"><b>" + fileUtil::stripPath(*i) + "</b>&nbsp;&nbsp;&nbsp;"
  5730. "<a href=\"admin.cgi?mode=viewlog&amp;server=1&amp;viewlog=save&amp;file="+urlUtils::escapeURI_RFC3986(*i)+"\">Save</a></div>";
  5731. #endif
  5732. }
  5733. }
  5734. body += "</div>";
  5735. #if 0
  5736. utf8 archived = fileUtil::stripSuffix(logfile) + "_*.gz";
  5737. body += "<div style=\"padding:5px 0 0 27px;\"><b>Log file (archived):</b> "/* + aolxml::escapeXML(fileUtil::getFullFilePath(archived)) + */"</div><br>";
  5738. body += "<div>";
  5739. #ifdef _WIN32
  5740. fileList = fileUtil::directoryFileList(utf8(fileUtil::getFullFilePath(archived)).toWString(), L"", true, true);
  5741. #else
  5742. fileList = fileUtil::directoryFileList(fileUtil::getFullFilePath(archived), "");
  5743. #endif
  5744. if (!fileList.empty())
  5745. {
  5746. #ifdef _WIN32
  5747. for (vector<wstring>::const_iterator i = fileList.begin(); i != fileList.end(); ++i)
  5748. #else
  5749. for (vector<string>::const_iterator i = fileList.begin(); i != fileList.end(); ++i)
  5750. #endif
  5751. {
  5752. #ifdef _WIN32
  5753. utf32 u32file(*i);
  5754. utf8 u8f(u32file.toUtf8());
  5755. body += "<div style=\"padding-left:27px;\">" + fileUtil::stripPath(u8f) + "</div>";
  5756. #else
  5757. body += "<div style=\"padding-left:27px;\">" + fileUtil::stripPath(*i) + "</div>";
  5758. #endif
  5759. }
  5760. }
  5761. body += "</div>";
  5762. body += "<hr>";
  5763. utf8 w3cfile = gOptions.w3cLog();
  5764. body += "<div style=\"padding:5px 0 0 27px;\">W3C file: " + aolxml::escapeXML(fileUtil::getFullFilePath(w3cfile)) + "</div><br>";
  5765. utf8 archived = fileUtil::stripSuffix(w3cfile) + "_*.gz";
  5766. body += "<div style=\"padding:5px 0 0 27px;\">W3C file (archived): " + aolxml::escapeXML(fileUtil::getFullFilePath(archived)) + "</div><br>";
  5767. archived = fileUtil::stripSuffix(w3cfile) + "_*_w3c.gz";
  5768. body += "<div style=\"padding:5px 0 0 27px;\">W3C file (archived 2): " + aolxml::escapeXML(fileUtil::getFullFilePath(archived)) + "</div><br>";
  5769. body += "<div>";
  5770. config::streams_t streams;
  5771. gOptions.getStreamConfigs(streams);
  5772. for (config::streams_t::const_iterator i = streams.begin(); i != streams.end(); ++i)
  5773. {
  5774. // w3c logging
  5775. if (gOptions.read_stream_w3cLog((*i).first))
  5776. {
  5777. body += "<div style=\"padding:5px 0 0 27px;\">Stream W3C file: " + aolxml::escapeXML(fileUtil::getFullFilePath(gOptions.stream_w3cLog((*i).first))) + "</div><br>";
  5778. }
  5779. }
  5780. body += "</div>";
  5781. body += "<hr>";
  5782. body += "<div>";
  5783. #ifdef _WIN32
  5784. fileList = fileUtil::directoryFileList(gStartupDirectory.toWString() + L"sc_w3c*.log", L"", true, true);
  5785. #else
  5786. fileList = fileUtil::directoryFileList(gStartupDirectory.hideAsString() + "sc_w3c*.log", "");
  5787. #endif
  5788. if (!fileList.empty())
  5789. {
  5790. #ifdef _WIN32
  5791. for (vector<wstring>::const_iterator i = fileList.begin(); i != fileList.end(); ++i)
  5792. #else
  5793. for (vector<string>::const_iterator i = fileList.begin(); i != fileList.end(); ++i)
  5794. #endif
  5795. {
  5796. #ifdef _WIN32
  5797. utf32 u32file(*i);
  5798. utf8 u8f(u32file.toUtf8());
  5799. body += "<div style=\"padding-left:27px;\">" + fileUtil::stripPath(u8f) + "</div>";
  5800. #else
  5801. body += "<div style=\"padding-left:27px;\">" + fileUtil::stripPath(*i) + "</div>";
  5802. #endif
  5803. }
  5804. }
  5805. body += "</div>";
  5806. #endif
  5807. body += "</td></tr></table></td></tr></table></div>"
  5808. + getUptimeScript() +
  5809. "<script type=\"text/javascript\">" EL
  5810. "function toggle(opt, on, all) {" EL
  5811. "if(window.XMLHttpRequest){" EL
  5812. "xmlhttp=new XMLHttpRequest();" EL
  5813. "}else{" EL
  5814. "xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");" EL
  5815. "}" EL
  5816. "xmlhttp.open(\"GET\",\"admin.cgi?pass="+gOptions.adminPassword()+"&mode=debug&option=\"+opt+\"&on=\"+on,true);" EL
  5817. "xmlhttp.send(null);" EL
  5818. "if(all){" EL
  5819. "var labels = document.getElementsByTagName('LAB EL');" EL
  5820. "for (var i = 0; i < labels.length; i++) {" EL
  5821. "if (labels[i].htmlFor != '') {" EL
  5822. "$(labels[i].htmlFor).checked=(on=='true'?'true':'');"
  5823. "}" EL
  5824. "}" EL
  5825. "}" EL
  5826. "}</script>" + getfooterStr();
  5827. COMPRESS(header, body);
  5828. header += "Content-Length: " + tos(body.size()) + "\r\n\r\n";
  5829. sendMessageAndClose(header + (!HEAD_REQUEST ? body : ""));
  5830. }
  5831. #endif