filesystem.inc.php 169 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034
  1. <?php
  2. // -------------------------------------------------------------------------------
  3. // | net2ftp: a web based FTP client |
  4. // | Copyright (c) 2003-2013 by David Gartner |
  5. // | |
  6. // | This program is free software; you can redistribute it and/or |
  7. // | modify it under the terms of the GNU General Public License |
  8. // | as published by the Free Software Foundation; either version 2 |
  9. // | of the License, or (at your option) any later version. |
  10. // | |
  11. // -------------------------------------------------------------------------------
  12. // **************************************************************************************
  13. // **************************************************************************************
  14. // ** **
  15. // ** **
  16. function ftp_openconnection() {
  17. // --------------
  18. // This function opens an ftp connection
  19. // --------------
  20. // Global variables
  21. global $net2ftp_globals;
  22. // Check if the FTP module of PHP is installed
  23. if (function_exists("ftp_connect") == false) {
  24. $errormessage = __("The <a href=\"http://www.php.net/manual/en/ref.ftp.php\" target=\"_blank\">FTP module of PHP</a> is not installed.<br /><br /> The administrator of this website should install this FTP module. Installation instructions are given on <a href=\"http://www.php.net/manual/en/ref.ftp.php\" target=\"_blank\">php.net</a><br />");
  25. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  26. return false;
  27. }
  28. // Decrypt password
  29. if (isset($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]) == true) {
  30. $net2ftp_password = decryptPassword($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]);
  31. }
  32. else {
  33. $net2ftp_password = decryptPassword($net2ftp_globals["password_encrypted"]);
  34. }
  35. // Check if port nr is filled in
  36. if ($net2ftp_globals["ftpserverport"] < 1 || $net2ftp_globals["ftpserverport"] > 65535 || $net2ftp_globals["ftpserverport"] == "") { $net2ftp_globals["ftpserverport"] = 21; }
  37. // Set up basic connection
  38. $ftp_connect = "ftp_connect";
  39. if (array_key_exists("sslconnect", $net2ftp_globals) && $net2ftp_globals["sslconnect"] == "yes" && function_exists("ftp_ssl_connect")) { $ftp_connect = "ftp_ssl_connect"; }
  40. $conn_id = $ftp_connect($net2ftp_globals["ftpserver"], $net2ftp_globals["ftpserverport"]);
  41. if ($conn_id == false) {
  42. $errormessage = __("Unable to connect to FTP server <b>%1\$s</b> on port <b>%2\$s</b>.<br /><br />Are you sure this is the address of the FTP server? This is often different from that of the HTTP (web) server. Please contact your ISP helpdesk or system administrator for help.<br />", $net2ftp_globals["ftpserver"], $net2ftp_globals["ftpserverport"]);
  43. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  44. return false;
  45. }
  46. // Login with username and password
  47. $login_result = ftp_login($conn_id, $net2ftp_globals["username"], $net2ftp_password);
  48. if ($login_result == false) {
  49. $errormessage = __("Unable to login to FTP server <b>%1\$s</b> with username <b>%2\$s</b>.<br /><br />Are you sure your username and password are correct? Please contact your ISP helpdesk or system administrator for help.<br />", $net2ftp_globals["ftpserver"], $net2ftp_globals["username"]);
  50. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  51. return false;
  52. }
  53. // Set passive mode
  54. if ($net2ftp_globals["passivemode"] == "yes") {
  55. $success = ftp_pasv($conn_id, TRUE);
  56. if ($success == false) {
  57. $errormessage = __("Unable to switch to the passive mode on FTP server <b>%1\$s</b>.", $net2ftp_globals["ftpserver"]);
  58. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  59. return false;
  60. }
  61. }
  62. // Get the system type
  63. // $net2ftp_globals["systype"] = ftp_systype($conn_id);
  64. // Return the connection ID
  65. return $conn_id;
  66. } // End function ftp_openconnection
  67. // ** **
  68. // ** **
  69. // **************************************************************************************
  70. // **************************************************************************************
  71. // **************************************************************************************
  72. // **************************************************************************************
  73. // ** **
  74. // ** **
  75. function ftp_openconnection2() {
  76. // --------------
  77. // This function opens an ftp connection to the secondary FTP server, to which
  78. // files can be copied or moved.
  79. // --------------
  80. // Global variables
  81. global $net2ftp_globals;
  82. // Check if the FTP module of PHP is installed
  83. if (function_exists("ftp_connect") == false) {
  84. $errormessage = __("The <a href=\"http://www.php.net/manual/en/ref.ftp.php\" target=\"_blank\">FTP module of PHP</a> is not installed.<br /><br /> The administrator of this website should install this FTP module. Installation instructions are given on <a href=\"http://www.php.net/manual/en/ref.ftp.php\" target=\"_blank\">php.net</a><br />");
  85. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  86. return false;
  87. }
  88. // Check if port nr is correct
  89. if ($net2ftp_globals["ftpserverport2"] < 1 || $net2ftp_globals["ftpserverport2"] > 65535 || $net2ftp_globals["ftpserverport2"] == "") { $net2ftp_globals["ftpserverport2"] = 21; }
  90. // Set up basic connection
  91. $conn_id = ftp_connect($net2ftp_globals["ftpserver2"], $net2ftp_globals["ftpserverport2"]);
  92. if ($conn_id == false) {
  93. $errormessage = __("Unable to connect to the second (target) FTP server <b>%1\$s</b> on port <b>%2\$s</b>.<br /><br />Are you sure this is the address of the second (target) FTP server? This is often different from that of the HTTP (web) server. Please contact your ISP helpdesk or system administrator for help.<br />", $net2ftp_globals["ftpserver2"], $net2ftp_globals["ftpserverport2"]);
  94. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  95. return false;
  96. }
  97. // Login with username and password
  98. $login_result = ftp_login($conn_id, $net2ftp_globals["username2"], $net2ftp_globals["password2"]);
  99. if ($login_result == false) {
  100. $errormessage = __("Unable to login to the second (target) FTP server <b>%1\$s</b> with username <b>%2\$s</b>.<br /><br />Are you sure your username and password are correct? Please contact your ISP helpdesk or system administrator for help.<br />", $net2ftp_globals["ftpserver2"], $net2ftp_globals["username2"]);
  101. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  102. return false;
  103. }
  104. // Set passive mode
  105. if ($net2ftp_globals["passivemode"] == "yes") {
  106. $success = ftp_pasv($conn_id, TRUE);
  107. if ($success == false) {
  108. $errormessage = __("Unable to switch to the passive mode on the second (target) FTP server <b>%1\$s</b>.", $net2ftp_globals["ftpserver2"]);
  109. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  110. return false;
  111. }
  112. }
  113. // Get the system type
  114. // $net2ftp_globals["systype2"] = ftp_systype($conn_id);
  115. // Return the connection ID
  116. return $conn_id;
  117. } // End function ftp_openconnection2
  118. // ** **
  119. // ** **
  120. // **************************************************************************************
  121. // **************************************************************************************
  122. // **************************************************************************************
  123. // **************************************************************************************
  124. // ** **
  125. // ** **
  126. function ftp_closeconnection($conn_id) {
  127. // --------------
  128. // This function closes an ftp connection
  129. // --------------
  130. ftp_quit($conn_id);
  131. } // End function ftp_closeconnection
  132. // ** **
  133. // ** **
  134. // **************************************************************************************
  135. // **************************************************************************************
  136. // **************************************************************************************
  137. // **************************************************************************************
  138. // ** **
  139. // ** **
  140. function ftp_rename2($conn_id, $directory, $entry, $newName) {
  141. // --------------
  142. // This function renames a directory
  143. // --------------
  144. $old = glueDirectories($directory, $entry);
  145. $new = glueDirectories($directory, $newName);
  146. $ftp_rename_result = ftp_rename($conn_id, $old, $new);
  147. if ($ftp_rename_result == false) {
  148. $errormessage = __("Unable to rename directory or file <b>%1\$s</b> into <b>%2\$s</b>", $old, $new);
  149. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  150. return false;
  151. }
  152. } // End function ftp_rename2
  153. // ** **
  154. // ** **
  155. // **************************************************************************************
  156. // **************************************************************************************
  157. // **************************************************************************************
  158. // **************************************************************************************
  159. // ** **
  160. // ** **
  161. function ftp_rename3($conn_id, $old, $new) {
  162. // --------------
  163. // This function renames a directory or file
  164. // --------------
  165. $ftp_rename_result = ftp_rename($conn_id, $old, $new);
  166. if ($ftp_rename_result == false) {
  167. $errormessage = __("Unable to rename directory or file <b>%1\$s</b> into <b>%2\$s</b>", $old, $new);
  168. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  169. return false;
  170. }
  171. } // End function ftp_rename3
  172. // ** **
  173. // ** **
  174. // **************************************************************************************
  175. // **************************************************************************************
  176. // **************************************************************************************
  177. // **************************************************************************************
  178. // ** **
  179. // ** **
  180. function ftp_chmod2($conn_id, $directory, $list, $divelevel) {
  181. // --------------
  182. // This function chmods a directory or file
  183. //
  184. // $list[$i]["dirorfile"] contains d or - which indicates if the entry is a directory or a file
  185. // $list[$i]["dirfilename"] contains the name of the entry
  186. // $list[$i]["chmodoctal"] contains the 3-digit nr
  187. //
  188. // If the entry is a directory, $list[$i]["chmod_subdirectories"] and $list[$i]["chmod_subfiles"] are "yes" if
  189. // the subdirectories and files within the chmodded directory should also be chmodded
  190. // --------------
  191. // -------------------------------------------------------------------------
  192. // Global variables
  193. // -------------------------------------------------------------------------
  194. global $net2ftp_globals, $net2ftp_result, $net2ftp_output;
  195. // -------------------------------------------------------------------------
  196. // Initialization
  197. // -------------------------------------------------------------------------
  198. if ($divelevel == 0) {
  199. $net2ftp_output["ftp_chmod2"][] = "<ul>";
  200. }
  201. // -------------------------------------------------------------------------
  202. // For all directories
  203. // -------------------------------------------------------------------------
  204. for ($i=1; $i<=$list["stats"]["directories"]["total_number"]; $i=$i+1) {
  205. $currentdirectory = glueDirectories($directory, $list["directories"][$i]["dirfilename"]);
  206. // ------------------------------------
  207. // Determine if the directory must first be chmodded (if chmodded to 5 or 7),
  208. // or first be traversed (if chmodded to other values)
  209. // A problem is that we don't know if the FTP user is the owner/group/other of the file...
  210. // ------------------------------------
  211. if ($list["directories"][$i]["chmodoctal"] == 555 ||
  212. $list["directories"][$i]["chmodoctal"] == 557 ||
  213. $list["directories"][$i]["chmodoctal"] == 575 ||
  214. $list["directories"][$i]["chmodoctal"] == 577 ||
  215. $list["directories"][$i]["chmodoctal"] == 755 ||
  216. $list["directories"][$i]["chmodoctal"] == 757 ||
  217. $list["directories"][$i]["chmodoctal"] == 775 ||
  218. $list["directories"][$i]["chmodoctal"] == 777) {
  219. $first_chmod_then_traverse = true;
  220. }
  221. else {
  222. $first_chmod_then_traverse = false;
  223. }
  224. // ------------------------------------
  225. // Chmod the directory - FIRST CHMOD THEN TRAVERSE
  226. // If the $divelevel == 0 then chmod it in any case as it is the top directory
  227. // If the $divelevel > 0 then chmod it only if chmod_subdirectories == "yes"
  228. // ------------------------------------
  229. if ($first_chmod_then_traverse == true && ($list["directories"][$i]["chmod_subdirectories"] == "yes" || $divelevel == 0)) {
  230. $sitecommand = "chmod 0" . $list["directories"][$i]["chmodoctal"] . " $currentdirectory";
  231. $success1 = ftp_site($conn_id, $sitecommand);
  232. if ($success1 == false) {
  233. $errormessage = __("Unable to execute site command <b>%1\$s</b>. Note that the CHMOD command is only available on Unix FTP servers, not on Windows FTP servers.", $sitecommand);
  234. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  235. return false;
  236. }
  237. elseif ($success1 == true) {
  238. $net2ftp_output["ftp_chmod2"][] = __("Directory <b>%1\$s</b> successfully chmodded to <b>%2\$s</b>", $currentdirectory, $list["directories"][$i]["chmodoctal"]);
  239. }
  240. }
  241. // ------------------------------------
  242. // If the subdirectories and files within the current directory also have to be chmodded...
  243. // ------------------------------------
  244. if ($list["directories"][$i]["chmod_subdirectories"] == "yes" || $list["directories"][$i]["chmod_subfiles"] == "yes") {
  245. // Get a new list
  246. $newlist = ftp_getlist($conn_id, $currentdirectory);
  247. if ($net2ftp_result["success"] == false) { return false; }
  248. // Add information to the list
  249. for ($j=1; $j<=$newlist["stats"]["directories"]["total_number"]; $j++) {
  250. $newlist["directories"][$j]["chmodoctal"] = $list["directories"][$i]["chmodoctal"];
  251. $newlist["directories"][$j]["chmod_subdirectories"] = $list["directories"][$i]["chmod_subdirectories"];
  252. $newlist["directories"][$j]["chmod_subfiles"] = $list["directories"][$i]["chmod_subfiles"];
  253. }
  254. for ($j=1; $j<=$newlist["stats"]["files"]["total_number"]; $j++) {
  255. $newlist["files"][$j]["chmodoctal"] = $list["directories"][$i]["chmodoctal"];
  256. $newlist["files"][$j]["chmod_subdirectories"] = $list["directories"][$i]["chmod_subdirectories"];
  257. $newlist["files"][$j]["chmod_subfiles"] = $list["directories"][$i]["chmod_subfiles"];
  258. }
  259. // Call the function recursively
  260. $net2ftp_output["ftp_chmod2"][] = __("Processing entries within directory <b>%1\$s</b>:", $currentdirectory);
  261. $net2ftp_output["ftp_chmod2"][] = "<ul>";
  262. $newdivelevel = $divelevel + 1;
  263. ftp_chmod2($conn_id, $currentdirectory, $newlist, $newdivelevel);
  264. $net2ftp_output["ftp_chmod2"][] = "</ul>";
  265. } // end if subdirectories and files
  266. // ------------------------------------
  267. // Chmod the directory - FIRST TRAVERSE THEN CHMOD
  268. // If the $divelevel == 0 then chmod it in any case as it is the top directory
  269. // If the $divelevel > 0 then chmod it only if chmod_subdirectories == "yes"
  270. // ------------------------------------
  271. if ($first_chmod_then_traverse == false && ($list["directories"][$i]["chmod_subdirectories"] == "yes" || $divelevel == 0)) {
  272. $sitecommand = "chmod 0" . $list["directories"][$i]["chmodoctal"] . " $currentdirectory";
  273. $success1 = ftp_site($conn_id, $sitecommand);
  274. if ($success1 == false) {
  275. $errormessage = __("Unable to execute site command <b>%1\$s</b>. Note that the CHMOD command is only available on Unix FTP servers, not on Windows FTP servers.", $sitecommand);
  276. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  277. return false;
  278. }
  279. elseif ($success1 == true) {
  280. $net2ftp_output["ftp_chmod2"][] = __("Directory <b>%1\$s</b> successfully chmodded to <b>%2\$s</b>", $currentdirectory, $list["directories"][$i]["chmodoctal"]);
  281. }
  282. }
  283. } // end for list_directories
  284. // -------------------------------------------------------------------------
  285. // Process the files
  286. // -------------------------------------------------------------------------
  287. for ($i=1; $i<=$list["stats"]["files"]["total_number"]; $i=$i+1) {
  288. $currentfile = glueDirectories($directory, $list["files"][$i]["dirfilename"]);
  289. // Chmod the files
  290. // If the $divelevel == 0 then chmod them in any case as they are the top files
  291. // If the $divelevel > 0 then chmod them only if chmod_subfiles == "yes"
  292. if ($list["files"][$i]["chmod_subfiles"] == "yes" || $divelevel == 0) {
  293. $sitecommand = "chmod 0" . $list["files"][$i]["chmodoctal"] . " $currentfile";
  294. $success2 = ftp_site($conn_id, $sitecommand);
  295. if ($success2 == false) {
  296. $errormessage = __("Unable to execute site command <b>%1\$s</b>. Note that the CHMOD command is only available on Unix FTP servers, not on Windows FTP servers.", $sitecommand);
  297. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  298. return false;
  299. }
  300. elseif ($success2 == true) {
  301. $net2ftp_output["ftp_chmod2"][] = __("File <b>%1\$s</b> was successfully chmodded to <b>%2\$s</b>", $currentfile, $list["files"][$i]["chmodoctal"]);
  302. }
  303. }
  304. } // end for list_files
  305. // Print message
  306. if ($divelevel == 0) { $net2ftp_output["ftp_chmod2"][] = __("All the selected directories and files have been processed."); }
  307. } // End function ftp_chmod2
  308. // ** **
  309. // ** **
  310. // **************************************************************************************
  311. // **************************************************************************************
  312. // **************************************************************************************
  313. // **************************************************************************************
  314. // ** **
  315. // ** **
  316. function ftp_rmdir2($conn_id, $directory) {
  317. // --------------
  318. // This function deletes a directory
  319. // --------------
  320. // Replace \' by \\' to be able to delete directories with names containing \'
  321. $directory = str_replace("\'", "\\\'", $directory);
  322. // QUICK WAY TO DELETE A DIRECTORY
  323. $success1 = ftp_rmdir($conn_id, $directory);
  324. // THE FTP_RMDIR MAY NOT WORK WITH ALL FTP SERVERS, AS DESCRIBED ON THE FORUM
  325. // http://www.net2ftp.org/forums/index.php?showtopic=658
  326. // Solution: to delete /dir/parent/dirtodelete
  327. // 1. chdir to the parent directory /dir/parent
  328. // 2. delete the subdirectory, but use only its name (dirtodelete), not the full path (/dir/parent/dirtodelete)
  329. if ($success1 == false) {
  330. ftp_chdir($conn_id, upDir($directory));
  331. $parts = explode("/", $directory);
  332. $lastpartnr = sizeof($parts)-1;
  333. $success2 = ftp_rmdir($conn_id, $parts[$lastpartnr]);
  334. if ($success2 == false) {
  335. $errormessage = __("Unable to delete the directory <b>%1\$s</b>", $directory);
  336. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  337. return false;
  338. }
  339. }
  340. } // End function ftp_rmdir2
  341. // ** **
  342. // ** **
  343. // **************************************************************************************
  344. // **************************************************************************************
  345. // **************************************************************************************
  346. // **************************************************************************************
  347. // ** **
  348. // ** **
  349. function ftp_delete2($conn_id, $file) {
  350. // --------------
  351. // This function deletes a file
  352. // --------------
  353. // Replace \' by \\' to be able to delete directories with names containing \'
  354. $file = str_replace("\'", "\\\'", $file);
  355. $success1 = ftp_delete($conn_id, $file);
  356. // THE FTP_RMDIR MAY NOT WORK WITH ALL FTP SERVERS, AS DESCRIBED ON THE FORUM
  357. // http://www.net2ftp.org/forums/index.php?showtopic=658
  358. // Solution: to delete /dir/parent/dirtodelete
  359. // 1. chdir to the parent directory /dir/parent
  360. // 2. delete the subdirectory, but use only its name (dirtodelete), not the full path (/dir/parent/dirtodelete)
  361. if ($success1 == false) {
  362. ftp_chdir($conn_id, upDir($file));
  363. $parts = explode("/", $file);
  364. $lastpartnr = sizeof($parts)-1;
  365. $success2 = ftp_delete($conn_id, $parts[$lastpartnr]);
  366. if ($success2 == false) {
  367. $errormessage = __("Unable to delete the file <b>%1\$s</b>", $file);
  368. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  369. return false;
  370. }
  371. }
  372. } // End function ftp_delete2
  373. // ** **
  374. // ** **
  375. // **************************************************************************************
  376. // **************************************************************************************
  377. // **************************************************************************************
  378. // **************************************************************************************
  379. // ** **
  380. // ** **
  381. function ftp_newdirectory($conn_id, $directory) {
  382. // --------------
  383. // This function creates a new remote directory
  384. // --------------
  385. $success1 = ftp_mkdir($conn_id, $directory);
  386. if ($success1 == false) {
  387. $errormessage = __("Unable to create the directory <b>%1\$s</b>", $directory);
  388. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  389. return false;
  390. }
  391. } // End function ftp_newdirectory
  392. // ** **
  393. // ** **
  394. // **************************************************************************************
  395. // **************************************************************************************
  396. // **************************************************************************************
  397. // **************************************************************************************
  398. // ** **
  399. // ** **
  400. function ftp_readfile($conn_id, $directory, $file) {
  401. // --------------
  402. // This function opens a remote text file and it returns a string
  403. // It can be used stand-alone (with conn_id = "") and then a new connection is opened
  404. // Else it can also be used in a loop (with conn_id != false) and then the existing connection is opened
  405. // --------------
  406. // -------------------------------------------------------------------------
  407. // Global variables
  408. // -------------------------------------------------------------------------
  409. global $net2ftp_globals, $net2ftp_result;
  410. $source = glueDirectories($directory, $file);
  411. // Step 1/4: Create a temporary filename
  412. $tempfilename = tempnam($net2ftp_globals["application_tempdir"], "read__");
  413. if ($tempfilename == false) {
  414. @unlink($tempfilename);
  415. $errormessage = __("Unable to create the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]);
  416. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  417. return false;
  418. }
  419. registerTempfile("register", $tempfilename);
  420. // Step 2/4: Copy remote file to the temporary file
  421. // Open connection if needed
  422. if ($conn_id == "") {
  423. $conn_id = ftp_openconnection();
  424. if ($net2ftp_result["success"] == false) {
  425. @unlink($tempfilename);
  426. return false;
  427. }
  428. $leave_conn_open = "no";
  429. }
  430. else {
  431. $leave_conn_open = "yes";
  432. }
  433. // Check the consumption
  434. if(checkConsumption() == false) {
  435. $errormessage = __("Daily limit reached: the file <b>%1\$s</b> will not be transferred", $source);
  436. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  437. return false;
  438. }
  439. // Get file
  440. $ftpmode = ftpAsciiBinary($source);
  441. $ftp_get_result = ftp_get($conn_id, "$tempfilename", "$source", $ftpmode);
  442. if ($ftp_get_result == false) {
  443. @unlink($tempfilename);
  444. $errormessage = __("Unable to get the file <b>%1\$s</b> from the FTP server and to save it as temporary file <b>%2\$s</b>.<br />Check the permissions of the %3\$s directory.<br />", $source, $tempfilename, $net2ftp_globals["application_tempdir"]);
  445. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  446. return false;
  447. }
  448. // Add the filesize to the global consumption variables
  449. addConsumption(filesize($tempfilename), 0);
  450. // Close connection
  451. if ($leave_conn_open == "no") { ftp_closeconnection($conn_id); }
  452. // Step 3/4: Read temporary file
  453. $string = local_readfile($tempfilename);
  454. if ($net2ftp_result["success"] == false) { return false; }
  455. // Step 4/4: Delete temporary file
  456. $unlink_result = @unlink($tempfilename);
  457. if ($unlink_result == false) {
  458. $errormessage = __("Unable to delete the temporary file");
  459. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  460. return false;
  461. }
  462. registerTempfile("unregister", $tempfilename);
  463. // Change CarriageReturn+LineFeed by LineFeed
  464. // This is because some FTP servers replace LineFeed by CarriageReturn+LineFeed
  465. // if ($ftpmode == FTP_ASCII) {
  466. // $string = standardize_eol($string);
  467. // }
  468. return $string;
  469. } // End function ftp_readfile
  470. // ** **
  471. // ** **
  472. // **************************************************************************************
  473. // **************************************************************************************
  474. // **************************************************************************************
  475. // **************************************************************************************
  476. // ** **
  477. // ** **
  478. function ftp_writefile($conn_id, $directory, $file, $string) {
  479. // --------------
  480. // This function writes a string to a remote text file.
  481. // If it already existed, it will be overwritten without asking for a confirmation.
  482. // It can be used stand-alone (with conn_id = "") and then a new connection is opened
  483. // Else it can also be used in a loop (with conn_id != false) and then the existing connection is opened
  484. // --------------
  485. // -------------------------------------------------------------------------
  486. // Global variables
  487. // -------------------------------------------------------------------------
  488. global $net2ftp_globals, $net2ftp_result;
  489. $target = glueDirectories($directory, $file);
  490. $ftpmode = ftpAsciiBinary($file);
  491. // Change CarriageReturn+LineFeed by LineFeed
  492. // This is because some FTP servers replace LineFeed by CarriageReturn+LineFeed
  493. // if ($ftpmode == FTP_ASCII) {
  494. // $string = standardize_eol($string);
  495. // }
  496. // Step 1/4: Create a temporary filename
  497. $tempfilename = tempnam($net2ftp_globals["application_tempdir"], "write__");
  498. if ($tempfilename == false) {
  499. @unlink($tempfilename);
  500. $errormessage = __("Unable to create the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]);
  501. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  502. return false;
  503. }
  504. registerTempfile("register", $tempfilename);
  505. // Step 2/4: Write the string to the temporary file
  506. local_writefile($tempfilename, $string);
  507. if ($net2ftp_result["success"] == false) { return false; }
  508. // Step 3/4: Copy temporary file to remote file
  509. // Open connection if needed
  510. if ($conn_id == "") {
  511. $conn_id = ftp_openconnection();
  512. if ($net2ftp_result["success"] == false) {
  513. @unlink($tempfilename);
  514. return false;
  515. }
  516. $leave_conn_open = "no";
  517. }
  518. else {
  519. $leave_conn_open = "yes";
  520. }
  521. // Add the filesize to the global consumption variables
  522. addConsumption(filesize($tempfilename), 0);
  523. // Check the consumption
  524. if(checkConsumption() == false) {
  525. addConsumption((-1)*filesize($tempfilename), 0);
  526. $errormessage = __("Daily limit reached: the file <b>%1\$s</b> will not be transferred", $target);
  527. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  528. return false;
  529. }
  530. // Put file
  531. // The FTP mode is calculated a few lines above
  532. //$ftpmode = ftpAsciiBinary($file);
  533. $success3 = ftp_put($conn_id, $target, $tempfilename, $ftpmode);
  534. if ($success3 == false) {
  535. @unlink($tempfilename);
  536. $errormessage = __("Unable to put the file <b>%1\$s</b> on the FTP server.<br />You may not have write permissions on the directory.", $target);
  537. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  538. return false;
  539. }
  540. // Close connection
  541. if ($leave_conn_open == "no") { ftp_closeconnection($conn_id); }
  542. // Step 4/4: Delete temporary file
  543. $success4 = @unlink($tempfilename);
  544. if ($success4 == false) {
  545. $errormessage = __("Unable to delete the temporary file");
  546. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  547. return false;
  548. }
  549. registerTempfile("unregister", $tempfilename);
  550. } // End function ftp_writefile
  551. // ** **
  552. // ** **
  553. // **************************************************************************************
  554. // **************************************************************************************
  555. // **************************************************************************************
  556. // **************************************************************************************
  557. // ** **
  558. // ** **
  559. function ftp_copymovedelete($conn_id_source, $conn_id_target, $list, $copymovedelete, $divelevel) {
  560. // --------------
  561. // This function copies/moves/deletes directories and files from an FTP server to the same
  562. // or another FTP server.
  563. //
  564. // Note there is a difference between move on the same FTP server, and move to another FTP
  565. // server. Move on the same FTP server is done by renaming the directories and files because
  566. // this is much faster.
  567. //
  568. // For copy (on same or another FTP server) and move (to another FTP server), files
  569. // are first transferred from the source FTP server to the webserver, and then transferred
  570. // to the target FTP server.
  571. //
  572. // $list[$i]["dirorfile"] contains d or - which indicates if its a directory or a file
  573. // $list[$i]["dirfilename"] contains the entry name
  574. // $list[$i]["sourcedirectory"] contains the source directory
  575. // $list[$i]["targetdirectory"] contains the target directory
  576. // $list[$i]["newname"] contains the new name if divelevel = 0; for deeper levels the newname is the entry name itself
  577. // --------------
  578. // -------------------------------------------------------------------------
  579. // Global variables
  580. // -------------------------------------------------------------------------
  581. global $net2ftp_globals, $net2ftp_settings, $net2ftp_result, $net2ftp_output;
  582. // -------------------------------------------------------------------------
  583. // Initialization
  584. // -------------------------------------------------------------------------
  585. if ($divelevel == 0) {
  586. $net2ftp_output["ftp_copymovedelete"][] = "<ul>";
  587. }
  588. // Total number of directories and files on level 0 (chosen by the user)
  589. $total_dirs_files = $list["stats"]["directories"]["total_number"] + $list["stats"]["files"]["total_number"];
  590. // -------------------------------------------------------------------------
  591. // For all directories
  592. // -------------------------------------------------------------------------
  593. for ($i=1; $i<=$list["stats"]["directories"]["total_number"]; $i=$i+1) {
  594. // ------------------------------
  595. // Set the status
  596. // ------------------------------
  597. $message = __("Processing entry %1\$s", javascriptEncode2($list["directories"][$i]["dirfilename"])) . " ($i/$total_dirs_files)";
  598. setStatus($i, $total_dirs_files, $message);
  599. // ------------------------------
  600. // Source and target
  601. // ------------------------------
  602. $source = glueDirectories($list["directories"][$i]["sourcedirectory"], $list["directories"][$i]["dirfilename"]);
  603. if ($copymovedelete == "copy" || $copymovedelete == "move") {
  604. if ($divelevel > 0) { $target = glueDirectories($list["directories"][$i]["targetdirectory"], $list["directories"][$i]["dirfilename"]); } // Subdirectories keep their original names
  605. else { $target = glueDirectories($list["directories"][$i]["targetdirectory"], $list["directories"][$i]["newname"]); } // First-level user-selected directories can have been renamed
  606. }
  607. else {
  608. $target = "";
  609. }
  610. // ------------------------------
  611. // Print starting message
  612. // ------------------------------
  613. $net2ftp_output["ftp_copymovedelete"][] = __("Processing directory <b>%1\$s</b>", $source);
  614. $net2ftp_output["ftp_copymovedelete"][] = "<ul>";
  615. // ------------------------------
  616. // Check that the targetdirectory is not a subdirectory of the sourcedirectory
  617. // ------------------------------
  618. if (($conn_id_source == $conn_id_target) && ($copymovedelete != "delete") && (isSubdirectory($source, $target) == true)) {
  619. $net2ftp_output["ftp_copymovedelete"][] = __("The target directory <b>%1\$s</b> is the same as or a subdirectory of the source directory <b>%2\$s</b>, so this directory will be skipped", $target, $source);
  620. $net2ftp_output["ftp_copymovedelete"][] = "</ul>";
  621. continue;
  622. }
  623. // ------------------------------
  624. // Check if the directory contains a banned keyword
  625. // ------------------------------
  626. // If banned keyword - copy: continue
  627. // If banned keyword - move: abort
  628. if ($list["directories"][$i]["selectable"] == "banned_keyword") {
  629. if ($copymovedelete == "copy") {
  630. $net2ftp_output["ftp_copymovedelete"][] = __("The directory <b>%1\$s</b> contains a banned keyword, so this directory will be skipped", $source);
  631. $net2ftp_output["ftp_copymovedelete"][] = "</ul>";
  632. continue;
  633. }
  634. elseif ($copymovedelete == "move") {
  635. $net2ftp_output["ftp_copymovedelete"][] = __("The directory <b>%1\$s</b> contains a banned keyword, aborting the move", $source);
  636. $net2ftp_output["ftp_copymovedelete"][] = "</ul>";
  637. return false;
  638. }
  639. }
  640. // ------------------------------
  641. // For copy (to the same or another FTP server), move (to another FTP server) or delete
  642. // ------------------------------
  643. if ($copymovedelete == "copy" || ($copymovedelete == "move" && $conn_id_source != $conn_id_target) || $copymovedelete == "delete") {
  644. // Create the targetdirectory
  645. if ($copymovedelete == "copy" || $copymovedelete == "move") {
  646. $success1 = ftp_mkdir($conn_id_target, $target);
  647. if ($success1 == false) { $net2ftp_output["ftp_copymovedelete"][] = __("Unable to create the subdirectory <b>%1\$s</b>. It may already exist. Continuing the copy/move process...", $target); }
  648. else { $net2ftp_output["ftp_copymovedelete"][] = __("Created target subdirectory <b>%1\$s</b>", $target); }
  649. }
  650. // Get a new list
  651. $newlist = ftp_getlist($conn_id_source, $source);
  652. if ($net2ftp_result["success"] == false) {
  653. $net2ftp_output["ftp_copymovedelete"][] = __("The directory <b>%1\$s</b> could not be selected, so this directory will be skipped", $source);
  654. $net2ftp_output["ftp_copymovedelete"][] = "</ul>";
  655. setErrorVars(true, "", "", "", "");
  656. continue;
  657. }
  658. // Add information to the list
  659. for ($j=1; $j<=$newlist["stats"]["directories"]["total_number"]; $j++) {
  660. $newlist["directories"][$j]["sourcedirectory"] = $source;
  661. $newlist["directories"][$j]["targetdirectory"] = $target;
  662. }
  663. for ($j=1; $j<=$newlist["stats"]["files"]["total_number"]; $j++) {
  664. $newlist["files"][$j]["sourcedirectory"] = $source;
  665. $newlist["files"][$j]["targetdirectory"] = $target;
  666. }
  667. // Call the function recursively
  668. $newdivelevel = $divelevel + 1;
  669. $ftp_copymovedelete_result = ftp_copymovedelete($conn_id_source, $conn_id_target, $newlist, $copymovedelete, $newdivelevel);
  670. // Delete the source directory
  671. // (Only if there were no problems in the recursive call to ftp_copymovedelete() above)
  672. if ($ftp_copymovedelete_result == true && ($copymovedelete == "move" || $copymovedelete == "delete")) {
  673. ftp_rmdir2($conn_id_source, $source);
  674. if ($net2ftp_result["success"] == false) {
  675. setErrorVars(true, "", "", "", "");
  676. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to delete the subdirectory <b>%1\$s</b> - it may not be empty", $source);
  677. }
  678. else {
  679. $net2ftp_output["ftp_copymovedelete"][] = __("Deleted subdirectory <b>%1\$s</b>", $source);
  680. }
  681. }
  682. } // end if copy, move to another FTP server, delete
  683. // ------------------------------
  684. // For move (to the same FTP server)
  685. // ------------------------------
  686. if ($copymovedelete == "move" && $conn_id_source == $conn_id_target) {
  687. ftp_rename3($conn_id_source, $source, $target);
  688. if ($net2ftp_result["success"] == false) {
  689. setErrorVars(true, "", "", "", "");
  690. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to move the directory <b>%1\$s</b>", $source);
  691. $net2ftp_output["ftp_copymovedelete"][] = "</ul>";
  692. continue;
  693. }
  694. else {
  695. $net2ftp_output["ftp_copymovedelete"][] = __("Moved directory <b>%1\$s</b>", $source);
  696. }
  697. } // end if move to the same FTP server
  698. // ------------------------------
  699. // Print ending message
  700. // ------------------------------
  701. $net2ftp_output["ftp_copymovedelete"][] = __("Processing of directory <b>%1\$s</b> completed", $source);
  702. $net2ftp_output["ftp_copymovedelete"][] = "</ul>";
  703. } // end for list_directories
  704. // -------------------------------------------------------------------------
  705. // Process the files
  706. // -------------------------------------------------------------------------
  707. for ($i=1; $i<=$list["stats"]["files"]["total_number"]; $i=$i+1) {
  708. // ------------------------------
  709. // Set the status
  710. // ------------------------------
  711. $j = $list["stats"]["directories"]["total_number"] + $i;
  712. $message = __("Processing entry %1\$s", javascriptEncode2($list["files"][$i]["dirfilename"])) . " ($j/$total_dirs_files)";
  713. setStatus($j, $total_dirs_files, $message);
  714. // ------------------------------
  715. // Source and target
  716. // ------------------------------
  717. $source = glueDirectories($list["files"][$i]["sourcedirectory"], $list["files"][$i]["dirfilename"]);
  718. if ($copymovedelete == "copy" || $copymovedelete == "move") {
  719. if (isset($list["files"][$i]["newname"])) { $target = glueDirectories($list["files"][$i]["targetdirectory"], $list["files"][$i]["newname"]); }
  720. else { $target = glueDirectories($list["files"][$i]["targetdirectory"], $list["files"][$i]["dirfilename"]); }
  721. }
  722. else {
  723. $target = "";
  724. }
  725. // ------------------------------
  726. // Check that the target is not the same as the source file
  727. // ------------------------------
  728. if (($conn_id_source == $conn_id_target) && ($target == $source)) {
  729. $net2ftp_output["ftp_copymovedelete"][] = __("The target for file <b>%1\$s</b> is the same as the source, so this file will be skipped", $source);
  730. continue;
  731. }
  732. // ------------------------------
  733. // Check if the file contains a banned keyword, and if it is not bigger than the limit
  734. // ------------------------------
  735. // If banned keyword or too big - copy: continue with the other files
  736. // If banned keyword or too big - move: abort
  737. if ($list["files"][$i]["selectable"] == "banned_keyword") {
  738. if ($copymovedelete == "copy") {
  739. $net2ftp_output["ftp_copymovedelete"][] = __("The file <b>%1\$s</b> contains a banned keyword, so this file will be skipped", $source);
  740. continue;
  741. }
  742. elseif ($copymovedelete == "move") {
  743. $net2ftp_output["ftp_copymovedelete"][] = __("The file <b>%1\$s</b> contains a banned keyword, aborting the move", $source);
  744. return false;
  745. }
  746. }
  747. elseif ($list["files"][$i]["selectable"] == "too_big") {
  748. if ($copymovedelete == "copy") {
  749. $net2ftp_output["ftp_copymovedelete"][] = __("The file <b>%1\$s</b> is too big to be copied, so this file will be skipped", $source);
  750. continue;
  751. }
  752. elseif ($copymovedelete == "move") {
  753. $net2ftp_output["ftp_copymovedelete"][] = __("The file <b>%1\$s</b> is too big to be moved, aborting the move", $source);
  754. return false;
  755. }
  756. }
  757. // ------------------------------------
  758. // For copy (to the same or another FTP server) or move (to another FTP server)
  759. // ------------------------------------
  760. if ($copymovedelete == "copy" || ($copymovedelete == "move" && $conn_id_source != $conn_id_target)) {
  761. // Get file from remote sourcedirectory to local temp directory
  762. // Don't delete the source file yet
  763. $localtargetdir = $net2ftp_globals["application_tempdir"];
  764. $localtargetfile = $list["files"][$i]["dirfilename"] . ".txt";
  765. $remotesourcedir = $list["files"][$i]["sourcedirectory"];
  766. $remotesourcefile = $list["files"][$i]["dirfilename"];
  767. $ftpmode = ftpAsciiBinary($list["files"][$i]["dirfilename"]);
  768. $copymove = "copy";
  769. ftp_getfile($conn_id_source, $localtargetdir, $localtargetfile, $remotesourcedir, $remotesourcefile, $ftpmode, $copymove);
  770. if ($net2ftp_result["success"] == false) {
  771. setErrorVars(true, "", "", "", "");
  772. if ($copymovedelete == "copy") {
  773. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to copy the file <b>%1\$s</b>", $list["files"][$i]["dirfilename"]);
  774. continue;
  775. }
  776. elseif ($copymovedelete == "move") {
  777. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to move the file <b>%1\$s</b>, aborting the move", $list["files"][$i]["dirfilename"]);
  778. return false;
  779. }
  780. }
  781. // Put file from local temp directory to remote targetdirectory
  782. // Delete the temporary file
  783. $localsourcedir = $net2ftp_globals["application_tempdir"];
  784. $localsourcefile = $list["files"][$i]["dirfilename"] . ".txt";
  785. $remotetargetdir = $list["files"][$i]["targetdirectory"];
  786. if (isset($list["files"][$i]["newname"])) { $remotetargetfile = $list["files"][$i]["newname"]; }
  787. else { $remotetargetfile = $list["files"][$i]["dirfilename"]; }
  788. $copymove = "move";
  789. ftp_putfile($conn_id_target, $localsourcedir, $localsourcefile, $remotetargetdir, $remotetargetfile, $ftpmode, $copymove);
  790. if ($net2ftp_result["success"] == false) {
  791. setErrorVars(true, "", "", "", "");
  792. if ($copymovedelete == "copy") {
  793. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to copy the file <b>%1\$s</b>", $list["files"][$i]["dirfilename"]);
  794. continue;
  795. }
  796. elseif ($copymovedelete == "move") {
  797. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to move the file <b>%1\$s</b>, aborting the move", $list["files"][$i]["dirfilename"]);
  798. return false;
  799. }
  800. }
  801. // Copy: if the operation is successful, print a message
  802. elseif ($net2ftp_result["success"] == true && $copymovedelete == "copy") {
  803. $net2ftp_output["ftp_copymovedelete"][] = __("Copied file <b>%1\$s</b>", $list["files"][$i]["dirfilename"]);
  804. }
  805. // Move: only if the operation is successful, delete the source file
  806. elseif ($copymovedelete == "move") {
  807. $remotesource = glueDirectories($list["files"][$i]["sourcedirectory"], $list["files"][$i]["dirfilename"]);
  808. ftp_delete2($conn_id_source, $remotesource);
  809. if ($net2ftp_result["success"] == false) {
  810. setErrorVars(true, "", "", "", "");
  811. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to move the file <b>%1\$s</b>", $list["files"][$i]["dirfilename"]);
  812. }
  813. else {
  814. $net2ftp_output["ftp_copymovedelete"][] = __("Moved file <b>%1\$s</b>", $list["files"][$i]["dirfilename"]);
  815. }
  816. }
  817. } // end if copy, move to another FTP server, delete
  818. // ------------------------------
  819. // For move (to the same FTP server)
  820. // ------------------------------
  821. elseif ($copymovedelete == "move" && $conn_id_source == $conn_id_target) {
  822. ftp_rename3($conn_id_source, $source, $target);
  823. if ($net2ftp_result["success"] == false) {
  824. setErrorVars(true, "", "", "", "");
  825. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to move the file <b>%1\$s</b>", $source);
  826. }
  827. else {
  828. $net2ftp_output["ftp_copymovedelete"][] = __("Moved file <b>%1\$s</b>", $source);
  829. }
  830. } // end if move to the same FTP server
  831. // ------------------------------------
  832. // For delete
  833. // ------------------------------------
  834. elseif ($copymovedelete == "delete") {
  835. $remotesource = glueDirectories($list["files"][$i]["sourcedirectory"], $list["files"][$i]["dirfilename"]);
  836. ftp_delete2($conn_id_source, $remotesource);
  837. if ($net2ftp_result["success"] == false) {
  838. setErrorVars(true, "", "", "", "");
  839. $net2ftp_output["ftp_copymovedelete"][] = __("Unable to delete the file <b>%1\$s</b>", $list["files"][$i]["dirfilename"]);
  840. continue;
  841. }
  842. else {
  843. $net2ftp_output["ftp_copymovedelete"][] = __("Deleted file <b>%1\$s</b>", $list["files"][$i]["dirfilename"]);
  844. }
  845. } // end delete
  846. } // end for list_files
  847. if ($divelevel == 0) { $net2ftp_output["ftp_copymovedelete"][] = "</ul>"; }
  848. // Print message
  849. if ($divelevel == 0) { $net2ftp_output["ftp_copymovedelete"][] = __("All the selected directories and files have been processed."); }
  850. return true;
  851. } // End function ftp_copymovedelete
  852. // ** **
  853. // ** **
  854. // **************************************************************************************
  855. // **************************************************************************************
  856. // **************************************************************************************
  857. // **************************************************************************************
  858. // ** **
  859. // ** **
  860. function ftp_processfiles($dowhat, $conn_id, $directory, $list, $options, $result, $divelevel) {
  861. // --------------
  862. // This function does something with files (get size, find string, ...)
  863. // The $list contains both directories and files. The files are simply processed; the
  864. // directories are parsed recursively.
  865. //
  866. // $list[$i]["dirorfile"] contains d or - which indicates if the entry is a directory or a file
  867. // $list[$i]["dirfilename"] contains the name of the entry
  868. // $list[$i]["size"] contains the size of the entry
  869. //
  870. // OPTIONS:
  871. // if ($dowhat == "calculatesize") then
  872. // $options = array() doesn't contain anything
  873. // if ($dowhat == "findstring") then
  874. // $options["string"] a string
  875. // $options["case_sensitive"] blank or yes
  876. // $options["filename"] a filename with possible wildcard character * (it should match this preg_match regular expression: "/^[a-zA-Z0-9_ *-]*$/")
  877. // $options["size_from"], $options["size_to"] a number (in Bytes)
  878. // $options["modified_from"], $options["modified_to"] unix timestamps of the modification dates
  879. //
  880. // RESULT:
  881. // if ($dowhat == "calculatesize") then
  882. // $result["size"]
  883. // $result["skipped"]
  884. // if ($dowhat == "findstring") then
  885. // $result[$k]["directory"] contains the directory
  886. // $result[$k]["dirfilename"] contains the filename
  887. // $result[$k]["line"] contains the line nr
  888. //
  889. // --------------
  890. // -------------------------------------------------------------------------
  891. // Global variables
  892. // -------------------------------------------------------------------------
  893. global $net2ftp_globals, $net2ftp_result;
  894. // -------------------------------------------------------------------------
  895. // Initialization
  896. // -------------------------------------------------------------------------
  897. if ($divelevel == 0) {
  898. }
  899. // -------------------------------------------------------------------------
  900. // For all directories
  901. // -------------------------------------------------------------------------
  902. for ($i=1; $i<=$list["stats"]["directories"]["total_number"]; $i=$i+1) {
  903. $currentdirectory = glueDirectories($directory, $list["directories"][$i]["dirfilename"]);
  904. // Check if the directory contains a banned keyword
  905. if ($list["directories"][$i]["selectable"] != "ok") { continue; }
  906. // Get a new list
  907. $newlist = ftp_getlist($conn_id, $currentdirectory);
  908. if ($net2ftp_result["success"] == false) { return false; }
  909. // Call the function recursively
  910. $newdivelevel = $divelevel + 1;
  911. $result = ftp_processfiles($dowhat, $conn_id, $currentdirectory, $newlist, $options, $result, $newdivelevel);
  912. if ($net2ftp_result["success"] == false) { return false; }
  913. } // end for list_directories
  914. // -------------------------------------------------------------------------
  915. // Process the files
  916. // -------------------------------------------------------------------------
  917. for ($i=1; $i<=$list["stats"]["files"]["total_number"]; $i=$i+1) {
  918. // -------------------------------
  919. // Calculate size
  920. // -------------------------------
  921. if ($dowhat == "calculatesize") {
  922. // Check if the size information is entered
  923. // Check also if the size is numeric
  924. if (isset($list["files"][$i]["size"]) && is_numeric($list["files"][$i]["size"])) { $result["size"] = $result["size"] + $list["files"][$i]["size"]; }
  925. else { $result["skipped"] = $result["skipped"] + 1; }
  926. } // end if calculatesize
  927. // -------------------------------
  928. // Find string
  929. // -------------------------------
  930. elseif ($dowhat == "findstring") {
  931. // Check that the file is smaller than the maximum file size that can be processed with net2ftp
  932. if ($list["files"][$i]["selectable"] != "ok") {
  933. continue;
  934. }
  935. // Check that the file is within the limits indicated on the selection screen
  936. if ($list["files"][$i]["size"] < $options["size_from"] || $list["files"][$i]["size"] > $options["size_to"]) {
  937. // echo "File $i skipped";
  938. continue;
  939. }
  940. // Check modification date (if that data is returned by the FTP server in the correct format)
  941. $mtime_file = strtotime($list["files"][$i]["mtime"]);
  942. // If strtotime cannot interprete the data returned by the FTP server it returns -1
  943. if (($mtime_file != -1) && (($mtime_file < $options["modified_from"]) || ($mtime_file > $options["modified_to"]))) { continue; }
  944. // Check the filename
  945. $pattern = "/^" . $options["filename"] . "$/i"; // i at the end is for a case-insensitive match
  946. if (preg_match($pattern, $list["files"][$i]["dirfilename"]) == 0) { continue; }
  947. // Read the file
  948. $text = ftp_readfile("", $directory, $list["files"][$i]["dirfilename"]);
  949. // If the file could not be read correctly, continue to the next one
  950. if ($net2ftp_result["success"] == false) { setErrorVars(true, "", "", "", ""); continue; }
  951. elseif ($text == "") { continue; }
  952. // Split the file in an array, each element of the array containing one line of the file
  953. $text_lines = explode_lines($text);
  954. // For each line, check if the string occurs
  955. for ($line=0; $line<sizeof($text_lines); $line++) {
  956. // STRSTR AND STRISTR
  957. if ($options["case_sensitive"] == "yes") { $found = strstr($text_lines[$line], $options["string"]); }
  958. else { $found = stristr($text_lines[$line], $options["string"]); }
  959. if ($found != false) {
  960. $tempresult["directory"] = $directory;
  961. $tempresult["directory_html"] = htmlEncode2($directory);
  962. $tempresult["directory_js"] = javascriptEncode2($directory);
  963. $tempresult["dirfilename"] = $list["files"][$i]["dirfilename"];
  964. $tempresult["dirfilename_html"] = $list["files"][$i]["dirfilename_html"];
  965. $tempresult["dirfilename_js"] = $list["files"][$i]["dirfilename_js"];
  966. $tempresult["line"] = $line+1; // $text_lines[0] contains the line 1, etc...
  967. array_push($result, $tempresult);
  968. }
  969. } // end for
  970. } // end if findstring
  971. } // end for list_files
  972. return $result;
  973. } // End function ftp_processfiles
  974. // ** **
  975. // ** **
  976. // **************************************************************************************
  977. // **************************************************************************************
  978. // **************************************************************************************
  979. // **************************************************************************************
  980. // ** **
  981. // ** **
  982. function ftp_getfile($conn_id, $localtargetdir, $localtargetfile, $remotesourcedir, $remotesourcefile, $ftpmode, $copymove) {
  983. // --------------
  984. // This function copies or moves a remote file to a local file
  985. // $ftpmode is used to specify whether the file is to be transferred in ASCII or BINARY mode
  986. // $copymove is used to specify whether to delete (move) or not (copy) the local source
  987. //
  988. // True or false is returned
  989. //
  990. // The opposite function is ftp_putfile
  991. // --------------
  992. // Global variables
  993. global $net2ftp_settings;
  994. // Source and target
  995. if ($ftpmode == FTP_ASCII) { $printftpmode = "FTP_ASCII"; }
  996. elseif ($ftpmode == FTP_BINARY) { $printftpmode = "FTP_BINARY"; }
  997. $remotesource = glueDirectories($remotesourcedir, $remotesourcefile);
  998. $localtarget = glueDirectories($localtargetdir, $localtargetfile);
  999. // Check if the filesize is smaller than the allowed filesize
  1000. // $ftp_size_result = ftp_size($conn_id, $remotesource);
  1001. // if ($ftp_size_result > $net2ftp_settings["max_filesize"]) {
  1002. // $errormessage = __("The file is too big to be transferred");
  1003. // setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1004. // return false;
  1005. // }
  1006. // Check the consumption
  1007. if(checkConsumption() == false) {
  1008. $errormessage = __("Daily limit reached: the file <b>%1\$s</b> will not be transferred", $remotesource);
  1009. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1010. return false;
  1011. }
  1012. // Get file
  1013. $success1 = ftp_get($conn_id, $localtarget, $remotesource, $ftpmode);
  1014. if ($success1 == false) {
  1015. $errormessage = __("Unable to copy the remote file <b>%1\$s</b> to the local file using FTP mode <b>%2\$s</b>", $remotesource, $printftpmode);
  1016. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1017. return false;
  1018. }
  1019. else { registerTempfile("register", $localtarget); }
  1020. // Add the filesize to the global consumption variables
  1021. addConsumption(filesize($localtarget), 0);
  1022. // Copy ==> do nothing
  1023. // Move ==> delete remote source file
  1024. if ($copymove != "copy") {
  1025. $success2 = ftp_delete2($conn_id, $remotesource);
  1026. if ($success2 == false) {
  1027. $errormessage = __("Unable to delete file <b>%1\$s</b>", $remotesource);
  1028. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1029. return false;
  1030. }
  1031. }
  1032. } // End function ftp_getfile
  1033. // ** **
  1034. // ** **
  1035. // **************************************************************************************
  1036. // **************************************************************************************
  1037. // **************************************************************************************
  1038. // **************************************************************************************
  1039. // ** **
  1040. // ** **
  1041. function ftp_putfile($conn_id, $localsourcedir, $localsourcefile, $remotetargetdir, $remotetargetfile, $ftpmode, $copymove) {
  1042. // --------------
  1043. // This function copies or moves a local file to a remote file
  1044. // $ftpmode is used to specify whether the file is to be transferred in ASCII or BINARY mode
  1045. // $copymove is used to specify whether to delete (move) or not (copy) the local source
  1046. //
  1047. // The opposite function is ftp_getfile
  1048. // --------------
  1049. // Global variables
  1050. global $net2ftp_settings;
  1051. // Source and target
  1052. $localsource = glueDirectories($localsourcedir, $localsourcefile);
  1053. $remotetarget = glueDirectories($remotetargetdir, $remotetargetfile);
  1054. // In the function ftp_put, use FTP_BINARY without the double quotes, otherwhise ftp_put assumes FTP_ASCII
  1055. // DO NOT REMOVE THIS OR THE BINARY FILES WILL BE CORRUPTED (when copying, moving, uploading,...)
  1056. if ($ftpmode == "FTP_BINARY") { $ftpmode = FTP_BINARY; }
  1057. if ($ftpmode == FTP_ASCII) { $printftpmode = "FTP_ASCII"; }
  1058. elseif ($ftpmode == FTP_BINARY) { $printftpmode = "FTP_BINARY"; }
  1059. // Check if the filesize is smaller than the allowed filesize
  1060. if (filesize($localsource) > $net2ftp_settings["max_filesize"]) {
  1061. $errormessage = __("The file is too big to be transferred");
  1062. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1063. return false;
  1064. }
  1065. // Add the filesize to the global consumption variables
  1066. addConsumption(filesize($localsource), 0);
  1067. // Check the consumption
  1068. if(checkConsumption() == false) {
  1069. addConsumption((-1)*filesize($localsource), 0);
  1070. $errormessage = __("Daily limit reached: the file <b>%1\$s</b> will not be transferred", $remotetarget);
  1071. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1072. return false;
  1073. }
  1074. // Put local file to remote file
  1075. // int ftp_put (int ftp_stream, string remote_file, string local_file, int mode)
  1076. $success1 = ftp_put($conn_id, $remotetarget, $localsource, $ftpmode);
  1077. if ($success1 == false) {
  1078. $errormessage = __("Unable to copy the local file to the remote file <b>%1\$s</b> using FTP mode <b>%2\$s</b>", $remotetarget, $printftpmode);
  1079. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1080. return false;
  1081. }
  1082. // If ftp_put fails, this function returns an error message and does not delete the temporary file.
  1083. // In case the file was copied, a copy exists in the source directory.
  1084. // In case the file was moved, the only copy is in the temporary directory, and so this has to be moved back to the source directory.
  1085. // Copy ==> do nothing
  1086. // Move ==> delete local source file
  1087. if ($copymove != "copy") {
  1088. $success2 = unlink($localsource);
  1089. if ($success2 == false) {
  1090. $errormessage = __("Unable to delete the local file");
  1091. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1092. return false;
  1093. }
  1094. else { registerTempfile("unregister", $localsource); }
  1095. }
  1096. } // End function ftp_putfile
  1097. // ** **
  1098. // ** **
  1099. // **************************************************************************************
  1100. // **************************************************************************************
  1101. // **************************************************************************************
  1102. // **************************************************************************************
  1103. // ** **
  1104. // ** **
  1105. function getContentType($entry) {
  1106. // --------------------
  1107. // Content-type, for a complete list, see http://www.isi.edu/in-notes/iana/assignments/media-types/media-types
  1108. // Content-disposition: attachment. See http://www.w3.org/Protocols/HTTP/Issues/content-disposition.txt
  1109. // --------------------
  1110. $filename_extension = get_filename_extension($entry);
  1111. if ($filename_extension == "ai") { $content_type = "application/postscript"; }
  1112. elseif ($filename_extension == "aif") { $content_type = "audio/x-aiff"; }
  1113. elseif ($filename_extension == "aifc") { $content_type = "audio/x-aiff"; }
  1114. elseif ($filename_extension == "aiff") { $content_type = "audio/x-aiff"; }
  1115. elseif ($filename_extension == "asc") { $content_type = "text/plain"; }
  1116. elseif ($filename_extension == "atom") { $content_type = "application/atom+xml"; }
  1117. elseif ($filename_extension == "au") { $content_type = "audio/basic"; }
  1118. elseif ($filename_extension == "avi") { $content_type = "video/x-msvideo"; }
  1119. elseif ($filename_extension == "bcpio") { $content_type = "application/x-bcpio"; }
  1120. elseif ($filename_extension == "bin") { $content_type = "application/octet-stream"; }
  1121. elseif ($filename_extension == "bmp") { $content_type = "image/bmp"; }
  1122. elseif ($filename_extension == "cdf") { $content_type = "application/x-netcdf"; }
  1123. elseif ($filename_extension == "cgm") { $content_type = "image/cgm"; }
  1124. elseif ($filename_extension == "class") { $content_type = "application/octet-stream"; }
  1125. elseif ($filename_extension == "cpio") { $content_type = "application/x-cpio"; }
  1126. elseif ($filename_extension == "cpt") { $content_type = "application/mac-compactpro"; }
  1127. elseif ($filename_extension == "csh") { $content_type = "application/x-csh"; }
  1128. elseif ($filename_extension == "css") { $content_type = "text/css"; }
  1129. elseif ($filename_extension == "dcr") { $content_type = "application/x-director"; }
  1130. elseif ($filename_extension == "dif") { $content_type = "video/x-dv"; }
  1131. elseif ($filename_extension == "dir") { $content_type = "application/x-director"; }
  1132. elseif ($filename_extension == "djv") { $content_type = "image/vnd.djvu"; }
  1133. elseif ($filename_extension == "djvu") { $content_type = "image/vnd.djvu"; }
  1134. elseif ($filename_extension == "dll") { $content_type = "application/octet-stream"; }
  1135. elseif ($filename_extension == "dmg") { $content_type = "application/octet-stream"; }
  1136. elseif ($filename_extension == "dms") { $content_type = "application/octet-stream"; }
  1137. elseif ($filename_extension == "doc") { $content_type = "application/msword"; }
  1138. elseif ($filename_extension == "dtd") { $content_type = "application/xml-dtd"; }
  1139. elseif ($filename_extension == "dv") { $content_type = "video/x-dv"; }
  1140. elseif ($filename_extension == "dvi") { $content_type = "application/x-dvi"; }
  1141. elseif ($filename_extension == "dxr") { $content_type = "application/x-director"; }
  1142. elseif ($filename_extension == "eps") { $content_type = "application/postscript"; }
  1143. elseif ($filename_extension == "etx") { $content_type = "text/x-setext"; }
  1144. elseif ($filename_extension == "exe") { $content_type = "application/octet-stream"; }
  1145. elseif ($filename_extension == "ez") { $content_type = "application/andrew-inset"; }
  1146. elseif ($filename_extension == "gif") { $content_type = "image/gif"; }
  1147. elseif ($filename_extension == "gram") { $content_type = "application/srgs"; }
  1148. elseif ($filename_extension == "grxml") { $content_type = "application/srgs+xml"; }
  1149. elseif ($filename_extension == "gtar") { $content_type = "application/x-gtar"; }
  1150. elseif ($filename_extension == "hdf") { $content_type = "application/x-hdf"; }
  1151. elseif ($filename_extension == "hqx") { $content_type = "application/mac-binhex40"; }
  1152. elseif ($filename_extension == "htm") { $content_type = "text/html"; }
  1153. elseif ($filename_extension == "html") { $content_type = "text/html"; }
  1154. elseif ($filename_extension == "ice") { $content_type = "x-conference/x-cooltalk"; }
  1155. elseif ($filename_extension == "ico") { $content_type = "image/x-icon"; }
  1156. elseif ($filename_extension == "ics") { $content_type = "text/calendar"; }
  1157. elseif ($filename_extension == "ief") { $content_type = "image/ief"; }
  1158. elseif ($filename_extension == "ifb") { $content_type = "text/calendar"; }
  1159. elseif ($filename_extension == "iges") { $content_type = "model/iges"; }
  1160. elseif ($filename_extension == "igs") { $content_type = "model/iges"; }
  1161. elseif ($filename_extension == "jnlp") { $content_type = "application/x-java-jnlp-file"; }
  1162. elseif ($filename_extension == "jp2") { $content_type = "image/jp2"; }
  1163. elseif ($filename_extension == "jpe") { $content_type = "image/jpeg"; }
  1164. elseif ($filename_extension == "jpeg") { $content_type = "image/jpeg"; }
  1165. elseif ($filename_extension == "jpg") { $content_type = "image/jpeg"; }
  1166. elseif ($filename_extension == "js") { $content_type = "application/x-javascript"; }
  1167. elseif ($filename_extension == "kar") { $content_type = "audio/midi"; }
  1168. elseif ($filename_extension == "latex") { $content_type = "application/x-latex"; }
  1169. elseif ($filename_extension == "lha") { $content_type = "application/octet-stream"; }
  1170. elseif ($filename_extension == "lzh") { $content_type = "application/octet-stream"; }
  1171. elseif ($filename_extension == "m3u") { $content_type = "audio/x-mpegurl"; }
  1172. elseif ($filename_extension == "m4a") { $content_type = "audio/mp4a-latm"; }
  1173. elseif ($filename_extension == "m4b") { $content_type = "audio/mp4a-latm"; }
  1174. elseif ($filename_extension == "m4p") { $content_type = "audio/mp4a-latm"; }
  1175. elseif ($filename_extension == "m4u") { $content_type = "video/vnd.mpegurl"; }
  1176. elseif ($filename_extension == "m4v") { $content_type = "video/x-m4v"; }
  1177. elseif ($filename_extension == "mac") { $content_type = "image/x-macpaint"; }
  1178. elseif ($filename_extension == "man") { $content_type = "application/x-troff-man"; }
  1179. elseif ($filename_extension == "mathml") { $content_type = "application/mathml+xml"; }
  1180. elseif ($filename_extension == "me") { $content_type = "application/x-troff-me"; }
  1181. elseif ($filename_extension == "mesh") { $content_type = "model/mesh"; }
  1182. elseif ($filename_extension == "mid") { $content_type = "audio/midi"; }
  1183. elseif ($filename_extension == "midi") { $content_type = "audio/midi"; }
  1184. elseif ($filename_extension == "mif") { $content_type = "application/vnd.mif"; }
  1185. elseif ($filename_extension == "mov") { $content_type = "video/quicktime"; }
  1186. elseif ($filename_extension == "movie") { $content_type = "video/x-sgi-movie"; }
  1187. elseif ($filename_extension == "mp2") { $content_type = "audio/mpeg"; }
  1188. elseif ($filename_extension == "mp3") { $content_type = "audio/mpeg"; }
  1189. elseif ($filename_extension == "mp4") { $content_type = "video/mp4"; }
  1190. elseif ($filename_extension == "mpe") { $content_type = "video/mpeg"; }
  1191. elseif ($filename_extension == "mpeg") { $content_type = "video/mpeg"; }
  1192. elseif ($filename_extension == "mpg") { $content_type = "video/mpeg"; }
  1193. elseif ($filename_extension == "mpga") { $content_type = "audio/mpeg"; }
  1194. elseif ($filename_extension == "ms") { $content_type = "application/x-troff-ms"; }
  1195. elseif ($filename_extension == "msh") { $content_type = "model/mesh"; }
  1196. elseif ($filename_extension == "mxu") { $content_type = "video/vnd.mpegurl"; }
  1197. elseif ($filename_extension == "nc") { $content_type = "application/x-netcdf"; }
  1198. elseif ($filename_extension == "oda") { $content_type = "application/oda"; }
  1199. elseif ($filename_extension == "ogg") { $content_type = "application/ogg"; }
  1200. elseif ($filename_extension == "pbm") { $content_type = "image/x-portable-bitmap"; }
  1201. elseif ($filename_extension == "pct") { $content_type = "image/pict"; }
  1202. elseif ($filename_extension == "pdb") { $content_type = "chemical/x-pdb"; }
  1203. elseif ($filename_extension == "pdf") { $content_type = "application/pdf"; }
  1204. elseif ($filename_extension == "pgm") { $content_type = "image/x-portable-graymap"; }
  1205. elseif ($filename_extension == "pgn") { $content_type = "application/x-chess-pgn"; }
  1206. elseif ($filename_extension == "pic") { $content_type = "image/pict"; }
  1207. elseif ($filename_extension == "pict") { $content_type = "image/pict"; }
  1208. elseif ($filename_extension == "png") { $content_type = "image/png"; }
  1209. elseif ($filename_extension == "pnm") { $content_type = "image/x-portable-anymap"; }
  1210. elseif ($filename_extension == "pnt") { $content_type = "image/x-macpaint"; }
  1211. elseif ($filename_extension == "pntg") { $content_type = "image/x-macpaint"; }
  1212. elseif ($filename_extension == "ppm") { $content_type = "image/x-portable-pixmap"; }
  1213. elseif ($filename_extension == "ppt") { $content_type = "application/vnd.ms-powerpoint"; }
  1214. elseif ($filename_extension == "ps") { $content_type = "application/postscript"; }
  1215. elseif ($filename_extension == "qt") { $content_type = "video/quicktime"; }
  1216. elseif ($filename_extension == "qti") { $content_type = "image/x-quicktime"; }
  1217. elseif ($filename_extension == "qtif") { $content_type = "image/x-quicktime"; }
  1218. elseif ($filename_extension == "ra") { $content_type = "audio/x-pn-realaudio"; }
  1219. elseif ($filename_extension == "ram") { $content_type = "audio/x-pn-realaudio"; }
  1220. elseif ($filename_extension == "ras") { $content_type = "image/x-cmu-raster"; }
  1221. elseif ($filename_extension == "rdf") { $content_type = "application/rdf+xml"; }
  1222. elseif ($filename_extension == "rgb") { $content_type = "image/x-rgb"; }
  1223. elseif ($filename_extension == "rm") { $content_type = "application/vnd.rn-realmedia"; }
  1224. elseif ($filename_extension == "roff") { $content_type = "application/x-troff"; }
  1225. elseif ($filename_extension == "rtf") { $content_type = "text/rtf"; }
  1226. elseif ($filename_extension == "rtx") { $content_type = "text/richtext"; }
  1227. elseif ($filename_extension == "sgm") { $content_type = "text/sgml"; }
  1228. elseif ($filename_extension == "sgml") { $content_type = "text/sgml"; }
  1229. elseif ($filename_extension == "sh") { $content_type = "application/x-sh"; }
  1230. elseif ($filename_extension == "shar") { $content_type = "application/x-shar"; }
  1231. elseif ($filename_extension == "silo") { $content_type = "model/mesh"; }
  1232. elseif ($filename_extension == "sit") { $content_type = "application/x-stuffit"; }
  1233. elseif ($filename_extension == "skd") { $content_type = "application/x-koan"; }
  1234. elseif ($filename_extension == "skm") { $content_type = "application/x-koan"; }
  1235. elseif ($filename_extension == "skp") { $content_type = "application/x-koan"; }
  1236. elseif ($filename_extension == "skt") { $content_type = "application/x-koan"; }
  1237. elseif ($filename_extension == "smi") { $content_type = "application/smil"; }
  1238. elseif ($filename_extension == "smil") { $content_type = "application/smil"; }
  1239. elseif ($filename_extension == "snd") { $content_type = "audio/basic"; }
  1240. elseif ($filename_extension == "so") { $content_type = "application/octet-stream"; }
  1241. elseif ($filename_extension == "spl") { $content_type = "application/x-futuresplash"; }
  1242. elseif ($filename_extension == "src") { $content_type = "application/x-wais-source"; }
  1243. elseif ($filename_extension == "sv4cpio") { $content_type = "application/x-sv4cpio"; }
  1244. elseif ($filename_extension == "sv4crc") { $content_type = "application/x-sv4crc"; }
  1245. elseif ($filename_extension == "svg") { $content_type = "image/svg+xml"; }
  1246. elseif ($filename_extension == "swf") { $content_type = "application/x-shockwave-flash"; }
  1247. elseif ($filename_extension == "t") { $content_type = "application/x-troff"; }
  1248. elseif ($filename_extension == "tar") { $content_type = "application/x-tar"; }
  1249. elseif ($filename_extension == "tcl") { $content_type = "application/x-tcl"; }
  1250. elseif ($filename_extension == "tex") { $content_type = "application/x-tex"; }
  1251. elseif ($filename_extension == "texi") { $content_type = "application/x-texinfo"; }
  1252. elseif ($filename_extension == "texinfo") { $content_type = "application/x-texinfo"; }
  1253. elseif ($filename_extension == "tif") { $content_type = "image/tiff"; }
  1254. elseif ($filename_extension == "tiff") { $content_type = "image/tiff"; }
  1255. elseif ($filename_extension == "tr") { $content_type = "application/x-troff"; }
  1256. elseif ($filename_extension == "tsv") { $content_type = "text/tab-separated-values"; }
  1257. elseif ($filename_extension == "txt") { $content_type = "text/plain"; }
  1258. elseif ($filename_extension == "ustar") { $content_type = "application/x-ustar"; }
  1259. elseif ($filename_extension == "vcd") { $content_type = "application/x-cdlink"; }
  1260. elseif ($filename_extension == "vrml") { $content_type = "model/vrml"; }
  1261. elseif ($filename_extension == "vxml") { $content_type = "application/voicexml+xml"; }
  1262. elseif ($filename_extension == "wav") { $content_type = "audio/x-wav"; }
  1263. elseif ($filename_extension == "wbmp") { $content_type = "image/vnd.wap.wbmp"; }
  1264. elseif ($filename_extension == "wbmxl") { $content_type = "application/vnd.wap.wbxml"; }
  1265. elseif ($filename_extension == "wml") { $content_type = "text/vnd.wap.wml"; }
  1266. elseif ($filename_extension == "wmlc") { $content_type = "application/vnd.wap.wmlc"; }
  1267. elseif ($filename_extension == "wmls") { $content_type = "text/vnd.wap.wmlscript"; }
  1268. elseif ($filename_extension == "wmlsc") { $content_type = "application/vnd.wap.wmlscriptc"; }
  1269. elseif ($filename_extension == "wrl") { $content_type = "model/vrml"; }
  1270. elseif ($filename_extension == "xbm") { $content_type = "image/x-xbitmap"; }
  1271. elseif ($filename_extension == "xht") { $content_type = "application/xhtml+xml"; }
  1272. elseif ($filename_extension == "xhtml") { $content_type = "application/xhtml+xml"; }
  1273. elseif ($filename_extension == "xls") { $content_type = "application/vnd.ms-excel"; }
  1274. elseif ($filename_extension == "xml") { $content_type = "application/xml"; }
  1275. elseif ($filename_extension == "xpm") { $content_type = "image/x-xpixmap"; }
  1276. elseif ($filename_extension == "xsl") { $content_type = "application/xml"; }
  1277. elseif ($filename_extension == "xslt") { $content_type = "application/xslt+xml"; }
  1278. elseif ($filename_extension == "xul") { $content_type = "application/vnd.mozilla.xul+xml"; }
  1279. elseif ($filename_extension == "xwd") { $content_type = "image/x-xwindowdump"; }
  1280. elseif ($filename_extension == "xyz") { $content_type = "chemical/x-xyz"; }
  1281. elseif ($filename_extension == "zip") { $content_type = "application/zip"; }
  1282. else { $content_type = "application/octet-stream"; }
  1283. return $content_type;
  1284. }
  1285. // ** **
  1286. // ** **
  1287. // **************************************************************************************
  1288. // **************************************************************************************
  1289. // **************************************************************************************
  1290. // **************************************************************************************
  1291. // ** **
  1292. // ** **
  1293. function ftp_downloadfile($directory, $entry) {
  1294. // -------------------------------------------------------------------------
  1295. // Global variables
  1296. // -------------------------------------------------------------------------
  1297. global $net2ftp_globals, $net2ftp_result, $net2ftp_settings;
  1298. // -------------------------------------------------------------------------
  1299. // Get the file from the FTP server to the web server
  1300. // -------------------------------------------------------------------------
  1301. // Open connection
  1302. $conn_id = ftp_openconnection();
  1303. if ($net2ftp_result["success"] == false) { return false; }
  1304. // Check if the filesize is smaller than the allowed filesize
  1305. // $ftp_size_result = ftp_size($conn_id, "$directory/$entry");
  1306. // if ($ftp_size_result > $net2ftp_settings["max_filesize"]) {
  1307. // $errormessage = __("The file is too big to be transferred");
  1308. // setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1309. // return false;
  1310. // }
  1311. // FTP mode
  1312. $ftpmode = ftpAsciiBinary($entry);
  1313. // Temporary filename
  1314. $tempfilename = tempnam($net2ftp_globals["application_tempdir"], "downl__");
  1315. if ($tempfilename == false) {
  1316. @unlink($tempfilename);
  1317. $errormessage = __("Unable to create the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]);
  1318. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1319. return false;
  1320. }
  1321. registerTempfile("register", $tempfilename);
  1322. // Get the file
  1323. // ftp_getfile($conn_id, $localtargetdir, $localtargetfile, $remotesourcedir, $remotesourcefile, $ftpmode, $copymove)
  1324. ftp_getfile($conn_id, "", $tempfilename, $directory, $entry, $ftpmode, "copy");
  1325. if ($net2ftp_result["success"] == false) {
  1326. @unlink($tempfilename);
  1327. $errormessage = __("Unable to get the file <b>%1\$s</b> from the FTP server and to save it as temporary file <b>%2\$s</b>.<br />Check the permissions of the %3\$s directory.<br />", $entry, $tempfilename, $net2ftp_globals["application_tempdir"]);
  1328. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1329. return false;
  1330. }
  1331. // Close connection
  1332. ftp_closeconnection($conn_id);
  1333. // -------------------------------------------------------------------------
  1334. // Transfer temp file to browser
  1335. // -------------------------------------------------------------------------
  1336. // Send the download headers - this function is in httpheaders.inc.php
  1337. sendDownloadHeaders($entry, filesize($tempfilename));
  1338. // --------------------
  1339. // Open file
  1340. // --------------------
  1341. // From the PHP manual:
  1342. // Note: The mode may contain the letter 'b'.
  1343. // This is useful only on systems which differentiate between binary and text
  1344. // files (i.e. Windows. It's useless on Unix). If not needed, this will be
  1345. // ignored. You are encouraged to include the 'b' flag in order to make your scripts
  1346. // more portable.
  1347. // Thanks to Malte for bringing this to my attention !
  1348. registerTempfile("register", $tempfilename);
  1349. $handle = fopen($tempfilename , "rb");
  1350. if ($handle == false) {
  1351. @unlink($tempfilename);
  1352. $errormessage = __("Unable to open the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]);
  1353. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1354. return false;
  1355. }
  1356. // --------------------
  1357. // Send file to browser
  1358. // --------------------
  1359. // Old method: fpassthru. Avoid using fpassthru, as it reads the entire file into memory!
  1360. // $success1 = fpassthru($handle);
  1361. // if ($success1 == false) {
  1362. // @fclose($handle);
  1363. // @unlink($tempfilename);
  1364. // $errormessage = __("Unable to send the file to the browser");
  1365. // setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1366. // return false;
  1367. // }
  1368. // New method: read the file piece by piece and send it to the browser.
  1369. while(!feof($handle)) {
  1370. $buffer = fread($handle, 2048);
  1371. echo $buffer;
  1372. }
  1373. // --------------------
  1374. // Close file
  1375. // --------------------
  1376. $success2 = @fclose($handle);
  1377. // --------------------
  1378. // Delete the temporary file
  1379. // --------------------
  1380. $success3 = @unlink($tempfilename);
  1381. if ($success3 == false) {
  1382. $errormessage = __("Unable to delete the temporary file");
  1383. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1384. return false;
  1385. }
  1386. registerTempfile("unregister", $tempfilename);
  1387. } // End function ftp_downloadfile
  1388. // ** **
  1389. // ** **
  1390. // **************************************************************************************
  1391. // **************************************************************************************
  1392. // **************************************************************************************
  1393. // **************************************************************************************
  1394. // ** **
  1395. // ** **
  1396. function ftp_zip($conn_id, $directory, $list, $zipactions, $zipdir, $divelevel) {
  1397. // --------------
  1398. // This function allows to download/save/email a zipfile which contains the selected directories and files
  1399. // --------------
  1400. // -------------------------------------------------------------------------
  1401. // Global variables
  1402. // -------------------------------------------------------------------------
  1403. global $net2ftp_globals, $net2ftp_settings, $net2ftp_result, $net2ftp_output;
  1404. // -------------------------------------------------------------------------
  1405. // Initialization
  1406. // -------------------------------------------------------------------------
  1407. if ($divelevel == 0) {
  1408. // Create the zipfile
  1409. $net2ftp_globals["zipfile"] = new zipfile();
  1410. $timenow = time();
  1411. $zipdir = "";
  1412. // Open the connection
  1413. $conn_id = ftp_openconnection();
  1414. if ($net2ftp_result["success"] == false) { return false; }
  1415. }
  1416. // -------------------------------------------------------------------------
  1417. // For all directories...
  1418. // -------------------------------------------------------------------------
  1419. for ($i=1; $i<=$list["stats"]["directories"]["total_number"]; $i=$i+1) {
  1420. $newdir = glueDirectories($directory, $list["directories"][$i]["dirfilename"]);
  1421. $newzipdir = glueDirectories($zipdir, $list["directories"][$i]["dirfilename"]);
  1422. $newdivelevel = $divelevel + 1;
  1423. // Check if the directory contains a banned keyword
  1424. if ($list["directories"][$i]["selectable"] == "banned_keyword") { continue; }
  1425. // Get a new list
  1426. $newlist = ftp_getlist($conn_id, $newdir);
  1427. if ($net2ftp_result["success"] == false) { return false; }
  1428. ftp_zip($conn_id, $newdir, $newlist, $zipactions, $newzipdir, $newdivelevel);
  1429. if ($net2ftp_result["success"] == false) { setErrorVars(true, "", "", "", ""); continue; }
  1430. if ($divelevel == 0 && ($zipactions["save"] == "yes" || $zipactions["email"] == "yes")) {
  1431. $total = $list["stats"]["directories"]["total_number"] + $list["stats"]["files"]["total_number"];
  1432. setStatus($i, $total, __("Processing the entries"));
  1433. }
  1434. } // end for directories
  1435. // -------------------------------------------------------------------------
  1436. // For all files...
  1437. // -------------------------------------------------------------------------
  1438. for ($i=1; $i<=$list["stats"]["files"]["total_number"]; $i=$i+1) {
  1439. if ($list["files"][$i]["selectable"] != "ok") { continue; }
  1440. $text = ftp_readfile($conn_id, $directory, $list["files"][$i]["dirfilename"]);
  1441. if ($net2ftp_result["success"] == false) { setErrorVars(true, "", "", "", ""); continue; }
  1442. $filename = stripDirectory(glueDirectories($zipdir, $list["files"][$i]["dirfilename"]));
  1443. $net2ftp_globals["zipfile"]->addFile($text, $filename);
  1444. if ($divelevel == 0 && ($zipactions["save"] == "yes" || $zipactions["email"] == "yes")) {
  1445. $total = $list["stats"]["directories"]["total_number"] + $list["stats"]["files"]["total_number"];
  1446. setStatus($list["stats"]["directories"]["total_number"] + $i - 1, $total, __("Processing the entries"));
  1447. }
  1448. } // end for files
  1449. // -------------------------------------------------------------------------
  1450. // End
  1451. // -------------------------------------------------------------------------
  1452. if ($divelevel == 0) {
  1453. // ------------------------
  1454. // Send the zipfile to the browser
  1455. // ------------------------
  1456. if ($zipactions["download"] == "yes") {
  1457. $timenow = time();
  1458. $filenameToSend = "net2ftp-" . $timenow . ".zip";
  1459. $filesizeToSend = strlen($net2ftp_globals["zipfile"]->file());
  1460. sendDownloadHeaders($filenameToSend, $filesizeToSend);
  1461. echo $net2ftp_globals["zipfile"]->file();
  1462. flush();
  1463. }
  1464. // ------------------------
  1465. // Save the zipfile string to a file
  1466. // ------------------------
  1467. if ($zipactions["save"] == "yes" || $zipactions["email"] == "yes") {
  1468. $string = $net2ftp_globals["zipfile"]->file();
  1469. $tempfilename = tempnam($net2ftp_globals["application_tempdir"], "zip__");
  1470. if ($tempfilename == false) {
  1471. @unlink($tempfilename);
  1472. $errormessage = __("Unable to create the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]);
  1473. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1474. return false;
  1475. }
  1476. registerTempfile("register", $tempfilename);
  1477. local_writefile($tempfilename, $string);
  1478. if ($net2ftp_result["success"] == false) { return false; }
  1479. }
  1480. // ------------------------
  1481. // Save the zip file to the FTP server
  1482. // ------------------------
  1483. if ($zipactions["save"] == "yes") {
  1484. ftp_putfile($conn_id, "", $tempfilename, $directory, $zipactions["save_filename"], FTP_BINARY, "copy");
  1485. if ($net2ftp_result["success"] == false) {
  1486. @unlink($tempfilename);
  1487. // $errormessage = __("Unable to put the file <b>%1\$s</b> on the FTP server.<br />You may not have write permissions on the directory.", $zipactions["save_filename"]);
  1488. // setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1489. return false;
  1490. }
  1491. else { $net2ftp_output["ftp_zip"][] = __("The zip file has been saved on the FTP server as <b>%1\$s</b>", $zipactions["save_filename"]) . "<br /><br />\n"; }
  1492. }
  1493. // ------------------------
  1494. // Close the connection
  1495. // ------------------------
  1496. ftp_closeconnection($conn_id);
  1497. // ------------------------
  1498. // Email
  1499. // ------------------------
  1500. if ($zipactions["email"] == "yes") {
  1501. $FromName = "net2ftp";
  1502. $From = $net2ftp_settings["email_feedback"];
  1503. $ToName = "";
  1504. $To = $zipactions["email_to"];
  1505. $Subject = __("Requested files");
  1506. // Email message
  1507. $Text = __("Dear,") . "\n\n";
  1508. $Text .= __("Someone has requested the files in attachment to be sent to this email account (%1\$s).", $To) . "\n";
  1509. $Text .= __("If you know nothing about this or if you don't trust that person, please delete this email without opening the Zip file in attachment.") . "\n";
  1510. $Text .= __("Note that if you don't open the Zip file, the files inside cannot harm your computer.") . "\n";
  1511. $Text .= "\n\n---------------------------------------\n";
  1512. $Text .= __("Information about the sender: ") . "\n";
  1513. $Text .= __("IP address: ") . $REMOTE_ADDR . "\n";
  1514. $Text .= __("Time of sending: ") . mytime() . "\n";
  1515. $Text .= __("Sent via the net2ftp application installed on this website: ") . $HTTP_REFERER . "\n";
  1516. $Text .= __("Webmaster's email: ") . $From . "\n";
  1517. $Text .= "\n\n---------------------------------------\n";
  1518. $Text .= __("Message of the sender: ") . "\n";
  1519. $Text .= $zipactions["message"] . "\n";
  1520. $Text .= "\n\n---------------------------------------\n";
  1521. $Text .= __("net2ftp is free software, released under the GNU/GPL license. For more information, go to http://www.net2ftp.com.") . "\n\n\n";
  1522. $AttmFiles = array($tempfilename);
  1523. SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles);
  1524. if ($net2ftp_result["success"] == false) {
  1525. @unlink($tempfilename);
  1526. return false;
  1527. }
  1528. $net2ftp_output["ftp_zip"][] = __("The zip file has been sent to <b>%1\$s</b>.", $To) . "<br /><br />";
  1529. }
  1530. // ------------------------
  1531. // Delete the temporary zipfile
  1532. // ------------------------
  1533. if ($zipactions["save"] == "yes" || $zipactions["email"] == "yes") {
  1534. $success4 = @unlink($tempfilename);
  1535. if ($success4 == false) {
  1536. $errormessage = __("Unable to delete the temporary file");
  1537. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1538. return false;
  1539. }
  1540. registerTempfile("unregister", $tempfilename);
  1541. }
  1542. // Set the variable to NULL to save memory
  1543. $net2ftp_globals["zipfile"] = NULL;
  1544. } // end if $divelevel == 0
  1545. } // End function ftp_zip
  1546. // ** **
  1547. // ** **
  1548. // **************************************************************************************
  1549. // **************************************************************************************
  1550. // **************************************************************************************
  1551. // **************************************************************************************
  1552. // ** **
  1553. // ** **
  1554. function acceptFiles($uploadedFilesArray) {
  1555. // --------------
  1556. // This PHP function takes files that were just uploaded with HTTP POST,
  1557. // verifies if the size is smaller than a certain value, and moves them
  1558. // using move_uploaded_file() from the server's temporary directory to
  1559. // net2ftp's temporary directory
  1560. //
  1561. // $uploadedFilesArray[number]["name"] and $acceptedFilesArray[number]["name"] contain the real name of the file
  1562. // $uploadedFilesArray[number]["tmp_name"] contains the temporary name of the file in the *webserver's* temporary directory (eg C:\temp)
  1563. // $acceptedFilesArray[number]["tmp_name"] contains the temporary name of the file in *net2ftp's* temporary directory (eg C:\web\net2ftp\temp)
  1564. //
  1565. // Note 1 - $acceptedFilesArray[number]["tmp_name"] may not be the same as $uploadedFilesArray[number]["tmp_name"] because
  1566. // $acceptedFilesArray[number]["tmp_name"] should be unique at the moment the file is transferred to the new directory.
  1567. // Note 2 - $acceptedFilesArray[number]["tmp_name"]
  1568. // - starts with upload (or upl on Windows, because on that platform only the first 3 letters are kept)
  1569. // - has the same filename extension as the real filename
  1570. // - ends with .txt
  1571. // The filename extension is needed by the PCL TAR library, which needs to determine if the archive is tar, tgz or gz.
  1572. // The additional .txt is to ensure that no temporary file would be executed on the web server, which could compromise it.
  1573. //
  1574. // For example: script.php is uploaded to the web server's temporary directory C:\temp\f9skpqri
  1575. // Then it is moved to net2ftp's temporary directory C:\web\net2ftp\temp\upload9oeic.php.txt
  1576. // And finally it is transferred to the FTP server as script.php in functions ftp_transferfiles() and ftp_unziptransferfiles() -- see below
  1577. // --------------
  1578. // -------------------------------------------------------------------------
  1579. // Global variables
  1580. // -------------------------------------------------------------------------
  1581. global $net2ftp_globals, $net2ftp_settings, $net2ftp_output;
  1582. $max_filesize = $net2ftp_settings["max_filesize"];
  1583. $skipped = 0; // Index of the files which are too big / contain a banned keyword
  1584. $moved_ok = 0; // Index of the files that have been treated successfully
  1585. $moved_notok = 0; // Index of the files that have been treated unsuccessfully
  1586. for ($i=1; $i<=sizeof($uploadedFilesArray); $i++) {
  1587. // -------------------------------------------------------------------------
  1588. // 1 -- Get the data from the filesArray (for each file, its location, name, size, ftpmode
  1589. // -------------------------------------------------------------------------
  1590. $file_name = $uploadedFilesArray["$i"]["name"];
  1591. $file_tmp_name = $uploadedFilesArray["$i"]["tmp_name"];
  1592. $file_size = $uploadedFilesArray["$i"]["size"];
  1593. if (($file_name != "" && $file_tmp_name == "") || $file_size > $max_filesize) {
  1594. // The case ($file_name != "" && $file_tmp_name == "") occurs when the file is bigger than the directives set in php.ini
  1595. // In that case, only $uploadedFilesArray["$i"]["name"] is filled in.
  1596. $net2ftp_output["acceptFiles"][] = __("File <b>%1\$s</b> is too big. This file will not be uploaded.", $file_name);
  1597. $skipped = $skipped + 1;
  1598. @unlink($file_tmp_name);
  1599. continue;
  1600. }
  1601. elseif (checkAuthorizedName($file_name) == false) {
  1602. $net2ftp_output["acceptFiles"][] = __("File <b>%1\$s</b> is contains a banned keyword. This file will not be uploaded.", $file_name);
  1603. $skipped = $skipped + 1;
  1604. @unlink($file_tmp_name);
  1605. continue;
  1606. }
  1607. // -------------------------------------------------------------------------
  1608. // 3 -- upload and copy the file; if a file with the same name already exists, it is overwritten with the new file
  1609. // -------------------------------------------------------------------------
  1610. $extension = get_filename_extension($file_name);
  1611. if (substr($file_name, -6) == "tar.gz") { $extension = "tar.gz"; }
  1612. $tempfilename = tempnam2($net2ftp_globals["application_tempdir"], "upload__", "." . $extension . ".txt");
  1613. if ($tempfilename == false) {
  1614. @unlink($tempfilename);
  1615. $errormessage = __("Could not generate a temporary file.");
  1616. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1617. return false;
  1618. }
  1619. $success2 = move_uploaded_file($file_tmp_name, $tempfilename);
  1620. if ($success2 == false) {
  1621. $net2ftp_output["acceptFiles"][] = __("File <b>%1\$s</b> could not be moved", $file_name);
  1622. @unlink($file_tmp_name);
  1623. @unlink($tempfilename);
  1624. $moved_notok = $moved_notok + 1;
  1625. continue;
  1626. }
  1627. // -------------------------------------------------------------------------
  1628. // 4 -- if everything went fine, put file in acceptedFilesArray
  1629. // -------------------------------------------------------------------------
  1630. else {
  1631. // When uploading files, print some output
  1632. // When updating files, do not print anything
  1633. registerTempfile("register", $tempfilename);
  1634. if ($net2ftp_globals["state"] == "upload") {
  1635. $net2ftp_output["acceptFiles"][] = __("File <b>%1\$s</b> is OK", $file_name);
  1636. }
  1637. $moved_ok = $moved_ok + 1;
  1638. $acceptedFilesArray[$moved_ok]["name"] = $file_name;
  1639. $acceptedFilesArray[$moved_ok]["tmp_name"] = $tempfilename;
  1640. }
  1641. } // End for
  1642. if ($moved_notok > 0) {
  1643. $errormessage = __("Unable to move the uploaded file to the temp directory.<br /><br />The administrator of this website has to <b>chmod 777</b> the /temp directory of net2ftp.");
  1644. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1645. return false;
  1646. }
  1647. elseif ($moved_ok == 0 && $skipped == 0) {
  1648. $errormessage = __("You did not provide any file to upload.");
  1649. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1650. return false;
  1651. }
  1652. elseif ($moved_ok == 0 && $skipped > 0) {
  1653. return "all_uploaded_files_are_too_big";
  1654. }
  1655. else {
  1656. return $acceptedFilesArray;
  1657. }
  1658. } // End function acceptFiles
  1659. // ** **
  1660. // ** **
  1661. // **************************************************************************************
  1662. // **************************************************************************************
  1663. // **************************************************************************************
  1664. // **************************************************************************************
  1665. // ** **
  1666. // ** **
  1667. function ftp_transferfiles($filesArray, $targetDir) {
  1668. // --------------
  1669. // This PHP function takes a file that was uploaded from a client computer via a browser to the web server,
  1670. // and puts it on another FTP server
  1671. // --------------
  1672. // -------------------------------------------------------------------------
  1673. // Global variables
  1674. // -------------------------------------------------------------------------
  1675. global $net2ftp_globals, $net2ftp_result, $net2ftp_output;
  1676. // ------------------------------
  1677. // Open connection
  1678. // ------------------------------
  1679. $conn_id = ftp_openconnection();
  1680. if ($net2ftp_result["success"] == false) {
  1681. for ($i=1; $i<=sizeof($filesArray); $i++) { @unlink($filesArray[$i]["tmp_name"]); }
  1682. return false;
  1683. }
  1684. // ------------------------------
  1685. // For loop
  1686. // ------------------------------
  1687. for ($i=1; $i<=sizeof($filesArray); $i++) {
  1688. // Set status
  1689. setStatus($i, sizeof($filesArray), __("Transferring files to the FTP server"));
  1690. // Determine which FTP mode should be used
  1691. $ftpmode = ftpAsciiBinary($filesArray[$i]["name"]);
  1692. if ($ftpmode == FTP_ASCII) { $printftpmode = "FTP_ASCII"; }
  1693. elseif ($ftpmode == FTP_BINARY) { $printftpmode = "FTP_BINARY"; }
  1694. // Put files
  1695. ftp_putfile($conn_id, "", $filesArray[$i]["tmp_name"], $targetDir, $filesArray[$i]["name"], $ftpmode, "move");
  1696. if ($net2ftp_result["success"] == false) {
  1697. setErrorVars(true, "", "", "", "");
  1698. @unlink($filesArray[$i]["tmp_name"]);
  1699. $net2ftp_output["ftp_transferfiles"][] = __("File <b>%1\$s</b> could not be transferred to the FTP server", $filesArray[$i]["name"]);
  1700. continue;
  1701. }
  1702. $net2ftp_output["ftp_transferfiles"][] = __("File <b>%1\$s</b> has been transferred to the FTP server using FTP mode <b>%2\$s</b>", $filesArray[$i]["name"], $printftpmode);
  1703. } // End for
  1704. // ------------------------------
  1705. // Close connection
  1706. // ------------------------------
  1707. ftp_closeconnection($conn_id);
  1708. } // End function ftp_transferfiles
  1709. // ** **
  1710. // ** **
  1711. // **************************************************************************************
  1712. // **************************************************************************************
  1713. // **************************************************************************************
  1714. // **************************************************************************************
  1715. // ** **
  1716. // ** **
  1717. function ftp_unziptransferfiles($archivesArray) {
  1718. // --------------
  1719. // Extract the directories and files from the archive to a temporary directory on the web server, and
  1720. // then create the directories and put the files on the FTP server
  1721. // --------------
  1722. // -------------------------------------------------------------------------
  1723. // Global variables
  1724. // -------------------------------------------------------------------------
  1725. global $net2ftp_globals, $net2ftp_result, $net2ftp_output;
  1726. // -------------------------------------------------------------------------
  1727. // Open connection
  1728. // -------------------------------------------------------------------------
  1729. $conn_id = ftp_openconnection();
  1730. if ($net2ftp_result["success"] == false) {
  1731. for ($archive_nr=1; $archive_nr<=sizeof($archivesArray); $archive_nr++) { @unlink($archivesArray[$archive_nr]["tmp_name"]); }
  1732. return false;
  1733. }
  1734. // -------------------------------------------------------------------------
  1735. // For each archive...
  1736. // -------------------------------------------------------------------------
  1737. for ($archive_nr=1; $archive_nr<=sizeof($archivesArray); $archive_nr++) {
  1738. // Set status
  1739. setStatus($archive_nr, sizeof($archivesArray), __("Decompressing archives and transferring files"));
  1740. // -------------------------------------------------------------------------
  1741. // Determine the type of archive depending on the filename extension
  1742. // -------------------------------------------------------------------------
  1743. $archive_name = $archivesArray[$archive_nr]["name"];
  1744. $archive_file = $archivesArray[$archive_nr]["tmp_name"];
  1745. $archivename_without_dottext = substr($archivesArray[$archive_nr]["tmp_name"], 0, strlen($archive)-4);
  1746. $archive_type = get_filename_extension($archivename_without_dottext);
  1747. $net2ftp_output["ftp_unziptransferfiles"][] = __("Processing archive nr %1\$s: <b>%2\$s</b>", $archive_nr, $archive_name);
  1748. $net2ftp_output["ftp_unziptransferfiles"][] = "<ul>";
  1749. if ($archive_type != "zip" && $archive_type != "tar" && $archive_type != "tgz" && $archive_type != "gz") {
  1750. $net2ftp_output["ftp_unziptransferfiles"][] = __("Archive <b>%1\$s</b> was not processed because its filename extension was not recognized. Only zip, tar, tgz and gz archives are supported at the moment.", $archive_name);
  1751. continue;
  1752. }
  1753. // -------------------------------------------------------------------------
  1754. // Extract directories and files
  1755. // -------------------------------------------------------------------------
  1756. // ------------------------------
  1757. // Check list of files to see if there are any malicious filenames
  1758. // ------------------------------
  1759. if ($archive_type == "zip") {
  1760. $zip = new PclZip($archive_file);
  1761. $list_to_check = $zip->listContent();
  1762. }
  1763. elseif ($archive_type == "tar" || $archive_type == "tgz" || $archive_type == "gz") {
  1764. $list_to_check = PclTarList($archive_file);
  1765. }
  1766. if ($list_to_check <= 0) {
  1767. $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to extract the files and directories from the archive");
  1768. continue;
  1769. }
  1770. for ($i=0; $i<sizeof($list_to_check); $i++) {
  1771. $source = trim($list_to_check[$i]["filename"]);
  1772. if (strpos($source, "../") !== false || strpos($source, "..\\") !== false) {
  1773. $errormessage = __("Archive contains filenames with ../ or ..\\ - aborting the extraction");
  1774. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1775. return false;
  1776. }
  1777. }
  1778. // ------------------------------
  1779. // Generate random directory
  1780. // ------------------------------
  1781. $tempdir = tempdir2($net2ftp_globals["application_tempdir"], "unzip__", "");
  1782. if ($net2ftp_result["success"] == false) { return false; }
  1783. registerTempfile("register", "$tempdir");
  1784. // ------------------------------
  1785. // Extract
  1786. // ------------------------------
  1787. if ($archive_type == "zip") {
  1788. $zip = new PclZip($archive_file);
  1789. $list = $zip->extract($p_path = $tempdir);
  1790. }
  1791. elseif ($archive_type == "tar" || $archive_type == "tgz" || $archive_type == "gz") {
  1792. $list = PclTarExtract($archive_file, $tempdir);
  1793. }
  1794. // This code is not needed any more - see above: if ($list_to_check <= 0)
  1795. if ($list <= 0) {
  1796. // $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to extract the files and directories from the archive");
  1797. continue;
  1798. }
  1799. // ------------------------------
  1800. // Create the directories and put the files on the FTP server
  1801. // ------------------------------
  1802. for ($i=0; $i<sizeof($list); $i++) {
  1803. $source = trim($list[$i]["filename"]);
  1804. $unzip_status = trim($list[$i]["status"]);
  1805. $target_relative = substr($source, strlen($tempdir));
  1806. $target = $net2ftp_globals["directory"] . $target_relative;
  1807. $ftpmode = ftpAsciiBinary($source);
  1808. if ($unzip_status != "ok") {
  1809. $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not unzip entry %1\$s (error code %2\$s)", $target_relative, $unzip_status);
  1810. setErrorVars(true, "", "", "", "");
  1811. continue;
  1812. }
  1813. // Directory entry in the archive: create the directory
  1814. if (is_dir($source) == true) {
  1815. ftp_newdirectory($conn_id, $target);
  1816. if ($net2ftp_result["success"] == true) {
  1817. $net2ftp_output["ftp_unziptransferfiles"][] = __("Created directory %1\$s", $target);
  1818. }
  1819. else {
  1820. $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not create directory %1\$s", $target);
  1821. setErrorVars(true, "", "", "", "");
  1822. }
  1823. } // end if directory
  1824. // File entry in the archive: put the file
  1825. // If this fails, create the required directories and try again
  1826. elseif (is_file($source) == true) {
  1827. ftp_putfile($conn_id, dirname($source), basename($source), dirname($target), basename($target), $ftpmode, "move");
  1828. if ($net2ftp_result["success"] == true) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Copied file %1\$s", $target); }
  1829. else {
  1830. setErrorVars(true, "", "", "", "");
  1831. $target_relative_parts = explode("/", str_replace("\\", "/", dirname($target_relative)));
  1832. $directory_to_create = $net2ftp_globals["directory"];
  1833. for ($j=0; $j<sizeof($target_relative_parts); $j=$j+1) {
  1834. $directory_to_create = $directory_to_create . "/" . $target_relative_parts[$j];
  1835. $ftp_chdir_result = @ftp_chdir($conn_id, $directory_to_create);
  1836. if ($ftp_chdir_result == false) {
  1837. ftp_newdirectory($conn_id, $directory_to_create);
  1838. if ($net2ftp_result["success"] == true) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Created directory %1\$s", $directory_to_create); }
  1839. else { setErrorVars(true, "", "", "", ""); }
  1840. } // end if
  1841. } // end for
  1842. ftp_putfile($conn_id, dirname($source), basename($source), dirname($target), basename($target), $ftpmode, "copy");
  1843. if ($net2ftp_result["success"] == true) { $net2ftp_output["ftp_unziptransferfiles"][] = __("Copied file %1\$s", $target); }
  1844. else {
  1845. setErrorVars(true, "", "", "", "");
  1846. $net2ftp_output["ftp_unziptransferfiles"][] = __("Could not copy file %1\$s", $target);
  1847. }
  1848. }
  1849. } // end elseif file
  1850. } // end for
  1851. // -------------------------------------------------------------------------
  1852. // Delete the uploaded archive and the temporary files
  1853. // -------------------------------------------------------------------------
  1854. // Delete the temporary directory and its contents
  1855. $delete_dirorfile_result = delete_dirorfile($tempdir);
  1856. if ($delete_dirorfile_result == false) {
  1857. $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to delete the temporary directory");
  1858. }
  1859. else {
  1860. registerTempfile("unregister", "$tempdir");
  1861. }
  1862. // Delete the archive
  1863. $unlink_result = @unlink($archive_file);
  1864. if ($unlink_result == false) {
  1865. $net2ftp_output["ftp_unziptransferfiles"][] = __("Unable to delete the temporary file %1\$s", $archive_file);
  1866. }
  1867. else {
  1868. registerTempfile("unregister", "$archive_file");
  1869. }
  1870. $net2ftp_output["ftp_unziptransferfiles"][] = "</ul>";
  1871. } // End for
  1872. // -------------------------------------------------------------------------
  1873. // Close connection
  1874. // -------------------------------------------------------------------------
  1875. ftp_closeconnection($conn_id);
  1876. } // End function ftp_unziptransferfiles
  1877. // ** **
  1878. // ** **
  1879. // **************************************************************************************
  1880. // **************************************************************************************
  1881. // **************************************************************************************
  1882. // **************************************************************************************
  1883. // ** **
  1884. // ** **
  1885. function ftp_mysite($conn_id, $command) {
  1886. // --------------
  1887. // This function sends a site command to the FTP server
  1888. // Note:
  1889. // - These commands vary a lot depending on the FTP server type
  1890. // - PHP does not return any result other than TRUE or FALSE
  1891. // --------------
  1892. $success1 = ftp_site($conn_id, $command);
  1893. if ($success1 == false) {
  1894. $errormessage = __("Unable to execute site command <b>%1\$s</b>", $command);
  1895. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  1896. return false;
  1897. }
  1898. } // End function ftp_mysite
  1899. // ** **
  1900. // ** **
  1901. // **************************************************************************************
  1902. // **************************************************************************************
  1903. // **************************************************************************************
  1904. // **************************************************************************************
  1905. // ** **
  1906. // ** **
  1907. function upDir($directory) {
  1908. // --------------
  1909. // This function takes a directory string and returns the parent directory string
  1910. // --------------
  1911. if ($directory == "" || $directory == "/" || $directory == "\\") { return "/"; }
  1912. $parentdirectory = "";
  1913. $directory = stripDirectory($directory);
  1914. $parts = explode("/", $directory);
  1915. $parentdirectory = "";
  1916. for ($i=0; $i<sizeof($parts)-1; $i++) {
  1917. $parentdirectory = $parentdirectory . "/" . $parts[$i];
  1918. }
  1919. if ($parentdirectory == "") { $parentdirectory = "/"; }
  1920. return $parentdirectory;
  1921. } // End function upDir
  1922. // ** **
  1923. // ** **
  1924. // **************************************************************************************
  1925. // **************************************************************************************
  1926. // **************************************************************************************
  1927. // **************************************************************************************
  1928. // ** **
  1929. // ** **
  1930. function stripDirectory($directory) {
  1931. // --------------
  1932. // Removes a leading and trailing / or \ if there is one
  1933. // --------------
  1934. // Remove leading and trailing whitespaces
  1935. $directory = trim($directory);
  1936. // Replace // by / and replace \\ by \
  1937. $search[0] = "//";
  1938. $replace[0] = "/";
  1939. $search[1] = "\\\\";
  1940. $replace[1] = "\\";
  1941. $search[2] = "/\\";
  1942. $replace[2] = "/";
  1943. $search[3] = "\\/";
  1944. $replace[3] = "/";
  1945. $directory = str_replace($search, $replace, $directory);
  1946. // Check first and last characters
  1947. // Remove leading and trailing / or \ if needed
  1948. $firstchar = substr($directory, 0, 1);
  1949. $lastchar = substr($directory, strlen($directory)-1, 1);
  1950. if ($firstchar == "/" || $firstchar == "\\") { $directory = substr($directory, 1, strlen($directory)-1); }
  1951. if ($lastchar == "/" || $lastchar == "\\") { $directory = substr($directory, 0, strlen($directory)-1); }
  1952. return $directory;
  1953. } // end stripDirectory
  1954. // ** **
  1955. // ** **
  1956. // **************************************************************************************
  1957. // **************************************************************************************
  1958. // **************************************************************************************
  1959. // **************************************************************************************
  1960. // ** **
  1961. // ** **
  1962. function glueDirectories($part1, $part2) {
  1963. // --------------
  1964. // Returns the 2 dirs glued together in the format
  1965. // /home/dh1234/test (leading /, NO trailing /)
  1966. // \\server\web\mysite.com\net2ftp
  1967. // --------------
  1968. // Strip leading and trailing / and \
  1969. // Take Windows shared directory into account \\server\web\mysite.com\net2ftp
  1970. if (substr($part1, 0, 2) == "\\\\") { $part1 = "\\\\" . stripDirectory($part1); }
  1971. else { $part1 = stripDirectory($part1); }
  1972. if (substr($part2, 0, 2) == "\\\\") { $part2 = "\\\\" . stripDirectory($part2); }
  1973. else { $part2 = stripDirectory($part2); }
  1974. // Length
  1975. $part1_len = strlen($part1);
  1976. $part2_len = strlen($part2);
  1977. // Check if Unix or Windows style directories are used
  1978. if ($part1_len > 1 && (substr($part1, 1, 1) == ":" || substr($part1, 0, 2) == "\\\\")) { $system = "windows"; }
  1979. elseif ($part2_len > 1 && (substr($part2, 1, 1) == ":" || substr($part1, 0, 2) == "\\\\")) { $system = "windows"; }
  1980. else { $system = "unix"; }
  1981. // Glue the 2 parts together
  1982. if ($part1_len > 0 && $part2_len > 0) {
  1983. if ($system == "windows") { return $part1 . "\\" . $part2; }
  1984. else { return "/" . $part1 . "/" . $part2; }
  1985. }
  1986. elseif (($part1_len == 0 || $part1 == "/" || $part1 == "\\") && ($part2_len > 0)) {
  1987. if ($system == "windows") { return $part2; }
  1988. else { return "/" . $part2; }
  1989. }
  1990. elseif (($part2_len == 0 || $part2 == "/" || $part2 == "\\") && ($part1_len > 0)) {
  1991. if ($system == "windows") { return $part1; }
  1992. else { return "/" . $part1; }
  1993. }
  1994. else {
  1995. return "";
  1996. }
  1997. } // end glueDirectories
  1998. // ** **
  1999. // ** **
  2000. // **************************************************************************************
  2001. // **************************************************************************************
  2002. // **************************************************************************************
  2003. // **************************************************************************************
  2004. // ** **
  2005. // ** **
  2006. function get_filename_extension($filename) {
  2007. // --------------
  2008. // This function returns the extension of a filename:
  2009. // name.ext1.ext2.ext3 --> ext3
  2010. // name --> name
  2011. // .name --> name
  2012. // .name.ext --> ext
  2013. // It also converts the result to lower case:
  2014. // name.ext1.EXT2 --> ext2
  2015. // --------------
  2016. $lastdotposition = strrpos($filename,".");
  2017. if ($lastdotposition === 0) { $extension = substr($filename, 1); }
  2018. elseif ($lastdotposition == "") { $extension = $filename; }
  2019. else { $extension = substr($filename, $lastdotposition + 1); }
  2020. return strtolower($extension);
  2021. } // End get_filename_extension
  2022. // ** **
  2023. // ** **
  2024. // **************************************************************************************
  2025. // **************************************************************************************
  2026. // **************************************************************************************
  2027. // **************************************************************************************
  2028. // ** **
  2029. // ** **
  2030. function get_filename_name($filename) {
  2031. // --------------
  2032. // This function returns the name part of a filename:
  2033. // name.ext1.ext2.ext3 --> name
  2034. // name --> name
  2035. // .name --> name
  2036. // .name.ext --> name.ext
  2037. // It also converts the result to lower case:
  2038. // NAME.ext --> name
  2039. // --------------
  2040. $firstdotposition = strpos($filename,".");
  2041. if ($firstdotposition === 0) { $name = substr($filename, 1); }
  2042. elseif ($firstdotposition == "") { $name = $filename; }
  2043. else { $name = substr($filename, 0, $firstdotposition); }
  2044. return strtolower($name);
  2045. } // End get_filename_name
  2046. // ** **
  2047. // ** **
  2048. // **************************************************************************************
  2049. // **************************************************************************************
  2050. // **************************************************************************************
  2051. // **************************************************************************************
  2052. // ** **
  2053. // ** **
  2054. function ftpAsciiBinary($filename) {
  2055. // --------------
  2056. // Checks the first character of a file and its extension to see if it should be
  2057. // transferred in ASCII or Binary mode
  2058. // --------------
  2059. // -------------------------------------------------------------------------
  2060. // Global variables
  2061. // -------------------------------------------------------------------------
  2062. global $net2ftp_globals;
  2063. // -------------------------------------------------------------------------
  2064. // If $net2ftp_globals["ftpmode"] == "binary" then return FTP_BINARY
  2065. // -------------------------------------------------------------------------
  2066. if ($net2ftp_globals["ftpmode"] != "automatic") { return FTP_BINARY; }
  2067. // -------------------------------------------------------------------------
  2068. // If $net2ftp_globals["ftpmode"] == "automatic" then return return
  2069. // FTP_ASCII or FTP_BINARY
  2070. // -------------------------------------------------------------------------
  2071. $firstcharacter = substr($filename, 0, 1);
  2072. if ($firstcharacter == ".") {
  2073. $ftpmode = FTP_ASCII;
  2074. return $ftpmode;
  2075. }
  2076. // -------------------------------------------------------------------------
  2077. // If the first character is not a dot, check the extension
  2078. // -------------------------------------------------------------------------
  2079. $last = get_filename_extension($filename);
  2080. if (
  2081. $last == "1st" ||
  2082. $last == "asp" ||
  2083. $last == "bas" ||
  2084. $last == "bat" ||
  2085. $last == "c" ||
  2086. $last == "cfg" ||
  2087. $last == "cfm" ||
  2088. $last == "cgi" ||
  2089. $last == "conf" ||
  2090. $last == "cpp" ||
  2091. $last == "css" ||
  2092. $last == "csv" ||
  2093. $last == "dhtml" ||
  2094. $last == "diz" ||
  2095. $last == "default" ||
  2096. $last == "file" ||
  2097. $last == "h" ||
  2098. $last == "hpp" ||
  2099. $last == "htaccess" ||
  2100. $last == "htpasswd" ||
  2101. $last == "htm" ||
  2102. $last == "html" ||
  2103. $last == "inc" ||
  2104. $last == "ini" ||
  2105. $last == "js" ||
  2106. $last == "jsp" ||
  2107. $last == "log" ||
  2108. $last == "m3u" ||
  2109. $last == "mak" ||
  2110. $last == "msg" ||
  2111. $last == "nfo" ||
  2112. $last == "old" ||
  2113. $last == "pas" ||
  2114. $last == "patch" ||
  2115. $last == "perl" ||
  2116. $last == "php" ||
  2117. $last == "php3" ||
  2118. $last == "phps" ||
  2119. $last == "phtml" ||
  2120. $last == "pinerc" ||
  2121. $last == "pl" ||
  2122. $last == "pm" ||
  2123. $last == "qmail" ||
  2124. $last == "readme" ||
  2125. $last == "setup" ||
  2126. $last == "seq" ||
  2127. $last == "sh" ||
  2128. $last == "sql" ||
  2129. $last == "style" ||
  2130. $last == "tcl" ||
  2131. $last == "tex" ||
  2132. $last == "threads" ||
  2133. $last == "tmpl" ||
  2134. $last == "tpl" ||
  2135. $last == "txt" ||
  2136. $last == "ubb" ||
  2137. $last == "vbs" ||
  2138. $last == "xml" ||
  2139. strstr($last, "htm")
  2140. ) { $ftpmode = FTP_ASCII; }
  2141. else { $ftpmode = FTP_BINARY; }
  2142. return $ftpmode;
  2143. } // end ftpAsciiBinary
  2144. // ** **
  2145. // ** **
  2146. // **************************************************************************************
  2147. // **************************************************************************************
  2148. // **************************************************************************************
  2149. // **************************************************************************************
  2150. // ** **
  2151. // ** **
  2152. function standardize_eol($string) {
  2153. // --------------
  2154. // Input: text with Windows (\r\n), Unix (\n), or weird (\r\r) end-of-line characters
  2155. // Output: text with Unix style end-of-line characters (\n)
  2156. // --------------
  2157. $patterns[0] = "/\\r\\r/"; // this is \r\r
  2158. $patterns[1] = "/\\r\\n/"; // this is \r\n
  2159. $replacements[0] = "\r\n";
  2160. $replacements[1] = "\n";
  2161. $string = preg_replace($patterns, $replacements, $string);
  2162. return $string;
  2163. }
  2164. // ** **
  2165. // ** **
  2166. // **************************************************************************************
  2167. // **************************************************************************************
  2168. // **************************************************************************************
  2169. // **************************************************************************************
  2170. // ** **
  2171. // ** **
  2172. function explode_lines($string) {
  2173. // --------------
  2174. // Input: $string which may have Windows or Unix end-of-line characters
  2175. // Output: $lines array with the lines
  2176. // --------------
  2177. // $string = standardize_eol($string);
  2178. // Add a \n in the beginning of the strings so that the first line of the string would
  2179. // be in the first element of the exploded array
  2180. $lines = explode("\n", "\n" . $string);
  2181. return $lines;
  2182. } // explode_lines
  2183. // ** **
  2184. // ** **
  2185. // **************************************************************************************
  2186. // **************************************************************************************
  2187. // **************************************************************************************
  2188. // **************************************************************************************
  2189. // ** **
  2190. // ** **
  2191. function getFileType($filename) {
  2192. // --------------
  2193. // Checks the extension of a file to determine what should be done with it in the View and Edit functions
  2194. // Default: TEXT
  2195. // Exceptions (see list below): IMAGE, EXECUTABLE, OFFICE, ARCHIVE
  2196. // --------------
  2197. $last = get_filename_extension($filename);
  2198. if (
  2199. $last == "asp" ||
  2200. $last == "bas" ||
  2201. $last == "bat" ||
  2202. $last == "c" ||
  2203. $last == "cfg" ||
  2204. $last == "cfm" ||
  2205. $last == "cgi" ||
  2206. $last == "conf" ||
  2207. $last == "cpp" ||
  2208. $last == "css" ||
  2209. $last == "dhtml" ||
  2210. $last == "diz" ||
  2211. $last == "default" ||
  2212. $last == "file" ||
  2213. $last == "h" ||
  2214. $last == "hpp" ||
  2215. $last == "htaccess" ||
  2216. $last == "htpasswd" ||
  2217. $last == "htm" ||
  2218. $last == "html" ||
  2219. $last == "inc" ||
  2220. $last == "ini" ||
  2221. $last == "js" ||
  2222. $last == "jsp" ||
  2223. $last == "mak" ||
  2224. $last == "msg" ||
  2225. $last == "nfo" ||
  2226. $last == "old" ||
  2227. $last == "pas" ||
  2228. $last == "patch" ||
  2229. $last == "perl" ||
  2230. $last == "php" ||
  2231. $last == "php3" ||
  2232. $last == "phps" ||
  2233. $last == "phtml" ||
  2234. $last == "pinerc" ||
  2235. $last == "pl" ||
  2236. $last == "pm" ||
  2237. $last == "qmail" ||
  2238. $last == "readme" ||
  2239. $last == "setup" ||
  2240. $last == "sh" ||
  2241. $last == "shtml" ||
  2242. $last == "sql" ||
  2243. $last == "style" ||
  2244. $last == "tcl" ||
  2245. $last == "tex" ||
  2246. $last == "threads" ||
  2247. $last == "tmpl" ||
  2248. $last == "tpl" ||
  2249. $last == "txt" ||
  2250. $last == "ubb" ||
  2251. $last == "vbs" ||
  2252. $last == "xml" ||
  2253. $last == "conf" ||
  2254. strstr($last, "htm")) { return "TEXT"; }
  2255. elseif ( $last == "png" ||
  2256. $last == "jpg" ||
  2257. $last == "jpeg" ||
  2258. $last == "gif" ||
  2259. $last == "bmp" ||
  2260. $last == "tif" ||
  2261. $last == "tiff") { return "IMAGE"; }
  2262. elseif ( $last == "exe" ||
  2263. $last == "com") { return "EXECUTABLE"; }
  2264. elseif ( $last == "doc" ||
  2265. $last == "rtf" ||
  2266. $last == "xls" ||
  2267. $last == "ppt" ||
  2268. $last == "mdb" ||
  2269. $last == "vsd" ||
  2270. $last == "mpp") { return "OFFICE"; }
  2271. elseif ( $last == "zip" ||
  2272. $last == "tar" ||
  2273. $last == "gz" ||
  2274. $last == "tgz" ||
  2275. $last == "rar" ||
  2276. $last == "arj" ||
  2277. $last == "arc") { return "ARCHIVE"; }
  2278. else { return "OTHER"; }
  2279. } // end getFileType
  2280. // ** **
  2281. // ** **
  2282. // **************************************************************************************
  2283. // **************************************************************************************
  2284. // **************************************************************************************
  2285. // **************************************************************************************
  2286. // ** **
  2287. // ** **
  2288. function getSystemType() {
  2289. // --------------
  2290. // Gets the WEBSERVER system type on which PHP is running
  2291. // (Not the one for which is was built)
  2292. // --------------
  2293. $systemInfo = php_uname();
  2294. if (stristr($systemInfo, "Linux") != false) {
  2295. $system = "Linux";
  2296. }
  2297. elseif (stristr($systemInfo, "BSD") != false) {
  2298. $system = "BSD";
  2299. }
  2300. elseif (stristr($systemInfo, "Unix") != false) {
  2301. $system = "Unix";
  2302. }
  2303. elseif (stristr($systemInfo, "Win") != false) {
  2304. $system = "Windows";
  2305. }
  2306. return $system;
  2307. } // end getSystemType
  2308. // ** **
  2309. // ** **
  2310. // **************************************************************************************
  2311. // **************************************************************************************
  2312. // **************************************************************************************
  2313. // **************************************************************************************
  2314. // ** **
  2315. // ** **
  2316. function checkEmailAddress($email) {
  2317. // --------------
  2318. // Returns true for valid email addresses, false for non-valid email addresses
  2319. // --------------
  2320. if (eregi( "^" .
  2321. "[a-z0-9]+([_\.-][a-z0-9]+)*" . //user
  2322. "@" .
  2323. "([a-z0-9]+([\.-][a-z0-9]+)*)+" . //domain
  2324. "\\.[a-z]{2,}" . //sld, tld
  2325. "$", $email, $regs)) { return true; }
  2326. else { return false; }
  2327. } // end checkEmailAddress
  2328. // ** **
  2329. // ** **
  2330. // **************************************************************************************
  2331. // **************************************************************************************
  2332. // **************************************************************************************
  2333. // **************************************************************************************
  2334. // ** **
  2335. // ** **
  2336. function checkFilename($filename) {
  2337. // --------------
  2338. // Returns true for valid filename
  2339. // --------------
  2340. if (preg_match("/^[a-zA-Z0-9_ \.-]*$/", $filename) == 0) { return false; }
  2341. else { return true; }
  2342. } // end checkFilename
  2343. // ** **
  2344. // ** **
  2345. // **************************************************************************************
  2346. // **************************************************************************************
  2347. // **************************************************************************************
  2348. // **************************************************************************************
  2349. // ** **
  2350. // ** **
  2351. function htmlEncode2($string) {
  2352. // --------------
  2353. // This function HTML-encodes a string with *htmlspecialchars* to print it on a page.
  2354. // Only some special characters are encoded, otherwise special characters (e.g. é) appear encoded (&eacute).
  2355. // --------------
  2356. $isocode = __("iso-8859-1");
  2357. if ($isocode == "MESSAGE NOT FOUND") { $isocode = "iso-8859-1"; }
  2358. $string = @htmlspecialchars($string, ENT_QUOTES, $isocode);
  2359. return $string;
  2360. } // end htmlEncode2
  2361. // ** **
  2362. // ** **
  2363. // **************************************************************************************
  2364. // **************************************************************************************
  2365. // **************************************************************************************
  2366. // **************************************************************************************
  2367. // ** **
  2368. // ** **
  2369. function htmlEncode3($string) {
  2370. // --------------
  2371. // This function HTML-encodes a string with *htmlentities* to generate the filename for downloading.
  2372. // All special characters are encoded.
  2373. // --------------
  2374. $string = @htmlentities($string, ENT_QUOTES, "UTF-8");
  2375. return $string;
  2376. } // end htmlEncode3
  2377. // ** **
  2378. // ** **
  2379. // **************************************************************************************
  2380. // **************************************************************************************
  2381. // **************************************************************************************
  2382. // **************************************************************************************
  2383. // ** **
  2384. // ** **
  2385. function urlEncode2($string) {
  2386. // --------------
  2387. // This function URL-encodes a string
  2388. // --------------
  2389. // $isocode = __("iso-8859-1");
  2390. // if ($isocode == "MESSAGE NOT FOUND") { $isocode = "iso-8859-1"; }
  2391. // $string = @htmlentities($string, ENT_QUOTES, $isocode);
  2392. // $string = str_replace(" ", "%20", $string);
  2393. $string = rawurlencode($string);
  2394. return $string;
  2395. } // end urlEncode2
  2396. // ** **
  2397. // ** **
  2398. // **************************************************************************************
  2399. // **************************************************************************************
  2400. // **************************************************************************************
  2401. // **************************************************************************************
  2402. // ** **
  2403. // ** **
  2404. function javascriptEncode2($string) {
  2405. // --------------
  2406. // Encode string characters which cause problems in Javascript
  2407. // <input type="button" onclick="alert('single quote \' single quote');" value="Test single"> OK <br /><br />
  2408. // <input type="button" onclick="alert('double quote &quot; double quote');" value="Test double"> OK <br /><br />
  2409. // <input type="button" onclick="alert('bs single \\\' bs single');" value="Test bs single"> OK <br /><br />
  2410. // <input type="button" onclick="alert('bs double \\\&quot; bs double');" value="Test bs double"> OK <br /><br />
  2411. // --------------
  2412. $singlequote = "'"; // '
  2413. $doublequote = "\""; // "
  2414. $backslash = "\\"; // \
  2415. $doublequote_html = "&quot;"; // &quot;
  2416. // Executing the 3 steps below in this order will convert:
  2417. // ' --> \' in step 2
  2418. // " --> &quot; in step 3
  2419. // \' --> \\\' in step 1 and 2
  2420. // \" --> \\\&quot; in step 1 and 3
  2421. $string = str_replace($backslash, "$backslash$backslash", $string);
  2422. $string = str_replace($singlequote, "$backslash$singlequote", $string);
  2423. $string = str_replace($doublequote, $doublequote_html, $string);
  2424. return htmlEncode2($string);
  2425. } // end javascriptEncode2
  2426. // ** **
  2427. // ** **
  2428. // **************************************************************************************
  2429. // **************************************************************************************
  2430. // **************************************************************************************
  2431. // **************************************************************************************
  2432. // ** **
  2433. // ** **
  2434. function registerTempfile($dowhat, $filename) {
  2435. // --------------
  2436. // This function registers and unregisters temporary files which are created and deleted
  2437. // If the script is halted, all the registered temporary files are deleted by the net2ftp_shutdown() function
  2438. //
  2439. // $dowhat can be either "register" or "unregister"
  2440. // $filename is the absolute filename (/web/net2ftp/temp/file.txt)
  2441. // --------------
  2442. // -------------------------------------------------------------------------
  2443. // Global variables and settings
  2444. // -------------------------------------------------------------------------
  2445. global $net2ftp_globals;
  2446. // -------------------------------------------------------------------------
  2447. // Add the current file to/from the $net2ftp_globals["tempfiles"] array
  2448. // Initialize $net2ftp_tempfiles if needed
  2449. // -------------------------------------------------------------------------
  2450. if ($dowhat == "register") {
  2451. if (isset($net2ftp_globals["tempfiles"]) == false) { $net2ftp_globals["tempfiles"] = array(); }
  2452. @array_push($net2ftp_globals["tempfiles"], $filename);
  2453. } // end if register
  2454. // -------------------------------------------------------------------------
  2455. // Remove the current file to/from the $net2ftp_globals["tempfiles"] array
  2456. // -------------------------------------------------------------------------
  2457. elseif ($dowhat == "unregister" && isset($net2ftp_globals["tempfiles"]) == true) {
  2458. $newindex = 0;
  2459. $tempfiles_new = array();
  2460. for ($i=0; $i<=sizeof($net2ftp_globals["tempfiles"]); $i++) {
  2461. if (isset($net2ftp_globals["tempfiles"][$i]) == true && $net2ftp_globals["tempfiles"][$i] != $filename) {
  2462. $tempfiles_new[$newindex] = $net2ftp_globals["tempfiles"][$i];
  2463. $newindex = $newindex + 1;
  2464. }
  2465. } // end for
  2466. unset($net2ftp_globals["tempfiles"]);
  2467. $net2ftp_globals["tempfiles"] = $tempfiles_new;
  2468. } // end if unregister
  2469. return true;
  2470. } // end registerTempfile
  2471. // ** **
  2472. // ** **
  2473. // **************************************************************************************
  2474. // **************************************************************************************
  2475. // **************************************************************************************
  2476. // **************************************************************************************
  2477. // ** **
  2478. // ** **
  2479. function net2ftp_shutdown() {
  2480. // --------------
  2481. // This function is registered through register_shutdown_function, so that it would be
  2482. // executed when the script reaches the maximum execution time.
  2483. //
  2484. // The function displays a warning message, and deletes temporary files.
  2485. // --------------
  2486. // -------------------------------------------------------------------------
  2487. // Global variables and settings
  2488. // -------------------------------------------------------------------------
  2489. global $net2ftp_globals, $net2ftp_settings, $net2ftp_result;
  2490. // -------------------------------------------------------------------------
  2491. // Delete the temporary files which were not deleted automatically
  2492. // -------------------------------------------------------------------------
  2493. if (isset($net2ftp_globals["tempfiles"]) == true) {
  2494. for ($i=0; $i<sizeof($net2ftp_globals["tempfiles"]); $i++) { delete_dirorfile($net2ftp_globals["tempfiles"][$i]); }
  2495. } // end if
  2496. // -------------------------------------------------------------------------
  2497. // Store the consumption counter values in the database
  2498. // -------------------------------------------------------------------------
  2499. putConsumption();
  2500. // -------------------------------------------------------------------------
  2501. // Print a message to tell the user that the script was halted
  2502. // -------------------------------------------------------------------------
  2503. $time_taken = timer();
  2504. $max_execution_time = @ini_get("max_execution_time");
  2505. // - Check if the $max_execution_time is > 0, because on some PHP configs it is -1 (more
  2506. // specifically: when PHP is run as CGI module).
  2507. // - Check the time taken versus the maximum execution time, because on Windows + Apache
  2508. // servers, the shutdown function is always called, even if the maximum execution time
  2509. // was not reached.
  2510. if (($max_execution_time > 0) && ($time_taken > $max_execution_time - 1)) {
  2511. if (isStatusbarActive() == true && function_exists("setStatus") == true) {
  2512. setStatus(10, 10, __("Script halted"));
  2513. }
  2514. $text = "";
  2515. $text .= "<b>" . __("Your task was stopped") . "</b><br /><br />\n";
  2516. $text .= __("The task you wanted to perform with net2ftp took more time than the allowed %1\$s seconds, and therefor that task was stopped.", $max_execution_time) . "<br />\n";
  2517. $text .= __("This time limit guarantees the fair use of the web server for everyone.") . "<br /><br />\n";
  2518. $text .= __("Try to split your task in smaller tasks: restrict your selection of files, and omit the biggest files.") . "<br /><br />\n";
  2519. if ($net2ftp_settings["net2ftpdotcom"] == "yes") {
  2520. $text .= __("If you really need net2ftp to be able to handle big tasks which take a long time, consider installing net2ftp on your own server.");
  2521. }
  2522. if ($net2ftp_globals["state"] == "jupload") { echo $text; }
  2523. else { echo "<div class=\"warning-box\"><div class=\"warning-text\">$text</div></div>\n\n"; }
  2524. }
  2525. } // end shutdown
  2526. // ** **
  2527. // ** **
  2528. // **************************************************************************************
  2529. // **************************************************************************************
  2530. // **************************************************************************************
  2531. // **************************************************************************************
  2532. // ** **
  2533. // ** **
  2534. function SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles) {
  2535. // --------------
  2536. // This function taken from www.PHP.net.
  2537. // It was written by [email protected] (29-Nov-2002 06:25)
  2538. // Alex was inspired by the function of [email protected] (06-Nov-2002 04:52)
  2539. // Note: it has been changed slightly to fit into the net2ftp application.
  2540. // (Mainly the way error handling is done.)
  2541. // --------------
  2542. /* Alex's comments:
  2543. This might be some useful stuff to send out emails in either text
  2544. or html or multipart version, and attach one or more files or even
  2545. none to it. Inspired by Kieran's msg above, I thought it might be
  2546. useful to have a complete function for doing this, so it can be used
  2547. wherever it's needed. Anyway I am not too sure how this script will
  2548. behave under Windows.
  2549. {br} represent the HTML-tag for line break and should be replaced,
  2550. but I did not know how to not get the original tag parsed here.
  2551. function SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles)
  2552. $From ... sender mail address like "[email protected]"
  2553. $FromName ... sender name like "My Name"
  2554. $To ... recipient mail address like "[email protected]"
  2555. $ToName ... recipients name like "Your Name"
  2556. $Subject ... subject of the mail like "This is my first testmail"
  2557. $Text ... text version of the mail
  2558. $Html ... html version of the mail
  2559. $AttmFiles ... array containing the filenames to attach like array("file1","file2")
  2560. */
  2561. // -------------------------------------------------------------------------
  2562. // Global variables
  2563. // -------------------------------------------------------------------------
  2564. global $net2ftp_result;
  2565. // Initial tests
  2566. // $Html = $Html?$Html:preg_replace("/\n/","{br}",$Text) or die("neither text nor html part present.");
  2567. // $Text = $Text?$Text:"Sorry, but you need an html mailer to read this mail.";
  2568. // $From or die("sender address missing");
  2569. // $To or die("recipient address missing");
  2570. if ((strlen($Html) < 1) && (strlen($Text) < 1)) {
  2571. $errormessage = __("You did not provide any text to send by email!");
  2572. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2573. return false;
  2574. }
  2575. if (strlen($From) < 1) {
  2576. $errormessage = __("You did not supply a From address.");
  2577. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2578. return false;
  2579. }
  2580. if (strlen($To) < 1) {
  2581. $errormessage = __("You did not supply a To address.");
  2582. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2583. return false;
  2584. }
  2585. if (strlen($Html) < 1) {
  2586. $Html = preg_replace("/\n/","<br>",$Text);
  2587. }
  2588. // Check if the To email address is valid
  2589. if (!eregi( "^" .
  2590. "[a-zA-Z0-9]+([_\.-][a-zA-Z0-9]+)*" . //user
  2591. "@" .
  2592. "([a-zA-Z0-9]+([\.-][a-zA-Z0-9]+)*)+" . //domain
  2593. "\\.[a-zA-Z]{2,}" . //sld, tld
  2594. "$", $To, $regs)) {
  2595. $errormessage = __("The email address you have entered (%1\$s) does not seem to be valid.<br />Please enter an address in the format <b>[email protected]</b>", $To);
  2596. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2597. return false;
  2598. }
  2599. // Definition of some variables
  2600. $OB = "----=_OuterBoundary_000";
  2601. $IB = "----=_InnerBoundery_001";
  2602. // Headers
  2603. $headers ="MIME-Version: 1.0\r\n";
  2604. $headers.="From: ".$FromName." <".$From.">\n";
  2605. $headers.="To: ".$ToName." <".$To.">\n";
  2606. $headers.="Reply-To: ".$FromName." <".$From.">\n";
  2607. $headers.="X-Priority: 1\n";
  2608. $headers.="X-MSMail-Priority: High\n";
  2609. $headers.="X-Mailer: My PHP Mailer\n";
  2610. $headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";
  2611. // Messages start with text/html alternatives in OB
  2612. $Msg ="This is a multi-part message in MIME format.\n";
  2613. $Msg.="\n--".$OB."\n";
  2614. $Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";
  2615. // Plaintext section
  2616. $Msg.="\n--".$IB."\n";
  2617. $Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
  2618. $Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
  2619. // Plaintext goes here
  2620. $Msg.=$Text."\n\n";
  2621. // Html section
  2622. $Msg.="\n--".$IB."\n";
  2623. $Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
  2624. $Msg.="Content-Transfer-Encoding: base64\n\n";
  2625. // Html goes here
  2626. $Msg.=chunk_split(base64_encode($Html))."\n\n";
  2627. // End of IB
  2628. $Msg.="\n--".$IB."--\n";
  2629. // Attachments
  2630. if($AttmFiles){
  2631. foreach($AttmFiles as $AttmFile){
  2632. // $patharray = explode ("/", $AttmFile);
  2633. // $FileName=$patharray[sizeof($patharray)-1];
  2634. $FileName = "RequestedFile.zip";
  2635. $Msg.= "\n--".$OB."\n";
  2636. $Msg.="Content-Type: application/octet-stream;\n\tname=\"".$FileName."\"\n";
  2637. $Msg.="Content-Transfer-Encoding: base64\n";
  2638. $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n";
  2639. // File goes here
  2640. $FileContent = local_readfile($AttmFile);
  2641. if ($net2ftp_result["success"] == false) { return false; }
  2642. $FileContent = chunk_split(base64_encode($FileContent));
  2643. $Msg.=$FileContent;
  2644. $Msg.="\n\n";
  2645. } // end for
  2646. } // end if
  2647. // Message ends
  2648. $Msg.="\n--".$OB."--\n";
  2649. // Send mail
  2650. $success2 = mail($To, $Subject, $Msg, $headers);
  2651. if ($success2 == false) {
  2652. $errormessage = __("Due to technical problems the email to <b>%1\$s</b> could not be sent.", $To);
  2653. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2654. return false;
  2655. }
  2656. // Logging
  2657. //syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");
  2658. } // end function SendMail
  2659. // ** **
  2660. // ** **
  2661. // **************************************************************************************
  2662. // **************************************************************************************
  2663. // **************************************************************************************
  2664. // **************************************************************************************
  2665. // ** **
  2666. // ** **
  2667. function printDirFileProperties($number, $entry, $checkbox_hidden, $onclick) {
  2668. // --------------
  2669. // Prints a checkbox and some hidden fields
  2670. // $onclick should be like "onclick=\"do_something_javascript();\""
  2671. // --------------
  2672. // Replace ' by &#039; to avoid errors when using this variable in an HTML value tag
  2673. // $dirfilename_html = htmlspecialchars($dirfilename, ENT_QUOTES);
  2674. // Print checkbox or hidden field
  2675. if (isset($entry["selectable"]) && $entry["selectable"] == "ok" && $checkbox_hidden == "checkbox") {
  2676. echo "<input type=\"checkbox\" name=\"list[$number][dirfilename]\" id=\"list_" . $number . "_dirfilename\" value=\"" . $entry["dirfilename_html"] . "\" $onclick />\n";
  2677. }
  2678. else {
  2679. echo "<input type=\"hidden\" name=\"list[$number][dirfilename]\" value=\"" . $entry["dirfilename_html"] . "\" />\n";
  2680. }
  2681. // Print hidden fields
  2682. echo "<input type=\"hidden\" name=\"list[$number][dirorfile]\" value=\"" . $entry["dirorfile"] . "\" />\n";
  2683. echo "<input type=\"hidden\" name=\"list[$number][size]\" value=\"" . $entry["size"] . "\" />\n";
  2684. echo "<input type=\"hidden\" name=\"list[$number][selectable]\" value=\"" . $entry["selectable"] . "\" />\n";
  2685. echo "<input type=\"hidden\" name=\"list[$number][permissions]\" value=\"" . $entry["permissions"] . "\" />\n";
  2686. echo "<input type=\"hidden\" name=\"list[$number][mtime]\" value=\"" . $entry["mtime"] . "\" />\n";
  2687. } // end printDirFileProperties
  2688. // ** **
  2689. // ** **
  2690. // **************************************************************************************
  2691. // **************************************************************************************
  2692. // **************************************************************************************
  2693. // **************************************************************************************
  2694. // ** **
  2695. // ** **
  2696. function getSelectedEntries($list) {
  2697. // --------------
  2698. // Input = array where dirfilename is set if the entry was selected, not set if not selected:
  2699. // [1] => Array ( [dirfilename] => dir1 [dirorfile] => d [size] => 0 [selectable] => ok [permissions] => ---rw-rw- ) <-- selected
  2700. // [2] => Array ( [dirfilename] => dir2 [dirorfile] => d [size] => 0 [selectable] => ok [permissions] => ---rw-rw- ) <-- selected
  2701. // [3] => Array ( [dirfilename] => dir3 [dirorfile] => d [size] => 0 [selectable] => too_big [permissions] => ---rw-rw- ) <-- selected
  2702. // [4] => Array ( [dirorfile] => d [size] => 0 [selectable] => ok [permissions] => ---rw-rw- ) <-- not selected
  2703. //
  2704. // Output = array with only the selected entries, which are not TOO BIG or which do not contain a forbidden keyword
  2705. // [1] => Array ( [dirfilename] => dir1 [dirorfile] => d [size] => 0 [permissions] => ---rw-rw- )
  2706. // [2] => Array ( [dirfilename] => dir2 [dirorfile] => d [size] => 0 [permissions] => ---rw-rw- )
  2707. // --------------
  2708. // Global variables
  2709. global $net2ftp_globals;
  2710. $newlist = array();
  2711. $newlist["directories"] = array();
  2712. $newlist["files"] = array();
  2713. $newlist["symlinks"] = array();
  2714. $newlist["unrecognized"] = array();
  2715. $directory_index = 1;
  2716. $file_index = 1;
  2717. $symlink_index = 1;
  2718. $unrecognized_index = 1;
  2719. $all_index = 1;
  2720. for ($i=1; $i<=sizeof($list); $i=$i+1) {
  2721. if (isset($list[$i]["dirorfile"]) == true && isset($list[$i]["dirfilename"]) == true) {
  2722. if (isset($list[$i]["selectable"]) == false || $list[$i]["selectable"] != "ok" &&
  2723. ($net2ftp_globals["state"] == "downloadfile" || $net2ftp_globals["state"] == "downloadzip" ||
  2724. $net2ftp_globals["state"] == "edit" || $net2ftp_globals["state"] == "findstring" ||
  2725. $net2ftp_globals["state"] == "unzip" || $net2ftp_globals["state"] == "view" ||
  2726. $net2ftp_globals["state"] == "zip" ||
  2727. $net2ftp_globals["state2"] == "copy" || $net2ftp_globals["state2"] == "move")) {
  2728. continue;
  2729. }
  2730. $list[$i]["dirfilename"] = validateGenericInput($list[$i]["dirfilename"]);
  2731. $list[$i]["dirfilename_html"] = htmlEncode2($list[$i]["dirfilename"]);
  2732. $list[$i]["dirfilename_js"] = javascriptEncode2($list[$i]["dirfilename"]);
  2733. if ($list[$i]["dirorfile"] == "d") {
  2734. $newlist["directories"][$directory_index] = $list[$i];
  2735. $directory_index++;
  2736. $newlist["all"][$all_index] = $list[$i];
  2737. $all_index++;
  2738. }
  2739. elseif ($list[$i]["dirorfile"] == "-") {
  2740. $newlist["files"][$file_index] = $list[$i];
  2741. $file_index++;
  2742. $newlist["all"][$all_index] = $list[$i];
  2743. $all_index++;
  2744. }
  2745. elseif ($list[$i]["dirorfile"] == "l") {
  2746. $newlist["symlinks"][$symlink_index] = $list[$i];
  2747. $symlink_index++;
  2748. $newlist["all"][$all_index] = $list[$i];
  2749. $all_index++;
  2750. }
  2751. elseif ($list[$i]["dirorfile"] == "u") {
  2752. $newlist["unrecognized"][$unrecognized_index] = $list[$i];
  2753. $unrecognized_index++;
  2754. $newlist["all"][$all_index] = $list[$i];
  2755. $all_index++;
  2756. }
  2757. }
  2758. } // end for
  2759. // Store the statistics
  2760. $newlist["stats"]["directories"]["total_number"] = $directory_index - 1;
  2761. $newlist["stats"]["files"]["total_number"] = $file_index - 1;
  2762. $newlist["stats"]["symlinks"]["total_number"] = $symlink_index - 1;
  2763. $newlist["stats"]["unrecognized"]["total_number"] = $unrecognized_index - 1;
  2764. return $newlist;
  2765. } // end getSelectedEntries
  2766. // ** **
  2767. // ** **
  2768. // **************************************************************************************
  2769. // **************************************************************************************
  2770. // **************************************************************************************
  2771. // **************************************************************************************
  2772. // ** **
  2773. // ** **
  2774. function formatFilesize($filesize) {
  2775. // --------------
  2776. // From php.net, code snippet submitted by sponger (10-Jun-2002 05:28)
  2777. // Edited for use in net2ftp.
  2778. //
  2779. // This may come in handy for someone.
  2780. // Returns the size of the passed file in the appropriate measurement format.
  2781. // --------------
  2782. // Setup some common file size measurements.
  2783. $kb = 1024; // Kilobyte
  2784. $mb = 1048576; // Megabyte
  2785. $gb = 1073741824; // Gigabyte
  2786. $tb = 1099511627776;// Terabyte
  2787. // Check if the last character is a letter
  2788. // Example: 8M = 8 Megabyte
  2789. $lastletter1 = strtolower(substr($filesize, -1));
  2790. $lastletter2 = strtolower(substr($filesize, -2));
  2791. if ($lastletter1 == "k") { $filesize = substr($filesize, 0, strlen($filesize)-1) * $kb; }
  2792. elseif ($lastletter1 == "m") { $filesize = substr($filesize, 0, strlen($filesize)-1) * $mb; }
  2793. elseif ($lastletter1 == "g") { $filesize = substr($filesize, 0, strlen($filesize)-1) * $gb; }
  2794. elseif ($lastletter1 == "t") { $filesize = substr($filesize, 0, strlen($filesize)-1) * $tb; }
  2795. elseif ($lastletter2 == "kb") { $filesize = substr($filesize, 0, strlen($filesize)-2) * $kb; }
  2796. elseif ($lastletter2 == "mb") { $filesize = substr($filesize, 0, strlen($filesize)-2) * $mb; }
  2797. elseif ($lastletter2 == "gb") { $filesize = substr($filesize, 0, strlen($filesize)-2) * $gb; }
  2798. elseif ($lastletter2 == "tb") { $filesize = substr($filesize, 0, strlen($filesize)-2) * $tb; }
  2799. // If it's less than a kb we just return the size, otherwise we keep going until
  2800. // the size is in the appropriate measurement range.
  2801. if($filesize == "") {
  2802. return "0 B";
  2803. }
  2804. elseif($filesize < $kb) {
  2805. return $filesize . " B";
  2806. }
  2807. elseif($filesize < $mb) {
  2808. return round($filesize/$kb,2) . " kB";
  2809. }
  2810. elseif($filesize < $gb) {
  2811. return round($filesize/$mb,2) . " MB";
  2812. }
  2813. elseif($filesize < $tb) {
  2814. return round($filesize/$gb,2) . " GB";
  2815. }
  2816. else {
  2817. return round($filesize/$tb,2) . " TB";
  2818. }
  2819. } // end formatFilesize
  2820. // ** **
  2821. // ** **
  2822. // **************************************************************************************
  2823. // **************************************************************************************
  2824. // **************************************************************************************
  2825. // **************************************************************************************
  2826. // ** **
  2827. // ** **
  2828. function tempnam2($dir, $prefix, $postfix) {
  2829. // --------------
  2830. // Contributed by anonymous on http://www.php.net on 23-Jul-2003 04:56
  2831. // The tempnam() function will not let you specify a postfix to the filename created.
  2832. // Here is a function that will create a new filename with pre and post fix'es.
  2833. // It returns false if it can't create in the dir specified. (The function tempnam, on the contrary, creates the file in the systems temp dir.)
  2834. // --------------
  2835. if ($dir[strlen($dir) - 1] == '/') { $trailing_slash = ""; }
  2836. else { $trailing_slash = "/"; }
  2837. // Check if the $dir is a directory
  2838. if (!is_dir($dir) || filetype($dir) != "dir") { return false; }
  2839. // Check if the directory is writeable
  2840. if (!is_writable($dir)){ return false; }
  2841. // Create the temporary filename
  2842. do {
  2843. $seed = substr(md5(microtime()), 0, 8);
  2844. $filename = $dir . $trailing_slash . $prefix . $seed . $postfix;
  2845. clearstatcache();
  2846. $file_exists = file_exists($filename);
  2847. } while ($file_exists == true);
  2848. $fp = fopen($filename, "wb");
  2849. fclose($fp);
  2850. return $filename;
  2851. } // end tempnam2
  2852. // ** **
  2853. // ** **
  2854. // **************************************************************************************
  2855. // **************************************************************************************
  2856. // **************************************************************************************
  2857. // **************************************************************************************
  2858. // ** **
  2859. // ** **
  2860. function tempdir2($dir, $prefix, $postfix) {
  2861. // --------------
  2862. // Same as tempnam2 but creates a directory instead of a file
  2863. // --------------
  2864. // Check if the parent directory $dir is a directory
  2865. if (!is_dir($dir) || filetype($dir) != "dir") {
  2866. $errormessage = __("Unable to create a temporary directory because (unvalid parent directory)");
  2867. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2868. return false;
  2869. }
  2870. // Check if the parent directory is writeable
  2871. if (!is_writable($dir)){
  2872. $errormessage = __("Unable to create a temporary directory because (parent directory is not writeable)");
  2873. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2874. return false;
  2875. }
  2876. // Check if the parent directory name ends with a /
  2877. if ($dir[strlen($dir) - 1] == '/') { $trailing_slash = ""; }
  2878. else { $trailing_slash = "/"; }
  2879. // Create the temporary directory
  2880. $result = false;
  2881. $i = 0;
  2882. do {
  2883. $seed = substr(md5(microtime()), 0, 8);
  2884. $filename = $dir . $trailing_slash . $prefix . $seed . $postfix;
  2885. $result = mkdir($filename);
  2886. $i = $i + 1;
  2887. } while ($result == false && $i < 10);
  2888. // Return result
  2889. if ($result == true) { return $filename; }
  2890. else {
  2891. $errormessage = __("Unable to create a temporary directory (too many tries)");
  2892. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2893. return false;
  2894. }
  2895. } // end tempdir2
  2896. // ** **
  2897. // ** **
  2898. // **************************************************************************************
  2899. // **************************************************************************************
  2900. // **************************************************************************************
  2901. // **************************************************************************************
  2902. // ** **
  2903. // ** **
  2904. function local_readfile($file) {
  2905. // --------------
  2906. // Open the local file $file and return its content as a string
  2907. // --------------
  2908. global $net2ftp_globals;
  2909. // From the PHP manual:
  2910. // Note: The mode may contain the letter 'b'.
  2911. // This is useful only on systems which differentiate between binary and text
  2912. // files (i.e. Windows. It's useless on Unix). If not needed, this will be
  2913. // ignored. You are encouraged to include the 'b' flag in order to make your scripts
  2914. // more portable.
  2915. // Thanks to Malte for bringing this to my attention !
  2916. $handle = fopen($file, "rb"); // Open the file for reading only
  2917. if ($handle == false) {
  2918. $errormessage = __("Unable to open the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]);
  2919. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2920. return false;
  2921. }
  2922. clearstatcache(); // for filesize
  2923. $filesize = filesize($file);
  2924. if ($filesize == 0) { return ""; }
  2925. $string = fread($handle, $filesize);
  2926. if ($string == false && filesize($file)>0) {
  2927. $errormessage = __("Unable to read the temporary file");
  2928. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2929. return false;
  2930. }
  2931. $success3 = fclose($handle);
  2932. if ($success3 == false) {
  2933. $errormessage = __("Unable to close the handle of the temporary file");
  2934. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2935. return false;
  2936. }
  2937. return $string;
  2938. } // end local_readfile
  2939. // ** **
  2940. // ** **
  2941. // **************************************************************************************
  2942. // **************************************************************************************
  2943. // **************************************************************************************
  2944. // **************************************************************************************
  2945. // ** **
  2946. // ** **
  2947. function local_writefile($file, $string) {
  2948. // --------------
  2949. // Open the local file $file and write the $string to it
  2950. // --------------
  2951. global $net2ftp_globals;
  2952. $handle = fopen($file, "wb");
  2953. if ($handle == false) {
  2954. $errormessage = __("Unable to open the temporary file. Check the permissions of the %1\$s directory.", $net2ftp_globals["application_tempdir"]);
  2955. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2956. return false;
  2957. }
  2958. $success1 = fwrite($handle, $string);
  2959. if ($success1 == false && strlen($string)>0) {
  2960. $errormessage = __("Unable to write the string to the temporary file <b>%1\$s</b>.<br />Check the permissions of the %2\$s directory.", $file, $net2ftp_globals["application_tempdir"]);
  2961. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2962. return false;
  2963. }
  2964. $success2 = fclose($handle);
  2965. if ($success2 == false) {
  2966. $errormessage = __("Unable to close the handle of the temporary file");
  2967. setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
  2968. return false;
  2969. }
  2970. } // end local_writefile
  2971. // ** **
  2972. // ** **
  2973. // **************************************************************************************
  2974. // **************************************************************************************
  2975. // **************************************************************************************
  2976. // **************************************************************************************
  2977. // ** **
  2978. // ** **
  2979. function local_getlist($localdirectory) {
  2980. // --------------
  2981. // This function gets the list of subdirectories and files within a directory,
  2982. // and returns it in the same format as ftp_getlist.
  2983. // Big differences with ftp_getlist is that local_getlist:
  2984. // - does not return a warning message;
  2985. // - cannot change the $localdirectory.
  2986. // --------------
  2987. // -------------------------------------------------------------------------
  2988. // Global variables
  2989. // -------------------------------------------------------------------------
  2990. global $net2ftp_result;
  2991. // -------------------------------------------------------------------------
  2992. // Initialization
  2993. // -------------------------------------------------------------------------
  2994. $handle = opendir($localdirectory);
  2995. $list = array();
  2996. $list_directories = array();
  2997. $list_files = array();
  2998. $i = 0;
  2999. $j = 1;
  3000. // -------------------------------------------------------------------------
  3001. // While loop
  3002. // -------------------------------------------------------------------------
  3003. while (false !== ($dirfilename = readdir($handle))) {
  3004. if ($dirfilename != "." && $dirfilename != "..") {
  3005. if (is_dir($dirfilename) == true) {
  3006. $listline["scanrule"] = "local";
  3007. $listline["dirorfile"] = "d";
  3008. $listline["dirfilename"] = $dirfilename;
  3009. $listline["size"] = 0;
  3010. $listline["selectable"] = "ok";
  3011. array_push($list_directories, $listline);
  3012. }
  3013. else {
  3014. $listline["scanrule"] = "local";
  3015. $listline["dirorfile"] = "-";
  3016. $listline["dirfilename"] = $dirfilename;
  3017. $listline["size"] = filesize($localdirectory . "/" . $dirfilename);
  3018. // Check if the filesize is bigger than the maximum authorized filesize
  3019. if (isset($listline["size"]) && is_numeric($listline["size"]) && $listline["size"] > $net2ftp_settings["max_filesize"]) {
  3020. $listline["selectable"] = "too_big";
  3021. }
  3022. else {
  3023. $listline["selectable"] = "ok";
  3024. }
  3025. array_push($list_files, $listline);
  3026. }
  3027. }
  3028. } // end while
  3029. for ($i=0; $i<sizeof($list_directories); $i=$i+1) { $list[$j] = $list_directories[$i]; $j=$j+1; }
  3030. for ($i=0; $i<sizeof($list_files); $i=$i+1) { $list[$j] = $list_files[$i]; $j=$j+1; }
  3031. // -------------------------------------------------------------------------
  3032. // End
  3033. // -------------------------------------------------------------------------
  3034. closedir($handle);
  3035. return $list;
  3036. } // End function local_getlist
  3037. // ** **
  3038. // ** **
  3039. // **************************************************************************************
  3040. // **************************************************************************************
  3041. // **************************************************************************************
  3042. // **************************************************************************************
  3043. // ** **
  3044. // ** **
  3045. function delete_dirorfile($dirorfile) {
  3046. // --------------
  3047. // This function deletes a local directory recursively
  3048. // Credit goes to itportal at gmail dot com, 17-Jul-2006 05:29
  3049. // --------------
  3050. // THIS FUNCTION IS ALMOST IDENTICAL TO THE ONE IN /modules/install/net2ftp_installer.txt
  3051. // Difference: this one only runs in execute mode, doesn't echo any output and returns a value.
  3052. // $return = true if all went well, false if there was an error somewhere.
  3053. // --------------
  3054. $result = true;
  3055. if (is_dir($dirorfile)) {
  3056. $directory = $dirorfile;
  3057. if(substr($dir, -1, 1) == "/"){
  3058. $directory = substr($directory, 0, strlen($directory) - 1);
  3059. }
  3060. if ($handle = opendir("$directory")) {
  3061. while (false !== ($item = readdir($handle))) {
  3062. if ($item != "." && $item != "..") {
  3063. if (is_dir("$directory/$item")) {
  3064. $delete_dirorfile_result = delete_dirorfile("$directory/$item", $mode);
  3065. $result = $result && $delete_dirorfile_result;
  3066. }
  3067. else {
  3068. $unlink_result = unlink("$directory/$item");
  3069. $result = $result && $unlink_result;
  3070. }
  3071. }
  3072. }
  3073. closedir($handle);
  3074. $rmdir_result = rmdir($directory);
  3075. $result = $result && $rmdir_result;
  3076. }
  3077. }
  3078. elseif (is_file($dirorfile)) {
  3079. $file = $dirorfile;
  3080. $unlink_result = unlink($file);
  3081. $result = $result && $unlink_result;
  3082. }
  3083. return $result;
  3084. } // End delete_dirorfile
  3085. // ** **
  3086. // ** **
  3087. // **************************************************************************************
  3088. // **************************************************************************************
  3089. // **************************************************************************************
  3090. // **************************************************************************************
  3091. // ** **
  3092. // ** **
  3093. function sendDownloadHeaders($filename, $filesize) {
  3094. // --------------
  3095. // This function sends download headers to the browser
  3096. // --------------
  3097. // -------------------------------------------------------------------------
  3098. // Global variables
  3099. // -------------------------------------------------------------------------
  3100. global $net2ftp_globals;
  3101. // -------------------------------------------------------------------------
  3102. // Clean the input, and encode the filename with htmlentities
  3103. // -------------------------------------------------------------------------
  3104. $filename = trim($filename);
  3105. $filename_html = htmlEncode3($filename);
  3106. // -------------------------------------------------------------------------
  3107. // Check which is the content type and disposition
  3108. // -------------------------------------------------------------------------
  3109. $content_type = getContentType($filename);
  3110. $content_disposition = "attachment";
  3111. if (strpos($filename, ".zip")) { $content_disposition = "inline"; }
  3112. // -------------------------------------------------------------------------
  3113. // Send the headers - Internet Explorer
  3114. // From PhpMyAdmin 3.5.2.0 file core.lib.php
  3115. // -------------------------------------------------------------------------
  3116. header('Expires: ' . date(DATE_RFC1123)); // rfc2616 - Section 14.21
  3117. header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
  3118. if ($net2ftp_globals["browser_agent"] == "IE") {
  3119. header('Pragma: public');
  3120. }
  3121. else {
  3122. header('Pragma: no-cache'); // HTTP/1.0
  3123. header('Last-Modified: ' . date(DATE_RFC1123));
  3124. }
  3125. header('Content-Description: File Transfer');
  3126. header('Content-Disposition: attachment; filename="' . $filename_html . '"');
  3127. header('Content-Type: ' . $content_type);
  3128. header('Content-Transfer-Encoding: binary');
  3129. header('Content-Length: ' . $filesize);
  3130. } // End function sendDownloadHeaders
  3131. // ** **
  3132. // ** **
  3133. // **************************************************************************************
  3134. // **************************************************************************************
  3135. ?>