Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-18-2006, 12:52 AM
|
#1
|
Member
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855
Rep:
|
HTML interface for mounting a CD
hi there,
I'm looking for something really simple.
Basically what I want is to be able to go to http://ip-addresss and have be able to mount a CD by clicking on a button, can someone tell me how to do that? is it a simple bit of code? written with cgi or something?
|
|
|
04-18-2006, 06:11 PM
|
#2
|
Member
Registered: Jul 2005
Location: Maine, USA
Distribution: OpenSUSE, Gentoo, Fedora, Ubuntu, Mandriva, others
Posts: 413
Rep:
|
This can be done with a simple CGI program or PHP script or something. In PHP it is very easy to execute commands. If you want to use third party software, you should take a look at Webmin. I don't know if there is a simple button that you can press in webmin, but it has many other similar tools.
As far as writing a PHP script, you could just have a simple html page with a link on it to the PHP script that would mount the CD. That PHP script could look something like this:
Code:
<?php
$code_output = `mount /dev/cdrom /media/CD`;//Or whatever you use
echo $code_output;//Or you could include this output in a neat html interface
?>
I don't have PHP on the machine I'm using right now, but I'm 75% positive that code would do what you want. You could also do pretty much the same thing with perl or something.
Edit:
If you don't want output after executing the command, you could do this:
Code:
<?php
exec('mount /dev/cdrom /media/CD');
?>
Last edited by pdeman2; 04-18-2006 at 06:17 PM.
|
|
|
04-18-2006, 06:29 PM
|
#3
|
Member
Registered: Apr 2004
Location: Oxford, UK
Distribution: Ubuntu, Debian, various
Posts: 230
Rep:
|
Hi,
I'm intrigued as to why you would want to do this. I write a lot of CGI and once you get Apache (or whatever) configured then it is just a matter of something like a five-line Perl script in the cgi-bin directory (or indeed an even shorter bit of PHP).
Code:
#!/usr/bin/perl
use CGI qw(:standard);
if param('mount')
{
system('mount /mnt/cdrom');
}
else
{
print "
slap your HTML page with form in here
";
}
(I don't promise this is actually valid Perl)
I assume from looking at your site that you have a pretty good idea what configuring Apache and giving the apache user permissions to mount the device (or else using sudo or suexec) will entail. But then what? You want to read the CD, allow other users to read it, unmount it again, check if it is mounted or not? Or do you just want to make the tray go in and out? Who is going to access the page? Does it need any security?
Cheers,
TIM
|
|
|
04-18-2006, 06:40 PM
|
#4
|
Member
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855
Original Poster
Rep:
|
okay thats just what i'm looking for but i'm clearly not getting it right. This is what i've done to test out either of them and it's not working, can you tell me what i'm doing wrong?
<HTML>
<HEAD>
<script type="text/javascript">
function mount1()
{
<?php
$code_output = `mount /dev/cdrom /media/CD`;//Or whatever you use
echo $code_output;//Or you could include this output in a neat html interface
?>
}
function mount2()
{
<?php
exec('mount /dev/cdrom /media/cdrom');
?>
}
</script>
</HEAD>
<BODY>
<button onclick="mount1()">mount1</button>
<button onclick="mount2()">mount2</button>
</BODY>
<HTML>
|
|
|
04-18-2006, 06:48 PM
|
#5
|
Member
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855
Original Poster
Rep:
|
i'm looking at making an internel page, with auth required to access it and when I put a CD in my server i'm going to be able to login to this page and click a few buttons and what i want it to do is mount the drive, copy the contents of the drive to a folder & make a samba share, so the other network admins can access CD's across the network and mount them and all the rest without any *nix knowledge, i'm the only network admin here that knows anything about linux, so i have to make it pretty simple for the rest of them.
Thats why i really want to know how to get a cgi script that exec server side scripts, like being able to exec this script.
'mount /dev/cdrom /media/cdrom'
ps: i've just tried your perl script, all the permissions were right, but i get this error message.
500 Internal Server Error
Last edited by paul_mat; 04-18-2006 at 06:49 PM.
|
|
|
04-18-2006, 06:55 PM
|
#6
|
Member
Registered: Jul 2005
Location: Maine, USA
Distribution: OpenSUSE, Gentoo, Fedora, Ubuntu, Mandriva, others
Posts: 413
Rep:
|
I've never written PHP embedded in an HTML page, so I would recommend keeping the PHP script separate from the HTML page you wrote. I would have it set up so that there was simply a link on the HTML page to the PHP script. For the PHP page, you could write something like:
Code:
<?php
$code_output = `mount /dev/cdrom /media/cdrom`
echo "<html><head></head>
<body>
<b>The CD has been mounted:".$code_output."</b>
</body>
</html>";
?>
|
|
|
04-18-2006, 07:07 PM
|
#7
|
Member
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855
Original Poster
Rep:
|
I've made the php page just like you said above and it's not working ... thats all i put on the page thinking that would work, is that right? can you should be just what i should past into a page?? i suck at coding! so treat me like a real newbie!
|
|
|
04-18-2006, 07:14 PM
|
#8
|
Member
Registered: Apr 2004
Location: Oxford, UK
Distribution: Ubuntu, Debian, various
Posts: 230
Rep:
|
Hi Paul,
I seem to get in trouble for saying this to people, but the fact that you are confusing server side PHP and client-side JavaScript tells me that you really, really need to read a primer on CGI and/or PHP. Any book will do, but you need more than just some hints from this forum.
As for your specific problem, I'd avoid the web route. CGI interfaces are great for the user but a real pain for you. I'd script up the things you need to do in Bash or Perl and have the person log into the server with PuTTY and then run your script. Yes the text looks ugly (to a windows user), but your life is soooo much easier. You can even give them a desktop icon which runs the whole thing with no typing of commands required.
But that's just my opinion.
TIM
|
|
|
04-18-2006, 08:24 PM
|
#9
|
Member
Registered: Jul 2005
Location: Maine, USA
Distribution: OpenSUSE, Gentoo, Fedora, Ubuntu, Mandriva, others
Posts: 413
Rep:
|
paul_mat, you're right, I must be missing something in that PHP script. It seems to run fine in terminal, but it does not work with Apache. Anyway, I would strongly suggest looking into Webmin. I used to be sceptical about it, but then I installed it on my server. It has made remote configuration and other things so much easier.
|
|
|
04-19-2006, 01:09 AM
|
#10
|
Member
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855
Original Poster
Rep:
|
I know, i use webmin all the time, but i'm not looking at using webmin, i'm working on a bit of a project and i need to be able to mount a drive from a web interface to be able to do it.
unless you can have a look in the webmin code and tell me how webmin does it, i've already tried to look but i can't see anything...
|
|
|
All times are GMT -5. The time now is 11:50 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|