Upload file button for remote files - html

Here's the scenario. I have a simple browse button. Right now, it opens up the folder hierarchy on my local computer. (PC).
However, I want to pick a file from a remote unix server which I have access to. Is there a way to display the file hierarchy of the remote unix server WITHOUT having to mount the drive?
Are there other options other than using a java applet?
Thanks,
Michael

If you don't really want an applet you can do it server-side in PHP by using this something like this to let the user select a folder:
<?php
$connection = ssh2_connect('host', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, 'ls -a --file-type');
?>
Just parse the $stream variable to identify the folders (the ones ending with /) and present them in a table.
I guess this solves your problem. If you want the user to upload a file just put a simple file upload field, Once the user have selected a folder and uploaded a file in a temporal location in the server just move it with SSH too:
<?php
$connection = ssh2_connect('host', 22);
ssh2_auth_password($connection, 'username', 'password');
ssh2_scp_send($connection, '/temporal/filename', '/remote/filename');
?>
For getting this working you need to have enabled SSH2 libraries for PHP in your server.

Don't know how it is in Unix, but in Windows, you can either map a drive letter to remote path, or simply type the remote path in the browse dialog (\\server\share\filename)

Instead of using the regular input type file, invoke a Java applet. You can use VFS from apache to access your UNIX machines. VFS API supports many file access protocols.
http://commons.apache.org/vfs/filesystems.html

A friend of mine recommended Samba:
http://us3.samba.org/samba/
It apparently lets you link a unix server as a windows file/print server, which should show up in a file browser. :)

I don't know why; I've had much difficulty with installing anything on the solaris machine. So i've decided to go a slightly different route -- I found out that the machine is already mounted properly, so I can simply switch user accounts to access what I need -- without SSH.

Related

How can I disable direct access to a folder html page?

Heres the scenario: In the root of the server i have an folder named "data".
In this folder is a file named "random-file.html". Now I want, that you can't see the contents of the folder "data" if you type "domain.com/data/" but you have access to the file "random-file.html" and can it.
Sure you can. You can hide it using .htaccess. I assume you use xampp server. You can see this [1] https://www.opentechguides.com/how-to/article/apache/115/htaccess-file-dir-security.html
If I recall correctly, the most secure practice is to keep sensitive files outside the root of your webserver all together. Create a folder on the VM or server which your app is hosted and have your application read/write/use it from there.
Most serverside frameworks/tools have a "websecrets" type functionality you could use. But this step above is my 'framework agnostic' advice.

HTML code to open PuTTY client from browser

