1<?php
2	/*
3	Copyright (C) 2002-2004 Edwin van Wijk, www.phpwebftp.com
4
5	This program is free software; you can redistribute it and/or
6	modify it under the terms of the GNU General Public License
7	as published by the Free Software Foundation; either version 2
8	of the License, or (at your option) any later version.
9
10	This program is distributed in the hope that it will be useful,
11	but WITHOUT ANY WARRANTY; without even the implied warranty of
12	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13	GNU General Public License for more details.
14
15	You should have received a copy of the GNU General Public License
16	along with this program; if not, write to the Free Software
17	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19	New in Version 3.3b
20	- zip support for zipping and downloading an entire directory
21	- moved all ftp functions into a ftp class
22	- repaired ascii/binary mode button
23	- set default mode to binary
24	*/
25
26	include('config.inc.php'); //load configuration
27	$currentVersion = "3.3b";
28
29	// Report simple running errors
30	//error_reporting(E_ERROR | E_WARNING | E_PARSE);
31	error_reporting(E_ERROR | E_PARSE);
32
33	//Procedure for emptying the tmp directory
34	if($clearTemp==true)
35	{
36		if ($handle = opendir($downloadDir)) {
37			while (false !== ($delFile = readdir($handle))) {
38				if($delFile!="." and $delFile!="..") {
39					unlink($downloadDir . $delFile);
40				}
41			}
42			closedir($handle);
43		}
44	}
45
46
47	include("include/functions.inc.php");
48	include("include/ftp.class.php");
49	session_start();
50
51	// Get the POST, GET and SESSION variables (if register_globals=off (PHP4.2.1+))
52	// It's a bit of a dirty hack but variables are sometimes GET and sometimes POST variables
53	$goPassive=(isset($_POST['goPassive']))?$_POST['goPassive']:$_GET['goPassive'];
54	$mode=(isset($_POST['mode']))?$_POST['mode']:$_GET['mode'];
55	$actionType=(isset($_POST['actionType']))?$_POST['actionType']:$_GET['actionType'];
56	$currentDir=stripSlashes((isset($_POST['currentDir']))?$_POST['currentDir']:$_GET['currentDir']);
57	$file=(isset($_POST['file']))?$_POST['file']:$_GET['file'];
58	$file2=(isset($_POST['file2']))?$_POST['file2']:$_GET['file2'];
59	$permissions=(isset($_POST['permissions']))?$_POST['permissions']:$_GET['permissions'];
60	$directory=(isset($_POST['directory']))?$_POST['directory']:$_GET['directory'];
61	$fileContent=(isset($_POST['fileContent']))?$_POST['fileContent']:$_GET['fileContent'];
62
63	$file=StripSlashes($file);
64	$file2=StripSlashes($file2);
65
66	$mode=(isset($mode))?$mode:1;
67
68	if(isset($_POST['user'])) {
69		// we dont care if we are already logged or not in case user provides
70		// login information. That allows relogging in without explicitly
71		// loging out, eg with the "back" button.
72		if ($editDefaultServer)
73			$_SESSION['server']=$_POST['server'];
74		else
75			$_SESSION['server']=$defaultServer;
76
77		$_SESSION['user']=$_POST['user'];
78		$_SESSION['password']=$_POST['password'];
79		$_SESSION['language']=$_POST['language'];
80		$_SESSION['port']=$_POST['port'];
81		$_SESSION['passive']=$_POST['passive'];
82	}
83
84
85	if ($actionType=="logoff")
86	{
87		unset($_SESSION['server']);
88		unset($_SESSION['user']);
89		unset($_SESSION['password']);
90		unset($_SESSION['port']);
91		unset($_SESSION['passive']);
92
93		session_destroy();
94	}
95
96	$server=$_SESSION['server'];
97	$user=$_SESSION['user'];
98	$password=$_SESSION['password'];
99	$language=$_SESSION['language'];
100	$port=$_SESSION['port'];
101	$passive=$_SESSION['passive'];
102
103
104	// If language is not yet set, check the default language or try to get the language from your browser.
105	if($language==""){
106		if ($defaultLanguage !="") {
107			$language = $defaultLanguage ;
108		} else {
109			$browser_lang = getenv("http_accept_language");
110			$tmplang = $languages[$browser_lang];
111			if(file_exists("include/language/" . $tmplang . ".lang.php")) {
112				$language = $tmplang;
113			} else {
114				$language = "english";
115			}
116		}
117	}
118
119	//Include Language file
120	include("include/language/" . $language . ".lang.php");   // Selected language
121
122	if ($server!="")
123	{
124		$ftp = new ftp($server, $port, $user, $password, $passive);
125		$ftp->setMode($mode);
126		$ftp->setCurrentDir($currentDir);
127
128		// set some default values as defined in config.inc.php
129		$ftp->setResumeDownload($resumeDownload);
130		$ftp->setDownloadDir($downloadDir);
131
132		if ($ftp->loggedOn)
133		{
134			$msg = $ftp->getCurrentDirectoryShort();
135			// what to do now ???
136			if(isset($actionType)) {
137				switch ($actionType) {
138					case "chmod":	// Change permissions
139						if($ftp->chmod($permissions, $file)){
140							print $lblFilePermissionChanged;
141						} else {
142							print $lblCouldNotChangePermissions;
143						}
144						break;
145					case "cd":			// Change directory
146						$ftp->cd($file);
147						$msg = $lblndexOf . $ftp->getCurrentDirectoryShort();
148						break;
149					case "get":			// Download file
150						$ftp->download($file) or DIE($lblErrorDownloadingFile);
151						break;
152					case "put":			// Upload file
153						$fileObject = $_FILES['file'];
154						if($fileObject['size'] > $maxFileSize) {
155							$msg = "<B>" . $lblFileSizeTooBig . "</B> (max. " . $maxFileSize . " bytes)<P>";
156						} elseif(!$ftp->upload($fileObject)) {
157							$msg = $lblFileCouldNotBeUploaded;
158						}
159						break;
160					case "deldir";		// Delete directory
161						$ftp->deleteRecursive($file);
162						break;
163					case "delfile";		// Delete file
164						$ftp->deleteFile($file);
165						break;
166					case "rename";		// Rename file
167						if($ftp->rename($file, $file2))	{
168							$msg = $file . " " . $lblRenamedTo . " " . $file2;
169						} else {
170							$msg = $lblCouldNotRename . " " . $file . " " . $lblTo . " " . $file2;
171						}
172						break;
173					case "createdir":  // Create a new directory
174						if($ftp->makeDir($file)) {
175							$msg = $file . " " . $lblCreated;
176						} else {
177							$msg = $lblCouldNotCreate . " " . $file;
178						}
179						break;
180					case "edit":
181						//First download the file to the server
182						$ftp->get($file);
183
184						//Now open the content of the file in an edit window
185					?>
186						<html>
187						<HEAD>
188<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
189							<TITLE>phpWebFTP <?php echo $currentVersion;?> By Edwin van Wijk</TITLE>
190							<LINK REL=StyleSheet HREF="style/cm.css" TITLE=Contemporary TYPE="text/css">
191							<SCRIPT LANGUAGE="JavaScript" SRC="include/script.js"></SCRIPT>
192						</HEAD>
193						<body>
194						<h2>Edit <?php echo $file;?></h2>
195						<FORM METHOD=POST NAME='editFileForm' ACTION="<?php echo $php_self;?>">
196							<INPUT TYPE='hidden' NAME='actionType' VALUE='saveFile'>
197							<INPUT TYPE='hidden' NAME='currentDir' VALUE='<?php echo $ftp->currentDir;?>'>
198							<INPUT TYPE='hidden' NAME='file' VALUE='<?php echo $file;?>'>
199							<INPUT TYPE='hidden' NAME='mode' VALUE='<?php echo $ftp->mode;?>'>
200							<TEXTAREA NAME="fileContent" ROWS='30' COLS='80'><?php $data = stripslashes(readfile($ftp->downloadDir . $file));?></TEXTAREA>
201							<br>
202							<INPUT TYPE="submit" value="save"><INPUT TYPE=button OnClick='cancelEditFile();' VALUE="cancel" >
203						</FORM>
204						</body>
205						</html>
206					<?php
207						unlink($ftp->downloadDir . $file);
208						exit;
209						break;
210					case "saveFile":
211						//Write content of fileContent to tempFile
212						$tempFile = "tmpFile.txt";
213						$fp = fopen($ftp->downloadDir . $tempFile, "w+t");
214						if ($bytes=!fwrite($fp, stripslashes($fileContent))) {
215						   $msg = $lblFileCouldNotBeUploaded;
216						}
217						fclose($fp);
218
219						//Upload the file to the server
220						if(!$ftp->put($ftp->currentDir . "/" . filePart(StripSlashes($file)),$ftp->downloadDir . $tempFile)) $msg = $lblFileCouldNotBeUploaded;
221
222						//Delete temporary file
223						unlink($ftp->downloadDir . $tempFile);
224						break;
225
226					case "getzip":
227						set_time_limit(3000); //for big archives
228						$zipfile = $file . ".zip";
229						$dir = $ftp->downloadDir.$ftp->user . "/";   // a directory for every user, just in case...
230
231						header("Content-disposition: attachment; filename=\"$zipfile\"");
232						header("Content-type: application/octetstream");
233						header("Pragma: ");
234						header("Cache-Control: cache");
235						header("Expires: 0");
236
237						$zipfile = $ftp->downloadDir . $zipfile;
238
239						//Create temporary diretory
240						mkdir($dir);
241
242						//Get entire directory and store to temporary directory
243						$ftp->getRecursive($ftp->currentDir, $file);
244
245						//zip the directory
246						$zip = new ss_zip('',6);
247						$zip->zipDirTree($dir, $dir);
248						$zip->save($zipfile);
249
250						//send zipfile to the browser
251						$filearray = explode("/",$zipfile);
252						$file = $filearray[sizeof($filearray)-1];
253
254						$data = readfile($zipfile);
255						$i=0;
256						while ($data[$i] != "")
257						{
258							echo $data[$i];
259							$i++;
260						}
261
262						//Delete zip file
263						unlink($zipfile);
264
265						//Delete downloaded files from user specific directory
266						deleteRecursive($dir);
267						exit;
268						break;
269				}
270			}
271?>
272<HTML>
273<HEAD>
274<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
275	<TITLE>phpWebFTP <?php echo $currentVersion;?> By Edwin van Wijk</TITLE>
276	<LINK REL=StyleSheet HREF="style/cm.css" TITLE=Contemporary TYPE="text/css">
277	<SCRIPT LANGUAGE="JavaScript" SRC="include/script.js"></SCRIPT>
278</HEAD>
279<BODY>
280<TABLE CELLPADDING=0 CELLSPACING=0 HEIGHT="100%">
281<TR><TD>
282	<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0 WIDTH='100%'>
283		<TR>
284			<TD CLASS=titlebar COLSPAN=3>
285				<B>phpWebFTP <?php echo $lblVersion;?> <?php echo $currentVersion;?></B>
286			</TD>
287		</TR>
288		<TR>
289			<TD CLASS=menu>
290			<?php
291			$newMode=($ftp->mode==1)?0:1;
292			?>
293				<?php if($ftp->loggedOn) { ?>
294				<TABLE CELLPADDING=0 CELLSPACING=0><TR>
295
296				<TD VALIGN=CENTER>&nbsp;<A HREF='javascript:submitForm("cd","..")'><IMG SRC="img/parent.gif" HEIGHT=24 WIDTH=24 ALIGN=TOP BORDER=0></A></TD>
297				<TD VALIGN=CENTER><nobr><A HREF='javascript:submitForm("cd","..")'>&nbsp;<?php echo $lblUp;?></A> </nobr></TD>
298
299				<TD VALIGN=CENTER>&nbsp;<A CLASS=menu HREF="javascript:changeMode('<?php echo $newMode;?>')"><IMG SRC="img/mode.gif" HEIGHT=24 BORDER=0 ALIGN=CENTER></A></TD>
300				<TD VALIGN=CENTER><nobr><A CLASS=menu HREF="javascript:changeMode('<?php echo $newMode;?>')">&nbsp;<?php echo $lblChangeMode;?></A> </nobr></TD>
301
302				<TD VALIGN=CENTER>&nbsp;<A CLASS=menu HREF="javascript:logOff()"><IMG SRC="img/logoff.gif" HEIGHT=24 BORDER=0 ALIGN=CENTER></A></TD>
303				<TD VALIGN=CENTER><nobr><A CLASS=menu HREF="javascript:logOff()">&nbsp;<?php echo $lblLogOff;?></A> </nobr></TD>
304
305				<TD COLSPAN=6 VALIGN=TOP class=statusbar width="100%" VALIGN=CENTER ALIGN=RIGHT>
306					<?php echo directoryPath($ftp->currentDir, $server);?>
307				</TD>
308				</TR>
309</TABLE>
310				<?php } else { ?>
311				<TABLE CELLPADDING=0 CELLSPACING=0><TR>
312				<TD VALIGN=CENTER>&nbsp;<A CLASS=menu HREF="javascript:logOff()"><IMG SRC="img/logoff.gif" HEIGHT=24 BORDER=0 ALIGN=CENTER></A> </TD>
313				<TD VALIGN=CENTER>&nbsp;<A CLASS=menu HREF="javascript:logOff()"><?php echo $lblRetry;?></A> </TD>
314				</TR></TABLE>
315
316				<?php } ?>
317			</TD>
318			</FORM>
319		</TR>
320	</TABLE>
321</TD></TR>
322<TR><TD HEIGHT="100%">
323	<FORM NAME="actionform" METHOD=POST ACTION='<?php echo $PHP_SELF;?>'>
324		<INPUT TYPE='hidden' NAME='actionType' VALUE=''>
325		<INPUT TYPE='hidden' NAME='delaction' VALUE=''>
326		<INPUT TYPE='hidden' NAME='currentDir' VALUE='<?php echo $ftp->currentDir;?>'>
327		<INPUT TYPE='hidden' NAME='file' VALUE=''>
328		<INPUT TYPE='hidden' NAME='file2' VALUE=''>
329		<INPUT TYPE='hidden' NAME='extension' VALUE=''>
330		<INPUT TYPE='hidden' NAME='permissions' VALUE=''>
331		<INPUT TYPE='hidden' NAME='mode' VALUE='<?php echo $ftp->mode;?>' STYLE='border: none; background-color: #EFEFEF;'>
332	</FORM>
333	<HR>
334
335	<TABLE HEIGHT="100%">
336		<TR>
337		<TD class=leftmenu VALIGN=TOP width=210>
338			<DIV ALIGN=CENTER>
339				<BR>
340				<!-- File and folder -->
341				<TABLE CELLPADDING=0 CELLSPACING=0 class=item>
342					<TR>
343						<TD VALIGN=TOP class=itemhead>
344							<B><?php echo $lblFileTasks;?></B>
345						</TD>
346						</FORM>
347					</TR>
348					<TR>
349						<TD VALIGN=TOP class=leftmenuitem>
350
351							<DIV id="fileactions" style='display:none;'>
352							<TABLE>
353								<!-- Delete File -->
354								<TR>
355									<TD VALIGN=CENTER><IMG SRC="img/menu_delete.gif"></TD>
356									<TD VALIGN=CENTER>
357										<A HREF='javascript:deleteFile()' class=leftmenulink><?php echo $lblDeleteFile;?></A>
358									</TD>
359								</TR>
360
361								<TR>
362									<TD VALIGN=CENTER><IMG SRC="img/zip.gif"></TD>
363									<TD VALIGN=CENTER>
364										<A HREF='javascript:zipFile()' class=leftmenulink><?php echo "Zip & download";?></A>
365									</TD>
366								</TR>
367
368								<TR>
369									<TD VALIGN=CENTER><IMG SRC="img/menu_edit.gif"></TD>
370									<TD VALIGN=CENTER>
371										<A HREF='javascript:editFile()' class=leftmenulink><?php echo $lblEditFile;?></A>
372									</TD>
373								</TR>
374
375								<TR>
376									<TD VALIGN=top><IMG SRC="img/menu_rename.gif"></TD>
377									<TD VALIGN=top>
378										<A HREF='javascript:setNewFileName("<?php echo $myDir["name"];?>")' class=leftmenulink><?php echo $lblRename;?></A>
379										<!-- Rename file -->
380										<DIV ID='renameFileEntry' style='display:none;'>
381											<FORM NAME=renameFile>
382											<TABLE CELLSPACING=0 class=lined align=center>
383												<TR>
384													<TD class=tinyblue>
385													<B><?php echo $lblNewName;?></B><BR>
386													<INPUT TYPE="text" NAME="newName" value=""></TD>
387												</TR>
388												</TABLE>
389											<BR>
390											<DIV ALIGN=CENTER><INPUT TYPE=button OnClick='renameItem();' VALUE='<?php echo $lblRename;?>'></DIV>
391											</FORM>
392											<BR>
393										</DIV>
394									</TD>
395								</TR>
396
397								<TR>
398									<TD VALIGN=top><IMG SRC="img/menu_settings.gif"></TD>
399									<TD VALIGN=top>
400										<A HREF='javascript:;' OnClick='setPermissions()' class=leftmenulink><?php echo $lblSetPermissions;?></A>
401										<!-- Change permissions -->
402										<DIV ID='setPermissions' style='display:none;'>
403											<FORM NAME=permissions>
404											<TABLE CELLSPACING=0 class=lined align=center>
405											<TR>
406												<TD class=tinyblue ALIGN=CENTER><B><?php echo $lblOwner;?></B></TD>
407												<TD class=tiny ALIGN=CENTER><B><?php echo $lblGroup;?></B></TD>
408												<TD class=tinywhite ALIGN=CENTER><B><?php echo $lblPublic;?></B></TD>
409											</TR>
410											<TR>
411												<TD class=tinyblue><INPUT TYPE="checkbox" NAME="iOr"> <?php echo $lblRead;?></TD>
412												<TD class=tiny><INPUT TYPE="checkbox" NAME="iGr"> <?php echo $lblRead;?></TD>
413												<TD class=tinywhite><INPUT TYPE="checkbox" NAME="iPr"> <?php echo $lblRead;?></TD>
414											</TR>
415											<TR>
416												<TD class=tinyblue><INPUT TYPE="checkbox" NAME="iOw"> <?php echo $lblWrite;?></TD>
417												<TD class=tiny><INPUT TYPE="checkbox" NAME="iGw"> <?php echo $lblWrite;?></TD>
418												<TD class=tinywhite><INPUT TYPE="checkbox" NAME="iPw"> <?php echo $lblWrite;?></TD>
419											</TR>
420											<TR>
421												<TD class=tinyblue><INPUT TYPE="checkbox" NAME="iOx"> <?php echo $lblExecute;?></TD>
422												<TD class=tiny><INPUT TYPE="checkbox" NAME="iGx"> <?php echo $lblExecute;?></TD>
423												<TD class=tinywhite><INPUT TYPE="checkbox" NAME="iPx"> <?php echo $lblExecute;?></TD>
424											</TR>
425
426											</TABLE>
427											<BR>
428											<DIV ALIGN=CENTER><INPUT TYPE=button OnClick='changePermissions()' VALUE='<?php echo $lblSetPermissions;?>'></DIV>
429											</FORM>
430											<BR>
431										</DIV>
432									</TD>
433								</TR>
434							</TABLE>
435							</DIV>
436
437
438							<!-- Standaard actions -->
439							<TABLE>
440								<TR>
441									<TD VALIGN=top><IMG SRC="img/upload.gif" BORDER="0" ALT=""></TD>
442									<TD VALIGN=top>
443										<A HREF="JavaScript:toggle('uploadform');" class=leftmenulink><?php echo $lblUploadFile;?></A>
444											<FORM id="uploadform" style='display:none;' NAME='putForm' ENCTYPE="multipart/form-data" METHOD=POST ACTION="<?php echo $PHP_SELF;?>">
445												<INPUT TYPE="hidden" NAME="actionType" VALUE="put">
446												<INPUT TYPE='hidden' NAME='currentDir' VALUE='<?php echo $ftp->currentDir;?>'>
447												<INPUT TYPE='hidden' NAME='mode' VALUE='<?php echo $ftp->mode;?>'>
448												<INPUT TYPE="file" NAME="file" size=8 STYLE="width:10px; font-size:7pt;" onChange='document.uploadform.submit();'><BR>
449												<INPUT TYPE="SUBMIT" VALUE="OK" STYLE='width=150px; font-size:7pt;'>
450											</FORM>
451									</TD>
452								</TR>
453								<TR>
454									<TD VALIGN=top><IMG SRC="img/createdir.gif" BORDER="0" ALT=""></TD>
455									<TD VALIGN=top>
456										<A HREF="JavaScript:toggle('createform');" class=leftmenulink><?php echo $lblCreateDirectory;?></A>
457										<FORM id="createform" style='display:none;' METHOD=POST NAME='dirinput' ACTION="<?php echo $PHP_SELF;?>">
458											<INPUT TYPE="text" NAME="directory" VALUE="" STYLE="width:100px; font-size:7pt;">
459											<INPUT TYPE="BUTTON" VALUE="OK" OnClick='javascript:createDirectory(dirinput.directory.value)' STYLE="width:40px; font-size:7pt;">
460										</FORM>
461									</TD>
462								</TR>
463								<TR>
464									<TD VALIGN=top><IMG SRC="img/gotodir.gif" BORDER="0" ALT=""></TD>
465									<TD VALIGN=top>
466										<A HREF="JavaScript:toggle('gotoform');" class=leftmenulink><?php echo $lblGoToDirectory;?></A>
467										<FORM id="gotoform" style='display:none;' NAME='cdDirect' METHOD=POST ACTION='<?php echo $PHP_SELF;?>'>
468											<INPUT TYPE='hidden' NAME='actionType' VALUE='cd'>
469											<INPUT TYPE='hidden' NAME='currentDir' VALUE='<?php echo $ftp->currentDir;?>'>
470											<INPUT TYPE="text" NAME="file" VALUE="" STYLE="width:100px; font-size:7pt;">
471											<INPUT TYPE="SUBMIT" VALUE="OK" STYLE="width:40px; font-size:7pt;">
472										</FORM>
473									</TD>
474								</TR>
475							</TABLE>
476						</TD>
477					</TR>
478				</TABLE>
479				<P>
480				<!-- Details -->
481				<TABLE CELLPADDING=0 CELLSPACING=0 class=item>
482					<TR>
483						<TD VALIGN=TOP class=itemhead>
484							<B><?php echo $lblDetails;?></B>
485						</TD>
486						</FORM>
487					</TR>
488					<TR>
489						<TD VALIGN=TOP class=leftmenuitem style='color:black' >
490							<BR>
491							<B><?php echo $msg;?></B>
492							<P>
493							<?php echo ($ftp->loggedOn)?"$lblConnectedTo  $server:$port ($ftp->systype)":$lblNotConnected;?>
494							<P>
495							<?php echo $lblTransferMode;?> :<?php echo $ftp->mode==1?$lblBinaryMode:$lblASCIIMode;?>
496							<BR><BR>
497						</TD>
498					</TR>
499
500				</TABLE>
501
502			</DIV>
503		</TD>
504		<TD VALIGN=TOP>
505			<P>
506			<TABLE WIDTH="650" CELLSPACING=0 CELLPADDING=0 onClick='resetEntries()'>
507				<TR>
508					<TD COLSPAN=2 class=listhead><?php echo $lblName;?></TD>
509					<TD class=listhead><IMG SRC="img/listheaddiv.gif"></TD>
510					<TD class=listhead align=right><?php echo $lblSize;?>&nbsp;</TD>
511					<TD class=listhead><IMG SRC="img/listheaddiv.gif"></TD>
512					<TD class=listhead><?php echo $lblFileType;?>&nbsp;</TD>
513					<TD class=listhead><IMG SRC="img/listheaddiv.gif"></TD>
514					<TD class=listhead><?php echo $lblDate;?></TD>
515					<TD class=listhead><IMG SRC="img/listheaddiv.gif"></TD>
516					<TD class=listhead><?php echo $lblPermissions;?></TD>
517					<TD class=listhead><IMG SRC="img/listheaddiv.gif"></TD>
518					<TD class=listhead><?php echo $lblOwner;?></TD>
519					<TD class=listhead><IMG SRC="img/listheaddiv.gif"></TD>
520					<TD class=listhead><?php echo $lblGroup;?></TD>
521					<TD class=listhead><IMG SRC="img/listheaddiv.gif"></TD>
522				</TR>
523	 		<?php
524				$list = $ftp->ftpRawList();
525
526				if (is_array($list))
527				{
528					// Directories
529					$counter=0;
530					foreach($list as $myDir)
531					{
532						if ($myDir["is_dir"]==1)
533						{
534							$fileAction = "cd";
535							$fileName = $myDir["name"];
536							$fileSize="";
537							$delAction = "deldir";
538							$fileType['description'] = 'File Folder';
539							$fileType['imgfilename'] = 'folder.gif';
540						}
541
542						if ($myDir["is_link"]==1)
543						{
544							$fileAction = "cd";
545							$fileName = $myDir["target"];
546							$fileSize="";
547							$delAction = "delfile";
548							$fileType['description'] = 'Symbolic Link';
549							$fileType['imgfilename'] = 'link.gif';
550						}
551
552						if ($myDir["is_link"]!=1 && $myDir["is_dir"]!=1)
553						{
554						    $fileType = fileDescription($myDir["name"]);
555							$fileAction = "get";
556							$fileName = $myDir["name"];
557							$image = "file.gif";
558							if($myDir["size"]<1024) {
559								$fileSize= $myDir["size"] . " bytes ";
560									$fileSize=number_format($myDir["size"], 0, ',', '.') . " bytes";
561							} else {
562								if($myDir["size"]<1073741824) {
563									$fileSize=number_format($myDir["size"]/1024, 0, ',', '.') . " KB";
564								} else {
565									$fileSize=number_format($myDir["size"]/1048576, 0, ',', '.') . " MB";
566								}
567							}
568
569
570							$delAction = "delfile";
571						}
572				?>
573
574							<TR>
575							<TD class=filenamecol width=20><A HREF='javascript:selectEntry("<?php echo $fileAction;?>","<?php echo $fileName;?>","filename<?php echo $counter;?>","<?php echo $myDir["perms"];?>","<?php echo $delAction;?>")' ondblclick='submitForm("<?php echo $fileAction;?>","<?php echo $fileName;?>")'><IMG SRC="img/<?php echo $fileType['imgfilename'];?>" ALIGN=TOP BORDER=0></A></TD>
576							<TD class=filenamecol><span id='filename<?php echo $counter;?>'><A HREF='javascript:selectEntry("<?php echo $fileAction;?>","<?php echo $fileName;?>","filename<?php echo $counter;?>","<?php echo $myDir["perms"];?>","<?php echo $delAction;?>")' ondblclick='submitForm("<?php echo $fileAction;?>","<?php echo $fileName;?>")'><?php echo $fileName;?></A></span></TD>
577							<TD>&nbsp;</TD>
578							<TD ALIGN=RIGHT><?php echo $fileSize;?></TD>
579							<TD>&nbsp;</TD>
580							<TD ALIGN=left><?php echo $fileType['description'];?></TD>
581							<TD>&nbsp;</TD>
582							<TD><?php echo $myDir["date"];?></TD>
583							<TD>&nbsp;</TD>
584							<TD><?php echo $myDir["perms"];?></TD>
585							<TD>&nbsp;</TD>
586							<TD><?php echo $myDir["user"];?></TD>
587							<TD>&nbsp;</TD>
588							<TD><?php echo $myDir["group"];?></TD>
589							<TD>&nbsp;</TD>
590							</TR>
591				<?php
592						$counter++;
593					}
594				} else {
595				?>
596							<TR>
597							<TD colspan=14><BR><B><?php echo $lblDirectoryEmpty;?>...</B></TD>
598							</TR>
599				<?php
600				}
601				print "	</TABLE></TD></TR></TABLE>";
602			}
603			else
604			{
605				if(!isset($msg))
606				{
607					$msg = "$lblCouldNotConnectToServer  $server:$port $lblWithUser $user<P><A HREF='" . $_SERVER["PHP_SELF"] . "'>$lblTryAgain</A>";
608					unset($_SESSION['server']);
609					unset($_SESSION['user']);
610					unset($_SESSION['password']);
611					unset($_SESSION['port']);
612					session_destroy();
613				}
614	?>
615</TD></TR></TABLE>
616<HTML>
617<HEAD>
618<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
619	<TITLE>phpWebFTP <?php echo $currentVersion;?> By Edwin van Wijk</TITLE>
620	<LINK REL=StyleSheet HREF="style/cm.css" TITLE=Contemporary TYPE="text/css">
621	<SCRIPT LANGUAGE="JavaScript" SRC="include/script.js"></SCRIPT>
622</HEAD>
623<BODY>
624<?php
625			print $msg;
626		}
627	}
628	else // Still need to logon...
629	{
630?>
631<HTML>
632<HEAD>
633<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
634	<TITLE>phpWebFTP <?php echo $currentVersion;?> By Edwin van Wijk</TITLE>
635	<LINK REL=StyleSheet HREF="style/cm.css" TITLE=Contemporary TYPE="text/css">
636	<SCRIPT LANGUAGE="JavaScript" SRC="include/script.js"></SCRIPT>
637</HEAD>
638<BODY>
639		<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0 WIDTH='100%'>
640			<TR>
641				<TD CLASS=titlebar>
642					<B>phpWebFTP <?php echo $lblVersion;?> <?php echo $currentVersion;?></B>
643				</TD>
644			</TR>
645			<TR>
646				<TD CLASS=menu>
647					<TABLE CELLPADDING=0 CELLSPACING=0><TR>
648					<TD VALIGN=CENTER><IMG SRC="img/1px.gif" HEIGHT=24 BORDER=0 ALIGN=CENTER></TD>
649					<TD VALIGN=CENTER>&nbsp;</TD>
650					</TR></TABLE>
651				</TD>
652			</TR>
653		</TABLE>
654
655		<FORM NAME=login action='<?php echo $_SERVER['PHP_SELF'];?>' METHOD=POST>
656		<TABLE class=login cellpadding=3>
657			<TR>
658				<TD COLSPAN=3><B>&nbsp;<?php echo $lblLogIn;?></B></TD>
659			</TR>
660			<TR>
661				<TD COLSPAN=3><IMG SRC="img/1px.gif" HEIGHT=60></TD>
662			</TR>
663			<TR>
664				<TD COLSPAN=3>&nbsp;<?php echo $lblConnectToFTPServer;?></TD>
665			</TR>
666			<TR>
667				<TD VALIGN=TOP>&nbsp;<?php echo $lblServer;?></TD>
668				<TD VALIGN=TOP>
669					<?php
670						if($defaultServer == "") {
671							print "<INPUT TYPE=TEXT NAME=server SIZE=15>&nbsp;";
672						} else {
673							$inputType=($editDefaultServer==true)?"TEXT":"HIDDEN";
674							print "<INPUT TYPE=" . $inputType . " NAME=server VALUE=" . $defaultServer . ">";
675							if($editDefaultServer==false) {
676								print "<B>" . $defaultServer . "</B>&nbsp;";
677							}
678						}
679					?>
680				</TD>
681				<TD VALIGN=TOP>
682					<TABLE CELLSPACING=0>
683						<TR>
684							<TD><?php echo $lblPort;?></TD>
685							<TD><INPUT TYPE=TEXT NAME=port SIZE=3 VALUE=21></TD>
686						</TR>
687						<TR>
688							<TD><?php echo $lblPasive;?></TD>
689							<TD><INPUT TYPE="checkbox" NAME="goPassive"></TD>
690						</TR>
691					</TABLE>
692				</TD>
693			</TR>
694			<TR>
695				<TD>&nbsp;<?php echo $lblUser;?></TD>
696				<TD>
697					<INPUT TYPE=TEXT NAME=user SIZE=18>
698				</TD>
699				<TD>&nbsp;</TD>
700			</TR>
701			<TR>
702				<TD>&nbsp;<?php echo $lblPassword;?></TD>
703				<TD><INPUT TYPE=PASSWORD NAME=password SIZE=18></TD>
704				<TD><INPUT TYPE=SUBMIT VALUE="Log on"></TD>
705			</TR>
706
707			<?php
708				if($defaultLanguage == "") {
709			?>
710			<TR>
711				<TD>&nbsp;<?php echo $lblLanguage;?></TD>
712				<TD colspan=2>
713					<?php
714
715					?>
716					<SELECT NAME="language">
717					<?php
718						if ($handle = opendir('include/language/')) {
719							//Read file in directory and store them in an Array
720							while (false !== ($file = readdir($handle))) {
721								$fileArray[$file] = $file;
722							}
723							//Sort the array
724							ksort($fileArray);
725
726							foreach($fileArray as $file) {
727								if ($file != "." && $file != ".." ) {
728								    $file=str_replace(".lang.php","",$file);
729								    $counter=0;
730								    foreach($languages as $thislang)
731								    {
732								        if($thislang==$file)
733								        {
734								            $counter++;
735								        }
736								    }
737								    if($counter>0) {
738										$langName=strtoupper(substr($file,0,1)) . substr($file,1);
739					?>
740										<OPTION VALUE="<?php echo $file;?>" <?php echo ($language==$file)?"selected":"";?>><?php echo $langName;?></OPTION>
741					<?php
742								    }
743
744								}
745							}
746							closedir($handle);
747						}
748			 				?>
749					</SELECT>
750			</TR>
751			<?php
752				} // End default server
753			?>
754			<TR>
755				<TD COLSPAN=2><IMG SRC="img/1px.gif" HEIGHT=5></TD>
756			</TR>
757		</TABLE>
758		<TABLE WIDTH=328>
759		<TR>
760				<TD COLSPAN=2 VALIGN=TOP class=leftmenuitem>
761					<DIV style='font-size:7pt;'>
762					<?php echo $lblDisclaimer;?>
763					<BR><BR>
764					phpWebFTP <?php echo $lblVersion;?> <?php echo $currentVersion;?><BR>
765					&copy; 2002-2006, Edwin van Wijk,<BR>
766					<A HREF="http://www.phpwebftp.com" style='font-size:7pt;'>www.phpwebftp.com</A>
767					</div>
768					<P>
769				</TD>
770			</TR>
771			<TR>
772			<TD ALIGN=LEFT>&nbsp;</TD>
773			<TD ALIGN=RIGHT>
774				&nbsp;
775			</TD>
776			</TR>
777		</TABLE>
778		</FORM>
779<?php
780	}
781?>
782<P>
783</BODY>
784</HTML>
785