php form to run gam

568 views
Skip to first unread message

rama1200

unread,
Oct 15, 2013, 2:11:56 PM10/15/13
to google-ap...@googlegroups.com
I'm trying to create a php page to run gam in the background.
the page runs on debian, apache2, php 5.4.4
I have a one field form asking for the usersname; the user input the username in the field, then submits..
then on submit, the form runs on the background (/usr/bin/python2.7 /opt/google-provisioning/voffice/gam.py info user $jnum)... ideally, i would see the userinfo, but I get:
"Want to learn more about Dito? Hit Y to visit our website (you can switch back to this window when you're done). Hit Enter to continue without visiting Dito:"

when I run the same command via the command line i do get the user info...

I have created a noupdatecheck.txt file, but no luck....

any ideas?

Thanks

rama1200

unread,
Oct 15, 2013, 2:20:39 PM10/15/13
to google-ap...@googlegroups.com
Forgot to ask.. is there an option to run "silently"? I thought that is what the noupdatecheck.txt file would do in this case...

Thanks

Colin Matheson

unread,
Oct 15, 2013, 3:09:12 PM10/15/13
to google-ap...@googlegroups.com
Hmm. I am not sure if I can help you, but I have created a php page that runs gam.
Here is my working code snippet.

$pythonCommand1 = "python gamHigh/gam.py update user $USER->username password $data->newpassword1";

exec($pythonCommand1);

rama1200

unread,
Oct 15, 2013, 5:58:59 PM10/15/13
to google-ap...@googlegroups.com
Thanks, Colin.
I tried that, but got:
"Notice: Undefined variable: jnum in /var/www/test.php on line 6

Notice: Trying to get property of non-object in /var/www/test.php on line 6"


$command = "/path-to-python/python2.7 /path-to-gam/gam.py info user $jnum->jnum";
exec($command);

What are the "->" ?
----


This is my full code:

<html>
<?php
if(isset($_POST['submit']))
{
$timestamp = (`date +'%Y%m%d%k%M%S'`);
echo $timestamp;
echo "<br>";
echo exec('/path-to-python/python2.7 /path-to-gam/gam.py info user [`$jnum`]');
} else {
?>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>" >
echo Jnumber <input type="Text" name="jnum" value="">
<input type="submit" name="submit" value="CLICK ME" >
</form>
<?php } ?>
</html>



