LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Router headaches (https://www.linuxquestions.org/questions/linux-networking-3/router-headaches-34673/)

DavidPhillips 03-25-2003 04:33 PM

do you mean the document root or virtual domain?
upload or just download


<Directory /var/www/upload>
EnablePut On
Options +Indexes
AuthType Basic
AuthName Temporary
AuthUserFile /etc/httpd/conf/access/upload/.htpasswd
EnableDelete Off
umask 007
require valid-user
</Directory>

<VirtualHost *>
ServerAdmin admin@domain.com
DocumentRoot /var/www/upload
ServerName upload.domain.com
ErrorLog logs/dm3-error_log
CustomLog logs/dm3-access_log common
</VirtualHost>


you will need a webpage interface and cgi script to actually do an upload



upload.html
Code:

<html>
<head>
    <title>Upload ...</title>
</head>
<body BGCOLOR="396DA5">
<p>
        <form ENCTYPE="multipart/form-data" ACTION="/cgi-bin/upload.cgi" METHOD="POST">
     
        <h3>Choose the files you want to upload from your computer.</h3>

        <hr size=l>
        <table BORDER=0 WIDTH="500">

        <tr>
            <td ALIGN=RIGHT>
                File #1:
            </td>
            <td>
                <input TYPE="FILE" NAME="file-to-upload-01" SIZE="35">
            </td>
        </tr>
        <tr>

            <td ALIGN=RIGHT>
                File #2:
            </td>
            <td>
                <input TYPE="FILE" NAME="file-to-upload-02" SIZE="35">
            </td>
        </tr>
        <tr>
            <td ALIGN=RIGHT>

                File #3:
            </td>
            <td>
                <input TYPE="FILE" NAME="file-to-upload-03" SIZE="35">
            </td>
        </tr>
        <tr>
            <td ALIGN=RIGHT>
                File #4:
            </td>

            <td>
                <input TYPE="FILE" NAME="file-to-upload-04" SIZE="35">
            </td>
        </tr>
                <tr>
                        <td COLSPAN=2>&nbsp;<br></td>
                </tr>
        <tr>
            <td>

                <input TYPE="SUBMIT" VALUE="Upload">
                <input TYPE="RESET" VALUE="Reset">
            </td>
        </tr>
        </table>
        </form>

</body>
</html>

----------------------------------------------------------------

<Directory /home/user/Documents>
order deny,allow
deny from all
allow from localhost .localdomain
Options Indexes FollowSymLinks
</Directory>


--------------------------------------------------------------


DocumentRoot /var/www/html




Tell him to get a GUI for windows that supports sftp and connect it to localhost on the forwarded port.

I'm sure you can get a number of them that will work.

DavidPhillips 03-25-2003 04:38 PM

upload.cgi


Code:


#!/usr/bin/perl
BEGIN
{
$SAVE_DIRECTORY = "/var/www/upload";
$MAXIMUM_UPLOAD = 0;
$ALLOW_INDEX = 0;
$SUCCESS_LOCATION = "";

chop $SAVE_DIRECTORY if ($SAVE_DIRECTORY =~ /\/$/);
use CGI qw(:standard);
$query = new CGI;

foreach $key (sort {$a <=> $b} $query->param())
{
next if ($key =~ /^\s*$/);
next if ($query->param($key) =~ /^\s*$/);
next if ($key !~ /^file-to-upload-(\d+)$/);

$Number = $1;

        if ($query->param($key) =~ /([^\/\\]+)$/)
                {
                $Filename = $1;
                $Filename =~ s/^\.+//;
                $File_Handle = $query->param($key);

                if (!$ALLOW_INDEX && $Filename =~ /^index/i)
                        {
                        print header;
                        print <<__END_OF_HTML_CODE__;
<HTML><HEAD><TITLE>Error: Filename Problem</TITLE></HEAD><BODY BGCOLOR=396DA5><H3>Filename Problem</H3><P>You attempted to upload a file that is not properly formatted.  The system administrator has decided that you can not upload files that begin with the word '<B>index</B>'. Please rename the file on your computer, and try uploading it again.<P><A HREF="https://www.domain.com">www.domain.com</A> - <A HREF="https://upload.domain.com/upload.html">Upload Files</A> - <A HREF="https://upload.domain.com/">Browse Upload Folder</A></BODY></HTML>
__END_OF_HTML_CODE__
                        exit;
                        }

                        if (!open(OUTFILE, ">$SAVE_DIRECTORY\/$Filename"))
                                {
                                print header;
                                print <<__END_OF_HTML_CODE__;
<HTML><HEAD><TITLE>Error: Filename Exists</TITLE></HEAD><BODY BGCOLOR=396DA5><H3>Filename Problem</H3><P>The filename '<B>$Filename</B>' already exists on the server.  The system administrator has decided that you can not overwrite files on this server. Please rename the file on your computer, and try uploading it again.<P><A HREF="https://www.domain.com">www.domain.com</A> - <A HREF="https://upload.domain.com/upload.html">Upload Files</A> - <A HREF="https://upload.domain.com/">Browse Upload Folder</A></BODY></HTML>
__END_OF_HTML_CODE__
                                exit;
                                }
                undef $BytesRead;
                undef $Buffer;
                while ($Bytes = read($File_Handle,$Buffer,1024))
                        {
                        $BytesRead += $Bytes;
                        print OUTFILE $Buffer;
                        }
                push(@Files_Written, "$SAVE_DIRECTORY\/$Filename");
                $TOTAL_BYTES += $BytesRead;
                $Confirmation{$File_Handle} = $BytesRead;
                close($File_Handle);
                close(OUTFILE);
                chmod (0444, "$SAVE_DIRECTORY\/$Filename");
                }
        fi
}
        $FILES_UPLOADED = scalar(keys(%Confirmation));
        print header;
        print <<__END_OF_HTML_CODE__;
<HTML><HEAD><TITLE>Upload Finished</TITLE></HEAD><BODY BGCOLOR=396DA5><H3>Upload Finished</H3><P>You uploaded <B>$FILES_UPLOADED</B> files totalling <B>$TOTAL_BYTES</B> total bytes.  Individual file information is listed below:<PRE>
__END_OF_HTML_CODE__
        foreach $key (keys (%Confirmation))
                {
                print "$key - $Confirmation{$key} bytes\n";
                }
        print <<__END_OF_HTML_CODE__;
</PRE><P><A HREF="https://www.domain.com">www.domain.com</A> - <A HREF="https://upload.domain.com/upload.html">Upload Files</A> - <A HREF="https://upload.domain.com/">Browse Upload Folder</A></BODY></HTML>
__END_OF_HTML_CODE__
exit;

}
# ---------------------------------------------------------------------
# EOF


hotrodowner 03-27-2003 06:50 AM

I dont have perl on the computer because both computers are running Windows XP. I trust linux software above any other, and believe the linux programmers know exactly what they're doing. However, I need this cabability from two windows computers. I installed a windows version of openssh and apache. That is why sftp didn't work, and I needed apache to do the file management. But this means that the cgi script you gave me wont work. Is there another way to upload files to my windows apache web server?

DavidPhillips 03-27-2003 10:39 AM

now I'm confused :)

Quote:

Router headaches ( post #1)

My Linux server is on my school's network. But I want to access it at home.

DavidPhillips 03-27-2003 10:43 AM

if you have ssh you can still do ftp to the internet from the ssh login. The computer on the internet has to be the server.


You could get an account on a server that has ftp upload, then you would not need to run an ftp server and you could still share files through it.

DavidPhillips 03-27-2003 10:50 AM

if you simply must have a gui then run vnc and tunnel it through ssh

once you are connected you can do anything you want, including using a gui ftp program to send file to or receive from an ftp server.


I think I would just type `ftp user:password@ftp.domain.com` into a dos prompt and get on with it.

viewing the desktop over a slow connection is going to be painful.

SlickWilly 03-27-2003 02:19 PM

Urm... don't want to butt in on this...

But there's a GUI version of scp :)

ssh.com recently released their ssh for Workstations for non-commercialy use free.

You can download it here :

http://www.ssh.com/support/downloads/secureshellwks/

and it has a very nice GUI scp program that integrates well with it. :)

Slick.

hotrodowner 03-27-2003 02:41 PM

The situation has changed from when I first started this thread. At first I wanted to access my server at home, now my teacher wants to access his windows xp computer at home, with the best security possible. The windows version of openssh does support sftp, only remote command prompt. But it the thing you said first about the ssh -R 8080:localhost:8080 <ip of home compuer> worked, and now I want to send files back and forth between the two computers. I tried IIS ftp, but it wouldn't work because it gave invalid syntax commands. I tried IIS web server, but could only get the anonymous user to work. I need more security. So I downloaded the new appache web server for windows and installed it. Now I have apache working on port 8080, and it denys everyone but 127.0.0.1, however, I now needs a means of having the web server upload files from the home computer, back to the <hidden behind school routers> work computer. I looked at your upload.cgi script, and noticed you were using perl for uploads. When I try to upload files, it just times out. I need another cgi script that is compatible with windows software. Thank you so much for your help so far!!!!!!!!!!!!

DavidPhillips 03-27-2003 04:13 PM

if the windows version of ssh works for forwarding http then there should be no problem using scp.

I believe I would go with that over trying to establish an http upload.

scp is much more of a suitable protocol for file transfer than http.


The same idea would apply. you would forward the ssh port and connect to the local port with scp

scp is secure copy and is a lot like sftp.

DavidPhillips 03-27-2003 04:17 PM

You will need CGI.pm for the script to work

There may be other scripts available for this.

I am sure you can do it with http if you must do it that way. cgi-bin works with most any platform

DavidPhillips 03-27-2003 04:58 PM

have you tried this
on the external client
local port 21
host internal client
remote 21
connect to local machine with any ftp program
you may need passive mode
make sure ftp server is working on the internal machine by trying to connect to it locally ( 127.0.0.1 )


ok I thought about this again

it will not work because you do not have an ip address to connect to


hotrodowner 03-27-2003 06:47 PM

yeah, the ftp over ssh thing is the first thing I tried. How would I use scp? Here the url to the ssh version I am using:
http://lexa.mckenna.edu/sshwindows/
I use WinSCP for my file transfers on my linux computers, but it doesn't work on windows. I though scp and sftp was the same thing?

Anyways, when I try to connect to my xp ssh server with winSCP, it ask me for my password <which is normal>, but then it gives the following error message:

______________________________

Error skipping startup message.

Can't detect command return code.
_______________________________

Do you know of any true <and free> sftp clients, or how to fix this problem?

DavidPhillips 03-27-2003 08:54 PM

The way it will need to work is the internal machine will need to make the connection, and if the connection is lost it will need to reistablish it. Otherwise everytime the connection is lost due to one of the machines going offline you would need to go and reconnect from the internal machine.

This may not be as easy to do with a system running windows. However it may be possible with scripts. You would need a specially designed app or something that can be run from another app you would need to create.

The machine that the internal machine is connected to will have it's local port connected to the internal machines port that you have a service running on that you plan to use. This may be anything that supports file transport.

This again is not as easy to do with windows as it would be with linux. It as well may be possible.

What you need is a windows solution to your problem.

If you decide to go with linux on the inside and have it connect to an outside ssh server this can be easily done as I have posted. I have tried this and it works great.

Using windows, I would say have the windows machine send all of the files somewhere on the internet on a regular basis using some scripting tool and get them that way. Or get an ip address for the internal machine.


I guess Linux has shown again just how powerful it is.

hotrodowner 03-27-2003 09:01 PM

I cann't have them upload to the internet, or give it it's own ip. You mean you have no solution to make the direct communication work; is there nothing I can do to upload files on http?

DavidPhillips 03-27-2003 09:14 PM

yes you can do cgi or php, I'm sure there are windows file upload programs.

here are a few of them

http://cgi.resourceindex.com/Program...ile_Uploading/


There's also a few thousand php solutions linked from there.


http://php.resourceindex.com/Complet...le_Management/

DavidPhillips 03-27-2003 09:18 PM

Do you have the "file download" part worked out?

hotrodowner 03-27-2003 09:35 PM

Yes, I can download files across the ssh connection with apache on port 8080. And it's set to deny connections to 10.255.255.255, and 192.168.255.255. I did blocked them so noone on this side of the router would get in <inputing "deny from all" would deny everything, even what I put after "accept from **" attribute. I told it to "accept from 127.0.0.1". I set the home directory as "Documents and Settings" and now he can gain access to all the user accounts from home. He just needs to upload files now, and we'll be done. <I think he may want me to figure out how to login to novell across ssh next...but I might just say forget that>

DavidPhillips 03-27-2003 09:38 PM

I think cgi would be simplier, but the php links look promising.

DavidPhillips 03-27-2003 09:49 PM

probably the best way to block access would be by location in apache

Order deny,allow
deny from all
allow from 127.0.0.1



if you want to firewall the system you could selectively block anything you want that way

DavidPhillips 03-27-2003 09:51 PM

https can be used to secure the connection, .htaccess could require a password.


All times are GMT -5. The time now is 06:07 PM.