admin.php 224 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595
  1. <?php
  2. //Default Configuration
  3. $CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":true,"hide_Cols":false,"theme":"dark"}';
  4. /**
  5. * H3K ~ Tiny File Manager V2.6
  6. * @author CCP Programmers
  7. * @github https://github.com/prasathmani/tinyfilemanager
  8. * @link https://tinyfilemanager.github.io
  9. */
  10. //TFM version
  11. define('VERSION', '2.6');
  12. //Application Title
  13. define('APP_TITLE', 'Tiny File Manager');
  14. // --- EDIT BELOW CONFIGURATION CAREFULLY ---
  15. // Auth with login/password
  16. // set true/false to enable/disable it
  17. // Is independent from IP white- and blacklisting
  18. $use_auth = true;
  19. // Login user name and password
  20. // Users: array('Username' => 'Password', 'Username2' => 'Password2', ...)
  21. // Generate secure password hash - https://tinyfilemanager.github.io/docs/pwd.html
  22. $auth_users = array(
  23. 'admin' => $2y$10$keX8TmH6rvOEdiJ3UVNRhuB9iSporfO.8zxdQlyJ6sZWkN.cH8ZCe,
  24. 'lakes' => $2y$10$keX8TmH6rvOEdiJ3UVNRhuB9iSporfO.8zxdQlyJ6sZWkN.cH8ZCe);
  25. // Readonly users
  26. // e.g. array('users', 'guest', ...)
  27. $readonly_users = array(
  28. 'user'
  29. );
  30. // Global readonly, including when auth is not being used
  31. $global_readonly = false;
  32. // user specific directories
  33. // array('Username' => 'Directory path', 'Username2' => 'Directory path', ...)
  34. $directories_users = array();
  35. // Enable highlight.js (https://highlightjs.org/) on view's page
  36. $use_highlightjs = true;
  37. // highlight.js style
  38. // for dark theme use 'ir-black'
  39. $highlightjs_style = 'vs';
  40. // Enable ace.js (https://ace.c9.io/) on view's page
  41. $edit_files = true;
  42. // Default timezone for date() and time()
  43. // Doc - http://php.net/manual/en/timezones.php
  44. $default_timezone = 'Etc/UTC'; // UTC
  45. // Root path for file manager
  46. // use absolute path of directory i.e: '/var/www/folder' or $_SERVER['DOCUMENT_ROOT'].'/folder'
  47. //make sure update $root_url in next section
  48. $root_path = $_SERVER['DOCUMENT_ROOT'];
  49. // Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
  50. // Will not working if $root_path will be outside of server document root
  51. $root_url = '';
  52. // Server hostname. Can set manually if wrong
  53. // $_SERVER['HTTP_HOST'].'/folder'
  54. $http_host = $_SERVER['HTTP_HOST'];
  55. // input encoding for iconv
  56. $iconv_input_encoding = 'UTF-8';
  57. // date() format for file modification date
  58. // Doc - https://www.php.net/manual/en/function.date.php
  59. $datetime_format = 'm/d/Y g:i A';
  60. // Path display mode when viewing file information
  61. // 'full' => show full path
  62. // 'relative' => show path relative to root_path
  63. // 'host' => show path on the host
  64. $path_display_mode = 'full';
  65. // Allowed file extensions for create and rename files
  66. // e.g. 'txt,html,css,js'
  67. $allowed_file_extensions = '';
  68. // Allowed file extensions for upload files
  69. // e.g. 'gif,png,jpg,html,txt'
  70. $allowed_upload_extensions = '';
  71. // Favicon path. This can be either a full url to an .PNG image, or a path based on the document root.
  72. // full path, e.g http://example.com/favicon.png
  73. // local path, e.g images/icons/favicon.png
  74. $favicon_path = '';
  75. // Files and folders to excluded from listing
  76. // e.g. array('myfile.html', 'personal-folder', '*.php', '/path/to/folder', ...)
  77. $exclude_items = array();
  78. // Online office Docs Viewer
  79. // Available rules are 'google', 'microsoft' or false
  80. // Google => View documents using Google Docs Viewer
  81. // Microsoft => View documents using Microsoft Web Apps Viewer
  82. // false => disable online doc viewer
  83. $online_viewer = 'google';
  84. // Sticky Nav bar
  85. // true => enable sticky header
  86. // false => disable sticky header
  87. $sticky_navbar = true;
  88. // Maximum file upload size
  89. // Increase the following values in php.ini to work properly
  90. // memory_limit, upload_max_filesize, post_max_size
  91. $max_upload_size_bytes = 5000000000; // size 5,000,000,000 bytes (~5GB)
  92. // chunk size used for upload
  93. // eg. decrease to 1MB if nginx reports problem 413 entity too large
  94. $upload_chunk_size_bytes = 2000000; // chunk size 2,000,000 bytes (~2MB)
  95. // Possible rules are 'OFF', 'AND' or 'OR'
  96. // OFF => Don't check connection IP, defaults to OFF
  97. // AND => Connection must be on the whitelist, and not on the blacklist
  98. // OR => Connection must be on the whitelist, or not on the blacklist
  99. $ip_ruleset = 'OFF';
  100. // Should users be notified of their block?
  101. $ip_silent = true;
  102. // IP-addresses, both ipv4 and ipv6
  103. $ip_whitelist = array(
  104. '127.0.0.1', // local ipv4
  105. '::1' // local ipv6
  106. );
  107. // IP-addresses, both ipv4 and ipv6
  108. $ip_blacklist = array(
  109. '0.0.0.0', // non-routable meta ipv4
  110. '::' // non-routable meta ipv6
  111. );
  112. // if User has the external config file, try to use it to override the default config above [config.php]
  113. // sample config - https://tinyfilemanager.github.io/config-sample.txt
  114. $config_file = __DIR__ . '/config.php';
  115. if (is_readable($config_file)) {
  116. @include($config_file);
  117. }
  118. // External CDN resources that can be used in the HTML (replace for GDPR compliance)
  119. $external = array(
  120. 'css-bootstrap' => '<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">',
  121. 'css-dropzone' => '<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.css" rel="stylesheet">',
  122. 'css-font-awesome' => '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" crossorigin="anonymous">',
  123. 'css-highlightjs' => '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/' . $highlightjs_style . '.min.css">',
  124. 'js-ace' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.2/ace.js"></script>',
  125. 'js-bootstrap' => '<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>',
  126. 'js-dropzone' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.js"></script>',
  127. 'js-jquery' => '<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>',
  128. 'js-jquery-datatables' => '<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js" crossorigin="anonymous" defer></script>',
  129. 'js-highlightjs' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>',
  130. 'pre-jsdelivr' => '<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin/><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"/>',
  131. 'pre-cloudflare' => '<link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin/><link rel="dns-prefetch" href="https://cdnjs.cloudflare.com"/>'
  132. );
  133. // --- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL ---
  134. // max upload file size
  135. define('MAX_UPLOAD_SIZE', $max_upload_size_bytes);
  136. // upload chunk size
  137. define('UPLOAD_CHUNK_SIZE', $upload_chunk_size_bytes);
  138. // private key and session name to store to the session
  139. if (!defined('FM_SESSION_ID')) {
  140. define('FM_SESSION_ID', 'filemanager');
  141. }
  142. // Configuration
  143. $cfg = new FM_Config();
  144. // Default language
  145. $lang = isset($cfg->data['lang']) ? $cfg->data['lang'] : 'en';
  146. // Show or hide files and folders that starts with a dot
  147. $show_hidden_files = isset($cfg->data['show_hidden']) ? $cfg->data['show_hidden'] : true;
  148. // PHP error reporting - false = Turns off Errors, true = Turns on Errors
  149. $report_errors = isset($cfg->data['error_reporting']) ? $cfg->data['error_reporting'] : true;
  150. // Hide Permissions and Owner cols in file-listing
  151. $hide_Cols = isset($cfg->data['hide_Cols']) ? $cfg->data['hide_Cols'] : true;
  152. // Theme
  153. $theme = isset($cfg->data['theme']) ? $cfg->data['theme'] : 'light';
  154. define('FM_THEME', $theme);
  155. //available languages
  156. $lang_list = array(
  157. 'en' => 'English'
  158. );
  159. if ($report_errors == true) {
  160. @ini_set('error_reporting', E_ALL);
  161. @ini_set('display_errors', 1);
  162. } else {
  163. @ini_set('error_reporting', E_ALL);
  164. @ini_set('display_errors', 0);
  165. }
  166. // if fm included
  167. if (defined('FM_EMBED')) {
  168. $use_auth = false;
  169. $sticky_navbar = false;
  170. } else {
  171. @set_time_limit(600);
  172. date_default_timezone_set($default_timezone);
  173. ini_set('default_charset', 'UTF-8');
  174. if (version_compare(PHP_VERSION, '5.6.0', '<') && function_exists('mb_internal_encoding')) {
  175. mb_internal_encoding('UTF-8');
  176. }
  177. if (function_exists('mb_regex_encoding')) {
  178. mb_regex_encoding('UTF-8');
  179. }
  180. session_cache_limiter('nocache'); // Prevent logout issue after page was cached
  181. session_name(FM_SESSION_ID);
  182. function session_error_handling_function($code, $msg, $file, $line)
  183. {
  184. // Permission denied for default session, try to create a new one
  185. if ($code == 2) {
  186. session_abort();
  187. session_id(session_create_id());
  188. @session_start();
  189. }
  190. }
  191. set_error_handler('session_error_handling_function');
  192. session_start();
  193. restore_error_handler();
  194. }
  195. //Generating CSRF Token
  196. if (empty($_SESSION['token'])) {
  197. if (function_exists('random_bytes')) {
  198. $_SESSION['token'] = bin2hex(random_bytes(32));
  199. } else {
  200. $_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(32));
  201. }
  202. }
  203. if (empty($auth_users)) {
  204. $use_auth = false;
  205. }
  206. $is_https = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1)
  207. || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
  208. // update $root_url based on user specific directories
  209. if (isset($_SESSION[FM_SESSION_ID]['logged']) && !empty($directories_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  210. $wd = fm_clean_path(dirname($_SERVER['PHP_SELF']));
  211. $root_url = $root_url . $wd . DIRECTORY_SEPARATOR . $directories_users[$_SESSION[FM_SESSION_ID]['logged']];
  212. }
  213. // clean $root_url
  214. $root_url = fm_clean_path($root_url);
  215. // abs path for site
  216. defined('FM_ROOT_URL') || define('FM_ROOT_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . (!empty($root_url) ? '/' . $root_url : ''));
  217. defined('FM_SELF_URL') || define('FM_SELF_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . $_SERVER['PHP_SELF']);
  218. // logout
  219. if (isset($_GET['logout'])) {
  220. unset($_SESSION[FM_SESSION_ID]['logged']);
  221. unset($_SESSION['token']);
  222. fm_redirect(FM_SELF_URL);
  223. }
  224. // Validate connection IP
  225. if ($ip_ruleset != 'OFF') {
  226. function getClientIP()
  227. {
  228. if (array_key_exists('HTTP_CF_CONNECTING_IP', $_SERVER)) {
  229. return $_SERVER["HTTP_CF_CONNECTING_IP"];
  230. } else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
  231. return $_SERVER["HTTP_X_FORWARDED_FOR"];
  232. } else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
  233. return $_SERVER['REMOTE_ADDR'];
  234. } else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
  235. return $_SERVER['HTTP_CLIENT_IP'];
  236. }
  237. return '';
  238. }
  239. $clientIp = getClientIP();
  240. $proceed = false;
  241. $whitelisted = in_array($clientIp, $ip_whitelist);
  242. $blacklisted = in_array($clientIp, $ip_blacklist);
  243. if ($ip_ruleset == 'AND') {
  244. if ($whitelisted == true && $blacklisted == false) {
  245. $proceed = true;
  246. }
  247. } else
  248. if ($ip_ruleset == 'OR') {
  249. if ($whitelisted == true || $blacklisted == false) {
  250. $proceed = true;
  251. }
  252. }
  253. if ($proceed == false) {
  254. trigger_error('User connection denied from: ' . $clientIp, E_USER_WARNING);
  255. if ($ip_silent == false) {
  256. fm_set_msg(lng('Access denied. IP restriction applicable'), 'error');
  257. fm_show_header_login();
  258. fm_show_message();
  259. }
  260. exit();
  261. }
  262. }
  263. // Checking if the user is logged in or not. If not, it will show the login form.
  264. if ($use_auth) {
  265. if (isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  266. // Logged
  267. } elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'], $_POST['token'])) {
  268. // Logging In
  269. sleep(1);
  270. if (function_exists('password_verify')) {
  271. if (isset($auth_users[$_POST['fm_usr']]) && isset($_POST['fm_pwd']) && password_verify($_POST['fm_pwd'], $auth_users[$_POST['fm_usr']]) && verifyToken($_POST['token'])) {
  272. $_SESSION[FM_SESSION_ID]['logged'] = $_POST['fm_usr'];
  273. fm_set_msg(lng('You are logged in'));
  274. fm_redirect(FM_SELF_URL);
  275. } else {
  276. unset($_SESSION[FM_SESSION_ID]['logged']);
  277. fm_set_msg(lng('Login failed. Invalid username or password'), 'error');
  278. fm_redirect(FM_SELF_URL);
  279. }
  280. } else {
  281. fm_set_msg(lng('password_hash not supported, Upgrade PHP version'), 'error');;
  282. }
  283. } else {
  284. // Form
  285. unset($_SESSION[FM_SESSION_ID]['logged']);
  286. fm_show_header_login();
  287. ?>
  288. <section class="h-100">
  289. <div class="container h-100">
  290. <div class="row justify-content-md-center align-content-center h-100vh">
  291. <div class="card-wrapper">
  292. <div class="card fat" data-bs-theme="<?php echo FM_THEME; ?>">
  293. <div class="card-body">
  294. <form class="form-signin" action="" method="post" autocomplete="off">
  295. <div class="mb-3">
  296. <div class="brand">
  297. <img src="https://computer.glamour.ovh/buttons/pc_glam.png" alt="Logo">
  298. </div>
  299. <div class="text-center">
  300. <h1 class="card-title"></h1>
  301. </div>
  302. </div>
  303. <hr />
  304. <div class="mb-3">
  305. <label for="fm_usr" class="pb-2"><?php echo lng('Username'); ?></label>
  306. <input type="text" class="form-control" id="fm_usr" name="fm_usr" required autofocus>
  307. </div>
  308. <div class="mb-3">
  309. <label for="fm_pwd" class="pb-2"><?php echo lng('Password'); ?></label>
  310. <input type="password" class="form-control" id="fm_pwd" name="fm_pwd" required>
  311. </div>
  312. <div class="mb-3">
  313. <?php fm_show_message(); ?>
  314. </div>
  315. <input type="hidden" name="token" value="<?php echo htmlentities($_SESSION['token']); ?>" />
  316. <div class="mb-3">
  317. <button type="submit" class="btn btn-success btn-block w-100 mt-4" role="button">
  318. <?php echo lng('Login'); ?>
  319. </div>
  320. </div>
  321. </form>
  322. </div>
  323. </div>
  324. <div class="footer text-center">
  325. Based on: <a href="https://tinyfilemanager.github.io/">tinyfilemanager.php</a>
  326. </div>
  327. </div>
  328. </div>
  329. </div>
  330. </section>
  331. <?php
  332. fm_show_footer_login();
  333. exit;
  334. }
  335. }
  336. // update root path
  337. if ($use_auth && isset($_SESSION[FM_SESSION_ID]['logged'])) {
  338. $root_path = isset($directories_users[$_SESSION[FM_SESSION_ID]['logged']]) ? $directories_users[$_SESSION[FM_SESSION_ID]['logged']] : $root_path;
  339. }
  340. // clean and check $root_path
  341. $root_path = rtrim($root_path, '\\/');
  342. $root_path = str_replace('\\', '/', $root_path);
  343. if (!@is_dir($root_path)) {
  344. echo "<h1>" . lng('Root path') . " \"{$root_path}\" " . lng('not found!') . " </h1>";
  345. exit;
  346. }
  347. defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $show_hidden_files);
  348. defined('FM_ROOT_PATH') || define('FM_ROOT_PATH', $root_path);
  349. defined('FM_LANG') || define('FM_LANG', $lang);
  350. defined('FM_FILE_EXTENSION') || define('FM_FILE_EXTENSION', $allowed_file_extensions);
  351. defined('FM_UPLOAD_EXTENSION') || define('FM_UPLOAD_EXTENSION', $allowed_upload_extensions);
  352. defined('FM_EXCLUDE_ITEMS') || define('FM_EXCLUDE_ITEMS', (version_compare(PHP_VERSION, '7.0.0', '<') ? serialize($exclude_items) : $exclude_items));
  353. defined('FM_DOC_VIEWER') || define('FM_DOC_VIEWER', $online_viewer);
  354. define('FM_READONLY', $global_readonly || ($use_auth && !empty($readonly_users) && isset($_SESSION[FM_SESSION_ID]['logged']) && in_array($_SESSION[FM_SESSION_ID]['logged'], $readonly_users)));
  355. define('FM_IS_WIN', DIRECTORY_SEPARATOR == '\\');
  356. // always use ?p=
  357. if (!isset($_GET['p']) && empty($_FILES)) {
  358. fm_redirect(FM_SELF_URL . '?p=');
  359. }
  360. // get path
  361. $p = isset($_GET['p']) ? $_GET['p'] : (isset($_POST['p']) ? $_POST['p'] : '');
  362. // clean path
  363. $p = fm_clean_path($p);
  364. // for ajax request - save
  365. $input = file_get_contents('php://input');
  366. $_POST = (strpos($input, 'ajax') != FALSE && strpos($input, 'save') != FALSE) ? json_decode($input, true) : $_POST;
  367. // instead globals vars
  368. define('FM_PATH', $p);
  369. define('FM_USE_AUTH', $use_auth);
  370. define('FM_EDIT_FILE', $edit_files);
  371. defined('FM_ICONV_INPUT_ENC') || define('FM_ICONV_INPUT_ENC', $iconv_input_encoding);
  372. defined('FM_USE_HIGHLIGHTJS') || define('FM_USE_HIGHLIGHTJS', $use_highlightjs);
  373. defined('FM_HIGHLIGHTJS_STYLE') || define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style);
  374. defined('FM_DATETIME_FORMAT') || define('FM_DATETIME_FORMAT', $datetime_format);
  375. unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style);
  376. /*************************** ACTIONS ***************************/
  377. // Handle all AJAX Request
  378. if ((isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']]) || !FM_USE_AUTH) && isset($_POST['ajax'], $_POST['token']) && !FM_READONLY) {
  379. if (!verifyToken($_POST['token'])) {
  380. header('HTTP/1.0 401 Unauthorized');
  381. die("Invalid Token.");
  382. }
  383. //search : get list of files from the current folder
  384. if (isset($_POST['type']) && $_POST['type'] == "search") {
  385. $dir = $_POST['path'] == "." ? '' : $_POST['path'];
  386. $response = scan(fm_clean_path($dir), $_POST['content']);
  387. echo json_encode($response);
  388. exit();
  389. }
  390. // save editor file
  391. if (isset($_POST['type']) && $_POST['type'] == "save") {
  392. // get current path
  393. $path = FM_ROOT_PATH;
  394. if (FM_PATH != '') {
  395. $path .= '/' . FM_PATH;
  396. }
  397. // check path
  398. if (!is_dir($path)) {
  399. fm_redirect(FM_SELF_URL . '?p=');
  400. }
  401. $file = $_GET['edit'];
  402. $file = fm_clean_path($file);
  403. $file = str_replace('/', '', $file);
  404. if ($file == '' || !is_file($path . '/' . $file)) {
  405. fm_set_msg(lng('File not found'), 'error');
  406. $FM_PATH = FM_PATH;
  407. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  408. }
  409. header('X-XSS-Protection:0');
  410. $file_path = $path . '/' . $file;
  411. $writedata = $_POST['content'];
  412. $fd = fopen($file_path, "w");
  413. $write_results = @fwrite($fd, $writedata);
  414. fclose($fd);
  415. if ($write_results === false) {
  416. header("HTTP/1.1 500 Internal Server Error");
  417. die("Could Not Write File! - Check Permissions / Ownership");
  418. }
  419. die(true);
  420. }
  421. // backup files
  422. if (isset($_POST['type']) && $_POST['type'] == "backup" && !empty($_POST['file'])) {
  423. $fileName = fm_clean_path($_POST['file']);
  424. $fullPath = FM_ROOT_PATH . '/';
  425. if (!empty($_POST['path'])) {
  426. $relativeDirPath = fm_clean_path($_POST['path']);
  427. $fullPath .= "{$relativeDirPath}/";
  428. }
  429. $date = date("dMy-His");
  430. $newFileName = "{$fileName}-{$date}.bak";
  431. $fullyQualifiedFileName = $fullPath . $fileName;
  432. try {
  433. if (!file_exists($fullyQualifiedFileName)) {
  434. throw new Exception("File {$fileName} not found");
  435. }
  436. if (copy($fullyQualifiedFileName, $fullPath . $newFileName)) {
  437. echo "Backup {$newFileName} created";
  438. } else {
  439. throw new Exception("Could not copy file {$fileName}");
  440. }
  441. } catch (Exception $e) {
  442. echo $e->getMessage();
  443. }
  444. }
  445. // Save Config
  446. if (isset($_POST['type']) && $_POST['type'] == "settings") {
  447. global $cfg, $lang, $report_errors, $show_hidden_files, $lang_list, $hide_Cols, $theme;
  448. $newLng = $_POST['js-language'];
  449. fm_get_translations([]);
  450. if (!array_key_exists($newLng, $lang_list)) {
  451. $newLng = 'en';
  452. }
  453. $erp = isset($_POST['js-error-report']) && $_POST['js-error-report'] == "true" ? true : false;
  454. $shf = isset($_POST['js-show-hidden']) && $_POST['js-show-hidden'] == "true" ? true : false;
  455. $hco = isset($_POST['js-hide-cols']) && $_POST['js-hide-cols'] == "true" ? true : false;
  456. $te3 = $_POST['js-theme-3'];
  457. if ($cfg->data['lang'] != $newLng) {
  458. $cfg->data['lang'] = $newLng;
  459. $lang = $newLng;
  460. }
  461. if ($cfg->data['error_reporting'] != $erp) {
  462. $cfg->data['error_reporting'] = $erp;
  463. $report_errors = $erp;
  464. }
  465. if ($cfg->data['show_hidden'] != $shf) {
  466. $cfg->data['show_hidden'] = $shf;
  467. $show_hidden_files = $shf;
  468. }
  469. if ($cfg->data['show_hidden'] != $shf) {
  470. $cfg->data['show_hidden'] = $shf;
  471. $show_hidden_files = $shf;
  472. }
  473. if ($cfg->data['hide_Cols'] != $hco) {
  474. $cfg->data['hide_Cols'] = $hco;
  475. $hide_Cols = $hco;
  476. }
  477. if ($cfg->data['theme'] != $te3) {
  478. $cfg->data['theme'] = $te3;
  479. $theme = $te3;
  480. }
  481. $cfg->save();
  482. echo true;
  483. }
  484. // new password hash
  485. if (isset($_POST['type']) && $_POST['type'] == "pwdhash") {
  486. $res = isset($_POST['inputPassword2']) && !empty($_POST['inputPassword2']) ? password_hash($_POST['inputPassword2'], PASSWORD_DEFAULT) : '';
  487. echo $res;
  488. }
  489. //upload using url
  490. if (isset($_POST['type']) && $_POST['type'] == "upload" && !empty($_REQUEST["uploadurl"])) {
  491. $path = FM_ROOT_PATH;
  492. if (FM_PATH != '') {
  493. $path .= '/' . FM_PATH;
  494. }
  495. function event_callback($message)
  496. {
  497. global $callback;
  498. echo json_encode($message);
  499. }
  500. function get_file_path()
  501. {
  502. global $path, $fileinfo, $temp_file;
  503. return $path . "/" . basename($fileinfo->name);
  504. }
  505. $url = !empty($_REQUEST["uploadurl"]) && preg_match("|^http(s)?://.+$|", stripslashes($_REQUEST["uploadurl"])) ? stripslashes($_REQUEST["uploadurl"]) : null;
  506. //prevent 127.* domain and known ports
  507. $domain = parse_url($url, PHP_URL_HOST);
  508. $port = parse_url($url, PHP_URL_PORT);
  509. $knownPorts = [22, 23, 25, 3306];
  510. if (preg_match("/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/i", $domain) || in_array($port, $knownPorts)) {
  511. $err = array("message" => "URL is not allowed");
  512. event_callback(array("fail" => $err));
  513. exit();
  514. }
  515. $use_curl = false;
  516. $temp_file = tempnam(sys_get_temp_dir(), "upload-");
  517. $fileinfo = new stdClass();
  518. $fileinfo->name = trim(urldecode(basename($url)), ".\x00..\x20");
  519. $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false;
  520. $ext = strtolower(pathinfo($fileinfo->name, PATHINFO_EXTENSION));
  521. $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  522. $err = false;
  523. if (!$isFileAllowed) {
  524. $err = array("message" => "File extension is not allowed");
  525. event_callback(array("fail" => $err));
  526. exit();
  527. }
  528. if (!$url) {
  529. $success = false;
  530. } else if ($use_curl) {
  531. @$fp = fopen($temp_file, "w");
  532. @$ch = curl_init($url);
  533. curl_setopt($ch, CURLOPT_NOPROGRESS, false);
  534. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  535. curl_setopt($ch, CURLOPT_FILE, $fp);
  536. @$success = curl_exec($ch);
  537. $curl_info = curl_getinfo($ch);
  538. if (!$success) {
  539. $err = array("message" => curl_error($ch));
  540. }
  541. @curl_close($ch);
  542. fclose($fp);
  543. $fileinfo->size = $curl_info["size_download"];
  544. $fileinfo->type = $curl_info["content_type"];
  545. } else {
  546. $ctx = stream_context_create();
  547. @$success = copy($url, $temp_file, $ctx);
  548. if (!$success) {
  549. $err = error_get_last();
  550. }
  551. }
  552. if ($success) {
  553. $success = rename($temp_file, strtok(get_file_path(), '?'));
  554. }
  555. if ($success) {
  556. event_callback(array("done" => $fileinfo));
  557. } else {
  558. unlink($temp_file);
  559. if (!$err) {
  560. $err = array("message" => "Invalid url parameter");
  561. }
  562. event_callback(array("fail" => $err));
  563. }
  564. }
  565. exit();
  566. }
  567. // Delete file / folder
  568. if (isset($_GET['del'], $_POST['token']) && !FM_READONLY) {
  569. $del = str_replace('/', '', fm_clean_path($_GET['del']));
  570. if ($del != '' && $del != '..' && $del != '.' && verifyToken($_POST['token'])) {
  571. $path = FM_ROOT_PATH;
  572. if (FM_PATH != '') {
  573. $path .= '/' . FM_PATH;
  574. }
  575. $is_dir = is_dir($path . '/' . $del);
  576. if (fm_rdelete($path . '/' . $del)) {
  577. $msg = $is_dir ? lng('Folder') . ' <b>%s</b> ' . lng('Deleted') : lng('File') . ' <b>%s</b> ' . lng('Deleted');
  578. fm_set_msg(sprintf($msg, fm_enc($del)));
  579. } else {
  580. $msg = $is_dir ? lng('Folder') . ' <b>%s</b> ' . lng('not deleted') : lng('File') . ' <b>%s</b> ' . lng('not deleted');
  581. fm_set_msg(sprintf($msg, fm_enc($del)), 'error');
  582. }
  583. } else {
  584. fm_set_msg(lng('Invalid file or folder name'), 'error');
  585. }
  586. $FM_PATH = FM_PATH;
  587. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  588. }
  589. // Create a new file/folder
  590. if (isset($_POST['newfilename'], $_POST['newfile'], $_POST['token']) && !FM_READONLY) {
  591. $type = urldecode($_POST['newfile']);
  592. $new = str_replace('/', '', fm_clean_path(strip_tags($_POST['newfilename'])));
  593. if (fm_isvalid_filename($new) && $new != '' && $new != '..' && $new != '.' && verifyToken($_POST['token'])) {
  594. $path = FM_ROOT_PATH;
  595. if (FM_PATH != '') {
  596. $path .= '/' . FM_PATH;
  597. }
  598. if ($type == "file") {
  599. if (!file_exists($path . '/' . $new)) {
  600. if (fm_is_valid_ext($new)) {
  601. @fopen($path . '/' . $new, 'w') or die('Cannot open file: ' . $new);
  602. fm_set_msg(sprintf(lng('File') . ' <b>%s</b> ' . lng('Created'), fm_enc($new)));
  603. } else {
  604. fm_set_msg(lng('File extension is not allowed'), 'error');
  605. }
  606. } else {
  607. fm_set_msg(sprintf(lng('File') . ' <b>%s</b> ' . lng('already exists'), fm_enc($new)), 'alert');
  608. }
  609. } else {
  610. if (fm_mkdir($path . '/' . $new, false) === true) {
  611. fm_set_msg(sprintf(lng('Folder') . ' <b>%s</b> ' . lng('Created'), $new));
  612. } elseif (fm_mkdir($path . '/' . $new, false) === $path . '/' . $new) {
  613. fm_set_msg(sprintf(lng('Folder') . ' <b>%s</b> ' . lng('already exists'), fm_enc($new)), 'alert');
  614. } else {
  615. fm_set_msg(sprintf(lng('Folder') . ' <b>%s</b> ' . lng('not created'), fm_enc($new)), 'error');
  616. }
  617. }
  618. } else {
  619. fm_set_msg(lng('Invalid characters in file or folder name'), 'error');
  620. }
  621. $FM_PATH = FM_PATH;
  622. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  623. }
  624. // Copy folder / file
  625. if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
  626. // from
  627. $copy = urldecode($_GET['copy']);
  628. $copy = fm_clean_path($copy);
  629. // empty path
  630. if ($copy == '') {
  631. fm_set_msg(lng('Source path not defined'), 'error');
  632. $FM_PATH = FM_PATH;
  633. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  634. }
  635. // abs path from
  636. $from = FM_ROOT_PATH . '/' . $copy;
  637. // abs path to
  638. $dest = FM_ROOT_PATH;
  639. if (FM_PATH != '') {
  640. $dest .= '/' . FM_PATH;
  641. }
  642. $dest .= '/' . basename($from);
  643. // move?
  644. $move = isset($_GET['move']);
  645. $move = fm_clean_path(urldecode($move));
  646. // copy/move/duplicate
  647. if ($from != $dest) {
  648. $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  649. if ($move) { // Move and to != from so just perform move
  650. $rename = fm_rename($from, $dest);
  651. if ($rename) {
  652. fm_set_msg(sprintf(lng('Moved from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  653. } elseif ($rename === null) {
  654. fm_set_msg(lng('File or folder with this path already exists'), 'alert');
  655. } else {
  656. fm_set_msg(sprintf(lng('Error while moving from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)), 'error');
  657. }
  658. } else { // Not move and to != from so copy with original name
  659. if (fm_rcopy($from, $dest)) {
  660. fm_set_msg(sprintf(lng('Copied from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  661. } else {
  662. fm_set_msg(sprintf(lng('Error while copying from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)), 'error');
  663. }
  664. }
  665. } else {
  666. if (!$move) { //Not move and to = from so duplicate
  667. $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  668. $fn_parts = pathinfo($from);
  669. $extension_suffix = '';
  670. if (!is_dir($from)) {
  671. $extension_suffix = '.' . $fn_parts['extension'];
  672. }
  673. //Create new name for duplicate
  674. $fn_duplicate = $fn_parts['dirname'] . '/' . $fn_parts['filename'] . '-' . date('YmdHis') . $extension_suffix;
  675. $loop_count = 0;
  676. $max_loop = 1000;
  677. // Check if a file with the duplicate name already exists, if so, make new name (edge case...)
  678. while (file_exists($fn_duplicate) & $loop_count < $max_loop) {
  679. $fn_parts = pathinfo($fn_duplicate);
  680. $fn_duplicate = $fn_parts['dirname'] . '/' . $fn_parts['filename'] . '-copy' . $extension_suffix;
  681. $loop_count++;
  682. }
  683. if (fm_rcopy($from, $fn_duplicate, False)) {
  684. fm_set_msg(sprintf('Copied from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($fn_duplicate)));
  685. } else {
  686. fm_set_msg(sprintf('Error while copying from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($fn_duplicate)), 'error');
  687. }
  688. } else {
  689. fm_set_msg(lng('Paths must be not equal'), 'alert');
  690. }
  691. }
  692. $FM_PATH = FM_PATH;
  693. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  694. }
  695. // Mass copy files/ folders
  696. if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish'], $_POST['token']) && !FM_READONLY) {
  697. if (!verifyToken($_POST['token'])) {
  698. fm_set_msg(lng('Invalid Token.'), 'error');
  699. }
  700. // from
  701. $path = FM_ROOT_PATH;
  702. if (FM_PATH != '') {
  703. $path .= '/' . FM_PATH;
  704. }
  705. // to
  706. $copy_to_path = FM_ROOT_PATH;
  707. $copy_to = fm_clean_path($_POST['copy_to']);
  708. if ($copy_to != '') {
  709. $copy_to_path .= '/' . $copy_to;
  710. }
  711. if ($path == $copy_to_path) {
  712. fm_set_msg(lng('Paths must be not equal'), 'alert');
  713. $FM_PATH = FM_PATH;
  714. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  715. }
  716. if (!is_dir($copy_to_path)) {
  717. if (!fm_mkdir($copy_to_path, true)) {
  718. fm_set_msg('Unable to create destination folder', 'error');
  719. $FM_PATH = FM_PATH;
  720. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  721. }
  722. }
  723. // move?
  724. $move = isset($_POST['move']);
  725. // copy/move
  726. $errors = 0;
  727. $files = $_POST['file'];
  728. if (is_array($files) && count($files)) {
  729. foreach ($files as $f) {
  730. if ($f != '') {
  731. $f = fm_clean_path($f);
  732. // abs path from
  733. $from = $path . '/' . $f;
  734. // abs path to
  735. $dest = $copy_to_path . '/' . $f;
  736. // do
  737. if ($move) {
  738. $rename = fm_rename($from, $dest);
  739. if ($rename === false) {
  740. $errors++;
  741. }
  742. } else {
  743. if (!fm_rcopy($from, $dest)) {
  744. $errors++;
  745. }
  746. }
  747. }
  748. }
  749. if ($errors == 0) {
  750. $msg = $move ? 'Selected files and folders moved' : 'Selected files and folders copied';
  751. fm_set_msg($msg);
  752. } else {
  753. $msg = $move ? 'Error while moving items' : 'Error while copying items';
  754. fm_set_msg($msg, 'error');
  755. }
  756. } else {
  757. fm_set_msg(lng('Nothing selected'), 'alert');
  758. }
  759. $FM_PATH = FM_PATH;
  760. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  761. }
  762. // Rename
  763. if (isset($_POST['rename_from'], $_POST['rename_to'], $_POST['token']) && !FM_READONLY) {
  764. if (!verifyToken($_POST['token'])) {
  765. fm_set_msg("Invalid Token.", 'error');
  766. }
  767. // old name
  768. $old = urldecode($_POST['rename_from']);
  769. $old = fm_clean_path($old);
  770. $old = str_replace('/', '', $old);
  771. // new name
  772. $new = urldecode($_POST['rename_to']);
  773. $new = fm_clean_path(strip_tags($new));
  774. $new = str_replace('/', '', $new);
  775. // path
  776. $path = FM_ROOT_PATH;
  777. if (FM_PATH != '') {
  778. $path .= '/' . FM_PATH;
  779. }
  780. // rename
  781. if (fm_isvalid_filename($new) && $old != '' && $new != '') {
  782. if (fm_rename($path . '/' . $old, $path . '/' . $new)) {
  783. fm_set_msg(sprintf(lng('Renamed from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($old), fm_enc($new)));
  784. } else {
  785. fm_set_msg(sprintf(lng('Error while renaming from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($old), fm_enc($new)), 'error');
  786. }
  787. } else {
  788. fm_set_msg(lng('Invalid characters in file name'), 'error');
  789. }
  790. $FM_PATH = FM_PATH;
  791. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  792. }
  793. // Download
  794. if (isset($_GET['dl'], $_POST['token'])) {
  795. // Verify the token to ensure it's valid
  796. if (!verifyToken($_POST['token'])) {
  797. fm_set_msg("Invalid Token.", 'error');
  798. exit;
  799. }
  800. // Clean the download file path
  801. $dl = urldecode($_GET['dl']);
  802. $dl = fm_clean_path($dl);
  803. $dl = str_replace('/', '', $dl); // Prevent directory traversal attacks
  804. // Define the file path
  805. $path = FM_ROOT_PATH;
  806. if (FM_PATH != '') {
  807. $path .= '/' . FM_PATH;
  808. }
  809. // Check if the file exists and is valid
  810. if ($dl != '' && is_file($path . '/' . $dl)) {
  811. // Close the session to prevent session locking
  812. if (session_status() === PHP_SESSION_ACTIVE) {
  813. session_write_close();
  814. }
  815. // Call the download function
  816. fm_download_file($path . '/' . $dl, $dl, 1024); // Download with a buffer size of 1024 bytes
  817. exit;
  818. } else {
  819. // Handle the case where the file is not found
  820. fm_set_msg(lng('File not found'), 'error');
  821. $FM_PATH = FM_PATH;
  822. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  823. }
  824. }
  825. // Upload
  826. if (!empty($_FILES) && !FM_READONLY) {
  827. if (isset($_POST['token'])) {
  828. if (!verifyToken($_POST['token'])) {
  829. $response = array('status' => 'error', 'info' => "Invalid Token.");
  830. echo json_encode($response);
  831. exit();
  832. }
  833. } else {
  834. $response = array('status' => 'error', 'info' => "Token Missing.");
  835. echo json_encode($response);
  836. exit();
  837. }
  838. $chunkIndex = $_POST['dzchunkindex'];
  839. $chunkTotal = $_POST['dztotalchunkcount'];
  840. $fullPathInput = fm_clean_path($_REQUEST['fullpath']);
  841. $f = $_FILES;
  842. $path = FM_ROOT_PATH;
  843. $ds = DIRECTORY_SEPARATOR;
  844. if (FM_PATH != '') {
  845. $path .= '/' . FM_PATH;
  846. }
  847. $errors = 0;
  848. $uploads = 0;
  849. $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false;
  850. $response = array(
  851. 'status' => 'error',
  852. 'info' => 'Oops! Try again'
  853. );
  854. $filename = $f['file']['name'];
  855. $tmp_name = $f['file']['tmp_name'];
  856. $ext = pathinfo($filename, PATHINFO_FILENAME) != '' ? strtolower(pathinfo($filename, PATHINFO_EXTENSION)) : '';
  857. $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  858. if (!fm_isvalid_filename($filename) && !fm_isvalid_filename($fullPathInput)) {
  859. $response = array(
  860. 'status' => 'error',
  861. 'info' => "Invalid File name!",
  862. );
  863. echo json_encode($response);
  864. exit();
  865. }
  866. $targetPath = $path . $ds;
  867. if (is_writable($targetPath)) {
  868. $fullPath = $path . '/' . $fullPathInput;
  869. $folder = substr($fullPath, 0, strrpos($fullPath, "/"));
  870. if (!is_dir($folder)) {
  871. $old = umask(0);
  872. mkdir($folder, 0777, true);
  873. umask($old);
  874. }
  875. if (empty($f['file']['error']) && !empty($tmp_name) && $tmp_name != 'none' && $isFileAllowed) {
  876. if ($chunkTotal) {
  877. $out = @fopen("{$fullPath}.part", $chunkIndex == 0 ? "wb" : "ab");
  878. if ($out) {
  879. $in = @fopen($tmp_name, "rb");
  880. if ($in) {
  881. if (PHP_VERSION_ID < 80009) {
  882. // workaround https://bugs.php.net/bug.php?id=81145
  883. do {
  884. for (;;) {
  885. $buff = fread($in, 4096);
  886. if ($buff === false || $buff === '') {
  887. break;
  888. }
  889. fwrite($out, $buff);
  890. }
  891. } while (!feof($in));
  892. } else {
  893. stream_copy_to_stream($in, $out);
  894. }
  895. $response = array(
  896. 'status' => 'success',
  897. 'info' => "file upload successful"
  898. );
  899. } else {
  900. $response = array(
  901. 'status' => 'error',
  902. 'info' => "failed to open output stream",
  903. 'errorDetails' => error_get_last()
  904. );
  905. }
  906. @fclose($in);
  907. @fclose($out);
  908. @unlink($tmp_name);
  909. $response = array(
  910. 'status' => 'success',
  911. 'info' => "file upload successful"
  912. );
  913. } else {
  914. $response = array(
  915. 'status' => 'error',
  916. 'info' => "failed to open output stream"
  917. );
  918. }
  919. if ($chunkIndex == $chunkTotal - 1) {
  920. if (file_exists($fullPath)) {
  921. $ext_1 = $ext ? '.' . $ext : '';
  922. $fullPathTarget = $path . '/' . basename($fullPathInput, $ext_1) . '_' . date('ymdHis') . $ext_1;
  923. } else {
  924. $fullPathTarget = $fullPath;
  925. }
  926. rename("{$fullPath}.part", $fullPathTarget);
  927. }
  928. } else if (move_uploaded_file($tmp_name, $fullPath)) {
  929. // Be sure that the file has been uploaded
  930. if (file_exists($fullPath)) {
  931. $response = array(
  932. 'status' => 'success',
  933. 'info' => "file upload successful"
  934. );
  935. } else {
  936. $response = array(
  937. 'status' => 'error',
  938. 'info' => 'Couldn\'t upload the requested file.'
  939. );
  940. }
  941. } else {
  942. $response = array(
  943. 'status' => 'error',
  944. 'info' => "Error while uploading files. Uploaded files $uploads",
  945. );
  946. }
  947. }
  948. } else {
  949. $response = array(
  950. 'status' => 'error',
  951. 'info' => 'The specified folder for upload isn\'t writeable.'
  952. );
  953. }
  954. // Return the response
  955. echo json_encode($response);
  956. exit();
  957. }
  958. // Mass deleting
  959. if (isset($_POST['group'], $_POST['delete'], $_POST['token']) && !FM_READONLY) {
  960. if (!verifyToken($_POST['token'])) {
  961. fm_set_msg(lng("Invalid Token."), 'error');
  962. }
  963. $path = FM_ROOT_PATH;
  964. if (FM_PATH != '') {
  965. $path .= '/' . FM_PATH;
  966. }
  967. $errors = 0;
  968. $files = $_POST['file'];
  969. if (is_array($files) && count($files)) {
  970. foreach ($files as $f) {
  971. if ($f != '') {
  972. $new_path = $path . '/' . $f;
  973. if (!fm_rdelete($new_path)) {
  974. $errors++;
  975. }
  976. }
  977. }
  978. if ($errors == 0) {
  979. fm_set_msg(lng('Selected files and folder deleted'));
  980. } else {
  981. fm_set_msg(lng('Error while deleting items'), 'error');
  982. }
  983. } else {
  984. fm_set_msg(lng('Nothing selected'), 'alert');
  985. }
  986. $FM_PATH = FM_PATH;
  987. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  988. }
  989. // Pack files zip, tar
  990. if (isset($_POST['group'], $_POST['token']) && (isset($_POST['zip']) || isset($_POST['tar'])) && !FM_READONLY) {
  991. if (!verifyToken($_POST['token'])) {
  992. fm_set_msg(lng("Invalid Token."), 'error');
  993. }
  994. $path = FM_ROOT_PATH;
  995. $ext = 'zip';
  996. if (FM_PATH != '') {
  997. $path .= '/' . FM_PATH;
  998. }
  999. //set pack type
  1000. $ext = isset($_POST['tar']) ? 'tar' : 'zip';
  1001. if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  1002. fm_set_msg(lng('Operations with archives are not available'), 'error');
  1003. $FM_PATH = FM_PATH;
  1004. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1005. }
  1006. $files = $_POST['file'];
  1007. $sanitized_files = array();
  1008. // clean path
  1009. foreach ($files as $file) {
  1010. array_push($sanitized_files, fm_clean_path($file));
  1011. }
  1012. $files = $sanitized_files;
  1013. if (!empty($files)) {
  1014. chdir($path);
  1015. if (count($files) == 1) {
  1016. $one_file = reset($files);
  1017. $one_file = basename($one_file);
  1018. $zipname = $one_file . '_' . date('ymd_His') . '.' . $ext;
  1019. } else {
  1020. $zipname = 'archive_' . date('ymd_His') . '.' . $ext;
  1021. }
  1022. if ($ext == 'zip') {
  1023. $zipper = new FM_Zipper();
  1024. $res = $zipper->create($zipname, $files);
  1025. } elseif ($ext == 'tar') {
  1026. $tar = new FM_Zipper_Tar();
  1027. $res = $tar->create($zipname, $files);
  1028. }
  1029. if ($res) {
  1030. fm_set_msg(sprintf(lng('Archive') . ' <b>%s</b> ' . lng('Created'), fm_enc($zipname)));
  1031. } else {
  1032. fm_set_msg(lng('Archive not created'), 'error');
  1033. }
  1034. } else {
  1035. fm_set_msg(lng('Nothing selected'), 'alert');
  1036. }
  1037. $FM_PATH = FM_PATH;
  1038. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1039. }
  1040. // Unpack zip, tar
  1041. if (isset($_POST['unzip'], $_POST['token']) && !FM_READONLY) {
  1042. if (!verifyToken($_POST['token'])) {
  1043. fm_set_msg(lng("Invalid Token."), 'error');
  1044. }
  1045. $unzip = urldecode($_POST['unzip']);
  1046. $unzip = fm_clean_path($unzip);
  1047. $unzip = str_replace('/', '', $unzip);
  1048. $isValid = false;
  1049. $path = FM_ROOT_PATH;
  1050. if (FM_PATH != '') {
  1051. $path .= '/' . FM_PATH;
  1052. }
  1053. if ($unzip != '' && is_file($path . '/' . $unzip)) {
  1054. $zip_path = $path . '/' . $unzip;
  1055. $ext = pathinfo($zip_path, PATHINFO_EXTENSION);
  1056. $isValid = true;
  1057. } else {
  1058. fm_set_msg(lng('File not found'), 'error');
  1059. }
  1060. if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  1061. fm_set_msg(lng('Operations with archives are not available'), 'error');
  1062. $FM_PATH = FM_PATH;
  1063. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1064. }
  1065. if ($isValid) {
  1066. //to folder
  1067. $tofolder = '';
  1068. if (isset($_POST['tofolder'])) {
  1069. $tofolder = pathinfo($zip_path, PATHINFO_FILENAME);
  1070. if (fm_mkdir($path . '/' . $tofolder, true)) {
  1071. $path .= '/' . $tofolder;
  1072. }
  1073. }
  1074. if ($ext == "zip") {
  1075. $zipper = new FM_Zipper();
  1076. $res = $zipper->unzip($zip_path, $path);
  1077. } elseif ($ext == "tar") {
  1078. try {
  1079. $gzipper = new PharData($zip_path);
  1080. if (@$gzipper->extractTo($path, null, true)) {
  1081. $res = true;
  1082. } else {
  1083. $res = false;
  1084. }
  1085. } catch (Exception $e) {
  1086. //TODO:: need to handle the error
  1087. $res = true;
  1088. }
  1089. }
  1090. if ($res) {
  1091. fm_set_msg(lng('Archive unpacked'));
  1092. } else {
  1093. fm_set_msg(lng('Archive not unpacked'), 'error');
  1094. }
  1095. } else {
  1096. fm_set_msg(lng('File not found'), 'error');
  1097. }
  1098. $FM_PATH = FM_PATH;
  1099. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1100. }
  1101. // Change Perms (not for Windows)
  1102. if (isset($_POST['chmod'], $_POST['token']) && !FM_READONLY && !FM_IS_WIN) {
  1103. if (!verifyToken($_POST['token'])) {
  1104. fm_set_msg(lng("Invalid Token."), 'error');
  1105. }
  1106. $path = FM_ROOT_PATH;
  1107. if (FM_PATH != '') {
  1108. $path .= '/' . FM_PATH;
  1109. }
  1110. $file = $_POST['chmod'];
  1111. $file = fm_clean_path($file);
  1112. $file = str_replace('/', '', $file);
  1113. if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  1114. fm_set_msg(lng('File not found'), 'error');
  1115. $FM_PATH = FM_PATH;
  1116. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1117. }
  1118. $mode = 0;
  1119. if (!empty($_POST['ur'])) {
  1120. $mode |= 0400;
  1121. }
  1122. if (!empty($_POST['uw'])) {
  1123. $mode |= 0200;
  1124. }
  1125. if (!empty($_POST['ux'])) {
  1126. $mode |= 0100;
  1127. }
  1128. if (!empty($_POST['gr'])) {
  1129. $mode |= 0040;
  1130. }
  1131. if (!empty($_POST['gw'])) {
  1132. $mode |= 0020;
  1133. }
  1134. if (!empty($_POST['gx'])) {
  1135. $mode |= 0010;
  1136. }
  1137. if (!empty($_POST['or'])) {
  1138. $mode |= 0004;
  1139. }
  1140. if (!empty($_POST['ow'])) {
  1141. $mode |= 0002;
  1142. }
  1143. if (!empty($_POST['ox'])) {
  1144. $mode |= 0001;
  1145. }
  1146. if (@chmod($path . '/' . $file, $mode)) {
  1147. fm_set_msg(lng('Permissions changed'));
  1148. } else {
  1149. fm_set_msg(lng('Permissions not changed'), 'error');
  1150. }
  1151. $FM_PATH = FM_PATH;
  1152. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1153. }
  1154. /*************************** ACTIONS ***************************/
  1155. // get current path
  1156. $path = FM_ROOT_PATH;
  1157. if (FM_PATH != '') {
  1158. $path .= '/' . FM_PATH;
  1159. }
  1160. // check path
  1161. if (!is_dir($path)) {
  1162. fm_redirect(FM_SELF_URL . '?p=');
  1163. }
  1164. // get parent folder
  1165. $parent = fm_get_parent_path(FM_PATH);
  1166. $objects = is_readable($path) ? scandir($path) : array();
  1167. $folders = array();
  1168. $files = array();
  1169. $current_path = array_slice(explode("/", $path), -1)[0];
  1170. if (is_array($objects) && fm_is_exclude_items($current_path, $path)) {
  1171. foreach ($objects as $file) {
  1172. if ($file == '.' || $file == '..') {
  1173. continue;
  1174. }
  1175. if (!FM_SHOW_HIDDEN && substr($file, 0, 1) === '.') {
  1176. continue;
  1177. }
  1178. $new_path = $path . '/' . $file;
  1179. if (@is_file($new_path) && fm_is_exclude_items($file, $new_path)) {
  1180. $files[] = $file;
  1181. } elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file, $new_path)) {
  1182. $folders[] = $file;
  1183. }
  1184. }
  1185. }
  1186. if (!empty($files)) {
  1187. natcasesort($files);
  1188. }
  1189. if (!empty($folders)) {
  1190. natcasesort($folders);
  1191. }
  1192. // upload form
  1193. if (isset($_GET['upload']) && !FM_READONLY) {
  1194. fm_show_header(); // HEADER
  1195. fm_show_nav_path(FM_PATH); // current path
  1196. //get the allowed file extensions
  1197. function getUploadExt()
  1198. {
  1199. $extArr = explode(',', FM_UPLOAD_EXTENSION);
  1200. if (FM_UPLOAD_EXTENSION && $extArr) {
  1201. array_walk($extArr, function (&$x) {
  1202. $x = ".$x";
  1203. });
  1204. return implode(',', $extArr);
  1205. }
  1206. return '';
  1207. }
  1208. ?>
  1209. <?php print_external('css-dropzone'); ?>
  1210. <div class="path">
  1211. <div class="card mb-2 fm-upload-wrapper" data-bs-theme="<?php echo FM_THEME; ?>">
  1212. <div class="card-header">
  1213. <ul class="nav nav-tabs card-header-tabs">
  1214. <li class="nav-item">
  1215. <a class="nav-link active" href="#fileUploader" data-target="#fileUploader"><i class="fa fa-arrow-circle-o-up"></i> <?php echo lng('UploadingFiles') ?></a>
  1216. </li>
  1217. <li class="nav-item">
  1218. <a class="nav-link" href="#urlUploader" class="js-url-upload" data-target="#urlUploader"><i class="fa fa-link"></i> <?php echo lng('Upload from URL') ?></a>
  1219. </li>
  1220. </ul>
  1221. </div>
  1222. <div class="card-body">
  1223. <p class="card-text">
  1224. <a href="?p=<?php echo FM_PATH ?>" class="float-right"><i class="fa fa-chevron-circle-left go-back"></i> <?php echo lng('Back') ?></a>
  1225. <strong><?php echo lng('DestinationFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_PATH)) ?>
  1226. </p>
  1227. <form action="<?php echo htmlspecialchars(FM_SELF_URL) . '?p=' . fm_enc(FM_PATH) ?>" class="dropzone card-tabs-container" id="fileUploader" enctype="multipart/form-data">
  1228. <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1229. <input type="hidden" name="fullpath" id="fullpath" value="<?php echo fm_enc(FM_PATH) ?>">
  1230. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1231. <div class="fallback">
  1232. <input name="file" type="file" multiple />
  1233. </div>
  1234. </form>
  1235. <div class="upload-url-wrapper card-tabs-container hidden" id="urlUploader">
  1236. <form id="js-form-url-upload" class="row row-cols-lg-auto g-3 align-items-center" onsubmit="return upload_from_url(this);" method="POST" action="">
  1237. <input type="hidden" name="type" value="upload" aria-label="hidden" aria-hidden="true">
  1238. <input type="url" placeholder="URL" name="uploadurl" required class="form-control" style="width: 80%">
  1239. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1240. <button type="submit" class="btn btn-primary ms-3"><?php echo lng('Upload') ?></div>
  1241. <div class="lds-facebook">
  1242. <div></div>
  1243. <div></div>
  1244. <div></div>
  1245. </div>
  1246. </form>
  1247. <div id="js-url-upload__list" class="col-9 mt-3"></div>
  1248. </div>
  1249. </div>
  1250. </div>
  1251. </div>
  1252. <?php print_external('js-dropzone'); ?>
  1253. <script>
  1254. Dropzone.options.fileUploader = {
  1255. chunking: true,
  1256. chunkSize: <?php echo UPLOAD_CHUNK_SIZE; ?>,
  1257. forceChunking: true,
  1258. retryChunks: true,
  1259. retryChunksLimit: 3,
  1260. parallelUploads: 1,
  1261. parallelChunkUploads: false,
  1262. timeout: 120000,
  1263. maxFilesize: "<?php echo MAX_UPLOAD_SIZE; ?>",
  1264. acceptedFiles: "<?php echo getUploadExt() ?>",
  1265. init: function() {
  1266. this.on("sending", function(file, xhr, formData) {
  1267. let _path = (file.fullPath) ? file.fullPath : file.name;
  1268. document.getElementById("fullpath").value = _path;
  1269. xhr.ontimeout = (function() {
  1270. toast('Error: Server Timeout');
  1271. });
  1272. }).on("success", function(res) {
  1273. try {
  1274. let _response = JSON.parse(res.xhr.response);
  1275. if (_response.status == "error") {
  1276. toast(_response.info);
  1277. }
  1278. } catch (e) {
  1279. toast("Error: Invalid JSON response");
  1280. }
  1281. }).on("error", function(file, response) {
  1282. toast(response);
  1283. });
  1284. }
  1285. }
  1286. </script>
  1287. <?php
  1288. fm_show_footer();
  1289. exit;
  1290. }
  1291. // copy form POST
  1292. if (isset($_POST['copy']) && !FM_READONLY) {
  1293. $copy_files = isset($_POST['file']) ? $_POST['file'] : null;
  1294. if (!is_array($copy_files) || empty($copy_files)) {
  1295. fm_set_msg(lng('Nothing selected'), 'alert');
  1296. $FM_PATH = FM_PATH;
  1297. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1298. }
  1299. fm_show_header(); // HEADER
  1300. fm_show_nav_path(FM_PATH); // current path
  1301. ?>
  1302. <div class="path">
  1303. <div class="card" data-bs-theme="<?php echo FM_THEME; ?>">
  1304. <div class="card-header">
  1305. <h6><?php echo lng('Copying') ?></h6>
  1306. </div>
  1307. <div class="card-body">
  1308. <form action="" method="post">
  1309. <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1310. <input type="hidden" name="finish" value="1">
  1311. <?php
  1312. foreach ($copy_files as $cf) {
  1313. echo '<input type="hidden" name="file[]" value="' . fm_enc($cf) . '">' . PHP_EOL;
  1314. }
  1315. ?>
  1316. <p class="break-word"><strong><?php echo lng('Files') ?></strong>: <b><?php echo implode('</b>, <b>', $copy_files) ?></b></p>
  1317. <p class="break-word"><strong><?php echo lng('SourceFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?><br>
  1318. <label for="inp_copy_to"><strong><?php echo lng('DestinationFolder') ?></strong>:</label>
  1319. <?php echo FM_ROOT_PATH ?>/<input type="text" name="copy_to" id="inp_copy_to" value="<?php echo fm_enc(FM_PATH) ?>">
  1320. </p>
  1321. <p class="custom-checkbox custom-control"><input type="checkbox" name="move" value="1" id="js-move-files" class="custom-control-input">
  1322. <label for="js-move-files" class="custom-control-label ms-2"><?php echo lng('Move') ?></label>
  1323. </p>
  1324. <p>
  1325. <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="btn btn-outline-danger"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></a></b>&nbsp;
  1326. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1327. <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Copy') ?></div>
  1328. </p>
  1329. </form>
  1330. </div>
  1331. </div>
  1332. </div>
  1333. <?php
  1334. fm_show_footer();
  1335. exit;
  1336. }
  1337. // copy form
  1338. if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
  1339. $copy = $_GET['copy'];
  1340. $copy = fm_clean_path($copy);
  1341. if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) {
  1342. fm_set_msg(lng('File not found'), 'error');
  1343. $FM_PATH = FM_PATH;
  1344. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1345. }
  1346. fm_show_header(); // HEADER
  1347. fm_show_nav_path(FM_PATH); // current path
  1348. ?>
  1349. <div class="path">
  1350. <p><b>Copying</b></p>
  1351. <p class="break-word">
  1352. <strong>Source path:</strong> <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . $copy)) ?><br>
  1353. <strong>Destination folder:</strong> <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?>
  1354. </p>
  1355. <p>
  1356. <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode($copy) ?>&amp;finish=1"><i class="fa fa-check-circle"></i> Copy</a></b> &nbsp;
  1357. <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode($copy) ?>&amp;finish=1&amp;move=1"><i class="fa fa-check-circle"></i> Move</a></b> &nbsp;
  1358. <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="text-danger"><i class="fa fa-times-circle"></i> Cancel</a></b>
  1359. </p>
  1360. <p><i><?php echo lng('Select folder') ?></i></p>
  1361. <ul class="folders break-word">
  1362. <?php
  1363. if ($parent !== false) {
  1364. ?>
  1365. <li><a href="?p=<?php echo urlencode($parent) ?>&amp;copy=<?php echo urlencode($copy) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></li>
  1366. <?php
  1367. }
  1368. foreach ($folders as $f) {
  1369. ?>
  1370. <li>
  1371. <a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>&amp;copy=<?php echo urlencode($copy) ?>"><i class="fa fa-folder-o"></i> <?php echo fm_convert_win($f) ?></a>
  1372. </li>
  1373. <?php
  1374. }
  1375. ?>
  1376. </ul>
  1377. </div>
  1378. <?php
  1379. fm_show_footer();
  1380. exit;
  1381. }
  1382. if (isset($_GET['settings']) && !FM_READONLY) {
  1383. fm_show_header(); // HEADER
  1384. fm_show_nav_path(FM_PATH); // current path
  1385. global $cfg, $lang, $lang_list;
  1386. ?>
  1387. <div class="col-md-8 offset-md-2 pt-3">
  1388. <div class="card mb-2" data-bs-theme="<?php echo FM_THEME; ?>">
  1389. <h6 class="card-header d-flex justify-content-between">
  1390. <span><i class="fa fa-cog"></i> <?php echo lng('Settings') ?></span>
  1391. <a href="?p=<?php echo FM_PATH ?>" class="text-danger"><i class="fa fa-times-circle-o"></i> <?php echo lng('Cancel') ?></a>
  1392. </h6>
  1393. <div class="card-body">
  1394. <form id="js-settings-form" action="" method="post" data-type="ajax" onsubmit="return save_settings(this)">
  1395. <input type="hidden" name="type" value="settings" aria-label="hidden" aria-hidden="true">
  1396. <div class="form-group row">
  1397. <label for="js-language" class="col-sm-3 col-form-label"><?php echo lng('Language') ?></label>
  1398. <div class="col-sm-5">
  1399. <select class="form-select" id="js-language" name="js-language">
  1400. <?php
  1401. function getSelected($l)
  1402. {
  1403. global $lang;
  1404. return ($lang == $l) ? 'selected' : '';
  1405. }
  1406. foreach ($lang_list as $k => $v) {
  1407. echo "<option value='$k' " . getSelected($k) . ">$v</option>";
  1408. }
  1409. ?>
  1410. </select>
  1411. </div>
  1412. </div>
  1413. <div class="mt-3 mb-3 row ">
  1414. <label for="js-error-report" class="col-sm-3 col-form-label"><?php echo lng('ErrorReporting') ?></label>
  1415. <div class="col-sm-9">
  1416. <div class="form-check form-switch">
  1417. <input class="form-check-input" type="checkbox" role="switch" id="js-error-report" name="js-error-report" value="true" <?php echo $report_errors ? 'checked' : ''; ?> />
  1418. </div>
  1419. </div>
  1420. </div>
  1421. <div class="mb-3 row">
  1422. <label for="js-show-hidden" class="col-sm-3 col-form-label"><?php echo lng('ShowHiddenFiles') ?></label>
  1423. <div class="col-sm-9">
  1424. <div class="form-check form-switch">
  1425. <input class="form-check-input" type="checkbox" role="switch" id="js-show-hidden" name="js-show-hidden" value="true" <?php echo $show_hidden_files ? 'checked' : ''; ?> />
  1426. </div>
  1427. </div>
  1428. </div>
  1429. <div class="mb-3 row">
  1430. <label for="js-hide-cols" class="col-sm-3 col-form-label"><?php echo lng('HideColumns') ?></label>
  1431. <div class="col-sm-9">
  1432. <div class="form-check form-switch">
  1433. <input class="form-check-input" type="checkbox" role="switch" id="js-hide-cols" name="js-hide-cols" value="true" <?php echo $hide_Cols ? 'checked' : ''; ?> />
  1434. </div>
  1435. </div>
  1436. </div>
  1437. <div class="mb-3 row">
  1438. <label for="js-3-1" class="col-sm-3 col-form-label"><?php echo lng('Theme') ?></label>
  1439. <div class="col-sm-5">
  1440. <select class="form-select w-100 text-capitalize" id="js-3-0" name="js-theme-3">
  1441. <option value='light' <?php if ($theme == "light") {
  1442. echo "selected";
  1443. } ?>>
  1444. <?php echo lng('light') ?>
  1445. </option>
  1446. <option value='dark' <?php if ($theme == "dark") {
  1447. echo "selected";
  1448. } ?>>
  1449. <?php echo lng('dark') ?>
  1450. </option>
  1451. </select>
  1452. </div>
  1453. </div>
  1454. <div class="mb-3 row">
  1455. <div class="col-sm-10">
  1456. <button type="submit" class="btn btn-success"> <i class="fa fa-check-circle"></i> <?php echo lng('Save'); ?></div>
  1457. </div>
  1458. </div>
  1459. <small class="text-body-secondary">* <?php echo lng('Sometimes the save action may not work on the first try, so please attempt it again') ?>.</span>
  1460. </form>
  1461. </div>
  1462. </div>
  1463. </div>
  1464. <?php
  1465. fm_show_footer();
  1466. exit;
  1467. }
  1468. if (isset($_GET['help'])) {
  1469. fm_show_header(); // HEADER
  1470. fm_show_nav_path(FM_PATH); // current path
  1471. global $cfg, $lang;
  1472. ?>
  1473. <div class="col-md-8 offset-md-2 pt-3">
  1474. <div class="card mb-2" data-bs-theme="<?php echo FM_THEME; ?>">
  1475. <h6 class="card-header d-flex justify-content-between">
  1476. <span><i class="fa fa-exclamation-circle"></i> <?php echo lng('Help') ?></span>
  1477. <a href="?p=<?php echo FM_PATH ?>" class="text-danger"><i class="fa fa-times-circle-o"></i> <?php echo lng('Cancel') ?></a>
  1478. </h6>
  1479. <div class="card-body">
  1480. <div class="row">
  1481. <div class="col-xs-12 col-sm-6">
  1482. <p>
  1483. <h3><a href="https://github.com/prasathmani/tinyfilemanager" target="_blank" class="app-v-title"> Tiny File Manager <?php echo VERSION; ?></a></h3>
  1484. </p>
  1485. <p>Author: PRAŚATH MANİ</p>
  1486. <p>Mail Us: <a href="mailto:ccpprogrammers@gmail.com">ccpprogrammers [at] gmail [dot] com</a> </p>
  1487. </div>
  1488. <div class="col-xs-12 col-sm-6">
  1489. <div class="card">
  1490. <ul class="list-group list-group-flush">
  1491. <li class="list-group-item"><a href="https://github.com/prasathmani/tinyfilemanager/wiki" target="_blank"><i class="fa fa-question-circle"></i> <?php echo lng('Help Documents') ?> </a> </li>
  1492. <li class="list-group-item"><a href="https://github.com/prasathmani/tinyfilemanager/issues" target="_blank"><i class="fa fa-bug"></i> <?php echo lng('Report Issue') ?></a></li>
  1493. <?php if (!FM_READONLY) { ?>
  1494. <li class="list-group-item"><a href="javascript:show_new_pwd();"><i class="fa fa-lock"></i> <?php echo lng('Generate new password hash') ?></a></li>
  1495. <?php } ?>
  1496. </ul>
  1497. </div>
  1498. </div>
  1499. </div>
  1500. <div class="row js-new-pwd hidden mt-2">
  1501. <div class="col-12">
  1502. <form class="form-inline" onsubmit="return new_password_hash(this)" method="POST" action="">
  1503. <input type="hidden" name="type" value="pwdhash" aria-label="hidden" aria-hidden="true">
  1504. <div class="form-group mb-2">
  1505. <label for="staticEmail2"><?php echo lng('Generate new password hash') ?></label>
  1506. </div>
  1507. <div class="form-group mx-sm-3 mb-2">
  1508. <label for="inputPassword2" class="sr-only"><?php echo lng('Password') ?></label>
  1509. <input type="text" class="form-control btn-sm" id="inputPassword2" name="inputPassword2" placeholder="<?php echo lng('Password') ?>" required>
  1510. </div>
  1511. <button type="submit" class="btn btn-success btn-sm mb-2"><?php echo lng('Generate') ?></div>
  1512. </form>
  1513. <textarea class="form-control" rows="2" readonly id="js-pwd-result"></textarea>
  1514. </div>
  1515. </div>
  1516. </div>
  1517. </div>
  1518. </div>
  1519. <?php
  1520. fm_show_footer();
  1521. exit;
  1522. }
  1523. // file viewer
  1524. if (isset($_GET['view'])) {
  1525. $file = $_GET['view'];
  1526. $file = fm_clean_path($file, false);
  1527. $file = str_replace('/', '', $file);
  1528. if ($file == '' || !is_file($path . '/' . $file) || !fm_is_exclude_items($file, $path . '/' . $file)) {
  1529. fm_set_msg(lng('File not found'), 'error');
  1530. $FM_PATH = FM_PATH;
  1531. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1532. }
  1533. fm_show_header(); // HEADER
  1534. fm_show_nav_path(FM_PATH); // current path
  1535. $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1536. $file_path = $path . '/' . $file;
  1537. $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1538. $mime_type = fm_get_mime_type($file_path);
  1539. $filesize_raw = fm_get_size($file_path);
  1540. $filesize = fm_get_filesize($filesize_raw);
  1541. $is_zip = false;
  1542. $is_gzip = false;
  1543. $is_image = false;
  1544. $is_audio = false;
  1545. $is_video = false;
  1546. $is_text = false;
  1547. $is_onlineViewer = false;
  1548. $view_title = 'File';
  1549. $filenames = false; // for zip
  1550. $content = ''; // for text
  1551. $online_viewer = strtolower(FM_DOC_VIEWER);
  1552. if ($online_viewer && $online_viewer !== 'false' && in_array($ext, fm_get_onlineViewer_exts())) {
  1553. $is_onlineViewer = true;
  1554. } elseif ($ext == 'zip' || $ext == 'tar') {
  1555. $is_zip = true;
  1556. $view_title = 'Archive';
  1557. $filenames = fm_get_zif_info($file_path, $ext);
  1558. } elseif (in_array($ext, fm_get_image_exts())) {
  1559. $is_image = true;
  1560. $view_title = 'Image';
  1561. } elseif (in_array($ext, fm_get_audio_exts())) {
  1562. $is_audio = true;
  1563. $view_title = 'Audio';
  1564. } elseif (in_array($ext, fm_get_video_exts())) {
  1565. $is_video = true;
  1566. $view_title = 'Video';
  1567. } elseif (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1568. $is_text = true;
  1569. $content = file_get_contents($file_path);
  1570. }
  1571. ?>
  1572. <div class="row">
  1573. <div class="col-12">
  1574. <ul class="list-group w-50 my-3" data-bs-theme="<?php echo FM_THEME; ?>">
  1575. <li class="list-group-item active" aria-current="true"><strong><?php echo lng($view_title) ?>:</strong> <?php echo fm_enc(fm_convert_win($file)) ?></li>
  1576. <?php $display_path = fm_get_display_path($file_path); ?>
  1577. <li class="list-group-item"><strong><?php echo $display_path['label']; ?>:</strong> <?php echo $display_path['path']; ?></li>
  1578. <li class="list-group-item"><strong><?php echo lng('Date Modified') ?>:</strong> <?php echo date(FM_DATETIME_FORMAT, filemtime($file_path)); ?></li>
  1579. <li class="list-group-item"><strong><?php echo lng('File size') ?>:</strong> <?php echo ($filesize_raw <= 1000) ? "$filesize_raw bytes" : $filesize; ?></li>
  1580. <li class="list-group-item"><strong><?php echo lng('MIME-type') ?>:</strong> <?php echo $mime_type ?></li>
  1581. <?php
  1582. // ZIP info
  1583. if (($is_zip || $is_gzip) && $filenames !== false) {
  1584. $total_files = 0;
  1585. $total_comp = 0;
  1586. $total_uncomp = 0;
  1587. foreach ($filenames as $fn) {
  1588. if (!$fn['folder']) {
  1589. $total_files++;
  1590. }
  1591. $total_comp += $fn['compressed_size'];
  1592. $total_uncomp += $fn['filesize'];
  1593. }
  1594. ?>
  1595. <li class="list-group-item"><?php echo lng('Files in archive') ?>: <?php echo $total_files ?></li>
  1596. <li class="list-group-item"><?php echo lng('Total size') ?>: <?php echo fm_get_filesize($total_uncomp) ?></li>
  1597. <li class="list-group-item"> <?php echo lng('Size in archive') ?>: <?php echo fm_get_filesize($total_comp) ?></li>
  1598. <li class="list-group-item"><?php echo lng('Compression') ?>: <?php echo round(($total_comp / max($total_uncomp, 1)) * 100) ?>%</li>
  1599. <?php
  1600. }
  1601. // Image info
  1602. if ($is_image) {
  1603. $image_size = getimagesize($file_path);
  1604. echo '<li class="list-group-item"><strong>' . lng('Image size') . ':</strong> ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '</li>';
  1605. }
  1606. // Text info
  1607. if ($is_text) {
  1608. $is_utf8 = fm_is_utf8($content);
  1609. if (function_exists('iconv')) {
  1610. if (!$is_utf8) {
  1611. $content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content);
  1612. }
  1613. }
  1614. echo '<li class="list-group-item"><strong>' . lng('Charset') . ':</strong> ' . ($is_utf8 ? 'utf-8' : '8 bit') . '</li>';
  1615. }
  1616. ?>
  1617. </ul>
  1618. <div class="btn-group btn-group-sm flex-wrap" role="group">
  1619. <form method="post" class="d-inline mb-0 btn btn-outline-primary" action="?p=<?php echo urlencode(FM_PATH) ?>&amp;dl=<?php echo urlencode($file) ?>">
  1620. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1621. <button type="submit" class="btn btn-link btn-sm text-decoration-none fw-bold p-0"><i class="fa fa-cloud-download"></i> <?php echo lng('Download') ?></div> &nbsp;
  1622. </form>
  1623. <?php if (!FM_READONLY): ?>
  1624. <a class="fw-bold btn btn-outline-primary" title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($file) ?>" onclick="confirmDailog(event, 1209, '<?php echo lng('Delete') . ' ' . lng('File'); ?>','<?php echo urlencode($file); ?>', this.href);"> <i class="fa fa-trash"></i> Delete</a>
  1625. <?php endif; ?>
  1626. <a class="fw-bold btn btn-outline-primary" href="<?php echo fm_enc($file_url) ?>" target="_blank"><i class="fa fa-external-link-square"></i> <?php echo lng('Open') ?></a></b>
  1627. <?php
  1628. // ZIP actions
  1629. if (!FM_READONLY && ($is_zip || $is_gzip) && $filenames !== false) {
  1630. $zip_name = pathinfo($file_path, PATHINFO_FILENAME);
  1631. ?>
  1632. <form method="post" class="d-inline btn btn-outline-primary mb-0">
  1633. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1634. <input type="hidden" name="unzip" value="<?php echo urlencode($file); ?>">
  1635. <button type="submit" class="btn btn-link text-decoration-none fw-bold p-0 border-0" style="font-size: 14px;"><i class="fa fa-check-circle"></i> <?php echo lng('UnZip') ?></div>
  1636. </form>
  1637. <form method="post" class="d-inline btn btn-outline-primary mb-0">
  1638. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1639. <input type="hidden" name="unzip" value="<?php echo urlencode($file); ?>">
  1640. <input type="hidden" name="tofolder" value="1">
  1641. <button type="submit" class="btn btn-link text-decoration-none fw-bold p-0" style="font-size: 14px;" title="UnZip to <?php echo fm_enc($zip_name) ?>"><i class="fa fa-check-circle"></i> <?php echo lng('UnZipToFolder') ?></div>
  1642. </form>
  1643. <?php
  1644. }
  1645. if ($is_text && !FM_READONLY) {
  1646. ?>
  1647. <a class="fw-bold btn btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>" class="edit-file">
  1648. <i class="fa fa-pencil-square"></i> <?php echo lng('Edit') ?>
  1649. </a>
  1650. <a class="fw-bold btn btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>&env=ace"
  1651. class="edit-file"><i class="fa fa-pencil-square"></i> <?php echo lng('AdvancedEditor') ?>
  1652. </a>
  1653. <?php } ?>
  1654. <a class="fw-bold btn btn-outline-primary" href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-chevron-circle-left go-back"></i> <?php echo lng('Back') ?></a>
  1655. </div>
  1656. <div class="row mt-3">
  1657. <?php
  1658. if ($is_onlineViewer) {
  1659. if ($online_viewer == 'google') {
  1660. echo '<iframe src="https://docs.google.com/viewer?embedded=true&hl=en&url=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px"></iframe>';
  1661. } else if ($online_viewer == 'microsoft') {
  1662. echo '<iframe src="https://view.officeapps.live.com/op/embed.aspx?src=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px"></iframe>';
  1663. }
  1664. } elseif ($is_zip) {
  1665. // ZIP content
  1666. if ($filenames !== false) {
  1667. echo '<code class="maxheight">';
  1668. foreach ($filenames as $fn) {
  1669. if ($fn['folder']) {
  1670. echo '<b>' . fm_enc($fn['name']) . '</b><br>';
  1671. } else {
  1672. echo $fn['name'] . ' (' . fm_get_filesize($fn['filesize']) . ')<br>';
  1673. }
  1674. }
  1675. echo '</code>';
  1676. } else {
  1677. echo '<p>' . lng('Error while fetching archive info') . '</p>';
  1678. }
  1679. } elseif ($is_image) {
  1680. // Image content
  1681. if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))) {
  1682. echo '<p><input type="checkbox" id="preview-img-zoomCheck"><label for="preview-img-zoomCheck"><img src="' . fm_enc($file_url) . '" alt="image" class="preview-img"></label></p>';
  1683. }
  1684. } elseif ($is_audio) {
  1685. // Audio content
  1686. echo '<p><audio src="' . fm_enc($file_url) . '" controls preload="metadata"></audio></p>';
  1687. } elseif ($is_video) {
  1688. // Video content
  1689. echo '<div class="preview-video"><video src="' . fm_enc($file_url) . '" width="640" height="360" controls preload="metadata"></video></div>';
  1690. } elseif ($is_text) {
  1691. if (FM_USE_HIGHLIGHTJS) {
  1692. // highlight
  1693. $hljs_classes = array(
  1694. 'shtml' => 'xml',
  1695. 'htaccess' => 'apache',
  1696. 'phtml' => 'php',
  1697. 'lock' => 'json',
  1698. 'svg' => 'xml',
  1699. );
  1700. $hljs_class = isset($hljs_classes[$ext]) ? 'lang-' . $hljs_classes[$ext] : 'lang-' . $ext;
  1701. if (empty($ext) || in_array(strtolower($file), fm_get_text_names()) || preg_match('#\.min\.(css|js)$#i', $file)) {
  1702. $hljs_class = 'nohighlight';
  1703. }
  1704. $content = '<pre class="with-hljs"><code class="' . $hljs_class . '">' . fm_enc($content) . '</code></pre>';
  1705. } elseif (in_array($ext, array('php', 'php4', 'php5', 'phtml', 'phps'))) {
  1706. // php highlight
  1707. $content = highlight_string($content, true);
  1708. } else {
  1709. $content = '<pre>' . fm_enc($content) . '</pre>';
  1710. }
  1711. echo $content;
  1712. }
  1713. ?>
  1714. </div>
  1715. </div>
  1716. </div>
  1717. <?php
  1718. fm_show_footer();
  1719. exit;
  1720. }
  1721. // file editor
  1722. if (isset($_GET['edit']) && !FM_READONLY) {
  1723. $file = $_GET['edit'];
  1724. $file = fm_clean_path($file, false);
  1725. $file = str_replace('/', '', $file);
  1726. if ($file == '' || !is_file($path . '/' . $file) || !fm_is_exclude_items($file, $path . '/' . $file)) {
  1727. fm_set_msg(lng('File not found'), 'error');
  1728. $FM_PATH = FM_PATH;
  1729. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1730. }
  1731. $editFile = ' : <i><b>' . $file . '</b></i>';
  1732. header('X-XSS-Protection:0');
  1733. fm_show_header(); // HEADER
  1734. fm_show_nav_path(FM_PATH); // current path
  1735. $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1736. $file_path = $path . '/' . $file;
  1737. // normal editer
  1738. $isNormalEditor = true;
  1739. if (isset($_GET['env'])) {
  1740. if ($_GET['env'] == "ace") {
  1741. $isNormalEditor = false;
  1742. }
  1743. }
  1744. // Save File
  1745. if (isset($_POST['savedata'])) {
  1746. $writedata = $_POST['savedata'];
  1747. $fd = fopen($file_path, "w");
  1748. @fwrite($fd, $writedata);
  1749. fclose($fd);
  1750. fm_set_msg(lng('File Saved Successfully'));
  1751. }
  1752. $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1753. $mime_type = fm_get_mime_type($file_path);
  1754. $filesize = filesize($file_path);
  1755. $is_text = false;
  1756. $content = ''; // for text
  1757. if (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1758. $is_text = true;
  1759. $content = file_get_contents($file_path);
  1760. }
  1761. ?>
  1762. <div class="path">
  1763. <div class="row">
  1764. <div class="col-xs-12 col-sm-5 col-lg-6 pt-1">
  1765. <div class="btn-toolbar" role="toolbar">
  1766. <?php if (!$isNormalEditor) { ?>
  1767. <div class="btn-group js-ace-toolbar">
  1768. <button data-cmd="none" data-option="fullscreen" class="btn btn-sm btn-outline-secondary" id="js-ace-fullscreen" title="<?php echo lng('Fullscreen') ?>"><i class="fa fa-expand" title="<?php echo lng('Fullscreen') ?>"></i></div>
  1769. <button data-cmd="find" class="btn btn-sm btn-outline-secondary" id="js-ace-search" title="<?php echo lng('Search') ?>"><i class="fa fa-search" title="<?php echo lng('Search') ?>"></i></div>
  1770. <button data-cmd="undo" class="btn btn-sm btn-outline-secondary" id="js-ace-undo" title="<?php echo lng('Undo') ?>"><i class="fa fa-undo" title="<?php echo lng('Undo') ?>"></i></div>
  1771. <button data-cmd="redo" class="btn btn-sm btn-outline-secondary" id="js-ace-redo" title="<?php echo lng('Redo') ?>"><i class="fa fa-repeat" title="<?php echo lng('Redo') ?>"></i></div>
  1772. <button data-cmd="none" data-option="wrap" class="btn btn-sm btn-outline-secondary" id="js-ace-wordWrap" title="<?php echo lng('Word Wrap') ?>"><i class="fa fa-text-width" title="<?php echo lng('Word Wrap') ?>"></i></div>
  1773. <select id="js-ace-mode" data-type="mode" title="<?php echo lng('Select Document Type') ?>" class="btn-outline-secondary border-start-0 d-none d-md-block">
  1774. <option>-- <?php echo lng('Select Mode') ?> --</option>
  1775. </select>
  1776. <select id="js-ace-theme" data-type="theme" title="<?php echo lng('Select Theme') ?>" class="btn-outline-secondary border-start-0 d-none d-lg-block">
  1777. <option>-- <?php echo lng('Select Theme') ?> --</option>
  1778. </select>
  1779. <select id="js-ace-fontSize" data-type="fontSize" title="<?php echo lng('Select Font Size') ?>" class="btn-outline-secondary border-start-0 d-none d-lg-block">
  1780. <option>-- <?php echo lng('Select Font Size') ?> --</option>
  1781. </select>
  1782. </div>
  1783. <?php } ?>
  1784. </div>
  1785. </div>
  1786. <div class="edit-file-actions col-xs-12 col-sm-7 col-lg-6 text-end pt-1">
  1787. <div class="btn-group">
  1788. <a title=" <?php echo lng('Back') ?>" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;view=<?php echo urlencode($file) ?>"><i class="fa fa-reply-all"></i> <?php echo lng('Back') ?></a>
  1789. <a title="<?php echo lng('BackUp') ?>" class="btn btn-sm btn-outline-primary" href="javascript:void(0);" onclick="backup('<?php echo urlencode(trim(FM_PATH)) ?>','<?php echo urlencode($file) ?>')"><i class="fa fa-database"></i> <?php echo lng('BackUp') ?></a>
  1790. <?php if ($is_text) { ?>
  1791. <?php if ($isNormalEditor) { ?>
  1792. <a title="Advanced" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>&amp;env=ace"><i class="fa fa-pencil-square-o"></i> <?php echo lng('AdvancedEditor') ?></a>
  1793. <button type="button" class="btn btn-sm btn-success" name="Save" data-url="<?php echo fm_enc($file_url) ?>" onclick="edit_save(this,'nrl')"><i class="fa fa-floppy-o"></i> Save
  1794. </div>
  1795. <?php } else { ?>
  1796. <a title="Plain Editor" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>"><i class="fa fa-text-height"></i> <?php echo lng('NormalEditor') ?></a>
  1797. <button type="button" class="btn btn-sm btn-success" name="Save" data-url="<?php echo fm_enc($file_url) ?>" onclick="edit_save(this,'ace')"><i class="fa fa-floppy-o"></i> <?php echo lng('Save') ?>
  1798. </div>
  1799. <?php } ?>
  1800. <?php } ?>
  1801. </div>
  1802. </div>
  1803. </div>
  1804. <?php
  1805. if ($is_text && $isNormalEditor) {
  1806. echo '<textarea class="mt-2" id="normal-editor" rows="33" cols="120" style="width: 99.5%;">' . htmlspecialchars($content) . '</textarea>';
  1807. echo '<script>document.addEventListener("keydown", function(e) {if ((window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.keyCode == 83) { e.preventDefault();edit_save(this,"nrl");}}, false);</script>';
  1808. } elseif ($is_text) {
  1809. echo '<div id="editor" contenteditable="true">' . htmlspecialchars($content) . '</div>';
  1810. } else {
  1811. fm_set_msg(lng('FILE EXTENSION HAS NOT SUPPORTED'), 'error');
  1812. }
  1813. ?>
  1814. </div>
  1815. <?php
  1816. fm_show_footer();
  1817. exit;
  1818. }
  1819. // chmod (not for Windows)
  1820. if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
  1821. $file = $_GET['chmod'];
  1822. $file = fm_clean_path($file);
  1823. $file = str_replace('/', '', $file);
  1824. if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  1825. fm_set_msg(lng('File not found'), 'error');
  1826. $FM_PATH = FM_PATH;
  1827. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1828. }
  1829. fm_show_header(); // HEADER
  1830. fm_show_nav_path(FM_PATH); // current path
  1831. $file_url = FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file;
  1832. $file_path = $path . '/' . $file;
  1833. $mode = fileperms($path . '/' . $file);
  1834. ?>
  1835. <div class="path">
  1836. <div class="card mb-2" data-bs-theme="<?php echo FM_THEME; ?>">
  1837. <h6 class="card-header">
  1838. <?php echo lng('ChangePermissions') ?>
  1839. </h6>
  1840. <div class="card-body">
  1841. <p class="card-text">
  1842. <?php $display_path = fm_get_display_path($file_path); ?>
  1843. <?php echo $display_path['label']; ?>: <?php echo $display_path['path']; ?><br>
  1844. </p>
  1845. <form action="" method="post">
  1846. <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1847. <input type="hidden" name="chmod" value="<?php echo fm_enc($file) ?>">
  1848. <table class="table compact-table" data-bs-theme="<?php echo FM_THEME; ?>">
  1849. <tr>
  1850. <td></td>
  1851. <td><b><?php echo lng('Owner') ?></b></td>
  1852. <td><b><?php echo lng('Group') ?></b></td>
  1853. <td><b><?php echo lng('Other') ?></b></td>
  1854. </tr>
  1855. <tr>
  1856. <td style="text-align: right"><b><?php echo lng('Read') ?></b></td>
  1857. <td><label><input type="checkbox" name="ur" value="1" <?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td>
  1858. <td><label><input type="checkbox" name="gr" value="1" <?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td>
  1859. <td><label><input type="checkbox" name="or" value="1" <?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td>
  1860. </tr>
  1861. <tr>
  1862. <td style="text-align: right"><b><?php echo lng('Write') ?></b></td>
  1863. <td><label><input type="checkbox" name="uw" value="1" <?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td>
  1864. <td><label><input type="checkbox" name="gw" value="1" <?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td>
  1865. <td><label><input type="checkbox" name="ow" value="1" <?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td>
  1866. </tr>
  1867. <tr>
  1868. <td style="text-align: right"><b><?php echo lng('Execute') ?></b></td>
  1869. <td><label><input type="checkbox" name="ux" value="1" <?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td>
  1870. <td><label><input type="checkbox" name="gx" value="1" <?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td>
  1871. <td><label><input type="checkbox" name="ox" value="1" <?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td>
  1872. </tr>
  1873. </table>
  1874. <p>
  1875. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1876. <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="btn btn-outline-primary"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></a></b>&nbsp;
  1877. <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Change') ?></div>
  1878. </p>
  1879. </form>
  1880. </div>
  1881. </div>
  1882. </div>
  1883. <?php
  1884. fm_show_footer();
  1885. exit;
  1886. }
  1887. // --- TINYFILEMANAGER MAIN ---
  1888. fm_show_header(); // HEADER
  1889. fm_show_nav_path(FM_PATH); // current path
  1890. // show alert messages
  1891. fm_show_message();
  1892. $num_files = count($files);
  1893. $num_folders = count($folders);
  1894. $all_files_size = 0;
  1895. ?>
  1896. <form action="" method="post" class="pt-3">
  1897. <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1898. <input type="hidden" name="group" value="1">
  1899. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1900. <div class="table-responsive">
  1901. <table class="table table-bordered table-hover table-sm" id="main-table" data-bs-theme="<?php echo FM_THEME; ?>">
  1902. <thead class="thead-white">
  1903. <tr>
  1904. <?php if (!FM_READONLY): ?>
  1905. <th style="width:3%" class="custom-checkbox-header">
  1906. <div class="custom-control custom-checkbox">
  1907. <input type="checkbox" class="custom-control-input" id="js-select-all-items" onclick="checkbox_toggle()">
  1908. <label class="custom-control-label" for="js-select-all-items"></label>
  1909. </div>
  1910. </th><?php endif; ?>
  1911. <th><?php echo lng('Name') ?></th>
  1912. <th><?php echo lng('Size') ?></th>
  1913. <th><?php echo lng('Modified') ?></th>
  1914. <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  1915. <th><?php echo lng('Perms') ?></th>
  1916. <th><?php echo lng('Owner') ?></th><?php endif; ?>
  1917. <th><?php echo lng('Actions') ?></th>
  1918. </tr>
  1919. </thead>
  1920. <?php
  1921. // link to parent folder
  1922. if ($parent !== false) {
  1923. ?>
  1924. <tr><?php if (!FM_READONLY): ?>
  1925. <td class="nosort"></td><?php endif; ?>
  1926. <td class="border-0" data-sort><a href="?p=<?php echo urlencode($parent) ?>"><i class="fa fa-chevron-circle-left go-back"></i> ..</a></td>
  1927. <td class="border-0" data-order></td>
  1928. <td class="border-0" data-order></td>
  1929. <td class="border-0"></td>
  1930. <?php if (!FM_IS_WIN && !$hide_Cols) { ?>
  1931. <td class="border-0"></td>
  1932. <td class="border-0"></td>
  1933. <?php } ?>
  1934. </tr>
  1935. <?php
  1936. }
  1937. $ii = 3399;
  1938. foreach ($folders as $f) {
  1939. $is_link = is_link($path . '/' . $f);
  1940. $img = $is_link ? 'icon-link_folder' : 'fa fa-folder-o';
  1941. $modif_raw = filemtime($path . '/' . $f);
  1942. $modif = date(FM_DATETIME_FORMAT, $modif_raw);
  1943. $date_sorting = strtotime(date("F d Y H:i:s.", $modif_raw));
  1944. $filesize_raw = "";
  1945. $filesize = lng('Folder');
  1946. $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  1947. $owner = array('name' => '?');
  1948. $group = array('name' => '?');
  1949. if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  1950. try {
  1951. $owner_id = fileowner($path . '/' . $f);
  1952. if ($owner_id != 0) {
  1953. $owner_info = posix_getpwuid($owner_id);
  1954. if ($owner_info) {
  1955. $owner = $owner_info;
  1956. }
  1957. }
  1958. $group_id = filegroup($path . '/' . $f);
  1959. $group_info = posix_getgrgid($group_id);
  1960. if ($group_info) {
  1961. $group = $group_info;
  1962. }
  1963. } catch (Exception $e) {
  1964. error_log("exception:" . $e->getMessage());
  1965. }
  1966. }
  1967. ?>
  1968. <tr>
  1969. <?php if (!FM_READONLY): ?>
  1970. <td class="custom-checkbox-td">
  1971. <div class="custom-control custom-checkbox">
  1972. <input type="checkbox" class="custom-control-input" id="<?php echo $ii ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  1973. <label class="custom-control-label" for="<?php echo $ii ?>"></label>
  1974. </div>
  1975. </td>
  1976. <?php endif; ?>
  1977. <td data-sort=<?php echo fm_convert_win(fm_enc($f)) ?>>
  1978. <div class="filename">
  1979. <a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win(fm_enc($f)) ?></a>
  1980. <?php echo ($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?>
  1981. </div>
  1982. </td>
  1983. <td data-order="a-<?php echo str_pad($filesize_raw, 18, "0", STR_PAD_LEFT); ?>">
  1984. <?php echo $filesize; ?>
  1985. </td>
  1986. <td data-order="a-<?php echo $date_sorting; ?>"><?php echo $modif ?></td>
  1987. <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  1988. <td>
  1989. <?php if (!FM_READONLY): ?><a title="Change Permissions" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?>
  1990. </td>
  1991. <td>
  1992. <?php echo $owner['name'] . ':' . $group['name'] ?>
  1993. </td>
  1994. <?php endif; ?>
  1995. <td class="inline-actions"><?php if (!FM_READONLY): ?>
  1996. <a title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, '1028','<?php echo lng('Delete') . ' ' . lng('Folder'); ?>','<?php echo urlencode($f) ?>', this.href);"> <i class="fa fa-trash-o" aria-hidden="true"></i></a>
  1997. <a title="<?php echo lng('Rename') ?>" href="#" onclick="rename('<?php echo fm_enc(addslashes(FM_PATH)) ?>', '<?php echo fm_enc(addslashes($f)) ?>');return false;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
  1998. <a title="<?php echo lng('CopyTo') ?>..." href="?p=&amp;copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o" aria-hidden="true"></i></a>
  1999. <?php endif; ?>
  2000. <a title="<?php echo lng('DirectLink') ?>" href="<?php echo fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f . '/') ?>" target="_blank"><i class="fa fa-link" aria-hidden="true"></i></a>
  2001. </td>
  2002. </tr>
  2003. <?php
  2004. flush();
  2005. $ii++;
  2006. }
  2007. $ik = 8002;
  2008. foreach ($files as $f) {
  2009. $is_link = is_link($path . '/' . $f);
  2010. $img = $is_link ? 'fa fa-file-text-o' : fm_get_file_icon_class($path . '/' . $f);
  2011. $modif_raw = filemtime($path . '/' . $f);
  2012. $modif = date(FM_DATETIME_FORMAT, $modif_raw);
  2013. $date_sorting = strtotime(date("F d Y H:i:s.", $modif_raw));
  2014. $filesize_raw = fm_get_size($path . '/' . $f);
  2015. $filesize = fm_get_filesize($filesize_raw);
  2016. $filelink = '?p=' . urlencode(FM_PATH) . '&amp;view=' . urlencode($f);
  2017. $all_files_size += $filesize_raw;
  2018. $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  2019. $owner = array('name' => '?');
  2020. $group = array('name' => '?');
  2021. if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  2022. try {
  2023. $owner_id = fileowner($path . '/' . $f);
  2024. if ($owner_id != 0) {
  2025. $owner_info = posix_getpwuid($owner_id);
  2026. if ($owner_info) {
  2027. $owner = $owner_info;
  2028. }
  2029. }
  2030. $group_id = filegroup($path . '/' . $f);
  2031. $group_info = posix_getgrgid($group_id);
  2032. if ($group_info) {
  2033. $group = $group_info;
  2034. }
  2035. } catch (Exception $e) {
  2036. error_log("exception:" . $e->getMessage());
  2037. }
  2038. }
  2039. ?>
  2040. <tr>
  2041. <?php if (!FM_READONLY): ?>
  2042. <td class="custom-checkbox-td">
  2043. <div class="custom-control custom-checkbox">
  2044. <input type="checkbox" class="custom-control-input" id="<?php echo $ik ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  2045. <label class="custom-control-label" for="<?php echo $ik ?>"></label>
  2046. </div>
  2047. </td><?php endif; ?>
  2048. <td data-sort=<?php echo fm_enc($f) ?>>
  2049. <div class="filename">
  2050. <?php
  2051. if (in_array(strtolower(pathinfo($f, PATHINFO_EXTENSION)), array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))): ?>
  2052. <?php $imagePreview = fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f); ?>
  2053. <a href="<?php echo $filelink ?>" data-preview-image="<?php echo $imagePreview ?>" title="<?php echo fm_enc($f) ?>">
  2054. <?php else: ?>
  2055. <a href="<?php echo $filelink ?>" title="<?php echo $f ?>">
  2056. <?php endif; ?>
  2057. <i class="<?php echo $img ?>"></i> <?php echo fm_convert_win(fm_enc($f)) ?>
  2058. </a>
  2059. <?php echo ($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?>
  2060. </div>
  2061. </td>
  2062. <td data-order="b-<?php echo str_pad($filesize_raw, 18, "0", STR_PAD_LEFT); ?>"><span title="<?php printf('%s bytes', $filesize_raw) ?>">
  2063. <?php echo $filesize; ?>
  2064. </span></td>
  2065. <td data-order="b-<?php echo $date_sorting; ?>"><?php echo $modif ?></td>
  2066. <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2067. <td><?php if (!FM_READONLY): ?><a title="<?php echo 'Change Permissions' ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?>
  2068. </td>
  2069. <td><?php echo fm_enc($owner['name'] . ':' . $group['name']) ?></td>
  2070. <?php endif; ?>
  2071. <td class="inline-actions">
  2072. <?php if (!FM_READONLY): ?>
  2073. <a title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, 1209, '<?php echo lng('Delete') . ' ' . lng('File'); ?>','<?php echo urlencode($f); ?>', this.href);"> <i class="fa fa-trash-o"></i></a>
  2074. <a title="<?php echo lng('Rename') ?>" href="#" onclick="rename('<?php echo fm_enc(addslashes(FM_PATH)) ?>', '<?php echo fm_enc(addslashes($f)) ?>');return false;"><i class="fa fa-pencil-square-o"></i></a>
  2075. <a title="<?php echo lng('CopyTo') ?>..."
  2076. href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o"></i></a>
  2077. <?php endif; ?>
  2078. <a title="<?php echo lng('DirectLink') ?>" href="<?php echo fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f) ?>" target="_blank"><i class="fa fa-link"></i></a>
  2079. <a title="<?php echo lng('Download') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;dl=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, 1211, '<?php echo lng('Download'); ?>','<?php echo urlencode($f); ?>', this.href);"><i class="fa fa-download"></i></a>
  2080. </td>
  2081. </tr>
  2082. <?php
  2083. flush();
  2084. $ik++;
  2085. }
  2086. if (empty($folders) && empty($files)) { ?>
  2087. <tfoot>
  2088. <tr><?php if (!FM_READONLY): ?>
  2089. <td></td><?php endif; ?>
  2090. <td colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? '6' : '4' ?>"><em><?php echo lng('Folder is empty') ?></em></td>
  2091. </tr>
  2092. </tfoot>
  2093. <?php
  2094. } else { ?>
  2095. <tfoot>
  2096. <tr>
  2097. <td class="gray fs-7" colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? (FM_READONLY ? '6' : '7') : (FM_READONLY ? '4' : '5') ?>">
  2098. <?php echo lng('FullSize') . ': <span class="badge text-bg-light border-radius-0">' . fm_get_filesize($all_files_size) . '</span>' ?>
  2099. <?php echo lng('File') . ': <span class="badge text-bg-light border-radius-0">' . $num_files . '</span>' ?>
  2100. <?php echo lng('Folder') . ': <span class="badge text-bg-light border-radius-0">' . $num_folders . '</span>' ?>
  2101. </td>
  2102. </tr>
  2103. </tfoot>
  2104. <?php } ?>
  2105. </table>
  2106. </div>
  2107. <div class="row">
  2108. <?php if (!FM_READONLY): ?>
  2109. <div class="col-xs-12 col-sm-9">
  2110. <div class="btn-group flex-wrap" data-toggle="buttons" role="toolbar">
  2111. <a href="#/select-all" class="btn btn-small btn-outline-primary btn-2" onclick="select_all();return false;"><i class="fa fa-check-square"></i> <?php echo lng('SelectAll') ?> </a>
  2112. <a href="#/unselect-all" class="btn btn-small btn-outline-primary btn-2" onclick="unselect_all();return false;"><i class="fa fa-window-close"></i> <?php echo lng('UnSelectAll') ?> </a>
  2113. <a href="#/invert-all" class="btn btn-small btn-outline-primary btn-2" onclick="invert_all();return false;"><i class="fa fa-th-list"></i> <?php echo lng('InvertSelection') ?> </a>
  2114. <input type="submit" class="hidden" name="delete" id="a-delete" value="Delete" onclick="return confirm('<?php echo lng('Delete selected files and folders?'); ?>')">
  2115. <a href="javascript:document.getElementById('a-delete').click();" class="btn btn-small btn-outline-primary btn-2"><i class="fa fa-trash"></i> <?php echo lng('Delete') ?> </a>
  2116. <input type="submit" class="hidden" name="zip" id="a-zip" value="zip" onclick="return confirm('<?php echo lng('Create archive?'); ?>')">
  2117. <a href="javascript:document.getElementById('a-zip').click();" class="btn btn-small btn-outline-primary btn-2"><i class="fa fa-file-archive-o"></i> <?php echo lng('Zip') ?> </a>
  2118. <input type="submit" class="hidden" name="tar" id="a-tar" value="tar" onclick="return confirm('<?php echo lng('Create archive?'); ?>')">
  2119. <a href="javascript:document.getElementById('a-tar').click();" class="btn btn-small btn-outline-primary btn-2"><i class="fa fa-file-archive-o"></i> <?php echo lng('Tar') ?> </a>
  2120. <input type="submit" class="hidden" name="copy" id="a-copy" value="Copy">
  2121. <a href="javascript:document.getElementById('a-copy').click();" class="btn btn-small btn-outline-primary btn-2"><i class="fa fa-files-o"></i> <?php echo lng('Copy') ?> </a>
  2122. </div>
  2123. </div>
  2124. <div class="col-3 d-none d-sm-block"><a href="https://tinyfilemanager.github.io" target="_blank" class="float-right text-muted">Tiny File Manager <?php echo VERSION; ?></a></div>
  2125. <?php else: ?>
  2126. <div class="col-12"><a href="https://tinyfilemanager.github.io" target="_blank" class="float-right text-muted">Tiny File Manager <?php echo VERSION; ?></a></div>
  2127. <?php endif; ?>
  2128. </div>
  2129. </form>
  2130. <?php
  2131. fm_show_footer();
  2132. // --- END HTML ---
  2133. // Functions
  2134. /**
  2135. * It prints the css/js files into html
  2136. * @param key The key of the external file to print.
  2137. */
  2138. function print_external($key)
  2139. {
  2140. global $external;
  2141. if (!array_key_exists($key, $external)) {
  2142. // throw new Exception('Key missing in external: ' . key);
  2143. echo "<!-- EXTERNAL: MISSING KEY $key -->";
  2144. return;
  2145. }
  2146. echo "$external[$key]";
  2147. }
  2148. /**
  2149. * Verify CSRF TOKEN and remove after certified
  2150. * @param string $token
  2151. * @return bool
  2152. */
  2153. function verifyToken($token)
  2154. {
  2155. if (hash_equals($_SESSION['token'], $token)) {
  2156. return true;
  2157. }
  2158. return false;
  2159. }
  2160. /**
  2161. * Delete file or folder (recursively)
  2162. * @param string $path
  2163. * @return bool
  2164. */
  2165. function fm_rdelete($path)
  2166. {
  2167. if (is_link($path)) {
  2168. return unlink($path);
  2169. } elseif (is_dir($path)) {
  2170. $objects = scandir($path);
  2171. $ok = true;
  2172. if (is_array($objects)) {
  2173. foreach ($objects as $file) {
  2174. if ($file != '.' && $file != '..') {
  2175. if (!fm_rdelete($path . '/' . $file)) {
  2176. $ok = false;
  2177. }
  2178. }
  2179. }
  2180. }
  2181. return ($ok) ? rmdir($path) : false;
  2182. } elseif (is_file($path)) {
  2183. return unlink($path);
  2184. }
  2185. return false;
  2186. }
  2187. /**
  2188. * Recursive chmod
  2189. * @param string $path
  2190. * @param int $filemode
  2191. * @param int $dirmode
  2192. * @return bool
  2193. * @todo Will use in mass chmod
  2194. */
  2195. function fm_rchmod($path, $filemode, $dirmode)
  2196. {
  2197. if (is_dir($path)) {
  2198. if (!chmod($path, $dirmode)) {
  2199. return false;
  2200. }
  2201. $objects = scandir($path);
  2202. if (is_array($objects)) {
  2203. foreach ($objects as $file) {
  2204. if ($file != '.' && $file != '..') {
  2205. if (!fm_rchmod($path . '/' . $file, $filemode, $dirmode)) {
  2206. return false;
  2207. }
  2208. }
  2209. }
  2210. }
  2211. return true;
  2212. } elseif (is_link($path)) {
  2213. return true;
  2214. } elseif (is_file($path)) {
  2215. return chmod($path, $filemode);
  2216. }
  2217. return false;
  2218. }
  2219. /**
  2220. * Check the file extension which is allowed or not
  2221. * @param string $filename
  2222. * @return bool
  2223. */
  2224. function fm_is_valid_ext($filename)
  2225. {
  2226. $allowed = (FM_FILE_EXTENSION) ? explode(',', FM_FILE_EXTENSION) : false;
  2227. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  2228. $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  2229. return ($isFileAllowed) ? true : false;
  2230. }
  2231. /**
  2232. * Safely rename
  2233. * @param string $old
  2234. * @param string $new
  2235. * @return bool|null
  2236. */
  2237. function fm_rename($old, $new)
  2238. {
  2239. $isFileAllowed = fm_is_valid_ext($new);
  2240. if (!is_dir($old)) {
  2241. if (!$isFileAllowed) return false;
  2242. }
  2243. return (!file_exists($new) && file_exists($old)) ? rename($old, $new) : null;
  2244. }
  2245. /**
  2246. * Copy file or folder (recursively).
  2247. * @param string $path
  2248. * @param string $dest
  2249. * @param bool $upd Update files
  2250. * @param bool $force Create folder with same names instead file
  2251. * @return bool
  2252. */
  2253. function fm_rcopy($path, $dest, $upd = true, $force = true)
  2254. {
  2255. if (!is_dir($path) && !is_file($path)) {
  2256. return false;
  2257. }
  2258. if (is_dir($path)) {
  2259. if (!fm_mkdir($dest, $force)) {
  2260. return false;
  2261. }
  2262. $objects = array_diff(scandir($path), ['.', '..']);
  2263. foreach ($objects as $file) {
  2264. if (!fm_rcopy("$path/$file", "$dest/$file", $upd, $force)) {
  2265. return false;
  2266. }
  2267. }
  2268. return true;
  2269. }
  2270. // Handle file copying
  2271. return fm_copy($path, $dest, $upd);
  2272. }
  2273. /**
  2274. * Safely create folder
  2275. * @param string $dir
  2276. * @param bool $force
  2277. * @return bool
  2278. */
  2279. function fm_mkdir($dir, $force)
  2280. {
  2281. if (file_exists($dir)) {
  2282. if (is_dir($dir)) {
  2283. return $dir;
  2284. } elseif (!$force) {
  2285. return false;
  2286. }
  2287. unlink($dir);
  2288. }
  2289. return mkdir($dir, 0777, true);
  2290. }
  2291. /**
  2292. * Safely copy file
  2293. * @param string $f1
  2294. * @param string $f2
  2295. * @param bool $upd Indicates if file should be updated with new content
  2296. * @return bool
  2297. */
  2298. function fm_copy($f1, $f2, $upd)
  2299. {
  2300. $time1 = filemtime($f1);
  2301. if (file_exists($f2)) {
  2302. $time2 = filemtime($f2);
  2303. if ($time2 >= $time1 && $upd) {
  2304. return false;
  2305. }
  2306. }
  2307. $ok = copy($f1, $f2);
  2308. if ($ok) {
  2309. touch($f2, $time1);
  2310. }
  2311. return $ok;
  2312. }
  2313. /**
  2314. * Get mime type
  2315. * @param string $file_path
  2316. * @return mixed|string
  2317. */
  2318. function fm_get_mime_type($file_path)
  2319. {
  2320. if (function_exists('finfo_open')) {
  2321. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  2322. $mime = finfo_file($finfo, $file_path);
  2323. finfo_close($finfo);
  2324. return $mime;
  2325. } elseif (function_exists('mime_content_type')) {
  2326. return mime_content_type($file_path);
  2327. } elseif (!stristr(ini_get('disable_functions'), 'shell_exec')) {
  2328. $file = escapeshellarg($file_path);
  2329. $mime = shell_exec('file -bi ' . $file);
  2330. return $mime;
  2331. } else {
  2332. return '--';
  2333. }
  2334. }
  2335. /**
  2336. * HTTP Redirect
  2337. * @param string $url
  2338. * @param int $code
  2339. */
  2340. function fm_redirect($url, $code = 302)
  2341. {
  2342. header('Location: ' . $url, true, $code);
  2343. exit;
  2344. }
  2345. /**
  2346. * Path traversal prevention and clean the url
  2347. * It replaces (consecutive) occurrences of / and \\ with whatever is in DIRECTORY_SEPARATOR, and processes /. and /.. fine.
  2348. * @param $path
  2349. * @return string
  2350. */
  2351. function get_absolute_path($path)
  2352. {
  2353. $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
  2354. $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
  2355. $absolutes = array();
  2356. foreach ($parts as $part) {
  2357. if ('.' == $part) continue;
  2358. if ('..' == $part) {
  2359. array_pop($absolutes);
  2360. } else {
  2361. $absolutes[] = $part;
  2362. }
  2363. }
  2364. return implode(DIRECTORY_SEPARATOR, $absolutes);
  2365. }
  2366. /**
  2367. * Clean path
  2368. * @param string $path
  2369. * @return string
  2370. */
  2371. function fm_clean_path($path, $trim = true)
  2372. {
  2373. $path = $trim ? trim($path) : $path;
  2374. $path = trim($path, '\\/');
  2375. $path = str_replace(array('../', '..\\'), '', $path);
  2376. $path = get_absolute_path($path);
  2377. if ($path == '..') {
  2378. $path = '';
  2379. }
  2380. return str_replace('\\', '/', $path);
  2381. }
  2382. /**
  2383. * Get parent path
  2384. * @param string $path
  2385. * @return bool|string
  2386. */
  2387. function fm_get_parent_path($path)
  2388. {
  2389. $path = fm_clean_path($path);
  2390. if ($path != '') {
  2391. $array = explode('/', $path);
  2392. if (count($array) > 1) {
  2393. $array = array_slice($array, 0, -1);
  2394. return implode('/', $array);
  2395. }
  2396. return '';
  2397. }
  2398. return false;
  2399. }
  2400. function fm_get_display_path($file_path)
  2401. {
  2402. global $path_display_mode, $root_path, $root_url;
  2403. switch ($path_display_mode) {
  2404. case 'relative':
  2405. return array(
  2406. 'label' => 'Path',
  2407. 'path' => fm_enc(fm_convert_win(str_replace($root_path, '', $file_path)))
  2408. );
  2409. case 'host':
  2410. $relative_path = str_replace($root_path, '', $file_path);
  2411. return array(
  2412. 'label' => 'Host Path',
  2413. 'path' => fm_enc(fm_convert_win('/' . $root_url . '/' . ltrim(str_replace('\\', '/', $relative_path), '/')))
  2414. );
  2415. case 'full':
  2416. default:
  2417. return array(
  2418. 'label' => 'Full Path',
  2419. 'path' => fm_enc(fm_convert_win($file_path))
  2420. );
  2421. }
  2422. }
  2423. /**
  2424. * Check file is in exclude list
  2425. * @param string $name The name of the file/folder
  2426. * @param string $path The full path of the file/folder
  2427. * @return bool
  2428. */
  2429. function fm_is_exclude_items($name, $path)
  2430. {
  2431. $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
  2432. if (isset($exclude_items) and sizeof($exclude_items)) {
  2433. unset($exclude_items);
  2434. }
  2435. $exclude_items = FM_EXCLUDE_ITEMS;
  2436. if (version_compare(PHP_VERSION, '7.0.0', '<')) {
  2437. $exclude_items = unserialize($exclude_items);
  2438. }
  2439. if (!in_array($name, $exclude_items) && !in_array("*.$ext", $exclude_items) && !in_array($path, $exclude_items)) {
  2440. return true;
  2441. }
  2442. return false;
  2443. }
  2444. /**
  2445. * get language translations from json file
  2446. * @param int $tr
  2447. * @return array
  2448. */
  2449. function fm_get_translations($tr)
  2450. {
  2451. try {
  2452. $content = @file_get_contents('translation.json');
  2453. if ($content !== FALSE) {
  2454. $lng = json_decode($content, TRUE);
  2455. global $lang_list;
  2456. foreach ($lng["language"] as $key => $value) {
  2457. $code = $value["code"];
  2458. $lang_list[$code] = $value["name"];
  2459. if ($tr)
  2460. $tr[$code] = $value["translation"];
  2461. }
  2462. return $tr;
  2463. }
  2464. } catch (Exception $e) {
  2465. echo $e;
  2466. }
  2467. }
  2468. /**
  2469. * @param string $file
  2470. * Recover all file sizes larger than > 2GB.
  2471. * Works on php 32bits and 64bits and supports linux
  2472. * @return int|string
  2473. */
  2474. function fm_get_size($file)
  2475. {
  2476. static $iswin = null;
  2477. static $isdarwin = null;
  2478. static $exec_works = null;
  2479. // Set static variables once
  2480. if ($iswin === null) {
  2481. $iswin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
  2482. $isdarwin = strtoupper(PHP_OS) === 'DARWIN';
  2483. $exec_works = function_exists('exec') && !ini_get('safe_mode') && @exec('echo EXEC') === 'EXEC';
  2484. }
  2485. // Attempt shell command if exec is available
  2486. if ($exec_works) {
  2487. $arg = escapeshellarg($file);
  2488. $cmd = $iswin ? "for %F in (\"$file\") do @echo %~zF" : ($isdarwin ? "stat -f%z $arg" : "stat -c%s $arg");
  2489. @exec($cmd, $output);
  2490. if (!empty($output) && ctype_digit($size = trim(implode("\n", $output)))) {
  2491. return $size;
  2492. }
  2493. }
  2494. // Attempt Windows COM interface for Windows systems
  2495. if ($iswin && class_exists('COM')) {
  2496. try {
  2497. $fsobj = new COM('Scripting.FileSystemObject');
  2498. $f = $fsobj->GetFile(realpath($file));
  2499. if (ctype_digit($size = $f->Size)) {
  2500. return $size;
  2501. }
  2502. } catch (Exception $e) {
  2503. // COM failed, fallback to filesize
  2504. }
  2505. }
  2506. // Default to PHP's filesize function
  2507. return filesize($file);
  2508. }
  2509. /**
  2510. * Get nice filesize
  2511. * @param int $size
  2512. * @return string
  2513. */
  2514. function fm_get_filesize($size)
  2515. {
  2516. $size = (float) $size;
  2517. $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  2518. $power = ($size > 0) ? floor(log($size, 1024)) : 0;
  2519. $power = ($power > (count($units) - 1)) ? (count($units) - 1) : $power;
  2520. return sprintf('%s %s', round($size / pow(1024, $power), 2), $units[$power]);
  2521. }
  2522. /**
  2523. * Get info about zip archive
  2524. * @param string $path
  2525. * @return array|bool
  2526. */
  2527. function fm_get_zif_info($path, $ext)
  2528. {
  2529. if ($ext == 'zip' && function_exists('zip_open')) {
  2530. $arch = @zip_open($path);
  2531. if ($arch) {
  2532. $filenames = array();
  2533. while ($zip_entry = @zip_read($arch)) {
  2534. $zip_name = @zip_entry_name($zip_entry);
  2535. $zip_folder = substr($zip_name, -1) == '/';
  2536. $filenames[] = array(
  2537. 'name' => $zip_name,
  2538. 'filesize' => @zip_entry_filesize($zip_entry),
  2539. 'compressed_size' => @zip_entry_compressedsize($zip_entry),
  2540. 'folder' => $zip_folder
  2541. //'compression_method' => zip_entry_compressionmethod($zip_entry),
  2542. );
  2543. }
  2544. @zip_close($arch);
  2545. return $filenames;
  2546. }
  2547. } elseif ($ext == 'tar' && class_exists('PharData')) {
  2548. $archive = new PharData($path);
  2549. $filenames = array();
  2550. foreach (new RecursiveIteratorIterator($archive) as $file) {
  2551. $parent_info = $file->getPathInfo();
  2552. $zip_name = str_replace("phar://" . $path, '', $file->getPathName());
  2553. $zip_name = substr($zip_name, ($pos = strpos($zip_name, '/')) !== false ? $pos + 1 : 0);
  2554. $zip_folder = $parent_info->getFileName();
  2555. $zip_info = new SplFileInfo($file);
  2556. $filenames[] = array(
  2557. 'name' => $zip_name,
  2558. 'filesize' => $zip_info->getSize(),
  2559. 'compressed_size' => $file->getCompressedSize(),
  2560. 'folder' => $zip_folder
  2561. );
  2562. }
  2563. return $filenames;
  2564. }
  2565. return false;
  2566. }
  2567. /**
  2568. * Encode html entities
  2569. * @param string $text
  2570. * @return string
  2571. */
  2572. function fm_enc($text)
  2573. {
  2574. return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  2575. }
  2576. /**
  2577. * Prevent XSS attacks
  2578. * @param string $text
  2579. * @return string
  2580. */
  2581. function fm_isvalid_filename($text)
  2582. {
  2583. return (strpbrk($text, '/?%*:|"<>') === FALSE) ? true : false;
  2584. }
  2585. /**
  2586. * Save message in session
  2587. * @param string $msg
  2588. * @param string $status
  2589. */
  2590. function fm_set_msg($msg, $status = 'ok')
  2591. {
  2592. $_SESSION[FM_SESSION_ID]['message'] = $msg;
  2593. $_SESSION[FM_SESSION_ID]['status'] = $status;
  2594. }
  2595. /**
  2596. * Check if string is in UTF-8
  2597. * @param string $string
  2598. * @return int
  2599. */
  2600. function fm_is_utf8($string)
  2601. {
  2602. return preg_match('//u', $string);
  2603. }
  2604. /**
  2605. * Convert file name to UTF-8 in Windows
  2606. * @param string $filename
  2607. * @return string
  2608. */
  2609. function fm_convert_win($filename)
  2610. {
  2611. if (FM_IS_WIN && function_exists('iconv')) {
  2612. $filename = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $filename);
  2613. }
  2614. return $filename;
  2615. }
  2616. /**
  2617. * @param $obj
  2618. * @return array
  2619. */
  2620. function fm_object_to_array($obj)
  2621. {
  2622. if (!is_object($obj) && !is_array($obj)) {
  2623. return $obj;
  2624. }
  2625. if (is_object($obj)) {
  2626. $obj = get_object_vars($obj);
  2627. }
  2628. return array_map('fm_object_to_array', $obj);
  2629. }
  2630. /**
  2631. * Get CSS classname for file
  2632. * @param string $path
  2633. * @return string
  2634. */
  2635. function fm_get_file_icon_class($path)
  2636. {
  2637. // get extension
  2638. $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
  2639. switch ($ext) {
  2640. case 'ico':
  2641. case 'gif':
  2642. case 'jpg':
  2643. case 'jpeg':
  2644. case 'jpc':
  2645. case 'jp2':
  2646. case 'jpx':
  2647. case 'xbm':
  2648. case 'wbmp':
  2649. case 'png':
  2650. case 'bmp':
  2651. case 'tif':
  2652. case 'tiff':
  2653. case 'webp':
  2654. case 'avif':
  2655. case 'svg':
  2656. $img = 'fa fa-picture-o';
  2657. break;
  2658. case 'passwd':
  2659. case 'ftpquota':
  2660. case 'sql':
  2661. case 'js':
  2662. case 'ts':
  2663. case 'jsx':
  2664. case 'tsx':
  2665. case 'hbs':
  2666. case 'json':
  2667. case 'sh':
  2668. case 'config':
  2669. case 'twig':
  2670. case 'tpl':
  2671. case 'md':
  2672. case 'gitignore':
  2673. case 'c':
  2674. case 'cpp':
  2675. case 'cs':
  2676. case 'py':
  2677. case 'rs':
  2678. case 'map':
  2679. case 'lock':
  2680. case 'dtd':
  2681. case 'ps1':
  2682. $img = 'fa fa-file-code-o';
  2683. break;
  2684. case 'txt':
  2685. case 'ini':
  2686. case 'conf':
  2687. case 'log':
  2688. case 'htaccess':
  2689. case 'yaml':
  2690. case 'yml':
  2691. case 'toml':
  2692. case 'tmp':
  2693. case 'top':
  2694. case 'bot':
  2695. case 'dat':
  2696. case 'bak':
  2697. case 'htpasswd':
  2698. case 'pl':
  2699. $img = 'fa fa-file-text-o';
  2700. break;
  2701. case 'css':
  2702. case 'less':
  2703. case 'sass':
  2704. case 'scss':
  2705. $img = 'fa fa-css3';
  2706. break;
  2707. case 'bz2':
  2708. case 'tbz2':
  2709. case 'tbz':
  2710. case 'zip':
  2711. case 'rar':
  2712. case 'gz':
  2713. case 'tgz':
  2714. case 'tar':
  2715. case '7z':
  2716. case 'xz':
  2717. case 'txz':
  2718. case 'zst':
  2719. case 'tzst':
  2720. $img = 'fa fa-file-archive-o';
  2721. break;
  2722. case 'php':
  2723. case 'php4':
  2724. case 'php5':
  2725. case 'phps':
  2726. case 'phtml':
  2727. $img = 'fa fa-code';
  2728. break;
  2729. case 'htm':
  2730. case 'html':
  2731. case 'shtml':
  2732. case 'xhtml':
  2733. $img = 'fa fa-html5';
  2734. break;
  2735. case 'xml':
  2736. case 'xsl':
  2737. $img = 'fa fa-file-excel-o';
  2738. break;
  2739. case 'wav':
  2740. case 'mp3':
  2741. case 'mp2':
  2742. case 'm4a':
  2743. case 'aac':
  2744. case 'ogg':
  2745. case 'oga':
  2746. case 'wma':
  2747. case 'mka':
  2748. case 'flac':
  2749. case 'ac3':
  2750. case 'tds':
  2751. $img = 'fa fa-music';
  2752. break;
  2753. case 'm3u':
  2754. case 'm3u8':
  2755. case 'pls':
  2756. case 'cue':
  2757. case 'xspf':
  2758. $img = 'fa fa-headphones';
  2759. break;
  2760. case 'avi':
  2761. case 'mpg':
  2762. case 'mpeg':
  2763. case 'mp4':
  2764. case 'm4v':
  2765. case 'flv':
  2766. case 'f4v':
  2767. case 'ogm':
  2768. case 'ogv':
  2769. case 'mov':
  2770. case 'mkv':
  2771. case '3gp':
  2772. case 'asf':
  2773. case 'wmv':
  2774. case 'webm':
  2775. $img = 'fa fa-file-video-o';
  2776. break;
  2777. case 'eml':
  2778. case 'msg':
  2779. $img = 'fa fa-envelope-o';
  2780. break;
  2781. case 'xls':
  2782. case 'xlsx':
  2783. case 'ods':
  2784. $img = 'fa fa-file-excel-o';
  2785. break;
  2786. case 'csv':
  2787. $img = 'fa fa-file-text-o';
  2788. break;
  2789. case 'bak':
  2790. case 'swp':
  2791. $img = 'fa fa-clipboard';
  2792. break;
  2793. case 'doc':
  2794. case 'docx':
  2795. case 'odt':
  2796. $img = 'fa fa-file-word-o';
  2797. break;
  2798. case 'ppt':
  2799. case 'pptx':
  2800. $img = 'fa fa-file-powerpoint-o';
  2801. break;
  2802. case 'ttf':
  2803. case 'ttc':
  2804. case 'otf':
  2805. case 'woff':
  2806. case 'woff2':
  2807. case 'eot':
  2808. case 'fon':
  2809. $img = 'fa fa-font';
  2810. break;
  2811. case 'pdf':
  2812. $img = 'fa fa-file-pdf-o';
  2813. break;
  2814. case 'psd':
  2815. case 'ai':
  2816. case 'eps':
  2817. case 'fla':
  2818. case 'swf':
  2819. $img = 'fa fa-file-image-o';
  2820. break;
  2821. case 'exe':
  2822. case 'msi':
  2823. $img = 'fa fa-file-o';
  2824. break;
  2825. case 'bat':
  2826. $img = 'fa fa-terminal';
  2827. break;
  2828. default:
  2829. $img = 'fa fa-info-circle';
  2830. }
  2831. return $img;
  2832. }
  2833. /**
  2834. * Get image files extensions
  2835. * @return array
  2836. */
  2837. function fm_get_image_exts()
  2838. {
  2839. return array('ico', 'gif', 'jpg', 'jpeg', 'jpc', 'jp2', 'jpx', 'xbm', 'wbmp', 'png', 'bmp', 'tif', 'tiff', 'psd', 'svg', 'webp', 'avif');
  2840. }
  2841. /**
  2842. * Get video files extensions
  2843. * @return array
  2844. */
  2845. function fm_get_video_exts()
  2846. {
  2847. return array('avi', 'webm', 'wmv', 'mp4', 'm4v', 'ogm', 'ogv', 'mov', 'mkv');
  2848. }
  2849. /**
  2850. * Get audio files extensions
  2851. * @return array
  2852. */
  2853. function fm_get_audio_exts()
  2854. {
  2855. return array('wav', 'mp3', 'ogg', 'm4a');
  2856. }
  2857. /**
  2858. * Get text file extensions
  2859. * @return array
  2860. */
  2861. function fm_get_text_exts()
  2862. {
  2863. return array(
  2864. 'txt',
  2865. 'css',
  2866. 'ini',
  2867. 'conf',
  2868. 'log',
  2869. 'htaccess',
  2870. 'passwd',
  2871. 'ftpquota',
  2872. 'sql',
  2873. 'js',
  2874. 'ts',
  2875. 'jsx',
  2876. 'tsx',
  2877. 'mjs',
  2878. 'json',
  2879. 'sh',
  2880. 'config',
  2881. 'php',
  2882. 'php4',
  2883. 'php5',
  2884. 'phps',
  2885. 'phtml',
  2886. 'htm',
  2887. 'html',
  2888. 'shtml',
  2889. 'xhtml',
  2890. 'xml',
  2891. 'xsl',
  2892. 'm3u',
  2893. 'm3u8',
  2894. 'pls',
  2895. 'cue',
  2896. 'bash',
  2897. 'vue',
  2898. 'eml',
  2899. 'msg',
  2900. 'csv',
  2901. 'bat',
  2902. 'twig',
  2903. 'tpl',
  2904. 'md',
  2905. 'gitignore',
  2906. 'less',
  2907. 'sass',
  2908. 'scss',
  2909. 'c',
  2910. 'cpp',
  2911. 'cs',
  2912. 'py',
  2913. 'go',
  2914. 'zsh',
  2915. 'swift',
  2916. 'map',
  2917. 'lock',
  2918. 'dtd',
  2919. 'svg',
  2920. 'asp',
  2921. 'aspx',
  2922. 'asx',
  2923. 'asmx',
  2924. 'ashx',
  2925. 'jsp',
  2926. 'jspx',
  2927. 'cgi',
  2928. 'dockerfile',
  2929. 'ruby',
  2930. 'yml',
  2931. 'yaml',
  2932. 'toml',
  2933. 'vhost',
  2934. 'scpt',
  2935. 'applescript',
  2936. 'csx',
  2937. 'cshtml',
  2938. 'c++',
  2939. 'coffee',
  2940. 'cfm',
  2941. 'rb',
  2942. 'graphql',
  2943. 'mustache',
  2944. 'jinja',
  2945. 'http',
  2946. 'handlebars',
  2947. 'java',
  2948. 'es',
  2949. 'es6',
  2950. 'markdown',
  2951. 'wiki',
  2952. 'tmp',
  2953. 'top',
  2954. 'bot',
  2955. 'dat',
  2956. 'bak',
  2957. 'htpasswd',
  2958. 'pl',
  2959. 'ps1'
  2960. );
  2961. }
  2962. /**
  2963. * Get mime types of text files
  2964. * @return array
  2965. */
  2966. function fm_get_text_mimes()
  2967. {
  2968. return array(
  2969. 'application/xml',
  2970. 'application/javascript',
  2971. 'application/x-javascript',
  2972. 'image/svg+xml',
  2973. 'message/rfc822',
  2974. 'application/json',
  2975. );
  2976. }
  2977. /**
  2978. * Get file names of text files w/o extensions
  2979. * @return array
  2980. */
  2981. function fm_get_text_names()
  2982. {
  2983. return array(
  2984. 'license',
  2985. 'readme',
  2986. 'authors',
  2987. 'contributors',
  2988. 'changelog',
  2989. );
  2990. }
  2991. /**
  2992. * Get online docs viewer supported files extensions
  2993. * @return array
  2994. */
  2995. function fm_get_onlineViewer_exts()
  2996. {
  2997. return array('doc', 'docx', 'xls', 'xlsx', 'pdf', 'ppt', 'pptx', 'ai', 'psd', 'dxf', 'xps', 'rar', 'odt', 'ods');
  2998. }
  2999. /**
  3000. * It returns the mime type of a file based on its extension.
  3001. * @param extension The file extension of the file you want to get the mime type for.
  3002. * @return string|string[] The mime type of the file.
  3003. */
  3004. function fm_get_file_mimes($extension)
  3005. {
  3006. $fileTypes['swf'] = 'application/x-shockwave-flash';
  3007. $fileTypes['pdf'] = 'application/pdf';
  3008. $fileTypes['exe'] = 'application/octet-stream';
  3009. $fileTypes['zip'] = 'application/zip';
  3010. $fileTypes['doc'] = 'application/msword';
  3011. $fileTypes['xls'] = 'application/vnd.ms-excel';
  3012. $fileTypes['ppt'] = 'application/vnd.ms-powerpoint';
  3013. $fileTypes['gif'] = 'image/gif';
  3014. $fileTypes['png'] = 'image/png';
  3015. $fileTypes['jpeg'] = 'image/jpg';
  3016. $fileTypes['jpg'] = 'image/jpg';
  3017. $fileTypes['webp'] = 'image/webp';
  3018. $fileTypes['avif'] = 'image/avif';
  3019. $fileTypes['rar'] = 'application/rar';
  3020. $fileTypes['ra'] = 'audio/x-pn-realaudio';
  3021. $fileTypes['ram'] = 'audio/x-pn-realaudio';
  3022. $fileTypes['ogg'] = 'audio/x-pn-realaudio';
  3023. $fileTypes['wav'] = 'video/x-msvideo';
  3024. $fileTypes['wmv'] = 'video/x-msvideo';
  3025. $fileTypes['avi'] = 'video/x-msvideo';
  3026. $fileTypes['asf'] = 'video/x-msvideo';
  3027. $fileTypes['divx'] = 'video/x-msvideo';
  3028. $fileTypes['mp3'] = 'audio/mpeg';
  3029. $fileTypes['mp4'] = 'audio/mpeg';
  3030. $fileTypes['mpeg'] = 'video/mpeg';
  3031. $fileTypes['mpg'] = 'video/mpeg';
  3032. $fileTypes['mpe'] = 'video/mpeg';
  3033. $fileTypes['mov'] = 'video/quicktime';
  3034. $fileTypes['swf'] = 'video/quicktime';
  3035. $fileTypes['3gp'] = 'video/quicktime';
  3036. $fileTypes['m4a'] = 'video/quicktime';
  3037. $fileTypes['aac'] = 'video/quicktime';
  3038. $fileTypes['m3u'] = 'video/quicktime';
  3039. $fileTypes['php'] = ['application/x-php'];
  3040. $fileTypes['html'] = ['text/html'];
  3041. $fileTypes['txt'] = ['text/plain'];
  3042. //Unknown mime-types should be 'application/octet-stream'
  3043. if (empty($fileTypes[$extension])) {
  3044. $fileTypes[$extension] = ['application/octet-stream'];
  3045. }
  3046. return $fileTypes[$extension];
  3047. }
  3048. /**
  3049. * This function scans the files and folder recursively, and return matching files
  3050. * @param string $dir
  3051. * @param string $filter
  3052. * @return array|null
  3053. */
  3054. function scan($dir = '', $filter = '')
  3055. {
  3056. $path = FM_ROOT_PATH . '/' . $dir;
  3057. if ($path) {
  3058. $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
  3059. $rii = new RegexIterator($ite, "/(" . $filter . ")/i");
  3060. $files = array();
  3061. foreach ($rii as $file) {
  3062. if (!$file->isDir()) {
  3063. $fileName = $file->getFilename();
  3064. $location = str_replace(FM_ROOT_PATH, '', $file->getPath());
  3065. $files[] = array(
  3066. "name" => $fileName,
  3067. "type" => "file",
  3068. "path" => $location,
  3069. );
  3070. }
  3071. }
  3072. return $files;
  3073. }
  3074. }
  3075. /**
  3076. * Parameters: downloadFile(File Location, File Name,
  3077. * max speed, is streaming
  3078. * If streaming - videos will show as videos, images as images
  3079. * instead of download prompt
  3080. * https://stackoverflow.com/a/13821992/1164642
  3081. */
  3082. function fm_download_file($fileLocation, $fileName, $chunkSize = 1024)
  3083. {
  3084. if (connection_status() != 0)
  3085. return (false);
  3086. $extension = pathinfo($fileName, PATHINFO_EXTENSION);
  3087. $contentType = fm_get_file_mimes($extension);
  3088. if (is_array($contentType)) {
  3089. $contentType = implode(' ', $contentType);
  3090. }
  3091. $size = filesize($fileLocation);
  3092. if ($size == 0) {
  3093. fm_set_msg(lng('Zero byte file! Aborting download'), 'error');
  3094. $FM_PATH = FM_PATH;
  3095. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  3096. return (false);
  3097. }
  3098. @ini_set('magic_quotes_runtime', 0);
  3099. $fp = fopen("$fileLocation", "rb");
  3100. if ($fp === false) {
  3101. fm_set_msg(lng('Cannot open file! Aborting download'), 'error');
  3102. $FM_PATH = FM_PATH;
  3103. fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  3104. return (false);
  3105. }
  3106. // headers
  3107. header('Content-Description: File Transfer');
  3108. header('Expires: 0');
  3109. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  3110. header('Pragma: public');
  3111. header("Content-Transfer-Encoding: binary");
  3112. header("Content-Type: $contentType");
  3113. $contentDisposition = 'attachment';
  3114. if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
  3115. $fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
  3116. header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
  3117. } else {
  3118. header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
  3119. }
  3120. header("Accept-Ranges: bytes");
  3121. $range = 0;
  3122. if (isset($_SERVER['HTTP_RANGE'])) {
  3123. list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
  3124. str_replace($range, "-", $range);
  3125. $size2 = $size - 1;
  3126. $new_length = $size - $range;
  3127. header("HTTP/1.1 206 Partial Content");
  3128. header("Content-Length: $new_length");
  3129. header("Content-Range: bytes $range$size2/$size");
  3130. } else {
  3131. $size2 = $size - 1;
  3132. header("Content-Range: bytes 0-$size2/$size");
  3133. header("Content-Length: " . $size);
  3134. }
  3135. $fileLocation = realpath($fileLocation);
  3136. while (ob_get_level()) ob_end_clean();
  3137. readfile($fileLocation);
  3138. fclose($fp);
  3139. return ((connection_status() == 0) and !connection_aborted());
  3140. }
  3141. /**
  3142. * Class to work with zip files (using ZipArchive)
  3143. */
  3144. class FM_Zipper
  3145. {
  3146. private $zip;
  3147. public function __construct()
  3148. {
  3149. $this->zip = new ZipArchive();
  3150. }
  3151. /**
  3152. * Create archive with name $filename and files $files (RELATIVE PATHS!)
  3153. * @param string $filename
  3154. * @param array|string $files
  3155. * @return bool
  3156. */
  3157. public function create($filename, $files)
  3158. {
  3159. $res = $this->zip->open($filename, ZipArchive::CREATE);
  3160. if ($res !== true) {
  3161. return false;
  3162. }
  3163. if (is_array($files)) {
  3164. foreach ($files as $f) {
  3165. $f = fm_clean_path($f);
  3166. if (!$this->addFileOrDir($f)) {
  3167. $this->zip->close();
  3168. return false;
  3169. }
  3170. }
  3171. $this->zip->close();
  3172. return true;
  3173. } else {
  3174. if ($this->addFileOrDir($files)) {
  3175. $this->zip->close();
  3176. return true;
  3177. }
  3178. return false;
  3179. }
  3180. }
  3181. /**
  3182. * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
  3183. * @param string $filename
  3184. * @param string $path
  3185. * @return bool
  3186. */
  3187. public function unzip($filename, $path)
  3188. {
  3189. $res = $this->zip->open($filename);
  3190. if ($res !== true) {
  3191. return false;
  3192. }
  3193. if ($this->zip->extractTo($path)) {
  3194. $this->zip->close();
  3195. return true;
  3196. }
  3197. return false;
  3198. }
  3199. /**
  3200. * Add file/folder to archive
  3201. * @param string $filename
  3202. * @return bool
  3203. */
  3204. private function addFileOrDir($filename)
  3205. {
  3206. if (is_file($filename)) {
  3207. return $this->zip->addFile($filename);
  3208. } elseif (is_dir($filename)) {
  3209. return $this->addDir($filename);
  3210. }
  3211. return false;
  3212. }
  3213. /**
  3214. * Add folder recursively
  3215. * @param string $path
  3216. * @return bool
  3217. */
  3218. private function addDir($path)
  3219. {
  3220. if (!$this->zip->addEmptyDir($path)) {
  3221. return false;
  3222. }
  3223. $objects = scandir($path);
  3224. if (is_array($objects)) {
  3225. foreach ($objects as $file) {
  3226. if ($file != '.' && $file != '..') {
  3227. if (is_dir($path . '/' . $file)) {
  3228. if (!$this->addDir($path . '/' . $file)) {
  3229. return false;
  3230. }
  3231. } elseif (is_file($path . '/' . $file)) {
  3232. if (!$this->zip->addFile($path . '/' . $file)) {
  3233. return false;
  3234. }
  3235. }
  3236. }
  3237. }
  3238. return true;
  3239. }
  3240. return false;
  3241. }
  3242. }
  3243. /**
  3244. * Class to work with Tar files (using PharData)
  3245. */
  3246. class FM_Zipper_Tar
  3247. {
  3248. private $tar;
  3249. public function __construct()
  3250. {
  3251. $this->tar = null;
  3252. }
  3253. /**
  3254. * Create archive with name $filename and files $files (RELATIVE PATHS!)
  3255. * @param string $filename
  3256. * @param array|string $files
  3257. * @return bool
  3258. */
  3259. public function create($filename, $files)
  3260. {
  3261. $this->tar = new PharData($filename);
  3262. if (is_array($files)) {
  3263. foreach ($files as $f) {
  3264. $f = fm_clean_path($f);
  3265. if (!$this->addFileOrDir($f)) {
  3266. return false;
  3267. }
  3268. }
  3269. return true;
  3270. } else {
  3271. if ($this->addFileOrDir($files)) {
  3272. return true;
  3273. }
  3274. return false;
  3275. }
  3276. }
  3277. /**
  3278. * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
  3279. * @param string $filename
  3280. * @param string $path
  3281. * @return bool
  3282. */
  3283. public function unzip($filename, $path)
  3284. {
  3285. $res = $this->tar->open($filename);
  3286. if ($res !== true) {
  3287. return false;
  3288. }
  3289. if ($this->tar->extractTo($path)) {
  3290. return true;
  3291. }
  3292. return false;
  3293. }
  3294. /**
  3295. * Add file/folder to archive
  3296. * @param string $filename
  3297. * @return bool
  3298. */
  3299. private function addFileOrDir($filename)
  3300. {
  3301. if (is_file($filename)) {
  3302. try {
  3303. $this->tar->addFile($filename);
  3304. return true;
  3305. } catch (Exception $e) {
  3306. return false;
  3307. }
  3308. } elseif (is_dir($filename)) {
  3309. return $this->addDir($filename);
  3310. }
  3311. return false;
  3312. }
  3313. /**
  3314. * Add folder recursively
  3315. * @param string $path
  3316. * @return bool
  3317. */
  3318. private function addDir($path)
  3319. {
  3320. $objects = scandir($path);
  3321. if (is_array($objects)) {
  3322. foreach ($objects as $file) {
  3323. if ($file != '.' && $file != '..') {
  3324. if (is_dir($path . '/' . $file)) {
  3325. if (!$this->addDir($path . '/' . $file)) {
  3326. return false;
  3327. }
  3328. } elseif (is_file($path . '/' . $file)) {
  3329. try {
  3330. $this->tar->addFile($path . '/' . $file);
  3331. } catch (Exception $e) {
  3332. return false;
  3333. }
  3334. }
  3335. }
  3336. }
  3337. return true;
  3338. }
  3339. return false;
  3340. }
  3341. }
  3342. /**
  3343. * Save Configuration
  3344. */
  3345. class FM_Config
  3346. {
  3347. var $data;
  3348. function __construct()
  3349. {
  3350. global $root_path, $root_url, $CONFIG;
  3351. $fm_url = $root_url . $_SERVER["PHP_SELF"];
  3352. $this->data = array(
  3353. 'lang' => 'en',
  3354. 'error_reporting' => true,
  3355. 'show_hidden' => true
  3356. );
  3357. $data = false;
  3358. if (strlen($CONFIG)) {
  3359. $data = fm_object_to_array(json_decode($CONFIG));
  3360. } else {
  3361. $msg = 'Tiny File Manager<br>Error: Cannot load configuration';
  3362. if (substr($fm_url, -1) == '/') {
  3363. $fm_url = rtrim($fm_url, '/');
  3364. $msg .= '<br>';
  3365. $msg .= '<br>Seems like you have a trailing slash on the URL.';
  3366. $msg .= '<br>Try this link: <a href="' . $fm_url . '">' . $fm_url . '</a>';
  3367. }
  3368. die($msg);
  3369. }
  3370. if (is_array($data) && count($data)) $this->data = $data;
  3371. else $this->save();
  3372. }
  3373. function save()
  3374. {
  3375. global $config_file;
  3376. $fm_file = is_readable($config_file) ? $config_file : __FILE__;
  3377. $var_name = '$CONFIG';
  3378. $var_value = var_export(json_encode($this->data), true);
  3379. $config_string = "<?php" . chr(13) . chr(10) . "//Default Configuration" . chr(13) . chr(10) . "$var_name = $var_value;" . chr(13) . chr(10);
  3380. if (is_writable($fm_file)) {
  3381. $lines = file($fm_file);
  3382. if ($fh = @fopen($fm_file, "w")) {
  3383. @fputs($fh, $config_string, strlen($config_string));
  3384. for ($x = 3; $x < count($lines); $x++) {
  3385. @fputs($fh, $lines[$x], strlen($lines[$x]));
  3386. }
  3387. @fclose($fh);
  3388. }
  3389. }
  3390. }
  3391. }
  3392. //--- Templates Functions ---
  3393. /**
  3394. * Show nav block
  3395. * @param string $path
  3396. */
  3397. function fm_show_nav_path($path)
  3398. {
  3399. global $lang, $sticky_navbar, $editFile;
  3400. $isStickyNavBar = $sticky_navbar ? 'fixed-top' : '';
  3401. ?>
  3402. <nav class="navbar navbar-expand-lg mb-4 main-nav <?php echo $isStickyNavBar ?> bg-body-tertiary" data-bs-theme="<?php echo FM_THEME; ?>">
  3403. <a class="navbar-brand"> <?php echo lng('AppTitle') ?> </a>
  3404. <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  3405. <span class="navbar-toggler-icon"></span>
  3406. </div>
  3407. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  3408. <?php
  3409. $path = fm_clean_path($path);
  3410. $root_url = "<a href='?p='><i class='fa fa-home' aria-hidden='true' title='" . FM_ROOT_PATH . "'></i></a>";
  3411. $sep = '<i class="bread-crumb"> / </i>';
  3412. if ($path != '') {
  3413. $exploded = explode('/', $path);
  3414. $count = count($exploded);
  3415. $array = array();
  3416. $parent = '';
  3417. for ($i = 0; $i < $count; $i++) {
  3418. $parent = trim($parent . '/' . $exploded[$i], '/');
  3419. $parent_enc = urlencode($parent);
  3420. $array[] = "<a href='?p={$parent_enc}'>" . fm_enc(fm_convert_win($exploded[$i])) . "</a>";
  3421. }
  3422. $root_url .= $sep . implode($sep, $array);
  3423. }
  3424. echo '<div class="col-xs-6 col-sm-5">' . $root_url . $editFile . '</div>';
  3425. ?>
  3426. <div class="col-xs-6 col-sm-7">
  3427. <ul class="navbar-nav justify-content-end" data-bs-theme="<?php echo FM_THEME; ?>">
  3428. <li class="nav-item mr-2">
  3429. <div class="input-group input-group-sm mr-1" style="margin-top:4px;">
  3430. <input type="text" class="form-control" placeholder="<?php echo lng('Search') ?>" aria-label="<?php echo lng('Search') ?>" aria-describedby="search-addon2" id="search-addon">
  3431. <div class="input-group-append">
  3432. <span class="input-group-text brl-0 brr-0" id="search-addon2"><i class="fa fa-search"></i></span>
  3433. </div>
  3434. <div class="input-group-append btn-group">
  3435. <span class="input-group-text dropdown-toggle brl-0" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
  3436. <div class="dropdown-menu dropdown-menu-right">
  3437. <a class="dropdown-item" href="<?php echo $path2 = $path ? $path : '.'; ?>" id="js-search-modal" data-bs-toggle="modal" data-bs-target="#searchModal"><?php echo lng('Advanced Search') ?></a>
  3438. </div>
  3439. </div>
  3440. </div>
  3441. </li>
  3442. <?php if (!FM_READONLY): ?>
  3443. <li class="nav-item">
  3444. <a title="<?php echo lng('Upload') ?>" class="nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;upload"><i class="fa fa-cloud-upload" aria-hidden="true"></i> <?php echo lng('Upload') ?></a>
  3445. </li>
  3446. <li class="nav-item">
  3447. <a title="<?php echo lng('NewItem') ?>" class="nav-link" href="#createNewItem" data-bs-toggle="modal" data-bs-target="#createNewItem"><i class="fa fa-plus-square"></i> <?php echo lng('NewItem') ?></a>
  3448. </li>
  3449. <?php endif; ?>
  3450. <?php if (FM_USE_AUTH): ?>
  3451. <li class="nav-item avatar dropdown">
  3452. <a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink-5" data-bs-toggle="dropdown" aria-expanded="false">
  3453. <i class="fa fa-user-circle"></i>
  3454. </a>
  3455. <div class="dropdown-menu dropdown-menu-end text-small shadow" aria-labelledby="navbarDropdownMenuLink-5" data-bs-theme="<?php echo FM_THEME; ?>">
  3456. <?php if (!FM_READONLY): ?>
  3457. <a title="<?php echo lng('Settings') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;settings=1"><i class="fa fa-cog" aria-hidden="true"></i> <?php echo lng('Settings') ?></a>
  3458. <?php endif ?>
  3459. <a title="<?php echo lng('Help') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;help=2"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> <?php echo lng('Help') ?></a>
  3460. <a title="<?php echo lng('Logout') ?>" class="dropdown-item nav-link" href="?logout=1"><i class="fa fa-sign-out" aria-hidden="true"></i> <?php echo lng('Logout') ?></a>
  3461. </div>
  3462. </li>
  3463. <?php else: ?>
  3464. <?php if (!FM_READONLY): ?>
  3465. <li class="nav-item">
  3466. <a title="<?php echo lng('Settings') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;settings=1"><i class="fa fa-cog" aria-hidden="true"></i> <?php echo lng('Settings') ?></a>
  3467. </li>
  3468. <?php endif; ?>
  3469. <?php endif; ?>
  3470. </ul>
  3471. </div>
  3472. </div>
  3473. </nav>
  3474. <?php
  3475. }
  3476. /**
  3477. * Show alert message from session
  3478. */
  3479. function fm_show_message()
  3480. {
  3481. if (isset($_SESSION[FM_SESSION_ID]['message'])) {
  3482. $class = isset($_SESSION[FM_SESSION_ID]['status']) ? $_SESSION[FM_SESSION_ID]['status'] : 'ok';
  3483. echo '<p class="message ' . $class . '">' . $_SESSION[FM_SESSION_ID]['message'] . '</p>';
  3484. unset($_SESSION[FM_SESSION_ID]['message']);
  3485. unset($_SESSION[FM_SESSION_ID]['status']);
  3486. }
  3487. }
  3488. /**
  3489. * Show page header in Login Form
  3490. */
  3491. function fm_show_header_login()
  3492. {
  3493. header("Content-Type: text/html; charset=utf-8");
  3494. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  3495. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  3496. header("Pragma: no-cache");
  3497. global $favicon_path;
  3498. ?>
  3499. <!DOCTYPE html>
  3500. <html lang="en" data-bs-theme="<?php echo (FM_THEME == "dark") ? 'dark' : 'light' ?>">
  3501. <head>
  3502. <meta charset="utf-8">
  3503. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  3504. <meta name="description" content="Web based File Manager in PHP, Manage your files efficiently and easily with Tiny File Manager">
  3505. <meta name="author" content="CCP Programmers">
  3506. <meta name="robots" content="noindex, nofollow">
  3507. <meta name="googlebot" content="noindex">
  3508. <?php if ($favicon_path) {
  3509. echo '<link rel="icon" href="' . fm_enc($favicon_path) . '" type="image/png">';
  3510. } ?>
  3511. <title><?php echo fm_enc(APP_TITLE) ?></title>
  3512. <?php print_external('pre-jsdelivr'); ?>
  3513. <?php print_external('css-bootstrap'); ?>
  3514. <style>
  3515. body.fm-login-page {
  3516. background-color: #f7f9fb;
  3517. font-size: 14px;
  3518. background-color: #f7f9fb;
  3519. background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 304 304' width='304' height='304'%3E%3Cpath fill='%23e2e9f1' fill-opacity='0.4' d='M44.1 224a5 5 0 1 1 0 2H0v-2h44.1zm160 48a5 5 0 1 1 0 2H82v-2h122.1zm57.8-46a5 5 0 1 1 0-2H304v2h-42.1zm0 16a5 5 0 1 1 0-2H304v2h-42.1zm6.2-114a5 5 0 1 1 0 2h-86.2a5 5 0 1 1 0-2h86.2zm-256-48a5 5 0 1 1 0 2H0v-2h12.1zm185.8 34a5 5 0 1 1 0-2h86.2a5 5 0 1 1 0 2h-86.2zM258 12.1a5 5 0 1 1-2 0V0h2v12.1zm-64 208a5 5 0 1 1-2 0v-54.2a5 5 0 1 1 2 0v54.2zm48-198.2V80h62v2h-64V21.9a5 5 0 1 1 2 0zm16 16V64h46v2h-48V37.9a5 5 0 1 1 2 0zm-128 96V208h16v12.1a5 5 0 1 1-2 0V210h-16v-76.1a5 5 0 1 1 2 0zm-5.9-21.9a5 5 0 1 1 0 2H114v48H85.9a5 5 0 1 1 0-2H112v-48h12.1zm-6.2 130a5 5 0 1 1 0-2H176v-74.1a5 5 0 1 1 2 0V242h-60.1zm-16-64a5 5 0 1 1 0-2H114v48h10.1a5 5 0 1 1 0 2H112v-48h-10.1zM66 284.1a5 5 0 1 1-2 0V274H50v30h-2v-32h18v12.1zM236.1 176a5 5 0 1 1 0 2H226v94h48v32h-2v-30h-48v-98h12.1zm25.8-30a5 5 0 1 1 0-2H274v44.1a5 5 0 1 1-2 0V146h-10.1zm-64 96a5 5 0 1 1 0-2H208v-80h16v-14h-42.1a5 5 0 1 1 0-2H226v18h-16v80h-12.1zm86.2-210a5 5 0 1 1 0 2H272V0h2v32h10.1zM98 101.9V146H53.9a5 5 0 1 1 0-2H96v-42.1a5 5 0 1 1 2 0zM53.9 34a5 5 0 1 1 0-2H80V0h2v34H53.9zm60.1 3.9V66H82v64H69.9a5 5 0 1 1 0-2H80V64h32V37.9a5 5 0 1 1 2 0zM101.9 82a5 5 0 1 1 0-2H128V37.9a5 5 0 1 1 2 0V82h-28.1zm16-64a5 5 0 1 1 0-2H146v44.1a5 5 0 1 1-2 0V18h-26.1zm102.2 270a5 5 0 1 1 0 2H98v14h-2v-16h124.1zM242 149.9V160h16v34h-16v62h48v48h-2v-46h-48v-66h16v-30h-16v-12.1a5 5 0 1 1 2 0zM53.9 18a5 5 0 1 1 0-2H64V2H48V0h18v18H53.9zm112 32a5 5 0 1 1 0-2H192V0h50v2h-48v48h-28.1zm-48-48a5 5 0 0 1-9.8-2h2.07a3 3 0 1 0 5.66 0H178v34h-18V21.9a5 5 0 1 1 2 0V32h14V2h-58.1zm0 96a5 5 0 1 1 0-2H137l32-32h39V21.9a5 5 0 1 1 2 0V66h-40.17l-32 32H117.9zm28.1 90.1a5 5 0 1 1-2 0v-76.51L175.59 80H224V21.9a5 5 0 1 1 2 0V82h-49.59L146 112.41v75.69zm16 32a5 5 0 1 1-2 0v-99.51L184.59 96H300.1a5 5 0 0 1 3.9-3.9v2.07a3 3 0 0 0 0 5.66v2.07a5 5 0 0 1-3.9-3.9H185.41L162 121.41v98.69zm-144-64a5 5 0 1 1-2 0v-3.51l48-48V48h32V0h2v50H66v55.41l-48 48v2.69zM50 53.9v43.51l-48 48V208h26.1a5 5 0 1 1 0 2H0v-65.41l48-48V53.9a5 5 0 1 1 2 0zm-16 16V89.41l-34 34v-2.82l32-32V69.9a5 5 0 1 1 2 0zM12.1 32a5 5 0 1 1 0 2H9.41L0 43.41V40.6L8.59 32h3.51zm265.8 18a5 5 0 1 1 0-2h18.69l7.41-7.41v2.82L297.41 50H277.9zm-16 160a5 5 0 1 1 0-2H288v-71.41l16-16v2.82l-14 14V210h-28.1zm-208 32a5 5 0 1 1 0-2H64v-22.59L40.59 194H21.9a5 5 0 1 1 0-2H41.41L66 216.59V242H53.9zm150.2 14a5 5 0 1 1 0 2H96v-56.6L56.6 162H37.9a5 5 0 1 1 0-2h19.5L98 200.6V256h106.1zm-150.2 2a5 5 0 1 1 0-2H80v-46.59L48.59 178H21.9a5 5 0 1 1 0-2H49.41L82 208.59V258H53.9zM34 39.8v1.61L9.41 66H0v-2h8.59L32 40.59V0h2v39.8zM2 300.1a5 5 0 0 1 3.9 3.9H3.83A3 3 0 0 0 0 302.17V256h18v48h-2v-46H2v42.1zM34 241v63h-2v-62H0v-2h34v1zM17 18H0v-2h16V0h2v18h-1zm273-2h14v2h-16V0h2v16zm-32 273v15h-2v-14h-14v14h-2v-16h18v1zM0 92.1A5.02 5.02 0 0 1 6 97a5 5 0 0 1-6 4.9v-2.07a3 3 0 1 0 0-5.66V92.1zM80 272h2v32h-2v-32zm37.9 32h-2.07a3 3 0 0 0-5.66 0h-2.07a5 5 0 0 1 9.8 0zM5.9 0A5.02 5.02 0 0 1 0 5.9V3.83A3 3 0 0 0 3.83 0H5.9zm294.2 0h2.07A3 3 0 0 0 304 3.83V5.9a5 5 0 0 1-3.9-5.9zm3.9 300.1v2.07a3 3 0 0 0-1.83 1.83h-2.07a5 5 0 0 1 3.9-3.9zM97 100a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-48 32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 48a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 96a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-144a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-96 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm96 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-32 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM49 36a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-32 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM33 68a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-48a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 240a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm80-176a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 48a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm112 176a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM17 180a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM17 84a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6z'%3E%3C/path%3E%3C/svg%3E");
  3520. }
  3521. .fm-login-page .brand {
  3522. width: 121px;
  3523. overflow: hidden;
  3524. margin: 0 auto;
  3525. position: relative;
  3526. z-index: 1
  3527. }
  3528. .fm-login-page .brand img {
  3529. width: 100%
  3530. }
  3531. .fm-login-page .card-wrapper {
  3532. width: 360px;
  3533. }
  3534. .fm-login-page .card {
  3535. border-color: transparent;
  3536. box-shadow: 0 4px 8px rgba(0, 0, 0, .05)
  3537. }
  3538. .fm-login-page .card-title {
  3539. margin-bottom: 1.5rem;
  3540. font-size: 24px;
  3541. font-weight: 400;
  3542. }
  3543. .fm-login-page .form-control {
  3544. border-width: 2.3px
  3545. }
  3546. .fm-login-page .form-group label {
  3547. width: 100%
  3548. }
  3549. .fm-login-page .btn.btn-block {
  3550. padding: 12px 10px
  3551. }
  3552. .fm-login-page .footer {
  3553. margin: 20px 0;
  3554. color: #888;
  3555. text-align: center
  3556. }
  3557. @media screen and (max-width:425px) {
  3558. .fm-login-page .card-wrapper {
  3559. width: 90%;
  3560. margin: 0 auto;
  3561. margin-top: 10%;
  3562. }
  3563. }
  3564. @media screen and (max-width:320px) {
  3565. .fm-login-page .card.fat {
  3566. padding: 0
  3567. }
  3568. .fm-login-page .card.fat .card-body {
  3569. padding: 15px
  3570. }
  3571. }
  3572. .message {
  3573. padding: 4px 7px;
  3574. border: 1px solid #ddd;
  3575. background-color: #fff
  3576. }
  3577. .message.ok {
  3578. border-color: green;
  3579. color: green
  3580. }
  3581. .message.error {
  3582. border-color: red;
  3583. color: red
  3584. }
  3585. .message.alert {
  3586. border-color: orange;
  3587. color: orange
  3588. }
  3589. body.fm-login-page.theme-dark {
  3590. background-color: #2f2a2a;
  3591. }
  3592. .theme-dark svg g,
  3593. .theme-dark svg path {
  3594. fill: #ffffff;
  3595. }
  3596. .theme-dark .form-control {
  3597. color: #fff;
  3598. background-color: #403e3e;
  3599. }
  3600. .h-100vh {
  3601. min-height: 100vh;
  3602. }
  3603. </style>
  3604. </head>
  3605. <body class="fm-login-page <?php echo (FM_THEME == "dark") ? 'theme-dark' : ''; ?>">
  3606. <div id="wrapper" class="container-fluid">
  3607. <?php
  3608. }
  3609. /**
  3610. * Show page footer in Login Form
  3611. */
  3612. function fm_show_footer_login()
  3613. {
  3614. ?>
  3615. </div>
  3616. <?php print_external('js-jquery'); ?>
  3617. <?php print_external('js-bootstrap'); ?>
  3618. </body>
  3619. </html>
  3620. <?php
  3621. }
  3622. /**
  3623. * Show Header after login
  3624. */
  3625. function fm_show_header()
  3626. {
  3627. header("Content-Type: text/html; charset=utf-8");
  3628. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  3629. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  3630. header("Pragma: no-cache");
  3631. global $sticky_navbar, $favicon_path;
  3632. $isStickyNavBar = $sticky_navbar ? 'navbar-fixed' : 'navbar-normal';
  3633. ?>
  3634. <!DOCTYPE html>
  3635. <html data-bs-theme="<?php echo FM_THEME; ?>">
  3636. <head>
  3637. <meta charset="utf-8">
  3638. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  3639. <meta name="description" content="Web based File Manager in PHP, Manage your files efficiently and easily with Tiny File Manager">
  3640. <meta name="author" content="CCP Programmers">
  3641. <meta name="robots" content="noindex, nofollow">
  3642. <meta name="googlebot" content="noindex">
  3643. <?php if ($favicon_path) {
  3644. echo '<link rel="icon" href="' . fm_enc($favicon_path) . '" type="image/png">';
  3645. } ?>
  3646. <title><?php echo fm_enc(APP_TITLE) ?> | <?php echo (isset($_GET['view']) ? $_GET['view'] : ((isset($_GET['edit'])) ? $_GET['edit'] : "H3K")); ?></title>
  3647. <?php print_external('pre-jsdelivr'); ?>
  3648. <?php print_external('pre-cloudflare'); ?>
  3649. <?php print_external('css-bootstrap'); ?>
  3650. <?php print_external('css-font-awesome'); ?>
  3651. <?php if (FM_USE_HIGHLIGHTJS && isset($_GET['view'])): ?>
  3652. <?php print_external('css-highlightjs'); ?>
  3653. <?php endif; ?>
  3654. <script type="text/javascript">
  3655. window.csrf = '<?php echo $_SESSION['token']; ?>';
  3656. </script>
  3657. <style>
  3658. html {
  3659. -moz-osx-font-smoothing: grayscale;
  3660. -webkit-font-smoothing: antialiased;
  3661. text-rendering: optimizeLegibility;
  3662. height: 100%;
  3663. scroll-behavior: smooth;
  3664. }
  3665. *,
  3666. *::before,
  3667. *::after {
  3668. box-sizing: border-box;
  3669. }
  3670. body {
  3671. font-size: 15px;
  3672. color: #222;
  3673. background: #F7F7F7;
  3674. }
  3675. body.navbar-fixed {
  3676. margin-top: 55px;
  3677. }
  3678. a,
  3679. a:hover,
  3680. a:visited,
  3681. a:focus {
  3682. text-decoration: none !important;
  3683. }
  3684. .filename,
  3685. td,
  3686. th {
  3687. white-space: nowrap
  3688. }
  3689. .navbar-brand {
  3690. font-weight: bold;
  3691. }
  3692. .nav-item.avatar a {
  3693. cursor: pointer;
  3694. text-transform: capitalize;
  3695. }
  3696. .nav-item.avatar a>i {
  3697. font-size: 15px;
  3698. }
  3699. .nav-item.avatar .dropdown-menu a {
  3700. font-size: 13px;
  3701. }
  3702. #search-addon {
  3703. font-size: 12px;
  3704. border-right-width: 0;
  3705. }
  3706. .brl-0 {
  3707. background: transparent;
  3708. border-left: 0;
  3709. border-top-left-radius: 0;
  3710. border-bottom-left-radius: 0;
  3711. }
  3712. .brr-0 {
  3713. border-top-right-radius: 0;
  3714. border-bottom-right-radius: 0;
  3715. }
  3716. .bread-crumb {
  3717. color: #cccccc;
  3718. font-style: normal;
  3719. }
  3720. #main-table {
  3721. transition: transform .25s cubic-bezier(0.4, 0.5, 0, 1), width 0s .25s;
  3722. }
  3723. #main-table .filename a {
  3724. color: #222222;
  3725. }
  3726. .table td,
  3727. .table th {
  3728. vertical-align: middle !important;
  3729. }
  3730. .table .custom-checkbox-td .custom-control.custom-checkbox,
  3731. .table .custom-checkbox-header .custom-control.custom-checkbox {
  3732. min-width: 18px;
  3733. display: flex;
  3734. align-items: center;
  3735. justify-content: center;
  3736. }
  3737. .table-sm td,
  3738. .table-sm th {
  3739. padding: .4rem;
  3740. }
  3741. .table-bordered td,
  3742. .table-bordered th {
  3743. border: 1px solid #f1f1f1;
  3744. }
  3745. .hidden {
  3746. display: none
  3747. }
  3748. pre.with-hljs {
  3749. padding: 0;
  3750. overflow: hidden;
  3751. }
  3752. pre.with-hljs code {
  3753. margin: 0;
  3754. border: 0;
  3755. overflow: scroll;
  3756. }
  3757. code.maxheight,
  3758. pre.maxheight {
  3759. max-height: 512px
  3760. }
  3761. .fa.fa-caret-right {
  3762. font-size: 1.2em;
  3763. margin: 0 4px;
  3764. vertical-align: middle;
  3765. color: #ececec
  3766. }
  3767. .fa.fa-home {
  3768. font-size: 1.3em;
  3769. vertical-align: bottom
  3770. }
  3771. .path {
  3772. margin-bottom: 10px
  3773. }
  3774. form.dropzone {
  3775. min-height: 200px;
  3776. border: 2px dashed #007bff;
  3777. line-height: 6rem;
  3778. }
  3779. .right {
  3780. text-align: right
  3781. }
  3782. .center,
  3783. .close,
  3784. .login-form,
  3785. .preview-img-container {
  3786. text-align: center
  3787. }
  3788. .message {
  3789. padding: 4px 7px;
  3790. border: 1px solid #ddd;
  3791. background-color: #fff
  3792. }
  3793. .message.ok {
  3794. border-color: green;
  3795. color: green
  3796. }
  3797. .message.error {
  3798. border-color: red;
  3799. color: red
  3800. }
  3801. .message.alert {
  3802. border-color: orange;
  3803. color: orange
  3804. }
  3805. .preview-img {
  3806. max-width: 100%;
  3807. max-height: 80vh;
  3808. background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC);
  3809. cursor: zoom-in
  3810. }
  3811. input#preview-img-zoomCheck[type=checkbox] {
  3812. display: none
  3813. }
  3814. input#preview-img-zoomCheck[type=checkbox]:checked~label>img {
  3815. max-width: none;
  3816. max-height: none;
  3817. cursor: zoom-out
  3818. }
  3819. .inline-actions>a>i {
  3820. font-size: 1em;
  3821. margin-left: 5px;
  3822. background: #3785c1;
  3823. color: #fff;
  3824. padding: 3px 4px;
  3825. border-radius: 3px;
  3826. }
  3827. .preview-video {
  3828. position: relative;
  3829. max-width: 100%;
  3830. height: 0;
  3831. padding-bottom: 62.5%;
  3832. margin-bottom: 10px
  3833. }
  3834. .preview-video video {
  3835. position: absolute;
  3836. width: 100%;
  3837. height: 100%;
  3838. left: 0;
  3839. top: 0;
  3840. background: #000
  3841. }
  3842. .compact-table {
  3843. border: 0;
  3844. width: auto
  3845. }
  3846. .compact-table td,
  3847. .compact-table th {
  3848. width: 100px;
  3849. border: 0;
  3850. text-align: center
  3851. }
  3852. .compact-table tr:hover td {
  3853. background-color: #fff
  3854. }
  3855. .filename {
  3856. max-width: 420px;
  3857. overflow: hidden;
  3858. text-overflow: ellipsis
  3859. }
  3860. .break-word {
  3861. word-wrap: break-word;
  3862. margin-left: 30px
  3863. }
  3864. .break-word.float-left a {
  3865. color: #7d7d7d
  3866. }
  3867. .break-word+.float-right {
  3868. padding-right: 30px;
  3869. position: relative
  3870. }
  3871. .break-word+.float-right>a {
  3872. color: #7d7d7d;
  3873. font-size: 1.2em;
  3874. margin-right: 4px
  3875. }
  3876. #editor {
  3877. position: absolute;
  3878. right: 15px;
  3879. top: 100px;
  3880. bottom: 15px;
  3881. left: 15px
  3882. }
  3883. @media (max-width:481px) {
  3884. #editor {
  3885. top: 150px;
  3886. }
  3887. }
  3888. #normal-editor {
  3889. border-radius: 3px;
  3890. border-width: 2px;
  3891. padding: 10px;
  3892. outline: none;
  3893. }
  3894. .btn-2 {
  3895. padding: 4px 10px;
  3896. font-size: small;
  3897. }
  3898. li.file:before,
  3899. li.folder:before {
  3900. font: normal normal normal 14px/1 FontAwesome;
  3901. content: "\f016";
  3902. margin-right: 5px
  3903. }
  3904. li.folder:before {
  3905. content: "\f114"
  3906. }
  3907. i.fa.fa-folder-o {
  3908. color: #0157b3
  3909. }
  3910. i.fa.fa-picture-o {
  3911. color: #26b99a
  3912. }
  3913. i.fa.fa-file-archive-o {
  3914. color: #da7d7d
  3915. }
  3916. .btn-2 i.fa.fa-file-archive-o {
  3917. color: inherit
  3918. }
  3919. i.fa.fa-css3 {
  3920. color: #f36fa0
  3921. }
  3922. i.fa.fa-file-code-o {
  3923. color: #007bff
  3924. }
  3925. i.fa.fa-code {
  3926. color: #cc4b4c
  3927. }
  3928. i.fa.fa-file-text-o {
  3929. color: #0096e6
  3930. }
  3931. i.fa.fa-html5 {
  3932. color: #d75e72
  3933. }
  3934. i.fa.fa-file-excel-o {
  3935. color: #09c55d
  3936. }
  3937. i.fa.fa-file-powerpoint-o {
  3938. color: #f6712e
  3939. }
  3940. i.go-back {
  3941. font-size: 1.2em;
  3942. color: #007bff;
  3943. }
  3944. .main-nav {
  3945. padding: 0.2rem 1rem;
  3946. box-shadow: 0 4px 5px 0 rgba(0, 0, 0, .14), 0 1px 10px 0 rgba(0, 0, 0, .12), 0 2px 4px -1px rgba(0, 0, 0, .2)
  3947. }
  3948. .dataTables_filter {
  3949. display: none;
  3950. }
  3951. table.dataTable thead .sorting {
  3952. cursor: pointer;
  3953. background-repeat: no-repeat;
  3954. background-position: center right;
  3955. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7XQMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL+Tq/QCM1oNiJidwox0355mXnG/DrEtIQ6azioNZQxI0ykPhTQIwhCR+BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4euts6z39GYMKRPCTKY9UnPQ6P+GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC');
  3956. }
  3957. table.dataTable thead .sorting_asc {
  3958. cursor: pointer;
  3959. background-repeat: no-repeat;
  3960. background-position: center right;
  3961. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBdqEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVoAADeemwtPcZI2wAAAABJRU5ErkJggg==');
  3962. }
  3963. table.dataTable thead .sorting_desc {
  3964. cursor: pointer;
  3965. background-repeat: no-repeat;
  3966. background-position: center right;
  3967. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWjYBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJzcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII=');
  3968. }
  3969. table.dataTable thead tr:first-child th.custom-checkbox-header:first-child {
  3970. background-image: none;
  3971. }
  3972. .footer-action li {
  3973. margin-bottom: 10px;
  3974. }
  3975. .app-v-title {
  3976. font-size: 24px;
  3977. font-weight: 300;
  3978. letter-spacing: -.5px;
  3979. text-transform: uppercase;
  3980. }
  3981. hr.custom-hr {
  3982. border-top: 1px dashed #8c8b8b;
  3983. border-bottom: 1px dashed #fff;
  3984. }
  3985. #snackbar {
  3986. visibility: hidden;
  3987. min-width: 250px;
  3988. margin-left: -125px;
  3989. background-color: #333;
  3990. color: #fff;
  3991. text-align: center;
  3992. border-radius: 2px;
  3993. padding: 16px;
  3994. position: fixed;
  3995. z-index: 1;
  3996. left: 50%;
  3997. bottom: 30px;
  3998. font-size: 17px;
  3999. }
  4000. #snackbar.show {
  4001. visibility: visible;
  4002. -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  4003. animation: fadein 0.5s, fadeout 0.5s 2.5s;
  4004. }
  4005. @-webkit-keyframes fadein {
  4006. from {
  4007. bottom: 0;
  4008. opacity: 0;
  4009. }
  4010. to {
  4011. bottom: 30px;
  4012. opacity: 1;
  4013. }
  4014. }
  4015. @keyframes fadein {
  4016. from {
  4017. bottom: 0;
  4018. opacity: 0;
  4019. }
  4020. to {
  4021. bottom: 30px;
  4022. opacity: 1;
  4023. }
  4024. }
  4025. @-webkit-keyframes fadeout {
  4026. from {
  4027. bottom: 30px;
  4028. opacity: 1;
  4029. }
  4030. to {
  4031. bottom: 0;
  4032. opacity: 0;
  4033. }
  4034. }
  4035. @keyframes fadeout {
  4036. from {
  4037. bottom: 30px;
  4038. opacity: 1;
  4039. }
  4040. to {
  4041. bottom: 0;
  4042. opacity: 0;
  4043. }
  4044. }
  4045. #main-table span.badge {
  4046. border-bottom: 2px solid #f8f9fa
  4047. }
  4048. #main-table span.badge:nth-child(1) {
  4049. border-color: #df4227
  4050. }
  4051. #main-table span.badge:nth-child(2) {
  4052. border-color: #f8b600
  4053. }
  4054. #main-table span.badge:nth-child(3) {
  4055. border-color: #00bd60
  4056. }
  4057. #main-table span.badge:nth-child(4) {
  4058. border-color: #4581ff
  4059. }
  4060. #main-table span.badge:nth-child(5) {
  4061. border-color: #ac68fc
  4062. }
  4063. #main-table span.badge:nth-child(6) {
  4064. border-color: #45c3d2
  4065. }
  4066. @media only screen and (min-device-width:768px) and (max-device-width:1024px) and (orientation:landscape) and (-webkit-min-device-pixel-ratio:2) {
  4067. .navbar-collapse .col-xs-6 {
  4068. padding: 0;
  4069. }
  4070. }
  4071. .btn.active.focus,
  4072. .btn.active:focus,
  4073. .btn.focus,
  4074. .btn.focus:active,
  4075. .btn:active:focus,
  4076. .btn:focus {
  4077. outline: 0 !important;
  4078. outline-offset: 0 !important;
  4079. background-image: none !important;
  4080. -webkit-box-shadow: none !important;
  4081. box-shadow: none !important
  4082. }
  4083. .lds-facebook {
  4084. display: none;
  4085. position: relative;
  4086. width: 64px;
  4087. height: 64px
  4088. }
  4089. .lds-facebook div,
  4090. .lds-facebook.show-me {
  4091. display: inline-block
  4092. }
  4093. .lds-facebook div {
  4094. position: absolute;
  4095. left: 6px;
  4096. width: 13px;
  4097. background: #007bff;
  4098. animation: lds-facebook 1.2s cubic-bezier(0, .5, .5, 1) infinite
  4099. }
  4100. .lds-facebook div:nth-child(1) {
  4101. left: 6px;
  4102. animation-delay: -.24s
  4103. }
  4104. .lds-facebook div:nth-child(2) {
  4105. left: 26px;
  4106. animation-delay: -.12s
  4107. }
  4108. .lds-facebook div:nth-child(3) {
  4109. left: 45px;
  4110. animation-delay: 0s
  4111. }
  4112. @keyframes lds-facebook {
  4113. 0% {
  4114. top: 6px;
  4115. height: 51px
  4116. }
  4117. 100%,
  4118. 50% {
  4119. top: 19px;
  4120. height: 26px
  4121. }
  4122. }
  4123. ul#search-wrapper {
  4124. padding-left: 0;
  4125. border: 1px solid #ecececcc;
  4126. }
  4127. ul#search-wrapper li {
  4128. list-style: none;
  4129. padding: 5px;
  4130. border-bottom: 1px solid #ecececcc;
  4131. }
  4132. ul#search-wrapper li:nth-child(odd) {
  4133. background: #f9f9f9cc;
  4134. }
  4135. .c-preview-img {
  4136. max-width: 300px;
  4137. }
  4138. .border-radius-0 {
  4139. border-radius: 0;
  4140. }
  4141. .float-right {
  4142. float: right;
  4143. }
  4144. .table-hover>tbody>tr:hover>td:first-child {
  4145. border-left: 1px solid #1b77fd;
  4146. }
  4147. #main-table tr.even {
  4148. background-color: #F8F9Fa;
  4149. }
  4150. .filename>a>i {
  4151. margin-right: 3px;
  4152. }
  4153. .fs-7 {
  4154. font-size: 14px;
  4155. }
  4156. </style>
  4157. <?php
  4158. if (FM_THEME == "dark"): ?>
  4159. <style>
  4160. :root {
  4161. --bs-bg-opacity: 1;
  4162. --bg-color: #f3daa6;
  4163. --bs-dark-rgb: 28, 36, 41 !important;
  4164. --bs-bg-opacity: 1;
  4165. }
  4166. body.theme-dark {
  4167. background-image: linear-gradient(90deg, #1c2429, #263238);
  4168. color: #CFD8DC;
  4169. }
  4170. .list-group .list-group-item {
  4171. background: #343a40;
  4172. }
  4173. .theme-dark .navbar-nav i,
  4174. .navbar-nav .dropdown-toggle,
  4175. .break-word {
  4176. color: #CFD8DC;
  4177. }
  4178. a,
  4179. a:hover,
  4180. a:visited,
  4181. a:active,
  4182. #main-table .filename a,
  4183. i.fa.fa-folder-o,
  4184. i.go-back {
  4185. color: var(--bg-color);
  4186. }
  4187. ul#search-wrapper li:nth-child(odd) {
  4188. background: #212a2f;
  4189. }
  4190. .theme-dark .btn-outline-primary {
  4191. color: #b8e59c;
  4192. border-color: #b8e59c;
  4193. }
  4194. .theme-dark .btn-outline-primary:hover,
  4195. .theme-dark .btn-outline-primary:active {
  4196. background-color: #2d4121;
  4197. }
  4198. .theme-dark input.form-control {
  4199. background-color: #101518;
  4200. color: #CFD8DC;
  4201. }
  4202. .theme-dark .dropzone {
  4203. background: transparent;
  4204. }
  4205. .theme-dark .inline-actions>a>i {
  4206. background: #79755e;
  4207. }
  4208. .theme-dark .text-white {
  4209. color: #CFD8DC !important;
  4210. }
  4211. .theme-dark .table-bordered td,
  4212. .table-bordered th {
  4213. border-color: #343434;
  4214. }
  4215. .theme-dark .table-bordered td .custom-control-input,
  4216. .theme-dark .table-bordered th .custom-control-input {
  4217. opacity: 0.678;
  4218. }
  4219. .message {
  4220. background-color: #212529;
  4221. }
  4222. form.dropzone {
  4223. border-color: #79755e;
  4224. }
  4225. </style>
  4226. <?php endif; ?>
  4227. </head>
  4228. <body class="<?php echo (FM_THEME == "dark") ? 'theme-dark' : ''; ?> <?php echo $isStickyNavBar; ?>">
  4229. <div id="wrapper" class="container-fluid">
  4230. <!-- New Item creation -->
  4231. <div class="modal fade" id="createNewItem" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false" aria-labelledby="newItemModalLabel" aria-hidden="true" data-bs-theme="<?php echo FM_THEME; ?>">
  4232. <div class="modal-dialog" role="document">
  4233. <form class="modal-content" method="post">
  4234. <div class="modal-header">
  4235. <h5 class="modal-title" id="newItemModalLabel"><i class="fa fa-plus-square fa-fw"></i><?php echo lng('CreateNewItem') ?></h5>
  4236. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></div>
  4237. </div>
  4238. <div class="modal-body">
  4239. <p><label for="newfile"><?php echo lng('ItemType') ?> </label></p>
  4240. <div class="form-check form-check-inline">
  4241. <input class="form-check-input" type="radio" name="newfile" id="customRadioInline1" name="newfile" value="file">
  4242. <label class="form-check-label" for="customRadioInline1"><?php echo lng('File') ?></label>
  4243. </div>
  4244. <div class="form-check form-check-inline">
  4245. <input class="form-check-input" type="radio" name="newfile" id="customRadioInline2" value="folder" checked>
  4246. <label class="form-check-label" for="customRadioInline2"><?php echo lng('Folder') ?></label>
  4247. </div>
  4248. <p class="mt-3"><label for="newfilename"><?php echo lng('ItemName') ?> </label></p>
  4249. <input type="text" name="newfilename" id="newfilename" value="" class="form-control" placeholder="<?php echo lng('Enter here...') ?>" required>
  4250. </div>
  4251. <div class="modal-footer">
  4252. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  4253. <button type="button" class="btn btn-outline-primary" data-bs-dismiss="modal"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></div>
  4254. <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('CreateNow') ?></div>
  4255. </div>
  4256. </form>
  4257. </div>
  4258. </div>
  4259. <!-- Advance Search Modal -->
  4260. <div class="modal fade" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true" data-bs-theme="<?php echo FM_THEME; ?>">
  4261. <div class="modal-dialog modal-lg" role="document">
  4262. <div class="modal-content">
  4263. <div class="modal-header">
  4264. <h5 class="modal-title col-10" id="searchModalLabel">
  4265. <div class="input-group mb-3">
  4266. <input type="text" class="form-control" placeholder="<?php echo lng('Search') ?> <?php echo lng('a files') ?>" aria-label="<?php echo lng('Search') ?>" aria-describedby="search-addon3" id="advanced-search" autofocus required>
  4267. <span class="input-group-text" id="search-addon3"><i class="fa fa-search"></i></span>
  4268. </div>
  4269. </h5>
  4270. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></div>
  4271. </div>
  4272. <div class="modal-body">
  4273. <form action="" method="post">
  4274. <div class="lds-facebook">
  4275. <div></div>
  4276. <div></div>
  4277. <div></div>
  4278. </div>
  4279. <ul id="search-wrapper">
  4280. <p class="m-2"><?php echo lng('Search file in folder and subfolders...') ?></p>
  4281. </ul>
  4282. </form>
  4283. </div>
  4284. </div>
  4285. </div>
  4286. </div>
  4287. <!--Rename Modal -->
  4288. <div class="modal modal-alert" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" role="dialog" id="renameDailog" data-bs-theme="<?php echo FM_THEME; ?>">
  4289. <div class="modal-dialog" role="document">
  4290. <form class="modal-content rounded-3 shadow" method="post" autocomplete="off">
  4291. <div class="modal-body p-4 text-center">
  4292. <h5 class="mb-3"><?php echo lng('Are you sure want to rename?') ?></h5>
  4293. <p class="mb-1">
  4294. <input type="text" name="rename_to" id="js-rename-to" class="form-control" placeholder="<?php echo lng('Enter new file name') ?>" required>
  4295. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  4296. <input type="hidden" name="rename_from" id="js-rename-from">
  4297. </p>
  4298. </div>
  4299. <div class="modal-footer flex-nowrap p-0">
  4300. <button type="button" class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0 border-end" data-bs-dismiss="modal"><?php echo lng('Cancel') ?></div>
  4301. <button type="submit" class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0"><strong><?php echo lng('Okay') ?></strong></div>
  4302. </div>
  4303. </form>
  4304. </div>
  4305. </div>
  4306. <!-- Confirm Modal -->
  4307. <script type="text/html" id="js-tpl-confirm">
  4308. <div class="modal modal-alert confirmDailog" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" role="dialog" id="confirmDailog-<%this.id%>" data-bs-theme="<?php echo FM_THEME; ?>">
  4309. <div class="modal-dialog" role="document">
  4310. <form class="modal-content rounded-3 shadow" method="post" autocomplete="off" action="<%this.action%>">
  4311. <div class="modal-body p-4 text-center">
  4312. <h5 class="mb-2"><?php echo lng('Are you sure want to') ?> <%this.title%> ?</h5>
  4313. <p class="mb-1"><%this.content%></p>
  4314. </div>
  4315. <div class="modal-footer flex-nowrap p-0">
  4316. <button type="button" class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0 border-end" data-bs-dismiss="modal"><?php echo lng('Cancel') ?></div>
  4317. <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  4318. <button type="submit" class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0" data-bs-dismiss="modal"><strong><?php echo lng('Okay') ?></strong></div>
  4319. </div>
  4320. </form>
  4321. </div>
  4322. </div>
  4323. </script>
  4324. <?php
  4325. }
  4326. /**
  4327. * Show page footer after login
  4328. */
  4329. function fm_show_footer()
  4330. {
  4331. ?>
  4332. </div>
  4333. <?php print_external('js-jquery'); ?>
  4334. <?php print_external('js-bootstrap'); ?>
  4335. <?php print_external('js-jquery-datatables'); ?>
  4336. <?php if (FM_USE_HIGHLIGHTJS && isset($_GET['view'])): ?>
  4337. <?php print_external('js-highlightjs'); ?>
  4338. <script>
  4339. hljs.highlightAll();
  4340. var isHighlightingEnabled = true;
  4341. </script>
  4342. <?php endif; ?>
  4343. <script>
  4344. function template(html, options) {
  4345. var re = /<\%([^\%>]+)?\%>/g,
  4346. reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,
  4347. code = 'var r=[];\n',
  4348. cursor = 0,
  4349. match;
  4350. var add = function(line, js) {
  4351. js ? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : '');
  4352. return add
  4353. }
  4354. while (match = re.exec(html)) {
  4355. add(html.slice(cursor, match.index))(match[1], !0);
  4356. cursor = match.index + match[0].length
  4357. }
  4358. add(html.substr(cursor, html.length - cursor));
  4359. code += 'return r.join("");';
  4360. return new Function(code.replace(/[\r\t\n]/g, '')).apply(options)
  4361. }
  4362. function rename(e, t) {
  4363. if (t) {
  4364. $("#js-rename-from").val(t);
  4365. $("#js-rename-to").val(t);
  4366. $("#renameDailog").modal('show');
  4367. }
  4368. }
  4369. function change_checkboxes(e, t) {
  4370. for (var n = e.length - 1; n >= 0; n--) e[n].checked = "boolean" == typeof t ? t : !e[n].checked
  4371. }
  4372. function get_checkboxes() {
  4373. for (var e = document.getElementsByName("file[]"), t = [], n = e.length - 1; n >= 0; n--)(e[n].type = "checkbox") && t.push(e[n]);
  4374. return t
  4375. }
  4376. function select_all() {
  4377. change_checkboxes(get_checkboxes(), !0)
  4378. }
  4379. function unselect_all() {
  4380. change_checkboxes(get_checkboxes(), !1)
  4381. }
  4382. function invert_all() {
  4383. change_checkboxes(get_checkboxes())
  4384. }
  4385. function checkbox_toggle() {
  4386. var e = get_checkboxes();
  4387. e.push(this), change_checkboxes(e)
  4388. }
  4389. // Create file backup with .bck
  4390. function backup(e, t) {
  4391. var n = new XMLHttpRequest,
  4392. a = "path=" + e + "&file=" + t + "&token=" + window.csrf + "&type=backup&ajax=true";
  4393. return n.open("POST", "", !0), n.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), n.onreadystatechange = function() {
  4394. 4 == n.readyState && 200 == n.status && toast(n.responseText)
  4395. }, n.send(a), !1
  4396. }
  4397. // Toast message
  4398. function toast(txt) {
  4399. var x = document.getElementById("snackbar");
  4400. x.innerHTML = txt;
  4401. x.className = "show";
  4402. setTimeout(function() {
  4403. x.className = x.className.replace("show", "");
  4404. }, 3000);
  4405. }
  4406. // Save file
  4407. function edit_save(e, t) {
  4408. var n = "ace" == t ? editor.getSession().getValue() : document.getElementById("normal-editor").value;
  4409. if (typeof n !== 'undefined' && n !== null) {
  4410. if (true) {
  4411. var data = {
  4412. ajax: true,
  4413. content: n,
  4414. type: 'save',
  4415. token: window.csrf
  4416. };
  4417. $.ajax({
  4418. type: "POST",
  4419. url: window.location,
  4420. data: JSON.stringify(data),
  4421. contentType: "application/json; charset=utf-8",
  4422. success: function(mes) {
  4423. toast("Saved Successfully");
  4424. window.onbeforeunload = function() {
  4425. return
  4426. }
  4427. },
  4428. failure: function(mes) {
  4429. toast("Error: try again");
  4430. },
  4431. error: function(mes) {
  4432. toast(`<p style="background-color:red">${mes.responseText}</p>`);
  4433. }
  4434. });
  4435. } else {
  4436. var a = document.createElement("form");
  4437. a.setAttribute("method", "POST"), a.setAttribute("action", "");
  4438. var o = document.createElement("textarea");
  4439. o.setAttribute("type", "textarea"), o.setAttribute("name", "savedata");
  4440. let cx = document.createElement("input");
  4441. cx.setAttribute("type", "hidden");
  4442. cx.setAttribute("name", "token");
  4443. cx.setAttribute("value", window.csrf);
  4444. var c = document.createTextNode(n);
  4445. o.appendChild(c), a.appendChild(o), a.appendChild(cx), document.body.appendChild(a), a.submit()
  4446. }
  4447. }
  4448. }
  4449. function show_new_pwd() {
  4450. $(".js-new-pwd").toggleClass('hidden');
  4451. }
  4452. // Save Settings
  4453. function save_settings($this) {
  4454. let form = $($this);
  4455. $.ajax({
  4456. type: form.attr('method'),
  4457. url: form.attr('action'),
  4458. data: form.serialize() + "&token=" + window.csrf + "&ajax=" + true,
  4459. success: function(data) {
  4460. if (data) {
  4461. window.location.reload();
  4462. }
  4463. }
  4464. });
  4465. return false;
  4466. }
  4467. //Create new password hash
  4468. function new_password_hash($this) {
  4469. let form = $($this),
  4470. $pwd = $("#js-pwd-result");
  4471. $pwd.val('');
  4472. $.ajax({
  4473. type: form.attr('method'),
  4474. url: form.attr('action'),
  4475. data: form.serialize() + "&token=" + window.csrf + "&ajax=" + true,
  4476. success: function(data) {
  4477. if (data) {
  4478. $pwd.val(data);
  4479. }
  4480. }
  4481. });
  4482. return false;
  4483. }
  4484. // Upload files using URL @param {Object}
  4485. function upload_from_url($this) {
  4486. let form = $($this),
  4487. resultWrapper = $("div#js-url-upload__list");
  4488. $.ajax({
  4489. type: form.attr('method'),
  4490. url: form.attr('action'),
  4491. data: form.serialize() + "&token=" + window.csrf + "&ajax=" + true,
  4492. beforeSend: function() {
  4493. form.find("input[name=uploadurl]").attr("disabled", "disabled");
  4494. form.find("button").hide();
  4495. form.find(".lds-facebook").addClass('show-me');
  4496. },
  4497. success: function(data) {
  4498. if (data) {
  4499. data = JSON.parse(data);
  4500. if (data.done) {
  4501. resultWrapper.append('<div class="alert alert-success row">Uploaded Successful: ' + data.done.name + '</div>');
  4502. form.find("input[name=uploadurl]").val('');
  4503. } else if (data['fail']) {
  4504. resultWrapper.append('<div class="alert alert-danger row">Error: ' + data.fail.message + '</div>');
  4505. }
  4506. form.find("input[name=uploadurl]").removeAttr("disabled");
  4507. form.find("button").show();
  4508. form.find(".lds-facebook").removeClass('show-me');
  4509. }
  4510. },
  4511. error: function(xhr) {
  4512. form.find("input[name=uploadurl]").removeAttr("disabled");
  4513. form.find("button").show();
  4514. form.find(".lds-facebook").removeClass('show-me');
  4515. console.error(xhr);
  4516. }
  4517. });
  4518. return false;
  4519. }
  4520. // Search template
  4521. function search_template(data) {
  4522. var response = "";
  4523. $.each(data, function(key, val) {
  4524. response += `<li><a href="?p=${val.path}&view=${val.name}">${val.path}/${val.name}</a></li>`;
  4525. });
  4526. return response;
  4527. }
  4528. // Advance search
  4529. function fm_search() {
  4530. var searchTxt = $("input#advanced-search").val(),
  4531. searchWrapper = $("ul#search-wrapper"),
  4532. path = $("#js-search-modal").attr("href"),
  4533. _html = "",
  4534. $loader = $("div.lds-facebook");
  4535. if (!!searchTxt && searchTxt.length > 2 && path) {
  4536. var data = {
  4537. ajax: true,
  4538. content: searchTxt,
  4539. path: path,
  4540. type: 'search',
  4541. token: window.csrf
  4542. };
  4543. $.ajax({
  4544. type: "POST",
  4545. url: window.location,
  4546. data: data,
  4547. beforeSend: function() {
  4548. searchWrapper.html('');
  4549. $loader.addClass('show-me');
  4550. },
  4551. success: function(data) {
  4552. $loader.removeClass('show-me');
  4553. data = JSON.parse(data);
  4554. if (data && data.length) {
  4555. _html = search_template(data);
  4556. searchWrapper.html(_html);
  4557. } else {
  4558. searchWrapper.html('<p class="m-2">No result found!<p>');
  4559. }
  4560. },
  4561. error: function(xhr) {
  4562. $loader.removeClass('show-me');
  4563. searchWrapper.html('<p class="m-2">ERROR: Try again later!</p>');
  4564. },
  4565. failure: function(mes) {
  4566. $loader.removeClass('show-me');
  4567. searchWrapper.html('<p class="m-2">ERROR: Try again later!</p>');
  4568. }
  4569. });
  4570. } else {
  4571. searchWrapper.html("OOPS: minimum 3 characters required!");
  4572. }
  4573. }
  4574. // action confirm dailog modal
  4575. function confirmDailog(e, id = 0, title = "Action", content = "", action = null) {
  4576. e.preventDefault();
  4577. const tplObj = {
  4578. id,
  4579. title,
  4580. content: decodeURIComponent(content.replace(/\+/g, ' ')),
  4581. action
  4582. };
  4583. let tpl = $("#js-tpl-confirm").html();
  4584. $(".modal.confirmDailog").remove();
  4585. $('#wrapper').append(template(tpl, tplObj));
  4586. const $confirmDailog = $("#confirmDailog-" + tplObj.id);
  4587. $confirmDailog.modal('show');
  4588. return false;
  4589. }
  4590. // on mouse hover image preview
  4591. ! function(s) {
  4592. s.previewImage = function(e) {
  4593. var o = s(document),
  4594. t = ".previewImage",
  4595. a = s.extend({
  4596. xOffset: 20,
  4597. yOffset: -20,
  4598. fadeIn: "fast",
  4599. css: {
  4600. padding: "5px",
  4601. border: "1px solid #cccccc",
  4602. "background-color": "#fff"
  4603. },
  4604. eventSelector: "[data-preview-image]",
  4605. dataKey: "previewImage",
  4606. overlayId: "preview-image-plugin-overlay"
  4607. }, e);
  4608. return o.off(t), o.on("mouseover" + t, a.eventSelector, function(e) {
  4609. s("p#" + a.overlayId).remove();
  4610. var o = s("<p>").attr("id", a.overlayId).css("position", "absolute").css("display", "none").append(s('<img class="c-preview-img">').attr("src", s(this).data(a.dataKey)));
  4611. a.css && o.css(a.css), s("body").append(o), o.css("top", e.pageY + a.yOffset + "px").css("left", e.pageX + a.xOffset + "px").fadeIn(a.fadeIn)
  4612. }), o.on("mouseout" + t, a.eventSelector, function() {
  4613. s("#" + a.overlayId).remove()
  4614. }), o.on("mousemove" + t, a.eventSelector, function(e) {
  4615. s("#" + a.overlayId).css("top", e.pageY + a.yOffset + "px").css("left", e.pageX + a.xOffset + "px")
  4616. }), this
  4617. }, s.previewImage()
  4618. }(jQuery);
  4619. // Dom Ready Events
  4620. $(document).ready(function() {
  4621. // dataTable init
  4622. var $table = $('#main-table'),
  4623. tableLng = $table.find('th').length,
  4624. _targets = (tableLng && tableLng == 7) ? [0, 4, 5, 6] : tableLng == 5 ? [0, 4] : [3];
  4625. mainTable = $('#main-table').DataTable({
  4626. paging: false,
  4627. info: false,
  4628. order: [],
  4629. columnDefs: [{
  4630. targets: _targets,
  4631. orderable: false
  4632. }]
  4633. });
  4634. // filter table
  4635. $('#search-addon').on('keyup', function() {
  4636. mainTable.search(this.value).draw();
  4637. });
  4638. $("input#advanced-search").on('keyup', function(e) {
  4639. if (e.keyCode === 13) {
  4640. fm_search();
  4641. }
  4642. });
  4643. $('#search-addon3').on('click', function() {
  4644. fm_search();
  4645. });
  4646. //upload nav tabs
  4647. $(".fm-upload-wrapper .card-header-tabs").on("click", 'a', function(e) {
  4648. e.preventDefault();
  4649. let target = $(this).data('target');
  4650. $(".fm-upload-wrapper .card-header-tabs a").removeClass('active');
  4651. $(this).addClass('active');
  4652. $(".fm-upload-wrapper .card-tabs-container").addClass('hidden');
  4653. $(target).removeClass('hidden');
  4654. });
  4655. });
  4656. </script>
  4657. <?php if (isset($_GET['edit']) && isset($_GET['env']) && FM_EDIT_FILE && !FM_READONLY):
  4658. $ext = pathinfo($_GET["edit"], PATHINFO_EXTENSION);
  4659. $ext = $ext == "js" ? "javascript" : $ext;
  4660. ?>
  4661. <?php print_external('js-ace'); ?>
  4662. <script>
  4663. var editor = ace.edit("editor");
  4664. editor.getSession().setMode({
  4665. path: "ace/mode/<?php echo $ext; ?>",
  4666. inline: true
  4667. });
  4668. //editor.setTheme("ace/theme/twilight"); // Dark Theme
  4669. editor.setShowPrintMargin(false); // Hide the vertical ruler
  4670. function ace_commend(cmd) {
  4671. editor.commands.exec(cmd, editor);
  4672. }
  4673. editor.commands.addCommands([{
  4674. name: 'save',
  4675. bindKey: {
  4676. win: 'Ctrl-S',
  4677. mac: 'Command-S'
  4678. },
  4679. exec: function(editor) {
  4680. edit_save(this, 'ace');
  4681. }
  4682. }]);
  4683. function renderThemeMode() {
  4684. var $modeEl = $("select#js-ace-mode"),
  4685. $themeEl = $("select#js-ace-theme"),
  4686. $fontSizeEl = $("select#js-ace-fontSize"),
  4687. optionNode = function(type, arr) {
  4688. var $Option = "";
  4689. $.each(arr, function(i, val) {
  4690. $Option += "<option value='" + type + i + "'>" + val + "</option>";
  4691. });
  4692. return $Option;
  4693. },
  4694. _data = {
  4695. "aceTheme": {
  4696. "bright": {
  4697. "chrome": "Chrome",
  4698. "clouds": "Clouds",
  4699. "crimson_editor": "Crimson Editor",
  4700. "dawn": "Dawn",
  4701. "dreamweaver": "Dreamweaver",
  4702. "eclipse": "Eclipse",
  4703. "github": "GitHub",
  4704. "iplastic": "IPlastic",
  4705. "solarized_light": "Solarized Light",
  4706. "textmate": "TextMate",
  4707. "tomorrow": "Tomorrow",
  4708. "xcode": "XCode",
  4709. "kuroir": "Kuroir",
  4710. "katzenmilch": "KatzenMilch",
  4711. "sqlserver": "SQL Server"
  4712. },
  4713. "dark": {
  4714. "ambiance": "Ambiance",
  4715. "chaos": "Chaos",
  4716. "clouds_midnight": "Clouds Midnight",
  4717. "dracula": "Dracula",
  4718. "cobalt": "Cobalt",
  4719. "gruvbox": "Gruvbox",
  4720. "gob": "Green on Black",
  4721. "idle_fingers": "idle Fingers",
  4722. "kr_theme": "krTheme",
  4723. "merbivore": "Merbivore",
  4724. "merbivore_soft": "Merbivore Soft",
  4725. "mono_industrial": "Mono Industrial",
  4726. "monokai": "Monokai",
  4727. "pastel_on_dark": "Pastel on dark",
  4728. "solarized_dark": "Solarized Dark",
  4729. "terminal": "Terminal",
  4730. "tomorrow_night": "Tomorrow Night",
  4731. "tomorrow_night_blue": "Tomorrow Night Blue",
  4732. "tomorrow_night_bright": "Tomorrow Night Bright",
  4733. "tomorrow_night_eighties": "Tomorrow Night 80s",
  4734. "twilight": "Twilight",
  4735. "vibrant_ink": "Vibrant Ink"
  4736. }
  4737. },
  4738. "aceMode": {
  4739. "javascript": "JavaScript",
  4740. "abap": "ABAP",
  4741. "abc": "ABC",
  4742. "actionscript": "ActionScript",
  4743. "ada": "ADA",
  4744. "apache_conf": "Apache Conf",
  4745. "asciidoc": "AsciiDoc",
  4746. "asl": "ASL",
  4747. "assembly_x86": "Assembly x86",
  4748. "autohotkey": "AutoHotKey",
  4749. "apex": "Apex",
  4750. "batchfile": "BatchFile",
  4751. "bro": "Bro",
  4752. "c_cpp": "C and C++",
  4753. "c9search": "C9Search",
  4754. "cirru": "Cirru",
  4755. "clojure": "Clojure",
  4756. "cobol": "Cobol",
  4757. "coffee": "CoffeeScript",
  4758. "coldfusion": "ColdFusion",
  4759. "csharp": "C#",
  4760. "csound_document": "Csound Document",
  4761. "csound_orchestra": "Csound",
  4762. "csound_score": "Csound Score",
  4763. "css": "CSS",
  4764. "curly": "Curly",
  4765. "d": "D",
  4766. "dart": "Dart",
  4767. "diff": "Diff",
  4768. "dockerfile": "Dockerfile",
  4769. "dot": "Dot",
  4770. "drools": "Drools",
  4771. "edifact": "Edifact",
  4772. "eiffel": "Eiffel",
  4773. "ejs": "EJS",
  4774. "elixir": "Elixir",
  4775. "elm": "Elm",
  4776. "erlang": "Erlang",
  4777. "forth": "Forth",
  4778. "fortran": "Fortran",
  4779. "fsharp": "FSharp",
  4780. "fsl": "FSL",
  4781. "ftl": "FreeMarker",
  4782. "gcode": "Gcode",
  4783. "gherkin": "Gherkin",
  4784. "gitignore": "Gitignore",
  4785. "glsl": "Glsl",
  4786. "gobstones": "Gobstones",
  4787. "golang": "Go",
  4788. "graphqlschema": "GraphQLSchema",
  4789. "groovy": "Groovy",
  4790. "haml": "HAML",
  4791. "handlebars": "Handlebars",
  4792. "haskell": "Haskell",
  4793. "haskell_cabal": "Haskell Cabal",
  4794. "haxe": "haXe",
  4795. "hjson": "Hjson",
  4796. "html": "HTML",
  4797. "html_elixir": "HTML (Elixir)",
  4798. "html_ruby": "HTML (Ruby)",
  4799. "ini": "INI",
  4800. "io": "Io",
  4801. "jack": "Jack",
  4802. "jade": "Jade",
  4803. "java": "Java",
  4804. "json": "JSON",
  4805. "jsoniq": "JSONiq",
  4806. "jsp": "JSP",
  4807. "jssm": "JSSM",
  4808. "jsx": "JSX",
  4809. "julia": "Julia",
  4810. "kotlin": "Kotlin",
  4811. "latex": "LaTeX",
  4812. "less": "LESS",
  4813. "liquid": "Liquid",
  4814. "lisp": "Lisp",
  4815. "livescript": "LiveScript",
  4816. "logiql": "LogiQL",
  4817. "lsl": "LSL",
  4818. "lua": "Lua",
  4819. "luapage": "LuaPage",
  4820. "lucene": "Lucene",
  4821. "makefile": "Makefile",
  4822. "markdown": "Markdown",
  4823. "mask": "Mask",
  4824. "matlab": "MATLAB",
  4825. "maze": "Maze",
  4826. "mel": "MEL",
  4827. "mixal": "MIXAL",
  4828. "mushcode": "MUSHCode",
  4829. "mysql": "MySQL",
  4830. "nix": "Nix",
  4831. "nsis": "NSIS",
  4832. "objectivec": "Objective-C",
  4833. "ocaml": "OCaml",
  4834. "pascal": "Pascal",
  4835. "perl": "Perl",
  4836. "perl6": "Perl 6",
  4837. "pgsql": "pgSQL",
  4838. "php_laravel_blade": "PHP (Blade Template)",
  4839. "php": "PHP",
  4840. "puppet": "Puppet",
  4841. "pig": "Pig",
  4842. "powershell": "Powershell",
  4843. "praat": "Praat",
  4844. "prolog": "Prolog",
  4845. "properties": "Properties",
  4846. "protobuf": "Protobuf",
  4847. "python": "Python",
  4848. "r": "R",
  4849. "razor": "Razor",
  4850. "rdoc": "RDoc",
  4851. "red": "Red",
  4852. "rhtml": "RHTML",
  4853. "rst": "RST",
  4854. "ruby": "Ruby",
  4855. "rust": "Rust",
  4856. "sass": "SASS",
  4857. "scad": "SCAD",
  4858. "scala": "Scala",
  4859. "scheme": "Scheme",
  4860. "scss": "SCSS",
  4861. "sh": "SH",
  4862. "sjs": "SJS",
  4863. "slim": "Slim",
  4864. "smarty": "Smarty",
  4865. "snippets": "snippets",
  4866. "soy_template": "Soy Template",
  4867. "space": "Space",
  4868. "sql": "SQL",
  4869. "sqlserver": "SQLServer",
  4870. "stylus": "Stylus",
  4871. "svg": "SVG",
  4872. "swift": "Swift",
  4873. "tcl": "Tcl",
  4874. "terraform": "Terraform",
  4875. "tex": "Tex",
  4876. "text": "Text",
  4877. "textile": "Textile",
  4878. "toml": "Toml",
  4879. "tsx": "TSX",
  4880. "twig": "Twig",
  4881. "typescript": "Typescript",
  4882. "vala": "Vala",
  4883. "vbscript": "VBScript",
  4884. "velocity": "Velocity",
  4885. "verilog": "Verilog",
  4886. "vhdl": "VHDL",
  4887. "visualforce": "Visualforce",
  4888. "wollok": "Wollok",
  4889. "xml": "XML",
  4890. "xquery": "XQuery",
  4891. "yaml": "YAML",
  4892. "django": "Django"
  4893. },
  4894. "fontSize": {
  4895. 8: 8,
  4896. 10: 10,
  4897. 11: 11,
  4898. 12: 12,
  4899. 13: 13,
  4900. 14: 14,
  4901. 15: 15,
  4902. 16: 16,
  4903. 17: 17,
  4904. 18: 18,
  4905. 20: 20,
  4906. 22: 22,
  4907. 24: 24,
  4908. 26: 26,
  4909. 30: 30
  4910. }
  4911. };
  4912. if (_data && _data.aceMode) {
  4913. $modeEl.html(optionNode("ace/mode/", _data.aceMode));
  4914. }
  4915. if (_data && _data.aceTheme) {
  4916. var lightTheme = optionNode("ace/theme/", _data.aceTheme.bright),
  4917. darkTheme = optionNode("ace/theme/", _data.aceTheme.dark);
  4918. $themeEl.html("<optgroup label=\"Bright\">" + lightTheme + "</optgroup><optgroup label=\"Dark\">" + darkTheme + "</optgroup>");
  4919. }
  4920. if (_data && _data.fontSize) {
  4921. $fontSizeEl.html(optionNode("", _data.fontSize));
  4922. }
  4923. $modeEl.val(editor.getSession().$modeId);
  4924. $themeEl.val(editor.getTheme());
  4925. $(function() {
  4926. //set default font size in drop down
  4927. $fontSizeEl.val(12).change();
  4928. });
  4929. }
  4930. $(function() {
  4931. renderThemeMode();
  4932. $(".js-ace-toolbar").on("click", 'button', function(e) {
  4933. e.preventDefault();
  4934. let cmdValue = $(this).attr("data-cmd"),
  4935. editorOption = $(this).attr("data-option");
  4936. if (cmdValue && cmdValue != "none") {
  4937. ace_commend(cmdValue);
  4938. } else if (editorOption) {
  4939. if (editorOption == "fullscreen") {
  4940. (void 0 !== document.fullScreenElement && null === document.fullScreenElement || void 0 !== document.msFullscreenElement && null === document.msFullscreenElement || void 0 !== document.mozFullScreen && !document.mozFullScreen || void 0 !== document.webkitIsFullScreen && !document.webkitIsFullScreen) &&
  4941. (editor.container.requestFullScreen ? editor.container.requestFullScreen() : editor.container.mozRequestFullScreen ? editor.container.mozRequestFullScreen() : editor.container.webkitRequestFullScreen ? editor.container.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT) : editor.container.msRequestFullscreen && editor.container.msRequestFullscreen());
  4942. } else if (editorOption == "wrap") {
  4943. let wrapStatus = (editor.getSession().getUseWrapMode()) ? false : true;
  4944. editor.getSession().setUseWrapMode(wrapStatus);
  4945. }
  4946. }
  4947. });
  4948. $("select#js-ace-mode, select#js-ace-theme, select#js-ace-fontSize").on("change", function(e) {
  4949. e.preventDefault();
  4950. let selectedValue = $(this).val(),
  4951. selectionType = $(this).attr("data-type");
  4952. if (selectedValue && selectionType == "mode") {
  4953. editor.getSession().setMode(selectedValue);
  4954. } else if (selectedValue && selectionType == "theme") {
  4955. editor.setTheme(selectedValue);
  4956. } else if (selectedValue && selectionType == "fontSize") {
  4957. editor.setFontSize(parseInt(selectedValue));
  4958. }
  4959. });
  4960. });
  4961. </script>
  4962. <?php endif; ?>
  4963. <div id="snackbar"></div>
  4964. </body>
  4965. </html>
  4966. <?php
  4967. }
  4968. /**
  4969. * Language Translation System
  4970. * @param string $txt
  4971. * @return string
  4972. */
  4973. function lng($txt)
  4974. {
  4975. global $lang;
  4976. // English Language
  4977. $tr['en']['AppName'] = 'Tiny File Manager';
  4978. $tr['en']['AppTitle'] = 'File Manager';
  4979. $tr['en']['Login'] = 'Sign in';
  4980. $tr['en']['Username'] = 'Username';
  4981. $tr['en']['Password'] = 'Password';
  4982. $tr['en']['Logout'] = 'Sign Out';
  4983. $tr['en']['Move'] = 'Move';
  4984. $tr['en']['Copy'] = 'Copy';
  4985. $tr['en']['Save'] = 'Save';
  4986. $tr['en']['SelectAll'] = 'Select all';
  4987. $tr['en']['UnSelectAll'] = 'Unselect all';
  4988. $tr['en']['File'] = 'File';
  4989. $tr['en']['Back'] = 'Back';
  4990. $tr['en']['Size'] = 'Size';
  4991. $tr['en']['Perms'] = 'Perms';
  4992. $tr['en']['Modified'] = 'Modified';
  4993. $tr['en']['Owner'] = 'Owner';
  4994. $tr['en']['Search'] = 'Search';
  4995. $tr['en']['NewItem'] = 'New Item';
  4996. $tr['en']['Folder'] = 'Folder';
  4997. $tr['en']['Delete'] = 'Delete';
  4998. $tr['en']['Rename'] = 'Rename';
  4999. $tr['en']['CopyTo'] = 'Copy to';
  5000. $tr['en']['DirectLink'] = 'Direct link';
  5001. $tr['en']['UploadingFiles'] = 'Upload Files';
  5002. $tr['en']['ChangePermissions'] = 'Change Permissions';
  5003. $tr['en']['Copying'] = 'Copying';
  5004. $tr['en']['CreateNewItem'] = 'Create New Item';
  5005. $tr['en']['Name'] = 'Name';
  5006. $tr['en']['AdvancedEditor'] = 'Advanced Editor';
  5007. $tr['en']['Actions'] = 'Actions';
  5008. $tr['en']['Folder is empty'] = 'Folder is empty';
  5009. $tr['en']['Upload'] = 'Upload';
  5010. $tr['en']['Cancel'] = 'Cancel';
  5011. $tr['en']['InvertSelection'] = 'Invert Selection';
  5012. $tr['en']['DestinationFolder'] = 'Destination Folder';
  5013. $tr['en']['ItemType'] = 'Item Type';
  5014. $tr['en']['ItemName'] = 'Item Name';
  5015. $tr['en']['CreateNow'] = 'Create Now';
  5016. $tr['en']['Download'] = 'Download';
  5017. $tr['en']['Open'] = 'Open';
  5018. $tr['en']['UnZip'] = 'UnZip';
  5019. $tr['en']['UnZipToFolder'] = 'UnZip to folder';
  5020. $tr['en']['Edit'] = 'Edit';
  5021. $tr['en']['NormalEditor'] = 'Normal Editor';
  5022. $tr['en']['BackUp'] = 'Back Up';
  5023. $tr['en']['SourceFolder'] = 'Source Folder';
  5024. $tr['en']['Files'] = 'Files';
  5025. $tr['en']['Move'] = 'Move';
  5026. $tr['en']['Change'] = 'Change';
  5027. $tr['en']['Settings'] = 'Settings';
  5028. $tr['en']['Language'] = 'Language';
  5029. $tr['en']['ErrorReporting'] = 'Error Reporting';
  5030. $tr['en']['ShowHiddenFiles'] = 'Show Hidden Files';
  5031. $tr['en']['Help'] = 'Help';
  5032. $tr['en']['Created'] = 'Created';
  5033. $tr['en']['Help Documents'] = 'Help Documents';
  5034. $tr['en']['Report Issue'] = 'Report Issue';
  5035. $tr['en']['Generate'] = 'Generate';
  5036. $tr['en']['FullSize'] = 'Full Size';
  5037. $tr['en']['HideColumns'] = 'Hide Perms/Owner columns';
  5038. $tr['en']['You are logged in'] = 'You are logged in';
  5039. $tr['en']['Nothing selected'] = 'Nothing selected';
  5040. $tr['en']['Paths must be not equal'] = 'Paths must be not equal';
  5041. $tr['en']['Renamed from'] = 'Renamed from';
  5042. $tr['en']['Archive not unpacked'] = 'Archive not unpacked';
  5043. $tr['en']['Deleted'] = 'Deleted';
  5044. $tr['en']['Archive not created'] = 'Archive not created';
  5045. $tr['en']['Copied from'] = 'Copied from';
  5046. $tr['en']['Permissions changed'] = 'Permissions changed';
  5047. $tr['en']['to'] = 'to';
  5048. $tr['en']['Saved Successfully'] = 'Saved Successfully';
  5049. $tr['en']['not found!'] = 'not found!';
  5050. $tr['en']['File Saved Successfully'] = 'File Saved Successfully';
  5051. $tr['en']['Archive'] = 'Archive';
  5052. $tr['en']['Permissions not changed'] = 'Permissions not changed';
  5053. $tr['en']['Select folder'] = 'Select folder';
  5054. $tr['en']['Source path not defined'] = 'Source path not defined';
  5055. $tr['en']['already exists'] = 'already exists';
  5056. $tr['en']['Error while moving from'] = 'Error while moving from';
  5057. $tr['en']['Create archive?'] = 'Create archive?';
  5058. $tr['en']['Invalid file or folder name'] = 'Invalid file or folder name';
  5059. $tr['en']['Archive unpacked'] = 'Archive unpacked';
  5060. $tr['en']['File extension is not allowed'] = 'File extension is not allowed';
  5061. $tr['en']['Root path'] = 'Root path';
  5062. $tr['en']['Error while renaming from'] = 'Error while renaming from';
  5063. $tr['en']['File not found'] = 'File not found';
  5064. $tr['en']['Error while deleting items'] = 'Error while deleting items';
  5065. $tr['en']['Moved from'] = 'Moved from';
  5066. $tr['en']['Generate new password hash'] = 'Generate new password hash';
  5067. $tr['en']['Login failed. Invalid username or password'] = 'Login failed. Invalid username or password';
  5068. $tr['en']['password_hash not supported, Upgrade PHP version'] = 'password_hash not supported, Upgrade PHP version';
  5069. $tr['en']['Advanced Search'] = 'Advanced Search';
  5070. $tr['en']['Error while copying from'] = 'Error while copying from';
  5071. $tr['en']['Invalid characters in file name'] = 'Invalid characters in file name';
  5072. $tr['en']['FILE EXTENSION HAS NOT SUPPORTED'] = 'FILE EXTENSION HAS NOT SUPPORTED';
  5073. $tr['en']['Selected files and folder deleted'] = 'Selected files and folder deleted';
  5074. $tr['en']['Error while fetching archive info'] = 'Error while fetching archive info';
  5075. $tr['en']['Delete selected files and folders?'] = 'Delete selected files and folders?';
  5076. $tr['en']['Search file in folder and subfolders...'] = 'Search file in folder and subfolders...';
  5077. $tr['en']['Access denied. IP restriction applicable'] = 'Access denied. IP restriction applicable';
  5078. $tr['en']['Invalid characters in file or folder name'] = 'Invalid characters in file or folder name';
  5079. $tr['en']['Operations with archives are not available'] = 'Operations with archives are not available';
  5080. $tr['en']['File or folder with this path already exists'] = 'File or folder with this path already exists';
  5081. $tr['en']['Are you sure want to rename?'] = 'Are you sure want to rename?';
  5082. $tr['en']['Are you sure want to'] = 'Are you sure want to';
  5083. $tr['en']['Date Modified'] = 'Date Modified';
  5084. $tr['en']['File size'] = 'File size';
  5085. $tr['en']['MIME-type'] = 'MIME-type';
  5086. $i18n = fm_get_translations($tr);
  5087. $tr = $i18n ? $i18n : $tr;
  5088. if (!strlen($lang)) $lang = 'en';
  5089. if (isset($tr[$lang][$txt])) return fm_enc($tr[$lang][$txt]);
  5090. else if (isset($tr['en'][$txt])) return fm_enc($tr['en'][$txt]);
  5091. else return "$txt";
  5092. }
  5093. ?>