LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Adding users with PHP (pass php variables to Expect script) (https://www.linuxquestions.org/questions/programming-9/adding-users-with-php-pass-php-variables-to-expect-script-493898/)

Jayla 10-19-2006 01:35 PM

Adding users with PHP (pass php variables to Expect script)
 
Hi there, I could't find an answer already here so I've made a post, forgive me if the answer is here but I couldnt find it.

Ok so here goes, I have a php page that takes a username in( from textbox), i want to send that username thru to an Expect script

The expect script will log in as root, add the user, do whatever else i decide, then switch out of root.

heres what I've come up with so far...

The first page, with the form that takes in the username
Code:

<html>
<head>
<title>Assignment</title>
</head>

<body>

<h1>The worst User management ever...</h1><p>
<form name="userdata" action="process.php" method="post">
Username:<input name="username" type="text"><br>
Password:<input name="password" type="text"><br>
Message:<br>

<br>
<input type="submit">
</form>
</body>
</html>


The username gets passed into this php file, and echoed back on the screen for confirmation, this part works fine
Code:

<html>
<body>

<?php
$username = $_POST['username'];
$password = $_POST['password'];
//$username = "jack";
//$password = "1234";

//error_reporting(E_ALL);

//Run some linux script to actually ADD the user, only passing 1 var till //i can work it out

exec("/opt/lampp/htdocs/wse/adding.exp". $username);

//print($bashreturn);
echo "Your Username is ". $username .".<br>";
echo "Your Password ir ". $password .".<br>";


?>
<p>
<a href="index.html">Go back and try again</a>
</body>
</html>


the username should be sent here, then added to the linux box, but this doesn't work
Code:

#! /usr/bin/expect -f

username=$1

set force_conservative 0

spawn su
match_max 100000
send -- "password\r"
send -- "useradd username\r"
send -- "exit\r"
expect eof

I think that the initial data is being passed to the second php file becuase it is echoed back on screen, but as for being sent to the exp script I have no idea

Can someone please help me solve this problem, I'm having little luck finding tutorials/solutions on the internet

Thank you for your time

J

senyahnoj 10-20-2006 10:44 AM

At a glance, you would need a space between adding.exp and $username

So change

PHP Code:

exec("/opt/lampp/htdocs/wse/adding.exp"$username); 

to

PHP Code:

exec("/opt/lampp/htdocs/wse/adding.exp "$username); 

I don't know anything about expect but the PHP looks alright to me. You can get the browser to display the output from your exec command like this:

PHP Code:

exec($cmd,$out);
print(
implode("<br>",$out)); 



All times are GMT -5. The time now is 01:38 AM.