I am trying to make a webpage which will have the entire inventory of servers that our team manages in the form of a table. I am using a simple LAMP stack and the inventory input as a CSV file.
The table has three columns: Hostname, IP address and device serial number.
While this works perfectly fine, I want to take this a step further and make every IP address in the table a hyperlink, clicking which will open an SSH client, which will connect to that IP address. Any cues to how this can be done? I was hoping there would be something like the the mailto: tag which opens an email client (Outlook window).
I've done it following the info of this blog post.
For future reference in case the original page becomes missing, here is the process:
you cannot directly map the ssh:// scheme to PuTTY, but you can map it to an intermediary script which will in turn launch PuTTY with the right arguments. Mine is called putty_ssh.bat and has the following content:
#echo off
set var=%1
set extract=%var:~6,-1%
start "C:\Program Files (x86)\PuTTY\putty.exe" %extract%
the script has to be registered in the registry. You can just create a ssh.reg file with the following content and open it (customizing last line as needed):
REGEDIT4
[HKEY_CLASSES_ROOT\ssh]
#="URL:ssh Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\ssh\shell]
[HKEY_CLASSES_ROOT\ssh\shell\open]
[HKEY_CLASSES_ROOT\ssh\shell\open\command]
#="\"C:\\path\\to\\putty_ssh.bat\" %1"
When I click on ssh:// links in web pages, it now opens PuTTY.
PuTTY unfortunately does not associate itself with the ssh:// or any other URLs.
You can associate an application with a protocol manually. But it's not trivial. For instructions, see below.
Easier way is to install WinSCP SFTP client. WinSCP 5.9 and newer registers itself to handle the ssh:// URL and opens the session specified by the URL in PuTTY.
So basically, if you just install WinSCP, it will make PuTTY handle the ssh:// URLs, without the below manual tweaks.
(I'm the author of WinSCP)
To register an application manually, see the MSDN article Registering an Application to a URI Scheme.
Basically you add a registry key like:
[HKEY_CLASSES_ROOT\ssh]
#="URL: SSH Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\ssh\DefaultIcon]
#="\"C:\\Program Files (x86)\\PuTTY\\PuTTY.exe\",0"
[HKEY_CLASSES_ROOT\ssh\shell]
[HKEY_CLASSES_ROOT\ssh\shell\open]
[HKEY_CLASSES_ROOT\ssh\shell\open\command]
#="\"C:\\Program Files (x86)\\PuTTY\\PuTTY.exe\""
Though the above passes a whole URL to the PuTTY command-line. And PuTTY does not understand the ssh:// prefix. So you would have to add a wrapper script that strips the ssh:// and passes only a user and a host to PuTTY.
For that see:
https://johnsofteng.wordpress.com/2009/05/12/launch-putty-from-browser/

How do you open a remote sqlite database over http?

Is it possible to open an sqlite file over http? I only need to read the db, and was hoping I could do something like:
var dbFile:File = new File("http://10.1.1.50/project/db.sqlite");
sqlConnection.open(dbFile);
Error #3125: Unable to open the database file.', details:'Connection closed.', operation:'open', detailID:'1001'
My situation calls for several apps compiled for various devices to share this file, which is served locally via wamp.
Zip your sqlite file from db.sqlite to db.zip. Load this zip file in flex using URLLoader and unzip it back in flex.
If not, you can also rename the file's extension to .xml, load it using httpservice or urlloader and once you get the result, you can rename the file's name back to .sqlite and start querying the file and it will work just fine.
There is no way you can achieve this over HTTP.
SqLite is a file and not a service/process that may be accessible via any port.
The best case scenario is when you have network access to the computer where the sqlite file is stored, like:
\\myserver\databases\mysqlitefile.db
...but this may work only on windows :(
You can adapt your code to use modsqlite http://modsqlite.sourceforge.net/#using
there's an apache module to allow remote sqlite access via http.
http://modsqlite.sourceforge.net/

MAMP htdocs phpinfo

I am trying to get a simple phpinfo() to print out on my local server (using MAMP). I made a new directory in /Applications/MAMP/htdocs (php_sandbox) and put a file in there named my_phpinfo with only phpinfo() in it. How can I view the contents of this file in my web browser?
Is it also advisable if I set the Apache document root to be in my home directory/sites? I will be mainly using this local server to test/host some small sites.
Thanks!
visit in your browser localhost/my_phpinfo/index.php assuming you named the file with
<? phpinfo();?> is in index.php. Also, make sure you are editing the correct php.ini in your MAMP directory by checking your mamp prefs and seeing what version of php MAMP is using.
Your in the right folder by default from what I remember. MAMP runs apache on port 8888 by default. You should be able to go to http://localhost:8888/ You can also get to this page via the control panel (should have a button to open home page). This page will also show you've configured MAMP's Apache to run on a different port.
Whatever you name your file; you'll want to give it a .php extension, so if you file is named my_phpinfo, add a .php so it becomes my_phpinfo.php. Make sure you function called is wrapped in php tags like so
<?php phpinfo(); ?>
If this file is directory in the htdocs folder you should be able to go to http://localhost:8888/my_phpinfo.php and get the PHP Info page.
As far is moving the directory. I normally do. Especially b/c it makes upgrading MAMP a little easier (already have to worry about MySQL). You might have to tweak the file permissions just a bit to make sure it runs correctly. I believe though you should be okay since it is running as your User.

How to use GVIM to edit a remote file?

I use GVIM on Ubuntu 9.10. I'm looking for the right way to configure GVIM to be able to edit remote files (HTML, PHP, CSS) by for exemple ftp.
When i use :e scp://username#remotehost/./path/to/file i get: error detected while processing BufEnter Auto commands for "*":E472: Command failed.
When i open a file on remote via Dolphin or Nautilus, i cannot use other files with NERDTree.
Finally when i edit on remote a file via Dolphin the rights are changing to access interdit.
So how to use GVIM to edit remote files like on my localhost?
I've found running the filesystem over ssh (by means of sshfs) a better option than having the editor handle that stuff or running the editor itself over an ssh tunnel.
So you need to
apt-get install sshfs
and then
sshfs remoteuser#remotehost:/remote/path /local/mountpoint
And that will let you edit your remote files as if they were on your local file system.
To make it even smoother you can add a line to /etc/fstab
sshfs#remoteusername#remotehost:/remote/path /local/mountpoint fuse user,noauto
For some reason I find that I have to use fusermount -u /local/mountpoint rather then just umount /local/mountpoint when experimenting with this. Maybe that's just my distro.
Recently I've also noted that the mounting user must be in the fuse group. So:
sudo addgroup <username> fuse
An other popular option of course, would be to run vim (rather then gvim) inside a GNU Screen session on one machine and connect to that session via ssh from wherever you happen to be. Code along all day at work and in the evening you ssh into your office computer, reattach to your gnu screen session and pick up exactly where you left off. I used find the richer color palette to be the only thing I really missed from gvim when using vim, but that can actually be fixed thanks to a fork of urxvt that will let you customize the entire 256 position color palette, not just the 16 first positions of the palette that most terminal emulators will let you customize.
There is one way and that is using the remote host's copy, using SSH to forward the X11 client to you, like so:
user#local:~/$ ssh -X user#host
...
user#host:~/$ gvim file
The latter command should open gvim on your desktop. Of course, this relies on the remote host having X11 / gnome / gvim installed in the first place, which might not be the solution you're looking for / an option in your case.
Note: X11 forwarding can be a security risk.
In order for netrw to work seamlessly, I believe you need to not be in compatibility mode.
Try
:set nocompatible
then
:edit scp://host/path/to/file
Try this
:e scp://username#remotehost//path/to/file
Note that the use of // is intentional after remotehost it gives the absolute path of your file
:)
http://www.celsius1414.com/2009/08/19/how-to-edit-remote-files-with-local-vim/
The vim tips wiki has an article on this, Editing remote files via scp in vim.
EDIT: Key authentication is not necessary for opening files over ssh. Vim will prompt for password.
It would be useful to note if netrw.vim was loaded by vim when it started.
:echo exists("g:loaded_netrwPlugin")
For opening files over ssh, you need your local machine's public key in the server's authorized keys. Following help section in vim documentation explains it pretty well.
:help netrw-ssh-hack
Quick way to export public key would be by using ssh-copy-id (if available).
ssh-copy-id user#host
And have a look at netrw documentation for network file editing over other protocols.
:help netrw
HTH.
According to the docs BufEnter is processed after the file has been read and the buffer created, so my guess is that netrw successfully read the file but you have a plugin that assumes the file is on the local filesystem and is trying to access it, e.g. to run ctags.
Try disabling all your plugin scripts except the default Vim ones, and then editing the file.
Also, try editing a directory to see if netrw can read that - you need to put the / on the end so that netrw knows it is a dir.
About your command, :e scp://username#remotehost/./path/to/file : note that with netrw, scp is taken relative to your home directory on that remote host. To avoid home-relative pathing, drop that "."; ie. :e scp://username#remotehost//path/to/file .
to accomplish this on windows download/install the Dokan library and Dokan SSHFS, which are the first and last links on this page.
I didn't think you were going to be able to directly edit a remote file using GVIM running locally. However, as others have pointed out, this is defintiely possible. This looks very interesting; I will check this out. I will leave the rest of my post up here, in case it is useful to anyone else, as an alternative method. This method will work even if you don't have SSH access to the file (ie, you only have FTP, or S3, or whatever).
You may get that effect, though, by tying GVIM into a graphical file transfer application. For example, on OS X, I use CyberDuck to transfer files (FTP, SFTP, etc). Then, I have it configured to use GVIM as my editor, so I can just double-click on a file in the remote listing, and CyberDuck will download a copy of that remote file, and open it in GVIM. When I save it in GVIM, CyberDuck uploads the file back to the remote host.
I'm sure that this functionality is not unique to CyberDuck, and is probably present in most nicer file transfer utilities.