Hi, Habr!
Today I want to tell you how to create a convenient http / ftp file storage. I'll say right away - it's pretty simple. What is required of the reader? Basic skills in the linux console, the ability to use the editor nano and, of course, the desire to create your own small file corner in the network.
I believe the following makes sense for people with a white IP address and fast internet connection. My version of the system involves the authorization of ftp / http and the ability to create hidden sections, while it remains possible to give direct links to files. Also, I provided for the use of http muzzle from mobile devices, so the script interface is nothing superfluous. For fans of fancy-look and wanting beauty and not functionality, this option is most likely not suitable. But this does not mean at all that your favorite file technician, my favorite technogic, will look ugly. See what comes out of this can be on the
link .
First, let's define the initial configuration: debian 6, apache2, php5, proftpd and good mood. Everyone's favorite ubunt also fit.
Attention! The following actions must be performed as
root . Just type su (or sudo su) and then the root password (or current user, in the case of sudo). Also, after any changes to the configuration files, the server must be restarted for the changes to take effect. This is done by teams
invoke-rc.d apache2 restart
and
invoke-rc.d proftpd restart
respectively.
So, all in order:
First we install the necessary software. Open the terminal, enter:
apt-get install apache2 php5 proftpd
Install it all, then enter:
nano /etc/apache2/sites-enabled/000-default
Here we will add a directive to disable the directory index and set the standard encoding.
At the beginning of the file will be a description of the directories with the contents. We are looking for the necessary lines:
DocumentRoot / var / www
<Directory />
Options FollowSymLinks
AllowOverride None
</ Directory>
We need to disable indexes and set the default encoding. You should have the following:
DocumentRoot / var / www
<Directory />
Options FollowSymLinks –Indexes
AddDefaultCharset utf-8
AllowOverride None
</ Directory>
With the apache setup, we are done. Save the config. In nano, this is done with the Ctrl + O combination, followed by Enter.
')
The next step is to create a user for the ftp login and define it in the same group as the apache. For example,
sosnickiy .
Attention! These username and password will need to be entered at the entrance to your ftp.
We write to the console:
adduser sosnickiy --ingroup www-data --shell /bin/false
Enter the password, the rest can not be filled, just click on Enter. The script will create a user, define it in a group and copy standard files. Create an ftp directory in its home directory:
mkdir -m 775 /home/sosnickiy/ftp
On this, perhaps, dealt with the user.
The next step is to set up an ftp server. So, we enter:
nano /etc/proftpd/proftpd.conf
We are looking for a parameter:
# DefaultRoot ~
A # (#) at the beginning of a line means that the parameter is commented out and ignored by the server. We remove this sieve.
We are looking for a parameter:
RequireValidShell on
Change it to:
RequireValidShell off
Add the following to the end of the configuration file:
<Directory / home / sosnickiy / ftp>
Umask 002 002
<Limit ALL>
AllowUser sosnickiy
Denyall
</ Limit>
</ Directory>
<Directory / home / sosnickiy / ftp / *>
Umask 002 002
<Limit ALL>
AllowUser sosnickiy
Denyall
</ Limit>
</ Directory>
This completes the ftp server setup. We save, restart it and can already use it. However, do not rush to upload files there. That's not all.
Now we will create an ftp directory in the http directory of the server and make it one with the ftp directory in the home folder of the user sosnickiy. This is where files will be uploaded via an ftp server.
Create a directory:
mkdir -m 775 /var/www/ftp
Execute the command:
mount --bind /home/sosnickiy/ftp /var/www/ftp
Now the directories are one.
We perpetuate change:
echo "/home/sosnickiy/ftp /var/www/ftp none bind 0 0" >> /etc/fstab
Now the directories will be one even after a reboot.
At this point, I would like to stop and make one important note: via http, the AutoIndex 2.2.4 script (
official site ) will be used to list files, upload them to the server, and manage directories, files and users. But its standard equipment does not allow starting and working right away as there is a bug with the Russian language file, a bug with the user / password storage file and there are some nuances with the rights created by the script files and directories. I have made minor changes, I will describe them below. If you don’t want to bother with his handset - I suggest downloading the script that is already fully ready for work: (
click here ). If you do not believe me, consider that I am in a conspiracy with the world government or just a bad person and added a bad change to the code of the Trojan / backdoor / other - manually do it yourself. At least, I advise you to take at least a file
ru.txt from my archive. I note that in the case of downloading a ready-made script, you only need to upload it to the server, unpack it in / var / www and show your friends a working file sharing service (hehe, irony). I will not describe the script settings as everything is very obvious there.
So, if you are an incredulous person, you will have to do the following:
We download the archive from the official site, unpack it on the working computer, in the classes directory we find the
Admin.php file, open it, look for line 68:
return @mkdir($path, 0755);
Change the number 755 to 775.
In the same directory, open the
Upload.php file, look for line 73:
@chmod($fullpathname, 0644);
Change the number 644 to 664.
In the file
Tar.php in line 78:
. str_pad('755', 7, '0', STR_PAD_LEFT) . "\0"
Instead of 755, we put 775.
This will fix the data access conflict.
Next, you need to open the file ru.txt in the languages ​​directory, delete its contents and insert corrected data into it:
ru.txt index of index
parent directory Parent directory
thumbnail of icon
continue continue
file
files Files
folder folder
folders Folders
size Size
total size overall size
total downloads total downloaded
total total
date Modified
description Description
downloads download
type Type
sort by Sort by
search Search
both Both
search results for Search results for
and its subdirectories and subdirectories
account Account
login login
logout logout
username Username
password Password
select user to remove Select user to remove
Are you sure you want to remove this user?
delete this user Delete this user
add user Add user
guest guest
user user
mod moderator
admin admin
level level
rename rename
renaming Rename
new filename New file name
you can also move the file by specifying a path. You can also move the file by specifying the path.
delete delete
are you sure you want to delete this file
edit description Edit description
yes, delete Yes, delete
upload Download
files to this folder Files in this folder
uploaded files Upload files
failed files not downloaded files
none No
file already exists File already exists
The file is marked as hidden.
reconfigure script Reconfigure script
create new directory in this folder Create a new directory in this
edit list of hidden files Edit list of hidden files
add new user Add new user
delete user Delete user
copy url Copy a remote file (to this folder)
upload to ftp upload file to FTP server
enter the new description for the file Enter the new file description
change Change
enter the new name Enter new name
create Create
add Add
remove remove
remove a hidden file Remove hidden file
add a new hidden file Add new hidden file
edit ban list Edit ban list
remove a ban ban ban
add a new ban Add to banned list
your administrator has your IP address or hostname Sorry, the administrator has blocked your IP address or hostname
view entries from log file View log file
view statistics from log file View statistics from the log file
How many entries would you like to view How many entries do you want to view
view View
page page
of of
calculate md5sum Calculate md5sum
download directory as tar.gz archive Download the directory as a tar.gz archive
Format: value [tab] translation to the desired language [line feed]
In the original file, the format is somewhat broken. Therefore, file sharing will not work.
Then, create in the root directory (next to the
index.php file) file
.htpasswd.autoindex . Mandatory with a dot at the beginning. Open, paste into it the following:
admin 7c4a8d09ca3762af61e59520943dc26494f8941b 3
user 12dea96fec20593566ab75692c9949596833adc9 1
In this case, the administrator password is
123456User Password:
userWe save everything, we pack the directory with the corrected script in a
zip archive, restart the ftp server, go in, upload the archive with the corrected script to the ftp directory.
For Windows, I recommend the Filezilla client. Or simply enter “Explorer” into the address bar:
ftp: // ip_address_server / ftp /
and hit enter. Also, you can save a password and add to Favorites. Conveniently.
So, the script is packed into the archive and lies in the ftp folder. Expand the console, write (better copy and paste):
cd /home/sosnickiy/ftp/ && unzip AutoIndex-2.2.4.zip && cp ./AutoIndex-2.2.4/* /var/www && rm -rf AutoIndex-2.2.4.zip AutoIndex-2.2.4
Now we execute a simple command:
chown -R www-data:www-data /var/www && chmod -R 775 /var/www
Now everything is ready! Use for health.
Thanks for attention.