LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 04-17-2006, 11:52 PM   #1
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Rep: Reputation: 30
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?
 
Old 04-18-2006, 05:11 PM   #2
pdeman2
Member
 
Registered: Jul 2005
Location: Maine, USA
Distribution: OpenSUSE, Gentoo, Fedora, Ubuntu, Mandriva, others
Posts: 413

Rep: Reputation: 30
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 05:17 PM.
 
Old 04-18-2006, 05:29 PM   #3
avarus
Member
 
Registered: Apr 2004
Location: Oxford, UK
Distribution: Ubuntu, Debian, various
Posts: 230
Blog Entries: 5

Rep: Reputation: 33
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
 
Old 04-18-2006, 05:40 PM   #4
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Original Poster
Rep: Reputation: 30
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>
 
Old 04-18-2006, 05:48 PM   #5
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Original Poster
Rep: Reputation: 30
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 05:49 PM.
 
Old 04-18-2006, 05:55 PM   #6
pdeman2
Member
 
Registered: Jul 2005
Location: Maine, USA
Distribution: OpenSUSE, Gentoo, Fedora, Ubuntu, Mandriva, others
Posts: 413

Rep: Reputation: 30
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>";
?>
 
Old 04-18-2006, 06:07 PM   #7
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Original Poster
Rep: Reputation: 30
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!
 
Old 04-18-2006, 06:14 PM   #8
avarus
Member
 
Registered: Apr 2004
Location: Oxford, UK
Distribution: Ubuntu, Debian, various
Posts: 230
Blog Entries: 5

Rep: Reputation: 33
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
 
Old 04-18-2006, 07:24 PM   #9
pdeman2
Member
 
Registered: Jul 2005
Location: Maine, USA
Distribution: OpenSUSE, Gentoo, Fedora, Ubuntu, Mandriva, others
Posts: 413

Rep: Reputation: 30
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.
 
Old 04-19-2006, 12:09 AM   #10
paul_mat
Member
 
Registered: Nov 2004
Location: Townsville, Australia
Distribution: Fedora Core 5, CentOS 4, RHEL 4
Posts: 855

Original Poster
Rep: Reputation: 30
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...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge Of Html Files Into A Single Html (or Pdf) fiomba Linux - Software 10 05-11-2018 11:28 AM
Send HTML mail via command line interface xlash Linux - General 2 11-02-2005 01:02 PM
html code and including html files Hockeyfan Programming 2 08-22-2005 05:11 PM
how to convert text(html) back to html. d1l2w3 Linux - Software 4 04-08-2005 08:16 PM
Konqueror + file:/usr/share/doc/HTML/index.html jon_k Linux - Software 2 11-25-2003 05:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration