organizr.class.php 262 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838
  1. <?php
  2. use Dibi\Connection;
  3. class Organizr
  4. {
  5. // Use Custom Functions From Traits;
  6. use TwoFAFunctions;
  7. use ApiFunctions;
  8. use AuthFunctions;
  9. use BackupFunctions;
  10. use ConfigFunctions;
  11. use HomepageConnectFunctions;
  12. use HomepageFunctions;
  13. use LogFunctions;
  14. use NetDataFunctions;
  15. use NormalFunctions;
  16. use OptionsFunction;
  17. use OrganizrFunctions;
  18. use PluginFunctions;
  19. use StaticFunctions;
  20. use SSOFunctions;
  21. use TokenFunctions;
  22. use UpdateFunctions;
  23. use UpgradeFunctions;
  24. // Use homepage item functions
  25. use CalendarHomepageItem;
  26. use CouchPotatoHomepageItem;
  27. use DelugeHomepageItem;
  28. use EmbyHomepageItem;
  29. use HealthChecksHomepageItem;
  30. use ICalHomepageItem;
  31. use JDownloaderHomepageItem;
  32. use LidarrHomepageItem;
  33. use MonitorrHomepageItem;
  34. use NetDataHomepageItem;
  35. use NZBGetHomepageItem;
  36. use OctoPrintHomepageItem;
  37. use OmbiHomepageItem;
  38. use PiHoleHomepageItem;
  39. use PlexHomepageItem;
  40. use QBitTorrentHomepageItem;
  41. use RadarrHomepageItem;
  42. use RTorrentHomepageItem;
  43. use SabNZBdHomepageItem;
  44. use SickRageHomepageItem;
  45. use SonarrHomepageItem;
  46. use SpeedTestHomepageItem;
  47. use TautulliHomepageItem;
  48. use TransmissionHomepageItem;
  49. use UnifiHomepageItem;
  50. use WeatherHomepageItem;
  51. // ===================================
  52. // Organizr Version
  53. public $version = '2.1.0';
  54. // ===================================
  55. // Quick php Version check
  56. public $minimumPHP = '7.2';
  57. // ===================================
  58. protected $db;
  59. protected $otherDb;
  60. public $config;
  61. public $user;
  62. public $userConfigPath;
  63. public $defaultConfigPath;
  64. public $currentTime;
  65. public $docker;
  66. public $dev;
  67. public $demo;
  68. public $commit;
  69. public $fileHash;
  70. public $cookieName;
  71. public $organizrLog;
  72. public $organizrLoginLog;
  73. public $timeExecution;
  74. public $root;
  75. public $paths;
  76. public $updating;
  77. public function __construct($updating = false)
  78. {
  79. // First Check PHP Version
  80. $this->checkPHP();
  81. // Constructed from Updater?
  82. $this->updating = $updating;
  83. // Set Project Root directory
  84. $this->root = dirname(__DIR__, 2);
  85. // Set Start Execution Time
  86. $this->timeExecution = $this->timeExecution();
  87. // Set location path to user config path
  88. $this->userConfigPath = dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
  89. // Set location path to default config path
  90. $this->defaultConfigPath = dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'default.php';
  91. // Set current time
  92. $this->currentTime = gmdate("Y-m-d\TH:i:s\Z");
  93. // Set variable if install is for official docker
  94. $this->docker = (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'Docker.txt'));
  95. // Set variable if install is for develop
  96. $this->dev = (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'Dev.txt'));
  97. // Set variable if install is for demo
  98. $this->demo = (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'Demo.txt'));
  99. // Set variable if install has commit hash
  100. $this->commit = ($this->docker && !$this->dev) ? file_get_contents(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'Github.txt') : null;
  101. // Set variable to be used as hash for files
  102. $this->fileHash = ($this->commit) ?? $this->version;
  103. // Load Config file
  104. $this->config = $this->config();
  105. // Set organizr Log file location
  106. $this->organizrLog = ($this->hasDB()) ? $this->config['dbLocation'] . 'organizrLog.json' : false;
  107. // Set organizr Login Log file location
  108. $this->organizrLoginLog = ($this->hasDB()) ? $this->config['dbLocation'] . 'organizrLoginLog.json' : false;
  109. // Set Paths
  110. $this->paths = array(
  111. 'Root Folder' => dirname(__DIR__, 2) . DIRECTORY_SEPARATOR,
  112. 'API Folder' => dirname(__DIR__, 1) . DIRECTORY_SEPARATOR,
  113. 'DB Folder' => ($this->hasDB()) ? $this->config['dbLocation'] : false
  114. );
  115. // Connect to DB
  116. $this->connectDB();
  117. // Set cookie name for Organizr Instance
  118. $this->cookieName = ($this->hasDB()) ? $this->config['uuid'] !== '' ? 'organizr_token_' . $this->config['uuid'] : 'organizr_token_temp' : 'organizr_token_temp';
  119. // Get token form cookie and validate
  120. $this->user = $this->hasCookie() ? $this->validateToken($_COOKIE[$this->cookieName]) ?? $this->guestUser() : $this->guestUser();
  121. // might just run this at index
  122. $this->upgradeCheck();
  123. // Is Page load Organizr OAuth?
  124. $this->checkForOrganizrOAuth();
  125. }
  126. protected function connectDB()
  127. {
  128. if ($this->hasDB()) {
  129. try {
  130. $this->db = new Connection([
  131. 'driver' => 'sqlite3',
  132. 'database' => $this->config['dbLocation'] . $this->config['dbName'],
  133. ]);
  134. } catch (Dibi\Exception $e) {
  135. $this->db = null;
  136. }
  137. } else {
  138. $this->db = null;
  139. }
  140. }
  141. public function connectOtherDB($file = null)
  142. {
  143. $file = $file ?? $this->config['dbLocation'] . 'tempMigration.db';
  144. try {
  145. $this->otherDb = new Connection([
  146. 'driver' => 'sqlite3',
  147. 'database' => $file,
  148. ]);
  149. } catch (Dibi\Exception $e) {
  150. $this->otherDb = null;
  151. }
  152. }
  153. public function checkForOrganizrOAuth()
  154. {
  155. // Oauth?
  156. if ($this->config['authProxyEnabled'] && $this->config['authProxyHeaderName'] !== '' && $this->config['authProxyWhitelist'] !== '') {
  157. if (isset(getallheaders()[$this->config['authProxyHeaderName']])) {
  158. $this->coookieSeconds('set', 'organizrOAuth', 'true', 20000, false);
  159. }
  160. }
  161. }
  162. public function auth()
  163. {
  164. if ($this->hasDB()) {
  165. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  166. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  167. $group = 0;
  168. $groupParam = $_GET['group'];
  169. $redirect = false;
  170. if (isset($groupParam)) {
  171. if (is_numeric($groupParam)) {
  172. $group = (int)$groupParam;
  173. } else {
  174. $group = $this->getTabGroupByTabName($groupParam);
  175. }
  176. }
  177. $currentIP = $this->userIP();
  178. $unlocked = ($this->user['locked'] == '1') ? false : true;
  179. if (isset($this->user)) {
  180. $currentUser = $this->user['username'];
  181. $currentGroup = $this->user['groupID'];
  182. $currentEmail = $this->user['email'];
  183. } else {
  184. $currentUser = 'Guest';
  185. $currentGroup = $this->getUserLevel();
  186. $currentEmail = 'guest@guest.com';
  187. }
  188. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  189. if ($whitelist) {
  190. if (in_array($currentIP, $this->arrayIP($whitelist))) {
  191. $this->setAPIResponse('success', 'User is whitelisted', 200);
  192. }
  193. }
  194. if ($blacklist) {
  195. if (in_array($currentIP, $this->arrayIP($blacklist))) {
  196. $this->setAPIResponse('error', $userInfo . ' User is blacklisted', 401);
  197. }
  198. }
  199. if ($group !== null) {
  200. if ((isset($_SERVER['HTTP_X_FORWARDED_SERVER']) && $_SERVER['HTTP_X_FORWARDED_SERVER'] == 'traefik') || $this->config['traefikAuthEnable']) {
  201. $redirect = 'Location: ' . $this->getServerPath();
  202. }
  203. if ($this->qualifyRequest($group) && $unlocked) {
  204. header("X-Organizr-User: $currentUser");
  205. header("X-Organizr-Email: $currentEmail");
  206. $this->setAPIResponse('success', $userInfo . ' User is Authorized', 200);
  207. } else {
  208. if (!$redirect) {
  209. $this->setAPIResponse('error', $userInfo . ' User is not Authorized or User is locked', 401);
  210. } else {
  211. exit(http_response_code(401) . header($redirect));
  212. }
  213. }
  214. } else {
  215. $this->setAPIResponse('error', 'Missing info', 401);
  216. }
  217. }
  218. return true;
  219. }
  220. public function setAPIResponse($result = null, $message = null, $responseCode = null, $data = null)
  221. {
  222. if ($result) {
  223. $GLOBALS['api']['response']['result'] = $result;
  224. }
  225. if ($message) {
  226. $GLOBALS['api']['response']['message'] = $message;
  227. }
  228. if ($responseCode) {
  229. $GLOBALS['responseCode'] = $responseCode;
  230. }
  231. if ($data) {
  232. $GLOBALS['api']['response']['data'] = $data;
  233. }
  234. }
  235. public function checkRoute($request)
  236. {
  237. $route = $request->getUri()->getPath();
  238. $method = $request->getMethod();
  239. $data = $this->apiData($request);
  240. if (!in_array($route, $GLOBALS['bypass'])) {
  241. if ($this->isApprovedRequest($method, $data) === false) {
  242. $this->setAPIResponse('error', 'Not authorized', 401);
  243. $this->writeLog('success', 'Killed Attack From [' . (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'No Referer') . ']', $this->user['username']);
  244. return false;
  245. }
  246. }
  247. return true;
  248. }
  249. public function apiData($request)
  250. {
  251. switch ($request->getMethod()) {
  252. case 'POST':
  253. if ($request->getHeaderLine('Content-Type') == 'application/json') {
  254. return json_decode(file_get_contents('php://input', 'r'), true);
  255. } else {
  256. return $request->getParsedBody();
  257. }
  258. default:
  259. if ($request->getHeaderLine('Content-Type') == 'application/json') {
  260. return json_decode(file_get_contents('php://input', 'r'), true);
  261. } else {
  262. return null;
  263. }
  264. }
  265. }
  266. public function getPlugins()
  267. {
  268. if ($this->hasDB()) {
  269. $pluginList = [];
  270. foreach ($GLOBALS['plugins'] as $plugin) {
  271. foreach ($plugin as $key => $value) {
  272. if (strpos($value['license'], $this->config['license']) !== false) {
  273. $plugin[$key]['enabled'] = $this->config[$value['configPrefix'] . '-enabled'];
  274. $pluginList[$key] = $plugin[$key];
  275. }
  276. }
  277. }
  278. return $pluginList;
  279. }
  280. return false;
  281. }
  282. public function refreshCookieName()
  283. {
  284. $this->cookieName = $this->config['uuid'] !== '' ? 'organizr_token_' . $this->config['uuid'] : 'organizr_token_temp';
  285. }
  286. public function favIcons()
  287. {
  288. $favicon = '
  289. <link rel="apple-touch-icon" sizes="180x180" href="plugins/images/favicon/apple-touch-icon.png">
  290. <link rel="icon" type="image/png" sizes="32x32" href="plugins/images/favicon/favicon-32x32.png">
  291. <link rel="icon" type="image/png" sizes="16x16" href="plugins/images/favicon/favicon-16x16.png">
  292. <link rel="manifest" href="plugins/images/favicon/site.webmanifest">
  293. <link rel="mask-icon" href="plugins/images/favicon/safari-pinned-tab.svg" color="#5bbad5">
  294. <link rel="shortcut icon" href="plugins/images/favicon/favicon.ico">
  295. <meta name="msapplication-TileColor" content="#da532c">
  296. <meta name="msapplication-TileImage" content="plugins/images/favicon/mstile-144x144.png">
  297. <meta name="msapplication-config" content="plugins/images/favicon/browserconfig.xml">
  298. <meta name="theme-color" content="#ffffff">
  299. ';
  300. return ($this->config['favIcon'] == '') ? $favicon : $this->config['favIcon'];
  301. }
  302. public function pluginGlobalList()
  303. {
  304. $pluginSearch = '-enabled';
  305. $pluginInclude = '-include';
  306. $plugins = array_filter($this->config, function ($k) use ($pluginSearch) {
  307. return stripos($k, $pluginSearch) !== false;
  308. }, ARRAY_FILTER_USE_KEY);
  309. $plugins['includes'] = array_filter($this->config, function ($k) use ($pluginInclude) {
  310. return stripos($k, $pluginInclude) !== false;
  311. }, ARRAY_FILTER_USE_KEY);
  312. return $plugins;
  313. }
  314. public function googleTracking()
  315. {
  316. if ($this->config['gaTrackingID'] !== '') {
  317. return '
  318. <script async src="https://www.googletagmanager.com/gtag/js?id=' . $this->config['gaTrackingID'] . '"></script>
  319. <script>
  320. window.dataLayer = window.dataLayer || [];
  321. function gtag(){dataLayer.push(arguments);}
  322. gtag("js", new Date());
  323. gtag("config","' . $this->config['gaTrackingID'] . '");
  324. </script>
  325. ';
  326. }
  327. return null;
  328. }
  329. public function matchBrackets($text, $brackets = 's')
  330. {
  331. switch ($brackets) {
  332. case 's':
  333. case 'square':
  334. $pattern = '#\[(.*?)\]#';
  335. break;
  336. case 'c':
  337. case 'curly':
  338. $pattern = '#\((.*?)\)#';
  339. break;
  340. default:
  341. return null;
  342. }
  343. preg_match($pattern, $text, $match);
  344. return $match[1];
  345. }
  346. public function languagePacks($encode = false)
  347. {
  348. $files = array();
  349. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'langpack' . DIRECTORY_SEPARATOR . "*.json") as $filename) {
  350. if (strpos(basename($filename), '[') !== false) {
  351. $explode = explode('[', basename($filename));
  352. $files[] = array(
  353. 'filename' => basename($filename),
  354. 'code' => $explode[0],
  355. 'language' => $this->matchBrackets(basename($filename))
  356. );
  357. }
  358. }
  359. usort($files, function ($a, $b) {
  360. return $a['language'] <=> $b['language'];
  361. });
  362. return ($encode) ? json_encode($files) : $files;
  363. }
  364. public function pluginFiles($type)
  365. {
  366. $files = '';
  367. switch ($type) {
  368. case 'js':
  369. foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . "*.js") as $filename) {
  370. $files .= '<script src="api/plugins/js/' . basename($filename) . '?v=' . $this->fileHash . '" defer="true"></script>';
  371. }
  372. break;
  373. case 'css':
  374. foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  375. $files .= '<link href="api/plugins/css/' . basename($filename) . '?v=' . $this->fileHash . '" rel="stylesheet">';
  376. }
  377. break;
  378. default:
  379. break;
  380. }
  381. return $files;
  382. }
  383. public function formKey($script = true)
  384. {
  385. if (isset($this->config['organizrHash'])) {
  386. if ($this->config['organizrHash'] !== '') {
  387. $hash = password_hash(substr($this->config['organizrHash'], 2, 10), PASSWORD_BCRYPT);
  388. return ($script) ? '<script>local("s","formKey","' . $hash . '");</script>' : $hash;
  389. }
  390. }
  391. }
  392. private function checkPHP()
  393. {
  394. if (!(version_compare(PHP_VERSION, $this->minimumPHP) >= 0)) {
  395. die('Organizr needs PHP Version: ' . $this->minimumPHP . '<br/> You have PHP Version: ' . PHP_VERSION);
  396. }
  397. }
  398. public function upgradeCheck()
  399. {
  400. if ($this->hasDB()) {
  401. $tempLock = $this->config['dbLocation'] . 'DBLOCK.txt';
  402. $updateComplete = $this->config['dbLocation'] . 'completed.txt';
  403. $cleanup = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'upgrade' . DIRECTORY_SEPARATOR;
  404. if (file_exists($updateComplete)) {
  405. @unlink($updateComplete);
  406. @$this->rrmdir($cleanup);
  407. }
  408. if (file_exists($tempLock)) {
  409. die('upgrading');
  410. }
  411. $updateDB = false;
  412. $updateSuccess = true;
  413. $compare = new Composer\Semver\Comparator;
  414. $oldVer = $this->config['configVersion'];
  415. // Upgrade check start for version below
  416. $versionCheck = '2.0.0-beta-200';
  417. if ($compare->lessThan($oldVer, $versionCheck)) {
  418. $updateDB = true;
  419. $oldVer = $versionCheck;
  420. }
  421. // End Upgrade check start for version above
  422. // Upgrade check start for version below
  423. $versionCheck = '2.0.0-beta-500';
  424. if ($compare->lessThan($oldVer, $versionCheck)) {
  425. $updateDB = true;
  426. $oldVer = $versionCheck;
  427. }
  428. // End Upgrade check start for version above
  429. // Upgrade check start for version below
  430. $versionCheck = '2.0.0-beta-800';
  431. if ($compare->lessThan($oldVer, $versionCheck)) {
  432. $updateDB = true;
  433. $oldVer = $versionCheck;
  434. }
  435. // End Upgrade check start for version above
  436. // Upgrade check start for version below
  437. $versionCheck = '2.1.0';
  438. if ($compare->lessThan($oldVer, $versionCheck)) {
  439. $updateDB = false;
  440. $oldVer = $versionCheck;
  441. $this->upgradeToVersion($versionCheck);
  442. }
  443. // End Upgrade check start for version above
  444. if ($updateDB == true) {
  445. //return 'Upgraded Needed - Current Version '.$oldVer.' - New Version: '.$versionCheck;
  446. // Upgrade database to latest version
  447. $updateSuccess = $this->updateDB($oldVer);
  448. }
  449. // Update config.php version if different to the installed version
  450. if ($updateSuccess && $this->version !== $this->config['configVersion']) {
  451. $this->updateConfig(array('apply_CONFIG_VERSION' => $this->version));
  452. }
  453. if ($updateSuccess == false) {
  454. die('Database update failed - Please manually check logs and fix - Then reload this page');
  455. }
  456. return true;
  457. }
  458. }
  459. public function updateDB($oldVerNum = false)
  460. {
  461. $tempLock = $this->config['dbLocation'] . 'DBLOCK.txt';
  462. if (!file_exists($tempLock)) {
  463. touch($tempLock);
  464. $migrationDB = 'tempMigration.db';
  465. $pathDigest = pathinfo($this->config['dbLocation'] . $this->config['dbName']);
  466. if (file_exists($this->config['dbLocation'] . $migrationDB)) {
  467. unlink($this->config['dbLocation'] . $migrationDB);
  468. }
  469. // Create Temp DB First
  470. $this->connectOtherDB();
  471. $backupDB = $pathDigest['dirname'] . '/' . $pathDigest['filename'] . '[' . date('Y-m-d_H-i-s') . ']' . ($oldVerNum ? '[' . $oldVerNum . ']' : '') . '.bak.db';
  472. copy($this->config['dbLocation'] . $this->config['dbName'], $backupDB);
  473. $success = $this->createDB($this->config['dbLocation'], true);
  474. if ($success) {
  475. $response = [
  476. array(
  477. 'function' => 'fetchAll',
  478. 'query' => array(
  479. 'SELECT name FROM sqlite_master WHERE type="table"'
  480. )
  481. ),
  482. ];
  483. $tables = $this->processQueries($response);
  484. foreach ($tables as $table) {
  485. $response = [
  486. array(
  487. 'function' => 'fetchAll',
  488. 'query' => array(
  489. 'SELECT * FROM ' . $table['name']
  490. )
  491. ),
  492. ];
  493. $data = $this->processQueries($response);
  494. $this->writeLog('success', 'Update Function - Grabbed Table data for Table: ' . $table['name'], 'Database');
  495. foreach ($data as $row) {
  496. $response = [
  497. array(
  498. 'function' => 'query',
  499. 'query' => array(
  500. 'INSERT into ' . $table['name'],
  501. $row
  502. )
  503. ),
  504. ];
  505. $this->processQueries($response, true);
  506. }
  507. $this->writeLog('success', 'Update Function - Wrote Table data for Table: ' . $table['name'], 'Database');
  508. }
  509. $this->writeLog('success', 'Update Function - All Table data converted - Starting Movement', 'Database');
  510. $this->db->disconnect();
  511. $this->otherDb->disconnect();
  512. // Remove Current Database
  513. if (file_exists($this->config['dbLocation'] . $migrationDB)) {
  514. $oldFileSize = filesize($this->config['dbLocation'] . $this->config['dbName']);
  515. $newFileSize = filesize($this->config['dbLocation'] . $migrationDB);
  516. if ($newFileSize > 0) {
  517. $this->writeLog('success', 'Update Function - Table Size of new DB ok..', 'Database');
  518. @unlink($this->config['dbLocation'] . $this->config['dbName']);
  519. copy($this->config['dbLocation'] . $migrationDB, $this->config['dbLocation'] . $this->config['dbName']);
  520. @unlink($this->config['dbLocation'] . $migrationDB);
  521. $this->writeLog('success', 'Update Function - Migrated Old Info to new Database', 'Database');
  522. @unlink($tempLock);
  523. return true;
  524. } else {
  525. $this->writeLog('error', 'Update Function - Filesize is zero', 'Database');
  526. }
  527. } else {
  528. $this->writeLog('error', 'Update Function - Migration DB does not exist', 'Database');
  529. }
  530. @unlink($tempLock);
  531. return false;
  532. } else {
  533. $this->writeLog('error', 'Update Function - Could not create migration DB', 'Database');
  534. }
  535. @unlink($tempLock);
  536. return false;
  537. }
  538. return false;
  539. }
  540. // Create config file in the return syntax
  541. public function createConfig($array, $path = null, $nest = 0)
  542. {
  543. $path = ($path) ? $path : $this->userConfigPath;
  544. // Define Initial Value
  545. $output = array();
  546. // Sort Items
  547. ksort($array);
  548. // Update the current config version
  549. if (!$nest) {
  550. // Inject Current Version
  551. $output[] = "\t'configVersion' => '" . (isset($array['apply_CONFIG_VERSION']) ? $array['apply_CONFIG_VERSION'] : $this->version) . "'";
  552. }
  553. unset($array['configVersion']);
  554. unset($array['apply_CONFIG_VERSION']);
  555. // Process Settings
  556. foreach ($array as $k => $v) {
  557. $allowCommit = true;
  558. $item = '';
  559. switch (gettype($v)) {
  560. case 'boolean':
  561. $item = ($v ? 'true' : 'false');
  562. break;
  563. case 'integer':
  564. case 'double':
  565. case 'NULL':
  566. $item = $v;
  567. break;
  568. case 'string':
  569. $item = "'" . str_replace(array('\\', "'"), array('\\\\', "\'"), $v) . "'";
  570. break;
  571. case 'array':
  572. $item = $this->createConfig($v, false, $nest + 1);
  573. break;
  574. default:
  575. $allowCommit = false;
  576. }
  577. if ($allowCommit) {
  578. $output[] = str_repeat("\t", $nest + 1) . "'$k' => $item";
  579. }
  580. }
  581. // Build output
  582. $output = (!$nest ? "<?php\nreturn " : '') . "array(\n" . implode(",\n", $output) . "\n" . str_repeat("\t", $nest) . ')' . (!$nest ? ';' : '');
  583. if (!$nest && $path) {
  584. $pathDigest = pathinfo($path);
  585. @mkdir($pathDigest['dirname'], 0770, true);
  586. if (file_exists($path)) {
  587. rename($path, $pathDigest['dirname'] . '/' . $pathDigest['filename'] . '.bak.php');
  588. }
  589. $file = fopen($path, 'w');
  590. fwrite($file, $output);
  591. fclose($file);
  592. if (file_exists($path)) {
  593. return true;
  594. }
  595. return false;
  596. } else {
  597. return $output;
  598. }
  599. }
  600. // Commit new values to the configuration
  601. public function updateConfig($new, $current = false)
  602. {
  603. // Get config if not supplied
  604. if ($current === false) {
  605. //$current = $this->loadConfig();
  606. $current = $this->config;
  607. } elseif (is_string($current) && is_file($current)) {
  608. $current = $this->loadConfig($current);
  609. }
  610. // Inject Parts
  611. foreach ($new as $k => $v) {
  612. $current[$k] = $v;
  613. }
  614. // Return Create
  615. return $this->createConfig($current);
  616. }
  617. public function loadConfig($path = null)
  618. {
  619. $path = ($path) ? $path : $this->userConfigPath;
  620. if (!is_file($path)) {
  621. return null;
  622. } else {
  623. return (array)call_user_func(function () use ($path) {
  624. return include($path);
  625. });
  626. }
  627. }
  628. public function fillDefaultConfig($array)
  629. {
  630. $path = $this->defaultConfigPath;
  631. if (is_string($path)) {
  632. $loadedDefaults = $this->loadConfig($path);
  633. } else {
  634. $loadedDefaults = $path;
  635. }
  636. // Include all plugin config files
  637. foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . "*.php") as $filename) {
  638. $loadedDefaults = array_merge($loadedDefaults, $this->loadConfig($filename));
  639. }
  640. return (is_array($loadedDefaults) ? $this->fillDefaultConfig_recurse($array, $loadedDefaults) : false);
  641. }
  642. public function fillDefaultConfig_recurse($current, $defaults)
  643. {
  644. foreach ($defaults as $k => $v) {
  645. if (!isset($current[$k])) {
  646. $current[$k] = $v;
  647. } elseif (is_array($current[$k]) && is_array($v)) {
  648. $current[$k] = $this->fillDefaultConfig_recurse($current[$k], $v);
  649. }
  650. }
  651. return $current;
  652. }
  653. public function config()
  654. {
  655. // Load config or default
  656. if (file_exists($this->userConfigPath)) {
  657. $config = $this->fillDefaultConfig($this->loadConfig($this->userConfigPath));
  658. } else {
  659. $config = $this->fillDefaultConfig($this->loadConfig($this->defaultConfigPath));
  660. }
  661. return $config;
  662. }
  663. public function combineConfig($array)
  664. {
  665. $this->config = array_merge($this->config, $array);
  666. return $this->config;
  667. }
  668. public function status()
  669. {
  670. $status = array();
  671. $dependenciesActive = array();
  672. $dependenciesInactive = array();
  673. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session", "filter");
  674. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  675. foreach ($extensions as $check) {
  676. if (extension_loaded($check)) {
  677. array_push($dependenciesActive, $check);
  678. } else {
  679. array_push($dependenciesInactive, $check);
  680. }
  681. }
  682. foreach ($functions as $check) {
  683. if (function_exists($check)) {
  684. array_push($dependenciesActive, $check);
  685. } else {
  686. array_push($dependenciesInactive, $check);
  687. }
  688. }
  689. if (!file_exists($this->userConfigPath)) {
  690. $status['status'] = "wizard";//wizard - ok for test
  691. }
  692. if (count($dependenciesInactive) > 0 || !is_writable(dirname(__DIR__, 2)) || !(version_compare(PHP_VERSION, $this->minimumPHP) >= 0)) {
  693. $status['status'] = "dependencies";
  694. }
  695. $status['status'] = ($status['status']) ?? "ok";
  696. $status['writable'] = is_writable(dirname(__DIR__, 2)) ? 'yes' : 'no';
  697. $status['minVersion'] = (version_compare(PHP_VERSION, $this->minimumPHP) >= 0) ? 'yes' : 'no';
  698. $status['dependenciesActive'] = $dependenciesActive;
  699. $status['dependenciesInactive'] = $dependenciesInactive;
  700. $status['version'] = $this->version;
  701. $status['os'] = $this->getOS();
  702. $status['php'] = phpversion();
  703. $status['userConfigPath'] = $this->userConfigPath;
  704. return $status;
  705. }
  706. public function hasDB()
  707. {
  708. return (file_exists($this->userConfigPath)) ?? false;
  709. }
  710. public function hasCookie()
  711. {
  712. return ($_COOKIE[$this->cookieName]) ?? false;
  713. }
  714. public function getGuest()
  715. {
  716. $guest = array(
  717. 'group' => 'Guest',
  718. 'group_id' => 999,
  719. 'image' => 'plugins/images/groups/guest.png'
  720. );
  721. $response = [
  722. array(
  723. 'function' => 'fetch',
  724. 'query' => 'SELECT * FROM groups WHERE `group_id` = 999'
  725. ),
  726. ];
  727. return $this->hasDB() ? $this->processQueries($response) : $guest;
  728. }
  729. public function getSchema()
  730. {
  731. $response = [
  732. array(
  733. 'function' => 'fetchAll',
  734. 'query' => 'SELECT name, sql FROM sqlite_master WHERE type=\'table\' ORDER BY name'
  735. ),
  736. ];
  737. return $this->hasDB() ? $this->processQueries($response) : 'Database not setup yet';
  738. }
  739. public function guestUser()
  740. {
  741. if ($this->hasDB()) {
  742. if ($this->getUserLevel() !== 999) {
  743. $guest = array(
  744. "token" => null,
  745. "tokenDate" => null,
  746. "tokenExpire" => null,
  747. "username" => "Organizr API",
  748. "uid" => $this->guestHash(0, 5),
  749. "group" => 'Admin',
  750. "groupID" => 0,
  751. "email" => null,
  752. //"groupImage"=>getGuest()['image'],
  753. "image" => $this->getGuest()['image'],
  754. "userID" => null,
  755. "loggedin" => false,
  756. "locked" => false,
  757. "tokenList" => null,
  758. "authService" => null
  759. );
  760. }
  761. }
  762. $guest = $guest ?? array(
  763. "token" => null,
  764. "tokenDate" => null,
  765. "tokenExpire" => null,
  766. "username" => "Guest",
  767. "uid" => $this->guestHash(0, 5),
  768. "group" => $this->getGuest()['group'],
  769. "groupID" => $this->getGuest()['group_id'],
  770. "email" => null,
  771. //"groupImage"=>getGuest()['image'],
  772. "image" => $this->getGuest()['image'],
  773. "userID" => null,
  774. "loggedin" => false,
  775. "locked" => false,
  776. "tokenList" => null,
  777. "authService" => null
  778. );
  779. return $guest;
  780. }
  781. public function getAllUserTokens($id)
  782. {
  783. $response = [
  784. array(
  785. 'function' => 'fetchAll',
  786. 'query' => array(
  787. 'SELECT * FROM `tokens` WHERE user_id = ? AND expires > ?',
  788. [$id],
  789. [$this->currentTime]
  790. )
  791. ),
  792. ];
  793. return $this->processQueries($response);
  794. }
  795. public function getUserById($id)
  796. {
  797. $response = [
  798. array(
  799. 'function' => 'fetch',
  800. 'query' => array(
  801. 'SELECT * FROM users WHERE id = ?',
  802. $id
  803. )
  804. )
  805. ];
  806. return $this->processQueries($response);
  807. }
  808. public function getUserByEmail($email)
  809. {
  810. $response = [
  811. array(
  812. 'function' => 'fetch',
  813. 'query' => array(
  814. 'SELECT * FROM users WHERE email = ? COLLATE NOCASE',
  815. $email
  816. )
  817. )
  818. ];
  819. return $this->processQueries($response);
  820. }
  821. protected function invalidToken()
  822. {
  823. $this->coookie('delete', $this->cookieName);
  824. $this->user = null;
  825. }
  826. public function validateToken($token)
  827. {
  828. // Validate script
  829. $userInfo = $this->jwtParse($token);
  830. $validated = $userInfo ? true : false;
  831. if ($validated == true) {
  832. $allTokens = $this->getAllUserTokens($userInfo['userID']);
  833. $user = $this->getUserById($userInfo['userID']);
  834. $tokenCheck = ($this->searchArray($allTokens, 'token', $token) !== false);
  835. if (!$tokenCheck) {
  836. $this->invalidToken();
  837. return false;
  838. } else {
  839. return array(
  840. "token" => $token,
  841. "tokenDate" => $userInfo['tokenDate'],
  842. "tokenExpire" => $userInfo['tokenExpire'],
  843. "username" => $user['username'],
  844. "uid" => $this->guestHash(0, 5),
  845. "group" => $user['group'],
  846. "groupID" => $user['group_id'],
  847. "email" => $user['email'],
  848. "image" => $user['image'],
  849. "userID" => $user['id'],
  850. "loggedin" => true,
  851. "locked" => $user['locked'],
  852. "tokenList" => $allTokens,
  853. "authService" => explode('::', $user['auth_service'])[0]
  854. );
  855. }
  856. } else {
  857. $this->invalidToken();
  858. }
  859. return false;
  860. }
  861. public function defaultUserGroup()
  862. {
  863. $response = [
  864. array(
  865. 'function' => 'fetch',
  866. 'query' => 'SELECT * FROM groups WHERE `default` = 1'
  867. )
  868. ];
  869. return $this->processQueries($response);
  870. }
  871. public function getAllTabs()
  872. {
  873. $response = [
  874. array(
  875. 'function' => 'fetchAll',
  876. 'query' => 'SELECT * FROM tabs ORDER BY `order` ASC',
  877. 'key' => 'tabs'
  878. ),
  879. array(
  880. 'function' => 'fetchAll',
  881. 'query' => 'SELECT * FROM categories ORDER BY `order` ASC',
  882. 'key' => 'categories'
  883. ),
  884. array(
  885. 'function' => 'fetchAll',
  886. 'query' => 'SELECT * FROM groups ORDER BY `group_id` ASC',
  887. 'key' => 'groups'
  888. ),
  889. ];
  890. return $this->processQueries($response);
  891. }
  892. public function getUsers()
  893. {
  894. $response = [
  895. array(
  896. 'function' => 'fetchAll',
  897. 'query' => 'SELECT * FROM users'
  898. ),
  899. array(
  900. 'function' => 'fetchAll',
  901. 'query' => 'SELECT * FROM groups ORDER BY group_id ASC'
  902. ),
  903. ];
  904. return $this->processQueries($response);
  905. }
  906. public function usernameTaken($username, $email, $id = null)
  907. {
  908. if ($id) {
  909. $response = [
  910. array(
  911. 'function' => 'fetch',
  912. 'query' => array(
  913. 'SELECT * FROM users WHERE `id` != ? AND (username = ? COLLATE NOCASE or email = ? COLLATE NOCASE)',
  914. $id,
  915. $username,
  916. $email
  917. )
  918. ),
  919. ];
  920. } else {
  921. $response = [
  922. array(
  923. 'function' => 'fetch',
  924. 'query' => array(
  925. 'SELECT * FROM users WHERE username = ? COLLATE NOCASE or email = ? COLLATE NOCASE',
  926. [$username],
  927. [$email]
  928. )
  929. ),
  930. ];
  931. }
  932. return $this->processQueries($response);
  933. }
  934. public function cleanPageName($page)
  935. {
  936. return ($page) ? strtolower(str_replace(array('%20', ' ', '-', '_'), '_', $page)) : '';
  937. }
  938. public function cleanClassName($name)
  939. {
  940. return ($name) ? (str_replace(array('%20', ' ', '-', '_'), '-', $name)) : '';
  941. }
  942. public function reverseCleanClassName($name)
  943. {
  944. return ($name) ? (str_replace(array('%20', '-', '_'), ' ', $name)) : '';
  945. }
  946. public function getPageList()
  947. {
  948. return $GLOBALS['organizrPages'];
  949. }
  950. public function getPage($page)
  951. {
  952. if (!$page) {
  953. $this->setAPIResponse('error', 'Page not setup', 409);
  954. return null;
  955. }
  956. $pageFunction = 'get_page_' . $this->cleanPageName($page);
  957. if (function_exists($pageFunction)) {
  958. return $pageFunction($this);
  959. } else {
  960. $this->setAPIResponse('error', 'Page not setup', 409);
  961. return null;
  962. }
  963. }
  964. public function getUserLevel()
  965. {
  966. // Grab token
  967. $requesterToken = isset($this->getallheaders()['Token']) ? $this->getallheaders()['Token'] : (isset($_GET['apikey']) ? $_GET['apikey'] : false);
  968. $apiKey = ($this->config['organizrAPI']) ?? null;
  969. // Check token or API key
  970. // If API key, return 0 for admin
  971. if (strlen($requesterToken) == 20 && $requesterToken == $apiKey) {
  972. //DO API CHECK
  973. return 0;
  974. } elseif (isset($this->user)) {
  975. return $this->user['groupID'];
  976. }
  977. // All else fails? return guest id
  978. return 999;
  979. }
  980. public function qualifyRequest($accessLevelNeeded, $api = false)
  981. {
  982. if ($this->getUserLevel() <= $accessLevelNeeded && $this->getUserLevel() !== null) {
  983. return true;
  984. } else {
  985. if ($api) {
  986. $this->setAPIResponse('error', 'Not Authorized', 401);
  987. }
  988. return false;
  989. }
  990. }
  991. public function getImages()
  992. {
  993. $allIconsPrep = array();
  994. $allIcons = array();
  995. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id", "index.html");
  996. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  997. $path = 'plugins/images/tabs/';
  998. $images = scandir($dirname);
  999. foreach ($images as $image) {
  1000. if (!in_array($image, $ignore)) {
  1001. $allIconsPrep[$image] = array(
  1002. 'path' => $path,
  1003. 'name' => $image
  1004. );
  1005. }
  1006. }
  1007. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'userTabs' . DIRECTORY_SEPARATOR;
  1008. $path = 'plugins/images/userTabs/';
  1009. $images = scandir($dirname);
  1010. foreach ($images as $image) {
  1011. if (!in_array($image, $ignore)) {
  1012. $allIconsPrep[$image] = array(
  1013. 'path' => $path,
  1014. 'name' => $image
  1015. );
  1016. }
  1017. }
  1018. ksort($allIconsPrep);
  1019. foreach ($allIconsPrep as $item) {
  1020. $allIcons[] = $item['path'] . $item['name'];
  1021. }
  1022. return $allIcons;
  1023. }
  1024. public function removeImage($image = null)
  1025. {
  1026. if (!$image) {
  1027. $this->setAPIResponse('error', 'No image supplied', 422);
  1028. return false;
  1029. }
  1030. $approvedPath = 'plugins/images/userTabs/';
  1031. $removeImage = $approvedPath . pathinfo($image, PATHINFO_BASENAME);
  1032. if ($this->approvedFileExtension($removeImage)) {
  1033. if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $removeImage)) {
  1034. $this->writeLog('success', 'Image Manager Function - Deleted Image [' . pathinfo($image, PATHINFO_BASENAME) . ']', $this->user['username']);
  1035. $this->setAPIResponse(null, pathinfo($image, PATHINFO_BASENAME) . ' has been deleted', null);
  1036. return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $removeImage));
  1037. } else {
  1038. $this->setAPIResponse('error', $removeImage . ' does not exist', 404);
  1039. return false;
  1040. }
  1041. } else {
  1042. $this->setAPIResponse('error', $removeImage . ' is not approved to be deleted', 409);
  1043. return false;
  1044. }
  1045. }
  1046. public function uploadImage()
  1047. {
  1048. $filesCheck = array_filter($_FILES);
  1049. if (!empty($filesCheck) && $this->approvedFileExtension($_FILES['file']['name']) && strpos($_FILES['file']['type'], 'image/') !== false) {
  1050. ini_set('upload_max_filesize', '10M');
  1051. ini_set('post_max_size', '10M');
  1052. $tempFile = $_FILES['file']['tmp_name'];
  1053. $targetPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'userTabs' . DIRECTORY_SEPARATOR;
  1054. $targetFile = $targetPath . $_FILES['file']['name'];
  1055. $this->setAPIResponse(null, pathinfo($_FILES['file']['name'], PATHINFO_BASENAME) . ' has been uploaded', null);
  1056. return move_uploaded_file($tempFile, $targetFile);
  1057. }
  1058. }
  1059. public function ping($pings)
  1060. {
  1061. if ($this->qualifyRequest($this->config['pingAuth'], true)) {
  1062. if (!$pings['list']) {
  1063. $this->setAPIResponse('error', 'No ping hostname/IP\'s entered', 409);
  1064. return null;
  1065. }
  1066. $pings = $pings['list'];
  1067. $type = gettype($pings);
  1068. $ping = new Ping("");
  1069. $ping->setTtl(128);
  1070. $ping->setTimeout(2);
  1071. switch ($type) {
  1072. case "array":
  1073. $results = [];
  1074. foreach ($pings as $k => $v) {
  1075. if (strpos($v, ':') !== false) {
  1076. $domain = explode(':', $v)[0];
  1077. $port = explode(':', $v)[1];
  1078. $ping->setHost($domain);
  1079. $ping->setPort($port);
  1080. $latency = $ping->ping('fsockopen');
  1081. } else {
  1082. $ping->setHost($v);
  1083. $latency = $ping->ping();
  1084. }
  1085. if ($latency || $latency === 0) {
  1086. $results[$v] = $latency;
  1087. } else {
  1088. $results[$v] = false;
  1089. }
  1090. }
  1091. break;
  1092. case "string":
  1093. if (strpos($pings, ':') !== false) {
  1094. $domain = explode(':', $pings)[0];
  1095. $port = explode(':', $pings)[1];
  1096. $ping->setHost($domain);
  1097. $ping->setPort($port);
  1098. $latency = $ping->ping('fsockopen');
  1099. } else {
  1100. $ping->setHost($pings);
  1101. $latency = $ping->ping();
  1102. }
  1103. if ($latency || $latency === 0) {
  1104. $results = $latency;
  1105. } else {
  1106. $results = null;
  1107. }
  1108. break;
  1109. }
  1110. return ($results) ?? null;
  1111. }
  1112. return null;
  1113. }
  1114. public function getCustomizeAppearance()
  1115. {
  1116. return array(
  1117. 'Top Bar' => array(
  1118. array(
  1119. 'type' => 'input',
  1120. 'name' => 'logo',
  1121. 'label' => 'Logo',
  1122. 'value' => $this->config['logo']
  1123. ),
  1124. array(
  1125. 'type' => 'input',
  1126. 'name' => 'title',
  1127. 'label' => 'Title',
  1128. 'value' => $this->config['title']
  1129. ),
  1130. array(
  1131. 'type' => 'switch',
  1132. 'name' => 'useLogo',
  1133. 'label' => 'Use Logo instead of Title',
  1134. 'value' => $this->config['useLogo'],
  1135. 'help' => 'Also sets the title of your site'
  1136. ),
  1137. array(
  1138. 'type' => 'input',
  1139. 'name' => 'description',
  1140. 'label' => 'Meta Description',
  1141. 'value' => $this->config['description'],
  1142. 'help' => 'Used to set the description for SEO meta tags'
  1143. ),
  1144. ),
  1145. 'Login Page' => array(
  1146. array(
  1147. 'type' => 'input',
  1148. 'name' => 'loginLogo',
  1149. 'label' => 'Login Logo',
  1150. 'value' => $this->config['loginLogo'],
  1151. ),
  1152. array(
  1153. 'type' => 'input',
  1154. 'name' => 'loginWallpaper',
  1155. 'label' => 'Login Wallpaper',
  1156. 'value' => $this->config['loginWallpaper'],
  1157. 'help' => 'You may enter multiple URL\'s using the CSV format. i.e. link#1,link#2,link#3'
  1158. ),
  1159. array(
  1160. 'type' => 'switch',
  1161. 'name' => 'useLogoLogin',
  1162. 'label' => 'Use Logo instead of Title on Login Page',
  1163. 'value' => $this->config['useLogoLogin']
  1164. ),
  1165. array(
  1166. 'type' => 'switch',
  1167. 'name' => 'minimalLoginScreen',
  1168. 'label' => 'Minimal Login Screen',
  1169. 'value' => $this->config['minimalLoginScreen']
  1170. )
  1171. ),
  1172. 'Options' => array(
  1173. array(
  1174. 'type' => 'switch',
  1175. 'name' => 'alternateHomepageHeaders',
  1176. 'label' => 'Alternate Homepage Titles',
  1177. 'value' => $this->config['alternateHomepageHeaders']
  1178. ),
  1179. array(
  1180. 'type' => 'switch',
  1181. 'name' => 'debugErrors',
  1182. 'label' => 'Show Debug Errors',
  1183. 'value' => $this->config['debugErrors']
  1184. ),
  1185. array(
  1186. 'type' => 'switch',
  1187. 'name' => 'githubMenuLink',
  1188. 'label' => 'Show GitHub Repo Link',
  1189. 'value' => $this->config['githubMenuLink']
  1190. ),
  1191. array(
  1192. 'type' => 'switch',
  1193. 'name' => 'organizrSupportMenuLink',
  1194. 'label' => 'Show Organizr Support Link',
  1195. 'value' => $this->config['organizrSupportMenuLink']
  1196. ),
  1197. array(
  1198. 'type' => 'switch',
  1199. 'name' => 'organizrDocsMenuLink',
  1200. 'label' => 'Show Organizr Docs Link',
  1201. 'value' => $this->config['organizrDocsMenuLink']
  1202. ),
  1203. array(
  1204. 'type' => 'switch',
  1205. 'name' => 'organizrSignoutMenuLink',
  1206. 'label' => 'Show Organizr Sign out & in Button on Sidebar',
  1207. 'value' => $this->config['organizrSignoutMenuLink']
  1208. ),
  1209. array(
  1210. 'type' => 'select',
  1211. 'name' => 'unsortedTabs',
  1212. 'label' => 'Unsorted Tab Placement',
  1213. 'value' => $this->config['unsortedTabs'],
  1214. 'options' => array(
  1215. array(
  1216. 'name' => 'Top',
  1217. 'value' => 'top'
  1218. ),
  1219. array(
  1220. 'name' => 'Bottom',
  1221. 'value' => 'bottom'
  1222. )
  1223. )
  1224. ),
  1225. array(
  1226. 'type' => 'input',
  1227. 'name' => 'gaTrackingID',
  1228. 'label' => 'Google Analytics Tracking ID',
  1229. 'placeholder' => 'e.g. UA-XXXXXXXXX-X',
  1230. 'value' => $this->config['gaTrackingID']
  1231. )
  1232. ),
  1233. 'Colors & Themes' => array(
  1234. array(
  1235. 'type' => 'html',
  1236. 'override' => 12,
  1237. 'label' => 'Custom CSS [Can replace colors from above]',
  1238. 'html' => '
  1239. <div class="row">
  1240. <div class="col-lg-12">
  1241. <div class="panel panel-info">
  1242. <div class="panel-heading">
  1243. <span lang="en">Notice</span>
  1244. </div>
  1245. <div class="panel-wrapper collapse in" aria-expanded="true">
  1246. <div class="panel-body">
  1247. <span lang="en">The value of #987654 is just a placeholder, you can change to any value you like.</span>
  1248. <span lang="en">To revert back to default, save with no value defined in the relevant field.</span>
  1249. </div>
  1250. </div>
  1251. </div>
  1252. </div>
  1253. </div>
  1254. ',
  1255. ),
  1256. array(
  1257. 'type' => 'blank',
  1258. 'label' => ''
  1259. ),
  1260. array(
  1261. 'type' => 'input',
  1262. 'name' => 'headerColor',
  1263. 'label' => 'Nav Bar Color',
  1264. 'value' => $this->config['headerColor'],
  1265. 'class' => 'pick-a-color',
  1266. 'attr' => 'data-original="' . $this->config['headerColor'] . '"'
  1267. ),
  1268. array(
  1269. 'type' => 'input',
  1270. 'name' => 'headerTextColor',
  1271. 'label' => 'Nav Bar Text Color',
  1272. 'value' => $this->config['headerTextColor'],
  1273. 'class' => 'pick-a-color',
  1274. 'attr' => 'data-original="' . $this->config['headerTextColor'] . '"'
  1275. ),
  1276. array(
  1277. 'type' => 'input',
  1278. 'name' => 'sidebarColor',
  1279. 'label' => 'Side Bar Color',
  1280. 'value' => $this->config['sidebarColor'],
  1281. 'class' => 'pick-a-color',
  1282. 'attr' => 'data-original="' . $this->config['sidebarColor'] . '"'
  1283. ),
  1284. array(
  1285. 'type' => 'input',
  1286. 'name' => 'sidebarTextColor',
  1287. 'label' => 'Side Bar Text Color',
  1288. 'value' => $this->config['sidebarTextColor'],
  1289. 'class' => 'pick-a-color',
  1290. 'attr' => 'data-original="' . $this->config['sidebarTextColor'] . '"'
  1291. ),
  1292. array(
  1293. 'type' => 'input',
  1294. 'name' => 'accentColor',
  1295. 'label' => 'Accent Color',
  1296. 'value' => $this->config['accentColor'],
  1297. 'class' => 'pick-a-color',
  1298. 'attr' => 'data-original="' . $this->config['accentColor'] . '"'
  1299. ),
  1300. array(
  1301. 'type' => 'input',
  1302. 'name' => 'accentTextColor',
  1303. 'label' => 'Accent Text Color',
  1304. 'value' => $this->config['accentTextColor'],
  1305. 'class' => 'pick-a-color',
  1306. 'attr' => 'data-original="' . $this->config['accentTextColor'] . '"'
  1307. ),
  1308. array(
  1309. 'type' => 'input',
  1310. 'name' => 'buttonColor',
  1311. 'label' => 'Button Color',
  1312. 'value' => $this->config['buttonColor'],
  1313. 'class' => 'pick-a-color',
  1314. 'attr' => 'data-original="' . $this->config['buttonColor'] . '"'
  1315. ),
  1316. array(
  1317. 'type' => 'input',
  1318. 'name' => 'buttonTextColor',
  1319. 'label' => 'Button Text Color',
  1320. 'value' => $this->config['buttonTextColor'],
  1321. 'class' => 'pick-a-color',
  1322. 'attr' => 'data-original="' . $this->config['buttonTextColor'] . '"'
  1323. ),
  1324. array(
  1325. 'type' => 'select',
  1326. 'name' => 'theme',
  1327. 'label' => 'Theme',
  1328. 'class' => 'themeChanger',
  1329. 'value' => $this->config['theme'],
  1330. 'options' => $this->getThemes()
  1331. ),
  1332. array(
  1333. 'type' => 'select',
  1334. 'name' => 'style',
  1335. 'label' => 'Style',
  1336. 'class' => 'styleChanger',
  1337. 'value' => $this->config['style'],
  1338. 'options' => array(
  1339. array(
  1340. 'name' => 'Light',
  1341. 'value' => 'light'
  1342. ),
  1343. array(
  1344. 'name' => 'Dark',
  1345. 'value' => 'dark'
  1346. ),
  1347. array(
  1348. 'name' => 'Horizontal',
  1349. 'value' => 'horizontal'
  1350. )
  1351. )
  1352. )
  1353. ),
  1354. 'Notifications' => array(
  1355. array(
  1356. 'type' => 'select',
  1357. 'name' => 'notificationBackbone',
  1358. 'class' => 'notifyChanger',
  1359. 'label' => 'Type',
  1360. 'value' => $this->config['notificationBackbone'],
  1361. 'options' => $this->optionNotificationTypes()
  1362. ),
  1363. array(
  1364. 'type' => 'select',
  1365. 'name' => 'notificationPosition',
  1366. 'class' => 'notifyPositionChanger',
  1367. 'label' => 'Position',
  1368. 'value' => $this->config['notificationPosition'],
  1369. 'options' => $this->optionNotificationPositions()
  1370. ),
  1371. array(
  1372. 'type' => 'html',
  1373. 'label' => 'Test Message',
  1374. 'html' => '
  1375. <div class="btn-group m-r-10 dropup">
  1376. <button aria-expanded="false" data-toggle="dropdown" class="btn btn-info btn-outline dropdown-toggle waves-effect waves-light" type="button">
  1377. <i class="fa fa-comment m-r-5"></i>
  1378. <span>Test </span>
  1379. </button>
  1380. <ul role="menu" class="dropdown-menu">
  1381. <li><a onclick="message(\'Test Message\',\'This is a success Message\',activeInfo.settings.notifications.position,\'#FFF\',\'success\',\'5000\');">Success</a></li>
  1382. <li><a onclick="message(\'Test Message\',\'This is a info Message\',activeInfo.settings.notifications.position,\'#FFF\',\'info\',\'5000\');">Info</a></li>
  1383. <li><a onclick="message(\'Test Message\',\'This is a warning Message\',activeInfo.settings.notifications.position,\'#FFF\',\'warning\',\'5000\');">Warning</a></li>
  1384. <li><a onclick="message(\'Test Message\',\'This is a error Message\',activeInfo.settings.notifications.position,\'#FFF\',\'error\',\'5000\');">Error</a></li>
  1385. </ul>
  1386. </div>
  1387. '
  1388. )
  1389. ),
  1390. 'FavIcon' => array(
  1391. array(
  1392. 'type' => 'textbox',
  1393. 'name' => 'favIcon',
  1394. 'class' => '',
  1395. 'label' => 'Fav Icon Code',
  1396. 'value' => $this->config['favIcon'],
  1397. 'placeholder' => 'Paste Contents from https://realfavicongenerator.net/',
  1398. 'attr' => 'rows="10"',
  1399. ),
  1400. array(
  1401. 'type' => 'html',
  1402. 'label' => 'Instructions',
  1403. 'html' => '
  1404. <div class="panel panel-default">
  1405. <div class="panel-heading">
  1406. <a href="https://realfavicongenerator.net/" target="_blank"><span class="label label-info m-l-5">Visit FavIcon Site</span></a>
  1407. </div>
  1408. <div class="panel-wrapper collapse in">
  1409. <div class="panel-body">
  1410. <ul class="list-icons">
  1411. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click [Select your Favicon picture]</li>
  1412. <li lang="en"><i class="fa fa-caret-right text-info"></i> Choose your image to use</li>
  1413. <li lang="en"><i class="fa fa-caret-right text-info"></i> Edit settings to your liking</li>
  1414. <li lang="en"><i class="fa fa-caret-right text-info"></i> At bottom of page on [Favicon Generator Options] under [Path] choose [I cannot or I do not want to place favicon files at the root of my web site.]</li>
  1415. <li lang="en"><i class="fa fa-caret-right text-info"></i> Enter this path <code>plugins/images/faviconCustom</code></li>
  1416. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click [Generate your Favicons and HTML code]</li>
  1417. <li lang="en"><i class="fa fa-caret-right text-info"></i> Download and unzip file and place in <code>plugins/images/faviconCustom</code></li>
  1418. <li lang="en"><i class="fa fa-caret-right text-info"></i> Copy code and paste inside left box</li>
  1419. </ul>
  1420. </div>
  1421. </div>
  1422. </div>
  1423. '
  1424. ),
  1425. ),
  1426. 'Custom CSS' => array(
  1427. array(
  1428. 'type' => 'html',
  1429. 'override' => 12,
  1430. 'label' => 'Custom CSS [Can replace colors from above]',
  1431. 'html' => '<button type="button" class="hidden saveCss btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customCSSEditor" style="height:300px">' . htmlentities($this->config['customCss']) . '</div>'
  1432. ),
  1433. array(
  1434. 'type' => 'textbox',
  1435. 'name' => 'customCss',
  1436. 'class' => 'hidden cssTextarea',
  1437. 'label' => '',
  1438. 'value' => $this->config['customCss'],
  1439. 'placeholder' => 'No &lt;style&gt; tags needed',
  1440. 'attr' => 'rows="10"',
  1441. ),
  1442. ),
  1443. 'Theme CSS' => array(
  1444. array(
  1445. 'type' => 'html',
  1446. 'override' => 12,
  1447. 'label' => 'Theme CSS [Can replace colors from above]',
  1448. 'html' => '<button type="button" class="hidden saveCssTheme btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customThemeCSSEditor" style="height:300px">' . htmlentities($this->config['customThemeCss']) . '</div>'
  1449. ),
  1450. array(
  1451. 'type' => 'textbox',
  1452. 'name' => 'customThemeCss',
  1453. 'class' => 'hidden cssThemeTextarea',
  1454. 'label' => '',
  1455. 'value' => $this->config['customThemeCss'],
  1456. 'placeholder' => 'No &lt;style&gt; tags needed',
  1457. 'attr' => 'rows="10"',
  1458. ),
  1459. ),
  1460. 'Custom Javascript' => array(
  1461. array(
  1462. 'type' => 'html',
  1463. 'override' => 12,
  1464. 'label' => 'Custom Javascript',
  1465. 'html' => '<button type="button" class="hidden saveJava btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customJavaEditor" style="height:300px">' . htmlentities($this->config['customJava']) . '</div>'
  1466. ),
  1467. array(
  1468. 'type' => 'textbox',
  1469. 'name' => 'customJava',
  1470. 'class' => 'hidden javaTextarea',
  1471. 'label' => '',
  1472. 'value' => $this->config['customJava'],
  1473. 'placeholder' => 'No &lt;script&gt; tags needed',
  1474. 'attr' => 'rows="10"',
  1475. ),
  1476. ),
  1477. 'Theme Javascript' => array(
  1478. array(
  1479. 'type' => 'html',
  1480. 'override' => 12,
  1481. 'label' => 'Theme Javascript',
  1482. 'html' => '<button type="button" class="hidden saveJavaTheme btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customThemeJavaEditor" style="height:300px">' . htmlentities($this->config['customThemeJava']) . '</div>'
  1483. ),
  1484. array(
  1485. 'type' => 'textbox',
  1486. 'name' => 'customThemeJava',
  1487. 'class' => 'hidden javaThemeTextarea',
  1488. 'label' => '',
  1489. 'value' => $this->config['customThemeJava'],
  1490. 'placeholder' => 'No &lt;script&gt; tags needed',
  1491. 'attr' => 'rows="10"',
  1492. ),
  1493. ),
  1494. );
  1495. }
  1496. public function loadAppearance()
  1497. {
  1498. $appearance['logo'] = $this->config['logo'];
  1499. $appearance['title'] = $this->config['title'];
  1500. $appearance['useLogo'] = $this->config['useLogo'];
  1501. $appearance['useLogoLogin'] = $this->config['useLogoLogin'];
  1502. $appearance['headerColor'] = $this->config['headerColor'];
  1503. $appearance['headerTextColor'] = $this->config['headerTextColor'];
  1504. $appearance['sidebarColor'] = $this->config['sidebarColor'];
  1505. $appearance['headerTextColor'] = $this->config['headerTextColor'];
  1506. $appearance['sidebarTextColor'] = $this->config['sidebarTextColor'];
  1507. $appearance['accentColor'] = $this->config['accentColor'];
  1508. $appearance['accentTextColor'] = $this->config['accentTextColor'];
  1509. $appearance['buttonColor'] = $this->config['buttonColor'];
  1510. $appearance['buttonTextColor'] = $this->config['buttonTextColor'];
  1511. $appearance['buttonTextHoverColor'] = $this->config['buttonTextHoverColor'];
  1512. $appearance['buttonHoverColor'] = $this->config['buttonHoverColor'];
  1513. $appearance['loginWallpaper'] = $this->config['loginWallpaper'];
  1514. $appearance['loginLogo'] = $this->config['loginLogo'];
  1515. $appearance['customCss'] = $this->config['customCss'];
  1516. $appearance['customThemeCss'] = $this->config['customThemeCss'];
  1517. $appearance['customJava'] = $this->config['customJava'];
  1518. $appearance['customThemeJava'] = $this->config['customThemeJava'];
  1519. return $appearance;
  1520. }
  1521. public function getSettingsMain()
  1522. {
  1523. return array(
  1524. 'Github' => array(
  1525. array(
  1526. 'type' => 'select',
  1527. 'name' => 'branch',
  1528. 'label' => 'Branch',
  1529. 'value' => $this->config['branch'],
  1530. 'options' => $this->getBranches(),
  1531. 'disabled' => $this->docker,
  1532. 'help' => ($this->docker) ? 'Since you are using the Official Docker image, Change the image to change the branch' : 'Choose which branch to download from'
  1533. ),
  1534. array(
  1535. 'type' => 'button',
  1536. 'name' => 'force-install-branch',
  1537. 'label' => 'Force Install Branch',
  1538. 'class' => 'updateNow',
  1539. 'icon' => 'fa fa-download',
  1540. 'text' => 'Retrieve',
  1541. 'attr' => ($this->docker) ? 'title="You can just restart your docker to update"' : '',
  1542. 'help' => ($this->docker) ? 'Since you are using the official Docker image, you can just restart your Docker container to update Organizr' : 'This will re-download all of the source files for Organizr'
  1543. )
  1544. ),
  1545. 'API' => array(
  1546. array(
  1547. 'type' => 'password-alt',
  1548. 'name' => 'organizrAPI',
  1549. 'label' => 'Organizr API',
  1550. 'value' => $this->config['organizrAPI']
  1551. ),
  1552. array(
  1553. 'type' => 'button',
  1554. 'label' => 'Generate New API Key',
  1555. 'class' => 'newAPIKey',
  1556. 'icon' => 'fa fa-refresh',
  1557. 'text' => 'Generate'
  1558. )
  1559. ),
  1560. 'Authentication' => array(
  1561. array(
  1562. 'type' => 'select',
  1563. 'name' => 'authType',
  1564. 'id' => 'authSelect',
  1565. 'label' => 'Authentication Type',
  1566. 'value' => $this->config['authType'],
  1567. 'options' => $this->getAuthTypes()
  1568. ),
  1569. array(
  1570. 'type' => 'select',
  1571. 'name' => 'authBackend',
  1572. 'id' => 'authBackendSelect',
  1573. 'label' => 'Authentication Backend',
  1574. 'class' => 'backendAuth switchAuth',
  1575. 'value' => $this->config['authBackend'],
  1576. 'options' => $this->getAuthBackends()
  1577. ),
  1578. array(
  1579. 'type' => 'password-alt',
  1580. 'name' => 'plexToken',
  1581. 'class' => 'plexAuth switchAuth',
  1582. 'label' => 'Plex Token',
  1583. 'value' => $this->config['plexToken'],
  1584. 'placeholder' => 'Use Get Token Button'
  1585. ),
  1586. array(
  1587. 'type' => 'button',
  1588. 'label' => 'Get Plex Token',
  1589. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  1590. 'icon' => 'fa fa-ticket',
  1591. 'text' => 'Retrieve',
  1592. 'href' => '#auth-plex-token-form',
  1593. 'attr' => 'data-effect="mfp-3d-unfold"'
  1594. ),
  1595. array(
  1596. 'type' => 'password-alt',
  1597. 'name' => 'plexID',
  1598. 'class' => 'plexAuth switchAuth',
  1599. 'label' => 'Plex Machine',
  1600. 'value' => $this->config['plexID'],
  1601. 'placeholder' => 'Use Get Plex Machine Button'
  1602. ),
  1603. array(
  1604. 'type' => 'button',
  1605. 'label' => 'Get Plex Machine',
  1606. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  1607. 'icon' => 'fa fa-id-badge',
  1608. 'text' => 'Retrieve',
  1609. 'href' => '#auth-plex-machine-form',
  1610. 'attr' => 'data-effect="mfp-3d-unfold"'
  1611. ),
  1612. array(
  1613. 'type' => 'input',
  1614. 'name' => 'plexAdmin',
  1615. 'label' => 'Plex Admin Username',
  1616. 'class' => 'plexAuth switchAuth',
  1617. 'value' => $this->config['plexAdmin'],
  1618. 'placeholder' => 'Admin username for Plex'
  1619. ),
  1620. array(
  1621. 'type' => 'switch',
  1622. 'name' => 'plexoAuth',
  1623. 'label' => 'Enable Plex oAuth',
  1624. 'class' => 'plexAuth switchAuth',
  1625. 'value' => $this->config['plexoAuth']
  1626. ),
  1627. array(
  1628. 'type' => 'switch',
  1629. 'name' => 'plexStrictFriends',
  1630. 'label' => 'Strict Plex Friends ',
  1631. 'class' => 'plexAuth switchAuth',
  1632. 'value' => $this->config['plexStrictFriends'],
  1633. 'help' => 'Enabling this will only allow Friends that have shares to the Machine ID entered above to login, Having this disabled will allow all Friends on your Friends list to login'
  1634. ),
  1635. array(
  1636. 'type' => 'switch',
  1637. 'name' => 'ignoreTFALocal',
  1638. 'label' => 'Ignore External 2FA on Local Subnet',
  1639. 'value' => $this->config['ignoreTFALocal'],
  1640. 'help' => 'Enabling this will bypass external 2FA security if user is on local Subnet'
  1641. ),
  1642. array(
  1643. 'type' => 'input',
  1644. 'name' => 'authBackendHost',
  1645. 'class' => 'ldapAuth ftpAuth switchAuth',
  1646. 'label' => 'Host Address',
  1647. 'value' => $this->config['authBackendHost'],
  1648. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  1649. ),
  1650. array(
  1651. 'type' => 'input',
  1652. 'name' => 'authBaseDN',
  1653. 'class' => 'ldapAuth switchAuth',
  1654. 'label' => 'Host Base DN',
  1655. 'value' => $this->config['authBaseDN'],
  1656. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  1657. ),
  1658. array(
  1659. 'type' => 'select',
  1660. 'name' => 'ldapType',
  1661. 'id' => 'ldapType',
  1662. 'label' => 'LDAP Backend Type',
  1663. 'class' => 'ldapAuth switchAuth',
  1664. 'value' => $this->config['ldapType'],
  1665. 'options' => $this->getLDAPOptions()
  1666. ),
  1667. array(
  1668. 'type' => 'input',
  1669. 'name' => 'authBackendHostPrefix',
  1670. 'class' => 'ldapAuth switchAuth',
  1671. 'label' => 'Account Prefix',
  1672. 'id' => 'authBackendHostPrefix-input',
  1673. 'value' => $this->config['authBackendHostPrefix'],
  1674. 'placeholder' => 'Account prefix - i.e. Controller\ from Controller\Username for AD - uid= for OpenLDAP'
  1675. ),
  1676. array(
  1677. 'type' => 'input',
  1678. 'name' => 'authBackendHostSuffix',
  1679. 'class' => 'ldapAuth switchAuth',
  1680. 'label' => 'Account Suffix',
  1681. 'id' => 'authBackendHostSuffix-input',
  1682. 'value' => $this->config['authBackendHostSuffix'],
  1683. 'placeholder' => 'Account suffix - start with comma - ,ou=people,dc=domain,dc=tld'
  1684. ),
  1685. array(
  1686. 'type' => 'input',
  1687. 'name' => 'ldapBindUsername',
  1688. 'class' => 'ldapAuth switchAuth',
  1689. 'label' => 'Bind Username',
  1690. 'value' => $this->config['ldapBindUsername'],
  1691. 'placeholder' => ''
  1692. ),
  1693. array(
  1694. 'type' => 'password',
  1695. 'name' => 'ldapBindPassword',
  1696. 'class' => 'ldapAuth switchAuth',
  1697. 'label' => 'Password',
  1698. 'value' => $this->config['ldapBindPassword']
  1699. ),
  1700. array(
  1701. 'type' => 'html',
  1702. 'class' => 'ldapAuth switchAuth',
  1703. 'label' => 'Account DN',
  1704. 'html' => '<span id="accountDN" class="ldapAuth switchAuth">' . $this->config['authBackendHostPrefix'] . 'TestAcct' . $this->config['authBackendHostSuffix'] . '</span>'
  1705. ),
  1706. array(
  1707. 'type' => 'switch',
  1708. 'name' => 'ldapSSL',
  1709. 'class' => 'ldapAuth switchAuth',
  1710. 'label' => 'Enable LDAP SSL',
  1711. 'value' => $this->config['ldapSSL'],
  1712. 'help' => 'This will enable the use of SSL for LDAP connections'
  1713. ),
  1714. array(
  1715. 'type' => 'switch',
  1716. 'name' => 'ldapSSL',
  1717. 'class' => 'ldapAuth switchAuth',
  1718. 'label' => 'Enable LDAP TLS',
  1719. 'value' => $this->config['ldapTLS'],
  1720. 'help' => 'This will enable the use of TLS for LDAP connections'
  1721. ),
  1722. array(
  1723. 'type' => 'button',
  1724. 'name' => 'test-button-ldap',
  1725. 'label' => 'Test Connection',
  1726. 'icon' => 'fa fa-flask',
  1727. 'class' => 'ldapAuth switchAuth',
  1728. 'text' => 'Test Connection',
  1729. 'attr' => 'onclick="testAPIConnection(\'ldap\')"',
  1730. 'help' => 'Remember! Please save before using the test button!'
  1731. ),
  1732. array(
  1733. 'type' => 'button',
  1734. 'name' => 'test-button-ldap-login',
  1735. 'label' => 'Test Login',
  1736. 'icon' => 'fa fa-flask',
  1737. 'class' => 'ldapAuth switchAuth',
  1738. 'text' => 'Test Login',
  1739. 'attr' => 'onclick="showLDAPLoginTest()"'
  1740. ),
  1741. array(
  1742. 'type' => 'input',
  1743. 'name' => 'embyURL',
  1744. 'class' => 'embyAuth switchAuth',
  1745. 'label' => 'Emby/Jellyfin URL',
  1746. 'value' => $this->config['embyURL'],
  1747. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  1748. 'placeholder' => 'http(s)://hostname:port'
  1749. ),
  1750. array(
  1751. 'type' => 'password-alt',
  1752. 'name' => 'embyToken',
  1753. 'class' => 'embyAuth switchAuth',
  1754. 'label' => 'Emby/Jellyfin Token',
  1755. 'value' => $this->config['embyToken'],
  1756. 'placeholder' => ''
  1757. ),
  1758. ),
  1759. 'Security' => array(
  1760. array(
  1761. 'type' => 'number',
  1762. 'name' => 'loginAttempts',
  1763. 'label' => 'Max Login Attempts',
  1764. 'value' => $this->config['loginAttempts'],
  1765. 'placeholder' => ''
  1766. ),
  1767. array(
  1768. 'type' => 'select',
  1769. 'name' => 'loginLockout',
  1770. 'label' => 'Login Lockout Seconds',
  1771. 'value' => $this->config['loginLockout'],
  1772. 'options' => $this->optionTime()
  1773. ),
  1774. array(
  1775. 'type' => 'number',
  1776. 'name' => 'lockoutTimeout',
  1777. 'label' => 'Inactivity Timer [Minutes]',
  1778. 'value' => $this->config['lockoutTimeout'],
  1779. 'placeholder' => ''
  1780. ),
  1781. array(
  1782. 'type' => 'select',
  1783. 'name' => 'lockoutMinAuth',
  1784. 'label' => 'Lockout Groups From',
  1785. 'value' => $this->config['lockoutMinAuth'],
  1786. 'options' => $this->groupSelect()
  1787. ),
  1788. array(
  1789. 'type' => 'select',
  1790. 'name' => 'lockoutMaxAuth',
  1791. 'label' => 'Lockout Groups To',
  1792. 'value' => $this->config['lockoutMaxAuth'],
  1793. 'options' => $this->groupSelect()
  1794. ),
  1795. array(
  1796. 'type' => 'switch',
  1797. 'name' => 'lockoutSystem',
  1798. 'label' => 'Inactivity Lock',
  1799. 'value' => $this->config['lockoutSystem']
  1800. ),
  1801. array(
  1802. 'type' => 'select',
  1803. 'name' => 'debugAreaAuth',
  1804. 'label' => 'Minimum Authentication for Debug Area',
  1805. 'value' => $this->config['debugAreaAuth'],
  1806. 'options' => $this->groupSelect()
  1807. ),
  1808. array(
  1809. 'type' => 'switch',
  1810. 'name' => 'authDebug',
  1811. 'label' => 'Nginx Auth Debug',
  1812. 'help' => 'Important! Do not keep this enabled for too long as this opens up Authentication while testing.',
  1813. 'value' => $this->config['authDebug'],
  1814. 'class' => 'authDebug'
  1815. ),
  1816. array(
  1817. 'type' => 'select2',
  1818. 'class' => 'select2-multiple',
  1819. 'id' => 'sandbox-select',
  1820. 'name' => 'sandbox',
  1821. 'label' => 'iFrame Sandbox',
  1822. 'value' => $this->config['sandbox'],
  1823. 'help' => 'WARNING! This can potentially mess up your iFrames',
  1824. 'options' => array(
  1825. array(
  1826. 'name' => 'Allow Presentation',
  1827. 'value' => 'allow-presentation'
  1828. ),
  1829. array(
  1830. 'name' => 'Allow Forms',
  1831. 'value' => 'allow-forms'
  1832. ),
  1833. array(
  1834. 'name' => 'Allow Same Origin',
  1835. 'value' => 'allow-same-origin'
  1836. ),
  1837. array(
  1838. 'name' => 'Allow Pointer Lock',
  1839. 'value' => 'allow-pointer-lock'
  1840. ),
  1841. array(
  1842. 'name' => 'Allow Scripts',
  1843. 'value' => 'allow-scripts'
  1844. ), array(
  1845. 'name' => 'Allow Popups',
  1846. 'value' => 'allow-popups'
  1847. ),
  1848. array(
  1849. 'name' => 'Allow Modals',
  1850. 'value' => 'allow-modals'
  1851. ),
  1852. array(
  1853. 'name' => 'Allow Top Navigation',
  1854. 'value' => 'allow-top-navigation'
  1855. ),
  1856. array(
  1857. 'name' => 'Allow Downloads',
  1858. 'value' => 'allow-downloads'
  1859. ),
  1860. )
  1861. ),
  1862. array(
  1863. 'type' => 'switch',
  1864. 'name' => 'traefikAuthEnable',
  1865. 'label' => 'Enable Traefik Auth Redirect',
  1866. 'help' => 'This will enable the webserver to forward errors so traefik will accept them',
  1867. 'value' => $this->config['traefikAuthEnable']
  1868. ),
  1869. ),
  1870. 'Performance' => array(
  1871. array(
  1872. 'type' => 'switch',
  1873. 'name' => 'performanceDisableIconDropdown',
  1874. 'label' => 'Disable Icon Dropdown',
  1875. 'help' => 'Disable select dropdown boxes on new and edit tab forms',
  1876. 'value' => $this->config['performanceDisableIconDropdown'],
  1877. ),
  1878. array(
  1879. 'type' => 'switch',
  1880. 'name' => 'performanceDisableImageDropdown',
  1881. 'label' => 'Disable Image Dropdown',
  1882. 'help' => 'Disable select dropdown boxes on new and edit tab forms',
  1883. 'value' => $this->config['performanceDisableImageDropdown'],
  1884. ),
  1885. ),
  1886. 'Login' => array(
  1887. array(
  1888. 'type' => 'password-alt',
  1889. 'name' => 'registrationPassword',
  1890. 'label' => 'Registration Password',
  1891. 'help' => 'Sets the password for the Registration form on the login screen',
  1892. 'value' => $this->config['registrationPassword'],
  1893. ),
  1894. array(
  1895. 'type' => 'switch',
  1896. 'name' => 'hideRegistration',
  1897. 'label' => 'Hide Registration',
  1898. 'help' => 'Enable this to hide the Registration button on the login screen',
  1899. 'value' => $this->config['hideRegistration'],
  1900. ),
  1901. array(
  1902. 'type' => 'number',
  1903. 'name' => 'rememberMeDays',
  1904. 'label' => 'Remember Me Length',
  1905. 'help' => 'Number of days cookies and tokens will be valid for',
  1906. 'value' => $this->config['rememberMeDays'],
  1907. 'placeholder' => '',
  1908. 'attr' => 'min="1"'
  1909. ),
  1910. array(
  1911. 'type' => 'switch',
  1912. 'name' => 'rememberMe',
  1913. 'label' => 'Remember Me',
  1914. 'help' => 'Default status of Remember Me button on login screen',
  1915. 'value' => $this->config['rememberMe'],
  1916. ),
  1917. array(
  1918. 'type' => 'input',
  1919. 'name' => 'localIPFrom',
  1920. 'label' => 'Override Local IP From',
  1921. 'value' => $this->config['localIPFrom'],
  1922. 'placeholder' => 'i.e. 123.123.123.123',
  1923. 'help' => 'IPv4 only at the moment - This will set your login as local if your IP falls within the From and To'
  1924. ),
  1925. array(
  1926. 'type' => 'input',
  1927. 'name' => 'localIPTo',
  1928. 'label' => 'Override Local IP To',
  1929. 'value' => $this->config['localIPTo'],
  1930. 'placeholder' => 'i.e. 123.123.123.123',
  1931. 'help' => 'IPv4 only at the moment - This will set your login as local if your IP falls within the From and To'
  1932. ),
  1933. array(
  1934. 'type' => 'input',
  1935. 'name' => 'wanDomain',
  1936. 'label' => 'WAN Domain',
  1937. 'value' => $this->config['wanDomain'],
  1938. 'placeholder' => 'only domain and tld - i.e. domain.com',
  1939. 'help' => 'Enter domain if you wish to be forwarded to a local address - Local Address filled out on next item'
  1940. ),
  1941. array(
  1942. 'type' => 'input',
  1943. 'name' => 'localAddress',
  1944. 'label' => 'Local Address',
  1945. 'value' => $this->config['localAddress'],
  1946. 'placeholder' => 'http://home.local',
  1947. 'help' => 'Full local address of organizr install - i.e. http://home.local or http://192.168.0.100'
  1948. ),
  1949. array(
  1950. 'type' => 'switch',
  1951. 'name' => 'enableLocalAddressForward',
  1952. 'label' => 'Enable Local Address Forward',
  1953. 'help' => 'Enables the local address forward if on local address and accessed from WAN Domain',
  1954. 'value' => $this->config['enableLocalAddressForward'],
  1955. ),
  1956. ),
  1957. 'Auth Proxy' => array(
  1958. array(
  1959. 'type' => 'switch',
  1960. 'name' => 'authProxyEnabled',
  1961. 'label' => 'Auth Proxy',
  1962. 'help' => 'Enable option to set Auth Proxy Header Login',
  1963. 'value' => $this->config['authProxyEnabled'],
  1964. ),
  1965. array(
  1966. 'type' => 'input',
  1967. 'name' => 'authProxyHeaderName',
  1968. 'label' => 'Auth Proxy Header Name',
  1969. 'value' => $this->config['authProxyHeaderName'],
  1970. 'placeholder' => 'i.e. X-Forwarded-User',
  1971. 'help' => 'Please choose a unique value for added security'
  1972. ),
  1973. array(
  1974. 'type' => 'input',
  1975. 'name' => 'authProxyWhitelist',
  1976. 'label' => 'Auth Proxy Whitelist',
  1977. 'value' => $this->config['authProxyWhitelist'],
  1978. 'placeholder' => 'i.e. 10.0.0.0/24 or 10.0.0.20',
  1979. 'help' => 'IPv4 only at the moment - This must be set to work, will accept subnet or IP address'
  1980. ),
  1981. ),
  1982. 'Ping' => array(
  1983. array(
  1984. 'type' => 'select',
  1985. 'name' => 'pingAuth',
  1986. 'label' => 'Minimum Authentication',
  1987. 'value' => $this->config['pingAuth'],
  1988. 'options' => $this->groupSelect()
  1989. ),
  1990. array(
  1991. 'type' => 'select',
  1992. 'name' => 'pingAuthMessage',
  1993. 'label' => 'Minimum Authentication for Message and Sound',
  1994. 'value' => $this->config['pingAuthMessage'],
  1995. 'options' => $this->groupSelect()
  1996. ),
  1997. array(
  1998. 'type' => 'select',
  1999. 'name' => 'pingOnlineSound',
  2000. 'label' => 'Online Sound',
  2001. 'value' => $this->config['pingOnlineSound'],
  2002. 'options' => $this->getSounds()
  2003. ),
  2004. array(
  2005. 'type' => 'select',
  2006. 'name' => 'pingOfflineSound',
  2007. 'label' => 'Offline Sound',
  2008. 'value' => $this->config['pingOfflineSound'],
  2009. 'options' => $this->getSounds()
  2010. ),
  2011. array(
  2012. 'type' => 'switch',
  2013. 'name' => 'pingMs',
  2014. 'label' => 'Show Ping Time',
  2015. 'value' => $this->config['pingMs']
  2016. ),
  2017. array(
  2018. 'type' => 'switch',
  2019. 'name' => 'statusSounds',
  2020. 'label' => 'Enable Notify Sounds',
  2021. 'value' => $this->config['statusSounds'],
  2022. 'help' => 'Will play a sound if the server goes down and will play sound if comes back up.',
  2023. ),
  2024. array(
  2025. 'type' => 'select',
  2026. 'name' => 'pingAuthMs',
  2027. 'label' => 'Minimum Authentication for Time Display',
  2028. 'value' => $this->config['pingAuthMs'],
  2029. 'options' => $this->groupSelect()
  2030. ),
  2031. array(
  2032. 'type' => 'select',
  2033. 'name' => 'adminPingRefresh',
  2034. 'label' => 'Admin Refresh Seconds',
  2035. 'value' => $this->config['adminPingRefresh'],
  2036. 'options' => $this->optionTime()
  2037. ),
  2038. array(
  2039. 'type' => 'select',
  2040. 'name' => 'otherPingRefresh',
  2041. 'label' => 'Everyone Refresh Seconds',
  2042. 'value' => $this->config['otherPingRefresh'],
  2043. 'options' => $this->optionTime()
  2044. ),
  2045. )
  2046. );
  2047. }
  2048. public function getSettingsSSO()
  2049. {
  2050. return array(
  2051. 'FYI' => array(
  2052. array(
  2053. 'type' => 'html',
  2054. 'label' => 'Important Information',
  2055. 'override' => 12,
  2056. 'html' => '
  2057. <div class="row">
  2058. <div class="col-lg-12">
  2059. <div class="panel panel-info">
  2060. <div class="panel-heading">
  2061. <span lang="en">Notice</span>
  2062. </div>
  2063. <div class="panel-wrapper collapse in" aria-expanded="true">
  2064. <div class="panel-body">
  2065. <span lang="en">This is not the same as database authentication - i.e. Plex Authentication | Emby Authentication | FTP Authentication<br/>Click Main on the sub-menu above.</span>
  2066. </div>
  2067. </div>
  2068. </div>
  2069. </div>
  2070. </div>
  2071. '
  2072. )
  2073. ),
  2074. 'Plex' => array(
  2075. array(
  2076. 'type' => 'password-alt',
  2077. 'name' => 'plexToken',
  2078. 'label' => 'Plex Token',
  2079. 'value' => $this->config['plexToken'],
  2080. 'placeholder' => 'Use Get Token Button'
  2081. ),
  2082. array(
  2083. 'type' => 'button',
  2084. 'label' => 'Get Plex Token',
  2085. 'class' => 'popup-with-form getPlexTokenSSO',
  2086. 'icon' => 'fa fa-ticket',
  2087. 'text' => 'Retrieve',
  2088. 'href' => '#sso-plex-token-form',
  2089. 'attr' => 'data-effect="mfp-3d-unfold"'
  2090. ),
  2091. array(
  2092. 'type' => 'password-alt',
  2093. 'name' => 'plexID',
  2094. 'label' => 'Plex Machine',
  2095. 'value' => $this->config['plexID'],
  2096. 'placeholder' => 'Use Get Plex Machine Button'
  2097. ),
  2098. array(
  2099. 'type' => 'button',
  2100. 'label' => 'Get Plex Machine',
  2101. 'class' => 'popup-with-form getPlexMachineSSO',
  2102. 'icon' => 'fa fa-id-badge',
  2103. 'text' => 'Retrieve',
  2104. 'href' => '#sso-plex-machine-form',
  2105. 'attr' => 'data-effect="mfp-3d-unfold"'
  2106. ),
  2107. array(
  2108. 'type' => 'input',
  2109. 'name' => 'plexAdmin',
  2110. 'label' => 'Admin Username',
  2111. 'value' => $this->config['plexAdmin'],
  2112. 'placeholder' => 'Admin username for Plex'
  2113. ),
  2114. array(
  2115. 'type' => 'blank',
  2116. 'label' => ''
  2117. ),
  2118. array(
  2119. 'type' => 'html',
  2120. 'label' => 'Plex Note',
  2121. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  2122. ),
  2123. array(
  2124. 'type' => 'switch',
  2125. 'name' => 'ssoPlex',
  2126. 'label' => 'Enable',
  2127. 'value' => $this->config['ssoPlex']
  2128. )
  2129. ),
  2130. 'Tautulli' => array(
  2131. array(
  2132. 'type' => 'input',
  2133. 'name' => 'tautulliURL',
  2134. 'label' => 'Tautulli URL',
  2135. 'value' => $this->config['tautulliURL'],
  2136. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  2137. 'placeholder' => 'http(s)://hostname:port'
  2138. ),
  2139. array(
  2140. 'type' => 'switch',
  2141. 'name' => 'ssoTautulli',
  2142. 'label' => 'Enable',
  2143. 'value' => $this->config['ssoTautulli']
  2144. )
  2145. ),
  2146. 'Ombi' => array(
  2147. array(
  2148. 'type' => 'input',
  2149. 'name' => 'ombiURL',
  2150. 'label' => 'Ombi URL',
  2151. 'value' => $this->config['ombiURL'],
  2152. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  2153. 'placeholder' => 'http(s)://hostname:port'
  2154. ),
  2155. array(
  2156. 'type' => 'password-alt',
  2157. 'name' => 'ombiToken',
  2158. 'label' => 'Token',
  2159. 'value' => $this->config['ombiToken']
  2160. ),
  2161. array(
  2162. 'type' => 'switch',
  2163. 'name' => 'ssoOmbi',
  2164. 'label' => 'Enable',
  2165. 'value' => $this->config['ssoOmbi']
  2166. )
  2167. )
  2168. );
  2169. }
  2170. public function updateConfigMultiple($array)
  2171. {
  2172. return ($this->updateConfig($array)) ? true : false;
  2173. }
  2174. public function updateConfigItems($array)
  2175. {
  2176. if (!count($array)) {
  2177. $this->setAPIResponse('error', 'No data submitted', 409);
  2178. return false;
  2179. }
  2180. $newItem = array();
  2181. foreach ($array as $k => $v) {
  2182. $v = $v ?? '';
  2183. switch ($v) {
  2184. case 'true':
  2185. $v = (bool)true;
  2186. break;
  2187. case 'false':
  2188. $v = (bool)false;
  2189. break;
  2190. }
  2191. // Hash
  2192. if ((stripos($k, 'password') !== false)) {
  2193. if (!$this->isEncrypted($v)) {
  2194. if ($v !== '') {
  2195. $v = $this->encrypt($v);
  2196. }
  2197. }
  2198. }
  2199. if (strtolower($k) !== 'formkey') {
  2200. $newItem[$k] = $v;
  2201. }
  2202. }
  2203. $this->setAPIResponse('success', 'Config items updated', 200);
  2204. return ($this->updateConfig($newItem)) ? true : false;
  2205. }
  2206. public function updateConfigItem($array)
  2207. {
  2208. $array['value'] = $array['value'] ?? '';
  2209. switch ($array['value']) {
  2210. case 'true':
  2211. $array['value'] = (bool)true;
  2212. break;
  2213. case 'false':
  2214. $array['value'] = (bool)false;
  2215. break;
  2216. }
  2217. // Hash
  2218. if ($array['type'] == 'password') {
  2219. $array['value'] = $this->encrypt($array['value']);
  2220. }
  2221. $newItem = array(
  2222. $array['name'] => $array['value']
  2223. );
  2224. return ($this->updateConfig($newItem)) ? true : false;
  2225. }
  2226. public function testWizardPath($array)
  2227. {
  2228. if ($this->hasDB()) {
  2229. $this->setAPIResponse('error', 'Endpoint disabled as database already exists', 401);
  2230. return false;
  2231. }
  2232. $path = $array['path'] ?? null;
  2233. if (file_exists($path)) {
  2234. if (is_writable($path)) {
  2235. $this->setAPIResponse('success', 'Path exists and is writable', 200);
  2236. return true;
  2237. }
  2238. } else {
  2239. if (is_writable(dirname($path, 1))) {
  2240. if (mkdir($path, 0760, true)) {
  2241. $this->setAPIResponse('success', 'Path is writable - Creating now', 200);
  2242. return true;
  2243. }
  2244. }
  2245. }
  2246. $this->setAPIResponse('error', 'Path is not writable', 401);
  2247. return false;
  2248. }
  2249. public function wizardConfig($array)
  2250. {
  2251. $dbName = $array['dbName'] ?? null;
  2252. $path = $array['dbPath'] ?? null;
  2253. $license = $array['license'] ?? null;
  2254. $hashKey = $array['hashKey'] ?? null;
  2255. $api = $array['api'] ?? null;
  2256. $registrationPassword = $array['registrationPassword'] ?? null;
  2257. $username = $array['username'] ?? null;
  2258. $password = $array['password'] ?? null;
  2259. $email = $array['email'] ?? null;
  2260. $validation = array(
  2261. 'dbName' => $dbName,
  2262. 'dbPath' => $path,
  2263. 'license' => $license,
  2264. 'hashKey' => $hashKey,
  2265. 'api' => $api,
  2266. 'registrationPassword' => $registrationPassword,
  2267. 'username' => $username,
  2268. 'password' => $password,
  2269. 'email' => $email,
  2270. );
  2271. foreach ($validation as $k => $v) {
  2272. if ($v == null) {
  2273. $this->setAPIResponse('error', '[' . $k . '] cannot be empty', 422);
  2274. return false;
  2275. }
  2276. }
  2277. $path = $this->cleanDirectory($path);
  2278. if (file_exists($path)) {
  2279. if (!is_writable($path)) {
  2280. $this->setAPIResponse('error', '[' . $path . '] is not writable', 422);
  2281. return false;
  2282. }
  2283. } else {
  2284. if (is_writable(dirname($path, 1))) {
  2285. if (!mkdir($path, 0760, true)) {
  2286. $this->setAPIResponse('error', '[' . $path . '] is not writable', 422);
  2287. return false;
  2288. }
  2289. } else {
  2290. $this->setAPIResponse('error', '[' . $path . '] is not writable', 422);
  2291. return false;
  2292. }
  2293. }
  2294. $dbName = $this->dbExtension($dbName);
  2295. $configVersion = $this->version;
  2296. $configArray = array(
  2297. 'dbName' => $dbName,
  2298. 'dbLocation' => $path,
  2299. 'license' => $license,
  2300. 'organizrHash' => $hashKey,
  2301. 'organizrAPI' => $api,
  2302. 'registrationPassword' => $registrationPassword,
  2303. 'uuid' => $this->gen_uuid()
  2304. );
  2305. // Create Config
  2306. if ($this->createConfig($configArray)) {
  2307. $this->config = $this->config();
  2308. $this->refreshCookieName();
  2309. $this->connectDB();
  2310. // Call DB Create
  2311. if ($this->createDB($path)) {
  2312. // Add in first user
  2313. if ($this->createFirstAdmin($username, $password, $email)) {
  2314. if ($this->createToken($username, $email, 1)) {
  2315. return true;
  2316. } else {
  2317. $this->setAPIResponse('error', 'error creating token', 500);
  2318. }
  2319. } else {
  2320. $this->setAPIResponse('error', 'error creating admin', 500);
  2321. }
  2322. } else {
  2323. $this->setAPIResponse('error', 'error creating database', 500);
  2324. }
  2325. } else {
  2326. $this->setAPIResponse('error', 'error creating config', 500);
  2327. }
  2328. return false;
  2329. }
  2330. public function createDB($path, $migration = false)
  2331. {
  2332. if (!file_exists($path)) {
  2333. mkdir($path, 0777, true);
  2334. }
  2335. $response = [
  2336. array(
  2337. 'function' => 'query',
  2338. 'query' => 'CREATE TABLE `users` (
  2339. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2340. `username` TEXT UNIQUE,
  2341. `password` TEXT,
  2342. `email` TEXT,
  2343. `plex_token` TEXT,
  2344. `group` TEXT,
  2345. `group_id` INTEGER,
  2346. `locked` INTEGER,
  2347. `image` TEXT,
  2348. `register_date` DATE,
  2349. `auth_service` TEXT DEFAULT \'internal\'
  2350. );'
  2351. ),
  2352. array(
  2353. 'function' => 'query',
  2354. 'query' => 'CREATE TABLE `chatroom` (
  2355. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2356. `username` TEXT,
  2357. `gravatar` TEXT,
  2358. `uid` TEXT,
  2359. `date` DATE,
  2360. `ip` TEXT,
  2361. `message` TEXT
  2362. );'
  2363. ),
  2364. array(
  2365. 'function' => 'query',
  2366. 'query' => 'CREATE TABLE `tokens` (
  2367. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2368. `token` TEXT UNIQUE,
  2369. `user_id` INTEGER,
  2370. `browser` TEXT,
  2371. `ip` TEXT,
  2372. `created` DATE,
  2373. `expires` DATE
  2374. );'
  2375. ),
  2376. array(
  2377. 'function' => 'query',
  2378. 'query' => 'CREATE TABLE `groups` (
  2379. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2380. `group` TEXT UNIQUE,
  2381. `group_id` INTEGER,
  2382. `image` TEXT,
  2383. `default` INTEGER
  2384. );'
  2385. ),
  2386. array(
  2387. 'function' => 'query',
  2388. 'query' => 'CREATE TABLE `categories` (
  2389. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2390. `order` INTEGER,
  2391. `category` TEXT UNIQUE,
  2392. `category_id` INTEGER,
  2393. `image` TEXT,
  2394. `default` INTEGER
  2395. );'
  2396. ),
  2397. array(
  2398. 'function' => 'query',
  2399. 'query' => 'CREATE TABLE `tabs` (
  2400. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2401. `order` INTEGER,
  2402. `category_id` INTEGER,
  2403. `name` TEXT,
  2404. `url` TEXT,
  2405. `url_local` TEXT,
  2406. `default` INTEGER,
  2407. `enabled` INTEGER,
  2408. `group_id` INTEGER,
  2409. `image` TEXT,
  2410. `type` INTEGER,
  2411. `splash` INTEGER,
  2412. `ping` INTEGER,
  2413. `ping_url` TEXT,
  2414. `timeout` INTEGER,
  2415. `timeout_ms` INTEGER,
  2416. `preload` INTEGER
  2417. );'
  2418. ),
  2419. array(
  2420. 'function' => 'query',
  2421. 'query' => 'CREATE TABLE `options` (
  2422. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2423. `name` TEXT UNIQUE,
  2424. `value` TEXT
  2425. );'
  2426. ),
  2427. array(
  2428. 'function' => 'query',
  2429. 'query' => 'CREATE TABLE `invites` (
  2430. `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
  2431. `code` TEXT UNIQUE,
  2432. `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  2433. `email` TEXT,
  2434. `username` TEXT,
  2435. `dateused` TIMESTAMP,
  2436. `usedby` TEXT,
  2437. `ip` TEXT,
  2438. `valid` TEXT,
  2439. `type` TEXT
  2440. );'
  2441. ),
  2442. ];
  2443. return $this->processQueries($response, $migration);
  2444. }
  2445. public function createFirstAdmin($username, $password, $email)
  2446. {
  2447. $userInfo = [
  2448. 'username' => $username,
  2449. 'password' => password_hash($password, PASSWORD_BCRYPT),
  2450. 'email' => $email,
  2451. 'group' => 'Admin',
  2452. 'group_id' => 0,
  2453. 'image' => $this->gravatar($email),
  2454. 'register_date' => $this->currentTime,
  2455. ];
  2456. $groupInfo0 = [
  2457. 'group' => 'Admin',
  2458. 'group_id' => 0,
  2459. 'default' => false,
  2460. 'image' => 'plugins/images/groups/admin.png',
  2461. ];
  2462. $groupInfo1 = [
  2463. 'group' => 'Co-Admin',
  2464. 'group_id' => 1,
  2465. 'default' => false,
  2466. 'image' => 'plugins/images/groups/coadmin.png',
  2467. ];
  2468. $groupInfo2 = [
  2469. 'group' => 'Super User',
  2470. 'group_id' => 2,
  2471. 'default' => false,
  2472. 'image' => 'plugins/images/groups/superuser.png',
  2473. ];
  2474. $groupInfo3 = [
  2475. 'group' => 'Power User',
  2476. 'group_id' => 3,
  2477. 'default' => false,
  2478. 'image' => 'plugins/images/groups/poweruser.png',
  2479. ];
  2480. $groupInfo4 = [
  2481. 'group' => 'User',
  2482. 'group_id' => 4,
  2483. 'default' => true,
  2484. 'image' => 'plugins/images/groups/user.png',
  2485. ];
  2486. $groupInfoGuest = [
  2487. 'group' => 'Guest',
  2488. 'group_id' => 999,
  2489. 'default' => false,
  2490. 'image' => 'plugins/images/groups/guest.png',
  2491. ];
  2492. $settingsInfo = [
  2493. 'order' => 1,
  2494. 'category_id' => 0,
  2495. 'name' => 'Settings',
  2496. 'url' => 'api/v2/page/settings',
  2497. 'default' => false,
  2498. 'enabled' => true,
  2499. 'group_id' => 1,
  2500. 'image' => 'fontawesome::cog',
  2501. 'type' => 0
  2502. ];
  2503. $homepageInfo = [
  2504. 'order' => 2,
  2505. 'category_id' => 0,
  2506. 'name' => 'Homepage',
  2507. 'url' => 'api/v2/page/homepage',
  2508. 'default' => false,
  2509. 'enabled' => false,
  2510. 'group_id' => 4,
  2511. 'image' => 'fontawesome::home',
  2512. 'type' => 0
  2513. ];
  2514. $unsortedInfo = [
  2515. 'order' => 1,
  2516. 'category' => 'Unsorted',
  2517. 'category_id' => 0,
  2518. 'image' => 'plugins/images/categories/unsorted.png',
  2519. 'default' => true
  2520. ];
  2521. $response = [
  2522. array(
  2523. 'function' => 'query',
  2524. 'query' => array(
  2525. 'INSERT INTO [users]',
  2526. $userInfo
  2527. )
  2528. ),
  2529. array(
  2530. 'function' => 'query',
  2531. 'query' => array(
  2532. 'INSERT INTO [groups]',
  2533. $groupInfo0
  2534. )
  2535. ),
  2536. array(
  2537. 'function' => 'query',
  2538. 'query' => array(
  2539. 'INSERT INTO [groups]',
  2540. $groupInfo1
  2541. )
  2542. ),
  2543. array(
  2544. 'function' => 'query',
  2545. 'query' => array(
  2546. 'INSERT INTO [groups]',
  2547. $groupInfo2
  2548. )
  2549. ),
  2550. array(
  2551. 'function' => 'query',
  2552. 'query' => array(
  2553. 'INSERT INTO [groups]',
  2554. $groupInfo3
  2555. )
  2556. ),
  2557. array(
  2558. 'function' => 'query',
  2559. 'query' => array(
  2560. 'INSERT INTO [groups]',
  2561. $groupInfo4
  2562. )
  2563. ),
  2564. array(
  2565. 'function' => 'query',
  2566. 'query' => array(
  2567. 'INSERT INTO [groups]',
  2568. $groupInfoGuest
  2569. )
  2570. ),
  2571. array(
  2572. 'function' => 'query',
  2573. 'query' => array(
  2574. 'INSERT INTO [tabs]',
  2575. $settingsInfo
  2576. )
  2577. ),
  2578. array(
  2579. 'function' => 'query',
  2580. 'query' => array(
  2581. 'INSERT INTO [tabs]',
  2582. $homepageInfo
  2583. )
  2584. ),
  2585. array(
  2586. 'function' => 'query',
  2587. 'query' => array(
  2588. 'INSERT INTO [categories]',
  2589. $unsortedInfo
  2590. )
  2591. ),
  2592. ];
  2593. return $this->processQueries($response);
  2594. }
  2595. public function getUserByUsernameAndEmail($username, $email)
  2596. {
  2597. $response = [
  2598. array(
  2599. 'function' => 'fetch',
  2600. 'query' => array(
  2601. 'SELECT * FROM users WHERE username = ? COLLATE NOCASE OR email = ? COLLATE NOCASE',
  2602. [$username],
  2603. [$email]
  2604. )
  2605. ),
  2606. ];
  2607. return $this->processQueries($response);
  2608. }
  2609. public function createToken($username, $email, $days = 1)
  2610. {
  2611. $days = ($days > 365) ? 365 : $days;
  2612. //Quick get user ID
  2613. $result = $this->getUserByUsernameAndEmail($username, $email);
  2614. // Create JWT
  2615. // Set key
  2616. // SHA256 Encryption
  2617. $signer = new Lcobucci\JWT\Signer\Hmac\Sha256();
  2618. // Start Builder
  2619. $jwttoken = (new Lcobucci\JWT\Builder())->issuedBy('Organizr')// Configures the issuer (iss claim)
  2620. ->permittedFor('Organizr')// Configures the audience (aud claim)
  2621. ->identifiedBy('4f1g23a12aa', true)// Configures the id (jti claim), replicating as a header item
  2622. ->issuedAt(time())// Configures the time that the token was issue (iat claim)
  2623. ->expiresAt(time() + (86400 * $days))// Configures the expiration time of the token (exp claim)
  2624. ->withClaim('username', $result['username'])// Configures a new claim, called "username"
  2625. ->withClaim('group', $result['group'])// Configures a new claim, called "group"
  2626. ->withClaim('groupID', $result['group_id'])// Configures a new claim, called "groupID"
  2627. ->withClaim('email', $result['email'])// Configures a new claim, called "email"
  2628. ->withClaim('image', $result['image'])// Configures a new claim, called "image"
  2629. ->withClaim('userID', $result['id'])// Configures a new claim, called "image"
  2630. ->sign($signer, $this->config['organizrHash'])// creates a signature using "testing" as key
  2631. ->getToken(); // Retrieves the generated token
  2632. $jwttoken->getHeaders(); // Retrieves the token headers
  2633. $jwttoken->getClaims(); // Retrieves the token claims
  2634. $this->coookie('set', $this->cookieName, $jwttoken, $days);
  2635. // Add token to DB
  2636. $addToken = [
  2637. 'token' => (string)$jwttoken,
  2638. 'user_id' => $result['id'],
  2639. 'created' => $this->currentTime,
  2640. 'browser' => isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : null,
  2641. 'ip' => $this->userIP(),
  2642. 'expires' => gmdate("Y-m-d\TH:i:s\Z", time() + (86400 * $days))
  2643. ];
  2644. $response = [
  2645. array(
  2646. 'function' => 'query',
  2647. 'query' => array(
  2648. 'INSERT INTO [tokens]',
  2649. $addToken
  2650. )
  2651. ),
  2652. ];
  2653. $token = $this->processQueries($response);
  2654. return $jwttoken;
  2655. }
  2656. public function login($array)
  2657. {
  2658. // Grab username, Password & other optional items from api call
  2659. $username = $array['username'] ?? null;
  2660. $password = $array['password'] ?? null;
  2661. $oAuth = $array['oAuth'] ?? null;
  2662. $oAuthType = $array['oAuthType'] ?? null;
  2663. $remember = $array['remember'] ?? null;
  2664. $tfaCode = $array['tfaCode'] ?? null;
  2665. $loginAttempts = $array['loginAttempts'] ?? null;
  2666. $output = $array['output'] ?? null;
  2667. $username = (strpos($this->config['authBackend'], 'emby') !== false) ? $username : strtolower($username);
  2668. $days = (isset($remember)) ? $this->config['rememberMeDays'] : 1;
  2669. // Set other variables
  2670. $function = 'plugin_auth_' . $this->config['authBackend'];
  2671. $authSuccess = false;
  2672. $authProxy = false;
  2673. // Check Login attempts and kill if over limit
  2674. if ($loginAttempts > $this->config['loginAttempts'] || isset($_COOKIE['lockout'])) {
  2675. $this->coookieSeconds('set', 'lockout', $this->config['loginLockout'], $this->config['loginLockout']);
  2676. $this->setAPIResponse('error', 'User is locked out', 403);
  2677. return false;
  2678. }
  2679. // Check if Auth Proxy is enabled
  2680. if ($this->config['authProxyEnabled'] && $this->config['authProxyHeaderName'] !== '' && $this->config['authProxyWhitelist'] !== '') {
  2681. if (isset($this->getallheaders()[$this->config['authProxyHeaderName']])) {
  2682. $usernameHeader = isset($this->getallheaders()[$this->config['authProxyHeaderName']]) ? $this->getallheaders()[$this->config['authProxyHeaderName']] : $username;
  2683. $this->writeLog('success', 'Auth Proxy Function - Starting Verification for IP: ' . $this->userIP() . ' for request on: ' . $_SERVER['REMOTE_ADDR'] . ' against IP/Subnet: ' . $this->config['authProxyWhitelist'], $usernameHeader);
  2684. $whitelistRange = $this->analyzeIP($this->config['authProxyWhitelist']);
  2685. $authProxy = $this->authProxyRangeCheck($whitelistRange['from'], $whitelistRange['to']);
  2686. $username = ($authProxy) ? $usernameHeader : $username;
  2687. if ($authProxy) {
  2688. $this->writeLog('success', 'Auth Proxy Function - IP: ' . $this->userIP() . ' has been verified', $usernameHeader);
  2689. } else {
  2690. $this->writeLog('error', 'Auth Proxy Function - IP: ' . $this->userIP() . ' has failed verification', $usernameHeader);
  2691. }
  2692. }
  2693. }
  2694. // Check if Login method was an oAuth login
  2695. if (!$oAuth) {
  2696. $result = $this->getUserByUsernameAndEmail($username, $username);
  2697. $result['password'] = $result['password'] ?? '';
  2698. // Switch AuthType - internal - external - both
  2699. switch ($this->config['authType']) {
  2700. case 'external':
  2701. if (method_exists($this, $function)) {
  2702. $authSuccess = $this->$function($username, $password);
  2703. }
  2704. break;
  2705. /** @noinspection PhpMissingBreakStatementInspection */
  2706. case 'both':
  2707. if (method_exists($this, $function)) {
  2708. $authSuccess = $this->$function($username, $password);
  2709. }
  2710. // no break
  2711. default: // Internal
  2712. if (!$authSuccess) {
  2713. // perform the internal authentication step
  2714. if (password_verify($password, $result['password'])) {
  2715. $authSuccess = true;
  2716. }
  2717. }
  2718. }
  2719. $authSuccess = ($authProxy) ? true : $authSuccess;
  2720. } else {
  2721. // Has oAuth Token!
  2722. switch ($oAuthType) {
  2723. case 'plex':
  2724. if ($this->config['plexoAuth']) {
  2725. $tokenInfo = $this->checkPlexToken($oAuth);
  2726. if ($tokenInfo) {
  2727. $authSuccess = array(
  2728. 'username' => $tokenInfo['user']['username'],
  2729. 'email' => $tokenInfo['user']['email'],
  2730. 'image' => $tokenInfo['user']['thumb'],
  2731. 'token' => $tokenInfo['user']['authToken']
  2732. );
  2733. $this->coookie('set', 'oAuth', 'true', $this->config['rememberMeDays']);
  2734. $authSuccess = ((!empty($this->config['plexAdmin']) && strtolower($this->config['plexAdmin']) == strtolower($tokenInfo['user']['username'])) || (!empty($this->config['plexAdmin']) && strtolower($this->config['plexAdmin']) == strtolower($tokenInfo['user']['email'])) || $this->checkPlexUser($tokenInfo['user']['username'])) ? $authSuccess : false;
  2735. }
  2736. } else {
  2737. $this->setAPIResponse('error', 'Plex oAuth is not setup', 422);
  2738. return false;
  2739. }
  2740. break;
  2741. default:
  2742. return ($output) ? 'No oAuthType defined' : 'error';
  2743. }
  2744. $result = ($authSuccess) ? $this->getUserByUsernameAndEmail($authSuccess['username'], $authSuccess['email']) : '';
  2745. }
  2746. if ($authSuccess) {
  2747. // Make sure user exists in database
  2748. $userExists = false;
  2749. $passwordMatches = $oAuth || $authProxy;
  2750. $token = (is_array($authSuccess) && isset($authSuccess['token']) ? $authSuccess['token'] : '');
  2751. if (isset($result['username'])) {
  2752. $userExists = true;
  2753. $username = $result['username'];
  2754. if ($passwordMatches == false) {
  2755. $passwordMatches = password_verify($password, $result['password']);
  2756. }
  2757. }
  2758. if ($userExists) {
  2759. //does org password need to be updated
  2760. if (!$passwordMatches) {
  2761. $this->updateUserPassword($password, $result['id']);
  2762. $this->writeLog('success', 'Login Function - User Password updated from backend', $username);
  2763. }
  2764. if ($token !== '') {
  2765. if ($token !== $result['plex_token']) {
  2766. $this->updateUserPlexToken($token, $result['id']);
  2767. $this->writeLog('success', 'Login Function - User Plex Token updated from backend', $username);
  2768. }
  2769. }
  2770. // 2FA might go here
  2771. if ($result['auth_service'] !== 'internal' && strpos($result['auth_service'], '::') !== false) {
  2772. $tfaProceed = true;
  2773. // Add check for local or not
  2774. if ($this->config['ignoreTFALocal'] !== false) {
  2775. $tfaProceed = ($this->isLocal()) ? false : true;
  2776. }
  2777. if ($tfaProceed) {
  2778. $TFA = explode('::', $result['auth_service']);
  2779. // Is code with login info?
  2780. if ($tfaCode == '') {
  2781. $this->setAPIResponse('warning', '2FA Code Needed', 422);
  2782. return false;
  2783. } else {
  2784. if (!$this->verify2FA($TFA[1], $tfaCode, $TFA[0])) {
  2785. $this->writeLoginLog($username, 'error');
  2786. $this->writeLog('error', 'Login Function - Wrong 2FA', $username);
  2787. $this->setAPIResponse('error', 'Wrong 2FA', 422);
  2788. return false;
  2789. }
  2790. }
  2791. }
  2792. }
  2793. // End 2FA
  2794. // authentication passed - 1) mark active and update token
  2795. $createToken = $this->createToken($result['username'], $result['email'], $days);
  2796. if ($createToken) {
  2797. $this->writeLoginLog($username, 'success');
  2798. $this->writeLog('success', 'Login Function - A User has logged in', $username);
  2799. $ssoUser = ((empty($result['email'])) ? $result['username'] : (strpos($result['email'], 'placeholder') !== false)) ? $result['username'] : $result['email'];
  2800. $this->ssoCheck($ssoUser, $password, $token); //need to work on this
  2801. return ($output) ? array('name' => $this->cookieName, 'token' => (string)$createToken) : true;
  2802. } else {
  2803. $this->setAPIResponse('error', 'Token creation error', 500);
  2804. return false;
  2805. }
  2806. } else {
  2807. // Create User
  2808. return $this->authRegister((is_array($authSuccess) && isset($authSuccess['username']) ? $authSuccess['username'] : $username), $password, (is_array($authSuccess) && isset($authSuccess['email']) ? $authSuccess['email'] : ''), $token);
  2809. }
  2810. } else {
  2811. // authentication failed
  2812. $this->writeLoginLog($username, 'error');
  2813. $this->writeLog('error', 'Login Function - Wrong Password', $username);
  2814. if ($loginAttempts >= $this->config['loginAttempts']) {
  2815. $this->coookieSeconds('set', 'lockout', $this->config['loginLockout'], $this->config['loginLockout']);
  2816. $this->setAPIResponse('error', 'User is locked out', 403);
  2817. return false;
  2818. } else {
  2819. $this->setAPIResponse('error', 'User credentials incorrect', 401);
  2820. return false;
  2821. }
  2822. }
  2823. }
  2824. public function logout()
  2825. {
  2826. $this->coookie('delete', $this->cookieName);
  2827. $this->coookie('delete', 'mpt');
  2828. $this->coookie('delete', 'Auth');
  2829. $this->coookie('delete', 'oAuth');
  2830. $this->clearTautulliTokens();
  2831. $this->revokeTokenCurrentUser($this->user['token']);
  2832. $this->user = null;
  2833. return true;
  2834. }
  2835. public function recover($array)
  2836. {
  2837. $email = $array['email'] ?? null;
  2838. if (!$email) {
  2839. $this->setAPIResponse('error', 'Email was not supplied', 422);
  2840. return false;
  2841. }
  2842. $newPassword = $this->randString(10);
  2843. $isUser = $this->getUserByEmail($email);
  2844. if ($isUser) {
  2845. $this->updateUserPassword($newPassword, $isUser['id']);
  2846. $this->setAPIResponse('success', 'User password has been reset', 200);
  2847. $this->writeLog('success', 'User Management Function - User: ' . $isUser['username'] . '\'s password was reset', $isUser['username']);
  2848. if ($this->config['PHPMAILER-enabled']) {
  2849. $PhpMailer = new PhpMailer();
  2850. $emailTemplate = array(
  2851. 'type' => 'reset',
  2852. 'body' => $this->config['PHPMAILER-emailTemplateReset'],
  2853. 'subject' => $this->config['PHPMAILER-emailTemplateResetSubject'],
  2854. 'user' => $isUser['username'],
  2855. 'password' => $newPassword,
  2856. 'inviteCode' => null,
  2857. );
  2858. $emailTemplate = $PhpMailer->_phpMailerPluginEmailTemplate($emailTemplate);
  2859. $sendEmail = array(
  2860. 'to' => $email,
  2861. 'user' => $isUser['username'],
  2862. 'subject' => $emailTemplate['subject'],
  2863. 'body' => $PhpMailer->_phpMailerPluginBuildEmail($emailTemplate),
  2864. );
  2865. $PhpMailer->_phpMailerPluginSendEmail($sendEmail);
  2866. $this->setAPIResponse('success', 'User password has been reset and email has been sent', 200);
  2867. }
  2868. return true;
  2869. } else {
  2870. $this->setAPIResponse('error', 'User not found', 404);
  2871. return false;
  2872. }
  2873. }
  2874. public function register($array)
  2875. {
  2876. $email = $array['email'] ?? null;
  2877. $username = $array['username'] ?? null;
  2878. $password = $array['password'] ?? null;
  2879. $registrationPassword = $array['registrationPassword'] ?? null;
  2880. if (!$email) {
  2881. $this->setAPIResponse('error', 'Email was not supplied', 422);
  2882. return false;
  2883. }
  2884. if (!$username) {
  2885. $this->setAPIResponse('error', 'Username was not supplied', 422);
  2886. return false;
  2887. }
  2888. if (!$password) {
  2889. $this->setAPIResponse('error', 'Password was not supplied', 422);
  2890. return false;
  2891. }
  2892. if (!$registrationPassword) {
  2893. $this->setAPIResponse('error', 'Registration Password was not supplied', 422);
  2894. return false;
  2895. }
  2896. if ($registrationPassword == $this->decrypt($this->config['registrationPassword'])) {
  2897. $this->writeLog('success', 'Registration Function - Registration Password Verified', $username);
  2898. if ($this->createUser($username, $password, $email)) {
  2899. $this->writeLog('success', 'Registration Function - A User has registered', $username);
  2900. if ($this->createToken($username, $email, $this->config['rememberMeDays'])) {
  2901. $this->writeLoginLog($username, 'success');
  2902. $this->writeLog('success', 'Login Function - A User has logged in', $username);
  2903. return true;
  2904. }
  2905. } else {
  2906. return false;
  2907. }
  2908. } else {
  2909. $this->writeLog('warning', 'Registration Function - Wrong Password', $username);
  2910. $this->setAPIResponse('error', 'Registration Password was incorrect', 401);
  2911. return false;
  2912. }
  2913. }
  2914. public function authRegister($username, $password, $email, $token = null)
  2915. {
  2916. if ($this->config['authBackend'] !== '') {
  2917. $this->ombiImport($this->config['authBackend']);
  2918. }
  2919. $this->ssoCheck($username, $password, $token);
  2920. if ($token && (!$password || $password == '')) {
  2921. $password = $this->random_ascii_string(10);
  2922. }
  2923. if ($this->createUser($username, $password, $email)) {
  2924. $this->writeLog('success', 'Registration Function - A User has registered', $username);
  2925. if ($this->config['PHPMAILER-enabled'] && $email !== '') {
  2926. $PhpMailer = new PhpMailer();
  2927. $emailTemplate = array(
  2928. 'type' => 'registration',
  2929. 'body' => $this->config['PHPMAILER-emailTemplateRegisterUser'],
  2930. 'subject' => $this->config['PHPMAILER-emailTemplateRegisterUserSubject'],
  2931. 'user' => $username,
  2932. 'password' => null,
  2933. 'inviteCode' => null,
  2934. );
  2935. $emailTemplate = $PhpMailer->_phpMailerPluginEmailTemplate($emailTemplate);
  2936. $sendEmail = array(
  2937. 'to' => $email,
  2938. 'user' => $username,
  2939. 'subject' => $emailTemplate['subject'],
  2940. 'body' => $PhpMailer->_phpMailerPluginBuildEmail($emailTemplate),
  2941. );
  2942. $PhpMailer->_phpMailerPluginSendEmail($sendEmail);
  2943. }
  2944. if ($this->createToken($username, $email, $this->gravatar($email), $this->config['rememberMeDays'])) {
  2945. $this->writeLoginLog($username, 'success');
  2946. $this->writeLog('success', 'Login Function - A User has logged in', $username);
  2947. return true;
  2948. } else {
  2949. return false;
  2950. }
  2951. } else {
  2952. $this->writeLog('error', 'Registration Function - An error occurred', $username);
  2953. return false;
  2954. }
  2955. }
  2956. public function revokeTokenCurrentUser($token)
  2957. {
  2958. $response = [
  2959. array(
  2960. 'function' => 'query',
  2961. 'query' => array(
  2962. 'DELETE FROM tokens WHERE user_id = ? or token = ?',
  2963. [$this->user['userID']],
  2964. [$token]
  2965. )
  2966. ),
  2967. ];
  2968. return $this->processQueries($response);
  2969. }
  2970. public function revokeToken($token = null)
  2971. {
  2972. if (!$token) {
  2973. $this->setAPIResponse('error', 'Token was not supplied', 422);
  2974. return false;
  2975. }
  2976. $response = [
  2977. array(
  2978. 'function' => 'query',
  2979. 'query' => array(
  2980. 'DELETE FROM tokens WHERE token = ?',
  2981. [$token]
  2982. )
  2983. ),
  2984. ];
  2985. $this->setAPIResponse('success', 'Token revoked', 204);
  2986. return $this->processQueries($response);
  2987. }
  2988. public function revokeTokenByIdCurrentUser($id = null)
  2989. {
  2990. if (!$id) {
  2991. $this->setAPIResponse('error', 'Id was not supplied', 422);
  2992. return false;
  2993. }
  2994. $response = [
  2995. array(
  2996. 'function' => 'query',
  2997. 'query' => array(
  2998. 'DELETE FROM tokens WHERE id = ? AND user_id = ?',
  2999. $id,
  3000. $this->user['userID']
  3001. )
  3002. ),
  3003. ];
  3004. $this->setAPIResponse('success', 'Token revoked', 204);
  3005. return $this->processQueries($response);
  3006. }
  3007. public function updateUserPassword($password, $id)
  3008. {
  3009. $response = [
  3010. array(
  3011. 'function' => 'query',
  3012. 'query' => array(
  3013. 'UPDATE users SET',
  3014. ['password' => password_hash($password, PASSWORD_BCRYPT)],
  3015. 'WHERE id = ?',
  3016. $id
  3017. )
  3018. ),
  3019. ];
  3020. return $this->processQueries($response);
  3021. }
  3022. public function updateUserPlexToken($token, $id)
  3023. {
  3024. $response = [
  3025. array(
  3026. 'function' => 'query',
  3027. 'query' => array(
  3028. 'UPDATE users SET',
  3029. ['plex_token' => $token],
  3030. 'WHERE id = ?',
  3031. $id
  3032. )
  3033. ),
  3034. ];
  3035. return $this->processQueries($response);
  3036. }
  3037. public function getUserTabsAndCategories($type = null)
  3038. {
  3039. if (!$this->hasDB()) {
  3040. return false;
  3041. }
  3042. $sort = ($this->config['unsortedTabs'] == 'top') ? 'DESC' : 'ASC';
  3043. $response = [
  3044. array(
  3045. 'function' => 'fetchAll',
  3046. 'query' => array(
  3047. 'SELECT * FROM tabs WHERE `group_id` >= ? AND `enabled` = 1 ORDER BY `order` ' . $sort,
  3048. $this->user['groupID']
  3049. ),
  3050. 'key' => 'tabs'
  3051. ),
  3052. array(
  3053. 'function' => 'fetchAll',
  3054. 'query' => array(
  3055. 'SELECT * FROM categories ORDER BY `order` ASC',
  3056. ),
  3057. 'key' => 'categories'
  3058. ),
  3059. ];
  3060. $queries = $this->processQueries($response);
  3061. $all['tabs'] = $queries['tabs'];
  3062. foreach ($queries['tabs'] as $k => $v) {
  3063. $v['access_url'] = (!empty($v['url_local']) && ($v['url_local'] !== null) && ($v['url_local'] !== 'null') && $this->isLocal() && $v['type'] !== 0) ? $v['url_local'] : $v['url'];
  3064. }
  3065. $count = array_map(function ($element) {
  3066. return $element['category_id'];
  3067. }, $queries['tabs']);
  3068. $count = (array_count_values($count));
  3069. foreach ($queries['categories'] as $k => $v) {
  3070. $v['count'] = isset($count[$v['category_id']]) ? $count[$v['category_id']] : 0;
  3071. }
  3072. $all['categories'] = $queries['categories'];
  3073. switch ($type) {
  3074. case 'categories':
  3075. return $all['categories'];
  3076. case 'tabs':
  3077. return $all['tabs'];
  3078. default:
  3079. return $all;
  3080. }
  3081. }
  3082. public function refreshList()
  3083. {
  3084. $searchTerm = "Refresh";
  3085. return array_filter($this->config, function ($k) use ($searchTerm) {
  3086. return stripos($k, $searchTerm) !== false;
  3087. }, ARRAY_FILTER_USE_KEY);
  3088. }
  3089. public function homepageOrderList()
  3090. {
  3091. $searchTerm = "homepageOrder";
  3092. $order = array_filter($this->config, function ($k) use ($searchTerm) {
  3093. return stripos($k, $searchTerm) !== false;
  3094. }, ARRAY_FILTER_USE_KEY);
  3095. asort($order);
  3096. return $order;
  3097. }
  3098. public function tautulliList()
  3099. {
  3100. $searchTerm = "tautulli_token";
  3101. return array_filter($this->config, function ($k) use ($searchTerm) {
  3102. return stripos($k, $searchTerm) !== false;
  3103. }, ARRAY_FILTER_USE_KEY);
  3104. }
  3105. public function checkPlexAdminFilled()
  3106. {
  3107. if ($this->config['plexAdmin'] == '') {
  3108. return false;
  3109. } else {
  3110. if ((strpos($this->config['plexAdmin'], '@') !== false)) {
  3111. return 'email';
  3112. } else {
  3113. return 'username';
  3114. }
  3115. }
  3116. }
  3117. public function organizrSpecialSettings()
  3118. {
  3119. return array(
  3120. 'homepage' => array(
  3121. 'refresh' => $this->refreshList(),
  3122. 'order' => $this->homepageOrderList(),
  3123. 'search' => array(
  3124. 'enabled' => $this->qualifyRequest($this->config['mediaSearchAuth']) && $this->config['mediaSearch'] == true && $this->config['plexToken'],
  3125. 'type' => $this->config['mediaSearchType'],
  3126. ),
  3127. 'ombi' => array(
  3128. 'enabled' => $this->qualifyRequest($this->config['homepageOmbiAuth']) && $this->qualifyRequest($this->config['homepageOmbiRequestAuth']) && $this->config['homepageOmbiEnabled'] == true && $this->config['ssoOmbi'] && isset($_COOKIE['Auth']),
  3129. 'authView' => $this->qualifyRequest($this->config['homepageOmbiAuth']),
  3130. 'authRequest' => $this->qualifyRequest($this->config['homepageOmbiRequestAuth']),
  3131. 'sso' => ($this->config['ssoOmbi']) ? true : false,
  3132. 'cookie' => isset($_COOKIE['Auth']),
  3133. 'alias' => ($this->config['ombiAlias']) ? true : false,
  3134. 'ombiDefaultFilterAvailable' => $this->config['ombiDefaultFilterAvailable'] ? true : false,
  3135. 'ombiDefaultFilterUnavailable' => $this->config['ombiDefaultFilterUnavailable'] ? true : false,
  3136. 'ombiDefaultFilterApproved' => $this->config['ombiDefaultFilterApproved'] ? true : false,
  3137. 'ombiDefaultFilterUnapproved' => $this->config['ombiDefaultFilterUnapproved'] ? true : false,
  3138. 'ombiDefaultFilterDenied' => $this->config['ombiDefaultFilterDenied'] ? true : false
  3139. ),
  3140. 'options' => array(
  3141. 'alternateHomepageHeaders' => $this->config['alternateHomepageHeaders'],
  3142. 'healthChecksTags' => $this->config['healthChecksTags'],
  3143. 'titles' => array(
  3144. 'tautulli' => $this->config['tautulliHeader']
  3145. )
  3146. ),
  3147. 'media' => array(
  3148. 'jellyfin' => $this->config['homepageJellyfinInstead']
  3149. )
  3150. ),
  3151. 'sso' => array(
  3152. 'misc' => array(
  3153. 'oAuthLogin' => isset($_COOKIE['oAuth']),
  3154. 'rememberMe' => $this->config['rememberMe'],
  3155. 'rememberMeDays' => $this->config['rememberMeDays']
  3156. ),
  3157. 'plex' => array(
  3158. 'enabled' => ($this->config['ssoPlex']) ? true : false,
  3159. 'cookie' => isset($_COOKIE['mpt']),
  3160. 'machineID' => strlen($this->config['plexID']) == 40,
  3161. 'token' => $this->config['plexToken'] !== '',
  3162. 'plexAdmin' => $this->checkPlexAdminFilled(),
  3163. 'strict' => ($this->config['plexStrictFriends']) ? true : false,
  3164. 'oAuthEnabled' => ($this->config['plexoAuth']) ? true : false,
  3165. 'backend' => $this->config['authBackend'] == 'plex',
  3166. ),
  3167. 'ombi' => array(
  3168. 'enabled' => ($this->config['ssoOmbi']) ? true : false,
  3169. 'cookie' => isset($_COOKIE['Auth']),
  3170. 'url' => ($this->config['ombiURL'] !== '') ? $this->config['ombiURL'] : false,
  3171. 'api' => $this->config['ombiToken'] !== '',
  3172. ),
  3173. 'tautulli' => array(
  3174. 'enabled' => ($this->config['ssoTautulli']) ? true : false,
  3175. 'cookie' => !empty($this->tautulliList()),
  3176. 'url' => ($this->config['tautulliURL'] !== '') ? $this->config['tautulliURL'] : false,
  3177. ),
  3178. ),
  3179. 'ping' => array(
  3180. 'onlineSound' => $this->config['pingOnlineSound'],
  3181. 'offlineSound' => $this->config['pingOfflineSound'],
  3182. 'statusSounds' => $this->config['statusSounds'],
  3183. 'auth' => $this->config['pingAuth'],
  3184. 'authMessage' => $this->config['pingAuthMessage'],
  3185. 'authMs' => $this->config['pingAuthMs'],
  3186. 'ms' => $this->config['pingMs'],
  3187. 'adminRefresh' => $this->config['adminPingRefresh'],
  3188. 'everyoneRefresh' => $this->config['otherPingRefresh'],
  3189. ),
  3190. 'notifications' => array(
  3191. 'backbone' => $this->config['notificationBackbone'],
  3192. 'position' => $this->config['notificationPosition']
  3193. ),
  3194. 'lockout' => array(
  3195. 'enabled' => $this->config['lockoutSystem'],
  3196. 'timer' => $this->config['lockoutTimeout'],
  3197. 'minGroup' => $this->config['lockoutMinAuth'],
  3198. 'maxGroup' => $this->config['lockoutMaxAuth']
  3199. ),
  3200. 'user' => array(
  3201. 'agent' => isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : null,
  3202. 'oAuthLogin' => isset($_COOKIE['oAuth']),
  3203. 'local' => $this->isLocal(),
  3204. 'ip' => $this->userIP()
  3205. ),
  3206. 'login' => array(
  3207. 'rememberMe' => $this->config['rememberMe'],
  3208. 'rememberMeDays' => $this->config['rememberMeDays'],
  3209. 'wanDomain' => $this->config['wanDomain'],
  3210. 'localAddress' => $this->config['localAddress'],
  3211. 'enableLocalAddressForward' => $this->config['enableLocalAddressForward'],
  3212. ),
  3213. 'misc' => array(
  3214. 'installedPlugins' => $this->qualifyRequest(1) ? $this->config['installedPlugins'] : '',
  3215. 'installedThemes' => $this->qualifyRequest(1) ? $this->config['installedThemes'] : '',
  3216. 'return' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false,
  3217. 'authDebug' => $this->config['authDebug'],
  3218. 'minimalLoginScreen' => $this->config['minimalLoginScreen'],
  3219. 'unsortedTabs' => $this->config['unsortedTabs'],
  3220. 'authType' => $this->config['authType'],
  3221. 'authBackend' => $this->config['authBackend'],
  3222. 'newMessageSound' => (isset($this->config['CHAT-newMessageSound-include'])) ? $this->config['CHAT-newMessageSound-include'] : '',
  3223. 'uuid' => ($this->config['uuid']) ?? null,
  3224. 'docker' => $this->qualifyRequest(1) ? $this->docker : '',
  3225. 'githubCommit' => $this->qualifyRequest(1) ? $this->commit : '',
  3226. 'schema' => $this->qualifyRequest(1) ? $this->getSchema() : '',
  3227. 'debugArea' => $this->qualifyRequest($this->config['debugAreaAuth']),
  3228. 'debugErrors' => $this->config['debugErrors'],
  3229. 'sandbox' => $this->config['sandbox'],
  3230. ),
  3231. 'menuLink' => array(
  3232. 'githubMenuLink' => $this->config['githubMenuLink'],
  3233. 'organizrSupportMenuLink' => $this->config['organizrSupportMenuLink'],
  3234. 'organizrDocsMenuLink' => $this->config['organizrDocsMenuLink'],
  3235. 'organizrSignoutMenuLink' => $this->config['organizrSignoutMenuLink']
  3236. )
  3237. );
  3238. }
  3239. public function getLog($log, $reverse = true)
  3240. {
  3241. switch ($log) {
  3242. case 'login':
  3243. case 'loginLog':
  3244. $file = $this->organizrLoginLog;
  3245. $parent = 'auth';
  3246. break;
  3247. case 'org':
  3248. case 'organizr':
  3249. case 'organizrLog':
  3250. $file = $this->organizrLog;
  3251. $parent = 'log_items';
  3252. break;
  3253. default:
  3254. $this->setAPIResponse('error', 'Log not defined', 404);
  3255. return null;
  3256. }
  3257. if (!file_exists($file)) {
  3258. $this->setAPIResponse('error', 'Log does not exist', 404);
  3259. return null;
  3260. }
  3261. $getLog = str_replace("\r\ndate", "date", file_get_contents($file));
  3262. $gotLog = json_decode($getLog, true);
  3263. return ($reverse) ? array_reverse($gotLog[$parent]) : $gotLog[$parent];
  3264. }
  3265. public function purgeLog($log)
  3266. {
  3267. switch ($log) {
  3268. case 'login':
  3269. case 'loginLog':
  3270. $file = $this->organizrLoginLog;
  3271. break;
  3272. case 'org':
  3273. case 'organizr':
  3274. case 'organizrLog':
  3275. case 'orgLog':
  3276. $file = $this->organizrLog;
  3277. break;
  3278. default:
  3279. $this->setAPIResponse('error', 'Log not defined', 404);
  3280. return null;
  3281. }
  3282. if (file_exists($file)) {
  3283. if (unlink($file)) {
  3284. $this->writeLog('success', 'Log Management Function - Log: ' . $log . ' has been purged/deleted', 'SYSTEM');
  3285. $this->setAPIResponse(null, 'Log purged');
  3286. return true;
  3287. } else {
  3288. $this->writeLog('error', 'Log Management Function - Log: ' . $log . ' - Error Occurred', 'SYSTEM');
  3289. $this->setAPIResponse('error', 'Log could not be purged', 500);
  3290. return false;
  3291. }
  3292. } else {
  3293. $this->setAPIResponse('error', 'Log does not exist', 404);
  3294. return false;
  3295. }
  3296. }
  3297. public function checkLog($path)
  3298. {
  3299. if (file_exists($path)) {
  3300. if (filesize($path) > 500000) {
  3301. rename($path, $path . '[' . date('Y-m-d') . '].json');
  3302. return false;
  3303. }
  3304. return true;
  3305. } else {
  3306. return false;
  3307. }
  3308. }
  3309. public function writeLoginLog($username, $authType)
  3310. {
  3311. $username = htmlspecialchars($username, ENT_QUOTES);
  3312. if ($this->checkLog($this->organizrLoginLog)) {
  3313. $getLog = str_replace("\r\ndate", "date", file_get_contents($this->organizrLoginLog));
  3314. $gotLog = json_decode($getLog, true);
  3315. }
  3316. $logEntryFirst = array('logType' => 'login_log', 'auth' => array(array('date' => date("Y-m-d H:i:s"), 'utc_date' => $this->currentTime, 'username' => $username, 'ip' => $this->userIP(), 'auth_type' => $authType)));
  3317. $logEntry = array('date' => date("Y-m-d H:i:s"), 'utc_date' => $this->currentTime, 'username' => $username, 'ip' => $this->userIP(), 'auth_type' => $authType);
  3318. if (isset($gotLog)) {
  3319. array_push($gotLog["auth"], $logEntry);
  3320. $writeFailLog = str_replace("date", "\r\ndate", json_encode($gotLog));
  3321. } else {
  3322. $writeFailLog = str_replace("date", "\r\ndate", json_encode($logEntryFirst));
  3323. }
  3324. file_put_contents($this->organizrLoginLog, $writeFailLog);
  3325. }
  3326. public function writeLog($type = 'error', $message, $username = null)
  3327. {
  3328. $this->timeExecution = $this->timeExecution($this->timeExecution);
  3329. $message = $message . ' [Execution Time: ' . $this->formatSeconds($this->timeExecution) . ']';
  3330. $username = ($username) ? htmlspecialchars($username, ENT_QUOTES) : $this->user['username'];
  3331. if ($this->checkLog($this->organizrLog)) {
  3332. $getLog = str_replace("\r\ndate", "date", file_get_contents($this->organizrLog));
  3333. $gotLog = json_decode($getLog, true);
  3334. }
  3335. $logEntryFirst = array('logType' => 'organizr_log', 'log_items' => array(array('date' => date("Y-m-d H:i:s"), 'utc_date' => $this->currentTime, 'type' => $type, 'username' => $username, 'ip' => $this->userIP(), 'message' => $message)));
  3336. $logEntry = array('date' => date("Y-m-d H:i:s"), 'utc_date' => $this->currentTime, 'type' => $type, 'username' => $username, 'ip' => $this->userIP(), 'message' => $message);
  3337. if (isset($gotLog)) {
  3338. array_push($gotLog["log_items"], $logEntry);
  3339. $writeFailLog = str_replace("date", "\r\ndate", json_encode($gotLog));
  3340. } else {
  3341. $writeFailLog = str_replace("date", "\r\ndate", json_encode($logEntryFirst));
  3342. }
  3343. file_put_contents($this->organizrLog, $writeFailLog);
  3344. }
  3345. public function isApprovedRequest($method, $data)
  3346. {
  3347. $requesterToken = isset($this->getallheaders()['Token']) ? $this->getallheaders()['Token'] : (isset($_GET['apikey']) ? $_GET['apikey'] : false);
  3348. $apiKey = ($this->config['organizrAPI']) ?? null;
  3349. if (isset($data['formKey'])) {
  3350. $formKey = $data['formKey'];
  3351. } elseif (isset($this->getallheaders()['Formkey'])) {
  3352. $formKey = $this->getallheaders()['Formkey'];
  3353. } elseif (isset($this->getallheaders()['formkey'])) {
  3354. $formKey = $this->getallheaders()['formkey'];
  3355. } elseif (isset($this->getallheaders()['formKey'])) {
  3356. $formKey = $this->getallheaders()['formKey'];
  3357. } elseif (isset($this->getallheaders()['FormKey'])) {
  3358. $formKey = $this->getallheaders()['FormKey'];
  3359. } else {
  3360. $formKey = false;
  3361. }
  3362. // Check token or API key
  3363. // If API key, return 0 for admin
  3364. if (strlen($requesterToken) == 20 && $requesterToken == $apiKey) {
  3365. //DO API CHECK
  3366. return true;
  3367. } elseif ($method == 'POST') {
  3368. if ($this->checkFormKey($formKey)) {
  3369. return true;
  3370. } else {
  3371. $this->writeLog('error', 'API ERROR: Unable to authenticate Form Key: ' . $formKey, $this->user['username']);
  3372. return false;
  3373. }
  3374. } else {
  3375. return true;
  3376. }
  3377. return false;
  3378. }
  3379. public function checkFormKey($formKey = '')
  3380. {
  3381. return password_verify(substr($this->config['organizrHash'], 2, 10), $formKey);
  3382. }
  3383. public function buildHomepage()
  3384. {
  3385. $homepageOrder = $this->homepageOrderList();
  3386. $homepageBuilt = '';
  3387. foreach ($homepageOrder as $key => $value) {
  3388. $homepageBuilt .= $this->buildHomepageItem($key);
  3389. }
  3390. return $homepageBuilt;
  3391. }
  3392. public function buildHomepageItem($homepageItem)
  3393. {
  3394. $item = '<div id="' . $homepageItem . '">';
  3395. switch ($homepageItem) {
  3396. case 'homepageOrdercustomhtml':
  3397. if ($this->config['homepageCustomHTMLoneEnabled'] && $this->qualifyRequest($this->config['homepageCustomHTMLoneAuth'])) {
  3398. $item .= ($this->config['customHTMLone'] !== '') ? $this->config['customHTMLone'] : '';
  3399. }
  3400. break;
  3401. case 'homepageOrdercustomhtmlTwo':
  3402. if ($this->config['homepageCustomHTMLtwoEnabled'] && $this->qualifyRequest($this->config['homepageCustomHTMLtwoAuth'])) {
  3403. $item .= ($this->config['customHTMLtwo'] !== '') ? $this->config['customHTMLtwo'] : '';
  3404. }
  3405. break;
  3406. case 'homepageOrdernotice':
  3407. break;
  3408. case 'homepageOrdernoticeguest':
  3409. break;
  3410. case 'homepageOrderqBittorrent':
  3411. if ($this->config['homepageqBittorrentEnabled'] && $this->qualifyRequest($this->config['homepageqBittorrentAuth'])) {
  3412. if ($this->config['qBittorrentCombine']) {
  3413. $item .= '
  3414. <script>
  3415. // homepageOrderqBittorrent
  3416. buildDownloaderCombined(\'qBittorrent\');
  3417. homepageDownloader("qBittorrent", "' . $this->config['homepageDownloadRefresh'] . '");
  3418. // End homepageOrderqBittorrent
  3419. </script>
  3420. ';
  3421. } else {
  3422. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3423. $item .= '
  3424. <script>
  3425. // homepageOrderqBittorrent
  3426. $("#' . $homepageItem . '").html(buildDownloader("qBittorrent"));
  3427. homepageDownloader("qBittorrent", "' . $this->config['homepageDownloadRefresh'] . '");
  3428. // End homepageOrderqBittorrent
  3429. </script>
  3430. ';
  3431. }
  3432. }
  3433. break;
  3434. case 'homepageOrderrTorrent':
  3435. if ($this->config['homepagerTorrentEnabled'] && $this->qualifyRequest($this->config['homepagerTorrentAuth'])) {
  3436. if ($this->config['rTorrentCombine']) {
  3437. $item .= '
  3438. <script>
  3439. // homepageOrderrTorrent
  3440. buildDownloaderCombined(\'rTorrent\');
  3441. homepageDownloader("rTorrent", "' . $this->config['homepageDownloadRefresh'] . '");
  3442. // End homepageOrderrTorrent
  3443. </script>
  3444. ';
  3445. } else {
  3446. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3447. $item .= '
  3448. <script>
  3449. // homepageOrderrTorrent
  3450. $("#' . $homepageItem . '").html(buildDownloader("rTorrent"));
  3451. homepageDownloader("rTorrent", "' . $this->config['homepageDownloadRefresh'] . '");
  3452. // End homepageOrderrTorrent
  3453. </script>
  3454. ';
  3455. }
  3456. }
  3457. break;
  3458. case 'homepageOrderdeluge':
  3459. if ($this->config['homepageDelugeEnabled'] && $this->qualifyRequest($this->config['homepageDelugeAuth'])) {
  3460. if ($this->config['delugeCombine']) {
  3461. $item .= '
  3462. <script>
  3463. // Deluge
  3464. buildDownloaderCombined(\'deluge\');
  3465. homepageDownloader("deluge", "' . $this->config['homepageDownloadRefresh'] . '");
  3466. // End Deluge
  3467. </script>
  3468. ';
  3469. } else {
  3470. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3471. $item .= '
  3472. <script>
  3473. // Deluge
  3474. $("#' . $homepageItem . '").html(buildDownloader("deluge"));
  3475. homepageDownloader("deluge", "' . $this->config['homepageDownloadRefresh'] . '");
  3476. // End Deluge
  3477. </script>
  3478. ';
  3479. }
  3480. }
  3481. break;
  3482. case 'homepageOrdertransmission':
  3483. if ($this->config['homepageTransmissionEnabled'] && $this->qualifyRequest($this->config['homepageTransmissionAuth'])) {
  3484. if ($this->config['transmissionCombine']) {
  3485. $item .= '
  3486. <script>
  3487. // Transmission
  3488. buildDownloaderCombined(\'transmission\');
  3489. homepageDownloader("transmission", "' . $this->config['homepageDownloadRefresh'] . '");
  3490. // End Transmission
  3491. </script>
  3492. ';
  3493. } else {
  3494. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3495. $item .= '
  3496. <script>
  3497. // Transmission
  3498. $("#' . $homepageItem . '").html(buildDownloader("transmission"));
  3499. homepageDownloader("transmission", "' . $this->config['homepageDownloadRefresh'] . '");
  3500. // End Transmission
  3501. </script>
  3502. ';
  3503. }
  3504. }
  3505. break;
  3506. case 'homepageOrdernzbget':
  3507. if ($this->config['homepageNzbgetEnabled'] && $this->qualifyRequest($this->config['homepageNzbgetAuth'])) {
  3508. if ($this->config['nzbgetCombine']) {
  3509. $item .= '
  3510. <script>
  3511. // NZBGet
  3512. buildDownloaderCombined(\'nzbget\');
  3513. homepageDownloader("nzbget", "' . $this->config['homepageDownloadRefresh'] . '");
  3514. // End NZBGet
  3515. </script>
  3516. ';
  3517. } else {
  3518. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3519. $item .= '
  3520. <script>
  3521. // NZBGet
  3522. $("#' . $homepageItem . '").html(buildDownloader("nzbget"));
  3523. homepageDownloader("nzbget", "' . $this->config['homepageDownloadRefresh'] . '");
  3524. // End NZBGet
  3525. </script>
  3526. ';
  3527. }
  3528. }
  3529. break;
  3530. case 'homepageOrderjdownloader':
  3531. if ($this->config['homepageJdownloaderEnabled'] && $this->qualifyRequest($this->config['homepageJdownloaderAuth'])) {
  3532. if ($this->config['jdownloaderCombine']) {
  3533. $item .= '
  3534. <script>
  3535. // JDownloader
  3536. buildDownloaderCombined(\'jdownloader\');
  3537. homepageDownloader("jdownloader", "' . $this->config['homepageDownloadRefresh'] . '");
  3538. // End JDownloader
  3539. </script>
  3540. ';
  3541. } else {
  3542. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3543. $item .= '
  3544. <script>
  3545. // JDownloader
  3546. $("#' . $homepageItem . '").html(buildDownloader("jdownloader"));
  3547. homepageDownloader("jdownloader", "' . $this->config['homepageDownloadRefresh'] . '");
  3548. // End JDownloader
  3549. </script>
  3550. ';
  3551. }
  3552. }
  3553. break;
  3554. case 'homepageOrdersabnzbd':
  3555. if ($this->config['homepageSabnzbdEnabled'] && $this->qualifyRequest($this->config['homepageSabnzbdAuth'])) {
  3556. if ($this->config['sabnzbdCombine']) {
  3557. $item .= '
  3558. <script>
  3559. // SabNZBd
  3560. buildDownloaderCombined(\'sabnzbd\');
  3561. homepageDownloader("sabnzbd", "' . $this->config['homepageDownloadRefresh'] . '");
  3562. // End SabNZBd
  3563. </script>
  3564. ';
  3565. } else {
  3566. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3567. $item .= '
  3568. <script>
  3569. // SabNZBd
  3570. $("#' . $homepageItem . '").html(buildDownloader("sabnzbd"));
  3571. homepageDownloader("sabnzbd", "' . $this->config['homepageDownloadRefresh'] . '");
  3572. // End SabNZBd
  3573. </script>
  3574. ';
  3575. }
  3576. }
  3577. break;
  3578. case 'homepageOrderplexnowplaying':
  3579. if ($this->config['homepagePlexStreams']) {
  3580. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Now Playing...</h2></div>';
  3581. $item .= '
  3582. <script>
  3583. // Plex Stream
  3584. homepageStream("plex", "' . $this->config['homepageStreamRefresh'] . '");
  3585. // End Plex Stream
  3586. </script>
  3587. ';
  3588. }
  3589. break;
  3590. case 'homepageOrderplexrecent':
  3591. if ($this->config['homepagePlexRecent']) {
  3592. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Recent...</h2></div>';
  3593. $item .= '
  3594. <script>
  3595. // Plex Recent
  3596. homepageRecent("plex", "' . $this->config['homepageRecentRefresh'] . '");
  3597. // End Plex Recent
  3598. </script>
  3599. ';
  3600. }
  3601. break;
  3602. case 'homepageOrderplexplaylist':
  3603. if ($this->config['homepagePlexPlaylist']) {
  3604. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Playlists...</h2></div>';
  3605. $item .= '
  3606. <script>
  3607. // Plex Playlist
  3608. homepagePlaylist("plex");
  3609. // End Plex Playlist
  3610. </script>
  3611. ';
  3612. }
  3613. break;
  3614. case 'homepageOrderembynowplaying':
  3615. if ($this->config['homepageEmbyStreams'] && $this->config['homepageEmbyEnabled']) {
  3616. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Now Playing...</h2></div>';
  3617. $item .= '
  3618. <script>
  3619. // Emby Stream
  3620. homepageStream("emby", "' . $this->config['homepageStreamRefresh'] . '");
  3621. // End Emby Stream
  3622. </script>
  3623. ';
  3624. }
  3625. break;
  3626. case 'homepageOrderembyrecent':
  3627. if ($this->config['homepageEmbyRecent'] && $this->config['homepageEmbyEnabled']) {
  3628. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Recent...</h2></div>';
  3629. $item .= '
  3630. <script>
  3631. // Emby Recent
  3632. homepageRecent("emby", "' . $this->config['homepageRecentRefresh'] . '");
  3633. // End Emby Recent
  3634. </script>
  3635. ';
  3636. }
  3637. break;
  3638. case 'homepageOrderombi':
  3639. if ($this->config['homepageOmbiEnabled']) {
  3640. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Requests...</h2></div>';
  3641. $item .= '
  3642. <script>
  3643. // Ombi Requests
  3644. homepageRequests("' . $this->config['ombiRefresh'] . '");
  3645. // End Ombi Requests
  3646. </script>
  3647. ';
  3648. }
  3649. break;
  3650. case 'homepageOrdercalendar':
  3651. if (
  3652. ($this->config['homepageLidarrEnabled'] && $this->qualifyRequest($this->config['homepageLidarrAuth'])) ||
  3653. ($this->config['homepageSonarrEnabled'] && $this->qualifyRequest($this->config['homepageSonarrAuth'])) ||
  3654. ($this->config['homepageRadarrEnabled'] && $this->qualifyRequest($this->config['homepageRadarrAuth'])) ||
  3655. ($this->config['homepageSickrageEnabled'] && $this->qualifyRequest($this->config['homepageSickrageAuth'])) ||
  3656. ($this->config['homepageCouchpotatoEnabled'] && $this->qualifyRequest($this->config['homepageCouchpotatoAuth'])) ||
  3657. ($this->config['homepageCalendarEnabled'] && $this->qualifyRequest($this->config['homepageCalendarAuth']) && $this->config['calendariCal'] !== '')
  3658. ) {
  3659. $item .= '
  3660. <div id="calendar" class="fc fc-ltr m-b-30"></div>
  3661. <script>
  3662. // Calendar
  3663. homepageCalendar("' . $this->config['calendarRefresh'] . '");
  3664. // End Calendar
  3665. </script>
  3666. ';
  3667. }
  3668. break;
  3669. case 'homepageOrderhealthchecks':
  3670. if ($this->config['homepageHealthChecksEnabled'] && $this->qualifyRequest($this->config['homepageHealthChecksAuth'])) {
  3671. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Health Checks...</h2></div>';
  3672. $item .= '
  3673. <script>
  3674. // Health Checks
  3675. homepageHealthChecks("' . $this->config['healthChecksTags'] . '","' . $this->config['homepageHealthChecksRefresh'] . '");
  3676. // End Health Checks
  3677. </script>
  3678. ';
  3679. }
  3680. break;
  3681. case 'homepageOrderunifi':
  3682. if ($this->config['homepageUnifiEnabled'] && $this->qualifyRequest($this->config['homepageUnifiAuth'])) {
  3683. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Unifi...</h2></div>';
  3684. $item .= '
  3685. <script>
  3686. // Unifi
  3687. homepageUnifi("' . $this->config['homepageHealthChecksRefresh'] . '");
  3688. // End Unifi
  3689. </script>
  3690. ';
  3691. }
  3692. break;
  3693. case 'homepageOrdertautulli':
  3694. if ($this->config['homepageTautulliEnabled'] && $this->qualifyRequest($this->config['homepageTautulliAuth'])) {
  3695. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Tautulli...</h2></div>';
  3696. $item .= '
  3697. <script>
  3698. // Tautulli
  3699. homepageTautulli("' . $this->config['homepageTautulliRefresh'] . '");
  3700. // End Tautulli
  3701. </script>
  3702. ';
  3703. }
  3704. break;
  3705. case 'homepageOrderPihole':
  3706. if ($this->config['homepagePiholeEnabled']) {
  3707. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Pi-hole Stats...</h2></div>';
  3708. $item .= '
  3709. <script>
  3710. // Pi-hole Stats
  3711. homepagePihole("' . $this->config['homepagePiholeRefresh'] . '");
  3712. // End Pi-hole Stats
  3713. </script>
  3714. ';
  3715. }
  3716. break;
  3717. case 'homepageOrderMonitorr':
  3718. if ($this->config['homepageMonitorrEnabled']) {
  3719. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Monitorr...</h2></div>';
  3720. $item .= '
  3721. <script>
  3722. // Monitorr
  3723. homepageMonitorr("' . $this->config['homepageMonitorrRefresh'] . '");
  3724. // End Monitorr
  3725. </script>
  3726. ';
  3727. }
  3728. break;
  3729. case 'homepageOrderWeatherAndAir':
  3730. if ($this->config['homepageWeatherAndAirEnabled']) {
  3731. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Weather And Air...</h2></div>';
  3732. $item .= '
  3733. <script>
  3734. // Weather And Air
  3735. homepageWeatherAndAir("' . $this->config['homepageWeatherAndAirRefresh'] . '");
  3736. // End Weather And Air
  3737. </script>
  3738. ';
  3739. }
  3740. break;
  3741. case 'homepageOrderSpeedtest':
  3742. if ($this->config['homepageSpeedtestEnabled']) {
  3743. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Speedtest...</h2></div>';
  3744. $item .= '
  3745. <script>
  3746. // Speedtest
  3747. homepageSpeedtest("' . $this->config['homepageSpeedtestRefresh'] . '");
  3748. // End Speedtest
  3749. </script>
  3750. ';
  3751. }
  3752. break;
  3753. case 'homepageOrderNetdata':
  3754. if ($this->config['homepageNetdataEnabled']) {
  3755. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Netdata...</h2></div>';
  3756. $item .= '
  3757. <script>
  3758. // Netdata
  3759. homepageNetdata("' . $this->config['homepageNetdataRefresh'] . '");
  3760. // End Netdata
  3761. </script>
  3762. ';
  3763. }
  3764. break;
  3765. case 'homepageOrderOctoprint':
  3766. if ($this->config['homepageOctoprintEnabled']) {
  3767. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Octoprint...</h2></div>';
  3768. $item .= '
  3769. <script>
  3770. // Octoprint
  3771. homepageOctoprint("' . $this->config['homepageOctoprintRefresh'] . '");
  3772. // End Octoprint
  3773. </script>
  3774. ';
  3775. }
  3776. break;
  3777. case 'homepageOrderSonarrQueue':
  3778. if ($this->config['homepageSonarrQueueEnabled'] && $this->qualifyRequest($this->config['homepageSonarrQueueAuth'])) {
  3779. if ($this->config['homepageSonarrQueueCombine']) {
  3780. $item .= '
  3781. <script>
  3782. // Sonarr Queue
  3783. buildDownloaderCombined(\'sonarr\');
  3784. homepageDownloader("sonarr", "' . $this->config['homepageSonarrQueueRefresh'] . '");
  3785. // End Sonarr Queue
  3786. </script>
  3787. ';
  3788. } else {
  3789. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3790. $item .= '
  3791. <script>
  3792. // Sonarr Queue
  3793. $("#' . $homepageItem . '").html(buildDownloader("sonarr"));
  3794. homepageDownloader("sonarr", "' . $this->config['homepageSonarrQueueRefresh'] . '");
  3795. // End Sonarr Queue
  3796. </script>
  3797. ';
  3798. }
  3799. }
  3800. break;
  3801. case 'homepageOrderRadarrQueue':
  3802. if ($this->config['homepageRadarrQueueEnabled'] && $this->qualifyRequest($this->config['homepageRadarrQueueAuth'])) {
  3803. if ($this->config['homepageRadarrQueueCombine']) {
  3804. $item .= '
  3805. <script>
  3806. // Radarr Queue
  3807. buildDownloaderCombined(\'radarr\');
  3808. homepageDownloader("radarr", "' . $this->config['homepageRadarrQueueRefresh'] . '");
  3809. // End Radarr Queue
  3810. </script>
  3811. ';
  3812. } else {
  3813. $item .= '<div class="white-box homepage-loading-box"><h2 class="text-center" lang="en">Loading Download Queue...</h2></div>';
  3814. $item .= '
  3815. <script>
  3816. // Radarr Queue
  3817. $("#' . $homepageItem . '").html(buildDownloader("radarr"));
  3818. homepageDownloader("radarr", "' . $this->config['homepageRadarrQueueRefresh'] . '");
  3819. // End Radarr Queue
  3820. </script>
  3821. ';
  3822. }
  3823. }
  3824. break;
  3825. default:
  3826. # code...
  3827. break;
  3828. }
  3829. return $item . '</div>';
  3830. }
  3831. public function buildHomepageSettings()
  3832. {
  3833. $homepageOrder = $this->homepageOrderList();
  3834. $homepageList = '<h4>Drag Homepage Items to Order Them</h4><div id="homepage-items-sort" class="external-events">';
  3835. $inputList = '<form id="homepage-values" class="row">';
  3836. foreach ($homepageOrder as $key => $val) {
  3837. switch ($key) {
  3838. case 'homepageOrdercustomhtml':
  3839. $class = 'bg-info';
  3840. $image = 'plugins/images/tabs/custom1.png';
  3841. if (!$this->config['homepageCustomHTMLoneEnabled']) {
  3842. $class .= ' faded';
  3843. }
  3844. break;
  3845. case 'homepageOrdercustomhtmlTwo':
  3846. $class = 'bg-info';
  3847. $image = 'plugins/images/tabs/custom2.png';
  3848. if (!$this->config['homepageCustomHTMLtwoEnabled']) {
  3849. $class .= ' faded';
  3850. }
  3851. break;
  3852. case 'homepageOrdertransmission':
  3853. $class = 'bg-transmission';
  3854. $image = 'plugins/images/tabs/transmission.png';
  3855. if (!$this->config['homepageTransmissionEnabled']) {
  3856. $class .= ' faded';
  3857. }
  3858. break;
  3859. case 'homepageOrdernzbget':
  3860. $class = 'bg-nzbget';
  3861. $image = 'plugins/images/tabs/nzbget.png';
  3862. if (!$this->config['homepageNzbgetEnabled']) {
  3863. $class .= ' faded';
  3864. }
  3865. break;
  3866. case 'homepageOrderjdownloader':
  3867. $class = 'bg-sab';
  3868. $image = 'plugins/images/tabs/jdownloader.png';
  3869. if (!$this->config['homepageJdownloaderEnabled']) {
  3870. $class .= ' faded';
  3871. }
  3872. break;
  3873. case 'homepageOrdersabnzbd':
  3874. $class = 'bg-sab';
  3875. $image = 'plugins/images/tabs/sabnzbd.png';
  3876. if (!$this->config['homepageSabnzbdEnabled']) {
  3877. $class .= ' faded';
  3878. }
  3879. break;
  3880. case 'homepageOrderdeluge':
  3881. $class = 'bg-deluge';
  3882. $image = 'plugins/images/tabs/deluge.png';
  3883. if (!$this->config['homepageDelugeEnabled']) {
  3884. $class .= ' faded';
  3885. }
  3886. break;
  3887. case 'homepageOrderqBittorrent':
  3888. $class = 'bg-qbit';
  3889. $image = 'plugins/images/tabs/qBittorrent.png';
  3890. if (!$this->config['homepageqBittorrentEnabled']) {
  3891. $class .= ' faded';
  3892. }
  3893. break;
  3894. case 'homepageOrderrTorrent':
  3895. $class = 'bg-qbit';
  3896. $image = 'plugins/images/tabs/rTorrent.png';
  3897. if (!$this->config['homepagerTorrentEnabled']) {
  3898. $class .= ' faded';
  3899. }
  3900. break;
  3901. case 'homepageOrderplexnowplaying':
  3902. case 'homepageOrderplexrecent':
  3903. case 'homepageOrderplexplaylist':
  3904. $class = 'bg-plex';
  3905. $image = 'plugins/images/tabs/plex.png';
  3906. if (!$this->config['homepagePlexEnabled']) {
  3907. $class .= ' faded';
  3908. }
  3909. break;
  3910. case 'homepageOrderembynowplaying':
  3911. case 'homepageOrderembyrecent':
  3912. $class = 'bg-emby';
  3913. $image = 'plugins/images/tabs/emby.png';
  3914. if (!$this->config['homepageEmbyEnabled']) {
  3915. $class .= ' faded';
  3916. }
  3917. break;
  3918. case 'homepageOrderombi':
  3919. $class = 'bg-inverse';
  3920. $image = 'plugins/images/tabs/ombi.png';
  3921. if (!$this->config['homepageOmbiEnabled']) {
  3922. $class .= ' faded';
  3923. }
  3924. break;
  3925. case 'homepageOrdercalendar':
  3926. $class = 'bg-primary';
  3927. $image = 'plugins/images/tabs/calendar.png';
  3928. if (!$this->config['homepageSonarrEnabled'] && !$this->config['homepageRadarrEnabled'] && !$this->config['homepageSickrageEnabled'] && !$this->config['homepageCouchpotatoEnabled']) {
  3929. $class .= ' faded';
  3930. }
  3931. break;
  3932. case 'homepageOrderdownloader':
  3933. $class = 'bg-inverse';
  3934. $image = 'plugins/images/tabs/downloader.png';
  3935. if (!$this->config['jdownloaderCombine'] && !$this->config['sabnzbdCombine'] && !$this->config['nzbgetCombine'] && !$this->config['rTorrentCombine'] && !$this->config['delugeCombine'] && !$this->config['transmissionCombine'] && !$this->config['qBittorrentCombine']) {
  3936. $class .= ' faded';
  3937. }
  3938. break;
  3939. case 'homepageOrderhealthchecks':
  3940. $class = 'bg-healthchecks';
  3941. $image = 'plugins/images/tabs/healthchecks.png';
  3942. if (!$this->config['homepageHealthChecksEnabled']) {
  3943. $class .= ' faded';
  3944. }
  3945. break;
  3946. case 'homepageOrderunifi':
  3947. $class = 'bg-info';
  3948. $image = 'plugins/images/tabs/ubnt.png';
  3949. if (!$this->config['homepageUnifiEnabled']) {
  3950. $class .= ' faded';
  3951. }
  3952. break;
  3953. case 'homepageOrdertautulli':
  3954. $class = 'bg-info';
  3955. $image = 'plugins/images/tabs/tautulli.png';
  3956. if (!$this->config['homepageTautulliEnabled']) {
  3957. $class .= ' faded';
  3958. }
  3959. break;
  3960. case 'homepageOrderPihole':
  3961. $class = 'bg-info';
  3962. $image = 'plugins/images/tabs/pihole.png';
  3963. if (!$this->config['homepagePiholeEnabled']) {
  3964. $class .= ' faded';
  3965. }
  3966. break;
  3967. case 'homepageOrderMonitorr':
  3968. $class = 'bg-info';
  3969. $image = 'plugins/images/tabs/monitorr.png';
  3970. if (!$this->config['homepageMonitorrEnabled']) {
  3971. $class .= ' faded';
  3972. }
  3973. break;
  3974. case 'homepageOrderWeatherAndAir':
  3975. $class = 'bg-success';
  3976. $image = 'plugins/images/tabs/wind.png';
  3977. if (!$this->config['homepageWeatherAndAirEnabled']) {
  3978. $class .= ' faded';
  3979. }
  3980. break;
  3981. case 'homepageOrderSpeedtest':
  3982. $class = 'bg-success';
  3983. $image = 'plugins/images/tabs/speedtest-icon.png';
  3984. if (!$this->config['homepageSpeedtestEnabled']) {
  3985. $class .= ' faded';
  3986. }
  3987. break;
  3988. case 'homepageOrderNetdata':
  3989. $class = 'bg-success';
  3990. $image = 'plugins/images/tabs/netdata.png';
  3991. if (!$this->config['homepageNetdataEnabled']) {
  3992. $class .= ' faded';
  3993. }
  3994. break;
  3995. case 'homepageOrderOctoprint':
  3996. $class = 'bg-success';
  3997. $image = 'plugins/images/tabs/octoprint.png';
  3998. if (!$this->config['homepageOctoprintEnabled']) {
  3999. $class .= ' faded';
  4000. }
  4001. break;
  4002. case 'homepageOrderSonarrQueue':
  4003. $class = 'bg-sonarr';
  4004. $image = 'plugins/images/tabs/sonarr.png';
  4005. if (!$this->config['homepageSonarrQueueEnabled']) {
  4006. $class .= ' faded';
  4007. }
  4008. break;
  4009. case 'homepageOrderRadarrQueue':
  4010. $class = 'bg-radarr';
  4011. $image = 'plugins/images/tabs/radarr.png';
  4012. if (!$this->config['homepageRadarrQueueEnabled']) {
  4013. $class .= ' faded';
  4014. }
  4015. break;
  4016. default:
  4017. $class = 'blue-bg';
  4018. $image = '';
  4019. break;
  4020. }
  4021. $homepageList .= '
  4022. <div class="col-md-3 col-xs-12 sort-homepage m-t-10 hvr-grow clearfix">
  4023. <div class="homepage-drag fc-event ' . $class . ' lazyload" data-src="' . $image . '">
  4024. <span class="ordinal-position text-uppercase badge bg-org homepage-number" data-link="' . $key . '" style="float:left;width: 30px;">' . $val . '</span>
  4025. <span class="homepage-text">&nbsp; ' . strtoupper(substr($key, 13)) . '</span>
  4026. </div>
  4027. </div>
  4028. ';
  4029. $inputList .= '<input type="hidden" name="' . $key . '">';
  4030. }
  4031. $homepageList .= '</div>';
  4032. $inputList .= '</form>';
  4033. return $homepageList . $inputList;
  4034. }
  4035. public function getSettingsHomepage()
  4036. {
  4037. $groups = $this->groupSelect();
  4038. $ombiTvOptions = array(
  4039. array(
  4040. 'name' => 'All Seasons',
  4041. 'value' => 'all'
  4042. ),
  4043. array(
  4044. 'name' => 'First Season Only',
  4045. 'value' => 'first'
  4046. ),
  4047. array(
  4048. 'name' => 'Last Season Only',
  4049. 'value' => 'last'
  4050. ),
  4051. );
  4052. $mediaServers = array(
  4053. array(
  4054. 'name' => 'N/A',
  4055. 'value' => ''
  4056. ),
  4057. array(
  4058. 'name' => 'Plex',
  4059. 'value' => 'plex'
  4060. ),
  4061. array(
  4062. 'name' => 'Emby [Not Available]',
  4063. 'value' => 'emby'
  4064. )
  4065. );
  4066. $limit = array(
  4067. array(
  4068. 'name' => '1 Item',
  4069. 'value' => '1'
  4070. ),
  4071. array(
  4072. 'name' => '2 Items',
  4073. 'value' => '2'
  4074. ),
  4075. array(
  4076. 'name' => '3 Items',
  4077. 'value' => '3'
  4078. ),
  4079. array(
  4080. 'name' => '4 Items',
  4081. 'value' => '4'
  4082. ),
  4083. array(
  4084. 'name' => '5 Items',
  4085. 'value' => '5'
  4086. ),
  4087. array(
  4088. 'name' => '6 Items',
  4089. 'value' => '6'
  4090. ),
  4091. array(
  4092. 'name' => '7 Items',
  4093. 'value' => '7'
  4094. ),
  4095. array(
  4096. 'name' => '8 Items',
  4097. 'value' => '8'
  4098. ),
  4099. array(
  4100. 'name' => 'Unlimited',
  4101. 'value' => '1000'
  4102. ),
  4103. );
  4104. $day = array(
  4105. array(
  4106. 'name' => 'Sunday',
  4107. 'value' => '0'
  4108. ),
  4109. array(
  4110. 'name' => 'Monday',
  4111. 'value' => '1'
  4112. ),
  4113. array(
  4114. 'name' => 'Tueday',
  4115. 'value' => '2'
  4116. ),
  4117. array(
  4118. 'name' => 'Wednesday',
  4119. 'value' => '3'
  4120. ),
  4121. array(
  4122. 'name' => 'Thursday',
  4123. 'value' => '4'
  4124. ),
  4125. array(
  4126. 'name' => 'Friday',
  4127. 'value' => '5'
  4128. ),
  4129. array(
  4130. 'name' => 'Saturday',
  4131. 'value' => '6'
  4132. )
  4133. );
  4134. $calendarDefault = array(
  4135. array(
  4136. 'name' => 'Month',
  4137. 'value' => 'month'
  4138. ),
  4139. array(
  4140. 'name' => 'Day',
  4141. 'value' => 'basicDay'
  4142. ),
  4143. array(
  4144. 'name' => 'Week',
  4145. 'value' => 'basicWeek'
  4146. ),
  4147. array(
  4148. 'name' => 'List',
  4149. 'value' => 'list'
  4150. )
  4151. );
  4152. $timeFormat = array(
  4153. array(
  4154. 'name' => '6p',
  4155. 'value' => 'h(:mm)t'
  4156. ),
  4157. array(
  4158. 'name' => '6:00p',
  4159. 'value' => 'h:mmt'
  4160. ),
  4161. array(
  4162. 'name' => '6:00',
  4163. 'value' => 'h:mm'
  4164. ),
  4165. array(
  4166. 'name' => '18',
  4167. 'value' => 'H(:mm)'
  4168. ),
  4169. array(
  4170. 'name' => '18:00',
  4171. 'value' => 'H:mm'
  4172. )
  4173. );
  4174. $rTorrentSortOptions = array(
  4175. array(
  4176. 'name' => 'Date Desc',
  4177. 'value' => 'dated'
  4178. ),
  4179. array(
  4180. 'name' => 'Date Asc',
  4181. 'value' => 'datea'
  4182. ),
  4183. array(
  4184. 'name' => 'Hash Desc',
  4185. 'value' => 'hashd'
  4186. ),
  4187. array(
  4188. 'name' => 'Hash Asc',
  4189. 'value' => 'hasha'
  4190. ),
  4191. array(
  4192. 'name' => 'Name Desc',
  4193. 'value' => 'named'
  4194. ),
  4195. array(
  4196. 'name' => 'Name Asc',
  4197. 'value' => 'namea'
  4198. ),
  4199. array(
  4200. 'name' => 'Size Desc',
  4201. 'value' => 'sized'
  4202. ),
  4203. array(
  4204. 'name' => 'Size Asc',
  4205. 'value' => 'sizea'
  4206. ),
  4207. array(
  4208. 'name' => 'Label Desc',
  4209. 'value' => 'labeld'
  4210. ),
  4211. array(
  4212. 'name' => 'Label Asc',
  4213. 'value' => 'labela'
  4214. ),
  4215. array(
  4216. 'name' => 'Status Desc',
  4217. 'value' => 'statusd'
  4218. ),
  4219. array(
  4220. 'name' => 'Status Asc',
  4221. 'value' => 'statusa'
  4222. ),
  4223. );
  4224. $qBittorrentApiOptions = array(
  4225. array(
  4226. 'name' => 'V1',
  4227. 'value' => '1'
  4228. ),
  4229. array(
  4230. 'name' => 'V2',
  4231. 'value' => '2'
  4232. ),
  4233. );
  4234. $qBittorrentSortOptions = array(
  4235. array(
  4236. 'name' => 'Hash',
  4237. 'value' => 'hash'
  4238. ),
  4239. array(
  4240. 'name' => 'Name',
  4241. 'value' => 'name'
  4242. ),
  4243. array(
  4244. 'name' => 'Size',
  4245. 'value' => 'size'
  4246. ),
  4247. array(
  4248. 'name' => 'Progress',
  4249. 'value' => 'progress'
  4250. ),
  4251. array(
  4252. 'name' => 'Download Speed',
  4253. 'value' => 'dlspeed'
  4254. ),
  4255. array(
  4256. 'name' => 'Upload Speed',
  4257. 'value' => 'upspeed'
  4258. ),
  4259. array(
  4260. 'name' => 'Priority',
  4261. 'value' => 'priority'
  4262. ),
  4263. array(
  4264. 'name' => 'Number of Seeds',
  4265. 'value' => 'num_seeds'
  4266. ),
  4267. array(
  4268. 'name' => 'Number of Seeds in Swarm',
  4269. 'value' => 'num_complete'
  4270. ),
  4271. array(
  4272. 'name' => 'Number of Leechers',
  4273. 'value' => 'num_leechs'
  4274. ),
  4275. array(
  4276. 'name' => 'Number of Leechers in Swarm',
  4277. 'value' => 'num_incomplete'
  4278. ),
  4279. array(
  4280. 'name' => 'Ratio',
  4281. 'value' => 'ratio'
  4282. ),
  4283. array(
  4284. 'name' => 'ETA',
  4285. 'value' => 'eta'
  4286. ),
  4287. array(
  4288. 'name' => 'State',
  4289. 'value' => 'state'
  4290. ),
  4291. array(
  4292. 'name' => 'Category',
  4293. 'value' => 'category'
  4294. )
  4295. );
  4296. $xmlStatus = (extension_loaded('xmlrpc')) ? 'Installed' : 'Not Installed';
  4297. return array(
  4298. array(
  4299. 'name' => 'Calendar',
  4300. 'enabled' => strpos('personal', $this->config['license']) !== false,
  4301. 'image' => 'plugins/images/tabs/calendar.png',
  4302. 'category' => 'HOMEPAGE',
  4303. 'settings' => array(
  4304. 'Enable' => array(
  4305. array(
  4306. 'type' => 'switch',
  4307. 'name' => 'homepageCalendarEnabled',
  4308. 'label' => 'Enable iCal',
  4309. 'value' => $this->config['homepageCalendarEnabled']
  4310. ),
  4311. array(
  4312. 'type' => 'select',
  4313. 'name' => 'homepageCalendarAuth',
  4314. 'label' => 'Minimum Authentication',
  4315. 'value' => $this->config['homepageCalendarAuth'],
  4316. 'options' => $groups
  4317. ),
  4318. array(
  4319. 'type' => 'input',
  4320. 'name' => 'calendariCal',
  4321. 'label' => 'iCal URL\'s',
  4322. 'value' => $this->config['calendariCal'],
  4323. 'placeholder' => 'separate by comma\'s'
  4324. ),
  4325. ),
  4326. 'Misc Options' => array(
  4327. array(
  4328. 'type' => 'number',
  4329. 'name' => 'calendarStart',
  4330. 'label' => '# of Days Before',
  4331. 'value' => $this->config['calendarStart'],
  4332. 'placeholder' => ''
  4333. ),
  4334. array(
  4335. 'type' => 'number',
  4336. 'name' => 'calendarEnd',
  4337. 'label' => '# of Days After',
  4338. 'value' => $this->config['calendarEnd'],
  4339. 'placeholder' => ''
  4340. ),
  4341. array(
  4342. 'type' => 'select',
  4343. 'name' => 'calendarFirstDay',
  4344. 'label' => 'Start Day',
  4345. 'value' => $this->config['calendarFirstDay'],
  4346. 'options' => $day
  4347. ),
  4348. array(
  4349. 'type' => 'select',
  4350. 'name' => 'calendarDefault',
  4351. 'label' => 'Default View',
  4352. 'value' => $this->config['calendarDefault'],
  4353. 'options' => $calendarDefault
  4354. ),
  4355. array(
  4356. 'type' => 'select',
  4357. 'name' => 'calendarTimeFormat',
  4358. 'label' => 'Time Format',
  4359. 'value' => $this->config['calendarTimeFormat'],
  4360. 'options' => $timeFormat
  4361. ),
  4362. array(
  4363. 'type' => 'select',
  4364. 'name' => 'calendarLimit',
  4365. 'label' => 'Items Per Day',
  4366. 'value' => $this->config['calendarLimit'],
  4367. 'options' => $limit
  4368. ),
  4369. array(
  4370. 'type' => 'select',
  4371. 'name' => 'calendarRefresh',
  4372. 'label' => 'Refresh Seconds',
  4373. 'value' => $this->config['calendarRefresh'],
  4374. 'options' => $this->optionTime()
  4375. )
  4376. ),
  4377. )
  4378. ),
  4379. array(
  4380. 'name' => 'Plex',
  4381. 'enabled' => strpos('personal', $this->config['license']) !== false,
  4382. 'image' => 'plugins/images/tabs/plex.png',
  4383. 'category' => 'Media Server',
  4384. 'settings' => array(
  4385. 'Enable' => array(
  4386. array(
  4387. 'type' => 'switch',
  4388. 'name' => 'homepagePlexEnabled',
  4389. 'label' => 'Enable',
  4390. 'value' => $this->config['homepagePlexEnabled']
  4391. ),
  4392. array(
  4393. 'type' => 'select',
  4394. 'name' => 'homepagePlexAuth',
  4395. 'label' => 'Minimum Authentication',
  4396. 'value' => $this->config['homepagePlexAuth'],
  4397. 'options' => $groups
  4398. )
  4399. ),
  4400. 'Connection' => array(
  4401. array(
  4402. 'type' => 'input',
  4403. 'name' => 'plexURL',
  4404. 'label' => 'URL',
  4405. 'value' => $this->config['plexURL'],
  4406. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  4407. 'placeholder' => 'http(s)://hostname:port'
  4408. ),
  4409. array(
  4410. 'type' => 'password-alt',
  4411. 'name' => 'plexToken',
  4412. 'label' => 'Token',
  4413. 'value' => $this->config['plexToken']
  4414. ),
  4415. array(
  4416. 'type' => 'password-alt',
  4417. 'name' => 'plexID',
  4418. 'label' => 'Plex Machine',
  4419. 'value' => $this->config['plexID']
  4420. )
  4421. ),
  4422. 'Active Streams' => array(
  4423. array(
  4424. 'type' => 'switch',
  4425. 'name' => 'homepagePlexStreams',
  4426. 'label' => 'Enable',
  4427. 'value' => $this->config['homepagePlexStreams']
  4428. ),
  4429. array(
  4430. 'type' => 'select',
  4431. 'name' => 'homepagePlexStreamsAuth',
  4432. 'label' => 'Minimum Authorization',
  4433. 'value' => $this->config['homepagePlexStreamsAuth'],
  4434. 'options' => $groups
  4435. ),
  4436. array(
  4437. 'type' => 'switch',
  4438. 'name' => 'homepageShowStreamNames',
  4439. 'label' => 'User Information',
  4440. 'value' => $this->config['homepageShowStreamNames']
  4441. ),
  4442. array(
  4443. 'type' => 'select',
  4444. 'name' => 'homepageShowStreamNamesAuth',
  4445. 'label' => 'Minimum Authorization',
  4446. 'value' => $this->config['homepageShowStreamNamesAuth'],
  4447. 'options' => $groups
  4448. ),
  4449. array(
  4450. 'type' => 'select',
  4451. 'name' => 'homepageStreamRefresh',
  4452. 'label' => 'Refresh Seconds',
  4453. 'value' => $this->config['homepageStreamRefresh'],
  4454. 'options' => $this->optionTime()
  4455. ),
  4456. ),
  4457. 'Recent Items' => array(
  4458. array(
  4459. 'type' => 'switch',
  4460. 'name' => 'homepagePlexRecent',
  4461. 'label' => 'Enable',
  4462. 'value' => $this->config['homepagePlexRecent']
  4463. ),
  4464. array(
  4465. 'type' => 'select',
  4466. 'name' => 'homepagePlexRecentAuth',
  4467. 'label' => 'Minimum Authorization',
  4468. 'value' => $this->config['homepagePlexRecentAuth'],
  4469. 'options' => $groups
  4470. ),
  4471. array(
  4472. 'type' => 'number',
  4473. 'name' => 'homepageRecentLimit',
  4474. 'label' => 'Item Limit',
  4475. 'value' => $this->config['homepageRecentLimit'],
  4476. ),
  4477. array(
  4478. 'type' => 'select',
  4479. 'name' => 'homepageRecentRefresh',
  4480. 'label' => 'Refresh Seconds',
  4481. 'value' => $this->config['homepageRecentRefresh'],
  4482. 'options' => $this->optionTime()
  4483. ),
  4484. ),
  4485. 'Media Search' => array(
  4486. array(
  4487. 'type' => 'switch',
  4488. 'name' => 'mediaSearch',
  4489. 'label' => 'Enable',
  4490. 'value' => $this->config['mediaSearch']
  4491. ),
  4492. array(
  4493. 'type' => 'select',
  4494. 'name' => 'mediaSearchAuth',
  4495. 'label' => 'Minimum Authorization',
  4496. 'value' => $this->config['mediaSearchAuth'],
  4497. 'options' => $groups
  4498. ),
  4499. array(
  4500. 'type' => 'select',
  4501. 'name' => 'mediaSearchType',
  4502. 'label' => 'Media Server',
  4503. 'value' => $this->config['mediaSearchType'],
  4504. 'options' => $mediaServers
  4505. ),
  4506. ),
  4507. 'Playlists' => array(
  4508. array(
  4509. 'type' => 'switch',
  4510. 'name' => 'homepagePlexPlaylist',
  4511. 'label' => 'Enable',
  4512. 'value' => $this->config['homepagePlexPlaylist']
  4513. ),
  4514. array(
  4515. 'type' => 'select',
  4516. 'name' => 'homepagePlexPlaylistAuth',
  4517. 'label' => 'Minimum Authorization',
  4518. 'value' => $this->config['homepagePlexPlaylistAuth'],
  4519. 'options' => $groups
  4520. ),
  4521. ),
  4522. 'Misc Options' => array(
  4523. array(
  4524. 'type' => 'input',
  4525. 'name' => 'plexTabName',
  4526. 'label' => 'Plex Tab Name',
  4527. 'value' => $this->config['plexTabName'],
  4528. 'placeholder' => 'Only use if you have Plex in a reverse proxy'
  4529. ),
  4530. array(
  4531. 'type' => 'input',
  4532. 'name' => 'plexTabURL',
  4533. 'label' => 'Plex Tab WAN URL',
  4534. 'value' => $this->config['plexTabURL'],
  4535. 'placeholder' => 'http(s)://hostname:port'
  4536. ),
  4537. array(
  4538. 'type' => 'select',
  4539. 'name' => 'cacheImageSize',
  4540. 'label' => 'Image Cache Size',
  4541. 'value' => $this->config['cacheImageSize'],
  4542. 'options' => array(
  4543. array(
  4544. 'name' => 'Low',
  4545. 'value' => '.5'
  4546. ),
  4547. array(
  4548. 'name' => '1x',
  4549. 'value' => '1'
  4550. ),
  4551. array(
  4552. 'name' => '2x',
  4553. 'value' => '2'
  4554. ),
  4555. array(
  4556. 'name' => '3x',
  4557. 'value' => '3'
  4558. )
  4559. )
  4560. )
  4561. ),
  4562. 'Test Connection' => array(
  4563. array(
  4564. 'type' => 'blank',
  4565. 'label' => 'Please Save before Testing'
  4566. ),
  4567. array(
  4568. 'type' => 'button',
  4569. 'label' => '',
  4570. 'icon' => 'fa fa-flask',
  4571. 'class' => 'pull-right',
  4572. 'text' => 'Test Connection',
  4573. 'attr' => 'onclick="testAPIConnection(\'plex\')"'
  4574. ),
  4575. )
  4576. )
  4577. ),
  4578. array(
  4579. 'name' => 'Emby-Jellyfin',
  4580. 'enabled' => strpos('personal', $this->config['license']) !== false,
  4581. 'image' => 'plugins/images/tabs/emby.png',
  4582. 'category' => 'Media Server',
  4583. 'settings' => array(
  4584. 'Enable' => array(
  4585. array(
  4586. 'type' => 'switch',
  4587. 'name' => 'homepageEmbyEnabled',
  4588. 'label' => 'Enable',
  4589. 'value' => $this->config['homepageEmbyEnabled']
  4590. ),
  4591. array(
  4592. 'type' => 'select',
  4593. 'name' => 'homepageEmbyAuth',
  4594. 'label' => 'Minimum Authentication',
  4595. 'value' => $this->config['homepageEmbyAuth'],
  4596. 'options' => $groups
  4597. )
  4598. ),
  4599. 'Connection' => array(
  4600. array(
  4601. 'type' => 'input',
  4602. 'name' => 'embyURL',
  4603. 'label' => 'URL',
  4604. 'value' => $this->config['embyURL'],
  4605. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  4606. 'placeholder' => 'http(s)://hostname:port'
  4607. ),
  4608. array(
  4609. 'type' => 'password-alt',
  4610. 'name' => 'embyToken',
  4611. 'label' => 'Token',
  4612. 'value' => $this->config['embyToken']
  4613. ),
  4614. array(
  4615. 'type' => 'switch',
  4616. 'name' => 'homepageJellyfinInstead',
  4617. 'label' => 'Jellyfin',
  4618. 'value' => $this->config['homepageJellyfinInstead']
  4619. )
  4620. ),
  4621. 'Active Streams' => array(
  4622. array(
  4623. 'type' => 'switch',
  4624. 'name' => 'homepageEmbyStreams',
  4625. 'label' => 'Enable',
  4626. 'value' => $this->config['homepageEmbyStreams']
  4627. ),
  4628. array(
  4629. 'type' => 'select',
  4630. 'name' => 'homepageEmbyStreamsAuth',
  4631. 'label' => 'Minimum Authorization',
  4632. 'value' => $this->config['homepageEmbyStreamsAuth'],
  4633. 'options' => $groups
  4634. ),
  4635. array(
  4636. 'type' => 'switch',
  4637. 'name' => 'homepageShowStreamNames',
  4638. 'label' => 'User Information',
  4639. 'value' => $this->config['homepageShowStreamNames']
  4640. ),
  4641. array(
  4642. 'type' => 'select',
  4643. 'name' => 'homepageShowStreamNamesAuth',
  4644. 'label' => 'Minimum Authorization',
  4645. 'value' => $this->config['homepageShowStreamNamesAuth'],
  4646. 'options' => $groups
  4647. ),
  4648. array(
  4649. 'type' => 'select',
  4650. 'name' => 'homepageStreamRefresh',
  4651. 'label' => 'Refresh Seconds',
  4652. 'value' => $this->config['homepageStreamRefresh'],
  4653. 'options' => $this->optionTime()
  4654. ),
  4655. ),
  4656. 'Recent Items' => array(
  4657. array(
  4658. 'type' => 'switch',
  4659. 'name' => 'homepageEmbyRecent',
  4660. 'label' => 'Enable',
  4661. 'value' => $this->config['homepageEmbyRecent']
  4662. ),
  4663. array(
  4664. 'type' => 'select',
  4665. 'name' => 'homepageEmbyRecentAuth',
  4666. 'label' => 'Minimum Authorization',
  4667. 'value' => $this->config['homepageEmbyRecentAuth'],
  4668. 'options' => $groups
  4669. ),
  4670. array(
  4671. 'type' => 'number',
  4672. 'name' => 'homepageRecentLimit',
  4673. 'label' => 'Item Limit',
  4674. 'value' => $this->config['homepageRecentLimit'],
  4675. ),
  4676. array(
  4677. 'type' => 'select',
  4678. 'name' => 'homepageRecentRefresh',
  4679. 'label' => 'Refresh Seconds',
  4680. 'value' => $this->config['homepageRecentRefresh'],
  4681. 'options' => $this->optionTime()
  4682. ),
  4683. ),
  4684. 'Misc Options' => array(
  4685. array(
  4686. 'type' => 'input',
  4687. 'name' => 'embyTabName',
  4688. 'label' => 'Emby Tab Name',
  4689. 'value' => $this->config['embyTabName'],
  4690. 'placeholder' => 'Only use if you have Emby in a reverse proxy'
  4691. ),
  4692. array(
  4693. 'type' => 'input',
  4694. 'name' => 'embyTabURL',
  4695. 'label' => 'Emby Tab WAN URL',
  4696. 'value' => $this->config['embyTabURL'],
  4697. 'placeholder' => 'http(s)://hostname:port'
  4698. ),
  4699. array(
  4700. 'type' => 'select',
  4701. 'name' => 'cacheImageSize',
  4702. 'label' => 'Image Cache Size',
  4703. 'value' => $this->config['cacheImageSize'],
  4704. 'options' => array(
  4705. array(
  4706. 'name' => 'Low',
  4707. 'value' => '.5'
  4708. ),
  4709. array(
  4710. 'name' => '1x',
  4711. 'value' => '1'
  4712. ),
  4713. array(
  4714. 'name' => '2x',
  4715. 'value' => '2'
  4716. ),
  4717. array(
  4718. 'name' => '3x',
  4719. 'value' => '3'
  4720. )
  4721. )
  4722. )
  4723. ),
  4724. 'Test Connection' => array(
  4725. array(
  4726. 'type' => 'blank',
  4727. 'label' => 'Please Save before Testing'
  4728. ),
  4729. array(
  4730. 'type' => 'button',
  4731. 'label' => '',
  4732. 'icon' => 'fa fa-flask',
  4733. 'class' => 'pull-right',
  4734. 'text' => 'Test Connection',
  4735. 'attr' => 'onclick="testAPIConnection(\'emby\')"'
  4736. ),
  4737. )
  4738. )
  4739. ),
  4740. array(
  4741. 'name' => 'JDownloader',
  4742. 'enabled' => strpos('personal', $this->config['license']) !== false,
  4743. 'image' => 'plugins/images/tabs/jdownloader.png',
  4744. 'category' => 'Downloader',
  4745. 'settings' => array(
  4746. 'custom' => '
  4747. <div class="row">
  4748. <div class="col-lg-12">
  4749. <div class="panel panel-info">
  4750. <div class="panel-heading">
  4751. <span lang="en">Notice</span>
  4752. </div>
  4753. <div class="panel-wrapper collapse in" aria-expanded="true">
  4754. <div class="panel-body">
  4755. <ul class="list-icons">
  4756. <li><i class="fa fa-chevron-right text-danger"></i> <a href="https://pypi.org/project/myjd-api/" target="_blank">Download [myjd-api] Module</a></li>
  4757. <li><i class="fa fa-chevron-right text-danger"></i> Add <b>/api/myjd</b> to the URL if you are using <a href="https://pypi.org/project/RSScrawler/" target="_blank">RSScrawler</a></li>
  4758. </ul>
  4759. </div>
  4760. </div>
  4761. </div>
  4762. </div>
  4763. </div>
  4764. ',
  4765. 'Enable' => array(
  4766. array(
  4767. 'type' => 'switch',
  4768. 'name' => 'homepageJdownloaderEnabled',
  4769. 'label' => 'Enable',
  4770. 'value' => $this->config['homepageJdownloaderEnabled']
  4771. ),
  4772. array(
  4773. 'type' => 'select',
  4774. 'name' => 'homepageJdownloaderAuth',
  4775. 'label' => 'Minimum Authentication',
  4776. 'value' => $this->config['homepageJdownloaderAuth'],
  4777. 'options' => $groups
  4778. )
  4779. ),
  4780. 'Connection' => array(
  4781. array(
  4782. 'type' => 'input',
  4783. 'name' => 'jdownloaderURL',
  4784. 'label' => 'URL',
  4785. 'value' => $this->config['jdownloaderURL'],
  4786. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  4787. 'placeholder' => 'http(s)://hostname:port'
  4788. )
  4789. ),
  4790. 'Misc Options' => array(
  4791. array(
  4792. 'type' => 'select',
  4793. 'name' => 'homepageDownloadRefresh',
  4794. 'label' => 'Refresh Seconds',
  4795. 'value' => $this->config['homepageDownloadRefresh'],
  4796. 'options' => $this->optionTime()
  4797. ),
  4798. array(
  4799. 'type' => 'switch',
  4800. 'name' => 'jdownloaderCombine',
  4801. 'label' => 'Add to Combined Downloader',
  4802. 'value' => $this->config['jdownloaderCombine']
  4803. ),
  4804. ),
  4805. 'Test Connection' => array(
  4806. array(
  4807. 'type' => 'blank',
  4808. 'label' => 'Please Save before Testing'
  4809. ),
  4810. array(
  4811. 'type' => 'button',
  4812. 'label' => '',
  4813. 'icon' => 'fa fa-flask',
  4814. 'class' => 'pull-right',
  4815. 'text' => 'Test Connection',
  4816. 'attr' => 'onclick="testAPIConnection(\'jdownloader\')"'
  4817. ),
  4818. )
  4819. )
  4820. ),
  4821. array(
  4822. 'name' => 'SabNZBD',
  4823. 'enabled' => strpos('personal', $this->config['license']) !== false,
  4824. 'image' => 'plugins/images/tabs/sabnzbd.png',
  4825. 'category' => 'Downloader',
  4826. 'settings' => array(
  4827. 'Enable' => array(
  4828. array(
  4829. 'type' => 'switch',
  4830. 'name' => 'homepageSabnzbdEnabled',
  4831. 'label' => 'Enable',
  4832. 'value' => $this->config['homepageSabnzbdEnabled']
  4833. ),
  4834. array(
  4835. 'type' => 'select',
  4836. 'name' => 'homepageSabnzbdAuth',
  4837. 'label' => 'Minimum Authentication',
  4838. 'value' => $this->config['homepageSabnzbdAuth'],
  4839. 'options' => $groups
  4840. )
  4841. ),
  4842. 'Connection' => array(
  4843. array(
  4844. 'type' => 'input',
  4845. 'name' => 'sabnzbdURL',
  4846. 'label' => 'URL',
  4847. 'value' => $this->config['sabnzbdURL'],
  4848. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  4849. 'placeholder' => 'http(s)://hostname:port'
  4850. ),
  4851. array(
  4852. 'type' => 'password-alt',
  4853. 'name' => 'sabnzbdToken',
  4854. 'label' => 'Token',
  4855. 'value' => $this->config['sabnzbdToken']
  4856. )
  4857. ),
  4858. 'Misc Options' => array(
  4859. array(
  4860. 'type' => 'select',
  4861. 'name' => 'homepageDownloadRefresh',
  4862. 'label' => 'Refresh Seconds',
  4863. 'value' => $this->config['homepageDownloadRefresh'],
  4864. 'options' => $this->optionTime()
  4865. ),
  4866. array(
  4867. 'type' => 'switch',
  4868. 'name' => 'sabnzbdCombine',
  4869. 'label' => 'Add to Combined Downloader',
  4870. 'value' => $this->config['sabnzbdCombine']
  4871. ),
  4872. ),
  4873. 'Test Connection' => array(
  4874. array(
  4875. 'type' => 'blank',
  4876. 'label' => 'Please Save before Testing'
  4877. ),
  4878. array(
  4879. 'type' => 'button',
  4880. 'label' => '',
  4881. 'icon' => 'fa fa-flask',
  4882. 'class' => 'pull-right',
  4883. 'text' => 'Test Connection',
  4884. 'attr' => 'onclick="testAPIConnection(\'sabnzbd\')"'
  4885. ),
  4886. )
  4887. )
  4888. ),
  4889. array(
  4890. 'name' => 'NZBGet',
  4891. 'enabled' => strpos('personal', $this->config['license']) !== false,
  4892. 'image' => 'plugins/images/tabs/nzbget.png',
  4893. 'category' => 'Downloader',
  4894. 'settings' => array(
  4895. 'Enable' => array(
  4896. array(
  4897. 'type' => 'switch',
  4898. 'name' => 'homepageNzbgetEnabled',
  4899. 'label' => 'Enable',
  4900. 'value' => $this->config['homepageNzbgetEnabled']
  4901. ),
  4902. array(
  4903. 'type' => 'select',
  4904. 'name' => 'homepageNzbgetAuth',
  4905. 'label' => 'Minimum Authentication',
  4906. 'value' => $this->config['homepageNzbgetAuth'],
  4907. 'options' => $groups
  4908. )
  4909. ),
  4910. 'Connection' => array(
  4911. array(
  4912. 'type' => 'input',
  4913. 'name' => 'nzbgetURL',
  4914. 'label' => 'URL',
  4915. 'value' => $this->config['nzbgetURL'],
  4916. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  4917. 'placeholder' => 'http(s)://hostname:port'
  4918. ),
  4919. array(
  4920. 'type' => 'input',
  4921. 'name' => 'nzbgetUsername',
  4922. 'label' => 'Username',
  4923. 'value' => $this->config['nzbgetUsername']
  4924. ),
  4925. array(
  4926. 'type' => 'password',
  4927. 'name' => 'nzbgetPassword',
  4928. 'label' => 'Password',
  4929. 'value' => $this->config['nzbgetPassword']
  4930. )
  4931. ),
  4932. 'Misc Options' => array(
  4933. array(
  4934. 'type' => 'select',
  4935. 'name' => 'homepageDownloadRefresh',
  4936. 'label' => 'Refresh Seconds',
  4937. 'value' => $this->config['homepageDownloadRefresh'],
  4938. 'options' => $this->optionTime()
  4939. ),
  4940. array(
  4941. 'type' => 'switch',
  4942. 'name' => 'nzbgetCombine',
  4943. 'label' => 'Add to Combined Downloader',
  4944. 'value' => $this->config['nzbgetCombine']
  4945. ),
  4946. ),
  4947. 'Test Connection' => array(
  4948. array(
  4949. 'type' => 'blank',
  4950. 'label' => 'Please Save before Testing'
  4951. ),
  4952. array(
  4953. 'type' => 'button',
  4954. 'label' => '',
  4955. 'icon' => 'fa fa-flask',
  4956. 'class' => 'pull-right',
  4957. 'text' => 'Test Connection',
  4958. 'attr' => 'onclick="testAPIConnection(\'nzbget\')"'
  4959. ),
  4960. )
  4961. )
  4962. ),
  4963. array(
  4964. 'name' => 'Transmission',
  4965. 'enabled' => strpos('personal', $this->config['license']) !== false,
  4966. 'image' => 'plugins/images/tabs/transmission.png',
  4967. 'category' => 'Downloader',
  4968. 'settings' => array(
  4969. 'Enable' => array(
  4970. array(
  4971. 'type' => 'switch',
  4972. 'name' => 'homepageTransmissionEnabled',
  4973. 'label' => 'Enable',
  4974. 'value' => $this->config['homepageTransmissionEnabled']
  4975. ),
  4976. array(
  4977. 'type' => 'select',
  4978. 'name' => 'homepageTransmissionAuth',
  4979. 'label' => 'Minimum Authentication',
  4980. 'value' => $this->config['homepageTransmissionAuth'],
  4981. 'options' => $groups
  4982. )
  4983. ),
  4984. 'Connection' => array(
  4985. array(
  4986. 'type' => 'input',
  4987. 'name' => 'transmissionURL',
  4988. 'label' => 'URL',
  4989. 'value' => $this->config['transmissionURL'],
  4990. 'help' => 'Please do not included /web in URL. Please make sure to use local IP address and port - You also may use local dns name too.',
  4991. 'placeholder' => 'http(s)://hostname:port'
  4992. ),
  4993. array(
  4994. 'type' => 'input',
  4995. 'name' => 'transmissionUsername',
  4996. 'label' => 'Username',
  4997. 'value' => $this->config['transmissionUsername']
  4998. ),
  4999. array(
  5000. 'type' => 'password',
  5001. 'name' => 'transmissionPassword',
  5002. 'label' => 'Password',
  5003. 'value' => $this->config['transmissionPassword']
  5004. )
  5005. ),
  5006. 'Misc Options' => array(
  5007. array(
  5008. 'type' => 'switch',
  5009. 'name' => 'transmissionHideSeeding',
  5010. 'label' => 'Hide Seeding',
  5011. 'value' => $this->config['transmissionHideSeeding']
  5012. ), array(
  5013. 'type' => 'switch',
  5014. 'name' => 'transmissionHideCompleted',
  5015. 'label' => 'Hide Completed',
  5016. 'value' => $this->config['transmissionHideCompleted']
  5017. ),
  5018. array(
  5019. 'type' => 'select',
  5020. 'name' => 'homepageDownloadRefresh',
  5021. 'label' => 'Refresh Seconds',
  5022. 'value' => $this->config['homepageDownloadRefresh'],
  5023. 'options' => $this->optionTime()
  5024. ),
  5025. array(
  5026. 'type' => 'switch',
  5027. 'name' => 'transmissionCombine',
  5028. 'label' => 'Add to Combined Downloader',
  5029. 'value' => $this->config['transmissionCombine']
  5030. ),
  5031. ),
  5032. 'Test Connection' => array(
  5033. array(
  5034. 'type' => 'blank',
  5035. 'label' => 'Please Save before Testing'
  5036. ),
  5037. array(
  5038. 'type' => 'button',
  5039. 'label' => '',
  5040. 'icon' => 'fa fa-flask',
  5041. 'class' => 'pull-right',
  5042. 'text' => 'Test Connection',
  5043. 'attr' => 'onclick="testAPIConnection(\'transmission\')"'
  5044. ),
  5045. )
  5046. )
  5047. ),
  5048. array(
  5049. 'name' => 'qBittorrent',
  5050. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5051. 'image' => 'plugins/images/tabs/qBittorrent.png',
  5052. 'category' => 'Downloader',
  5053. 'settings' => array(
  5054. 'Enable' => array(
  5055. array(
  5056. 'type' => 'switch',
  5057. 'name' => 'homepageqBittorrentEnabled',
  5058. 'label' => 'Enable',
  5059. 'value' => $this->config['homepageqBittorrentEnabled']
  5060. ),
  5061. array(
  5062. 'type' => 'select',
  5063. 'name' => 'homepageqBittorrentAuth',
  5064. 'label' => 'Minimum Authentication',
  5065. 'value' => $this->config['homepageqBittorrentAuth'],
  5066. 'options' => $groups
  5067. )
  5068. ),
  5069. 'Connection' => array(
  5070. array(
  5071. 'type' => 'input',
  5072. 'name' => 'qBittorrentURL',
  5073. 'label' => 'URL',
  5074. 'value' => $this->config['qBittorrentURL'],
  5075. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5076. 'placeholder' => 'http(s)://hostname:port'
  5077. ),
  5078. array(
  5079. 'type' => 'select',
  5080. 'name' => 'qBittorrentApiVersion',
  5081. 'label' => 'API Version',
  5082. 'value' => $this->config['qBittorrentApiVersion'],
  5083. 'options' => $qBittorrentApiOptions
  5084. ),
  5085. array(
  5086. 'type' => 'input',
  5087. 'name' => 'qBittorrentUsername',
  5088. 'label' => 'Username',
  5089. 'value' => $this->config['qBittorrentUsername']
  5090. ),
  5091. array(
  5092. 'type' => 'password',
  5093. 'name' => 'qBittorrentPassword',
  5094. 'label' => 'Password',
  5095. 'value' => $this->config['qBittorrentPassword']
  5096. )
  5097. ),
  5098. 'Misc Options' => array(
  5099. array(
  5100. 'type' => 'switch',
  5101. 'name' => 'qBittorrentHideSeeding',
  5102. 'label' => 'Hide Seeding',
  5103. 'value' => $this->config['qBittorrentHideSeeding']
  5104. ),
  5105. array(
  5106. 'type' => 'switch',
  5107. 'name' => 'qBittorrentHideCompleted',
  5108. 'label' => 'Hide Completed',
  5109. 'value' => $this->config['qBittorrentHideCompleted']
  5110. ),
  5111. array(
  5112. 'type' => 'select',
  5113. 'name' => 'qBittorrentSortOrder',
  5114. 'label' => 'Order',
  5115. 'value' => $this->config['qBittorrentSortOrder'],
  5116. 'options' => $qBittorrentSortOptions
  5117. ), array(
  5118. 'type' => 'switch',
  5119. 'name' => 'qBittorrentReverseSorting',
  5120. 'label' => 'Reverse Sorting',
  5121. 'value' => $this->config['qBittorrentReverseSorting']
  5122. ),
  5123. array(
  5124. 'type' => 'select',
  5125. 'name' => 'homepageDownloadRefresh',
  5126. 'label' => 'Refresh Seconds',
  5127. 'value' => $this->config['homepageDownloadRefresh'],
  5128. 'options' => $this->optionTime()
  5129. ),
  5130. array(
  5131. 'type' => 'switch',
  5132. 'name' => 'qBittorrentCombine',
  5133. 'label' => 'Add to Combined Downloader',
  5134. 'value' => $this->config['qBittorrentCombine']
  5135. ),
  5136. ),
  5137. 'Test Connection' => array(
  5138. array(
  5139. 'type' => 'blank',
  5140. 'label' => 'Please Save before Testing'
  5141. ),
  5142. array(
  5143. 'type' => 'button',
  5144. 'label' => '',
  5145. 'icon' => 'fa fa-flask',
  5146. 'class' => 'pull-right',
  5147. 'text' => 'Test Connection',
  5148. 'attr' => 'onclick="testAPIConnection(\'qbittorrent\')"'
  5149. ),
  5150. )
  5151. )
  5152. ),
  5153. array(
  5154. 'name' => 'rTorrent',
  5155. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5156. 'image' => 'plugins/images/tabs/rTorrent.png',
  5157. 'category' => 'Downloader',
  5158. 'settings' => array(
  5159. 'FYI' => array(
  5160. array(
  5161. 'type' => 'html',
  5162. 'label' => '',
  5163. 'override' => 12,
  5164. 'html' => '
  5165. <div class="row">
  5166. <div class="col-lg-12">
  5167. <div class="panel panel-info">
  5168. <div class="panel-heading">
  5169. <span lang="en">ATTENTION</span>
  5170. </div>
  5171. <div class="panel-wrapper collapse in" aria-expanded="true">
  5172. <div class="panel-body">
  5173. <h4 lang="en">This module requires XMLRPC</h4>
  5174. <span lang="en">Status: [ <b>' . $xmlStatus . '</b> ]</span>
  5175. <br/></br>
  5176. <span lang="en">
  5177. <h4><b>Note about API URL</b></h4>
  5178. Organizr appends the url with <code>/RPC2</code> unless the URL ends in <code>.php</code><br/>
  5179. <h5>Possible URLs:</h5>
  5180. <li>http://localhost:8080</li>
  5181. <li>https://domain.site/xmlrpc.php</li>
  5182. <li>https://seedbox.site/rutorrent/plugins/httprpc/action.php</li>
  5183. </span>
  5184. </div>
  5185. </div>
  5186. </div>
  5187. </div>
  5188. </div>
  5189. '
  5190. )
  5191. ),
  5192. 'Enable' => array(
  5193. array(
  5194. 'type' => 'switch',
  5195. 'name' => 'homepagerTorrentEnabled',
  5196. 'label' => 'Enable',
  5197. 'value' => $this->config['homepagerTorrentEnabled']
  5198. ),
  5199. array(
  5200. 'type' => 'select',
  5201. 'name' => 'homepagerTorrentAuth',
  5202. 'label' => 'Minimum Authentication',
  5203. 'value' => $this->config['homepagerTorrentAuth'],
  5204. 'options' => $groups
  5205. )
  5206. ),
  5207. 'Connection' => array(
  5208. array(
  5209. 'type' => 'input',
  5210. 'name' => 'rTorrentURL',
  5211. 'label' => 'URL',
  5212. 'value' => $this->config['rTorrentURL'],
  5213. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5214. 'placeholder' => 'http(s)://hostname:port'
  5215. ),
  5216. array(
  5217. 'type' => 'input',
  5218. 'name' => 'rTorrentURLOverride',
  5219. 'label' => 'rTorrent API URL Override',
  5220. 'value' => $this->config['rTorrentURLOverride'],
  5221. 'help' => 'Only use if you cannot connect. Please make sure to use local IP address and port - You also may use local dns name too.',
  5222. 'placeholder' => 'http(s)://hostname:port/xmlrpc'
  5223. ),
  5224. array(
  5225. 'type' => 'input',
  5226. 'name' => 'rTorrentUsername',
  5227. 'label' => 'Username',
  5228. 'value' => $this->config['rTorrentUsername']
  5229. ),
  5230. array(
  5231. 'type' => 'password',
  5232. 'name' => 'rTorrentPassword',
  5233. 'label' => 'Password',
  5234. 'value' => $this->config['rTorrentPassword']
  5235. ),
  5236. array(
  5237. 'type' => 'switch',
  5238. 'name' => 'rTorrentDisableCertCheck',
  5239. 'label' => 'Disable Certificate Check',
  5240. 'value' => $this->config['rTorrentDisableCertCheck']
  5241. ),
  5242. ),
  5243. 'Misc Options' => array(
  5244. array(
  5245. 'type' => 'switch',
  5246. 'name' => 'rTorrentHideSeeding',
  5247. 'label' => 'Hide Seeding',
  5248. 'value' => $this->config['rTorrentHideSeeding']
  5249. ), array(
  5250. 'type' => 'switch',
  5251. 'name' => 'rTorrentHideCompleted',
  5252. 'label' => 'Hide Completed',
  5253. 'value' => $this->config['rTorrentHideCompleted']
  5254. ),
  5255. array(
  5256. 'type' => 'select',
  5257. 'name' => 'rTorrentSortOrder',
  5258. 'label' => 'Order',
  5259. 'value' => $this->config['rTorrentSortOrder'],
  5260. 'options' => $rTorrentSortOptions
  5261. ),
  5262. array(
  5263. 'type' => 'select',
  5264. 'name' => 'homepageDownloadRefresh',
  5265. 'label' => 'Refresh Seconds',
  5266. 'value' => $this->config['homepageDownloadRefresh'],
  5267. 'options' => $this->optionTime()
  5268. ),
  5269. array(
  5270. 'type' => 'number',
  5271. 'name' => 'rTorrentLimit',
  5272. 'label' => 'Item Limit',
  5273. 'value' => $this->config['rTorrentLimit'],
  5274. ),
  5275. array(
  5276. 'type' => 'switch',
  5277. 'name' => 'rTorrentCombine',
  5278. 'label' => 'Add to Combined Downloader',
  5279. 'value' => $this->config['rTorrentCombine']
  5280. ),
  5281. ),
  5282. 'Test Connection' => array(
  5283. array(
  5284. 'type' => 'blank',
  5285. 'label' => 'Please Save before Testing'
  5286. ),
  5287. array(
  5288. 'type' => 'button',
  5289. 'label' => '',
  5290. 'icon' => 'fa fa-flask',
  5291. 'class' => 'pull-right',
  5292. 'text' => 'Test Connection',
  5293. 'attr' => 'onclick="testAPIConnection(\'rtorrent\')"'
  5294. ),
  5295. )
  5296. )
  5297. ),
  5298. array(
  5299. 'name' => 'Deluge',
  5300. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5301. 'image' => 'plugins/images/tabs/deluge.png',
  5302. 'category' => 'Downloader',
  5303. 'settings' => array(
  5304. 'custom' => '
  5305. <div class="row">
  5306. <div class="col-lg-12">
  5307. <div class="panel panel-info">
  5308. <div class="panel-heading">
  5309. <span lang="en">Notice</span>
  5310. </div>
  5311. <div class="panel-wrapper collapse in" aria-expanded="true">
  5312. <div class="panel-body">
  5313. <ul class="list-icons">
  5314. <li><i class="fa fa-chevron-right text-danger"></i> <a href="https://github.com/idlesign/deluge-webapi/tree/master/dist" target="_blank">Download Plugin</a></li>
  5315. <li><i class="fa fa-chevron-right text-danger"></i> Open Deluge Web UI, go to "Preferences -> Plugins -> Install plugin" and choose egg file.</li>
  5316. <li><i class="fa fa-chevron-right text-danger"></i> Activate WebAPI plugin </li>
  5317. </ul>
  5318. </div>
  5319. </div>
  5320. </div>
  5321. </div>
  5322. </div>
  5323. ',
  5324. 'Enable' => array(
  5325. array(
  5326. 'type' => 'switch',
  5327. 'name' => 'homepageDelugeEnabled',
  5328. 'label' => 'Enable',
  5329. 'value' => $this->config['homepageDelugeEnabled']
  5330. ),
  5331. array(
  5332. 'type' => 'select',
  5333. 'name' => 'homepageDelugeAuth',
  5334. 'label' => 'Minimum Authentication',
  5335. 'value' => $this->config['homepageDelugeAuth'],
  5336. 'options' => $groups
  5337. )
  5338. ),
  5339. 'Connection' => array(
  5340. array(
  5341. 'type' => 'input',
  5342. 'name' => 'delugeURL',
  5343. 'label' => 'URL',
  5344. 'value' => $this->config['delugeURL'],
  5345. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5346. 'placeholder' => 'http(s)://hostname:port'
  5347. ),
  5348. array(
  5349. 'type' => 'password',
  5350. 'name' => 'delugePassword',
  5351. 'label' => 'Password',
  5352. 'value' => $this->config['delugePassword']
  5353. )
  5354. ),
  5355. 'Misc Options' => array(
  5356. array(
  5357. 'type' => 'switch',
  5358. 'name' => 'delugeHideSeeding',
  5359. 'label' => 'Hide Seeding',
  5360. 'value' => $this->config['delugeHideSeeding']
  5361. ), array(
  5362. 'type' => 'switch',
  5363. 'name' => 'delugeHideCompleted',
  5364. 'label' => 'Hide Completed',
  5365. 'value' => $this->config['delugeHideCompleted']
  5366. ),
  5367. array(
  5368. 'type' => 'select',
  5369. 'name' => 'homepageDownloadRefresh',
  5370. 'label' => 'Refresh Seconds',
  5371. 'value' => $this->config['homepageDownloadRefresh'],
  5372. 'options' => $this->optionTime()
  5373. ),
  5374. array(
  5375. 'type' => 'switch',
  5376. 'name' => 'delugeCombine',
  5377. 'label' => 'Add to Combined Downloader',
  5378. 'value' => $this->config['delugeCombine']
  5379. ),
  5380. ),
  5381. 'Test Connection' => array(
  5382. array(
  5383. 'type' => 'blank',
  5384. 'label' => 'Please Save before Testing'
  5385. ),
  5386. array(
  5387. 'type' => 'button',
  5388. 'label' => '',
  5389. 'icon' => 'fa fa-flask',
  5390. 'class' => 'pull-right',
  5391. 'text' => 'Test Connection',
  5392. 'attr' => 'onclick="testAPIConnection(\'deluge\')"'
  5393. ),
  5394. )
  5395. )
  5396. ),
  5397. array(
  5398. 'name' => 'Sonarr',
  5399. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5400. 'image' => 'plugins/images/tabs/sonarr.png',
  5401. 'category' => 'PVR',
  5402. 'settings' => array(
  5403. 'Enable' => array(
  5404. array(
  5405. 'type' => 'switch',
  5406. 'name' => 'homepageSonarrEnabled',
  5407. 'label' => 'Enable',
  5408. 'value' => $this->config['homepageSonarrEnabled']
  5409. ),
  5410. array(
  5411. 'type' => 'select',
  5412. 'name' => 'homepageSonarrAuth',
  5413. 'label' => 'Minimum Authentication',
  5414. 'value' => $this->config['homepageSonarrAuth'],
  5415. 'options' => $groups
  5416. )
  5417. ),
  5418. 'Connection' => array(
  5419. array(
  5420. 'type' => 'input',
  5421. 'name' => 'sonarrURL',
  5422. 'label' => 'URL',
  5423. 'value' => $this->config['sonarrURL'],
  5424. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5425. 'placeholder' => 'http(s)://hostname:port'
  5426. ),
  5427. array(
  5428. 'type' => 'password-alt',
  5429. 'name' => 'sonarrToken',
  5430. 'label' => 'Token',
  5431. 'value' => $this->config['sonarrToken']
  5432. )
  5433. ),
  5434. 'Queue' => array(
  5435. array(
  5436. 'type' => 'switch',
  5437. 'name' => 'homepageSonarrQueueEnabled',
  5438. 'label' => 'Enable',
  5439. 'value' => $this->config['homepageSonarrQueueEnabled']
  5440. ),
  5441. array(
  5442. 'type' => 'select',
  5443. 'name' => 'homepageSonarrQueueAuth',
  5444. 'label' => 'Minimum Authentication',
  5445. 'value' => $this->config['homepageSonarrQueueAuth'],
  5446. 'options' => $groups
  5447. ),
  5448. array(
  5449. 'type' => 'switch',
  5450. 'name' => 'homepageSonarrQueueCombine',
  5451. 'label' => 'Add to Combined Downloader',
  5452. 'value' => $this->config['homepageSonarrQueueCombine']
  5453. ),
  5454. array(
  5455. 'type' => 'select',
  5456. 'name' => 'homepageSonarrQueueRefresh',
  5457. 'label' => 'Refresh Seconds',
  5458. 'value' => $this->config['homepageSonarrQueueRefresh'],
  5459. 'options' => $this->optionTime()
  5460. ),
  5461. ),
  5462. 'Calendar' => array(
  5463. array(
  5464. 'type' => 'number',
  5465. 'name' => 'calendarStart',
  5466. 'label' => '# of Days Before',
  5467. 'value' => $this->config['calendarStart'],
  5468. 'placeholder' => ''
  5469. ),
  5470. array(
  5471. 'type' => 'number',
  5472. 'name' => 'calendarEnd',
  5473. 'label' => '# of Days After',
  5474. 'value' => $this->config['calendarEnd'],
  5475. 'placeholder' => ''
  5476. ),
  5477. array(
  5478. 'type' => 'select',
  5479. 'name' => 'calendarFirstDay',
  5480. 'label' => 'Start Day',
  5481. 'value' => $this->config['calendarFirstDay'],
  5482. 'options' => $day
  5483. ),
  5484. array(
  5485. 'type' => 'select',
  5486. 'name' => 'calendarDefault',
  5487. 'label' => 'Default View',
  5488. 'value' => $this->config['calendarDefault'],
  5489. 'options' => $calendarDefault
  5490. ),
  5491. array(
  5492. 'type' => 'select',
  5493. 'name' => 'calendarTimeFormat',
  5494. 'label' => 'Time Format',
  5495. 'value' => $this->config['calendarTimeFormat'],
  5496. 'options' => $timeFormat
  5497. ),
  5498. array(
  5499. 'type' => 'select',
  5500. 'name' => 'calendarLimit',
  5501. 'label' => 'Items Per Day',
  5502. 'value' => $this->config['calendarLimit'],
  5503. 'options' => $limit
  5504. ),
  5505. array(
  5506. 'type' => 'select',
  5507. 'name' => 'calendarRefresh',
  5508. 'label' => 'Refresh Seconds',
  5509. 'value' => $this->config['calendarRefresh'],
  5510. 'options' => $this->optionTime()
  5511. ),
  5512. array(
  5513. 'type' => 'switch',
  5514. 'name' => 'sonarrUnmonitored',
  5515. 'label' => 'Show Unmonitored',
  5516. 'value' => $this->config['sonarrUnmonitored']
  5517. )
  5518. ),
  5519. 'Test Connection' => array(
  5520. array(
  5521. 'type' => 'blank',
  5522. 'label' => 'Please Save before Testing'
  5523. ),
  5524. array(
  5525. 'type' => 'button',
  5526. 'label' => '',
  5527. 'icon' => 'fa fa-flask',
  5528. 'class' => 'pull-right',
  5529. 'text' => 'Test Connection',
  5530. 'attr' => 'onclick="testAPIConnection(\'sonarr\')"'
  5531. ),
  5532. )
  5533. )
  5534. ),
  5535. array(
  5536. 'name' => 'Lidarr',
  5537. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5538. 'image' => 'plugins/images/tabs/lidarr.png',
  5539. 'category' => 'PMR',
  5540. 'settings' => array(
  5541. 'Enable' => array(
  5542. array(
  5543. 'type' => 'switch',
  5544. 'name' => 'homepageLidarrEnabled',
  5545. 'label' => 'Enable',
  5546. 'value' => $this->config['homepageLidarrEnabled']
  5547. ),
  5548. array(
  5549. 'type' => 'select',
  5550. 'name' => 'homepageLidarrAuth',
  5551. 'label' => 'Minimum Authentication',
  5552. 'value' => $this->config['homepageLidarrAuth'],
  5553. 'options' => $groups
  5554. )
  5555. ),
  5556. 'Connection' => array(
  5557. array(
  5558. 'type' => 'input',
  5559. 'name' => 'lidarrURL',
  5560. 'label' => 'URL',
  5561. 'value' => $this->config['lidarrURL'],
  5562. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5563. 'placeholder' => 'http(s)://hostname:port'
  5564. ),
  5565. array(
  5566. 'type' => 'password-alt',
  5567. 'name' => 'lidarrToken',
  5568. 'label' => 'Token',
  5569. 'value' => $this->config['lidarrToken']
  5570. )
  5571. ),
  5572. 'Misc Options' => array(
  5573. array(
  5574. 'type' => 'number',
  5575. 'name' => 'calendarStart',
  5576. 'label' => '# of Days Before',
  5577. 'value' => $this->config['calendarStart'],
  5578. 'placeholder' => ''
  5579. ),
  5580. array(
  5581. 'type' => 'number',
  5582. 'name' => 'calendarEnd',
  5583. 'label' => '# of Days After',
  5584. 'value' => $this->config['calendarEnd'],
  5585. 'placeholder' => ''
  5586. ),
  5587. array(
  5588. 'type' => 'select',
  5589. 'name' => 'calendarFirstDay',
  5590. 'label' => 'Start Day',
  5591. 'value' => $this->config['calendarFirstDay'],
  5592. 'options' => $day
  5593. ),
  5594. array(
  5595. 'type' => 'select',
  5596. 'name' => 'calendarDefault',
  5597. 'label' => 'Default View',
  5598. 'value' => $this->config['calendarDefault'],
  5599. 'options' => $calendarDefault
  5600. ),
  5601. array(
  5602. 'type' => 'select',
  5603. 'name' => 'calendarTimeFormat',
  5604. 'label' => 'Time Format',
  5605. 'value' => $this->config['calendarTimeFormat'],
  5606. 'options' => $timeFormat
  5607. ),
  5608. array(
  5609. 'type' => 'select',
  5610. 'name' => 'calendarLimit',
  5611. 'label' => 'Items Per Day',
  5612. 'value' => $this->config['calendarLimit'],
  5613. 'options' => $limit
  5614. ),
  5615. array(
  5616. 'type' => 'select',
  5617. 'name' => 'calendarRefresh',
  5618. 'label' => 'Refresh Seconds',
  5619. 'value' => $this->config['calendarRefresh'],
  5620. 'options' => $this->optionTime()
  5621. ),
  5622. ),
  5623. 'Test Connection' => array(
  5624. array(
  5625. 'type' => 'blank',
  5626. 'label' => 'Please Save before Testing'
  5627. ),
  5628. array(
  5629. 'type' => 'button',
  5630. 'label' => '',
  5631. 'icon' => 'fa fa-flask',
  5632. 'class' => 'pull-right',
  5633. 'text' => 'Test Connection',
  5634. 'attr' => 'onclick="testAPIConnection(\'lidarr\')"'
  5635. ),
  5636. )
  5637. )
  5638. ),
  5639. array(
  5640. 'name' => 'Radarr',
  5641. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5642. 'image' => 'plugins/images/tabs/radarr.png',
  5643. 'category' => 'PVR',
  5644. 'settings' => array(
  5645. 'Enable' => array(
  5646. array(
  5647. 'type' => 'switch',
  5648. 'name' => 'homepageRadarrEnabled',
  5649. 'label' => 'Enable',
  5650. 'value' => $this->config['homepageRadarrEnabled']
  5651. ),
  5652. array(
  5653. 'type' => 'select',
  5654. 'name' => 'homepageRadarrAuth',
  5655. 'label' => 'Minimum Authentication',
  5656. 'value' => $this->config['homepageRadarrAuth'],
  5657. 'options' => $groups
  5658. )
  5659. ),
  5660. 'Connection' => array(
  5661. array(
  5662. 'type' => 'input',
  5663. 'name' => 'radarrURL',
  5664. 'label' => 'URL',
  5665. 'value' => $this->config['radarrURL'],
  5666. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5667. 'placeholder' => 'http(s)://hostname:port'
  5668. ),
  5669. array(
  5670. 'type' => 'password-alt',
  5671. 'name' => 'radarrToken',
  5672. 'label' => 'Token',
  5673. 'value' => $this->config['radarrToken']
  5674. )
  5675. ),
  5676. 'Queue' => array(
  5677. array(
  5678. 'type' => 'switch',
  5679. 'name' => 'homepageRadarrQueueEnabled',
  5680. 'label' => 'Enable',
  5681. 'value' => $this->config['homepageRadarrQueueEnabled']
  5682. ),
  5683. array(
  5684. 'type' => 'select',
  5685. 'name' => 'homepageRadarrQueueAuth',
  5686. 'label' => 'Minimum Authentication',
  5687. 'value' => $this->config['homepageRadarrQueueAuth'],
  5688. 'options' => $groups
  5689. ),
  5690. array(
  5691. 'type' => 'switch',
  5692. 'name' => 'homepageRadarrQueueCombine',
  5693. 'label' => 'Add to Combined Downloader',
  5694. 'value' => $this->config['homepageRadarrQueueCombine']
  5695. ),
  5696. array(
  5697. 'type' => 'select',
  5698. 'name' => 'homepageRadarrQueueRefresh',
  5699. 'label' => 'Refresh Seconds',
  5700. 'value' => $this->config['homepageRadarrQueueRefresh'],
  5701. 'options' => $this->optionTime()
  5702. ),
  5703. ),
  5704. 'Calendar' => array(
  5705. array(
  5706. 'type' => 'number',
  5707. 'name' => 'calendarStart',
  5708. 'label' => '# of Days Before',
  5709. 'value' => $this->config['calendarStart'],
  5710. 'placeholder' => ''
  5711. ),
  5712. array(
  5713. 'type' => 'number',
  5714. 'name' => 'calendarEnd',
  5715. 'label' => '# of Days After',
  5716. 'value' => $this->config['calendarEnd'],
  5717. 'placeholder' => ''
  5718. ),
  5719. array(
  5720. 'type' => 'select',
  5721. 'name' => 'calendarFirstDay',
  5722. 'label' => 'Start Day',
  5723. 'value' => $this->config['calendarFirstDay'],
  5724. 'options' => $day
  5725. ),
  5726. array(
  5727. 'type' => 'select',
  5728. 'name' => 'calendarDefault',
  5729. 'label' => 'Default View',
  5730. 'value' => $this->config['calendarDefault'],
  5731. 'options' => $calendarDefault
  5732. ),
  5733. array(
  5734. 'type' => 'select',
  5735. 'name' => 'calendarTimeFormat',
  5736. 'label' => 'Time Format',
  5737. 'value' => $this->config['calendarTimeFormat'],
  5738. 'options' => $timeFormat
  5739. ),
  5740. array(
  5741. 'type' => 'select',
  5742. 'name' => 'calendarLimit',
  5743. 'label' => 'Items Per Day',
  5744. 'value' => $this->config['calendarLimit'],
  5745. 'options' => $limit
  5746. ),
  5747. array(
  5748. 'type' => 'select',
  5749. 'name' => 'calendarRefresh',
  5750. 'label' => 'Refresh Seconds',
  5751. 'value' => $this->config['calendarRefresh'],
  5752. 'options' => $this->optionTime()
  5753. )
  5754. ),
  5755. 'Test Connection' => array(
  5756. array(
  5757. 'type' => 'blank',
  5758. 'label' => 'Please Save before Testing'
  5759. ),
  5760. array(
  5761. 'type' => 'button',
  5762. 'label' => '',
  5763. 'icon' => 'fa fa-flask',
  5764. 'class' => 'pull-right',
  5765. 'text' => 'Test Connection',
  5766. 'attr' => 'onclick="testAPIConnection(\'radarr\')"'
  5767. ),
  5768. )
  5769. )
  5770. ),
  5771. array(
  5772. 'name' => 'CouchPotato',
  5773. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5774. 'image' => 'plugins/images/tabs/couchpotato.png',
  5775. 'category' => 'PVR',
  5776. 'settings' => array(
  5777. 'Enable' => array(
  5778. array(
  5779. 'type' => 'switch',
  5780. 'name' => 'homepageCouchpotatoEnabled',
  5781. 'label' => 'Enable',
  5782. 'value' => $this->config['homepageCouchpotatoEnabled']
  5783. ),
  5784. array(
  5785. 'type' => 'select',
  5786. 'name' => 'homepageCouchpotatoAuth',
  5787. 'label' => 'Minimum Authentication',
  5788. 'value' => $this->config['homepageCouchpotatoAuth'],
  5789. 'options' => $groups
  5790. )
  5791. ),
  5792. 'Connection' => array(
  5793. array(
  5794. 'type' => 'input',
  5795. 'name' => 'couchpotatoURL',
  5796. 'label' => 'URL',
  5797. 'value' => $this->config['couchpotatoURL'],
  5798. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5799. 'placeholder' => 'http(s)://hostname:port'
  5800. ),
  5801. array(
  5802. 'type' => 'password-alt',
  5803. 'name' => 'couchpotatoToken',
  5804. 'label' => 'Token',
  5805. 'value' => $this->config['couchpotatoToken']
  5806. )
  5807. ),
  5808. 'Misc Options' => array(
  5809. array(
  5810. 'type' => 'select',
  5811. 'name' => 'calendarFirstDay',
  5812. 'label' => 'Start Day',
  5813. 'value' => $this->config['calendarFirstDay'],
  5814. 'options' => $day
  5815. ),
  5816. array(
  5817. 'type' => 'select',
  5818. 'name' => 'calendarDefault',
  5819. 'label' => 'Default View',
  5820. 'value' => $this->config['calendarDefault'],
  5821. 'options' => $calendarDefault
  5822. ),
  5823. array(
  5824. 'type' => 'select',
  5825. 'name' => 'calendarTimeFormat',
  5826. 'label' => 'Time Format',
  5827. 'value' => $this->config['calendarTimeFormat'],
  5828. 'options' => $timeFormat
  5829. ),
  5830. array(
  5831. 'type' => 'select',
  5832. 'name' => 'calendarLimit',
  5833. 'label' => 'Items Per Day',
  5834. 'value' => $this->config['calendarLimit'],
  5835. 'options' => $limit
  5836. ),
  5837. array(
  5838. 'type' => 'select',
  5839. 'name' => 'calendarRefresh',
  5840. 'label' => 'Refresh Seconds',
  5841. 'value' => $this->config['calendarRefresh'],
  5842. 'options' => $this->optionTime()
  5843. )
  5844. )
  5845. )
  5846. ),
  5847. array(
  5848. 'name' => 'SickRage',
  5849. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5850. 'image' => 'plugins/images/tabs/sickrage.png',
  5851. 'category' => 'PVR',
  5852. 'settings' => array(
  5853. 'Enable' => array(
  5854. array(
  5855. 'type' => 'switch',
  5856. 'name' => 'homepageSickrageEnabled',
  5857. 'label' => 'Enable',
  5858. 'value' => $this->config['homepageSickrageEnabled']
  5859. ),
  5860. array(
  5861. 'type' => 'select',
  5862. 'name' => 'homepageSickrageAuth',
  5863. 'label' => 'Minimum Authentication',
  5864. 'value' => $this->config['homepageSickrageAuth'],
  5865. 'options' => $groups
  5866. )
  5867. ),
  5868. 'Connection' => array(
  5869. array(
  5870. 'type' => 'input',
  5871. 'name' => 'sickrageURL',
  5872. 'label' => 'URL',
  5873. 'value' => $this->config['sickrageURL'],
  5874. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5875. 'placeholder' => 'http(s)://hostname:port'
  5876. ),
  5877. array(
  5878. 'type' => 'password-alt',
  5879. 'name' => 'sickrageToken',
  5880. 'label' => 'Token',
  5881. 'value' => $this->config['sickrageToken']
  5882. )
  5883. ),
  5884. 'Misc Options' => array(
  5885. array(
  5886. 'type' => 'select',
  5887. 'name' => 'calendarFirstDay',
  5888. 'label' => 'Start Day',
  5889. 'value' => $this->config['calendarFirstDay'],
  5890. 'options' => $day
  5891. ),
  5892. array(
  5893. 'type' => 'select',
  5894. 'name' => 'calendarDefault',
  5895. 'label' => 'Default View',
  5896. 'value' => $this->config['calendarDefault'],
  5897. 'options' => $calendarDefault
  5898. ),
  5899. array(
  5900. 'type' => 'select',
  5901. 'name' => 'calendarTimeFormat',
  5902. 'label' => 'Time Format',
  5903. 'value' => $this->config['calendarTimeFormat'],
  5904. 'options' => $timeFormat
  5905. ),
  5906. array(
  5907. 'type' => 'select',
  5908. 'name' => 'calendarLimit',
  5909. 'label' => 'Items Per Day',
  5910. 'value' => $this->config['calendarLimit'],
  5911. 'options' => $limit
  5912. ),
  5913. array(
  5914. 'type' => 'select',
  5915. 'name' => 'calendarRefresh',
  5916. 'label' => 'Refresh Seconds',
  5917. 'value' => $this->config['calendarRefresh'],
  5918. 'options' => $this->optionTime()
  5919. )
  5920. ),
  5921. 'Test Connection' => array(
  5922. array(
  5923. 'type' => 'blank',
  5924. 'label' => 'Please Save before Testing'
  5925. ),
  5926. array(
  5927. 'type' => 'button',
  5928. 'label' => '',
  5929. 'icon' => 'fa fa-flask',
  5930. 'class' => 'pull-right',
  5931. 'text' => 'Test Connection',
  5932. 'attr' => 'onclick="testAPIConnection(\'sickrage\')"'
  5933. ),
  5934. )
  5935. )
  5936. ),
  5937. array(
  5938. 'name' => 'Ombi',
  5939. 'enabled' => strpos('personal', $this->config['license']) !== false,
  5940. 'image' => 'plugins/images/tabs/ombi.png',
  5941. 'category' => 'Requests',
  5942. 'settings' => array(
  5943. 'Enable' => array(
  5944. array(
  5945. 'type' => 'switch',
  5946. 'name' => 'homepageOmbiEnabled',
  5947. 'label' => 'Enable',
  5948. 'value' => $this->config['homepageOmbiEnabled']
  5949. ),
  5950. array(
  5951. 'type' => 'select',
  5952. 'name' => 'homepageOmbiAuth',
  5953. 'label' => 'Minimum Authentication',
  5954. 'value' => $this->config['homepageOmbiAuth'],
  5955. 'options' => $groups
  5956. )
  5957. ),
  5958. 'Connection' => array(
  5959. array(
  5960. 'type' => 'input',
  5961. 'name' => 'ombiURL',
  5962. 'label' => 'URL',
  5963. 'value' => $this->config['ombiURL'],
  5964. 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
  5965. 'placeholder' => 'http(s)://hostname:port'
  5966. ),
  5967. array(
  5968. 'type' => 'password-alt',
  5969. 'name' => 'ombiToken',
  5970. 'label' => 'Token',
  5971. 'value' => $this->config['ombiToken']
  5972. )
  5973. ),
  5974. 'Misc Options' => array(
  5975. array(
  5976. 'type' => 'select',
  5977. 'name' => 'homepageOmbiRequestAuth',
  5978. 'label' => 'Minimum Group to Request',
  5979. 'value' => $this->config['homepageOmbiRequestAuth'],
  5980. 'options' => $groups
  5981. ),
  5982. array(
  5983. 'type' => 'select',
  5984. 'name' => 'ombiTvDefault',
  5985. 'label' => 'TV Show Default Request',
  5986. 'value' => $this->config['ombiTvDefault'],
  5987. 'options' => $ombiTvOptions
  5988. ),
  5989. array(
  5990. 'type' => 'switch',
  5991. 'name' => 'ombiLimitUser',
  5992. 'label' => 'Limit to User',
  5993. 'value' => $this->config['ombiLimitUser']
  5994. ),
  5995. array(
  5996. 'type' => 'number',
  5997. 'name' => 'ombiLimit',
  5998. 'label' => 'Item Limit',
  5999. 'value' => $this->config['ombiLimit'],
  6000. ),
  6001. array(
  6002. 'type' => 'select',
  6003. 'name' => 'ombiRefresh',
  6004. 'label' => 'Refresh Seconds',
  6005. 'value' => $this->config['ombiRefresh'],
  6006. 'options' => $this->optionTime()
  6007. ),
  6008. array(
  6009. 'type' => 'switch',
  6010. 'name' => 'ombiAlias',
  6011. 'label' => 'Use Ombi Alias Names',
  6012. 'value' => $this->config['ombiAlias'],
  6013. 'help' => 'Use Ombi Alias Names instead of Usernames - If Alias is blank, Alias will fallback to Username'
  6014. )
  6015. ),
  6016. 'Default Filter' => array(
  6017. array(
  6018. 'type' => 'switch',
  6019. 'name' => 'ombiDefaultFilterAvailable',
  6020. 'label' => 'Show Available',
  6021. 'value' => $this->config['ombiDefaultFilterAvailable'],
  6022. 'help' => 'Show All Available Ombi Requests'
  6023. ),
  6024. array(
  6025. 'type' => 'switch',
  6026. 'name' => 'ombiDefaultFilterUnavailable',
  6027. 'label' => 'Show Unavailable',
  6028. 'value' => $this->config['ombiDefaultFilterUnavailable'],
  6029. 'help' => 'Show All Unavailable Ombi Requests'
  6030. ),
  6031. array(
  6032. 'type' => 'switch',
  6033. 'name' => 'ombiDefaultFilterApproved',
  6034. 'label' => 'Show Approved',
  6035. 'value' => $this->config['ombiDefaultFilterApproved'],
  6036. 'help' => 'Show All Approved Ombi Requests'
  6037. ),
  6038. array(
  6039. 'type' => 'switch',
  6040. 'name' => 'ombiDefaultFilterUnapproved',
  6041. 'label' => 'Show Unapproved',
  6042. 'value' => $this->config['ombiDefaultFilterUnapproved'],
  6043. 'help' => 'Show All Unapproved Ombi Requests'
  6044. ),
  6045. array(
  6046. 'type' => 'switch',
  6047. 'name' => 'ombiDefaultFilterDenied',
  6048. 'label' => 'Show Denied',
  6049. 'value' => $this->config['ombiDefaultFilterDenied'],
  6050. 'help' => 'Show All Denied Ombi Requests'
  6051. )
  6052. ),
  6053. 'Test Connection' => array(
  6054. array(
  6055. 'type' => 'blank',
  6056. 'label' => 'Please Save before Testing'
  6057. ),
  6058. array(
  6059. 'type' => 'button',
  6060. 'label' => '',
  6061. 'icon' => 'fa fa-flask',
  6062. 'class' => 'pull-right',
  6063. 'text' => 'Test Connection',
  6064. 'attr' => 'onclick="testAPIConnection(\'ombi\')"'
  6065. ),
  6066. )
  6067. )
  6068. ),
  6069. array(
  6070. 'name' => 'Unifi',
  6071. 'enabled' => true,
  6072. 'image' => 'plugins/images/tabs/ubnt.png',
  6073. 'category' => 'Monitor',
  6074. 'settings' => array(
  6075. 'Enable' => array(
  6076. array(
  6077. 'type' => 'switch',
  6078. 'name' => 'homepageUnifiEnabled',
  6079. 'label' => 'Enable',
  6080. 'value' => $this->config['homepageUnifiEnabled']
  6081. ),
  6082. array(
  6083. 'type' => 'select',
  6084. 'name' => 'homepageUnifiAuth',
  6085. 'label' => 'Minimum Authentication',
  6086. 'value' => $this->config['homepageUnifiAuth'],
  6087. 'options' => $groups
  6088. )
  6089. ),
  6090. 'Connection' => array(
  6091. array(
  6092. 'type' => 'input',
  6093. 'name' => 'unifiURL',
  6094. 'label' => 'URL',
  6095. 'value' => $this->config['unifiURL'],
  6096. 'help' => 'URL for Unifi',
  6097. 'placeholder' => 'Unifi API URL'
  6098. ),
  6099. array(
  6100. 'type' => 'blank',
  6101. 'label' => ''
  6102. ),
  6103. array(
  6104. 'type' => 'input',
  6105. 'name' => 'unifiUsername',
  6106. 'label' => 'Username',
  6107. 'value' => $this->config['unifiUsername'],
  6108. 'help' => 'Username is case-sensitive',
  6109. ),
  6110. array(
  6111. 'type' => 'password',
  6112. 'name' => 'unifiPassword',
  6113. 'label' => 'Password',
  6114. 'value' => $this->config['unifiPassword']
  6115. ),
  6116. array(
  6117. 'type' => 'input',
  6118. 'name' => 'unifiSiteName',
  6119. 'label' => 'Site Name (Not for UnifiOS)',
  6120. 'value' => $this->config['unifiSiteName'],
  6121. 'help' => 'Site Name - not Site ID nor Site Description',
  6122. ),
  6123. array(
  6124. 'type' => 'button',
  6125. 'label' => 'Grab Unifi Site (Not for UnifiOS)',
  6126. 'icon' => 'fa fa-building',
  6127. 'text' => 'Get Unifi Site',
  6128. 'attr' => 'onclick="getUnifiSite()"'
  6129. ),
  6130. ),
  6131. 'Misc Options' => array(
  6132. array(
  6133. 'type' => 'select',
  6134. 'name' => 'homepageUnifiRefresh',
  6135. 'label' => 'Refresh Seconds',
  6136. 'value' => $this->config['homepageUnifiRefresh'],
  6137. 'options' => $this->optionTime()
  6138. ),
  6139. ),
  6140. 'Test Connection' => array(
  6141. array(
  6142. 'type' => 'blank',
  6143. 'label' => 'Please Save before Testing'
  6144. ),
  6145. array(
  6146. 'type' => 'button',
  6147. 'label' => '',
  6148. 'icon' => 'fa fa-flask',
  6149. 'class' => 'pull-right',
  6150. 'text' => 'Test Connection',
  6151. 'attr' => 'onclick="testAPIConnection(\'unifi\')"'
  6152. ),
  6153. )
  6154. )
  6155. ),
  6156. array(
  6157. 'name' => 'HealthChecks',
  6158. 'enabled' => true,
  6159. 'image' => 'plugins/images/tabs/healthchecks.png',
  6160. 'category' => 'Monitor',
  6161. 'settings' => array(
  6162. 'Enable' => array(
  6163. array(
  6164. 'type' => 'switch',
  6165. 'name' => 'homepageHealthChecksEnabled',
  6166. 'label' => 'Enable',
  6167. 'value' => $this->config['homepageHealthChecksEnabled']
  6168. ),
  6169. array(
  6170. 'type' => 'select',
  6171. 'name' => 'homepageHealthChecksAuth',
  6172. 'label' => 'Minimum Authentication',
  6173. 'value' => $this->config['homepageHealthChecksAuth'],
  6174. 'options' => $groups
  6175. )
  6176. ),
  6177. 'Connection' => array(
  6178. array(
  6179. 'type' => 'input',
  6180. 'name' => 'healthChecksURL',
  6181. 'label' => 'URL',
  6182. 'value' => $this->config['healthChecksURL'],
  6183. 'help' => 'URL for HealthChecks API',
  6184. 'placeholder' => 'HealthChecks API URL'
  6185. ),
  6186. array(
  6187. 'type' => 'password-alt',
  6188. 'name' => 'healthChecksToken',
  6189. 'label' => 'Token',
  6190. 'value' => $this->config['healthChecksToken']
  6191. )
  6192. ),
  6193. 'Misc Options' => array(
  6194. array(
  6195. 'type' => 'input',
  6196. 'name' => 'healthChecksTags',
  6197. 'label' => 'Tags',
  6198. 'value' => $this->config['healthChecksTags'],
  6199. 'help' => 'Pull only checks with this tag - Blank for all',
  6200. 'placeholder' => 'Multiple tags using CSV - tag1,tag2'
  6201. ),
  6202. array(
  6203. 'type' => 'select',
  6204. 'name' => 'homepageHealthChecksRefresh',
  6205. 'label' => 'Refresh Seconds',
  6206. 'value' => $this->config['homepageHealthChecksRefresh'],
  6207. 'options' => $this->optionTime()
  6208. ),
  6209. ),
  6210. )
  6211. ),
  6212. array(
  6213. 'name' => 'CustomHTML-1',
  6214. 'enabled' => strpos('personal,business', $this->config['license']) !== false,
  6215. 'image' => 'plugins/images/tabs/custom1.png',
  6216. 'category' => 'Custom',
  6217. 'settings' => array(
  6218. 'Enable' => array(
  6219. array(
  6220. 'type' => 'switch',
  6221. 'name' => 'homepageCustomHTMLoneEnabled',
  6222. 'label' => 'Enable',
  6223. 'value' => $this->config['homepageCustomHTMLoneEnabled']
  6224. ),
  6225. array(
  6226. 'type' => 'select',
  6227. 'name' => 'homepageCustomHTMLoneAuth',
  6228. 'label' => 'Minimum Authentication',
  6229. 'value' => $this->config['homepageCustomHTMLoneAuth'],
  6230. 'options' => $groups
  6231. )
  6232. ),
  6233. 'Code' => array(
  6234. array(
  6235. 'type' => 'textbox',
  6236. 'name' => 'customHTMLone',
  6237. 'class' => 'hidden customHTMLoneTextarea',
  6238. 'label' => '',
  6239. 'value' => $this->config['customHTMLone'],
  6240. ),
  6241. array(
  6242. 'type' => 'html',
  6243. 'override' => 12,
  6244. 'label' => 'Custom HTML/JavaScript',
  6245. 'html' => '<button type="button" class="hidden savecustomHTMLoneTextarea btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customHTMLoneEditor" style="height:300px">' . htmlentities($this->config['customHTMLone']) . '</div>'
  6246. ),
  6247. )
  6248. )
  6249. ),
  6250. array(
  6251. 'name' => 'CustomHTML-2',
  6252. 'enabled' => strpos('personal,business', $this->config['license']) !== false,
  6253. 'image' => 'plugins/images/tabs/custom2.png',
  6254. 'category' => 'Custom',
  6255. 'settings' => array(
  6256. 'Enable' => array(
  6257. array(
  6258. 'type' => 'switch',
  6259. 'name' => 'homepageCustomHTMLtwoEnabled',
  6260. 'label' => 'Enable',
  6261. 'value' => $this->config['homepageCustomHTMLtwoEnabled']
  6262. ),
  6263. array(
  6264. 'type' => 'select',
  6265. 'name' => 'homepageCustomHTMLtwoAuth',
  6266. 'label' => 'Minimum Authentication',
  6267. 'value' => $this->config['homepageCustomHTMLtwoAuth'],
  6268. 'options' => $groups
  6269. )
  6270. ),
  6271. 'Code' => array(
  6272. array(
  6273. 'type' => 'textbox',
  6274. 'name' => 'customHTMLtwo',
  6275. 'class' => 'hidden customHTMLtwoTextarea',
  6276. 'label' => '',
  6277. 'value' => $this->config['customHTMLtwo'],
  6278. ),
  6279. array(
  6280. 'type' => 'html',
  6281. 'override' => 12,
  6282. 'label' => 'Custom HTML/JavaScript',
  6283. 'html' => '<button type="button" class="hidden savecustomHTMLtwoTextarea btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customHTMLtwoEditor" style="height:300px">' . htmlentities($this->config['customHTMLtwo']) . '</div>'
  6284. ),
  6285. )
  6286. )
  6287. ),
  6288. array(
  6289. 'name' => 'Misc',
  6290. 'enabled' => true,
  6291. 'image' => 'plugins/images/organizr/logo-no-border.png',
  6292. 'category' => 'Custom',
  6293. 'settings' => array(
  6294. 'YouTube' => array(
  6295. array(
  6296. 'type' => 'input',
  6297. 'name' => 'youtubeAPI',
  6298. 'label' => 'Youtube API Key',
  6299. 'value' => $this->config['youtubeAPI'],
  6300. 'help' => 'Please make sure to input this API key as the organizr one gets limited'
  6301. ),
  6302. array(
  6303. 'type' => 'html',
  6304. 'override' => 6,
  6305. 'label' => 'Instructions',
  6306. 'html' => '<a href="https://www.slickremix.com/docs/get-api-key-for-youtube/" target="_blank">Click here for instructions</a>'
  6307. ),
  6308. )
  6309. )
  6310. ),
  6311. array(
  6312. 'name' => 'Pi-hole',
  6313. 'enabled' => true,
  6314. 'image' => 'plugins/images/tabs/pihole.png',
  6315. 'category' => 'Monitor',
  6316. 'settings' => array(
  6317. 'Enable' => array(
  6318. array(
  6319. 'type' => 'switch',
  6320. 'name' => 'homepagePiholeEnabled',
  6321. 'label' => 'Enable',
  6322. 'value' => $this->config['homepagePiholeEnabled']
  6323. ),
  6324. array(
  6325. 'type' => 'select',
  6326. 'name' => 'homepagePiholeAuth',
  6327. 'label' => 'Minimum Authentication',
  6328. 'value' => $this->config['homepagePiholeAuth'],
  6329. 'options' => $groups
  6330. )
  6331. ),
  6332. 'Connection' => array(
  6333. array(
  6334. 'type' => 'input',
  6335. 'name' => 'piholeURL',
  6336. 'label' => 'URL',
  6337. 'value' => $this->config['piholeURL'],
  6338. 'help' => 'Please make sure to use local IP address and port and to include \'/admin/\' at the end of the URL. You can add multiple Pi-holes by comma separating the URLs.',
  6339. 'placeholder' => 'http(s)://hostname:port/admin/'
  6340. ),
  6341. ),
  6342. 'Misc' => array(
  6343. array(
  6344. 'type' => 'switch',
  6345. 'name' => 'piholeHeaderToggle',
  6346. 'label' => 'Toggle Title',
  6347. 'value' => $this->config['piholeHeaderToggle'],
  6348. 'help' => 'Shows/hides the title of this homepage module'
  6349. ),
  6350. array(
  6351. 'type' => 'switch',
  6352. 'name' => 'homepagePiholeCombine',
  6353. 'label' => 'Combine stat cards',
  6354. 'value' => $this->config['homepagePiholeCombine'],
  6355. 'help' => 'This controls whether to combine the stats for multiple pihole instances into 1 card.',
  6356. ),
  6357. ),
  6358. 'Test Connection' => array(
  6359. array(
  6360. 'type' => 'blank',
  6361. 'label' => 'Please Save before Testing'
  6362. ),
  6363. array(
  6364. 'type' => 'button',
  6365. 'label' => '',
  6366. 'icon' => 'fa fa-flask',
  6367. 'class' => 'pull-right',
  6368. 'text' => 'Test Connection',
  6369. 'attr' => 'onclick="testAPIConnection(\'pihole\')"'
  6370. ),
  6371. )
  6372. )
  6373. ),
  6374. array(
  6375. 'name' => 'Tautulli',
  6376. 'enabled' => strpos('personal', $this->config['license']) !== false,
  6377. 'image' => 'plugins/images/tabs/tautulli.png',
  6378. 'category' => 'Monitor',
  6379. 'settings' => array(
  6380. 'Enable' => array(
  6381. array(
  6382. 'type' => 'switch',
  6383. 'name' => 'homepageTautulliEnabled',
  6384. 'label' => 'Enable',
  6385. 'value' => $this->config['homepageTautulliEnabled']
  6386. ),
  6387. array(
  6388. 'type' => 'select',
  6389. 'name' => 'homepageTautulliAuth',
  6390. 'label' => 'Minimum Authentication',
  6391. 'value' => $this->config['homepageTautulliAuth'],
  6392. 'options' => $groups
  6393. )
  6394. ),
  6395. 'Options' => array(
  6396. array(
  6397. 'type' => 'input',
  6398. 'name' => 'tautulliHeader',
  6399. 'label' => 'Title',
  6400. 'value' => $this->config['tautulliHeader'],
  6401. 'help' => 'Sets the title of this homepage module'
  6402. ),
  6403. array(
  6404. 'type' => 'switch',
  6405. 'name' => 'tautulliHeaderToggle',
  6406. 'label' => 'Toggle Title',
  6407. 'value' => $this->config['tautulliHeaderToggle'],
  6408. 'help' => 'Shows/hides the title of this homepage module'
  6409. )
  6410. ),
  6411. 'Connection' => array(
  6412. array(
  6413. 'type' => 'input',
  6414. 'name' => 'tautulliURL',
  6415. 'label' => 'URL',
  6416. 'value' => $this->config['tautulliURL'],
  6417. 'help' => 'URL for Tautulli API, include the IP, the port and the base URL (e.g. /tautulli/) in the URL',
  6418. 'placeholder' => 'http://<ip>:<port>'
  6419. ),
  6420. array(
  6421. 'type' => 'password-alt',
  6422. 'name' => 'tautulliApikey',
  6423. 'label' => 'API Key',
  6424. 'value' => $this->config['tautulliApikey']
  6425. ),
  6426. array(
  6427. 'type' => 'select',
  6428. 'name' => 'homepageTautulliRefresh',
  6429. 'label' => 'Refresh Seconds',
  6430. 'value' => $this->config['homepageTautulliRefresh'],
  6431. 'options' => $this->optionTime()
  6432. ),
  6433. ),
  6434. 'Library Stats' => array(
  6435. array(
  6436. 'type' => 'switch',
  6437. 'name' => 'tautulliLibraries',
  6438. 'label' => 'Libraries',
  6439. 'value' => $this->config['tautulliLibraries'],
  6440. 'help' => 'Shows/hides the card with library information.',
  6441. ),
  6442. array(
  6443. 'type' => 'select',
  6444. 'name' => 'homepageTautulliLibraryAuth',
  6445. 'label' => 'Minimum Authentication',
  6446. 'value' => $this->config['homepageTautulliLibraryAuth'],
  6447. 'options' => $groups
  6448. ),
  6449. ),
  6450. 'Viewing Stats' => array(
  6451. array(
  6452. 'type' => 'switch',
  6453. 'name' => 'tautulliPopularMovies',
  6454. 'label' => 'Popular Movies',
  6455. 'value' => $this->config['tautulliPopularMovies'],
  6456. 'help' => 'Shows/hides the card with Popular Movies information.',
  6457. ),
  6458. array(
  6459. 'type' => 'switch',
  6460. 'name' => 'tautulliPopularTV',
  6461. 'label' => 'Popular TV',
  6462. 'value' => $this->config['tautulliPopularTV'],
  6463. 'help' => 'Shows/hides the card with Popular TV information.',
  6464. ),
  6465. array(
  6466. 'type' => 'switch',
  6467. 'name' => 'tautulliTopMovies',
  6468. 'label' => 'Top Movies',
  6469. 'value' => $this->config['tautulliTopMovies'],
  6470. 'help' => 'Shows/hides the card with Top Movies information.',
  6471. ),
  6472. array(
  6473. 'type' => 'switch',
  6474. 'name' => 'tautulliTopTV',
  6475. 'label' => 'Top TV',
  6476. 'value' => $this->config['tautulliTopTV'],
  6477. 'help' => 'Shows/hides the card with Top TV information.',
  6478. ),
  6479. array(
  6480. 'type' => 'select',
  6481. 'name' => 'homepageTautulliViewsAuth',
  6482. 'label' => 'Minimum Authentication',
  6483. 'value' => $this->config['homepageTautulliViewsAuth'],
  6484. 'options' => $groups
  6485. ),
  6486. ),
  6487. 'Misc Stats' => array(
  6488. array(
  6489. 'type' => 'switch',
  6490. 'name' => 'tautulliTopUsers',
  6491. 'label' => 'Top Users',
  6492. 'value' => $this->config['tautulliTopUsers'],
  6493. 'help' => 'Shows/hides the card with Top Users information.',
  6494. ),
  6495. array(
  6496. 'type' => 'switch',
  6497. 'name' => 'tautulliTopPlatforms',
  6498. 'label' => 'Top Platforms',
  6499. 'value' => $this->config['tautulliTopPlatforms'],
  6500. 'help' => 'Shows/hides the card with Top Platforms information.',
  6501. ),
  6502. array(
  6503. 'type' => 'select',
  6504. 'name' => 'homepageTautulliMiscAuth',
  6505. 'label' => 'Minimum Authentication',
  6506. 'value' => $this->config['homepageTautulliMiscAuth'],
  6507. 'options' => $groups
  6508. ),
  6509. ),
  6510. 'Test Connection' => array(
  6511. array(
  6512. 'type' => 'blank',
  6513. 'label' => 'Please Save before Testing'
  6514. ),
  6515. array(
  6516. 'type' => 'button',
  6517. 'label' => '',
  6518. 'icon' => 'fa fa-flask',
  6519. 'class' => 'pull-right',
  6520. 'text' => 'Test Connection',
  6521. 'attr' => 'onclick="testAPIConnection(\'tautulli\')"'
  6522. ),
  6523. )
  6524. )
  6525. ),
  6526. array(
  6527. 'name' => 'Monitorr',
  6528. 'enabled' => true,
  6529. 'image' => 'plugins/images/tabs/monitorr.png',
  6530. 'category' => 'Monitor',
  6531. 'settings' => array(
  6532. 'Enable' => array(
  6533. array(
  6534. 'type' => 'switch',
  6535. 'name' => 'homepageMonitorrEnabled',
  6536. 'label' => 'Enable',
  6537. 'value' => $this->config['homepageMonitorrEnabled']
  6538. ),
  6539. array(
  6540. 'type' => 'select',
  6541. 'name' => 'homepageMonitorrAuth',
  6542. 'label' => 'Minimum Authentication',
  6543. 'value' => $this->config['homepageMonitorrAuth'],
  6544. 'options' => $groups
  6545. )
  6546. ),
  6547. 'Connection' => array(
  6548. array(
  6549. 'type' => 'input',
  6550. 'name' => 'monitorrURL',
  6551. 'label' => 'URL',
  6552. 'value' => $this->config['monitorrURL'],
  6553. 'help' => 'URL for Monitorr. Please use the revers proxy URL i.e. https://domain.com/monitorr/.',
  6554. 'placeholder' => 'http://domain.com/monitorr/'
  6555. ),
  6556. array(
  6557. 'type' => 'select',
  6558. 'name' => 'homepageMonitorrRefresh',
  6559. 'label' => 'Refresh Seconds',
  6560. 'value' => $this->config['homepageMonitorrRefresh'],
  6561. 'options' => $this->optionTime()
  6562. ),
  6563. ),
  6564. 'Options' => array(
  6565. array(
  6566. 'type' => 'input',
  6567. 'name' => 'monitorrHeader',
  6568. 'label' => 'Title',
  6569. 'value' => $this->config['monitorrHeader'],
  6570. 'help' => 'Sets the title of this homepage module',
  6571. ),
  6572. array(
  6573. 'type' => 'switch',
  6574. 'name' => 'monitorrHeaderToggle',
  6575. 'label' => 'Toggle Title',
  6576. 'value' => $this->config['monitorrHeaderToggle'],
  6577. 'help' => 'Shows/hides the title of this homepage module'
  6578. ),
  6579. array(
  6580. 'type' => 'switch',
  6581. 'name' => 'monitorrCompact',
  6582. 'label' => 'Compact view',
  6583. 'value' => $this->config['monitorrCompact'],
  6584. 'help' => 'Toggles the compact view of this homepage module'
  6585. ),
  6586. ),
  6587. )
  6588. ),
  6589. array(
  6590. 'name' => 'Weather-Air',
  6591. 'enabled' => true,
  6592. 'image' => 'plugins/images/tabs/wind.png',
  6593. 'category' => 'Monitor',
  6594. 'settings' => array(
  6595. 'Enable' => array(
  6596. array(
  6597. 'type' => 'switch',
  6598. 'name' => 'homepageWeatherAndAirEnabled',
  6599. 'label' => 'Enable',
  6600. 'value' => $this->config['homepageWeatherAndAirEnabled']
  6601. ),
  6602. array(
  6603. 'type' => 'select',
  6604. 'name' => 'homepageWeatherAndAirAuth',
  6605. 'label' => 'Minimum Authentication',
  6606. 'value' => $this->config['homepageWeatherAndAirAuth'],
  6607. 'options' => $groups
  6608. )
  6609. ),
  6610. 'Connection' => array(
  6611. array(
  6612. 'type' => 'input',
  6613. 'name' => 'homepageWeatherAndAirLatitude',
  6614. 'label' => 'Latitude',
  6615. 'value' => $this->config['homepageWeatherAndAirLatitude'],
  6616. 'help' => 'Please enter full latitude including minus if needed'
  6617. ),
  6618. array(
  6619. 'type' => 'input',
  6620. 'name' => 'homepageWeatherAndAirLongitude',
  6621. 'label' => 'Longitude',
  6622. 'value' => $this->config['homepageWeatherAndAirLongitude'],
  6623. 'help' => 'Please enter full longitude including minus if needed'
  6624. ),
  6625. array(
  6626. 'type' => 'blank',
  6627. 'label' => ''
  6628. ),
  6629. array(
  6630. 'type' => 'button',
  6631. 'label' => '',
  6632. 'icon' => 'fa fa-search',
  6633. 'class' => 'pull-right',
  6634. 'text' => 'Need Help With Coordinates?',
  6635. 'attr' => 'onclick="showLookupCoordinatesModal()"'
  6636. ),
  6637. ),
  6638. 'Options' => array(
  6639. array(
  6640. 'type' => 'input',
  6641. 'name' => 'homepageWeatherAndAirWeatherHeader',
  6642. 'label' => 'Title',
  6643. 'value' => $this->config['homepageWeatherAndAirWeatherHeader'],
  6644. 'help' => 'Sets the title of this homepage module',
  6645. ),
  6646. array(
  6647. 'type' => 'switch',
  6648. 'name' => 'homepageWeatherAndAirWeatherHeaderToggle',
  6649. 'label' => 'Toggle Title',
  6650. 'value' => $this->config['homepageWeatherAndAirWeatherHeaderToggle'],
  6651. 'help' => 'Shows/hides the title of this homepage module'
  6652. ),
  6653. array(
  6654. 'type' => 'switch',
  6655. 'name' => 'homepageWeatherAndAirWeatherEnabled',
  6656. 'label' => 'Enable Weather',
  6657. 'value' => $this->config['homepageWeatherAndAirWeatherEnabled'],
  6658. 'help' => 'Toggles the view module for Weather'
  6659. ),
  6660. array(
  6661. 'type' => 'switch',
  6662. 'name' => 'homepageWeatherAndAirAirQualityEnabled',
  6663. 'label' => 'Enable Air Quality',
  6664. 'value' => $this->config['homepageWeatherAndAirAirQualityEnabled'],
  6665. 'help' => 'Toggles the view module for Air Quality'
  6666. ),
  6667. array(
  6668. 'type' => 'switch',
  6669. 'name' => 'homepageWeatherAndAirPollenEnabled',
  6670. 'label' => 'Enable Pollen',
  6671. 'value' => $this->config['homepageWeatherAndAirPollenEnabled'],
  6672. 'help' => 'Toggles the view module for Pollen'
  6673. ),
  6674. array(
  6675. 'type' => 'select',
  6676. 'name' => 'homepageWeatherAndAirUnits',
  6677. 'label' => 'Unit of Measurement',
  6678. 'value' => $this->config['homepageWeatherAndAirUnits'],
  6679. 'options' => array(
  6680. array(
  6681. 'name' => 'Imperial',
  6682. 'value' => 'imperial'
  6683. ),
  6684. array(
  6685. 'name' => 'Metric',
  6686. 'value' => 'metric'
  6687. )
  6688. )
  6689. ),
  6690. array(
  6691. 'type' => 'select',
  6692. 'name' => 'homepageWeatherAndAirRefresh',
  6693. 'label' => 'Refresh Seconds',
  6694. 'value' => $this->config['homepageWeatherAndAirRefresh'],
  6695. 'options' => $this->optionTime()
  6696. ),
  6697. ),
  6698. )
  6699. ),
  6700. array(
  6701. 'name' => 'Speedtest',
  6702. 'enabled' => true,
  6703. 'image' => 'plugins/images/tabs/speedtest-icon.png',
  6704. 'category' => 'Monitor',
  6705. 'settings' => array(
  6706. 'Enable' => array(
  6707. array(
  6708. 'type' => 'html',
  6709. 'override' => 6,
  6710. 'label' => 'Info',
  6711. 'html' => '<p>This homepage item requires <a href="https://github.com/henrywhitaker3/Speedtest-Tracker" target="_blank" rel="noreferrer noopener">Speedtest-Tracker <i class="fa fa-external-link" aria-hidden="true"></i></a> to be running on your network.</p>'
  6712. ),
  6713. array(
  6714. 'type' => 'switch',
  6715. 'name' => 'homepageSpeedtestEnabled',
  6716. 'label' => 'Enable',
  6717. 'value' => $this->config['homepageSpeedtestEnabled']
  6718. ),
  6719. array(
  6720. 'type' => 'select',
  6721. 'name' => 'homepageSpeedtestAuth',
  6722. 'label' => 'Minimum Authentication',
  6723. 'value' => $this->config['homepageSpeedtestAuth'],
  6724. 'options' => $groups
  6725. )
  6726. ),
  6727. 'Connection' => array(
  6728. array(
  6729. 'type' => 'input',
  6730. 'name' => 'speedtestURL',
  6731. 'label' => 'URL',
  6732. 'value' => $this->config['speedtestURL'],
  6733. 'help' => 'Enter the IP:PORT of your speedtest instance e.g. http(s)://<ip>:<port>'
  6734. ),
  6735. ),
  6736. 'Options' => array(
  6737. array(
  6738. 'type' => 'input',
  6739. 'name' => 'speedtestHeader',
  6740. 'label' => 'Title',
  6741. 'value' => $this->config['speedtestHeader'],
  6742. 'help' => 'Sets the title of this homepage module',
  6743. ),
  6744. array(
  6745. 'type' => 'switch',
  6746. 'name' => 'speedtestHeaderToggle',
  6747. 'label' => 'Toggle Title',
  6748. 'value' => $this->config['speedtestHeaderToggle'],
  6749. 'help' => 'Shows/hides the title of this homepage module'
  6750. ),
  6751. ),
  6752. )
  6753. ),
  6754. $this->netdataSettingsArray(),
  6755. array(
  6756. 'name' => 'Octoprint',
  6757. 'enabled' => true,
  6758. 'image' => 'plugins/images/tabs/octoprint.png',
  6759. 'category' => 'Monitor',
  6760. 'settings' => array(
  6761. 'Enable' => array(
  6762. array(
  6763. 'type' => 'switch',
  6764. 'name' => 'homepageOctoprintEnabled',
  6765. 'label' => 'Enable',
  6766. 'value' => $this->config['homepageOctoprintEnabled']
  6767. ),
  6768. array(
  6769. 'type' => 'select',
  6770. 'name' => 'homepageOctoprintAuth',
  6771. 'label' => 'Minimum Authentication',
  6772. 'value' => $this->config['homepageOctoprintAuth'],
  6773. 'options' => $groups
  6774. )
  6775. ),
  6776. 'Connection' => array(
  6777. array(
  6778. 'type' => 'input',
  6779. 'name' => 'octoprintURL',
  6780. 'label' => 'URL',
  6781. 'value' => $this->config['octoprintURL'],
  6782. 'help' => 'Enter the IP:PORT of your Octoprint instance e.g. http://octopi.local'
  6783. ),
  6784. array(
  6785. 'type' => 'input',
  6786. 'name' => 'octoprintToken',
  6787. 'label' => 'API Key',
  6788. 'value' => $this->config['octoprintToken'],
  6789. 'help' => 'Enter your Octoprint API key, found in Octoprint settings page.'
  6790. ),
  6791. ),
  6792. 'Options' => array(
  6793. array(
  6794. 'type' => 'input',
  6795. 'name' => 'octoprintHeader',
  6796. 'label' => 'Title',
  6797. 'value' => $this->config['octoprintHeader'],
  6798. 'help' => 'Sets the title of this homepage module',
  6799. ),
  6800. array(
  6801. 'type' => 'switch',
  6802. 'name' => 'octoprintToggle',
  6803. 'label' => 'Toggle Title',
  6804. 'value' => $this->config['octoprintHeaderToggle'],
  6805. 'help' => 'Shows/hides the title of this homepage module'
  6806. ),
  6807. ),
  6808. )
  6809. ),
  6810. );
  6811. }
  6812. public function isTabNameTaken($name, $id = null)
  6813. {
  6814. if ($id) {
  6815. $response = [
  6816. array(
  6817. 'function' => 'fetchAll',
  6818. 'query' => array(
  6819. 'SELECT * FROM tabs WHERE `name` LIKE ? AND `id` != ?',
  6820. $name,
  6821. $id
  6822. )
  6823. ),
  6824. ];
  6825. } else {
  6826. $response = [
  6827. array(
  6828. 'function' => 'fetchAll',
  6829. 'query' => array(
  6830. 'SELECT * FROM tabs WHERE `name` LIKE ?',
  6831. $name
  6832. )
  6833. ),
  6834. ];
  6835. }
  6836. return $this->processQueries($response);
  6837. }
  6838. public function isCategoryNameTaken($name, $id = null)
  6839. {
  6840. if ($id) {
  6841. $response = [
  6842. array(
  6843. 'function' => 'fetchAll',
  6844. 'query' => array(
  6845. 'SELECT * FROM categories WHERE `category` LIKE ? AND `id` != ?',
  6846. $name,
  6847. $id
  6848. )
  6849. ),
  6850. ];
  6851. } else {
  6852. $response = [
  6853. array(
  6854. 'function' => 'fetchAll',
  6855. 'query' => array(
  6856. 'SELECT * FROM categories WHERE `category` LIKE ?',
  6857. $name
  6858. )
  6859. ),
  6860. ];
  6861. }
  6862. return $this->processQueries($response);
  6863. }
  6864. public function isGroupNameTaken($name, $id = null)
  6865. {
  6866. if ($id) {
  6867. $response = [
  6868. array(
  6869. 'function' => 'fetchAll',
  6870. 'query' => array(
  6871. 'SELECT * FROM groups WHERE `group` LIKE ? AND `id` != ?',
  6872. $name,
  6873. $id
  6874. )
  6875. ),
  6876. ];
  6877. } else {
  6878. $response = [
  6879. array(
  6880. 'function' => 'fetchAll',
  6881. 'query' => array(
  6882. 'SELECT * FROM groups WHERE `group` LIKE ?',
  6883. $name
  6884. )
  6885. ),
  6886. ];
  6887. }
  6888. return $this->processQueries($response);
  6889. }
  6890. public function getTableColumns($table)
  6891. {
  6892. $response = [
  6893. array(
  6894. 'function' => 'fetchAll',
  6895. 'query' => array(
  6896. 'PRAGMA table_info(?)',
  6897. $table
  6898. )
  6899. ),
  6900. ];
  6901. return $this->processQueries($response);
  6902. }
  6903. public function getTableColumnsFormatted($table)
  6904. {
  6905. $columns = $this->getTableColumns($table);
  6906. if ($columns) {
  6907. $columnsFormatted = [];
  6908. foreach ($columns as $k => $v) {
  6909. $columnsFormatted[$v['name']] = $v;
  6910. }
  6911. return $columnsFormatted;
  6912. } else {
  6913. return false;
  6914. }
  6915. }
  6916. public function getTabById($id)
  6917. {
  6918. $response = [
  6919. array(
  6920. 'function' => 'fetch',
  6921. 'query' => array(
  6922. 'SELECT * FROM tabs WHERE `id` = ?',
  6923. $id
  6924. )
  6925. ),
  6926. ];
  6927. return $this->processQueries($response);
  6928. }
  6929. public function getTabGroupByTabName($tab)
  6930. {
  6931. $response = [
  6932. array(
  6933. 'function' => 'fetch',
  6934. 'query' => array(
  6935. 'SELECT group_id FROM tabs WHERE name LIKE %~like~',
  6936. $tab
  6937. )
  6938. ),
  6939. ];
  6940. $query = $this->processQueries($response);
  6941. return $query ? $query['group_id'] : 0;
  6942. }
  6943. public function getCategoryById($id)
  6944. {
  6945. $response = [
  6946. array(
  6947. 'function' => 'fetch',
  6948. 'query' => array(
  6949. 'SELECT * FROM categories WHERE `id` = ?',
  6950. $id
  6951. )
  6952. ),
  6953. ];
  6954. return $this->processQueries($response);
  6955. }
  6956. public function getGroupUserCountById($id)
  6957. {
  6958. $response = [
  6959. array(
  6960. 'function' => 'fetchSingle',
  6961. 'query' => array(
  6962. 'SELECT count(username) AS count FROM groups INNER JOIN users ON users.group_id = groups.group_id AND groups.id = ?',
  6963. $id
  6964. )
  6965. ),
  6966. ];
  6967. return $this->processQueries($response);
  6968. }
  6969. public function getGroupById($id)
  6970. {
  6971. $response = [
  6972. array(
  6973. 'function' => 'fetch',
  6974. 'query' => array(
  6975. 'SELECT * FROM groups WHERE `id` = ?',
  6976. $id
  6977. )
  6978. ),
  6979. ];
  6980. return $this->processQueries($response);
  6981. }
  6982. public function getGroupByGroupId($id)
  6983. {
  6984. $response = [
  6985. array(
  6986. 'function' => 'fetch',
  6987. 'query' => array(
  6988. 'SELECT * FROM groups WHERE `group_id` = ?',
  6989. $id
  6990. )
  6991. ),
  6992. ];
  6993. return $this->processQueries($response);
  6994. }
  6995. public function getDefaultGroup()
  6996. {
  6997. $response = [
  6998. array(
  6999. 'function' => 'fetch',
  7000. 'query' => array(
  7001. 'SELECT * FROM groups WHERE `default` = 1'
  7002. )
  7003. ),
  7004. ];
  7005. return $this->processQueries($response);
  7006. }
  7007. public function getDefaultGroupId()
  7008. {
  7009. $response = [
  7010. array(
  7011. 'function' => 'fetchSingle',
  7012. 'query' => array(
  7013. 'SELECT `group_id` FROM groups WHERE `default` = 1'
  7014. )
  7015. ),
  7016. ];
  7017. return $this->processQueries($response);
  7018. }
  7019. public function getDefaultCategory()
  7020. {
  7021. $response = [
  7022. array(
  7023. 'function' => 'fetch',
  7024. 'query' => array(
  7025. 'SELECT * FROM categories WHERE `default` = 1'
  7026. )
  7027. ),
  7028. ];
  7029. return $this->processQueries($response);
  7030. }
  7031. public function getDefaultCategoryId()
  7032. {
  7033. $response = [
  7034. array(
  7035. 'function' => 'fetchSingle',
  7036. 'query' => array(
  7037. 'SELECT `category_id` FROM categories WHERE `default` = 1'
  7038. )
  7039. ),
  7040. ];
  7041. return $this->processQueries($response);
  7042. }
  7043. public function getNextTabOrder()
  7044. {
  7045. $response = [
  7046. array(
  7047. 'function' => 'fetchSingle',
  7048. 'query' => array(
  7049. 'SELECT `order` from tabs ORDER BY `order` DESC'
  7050. )
  7051. ),
  7052. ];
  7053. return $this->processQueries($response);
  7054. }
  7055. public function getNextCategoryOrder()
  7056. {
  7057. $response = [
  7058. array(
  7059. 'function' => 'fetchSingle',
  7060. 'query' => array(
  7061. 'SELECT `order` from categories ORDER BY `order` DESC'
  7062. )
  7063. ),
  7064. ];
  7065. return $this->processQueries($response);
  7066. }
  7067. public function getNextGroupOrder()
  7068. {
  7069. $response = [
  7070. array(
  7071. 'function' => 'fetchSingle',
  7072. 'query' => array(
  7073. 'SELECT `group_id` from groups WHERE `group_id` != "999" ORDER BY `group_id` DESC'
  7074. )
  7075. ),
  7076. ];
  7077. return $this->processQueries($response);
  7078. }
  7079. public function getNextCategoryId()
  7080. {
  7081. $response = [
  7082. array(
  7083. 'function' => 'fetchSingle',
  7084. 'query' => array(
  7085. 'SELECT `category_id` from categories ORDER BY `category_id` DESC'
  7086. )
  7087. ),
  7088. ];
  7089. return $this->processQueries($response);
  7090. }
  7091. public function clearTabDefault()
  7092. {
  7093. $response = [
  7094. array(
  7095. 'function' => 'query',
  7096. 'query' => array(
  7097. 'UPDATE tabs SET `default` = 0'
  7098. )
  7099. ),
  7100. ];
  7101. return $this->processQueries($response);
  7102. }
  7103. public function clearCategoryDefault()
  7104. {
  7105. $response = [
  7106. array(
  7107. 'function' => 'query',
  7108. 'query' => array(
  7109. 'UPDATE categories SET `default` = 0'
  7110. )
  7111. ),
  7112. ];
  7113. return $this->processQueries($response);
  7114. }
  7115. public function clearGroupDefault()
  7116. {
  7117. $response = [
  7118. array(
  7119. 'function' => 'query',
  7120. 'query' => array(
  7121. 'UPDATE groups SET `default` = 0'
  7122. )
  7123. ),
  7124. ];
  7125. return $this->processQueries($response);
  7126. }
  7127. public function checkKeys($tabInfo, $newData)
  7128. {
  7129. foreach ($newData as $k => $v) {
  7130. if (!array_key_exists($k, $tabInfo)) {
  7131. unset($newData[$k]);
  7132. }
  7133. }
  7134. return $newData;
  7135. }
  7136. public function deleteTab($id)
  7137. {
  7138. $response = [
  7139. array(
  7140. 'function' => 'query',
  7141. 'query' => array(
  7142. 'DELETE FROM tabs WHERE id = ?',
  7143. $id
  7144. )
  7145. ),
  7146. ];
  7147. $tabInfo = $this->getTabById($id);
  7148. if ($tabInfo) {
  7149. $this->writeLog('success', 'Tab Delete Function - Deleted Tab [' . $tabInfo['name'] . ']', $this->user['username']);
  7150. $this->setAPIResponse('success', 'Tab deleted', 204);
  7151. return $this->processQueries($response);
  7152. } else {
  7153. $this->setAPIResponse('error', 'id not found', 404);
  7154. return false;
  7155. }
  7156. }
  7157. public function addTab($array)
  7158. {
  7159. if (!$array) {
  7160. $this->setAPIResponse('error', 'no data was sent', 422);
  7161. return null;
  7162. }
  7163. $array = $this->checkKeys($this->getTableColumnsFormatted('tabs'), $array);
  7164. $array['group_id'] = ($array['group_id']) ?? $this->getDefaultGroupId();
  7165. $array['category_id'] = ($array['category_id']) ?? $this->getDefaultCategoryId();
  7166. $array['enabled'] = ($array['enabled']) ?? 0;
  7167. $array['default'] = ($array['default']) ?? 0;
  7168. $array['type'] = ($array['type']) ?? 1;
  7169. $array['order'] = ($array['order']) ?? $this->getNextTabOrder() + 1;
  7170. if (array_key_exists('name', $array)) {
  7171. if ($this->isTabNameTaken($array['name'])) {
  7172. $this->setAPIResponse('error', 'Tab name: ' . $array['name'] . ' is already taken', 409);
  7173. return false;
  7174. }
  7175. } else {
  7176. $this->setAPIResponse('error', 'Tab name was not supplied', 422);
  7177. return false;
  7178. }
  7179. if (!array_key_exists('url', $array) && !array_key_exists('url_local', $array)) {
  7180. $this->setAPIResponse('error', 'Tab url or url_local was not supplied', 422);
  7181. return false;
  7182. }
  7183. if (!array_key_exists('image', $array)) {
  7184. $this->setAPIResponse('error', 'Tab image was not supplied', 422);
  7185. return false;
  7186. }
  7187. $response = [
  7188. array(
  7189. 'function' => 'query',
  7190. 'query' => array(
  7191. 'INSERT INTO [tabs]',
  7192. $array
  7193. )
  7194. ),
  7195. ];
  7196. $this->setAPIResponse(null, 'Tab added');
  7197. $this->writeLog('success', 'Tab Editor Function - Added Tab for [' . $array['name'] . ']', $this->user['username']);
  7198. return $this->processQueries($response);
  7199. }
  7200. public function updateTab($id, $array)
  7201. {
  7202. if (!$id || $id == '') {
  7203. $this->setAPIResponse('error', 'id was not set', 422);
  7204. return null;
  7205. }
  7206. if (!$array) {
  7207. $this->setAPIResponse('error', 'no data was sent', 422);
  7208. return null;
  7209. }
  7210. $tabInfo = $this->getTabById($id);
  7211. if ($tabInfo) {
  7212. $array = $this->checkKeys($tabInfo, $array);
  7213. } else {
  7214. $this->setAPIResponse('error', 'No tab info found', 404);
  7215. return false;
  7216. }
  7217. if (array_key_exists('name', $array)) {
  7218. if ($this->isTabNameTaken($array['name'], $id)) {
  7219. $this->setAPIResponse('error', 'Tab name: ' . $array['name'] . ' is already taken', 409);
  7220. return false;
  7221. }
  7222. }
  7223. if (array_key_exists('default', $array)) {
  7224. if ($array['default']) {
  7225. $this->clearTabDefault();
  7226. }
  7227. }
  7228. $response = [
  7229. array(
  7230. 'function' => 'query',
  7231. 'query' => array(
  7232. 'UPDATE tabs SET',
  7233. $array,
  7234. 'WHERE id = ?',
  7235. $id
  7236. )
  7237. ),
  7238. ];
  7239. $this->setAPIResponse(null, 'Tab info updated');
  7240. $this->writeLog('success', 'Tab Editor Function - Edited Tab Info for [' . $tabInfo['name'] . ']', $this->user['username']);
  7241. return $this->processQueries($response);
  7242. }
  7243. public function updateTabOrder($array)
  7244. {
  7245. if (count($array) >= 1) {
  7246. foreach ($array as $tab) {
  7247. if (count($tab) !== 2) {
  7248. $this->setAPIResponse('error', 'data is malformed', 422);
  7249. break;
  7250. }
  7251. $id = $tab['id'] ?? null;
  7252. $order = $tab['order'] ?? null;
  7253. if ($id && $order) {
  7254. $response = [
  7255. array(
  7256. 'function' => 'query',
  7257. 'query' => array(
  7258. 'UPDATE tabs set `order` = ? WHERE `id` = ?',
  7259. $order,
  7260. $id
  7261. )
  7262. ),
  7263. ];
  7264. $this->processQueries($response);
  7265. $this->setAPIResponse(null, 'Tab Order updated');
  7266. } else {
  7267. $this->setAPIResponse('error', 'data is malformed', 422);
  7268. }
  7269. }
  7270. } else {
  7271. $this->setAPIResponse('error', 'data is empty or not in array', 422);
  7272. return false;
  7273. }
  7274. }
  7275. public function addCategory($array)
  7276. {
  7277. if (!$array) {
  7278. $this->setAPIResponse('error', 'no data was sent', 422);
  7279. return null;
  7280. }
  7281. $array = $this->checkKeys($this->getTableColumnsFormatted('categories'), $array);
  7282. $array['default'] = ($array['default']) ?? 0;
  7283. $array['order'] = ($array['order']) ?? $this->getNextCategoryOrder() + 1;
  7284. $array['category_id'] = ($array['category_id']) ?? $this->getNextCategoryId() + 1;
  7285. if (array_key_exists('category', $array)) {
  7286. if ($this->isCategoryNameTaken($array['category'])) {
  7287. $this->setAPIResponse('error', 'Category name: ' . $array['category'] . ' is already taken', 409);
  7288. return false;
  7289. }
  7290. } else {
  7291. $this->setAPIResponse('error', 'Category name was not supplied', 422);
  7292. return false;
  7293. }
  7294. if (!array_key_exists('image', $array)) {
  7295. $this->setAPIResponse('error', 'Category image was not supplied', 422);
  7296. }
  7297. $response = [
  7298. array(
  7299. 'function' => 'query',
  7300. 'query' => array(
  7301. 'INSERT INTO [categories]',
  7302. $array
  7303. )
  7304. ),
  7305. ];
  7306. $this->setAPIResponse(null, 'Category added');
  7307. $this->writeLog('success', 'Category Editor Function - Added Category for [' . $array['category'] . ']', $this->user['username']);
  7308. return $this->processQueries($response);
  7309. }
  7310. public function updateCategory($id, $array)
  7311. {
  7312. if (!$id || $id == '') {
  7313. $this->setAPIResponse('error', 'id was not set', 422);
  7314. return null;
  7315. }
  7316. if (!$array) {
  7317. $this->setAPIResponse('error', 'no data was sent', 422);
  7318. return null;
  7319. }
  7320. $categoryInfo = $this->getCategoryById($id);
  7321. if ($categoryInfo) {
  7322. $array = $this->checkKeys($categoryInfo, $array);
  7323. } else {
  7324. $this->setAPIResponse('error', 'No category info found', 404);
  7325. return false;
  7326. }
  7327. if (array_key_exists('category', $array)) {
  7328. if ($this->isCategoryNameTaken($array['category'], $id)) {
  7329. $this->setAPIResponse('error', 'Category name: ' . $array['category'] . ' is already taken', 409);
  7330. return false;
  7331. }
  7332. }
  7333. if (array_key_exists('default', $array)) {
  7334. if ($array['default']) {
  7335. $this->clearCategoryDefault();
  7336. }
  7337. }
  7338. $response = [
  7339. array(
  7340. 'function' => 'query',
  7341. 'query' => array(
  7342. 'UPDATE categories SET',
  7343. $array,
  7344. 'WHERE id = ?',
  7345. $id
  7346. )
  7347. ),
  7348. ];
  7349. $this->setAPIResponse(null, 'Category info updated');
  7350. $this->writeLog('success', 'Category Editor Function - Edited Category Info for [' . $categoryInfo['category'] . ']', $this->user['username']);
  7351. return $this->processQueries($response);
  7352. }
  7353. public function updateCategoryOrder($array)
  7354. {
  7355. if (count($array) >= 1) {
  7356. foreach ($array as $category) {
  7357. if (count($category) !== 2) {
  7358. $this->setAPIResponse('error', 'data is malformed', 422);
  7359. break;
  7360. }
  7361. $id = $category['id'] ?? null;
  7362. $order = $category['order'] ?? null;
  7363. if ($id && $order) {
  7364. $response = [
  7365. array(
  7366. 'function' => 'query',
  7367. 'query' => array(
  7368. 'UPDATE categories set `order` = ? WHERE `id` = ?',
  7369. $order,
  7370. $id
  7371. )
  7372. ),
  7373. ];
  7374. $this->processQueries($response);
  7375. $this->setAPIResponse(null, 'Category Order updated');
  7376. } else {
  7377. $this->setAPIResponse('error', 'data is malformed', 422);
  7378. }
  7379. }
  7380. } else {
  7381. $this->setAPIResponse('error', 'data is empty or not in array', 422);
  7382. return false;
  7383. }
  7384. }
  7385. public function deleteCategory($id)
  7386. {
  7387. $response = [
  7388. array(
  7389. 'function' => 'query',
  7390. 'query' => array(
  7391. 'DELETE FROM categories WHERE id = ?',
  7392. $id
  7393. )
  7394. ),
  7395. ];
  7396. $categoryInfo = $this->getCategoryById($id);
  7397. if ($categoryInfo) {
  7398. $this->writeLog('success', 'Category Delete Function - Deleted Category [' . $categoryInfo['category'] . ']', $this->user['username']);
  7399. $this->setAPIResponse('success', 'Category deleted', 204);
  7400. return $this->processQueries($response);
  7401. } else {
  7402. $this->setAPIResponse('error', 'id not found', 404);
  7403. return false;
  7404. }
  7405. }
  7406. public function marketplaceFileListFormat($files, $folder, $type)
  7407. {
  7408. foreach ($files as $k => $v) {
  7409. $splitFiles = explode('|', $v);
  7410. $prePath = (strlen($k) !== 1) ? $k . '/' : $k;
  7411. foreach ($splitFiles as $file) {
  7412. $filesList[] = array(
  7413. 'fileName' => $file,
  7414. 'path' => $prePath,
  7415. 'githubPath' => 'https://raw.githubusercontent.com/causefx/Organizr/v2-' . $type . '/' . $folder . $prePath . $file
  7416. );
  7417. }
  7418. }
  7419. return $filesList;
  7420. }
  7421. public function removeTheme($theme)
  7422. {
  7423. $theme = $this->reverseCleanClassName($theme);
  7424. $array = $this->getThemesGithub();
  7425. $arrayLower = array_change_key_case($array);
  7426. if (!$array) {
  7427. $this->setAPIResponse('error', 'Could not access theme marketplace', 409);
  7428. return false;
  7429. }
  7430. if (!$arrayLower[$theme]) {
  7431. $this->setAPIResponse('error', 'Theme does not exist in marketplace', 404);
  7432. return false;
  7433. } else {
  7434. $key = array_search($theme, array_keys($arrayLower));
  7435. $theme = array_keys($array)[$key];
  7436. }
  7437. $array = $array[$theme];
  7438. $downloadList = $this->marketplaceFileListFormat($array['files'], $array['github_folder'], 'themes');
  7439. if (!$downloadList) {
  7440. $this->setAPIResponse('error', 'Could not get download list for theme', 409);
  7441. return false;
  7442. }
  7443. $name = $theme;
  7444. $version = $array['version'];
  7445. $installedThemesNew = '';
  7446. foreach ($downloadList as $k => $v) {
  7447. $file = array(
  7448. 'from' => $v['githubPath'],
  7449. 'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->root . $v['path'] . $v['fileName']),
  7450. 'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->root . $v['path'])
  7451. );
  7452. if (!$this->rrmdir($file['to'])) {
  7453. $this->writeLog('error', 'Theme Function - Remove File Failed for: ' . $v['githubPath'], $this->user['username']);
  7454. return false;
  7455. }
  7456. }
  7457. if ($this->config['installedThemes'] !== '') {
  7458. $installedThemes = explode('|', $this->config['installedThemes']);
  7459. foreach ($installedThemes as $k => $v) {
  7460. $themes = explode(':', $v);
  7461. $installedThemesList[$themes[0]] = $themes[1];
  7462. }
  7463. if (isset($installedThemesList[$name])) {
  7464. foreach ($installedThemesList as $k => $v) {
  7465. if ($k !== $name) {
  7466. if ($installedThemesNew == '') {
  7467. $installedThemesNew .= $k . ':' . $v;
  7468. } else {
  7469. $installedThemesNew .= '|' . $k . ':' . $v;
  7470. }
  7471. }
  7472. }
  7473. }
  7474. }
  7475. $this->updateConfig(array('installedThemes' => $installedThemesNew));
  7476. $this->setAPIResponse('success', 'Theme removed', 200, $installedThemesNew);
  7477. return true;
  7478. }
  7479. public function installTheme($theme)
  7480. {
  7481. $theme = $this->reverseCleanClassName($theme);
  7482. $array = $this->getThemesGithub();
  7483. $arrayLower = array_change_key_case($array);
  7484. if (!$array) {
  7485. $this->setAPIResponse('error', 'Could not access theme marketplace', 409);
  7486. return false;
  7487. }
  7488. if (!$arrayLower[$theme]) {
  7489. $this->setAPIResponse('error', 'Theme does not exist in marketplace', 404);
  7490. return false;
  7491. } else {
  7492. $key = array_search($theme, array_keys($arrayLower));
  7493. $theme = array_keys($array)[$key];
  7494. }
  7495. $array = $array[$theme];
  7496. $downloadList = $this->marketplaceFileListFormat($array['files'], $array['github_folder'], 'themes');
  7497. if (!$downloadList) {
  7498. $this->setAPIResponse('error', 'Could not get download list for theme', 409);
  7499. return false;
  7500. }
  7501. $name = $theme;
  7502. $version = $array['version'];
  7503. foreach ($downloadList as $k => $v) {
  7504. $file = array(
  7505. 'from' => $v['githubPath'],
  7506. 'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->root . $v['path'] . $v['fileName']),
  7507. 'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->root . $v['path'])
  7508. );
  7509. if (!$this->downloadFileToPath($file['from'], $file['to'], $file['path'])) {
  7510. $this->writeLog('error', 'Theme Function - Downloaded File Failed for: ' . $v['githubPath'], $this->user['username']);
  7511. $this->setAPIResponse('error', 'Theme download failed', 500);
  7512. return false;
  7513. }
  7514. }
  7515. if ($this->config['installedThemes'] !== '') {
  7516. $installedThemes = explode('|', $this->config['installedThemes']);
  7517. foreach ($installedThemes as $k => $v) {
  7518. $themes = explode(':', $v);
  7519. $installedThemesList[$themes[0]] = $themes[1];
  7520. }
  7521. if (isset($installedThemesList[$name])) {
  7522. $installedThemesList[$name] = $version;
  7523. $installedThemesNew = '';
  7524. foreach ($installedThemesList as $k => $v) {
  7525. if ($installedThemesNew == '') {
  7526. $installedThemesNew .= $k . ':' . $v;
  7527. } else {
  7528. $installedThemesNew .= '|' . $k . ':' . $v;
  7529. }
  7530. }
  7531. } else {
  7532. $installedThemesNew = $this->config['installedThemes'] . '|' . $name . ':' . $version;
  7533. }
  7534. } else {
  7535. $installedThemesNew = $name . ':' . $version;
  7536. }
  7537. $this->updateConfig(array('installedThemes' => $installedThemesNew));
  7538. $this->setAPIResponse('success', 'Theme installed', 200, $installedThemesNew);
  7539. return true;
  7540. }
  7541. public function removePlugin($plugin)
  7542. {
  7543. $plugin = $this->reverseCleanClassName($plugin);
  7544. $array = $this->getPluginsGithub();
  7545. $arrayLower = array_change_key_case($array);
  7546. if (!$array) {
  7547. $this->setAPIResponse('error', 'Could not access plugin marketplace', 409);
  7548. return false;
  7549. }
  7550. if (!$arrayLower[$plugin]) {
  7551. $this->setAPIResponse('error', 'Plugin does not exist in marketplace', 404);
  7552. return false;
  7553. } else {
  7554. $key = array_search($plugin, array_keys($arrayLower));
  7555. $plugin = array_keys($array)[$key];
  7556. }
  7557. $array = $array[$plugin];
  7558. $downloadList = $this->marketplaceFileListFormat($array['files'], $array['github_folder'], 'plugins');
  7559. if (!$downloadList) {
  7560. $this->setAPIResponse('error', 'Could not get download list for plugin', 409);
  7561. return false;
  7562. }
  7563. $name = $plugin;
  7564. $version = $array['version'];
  7565. $installedPluginsNew = '';
  7566. foreach ($downloadList as $k => $v) {
  7567. $file = array(
  7568. 'from' => $v['githubPath'],
  7569. 'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->root . $v['path'] . $v['fileName']),
  7570. 'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->root . $v['path'])
  7571. );
  7572. if (!$this->rrmdir($file['to'])) {
  7573. $this->writeLog('error', 'Plugin Function - Remove File Failed for: ' . $v['githubPath'], $this->user['username']);
  7574. return false;
  7575. }
  7576. }
  7577. if ($this->config['installedPlugins'] !== '') {
  7578. $installedPlugins = explode('|', $this->config['installedPlugins']);
  7579. foreach ($installedPlugins as $k => $v) {
  7580. $plugins = explode(':', $v);
  7581. $installedPluginsList[$plugins[0]] = $plugins[1];
  7582. }
  7583. if (isset($installedPluginsList[$name])) {
  7584. foreach ($installedPluginsList as $k => $v) {
  7585. if ($k !== $name) {
  7586. if ($installedPluginsNew == '') {
  7587. $installedPluginsNew .= $k . ':' . $v;
  7588. } else {
  7589. $installedPluginsNew .= '|' . $k . ':' . $v;
  7590. }
  7591. }
  7592. }
  7593. }
  7594. }
  7595. $this->updateConfig(array('installedPlugins' => $installedPluginsNew));
  7596. $this->setAPIResponse('success', 'Plugin removed', 200, $installedPluginsNew);
  7597. return true;
  7598. }
  7599. public function installPlugin($plugin)
  7600. {
  7601. $plugin = $this->reverseCleanClassName($plugin);
  7602. $array = $this->getPluginsGithub();
  7603. $arrayLower = array_change_key_case($array);
  7604. if (!$array) {
  7605. $this->setAPIResponse('error', 'Could not access plugin marketplace', 409);
  7606. return false;
  7607. }
  7608. if (!$arrayLower[$plugin]) {
  7609. $this->setAPIResponse('error', 'Plugin does not exist in marketplace', 404);
  7610. return false;
  7611. } else {
  7612. $key = array_search($plugin, array_keys($arrayLower));
  7613. $plugin = array_keys($array)[$key];
  7614. }
  7615. $array = $array[$plugin];
  7616. $downloadList = $this->marketplaceFileListFormat($array['files'], $array['github_folder'], 'plugins');
  7617. if (!$downloadList) {
  7618. $this->setAPIResponse('error', 'Could not get download list for plugin', 409);
  7619. return false;
  7620. }
  7621. $name = $plugin;
  7622. $version = $array['version'];
  7623. foreach ($downloadList as $k => $v) {
  7624. $file = array(
  7625. 'from' => $v['githubPath'],
  7626. 'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->root . $v['path'] . $v['fileName']),
  7627. 'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->root . $v['path'])
  7628. );
  7629. if (!$this->downloadFileToPath($file['from'], $file['to'], $file['path'])) {
  7630. $this->writeLog('error', 'Plugin Function - Downloaded File Failed for: ' . $v['githubPath'], $this->user['username']);
  7631. $this->setAPIResponse('error', 'Plugin download failed', 500);
  7632. return false;
  7633. }
  7634. }
  7635. if ($this->config['installedPlugins'] !== '') {
  7636. $installedPlugins = explode('|', $this->config['installedPlugins']);
  7637. foreach ($installedPlugins as $k => $v) {
  7638. $plugins = explode(':', $v);
  7639. $installedPluginsList[$plugins[0]] = $plugins[1];
  7640. }
  7641. if (isset($installedPluginsList[$name])) {
  7642. $installedPluginsList[$name] = $version;
  7643. $installedPluginsNew = '';
  7644. foreach ($installedPluginsList as $k => $v) {
  7645. if ($installedPluginsNew == '') {
  7646. $installedPluginsNew .= $k . ':' . $v;
  7647. } else {
  7648. $installedPluginsNew .= '|' . $k . ':' . $v;
  7649. }
  7650. }
  7651. } else {
  7652. $installedPluginsNew = $this->config['installedPlugins'] . '|' . $name . ':' . $version;
  7653. }
  7654. } else {
  7655. $installedPluginsNew = $name . ':' . $version;
  7656. }
  7657. $this->updateConfig(array('installedPlugins' => $installedPluginsNew));
  7658. $this->setAPIResponse('success', 'Plugin installed', 200, $installedPluginsNew);
  7659. return true;
  7660. }
  7661. public function getThemesGithub()
  7662. {
  7663. $url = 'https://raw.githubusercontent.com/causefx/Organizr/v2-themes/themes.json';
  7664. $options = (localURL($url)) ? array('verify' => false) : array();
  7665. $response = Requests::get($url, array(), $options);
  7666. if ($response->success) {
  7667. return json_decode($response->body, true);
  7668. }
  7669. return false;
  7670. }
  7671. public function getPluginsGithub()
  7672. {
  7673. $url = 'https://raw.githubusercontent.com/causefx/Organizr/v2-plugins/plugins.json';
  7674. $options = (localURL($url)) ? array('verify' => false) : array();
  7675. $response = Requests::get($url, array(), $options);
  7676. if ($response->success) {
  7677. return json_decode($response->body, true);
  7678. }
  7679. return false;
  7680. }
  7681. public function guestHash($start, $end)
  7682. {
  7683. $ip = $_SERVER['REMOTE_ADDR'];
  7684. $ip = md5($ip);
  7685. return substr($ip, $start, $end);
  7686. }
  7687. public function rrmdir($dir)
  7688. {
  7689. ini_set('max_execution_time', 0);
  7690. set_time_limit(0);
  7691. if (is_dir($dir)) {
  7692. $files = scandir($dir);
  7693. foreach ($files as $file) {
  7694. if ($file != "." && $file != "..") {
  7695. $this->rrmdir("$dir/$file");
  7696. }
  7697. }
  7698. rmdir($dir);
  7699. } elseif (file_exists($dir)) {
  7700. unlink($dir);
  7701. }
  7702. return true;
  7703. }
  7704. public function rcopy($src, $dst)
  7705. {
  7706. ini_set('max_execution_time', 0);
  7707. set_time_limit(0);
  7708. $src = $this->cleanPath($src);
  7709. $dst = $this->cleanPath($dst);
  7710. if (is_dir($src)) {
  7711. if (!file_exists($dst)) : mkdir($dst);
  7712. endif;
  7713. $files = scandir($src);
  7714. foreach ($files as $file) {
  7715. if ($file != "." && $file != "..") {
  7716. $this->rcopy("$src/$file", "$dst/$file");
  7717. }
  7718. }
  7719. } elseif (file_exists($src)) {
  7720. copy($src, $dst);
  7721. }
  7722. return true;
  7723. }
  7724. public function unzipFile($zipFile)
  7725. {
  7726. ini_set('max_execution_time', 0);
  7727. set_time_limit(0);
  7728. $zip = new ZipArchive;
  7729. $extractPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . "upgrade/";
  7730. if ($zip->open($extractPath . $zipFile) != "true") {
  7731. $this->writeLog("error", "organizr could not unzip upgrade.zip");
  7732. } else {
  7733. $this->writeLog("success", "organizr unzipped upgrade.zip");
  7734. }
  7735. /* Extract Zip File */
  7736. $zip->extractTo($extractPath);
  7737. $zip->close();
  7738. return true;
  7739. }
  7740. public function downloadFile($url, $path)
  7741. {
  7742. ini_set('max_execution_time', 0);
  7743. set_time_limit(0);
  7744. $folderPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . "upgrade" . DIRECTORY_SEPARATOR;
  7745. if (!file_exists($folderPath)) {
  7746. if (@!mkdir($folderPath)) {
  7747. $this->writeLog('error', 'Update Function - Folder Creation failed', $this->user['username']);
  7748. return false;
  7749. }
  7750. }
  7751. $newfname = $folderPath . $path;
  7752. $context = stream_context_create(
  7753. array(
  7754. 'ssl' => array(
  7755. 'verify_peer' => true,
  7756. 'cafile' => $this->getCert()
  7757. )
  7758. )
  7759. );
  7760. $file = fopen($url, 'rb', false, $context);
  7761. if ($file) {
  7762. $newf = fopen($newfname, 'wb');
  7763. if ($newf) {
  7764. while (!feof($file)) {
  7765. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  7766. }
  7767. }
  7768. } else {
  7769. $this->writeLog("error", "organizr could not download $url");
  7770. return false;
  7771. }
  7772. if ($file) {
  7773. fclose($file);
  7774. $this->writeLog("success", "organizr finished downloading the github zip file");
  7775. } else {
  7776. $this->writeLog("error", "organizr could not download the github zip file");
  7777. return false;
  7778. }
  7779. if ($newf) {
  7780. fclose($newf);
  7781. $this->writeLog("success", "organizr created upgrade zip file from github zip file");
  7782. } else {
  7783. $this->writeLog("error", "organizr could not create upgrade zip file from github zip file");
  7784. return false;
  7785. }
  7786. return true;
  7787. }
  7788. public function downloadFileToPath($from, $to, $path)
  7789. {
  7790. ini_set('max_execution_time', 0);
  7791. set_time_limit(0);
  7792. if (@!mkdir($path, 0777, true)) {
  7793. $this->writeLog("error", "organizr could not create folder or folder already exists", 'SYSTEM');
  7794. }
  7795. $file = fopen($from, 'rb');
  7796. if ($file) {
  7797. $newf = fopen($to, 'wb');
  7798. if ($newf) {
  7799. while (!feof($file)) {
  7800. fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
  7801. }
  7802. }
  7803. } else {
  7804. $this->writeLog("error", "organizr could not download file", 'SYSTEM');
  7805. }
  7806. if ($file) {
  7807. fclose($file);
  7808. $this->writeLog("success", "organizr finished downloading the file", 'SYSTEM');
  7809. } else {
  7810. $this->writeLog("error", "organizr could not download the file", 'SYSTEM');
  7811. }
  7812. if ($newf) {
  7813. fclose($newf);
  7814. $this->writeLog("success", "organizr saved/moved the file", 'SYSTEM');
  7815. } else {
  7816. $this->writeLog("error", "organizr could not saved/moved the file", 'SYSTEM');
  7817. }
  7818. return true;
  7819. }
  7820. public function getAllUsers($includeGroups = false)
  7821. {
  7822. $response = [
  7823. array(
  7824. 'function' => 'fetchAll',
  7825. 'query' => array(
  7826. 'SELECT * FROM users'
  7827. ),
  7828. 'key' => 'users'
  7829. ),
  7830. ];
  7831. $groups = array(
  7832. 'function' => 'fetchAll',
  7833. 'query' => array(
  7834. 'SELECT * FROM groups ORDER BY group_id ASC'
  7835. ),
  7836. 'key' => 'groups'
  7837. );
  7838. $addGroups = (isset($_GET['includeGroups']) || $includeGroups) ?? false;
  7839. if ($addGroups) {
  7840. array_push($response, $groups);
  7841. }
  7842. return $this->processQueries($response);
  7843. }
  7844. public function getAllGroups()
  7845. {
  7846. $response = [
  7847. array(
  7848. 'function' => 'fetchAll',
  7849. 'query' => array(
  7850. 'SELECT * FROM groups ORDER BY group_id ASC'
  7851. ),
  7852. 'key' => 'groups'
  7853. ),
  7854. ];
  7855. $users = array(
  7856. 'function' => 'fetchAll',
  7857. 'query' => array(
  7858. 'SELECT * FROM users'
  7859. ),
  7860. 'key' => 'users'
  7861. );
  7862. $addUsers = (isset($_GET['includeUsers'])) ?? false;
  7863. if ($addUsers) {
  7864. array_push($response, $users);
  7865. }
  7866. return $this->processQueries($response);
  7867. }
  7868. public function importUsers($array)
  7869. {
  7870. $imported = 0;
  7871. foreach ($array as $user) {
  7872. $password = $this->random_ascii_string(30);
  7873. if ($user['username'] !== '' && $user['email'] !== '' && $password !== '') {
  7874. $newUser = $this->createUser($user['username'], $password, $user['email']);
  7875. if (!$newUser) {
  7876. $this->writeLog('error', 'Import Function - Error', $user['username']);
  7877. } else {
  7878. $imported++;
  7879. }
  7880. }
  7881. }
  7882. $this->setAPIResponse('success', 'Imported ' . $imported . ' users', 200);
  7883. return true;
  7884. }
  7885. public function importUsersType($type)
  7886. {
  7887. if ($type !== '') {
  7888. switch ($type) {
  7889. case 'plex':
  7890. return $this->importUsers($this->allPlexUsers(true));
  7891. case 'jellyfin':
  7892. return $this->importUsers($this->allJellyfinUsers(true));
  7893. case 'emby':
  7894. return $this->importUsers($this->allEmbyUsers(true));
  7895. default:
  7896. return false;
  7897. }
  7898. }
  7899. return false;
  7900. }
  7901. public function allPlexUsers($newOnly = false, $friendsOnly = false)
  7902. {
  7903. try {
  7904. if (!empty($this->config['plexToken'])) {
  7905. $url = 'https://plex.tv/api/users';
  7906. $headers = array(
  7907. 'X-Plex-Token' => $this->config['plexToken'],
  7908. );
  7909. $response = Requests::get($url, $headers);
  7910. if ($response->success) {
  7911. libxml_use_internal_errors(true);
  7912. $userXML = simplexml_load_string($response->body);
  7913. if (is_array($userXML) || is_object($userXML)) {
  7914. $results = array();
  7915. foreach ($userXML as $child) {
  7916. if (((string)$child['restricted'] == '0')) {
  7917. if ($newOnly) {
  7918. $taken = $this->usernameTaken((string)$child['username'], (string)$child['email']);
  7919. if (!$taken) {
  7920. $results[] = array(
  7921. 'username' => (string)$child['username'],
  7922. 'email' => (string)$child['email'],
  7923. 'id' => (string)$child['id'],
  7924. );
  7925. }
  7926. } elseif ($friendsOnly) {
  7927. $machineMatches = false;
  7928. foreach ($child->Server as $server) {
  7929. if ((string)$server['machineIdentifier'] == $this->config['plexID']) {
  7930. $machineMatches = true;
  7931. }
  7932. }
  7933. if ($machineMatches) {
  7934. $results[] = array(
  7935. 'username' => (string)$child['username'],
  7936. 'email' => (string)$child['email'],
  7937. 'id' => (string)$child['id'],
  7938. );
  7939. }
  7940. } else {
  7941. $results[] = array(
  7942. 'username' => (string)$child['username'],
  7943. 'email' => (string)$child['email'],
  7944. 'id' => (string)$child['id'],
  7945. );
  7946. }
  7947. }
  7948. }
  7949. return $results;
  7950. }
  7951. }
  7952. }
  7953. return false;
  7954. } catch (Requests_Exception $e) {
  7955. $this->writeLog('success', 'Plex Import User Function - Error: ' . $e->getMessage(), 'SYSTEM');
  7956. }
  7957. return false;
  7958. }
  7959. public function allJellyfinUsers($newOnly = false)
  7960. {
  7961. try {
  7962. if (!empty($this->config['embyURL']) && !empty($this->config['embyToken'])) {
  7963. $url = $this->qualifyURL($this->config['embyURL']) . '/Users?api_key=' . $this->config['embyToken'];
  7964. $headers = array();
  7965. $response = Requests::get($url, $headers);
  7966. if ($response->success) {
  7967. $users = json_decode($response->body, true);
  7968. if (is_array($users) || is_object($users)) {
  7969. $results = array();
  7970. foreach ($users as $child) {
  7971. // Jellyfin doesn't list emails for some reason
  7972. $email = $this->random_ascii_string(10) . '@placeholder.eml';
  7973. if ($newOnly) {
  7974. $taken = $this->usernameTaken((string)$child['Name'], $email);
  7975. if (!$taken) {
  7976. $results[] = array(
  7977. 'username' => (string)$child['Name'],
  7978. 'email' => $email
  7979. );
  7980. }
  7981. } else {
  7982. $results[] = array(
  7983. 'username' => (string)$child['Name'],
  7984. 'email' => $email,
  7985. );
  7986. }
  7987. }
  7988. return $results;
  7989. }
  7990. }
  7991. }
  7992. return false;
  7993. } catch (Requests_Exception $e) {
  7994. $this->writeLog('success', 'Jellyfin Import User Function - Error: ' . $e->getMessage(), 'SYSTEM');
  7995. }
  7996. return false;
  7997. }
  7998. public function allEmbyUsers($newOnly = false)
  7999. {
  8000. try {
  8001. if (!empty($this->config['embyURL']) && !empty($this->config['embyToken'])) {
  8002. $url = $this->qualifyURL($this->config['embyURL']) . '/Users?api_key=' . $this->config['embyToken'];
  8003. $headers = array();
  8004. $response = Requests::get($url, $headers);
  8005. if ($response->success) {
  8006. $users = json_decode($response->body, true);
  8007. if (is_array($users) || is_object($users)) {
  8008. $results = array();
  8009. foreach ($users as $child) {
  8010. // Emby doesn't list emails for some reason
  8011. $email = $this->random_ascii_string(10) . '@placeholder.eml';
  8012. if ($newOnly) {
  8013. $taken = $this->usernameTaken((string)$child['Name'], $email);
  8014. if (!$taken) {
  8015. $results[] = array(
  8016. 'username' => (string)$child['Name'],
  8017. 'email' => $email
  8018. );
  8019. }
  8020. } else {
  8021. $results[] = array(
  8022. 'username' => (string)$child['Name'],
  8023. 'email' => $email,
  8024. );
  8025. }
  8026. }
  8027. return $results;
  8028. }
  8029. }
  8030. }
  8031. return false;
  8032. } catch (Requests_Exception $e) {
  8033. $this->writeLog('success', 'Emby Import User Function - Error: ' . $e->getMessage(), 'SYSTEM');
  8034. }
  8035. return false;
  8036. }
  8037. public function updateUser($id, $array)
  8038. {
  8039. if (!$id) {
  8040. $this->setAPIResponse('error', 'Id was not supplied', 422);
  8041. return false;
  8042. }
  8043. if ($id !== $this->user['userID']) {
  8044. if (!$this->qualifyRequest('1', true)) {
  8045. return false;
  8046. }
  8047. }
  8048. $user = $this->getUserById($id);
  8049. if ($user) {
  8050. $array = $this->checkKeys($user, $array);
  8051. } else {
  8052. $this->setAPIResponse('error', 'User was not found', 404);
  8053. return false;
  8054. }
  8055. if ($user['group_id'] == 0 && $this->user['groupID'] !== 0) {
  8056. $this->setAPIResponse('error', 'Cannot update admin unless you are admin', 401);
  8057. return false;
  8058. }
  8059. if (array_key_exists('username', $array)) {
  8060. if ($array['username'] == '') {
  8061. $this->setAPIResponse('error', 'Username was set but empty', 409);
  8062. return false;
  8063. }
  8064. if ($this->usernameTaken($array['username'], $array['username'], $id)) {
  8065. $this->setAPIResponse('error', 'Username: ' . $array['username'] . ' is already taken', 409);
  8066. return false;
  8067. }
  8068. }
  8069. if (array_key_exists('email', $array)) {
  8070. if ($array['email'] == '') {
  8071. $this->setAPIResponse('error', 'Email was set but empty', 409);
  8072. return false;
  8073. }
  8074. if ($this->usernameTaken($array['email'], $array['email'], $id)) {
  8075. $this->setAPIResponse('error', 'Email: ' . $array['email'] . ' is already taken', 409);
  8076. return false;
  8077. }
  8078. }
  8079. if (array_key_exists('group_id', $array)) {
  8080. if ($array['group_id'] == '') {
  8081. $this->setAPIResponse('error', 'group_id was set but empty', 409);
  8082. return false;
  8083. }
  8084. if (!$this->qualifyRequest('1', false)) {
  8085. $this->setAPIResponse('error', 'Cannot change your own group_id', 401);
  8086. return false;
  8087. }
  8088. if (($id == $this->user['userID']) && $this->user['groupID'] == 0) {
  8089. $array['group_id'] = 0;
  8090. }
  8091. if (($id == $this->user['userID']) && ($array['group_id'] == 0 && $this->user['groupID'] !== 0)) {
  8092. $this->setAPIResponse('error', 'Only admins can make others admins', 401);
  8093. return false;
  8094. }
  8095. $array['group'] = $this->getGroupByGroupId($array['group_id'])['group'];
  8096. if (!$array['group']) {
  8097. $this->setAPIResponse('error', 'group_id does not exist', 404);
  8098. return false;
  8099. }
  8100. }
  8101. if (array_key_exists('locked', $array)) {
  8102. $this->setAPIResponse('error', 'Cannot use endpoint to unlock or lock user - please use /users/{id}/lock', 409);
  8103. return false;
  8104. }
  8105. if (array_key_exists('password', $array)) {
  8106. if ($array['password'] == '') {
  8107. $this->setAPIResponse('error', 'Password was set but empty', 409);
  8108. return false;
  8109. }
  8110. $array['password'] = password_hash($array['password'], PASSWORD_BCRYPT);
  8111. }
  8112. if (array_key_exists('register_date', $array)) {
  8113. $this->setAPIResponse('error', 'Cannot update register date', 409);
  8114. return false;
  8115. }
  8116. $response = [
  8117. array(
  8118. 'function' => 'query',
  8119. 'query' => array(
  8120. 'UPDATE users SET',
  8121. $array,
  8122. 'WHERE id = ?',
  8123. $id
  8124. )
  8125. ),
  8126. ];
  8127. $this->setAPIResponse(null, 'User info updated');
  8128. $this->writeLog('success', 'User Editor Function - Updated User Info for [' . $user['username'] . ']', $this->user['username']);
  8129. return $this->processQueries($response);
  8130. }
  8131. public function deleteUser($id)
  8132. {
  8133. $response = [
  8134. array(
  8135. 'function' => 'query',
  8136. 'query' => array(
  8137. 'DELETE FROM users WHERE id = ?',
  8138. $id
  8139. )
  8140. ),
  8141. ];
  8142. $userInfo = $this->getUserById($id);
  8143. if ($userInfo) {
  8144. $this->writeLog('success', 'User Delete Function - Deleted User [' . $userInfo['username'] . ']', $this->user['username']);
  8145. $this->setAPIResponse('success', 'User deleted', 204);
  8146. return $this->processQueries($response);
  8147. } else {
  8148. $this->setAPIResponse('error', 'id not found', 404);
  8149. return false;
  8150. }
  8151. }
  8152. public function addUser($array)
  8153. {
  8154. $username = $array['username'] ?? null;
  8155. $password = $array['password'] ?? null;
  8156. $email = $array['email'] ?? null;
  8157. if (!$username) {
  8158. $this->setAPIResponse('error', 'Username was not supplied', 409);
  8159. return false;
  8160. }
  8161. if (!$password) {
  8162. $this->setAPIResponse('error', 'Password was not supplied', 409);
  8163. return false;
  8164. }
  8165. if ($this->createUser($username, $password, $email)) {
  8166. $this->writeLog('success', 'Create User Function - Account created for [' . $username . ']', $this->user['username']);
  8167. return true;
  8168. } else {
  8169. $this->writeLog('error', 'Create User Function - An error occurred', $this->user['username']);
  8170. return false;
  8171. }
  8172. }
  8173. public function createUser($username, $password, $email = null)
  8174. {
  8175. $username = $username ?? null;
  8176. $password = $password ?? null;
  8177. $email = ($email) ? $email : $this->random_ascii_string(10) . '@placeholder.eml';
  8178. if (!$username) {
  8179. $this->setAPIResponse('error', 'Username was set but empty', 409);
  8180. return false;
  8181. }
  8182. if (!$password) {
  8183. $this->setAPIResponse('error', 'Password was set but empty', 409);
  8184. return false;
  8185. }
  8186. if ($this->usernameTaken($username, $email)) {
  8187. $this->setAPIResponse('error', 'Username: ' . $username . ' or Email: ' . $email . ' is already taken', 409);
  8188. return false;
  8189. }
  8190. $defaults = $this->getDefaultGroup();
  8191. $userInfo = [
  8192. 'username' => $username,
  8193. 'password' => password_hash($password, PASSWORD_BCRYPT),
  8194. 'email' => $email,
  8195. 'group' => $defaults['group'],
  8196. 'group_id' => $defaults['group_id'],
  8197. 'image' => $this->gravatar($email),
  8198. 'register_date' => $this->currentTime,
  8199. ];
  8200. $response = [
  8201. array(
  8202. 'function' => 'query',
  8203. 'query' => array(
  8204. 'INSERT INTO [users]',
  8205. $userInfo
  8206. )
  8207. ),
  8208. ];
  8209. $this->setAPIResponse('success', 'User created', 200);
  8210. return $this->processQueries($response);
  8211. }
  8212. public function updateGroup($id, $array)
  8213. {
  8214. if (!$id || $id == '') {
  8215. $this->setAPIResponse('error', 'id was not set', 422);
  8216. return null;
  8217. }
  8218. if (!$array) {
  8219. $this->setAPIResponse('error', 'no data was sent', 422);
  8220. return null;
  8221. }
  8222. $groupInfo = $this->getGroupById($id);
  8223. if ($groupInfo) {
  8224. $array = $this->checkKeys($groupInfo, $array);
  8225. } else {
  8226. $this->setAPIResponse('error', 'No category info found', 404);
  8227. return false;
  8228. }
  8229. if (array_key_exists('group_id', $array)) {
  8230. $this->setAPIResponse('error', 'Cannot change group_id', 409);
  8231. return false;
  8232. }
  8233. if (array_key_exists('group', $array)) {
  8234. if ($array['group'] == '') {
  8235. $this->setAPIResponse('error', 'Group was set but empty', 409);
  8236. return false;
  8237. }
  8238. if ($this->isGroupNameTaken($array['group'], $id)) {
  8239. $this->setAPIResponse('error', 'Group name: ' . $array['group'] . ' is already taken', 409);
  8240. return false;
  8241. }
  8242. }
  8243. if (array_key_exists('image', $array)) {
  8244. if ($array['image'] == '') {
  8245. $this->setAPIResponse('error', 'Image was set but empty', 409);
  8246. return false;
  8247. }
  8248. }
  8249. if (array_key_exists('default', $array)) {
  8250. if ($groupInfo['group_id'] == 0 || $groupInfo['group_id'] == 999) {
  8251. $this->setAPIResponse('error', 'Setting ' . $groupInfo['group'] . ' as default group is not allowed', 409);
  8252. return false;
  8253. }
  8254. if ($array['default']) {
  8255. $this->clearGroupDefault();
  8256. $array['default'] = 1;
  8257. }
  8258. }
  8259. $response = [
  8260. array(
  8261. 'function' => 'query',
  8262. 'query' => array(
  8263. 'UPDATE groups SET',
  8264. $array,
  8265. 'WHERE id = ?',
  8266. $id
  8267. )
  8268. ),
  8269. ];
  8270. $this->setAPIResponse(null, 'Group info updated');
  8271. $this->writeLog('success', 'Group Editor Function - Edited Group Info for [' . $groupInfo['group'] . ']', $this->user['username']);
  8272. return $this->processQueries($response);
  8273. }
  8274. public function deleteGroup($id)
  8275. {
  8276. $response = [
  8277. array(
  8278. 'function' => 'query',
  8279. 'query' => array(
  8280. 'DELETE FROM groups WHERE id = ?',
  8281. $id
  8282. )
  8283. ),
  8284. ];
  8285. $groupInfo = $this->getGroupById($id);
  8286. if ($groupInfo['group_id'] == 0 || $groupInfo['group_id'] == 999) {
  8287. $this->setAPIResponse('error', 'Cannot delete group: ' . $groupInfo['group'] . ' as it is not allowed', 409);
  8288. return false;
  8289. }
  8290. if ($this->getGroupUserCountById($id) >= 1) {
  8291. $this->setAPIResponse('error', 'Cannot delete group as group still has users assigned to it', 409);
  8292. return false;
  8293. }
  8294. if ($groupInfo) {
  8295. $this->writeLog('success', 'Group Delete Function - Deleted Group [' . $groupInfo['group'] . ']', $this->user['username']);
  8296. $this->setAPIResponse('success', 'Group deleted', 204);
  8297. return $this->processQueries($response);
  8298. } else {
  8299. $this->setAPIResponse('error', 'id not found', 404);
  8300. return false;
  8301. }
  8302. }
  8303. public function addGroup($array)
  8304. {
  8305. if (!$array) {
  8306. $this->setAPIResponse('error', 'no data was sent', 422);
  8307. return null;
  8308. }
  8309. $array = $this->checkKeys($this->getTableColumnsFormatted('groups'), $array);
  8310. $array['default'] = ($array['default']) ?? 0;
  8311. $array['group_id'] = $this->getNextGroupOrder() + 1;
  8312. if (array_key_exists('group', $array)) {
  8313. if ($this->isGroupNameTaken($array['group'])) {
  8314. $this->setAPIResponse('error', 'Group name: ' . $array['group'] . ' is already taken', 409);
  8315. return false;
  8316. }
  8317. } else {
  8318. $this->setAPIResponse('error', 'Group name was not supplied', 422);
  8319. return false;
  8320. }
  8321. if (array_key_exists('image', $array)) {
  8322. if ($array['image'] == '') {
  8323. $this->setAPIResponse('error', 'Group image cannot be empty', 422);
  8324. return false;
  8325. }
  8326. } else {
  8327. $this->setAPIResponse('error', 'Group image was not supplied', 422);
  8328. return false;
  8329. }
  8330. $response = [
  8331. array(
  8332. 'function' => 'query',
  8333. 'query' => array(
  8334. 'INSERT INTO [groups]',
  8335. $array
  8336. )
  8337. ),
  8338. ];
  8339. $this->setAPIResponse(null, 'Tab added');
  8340. $this->writeLog('success', 'Tab Editor Function - Added Tab for [' . $array['name'] . ']', $this->user['username']);
  8341. return $this->processQueries($response);
  8342. }
  8343. public function userList($type = null)
  8344. {
  8345. switch ($type) {
  8346. case 'plex':
  8347. if (!empty($this->config['plexToken']) && !empty($this->config['plexID'])) {
  8348. $url = 'https://plex.tv/api/servers/' . $this->config['plexID'] . '/shared_servers';
  8349. try {
  8350. $headers = array(
  8351. "Accept" => "application/json",
  8352. "X-Plex-Token" => $this->config['plexToken']
  8353. );
  8354. $response = Requests::get($url, $headers, array());
  8355. libxml_use_internal_errors(true);
  8356. if ($response->success) {
  8357. $libraryList = array();
  8358. $plex = simplexml_load_string($response->body);
  8359. foreach ($plex->SharedServer as $child) {
  8360. if (!empty($child['username'])) {
  8361. $username = (string)strtolower($child['username']);
  8362. $email = (string)strtolower($child['email']);
  8363. $libraryList['users'][$username] = (string)$child['id'];
  8364. $libraryList['emails'][$email] = (string)$child['id'];
  8365. $libraryList['both'][$username] = $email;
  8366. }
  8367. }
  8368. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  8369. return $libraryList;
  8370. }
  8371. } catch (Requests_Exception $e) {
  8372. $this->writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  8373. }
  8374. }
  8375. break;
  8376. default:
  8377. # code...
  8378. break;
  8379. }
  8380. return false;
  8381. }
  8382. public function encrypt($password, $key = null)
  8383. {
  8384. $key = ($key) ? $key : ((isset($this->config['organizrHash'])) ? $this->config['organizrHash'] : null);
  8385. return openssl_encrypt($password, 'AES-256-CBC', $key, 0, $this->fillString($key, 16));
  8386. }
  8387. public function decrypt($password, $key = null)
  8388. {
  8389. if (empty($password)) {
  8390. return '';
  8391. }
  8392. $key = ($key) ? $key : ((isset($this->config['organizrHash'])) ? $this->config['organizrHash'] : null);
  8393. return openssl_decrypt($password, 'AES-256-CBC', $key, 0, $this->fillString($key, 16));
  8394. }
  8395. public function getCert()
  8396. {
  8397. $url = 'http://curl.haxx.se/ca/cacert.pem';
  8398. $file = dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'functions' . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'cacert.pem';
  8399. $file2 = dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'functions' . DIRECTORY_SEPARATOR . 'cert' . DIRECTORY_SEPARATOR . 'cacert-initial.pem';
  8400. $useCert = (file_exists($file)) ? $file : $file2;
  8401. if ($this->config['selfSignedCert'] !== '') {
  8402. if (file_exists($this->config['selfSignedCert'])) {
  8403. return $this->config['selfSignedCert'];
  8404. }
  8405. }
  8406. $context = stream_context_create(
  8407. array(
  8408. 'ssl' => array(
  8409. 'verify_peer' => true,
  8410. 'cafile' => $useCert
  8411. )
  8412. )
  8413. );
  8414. if (!file_exists($file)) {
  8415. file_put_contents($file, fopen($url, 'r', false, $context));
  8416. } elseif (file_exists($file) && time() - 2592000 > filemtime($file)) {
  8417. file_put_contents($file, fopen($url, 'r', false, $context));
  8418. }
  8419. return $file;
  8420. }
  8421. public function plexJoinAPI($array)
  8422. {
  8423. $username = ($array['username']) ?? null;
  8424. $email = ($array['email']) ?? null;
  8425. $password = ($array['password']) ?? null;
  8426. if (!$username) {
  8427. $this->setAPIResponse('error', 'Username not supplied', 409);
  8428. return false;
  8429. }
  8430. if (!$email) {
  8431. $this->setAPIResponse('error', 'Email not supplied', 409);
  8432. return false;
  8433. }
  8434. if (!$password) {
  8435. $this->setAPIResponse('error', 'Password not supplied', 409);
  8436. return false;
  8437. }
  8438. return $this->plexJoin($username, $email, $password);
  8439. }
  8440. public function plexJoin($username, $email, $password)
  8441. {
  8442. try {
  8443. $url = 'https://plex.tv/api/v2/users';
  8444. $headers = array(
  8445. 'Accept' => 'application/json',
  8446. 'Content-Type' => 'application/x-www-form-urlencoded',
  8447. 'X-Plex-Product' => 'Organizr',
  8448. 'X-Plex-Version' => '2.0',
  8449. 'X-Plex-Client-Identifier' => $this->config['uuid'],
  8450. );
  8451. $data = array(
  8452. 'email' => $email,
  8453. 'username' => $username,
  8454. 'password' => $password,
  8455. );
  8456. $response = Requests::post($url, $headers, $data, array());
  8457. $json = json_decode($response->body, true);
  8458. $errors = !empty($json['errors']);
  8459. $success = !empty($json['user']);
  8460. //Use This for later
  8461. $errorMessage = "";
  8462. if ($errors) {
  8463. foreach ($json['errors'] as $error) {
  8464. if (isset($error['message']) && isset($error['field'])) {
  8465. $errorMessage .= "[Plex.tv Error: " . $error['message'] . " for field: (" . $error['field'] . ")]";
  8466. }
  8467. }
  8468. }
  8469. $msg = (!empty($success) && empty($errors)) ? 'User has joined Plex' : $errorMessage;
  8470. $status = (!empty($success) && empty($errors)) ? 'success' : 'error';
  8471. $code = (!empty($success) && empty($errors)) ? 200 : 422;
  8472. $this->setAPIResponse($status, $msg, $code);
  8473. return (!empty($success) && empty($errors));
  8474. } catch (Requests_Exception $e) {
  8475. $this->writeLog('error', 'Plex.TV Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  8476. $this->setAPIResponse('error', 'An Error Occurred', 409);
  8477. return false;
  8478. }
  8479. return false;
  8480. }
  8481. public function lockCurrentUser()
  8482. {
  8483. if ($this->user['userID'] == '999') {
  8484. $this->setAPIResponse('error', 'Locking not allowed on Guest users', 409);
  8485. return false;
  8486. }
  8487. return $this->lockUser($this->user['userID']);
  8488. }
  8489. public function lockUser($id)
  8490. {
  8491. $user = $this->getUserById($id);
  8492. if (!$user) {
  8493. $this->setAPIResponse('error', 'User not found', 404);
  8494. return false;
  8495. }
  8496. $response = [
  8497. array(
  8498. 'function' => 'query',
  8499. 'query' => array(
  8500. 'UPDATE users SET',
  8501. ['locked' => '1'],
  8502. 'WHERE id = ?',
  8503. $id
  8504. )
  8505. ),
  8506. ];
  8507. $this->writeLog('success', 'User Lockout Function - User: ' . $user['username'] . ' account locked', $this->user['username']);
  8508. $this->setAPIResponse('success', 'User account locked', 200);
  8509. return $this->processQueries($response);
  8510. }
  8511. public function unlockCurrentUser($array)
  8512. {
  8513. if ($array['password'] == '') {
  8514. $this->setAPIResponse('error', 'Password Not Set', 422);
  8515. return false;
  8516. }
  8517. $user = $this->getUserById($this->user['userID']);
  8518. if (!password_verify($array['password'], $user['password'])) {
  8519. $this->setAPIResponse('error', 'Password Incorrect', 401);
  8520. return false;
  8521. }
  8522. return $this->unlockUser($this->user['userID']);
  8523. }
  8524. public function unlockUser($id)
  8525. {
  8526. $user = $this->getUserById($id);
  8527. if (!$user) {
  8528. $this->setAPIResponse('error', 'User not found', 404);
  8529. return false;
  8530. }
  8531. $response = [
  8532. array(
  8533. 'function' => 'query',
  8534. 'query' => array(
  8535. 'UPDATE users SET',
  8536. ['locked' => '0'],
  8537. 'WHERE id = ?',
  8538. $id
  8539. )
  8540. ),
  8541. ];
  8542. $this->writeLog('success', 'User Lockout Function - User: ' . $user['username'] . ' account unlocked', $this->user['username']);
  8543. $this->setAPIResponse('success', 'User account unlocked', 200);
  8544. return $this->processQueries($response);
  8545. }
  8546. public function youtubeSearch($query)
  8547. {
  8548. if (!$query) {
  8549. $this->setAPIResponse('error', 'No query supplied', 422);
  8550. return false;
  8551. }
  8552. $keys = array(
  8553. 'AIzaSyBsdt8nLJRMTwOq5PY5A5GLZ2q7scgn01w',
  8554. 'AIzaSyD-8SHutB60GCcSM8q_Fle38rJUV7ujd8k',
  8555. 'AIzaSyBzOpVBT6VII-b-8gWD0MOEosGg4hyhCsQ',
  8556. 'AIzaSyBKnRe1P8fpfBHgooJpmT0WOsrdUtZ4cpk'
  8557. );
  8558. $randomKeyIndex = array_rand($keys);
  8559. $key = $keys[$randomKeyIndex];
  8560. $apikey = ($this->config['youtubeAPI'] !== '') ? $this->config['youtubeAPI'] : $key;
  8561. $results = false;
  8562. $url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=$query+official+trailer&part=snippet&maxResults=1&type=video&videoDuration=short&key=$apikey";
  8563. $response = Requests::get($url);
  8564. if ($response->success) {
  8565. $results = json_decode($response->body, true);
  8566. $this->setAPIResponse('success', null, 200, $results);
  8567. return $results;
  8568. } else {
  8569. $this->setAPIResponse('error', 'Bad response from YouTube', 500);
  8570. return false;
  8571. }
  8572. }
  8573. public function scrapePage($array)
  8574. {
  8575. try {
  8576. $url = $array['url'] ?? false;
  8577. $type = $array['type'] ?? false;
  8578. if (!$url) {
  8579. $this->setAPIResponse('error', 'URL was not supplied', 422);
  8580. return false;
  8581. }
  8582. $url = $this->qualifyURL($url);
  8583. $data = array(
  8584. 'full_url' => $url,
  8585. 'drill_url' => $this->qualifyURL($url, true)
  8586. );
  8587. $options = array('verify' => false);
  8588. $response = Requests::get($url, array(), $options);
  8589. $data['response_code'] = $response->status_code;
  8590. if ($response->success) {
  8591. $data['result'] = 'Success';
  8592. switch ($type) {
  8593. case 'html':
  8594. $data['data'] = html_entity_decode($response->body);
  8595. break;
  8596. case 'json':
  8597. $data['data'] = json_decode($response->body);
  8598. break;
  8599. default:
  8600. $data['data'] = $response->body;
  8601. }
  8602. $this->setAPIResponse('success', null, 200, $data);
  8603. return $data;
  8604. } else {
  8605. $this->setAPIResponse('error', 'Error getting successful response', 500);
  8606. return false;
  8607. }
  8608. } catch (Requests_Exception $e) {
  8609. $this->setAPIResponse('error', $e->getMessage(), 500);
  8610. return false;
  8611. }
  8612. }
  8613. protected function processQueries(array $request, $migration = false)
  8614. {
  8615. $results = array();
  8616. $firstKey = '';
  8617. try {
  8618. foreach ($request as $k => $v) {
  8619. $query = ($migration) ? $this->otherDb->query($v['query']) : $this->db->query($v['query']);
  8620. $keyName = (isset($v['key'])) ? $v['key'] : $k;
  8621. $firstKey = (isset($v['key']) && $k == 0) ? $v['key'] : $k;
  8622. switch ($v['function']) {
  8623. case 'fetchAll':
  8624. $results[$keyName] = $query->fetchAll();
  8625. break;
  8626. case 'fetch':
  8627. $results[$keyName] = $query->fetch();
  8628. break;
  8629. case 'getAffectedRows':
  8630. $results[$keyName] = $query->getAffectedRows();
  8631. break;
  8632. case 'getRowCount':
  8633. $results[$keyName] = $query->getRowCount();
  8634. break;
  8635. case 'fetchSingle':
  8636. $results[$keyName] = $query->fetchSingle();
  8637. break;
  8638. case 'query':
  8639. $results[$keyName] = $query;
  8640. break;
  8641. default:
  8642. return false;
  8643. }
  8644. }
  8645. } catch (Exception $e) {
  8646. return $e;
  8647. }
  8648. return count($request) > 1 ? $results : $results[$firstKey];
  8649. }
  8650. }