when I use the "echo" in the exec line I get: "20131015165447
Want to learn more about Dito? Hit Y to visit our website (you can switch back to this window when you're done). Hit Enter to continue without visiting Dito:"

If I remove the echo I just get the "20131015165447"

Colin Matheson

unread,
Oct 15, 2013, 6:39:49 PM10/15/13
to google-ap...@googlegroups.com
The arrows are because my code was reading a variable from an object that has several variables stored in it. So you shouldn't need those and should just pass $jnum

Also you are getting the variable $jnum incorrectly. You need to use $_POST['jnum']

Then in the exec you sould put an output variable which will be an array.

This code works for me


<html>
<?php
if(isset($_POST['submit']))
{
$timestamp = (`date +'%Y%m%d%k%M%S'`);
echo $timestamp;
echo "<br>";
echo $_POST['jnum'];
echo "<br>";
$myString = '/path/to/python /path/to/gam.py info user ' . $_POST['jnum'];
echo $myString;
echo "<br>";
echo exec($myString, $output);
echo "<br>";
foreach ($output as $value){
    echo $value;
    echo "<br>";   
}

} else {
?>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>" >
echo Jnumber <input type="Text" name="jnum" value="">
<input type="submit" name="submit" value="CLICK ME" >
</form>
<?php } ?>
</html>


rama1200

unread,
Oct 16, 2013, 10:16:43 AM10/16/13
to google-ap...@googlegroups.com
Thanks for help, Colin.

I see about the ->... I forgot about objects..

I tried the new code... still not luck...

20131016 90809 
j00099899
/usr/bin/python2.7 /opt/google-provisioning/students/gam.py info user j00099899

Want to learn more about Dito? Hit Y to visit our website (you can switch back to this window when you're done). Hit Enter to continue without visiting Dito:


GAM is made possible and maintained by the work of Dito. Who is Dito?

Dito is solely focused on moving organizations to Google's cloud. After hundreds of successful deployments over the last 5 years, we have gained notoriety for our complete understanding of the platform, our change management & training ability, and our rock-star deployment engineers. We are known worldwide as the Google Apps Experts.


Want to learn more about Dito? Hit Y to visit our website (you can switch back to this window when you're done). Hit Enter to continue without visiting Dito:



I'll keep you researching

rama1200

unread,
Oct 16, 2013, 10:24:46 AM10/16/13
to google-ap...@googlegroups.com
funny... I meant to write: "I'll keep you posted and I continue researching"..... not "i'll keep you researching"...


On Tuesday, October 15, 2013 1:11:56 PM UTC-5, rama1200 wrote:

rama1200

unread,
Oct 16, 2013, 12:28:35 PM10/16/13
to google-ap...@googlegroups.com
Colin, did you have to change the permissions of the oauth2.txt file so that the webuser (apache user) could read it?
mine are:
-rw------- 1 root root 2116 Oct 16 11:15 oauth2.txt

and are some entries from the /var/log/apache2/error.log:


"visit_dito = raw_input("Want to learn more about Dito? Hit Y to visit our website (you can switch back to this window when you're done). Hit Enter to continue without visiting Dito: ")
EOFError: EOF when reading a line
Traceback (most recent call last):
 File "/path-to-gam/gam.py", line 5806, in <module>
    doGetUserInfo()
  File "/path-to-gam/gam.py", line 3663, in doGetUserInfo
    cd = buildGAPIObject('directory')
  File "/path-to-gam/gam.py", line 447, in buildGAPIObject
    doRequestOAuth()
  File "/path-to-gam/gam.py", line 5620, in doRequestOAuth
    visit_dito = raw_input("Want to learn more about Dito? Hit Y to visit our website (you can switch back to this window when you're done). Hit Enter to continue without visiting Dito: ")
EOFError: EOF when reading a line







On Tuesday, October 15, 2013 1:11:56 PM UTC-5, rama1200 wrote:

Colin Matheson

unread,
Oct 16, 2013, 3:28:45 PM10/16/13
to google-ap...@googlegroups.com
That text that is printed out is the first run text. You should go to the terminal and run python gam.py first to set up the config file. Once you have run through those steps then you can call gam normally.

rama1200

unread,
Oct 16, 2013, 3:52:54 PM10/16/13
to google-ap...@googlegroups.com
Yes... I know... that is the odd part... the initial setup is all done.

...if I run "python gam.py info user myuser" in the command line; it works fine ( I actually have my productions systems accounts provisioned using this very script - via command line - and a cron job taking user date from our oracle db)...... but when I run it via the php-form... that is when I get the error and the first-time setup text...

I think the problem is that when the command line runs the script, it does it as root (and no problems), but when the web runs it, the user (and IUD) changes to that of the www-data user/apache...

Currently I'm trying to figure out how to exec php as root...

Thanks.

On Tuesday, October 15, 2013 1:11:56 PM UTC-5, rama1200 wrote:

April Rosenberg

unread,
Oct 16, 2013, 3:58:31 PM10/16/13
to google-ap...@googlegroups.com

Disclaimer:  I have not tried to run gam this way…

 

As root you can become any other user, so you can do su - www-data –s/bin/bash and you should get a bash shell that allows you to run the script for the first time AS www-data. 

 

April

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/c2dc65e1-a950-4dfe-8af5-1fc87781b7bb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Colin Matheson

unread,
Oct 16, 2013, 4:07:12 PM10/16/13
to google-ap...@googlegroups.com
I would go to the folder below your gam.py location and run
sudo chown -R apache:apache yourFolder
That will make all the files accessible by the php script

rama1200

unread,
Oct 16, 2013, 4:52:49 PM10/16/13
to google-ap...@googlegroups.com
Yes.. that solves that problem... Thanks Colin and April.
This is what I gather the source of the problem was:

When you run gam (as root) you have no problems.... because of the omnipotent root; gam wants to write data to files or wants to create files (which I did not know - would have to trace the whole code to figure out)...
when you run gam via the web (as www-data or apache), unless gam is created/configured under/as www-data, it will complaint about permissions throwing a bunch of errors.

The question now is how to run gam securely as www-data...

On Tuesday, October 15, 2013 1:11:56 PM UTC-5, rama1200 wrote:

Godfried Borremans

unread,
Oct 18, 2013, 2:19:44 AM10/18/13
to google-ap...@googlegroups.com
As you are working with php: are you aware of this?
http://framework.zend.com/manual/1.12/en/zend.gdata.gapps.html


Op dinsdag 15 oktober 2013 20:11:56 UTC+2 schreef rama1200:

rama1200

unread,
Oct 18, 2013, 12:07:40 PM10/18/13
to google-ap...@googlegroups.com
Thanks, Godfried.
Yes, actually the Zend/Gdata/PHP API is what I was using before GAM, but Google has deprecated it (as off May, 2013 https://developers.google.com/google-apps/provisioning/?csw=1); in its place, Google said to use the Admin SDK...  since I'm that googd at programming, and after some research, it looked to me like GAM was a better solution... and it already handled the oauth2, json, etc. for me... so I didn't have to (want to) re-invent the wheel.

At this point, it is still not clear to me if Zend frame work is compatible with the new way Google is doing things.... mainly because I don't full understand how any of it works (GAM, Zend, json, etc.)... I just research enough to get what I need done... may be I should take a more detailed look at it.

Thanks
Reply all
Reply to author
Forward
0 new messages