Forum Moderators: bakedjake

Message Too Old, No Replies

$var in mkdir

         

Alterm

4:04 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



Hello everyone
Im having some troubles with an admin script
i want to make new dirs using php

apache ALL = (root) NOPASSWD: /bin/mkdir

<?php
exec("/usr/bin/sudo /bin/mkdir newdir");
?>
this will make me a new dir called newdir but! how do i do this with a variable

//mkdir.php
<?php
exec("/usr/bin/sudo /bin/mkdir $name");
?>

//make.html
<html><head><body><form action="mkdir.php" method="post">
New Dir:
<input type="text" name="name">
<input type="submit" value="Submit!"></form>

</body>
</head>
</html>
what do i do wrong here?

MattyMoose

7:05 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



This should actually be directed at the PHP forums, but the short answer to your problem is probably that you're using $name, and not extracting the variable from the POST array first.

ex:


<?php
$name = $_POST['name'];
exec("/usr/bin/sudo /bin/mkdir $name");
?>

A few notes about what you're doing:

* sudo isn't a good idea. There's got to be another way to do it with permissions.
* You should clean up any use-inputtable data. So, your $name should be cleaned up to prevent anything unsavoury happening. I know that your sudoers only allows them to execute /bin/mkdir, but remember that the exec is still happening without any input being scrubbed, so someone could pass along some bad data to your script. Imagine something like "myuselessdir;rm -rf /var/www/*" being passed. You should account for things like that. Limit the script to only use the first thing with spaces (although that's not so fantastic either).

Anyway, food for thought.

MM

Alterm

7:27 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



thnx for the quick reply
I see ur point :)

in short the thing i trie to do is ;
from a webbrowser

1.add a dir
#mkdir newdir

2.copy a executable file in that dir
#cp main/file newdir/file

3.create a text file online and save it as .cfg in that dir file.conf

4.execute the executable in that dir
#./file

do u have any ideas how to do this saver