| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Gdata
- * @subpackage Demos
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- /**
- * PHP sample code for the Google Calendar data API. Utilizes the
- * Zend Framework Gdata components to communicate with the Google API.
- *
- * Requires the Zend Framework Gdata components and PHP >= 5.2.11
- *
- * You can run this sample both from the command line (CLI) and also
- * from a web browser. Run this script without any command line options to
- * see usage, eg:
- * /usr/bin/env php Gapps.php
- *
- * More information on the Command Line Interface is available at:
- * http://www.php.net/features.commandline
- *
- * When running this code from a web browser, be sure to fill in your
- * Google Apps credentials below and choose a password for authentication
- * via the web browser.
- *
- * Since this is a demo, only minimal error handling and input validation
- * are performed. THIS CODE IS FOR DEMONSTRATION PURPOSES ONLY. NOT TO BE
- * USED IN A PRODUCTION ENVIRONMENT.
- *
- * NOTE: You must ensure that Zend Framework is in your PHP include
- * path. You can do this via php.ini settings, or by modifying the
- * argument to set_include_path in the code below.
- */
- // ************************ BEGIN WWW CONFIGURATION ************************
- /**
- * Google Apps username. This is the username (without domain) used
- * to administer your Google Apps account. This value is only
- * used when accessing this demo on a web server.
- *
- * For example, if you login to Google Apps as 'foo@bar.com.inavlid',
- * your username is 'foo'.
- */
- define('GAPPS_USERNAME', 'username');
- /**
- * Google Apps domain. This is the domain associated with your
- * Google Apps account. This value is only used when accessing this demo
- * on a web server.
- *
- * For example, if you login to Google Apps as foo@bar.com.inavlid,
- * your domain is 'bar.com.invalid'.
- */
- define('GAPPS_DOMAIN', 'example.com.invalid');
- /**
- * Google Apps password. This is the password associated with the above
- * username. This value is only used when accessing this demo on a
- * web server.
- */
- define('GAPPS_PASSWORD', 'your password here');
- /**
- * Login password. This password is used to protect your account from
- * unauthorized access when running this demo on a web server.
- *
- * If this field is blank, all access will be denied. A blank password
- * field is not the same as no password (which is disallowed for
- * security reasons).
- *
- * NOTE: While we could technically just ask the user for their Google Apps
- * credentials, the ClientLogin API is not intended for direct use by
- * web applications. If you are the only user of the application, this
- * is fine--- but you should not ask other users to enter their
- * credentials via your web application.
- */
- define('LOGIN_PASSWORD', '');
- // ************************* END WWW CONFIGURATION *************************
- /**
- * @see Zend_Loader
- */
- require_once 'Zend/Loader.php';
- /**
- * @see Zend_Gdata
- */
- Zend_Loader::loadClass('Zend_Gdata');
- /**
- * @see Zend_Gdata_ClientLogin
- */
- Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
- /**
- * @see Zend_Gdata_Gapps
- */
- Zend_Loader::loadClass('Zend_Gdata_Gapps');
- /**
- * Returns a HTTP client object with the appropriate headers for communicating
- * with Google using the ClientLogin credentials supplied.
- *
- * @param string $user The username, in e-mail address format, to authenticate
- * @param string $pass The password for the user specified
- * @return Zend_Http_Client
- */
- function getClientLoginHttpClient($user, $pass)
- {
- $service = Zend_Gdata_Gapps::AUTH_SERVICE_NAME;
- $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
- return $client;
- }
- /**
- * Creates a new user for the current domain. The user will be created
- * without admin privileges.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The desired username for the user.
- * @param string $givenName The given name for the user.
- * @param string $familyName The family name for the user.
- * @param string $password The plaintext password for the user.
- * @return void
- */
- function createUser($gapps, $html, $username, $givenName, $familyName,
- $password)
- {
- if ($html) {echo "<h2>Create User</h2>\n";}
- $gapps->createUser($username, $givenName, $familyName,
- $password);
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Retrieves a user for the current domain by username. Information about
- * that user is then output.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The desired username for the user.
- * @return void
- */
- function retrieveUser($gapps, $html, $username)
- {
- if ($html) {echo "<h2>User Information</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($html) {echo '<p>';}
- if ($user !== null) {
- echo ' Username: ' . $user->login->username;
- if ($html) {echo '<br />';}
- echo "\n";
- echo ' Given Name: ';
- if ($html) {
- echo htmlspecialchars($user->name->givenName);
- } else {
- echo $user->name->givenName;
- }
- if ($html) {echo '<br />';}
- echo "\n";
- echo ' Family Name: ';
- if ($html) {
- echo htmlspecialchars($user->name->familyName);
- } else {
- echo $user->name->familyName;
- }
- if ($html) {echo '<br />';}
- echo "\n";
- echo ' Suspended: ' . ($user->login->suspended ? 'Yes' : 'No');
- if ($html) {echo '<br />';}
- echo "\n";
- echo ' Admin: ' . ($user->login->admin ? 'Yes' : 'No');
- if ($html) {echo '<br />';}
- echo "\n";
- echo ' Must Change Password: ' .
- ($user->login->changePasswordAtNextLogin ? 'Yes' : 'No');
- if ($html) {echo '<br />';}
- echo "\n";
- echo ' Has Agreed To Terms: ' .
- ($user->login->agreedToTerms ? 'Yes' : 'No');
- } else {
- echo 'Error: Specified user not found.';
- }
- if ($html) {echo '</p>';}
- echo "\n";
- }
- /**
- * Retrieves the list of users for the current domain and outputs
- * that list.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @return void
- */
- function retrieveAllUsers($gapps, $html)
- {
- if ($html) {echo "<h2>Registered Users</h2>\n";}
- $feed = $gapps->retrieveAllUsers();
- if ($html) {echo "<ul>\n";}
- foreach ($feed as $user) {
- if ($html) {
- echo " <li>";
- } else {
- echo " * ";
- }
- echo $user->login->username . ' (';
- if ($html) {
- echo htmlspecialchars($user->name->givenName . ' ' .
- $user->name->familyName);
- } else {
- echo $user->name->givenName . ' ' . $user->name->familyName;
- }
- echo ')';
- if ($html) {echo '</li>';}
- echo "\n";
- }
- if ($html) {echo "</ul>\n";}
- }
- /**
- * Change the name for an existing user.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be updated
- * @param string $newGivenName The new given name for the user.
- * @param string $newFamilyName The new family name for the user.
- * @return void
- */
- function updateUserName($gapps, $html, $username, $newGivenName, $newFamilyName)
- {
- if ($html) {echo "<h2>Update User Name</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($user !== null) {
- $user->name->givenName = $newGivenName;
- $user->name->familyName = $newFamilyName;
- $user->save();
- } else {
- if ($html) {echo '<p>';}
- echo 'Error: Specified user not found.';
- if ($html) {echo '</p>';}
- echo "\n";
- }
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Change the password for an existing user.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be updated
- * @param string $newPassword The new password for the user.
- * @return void
- */
- function updateUserPassword($gapps, $html, $username, $newPassword)
- {
- if ($html) {echo "<h2>Update User Password</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($user !== null) {
- $user->login->password = $newPassword;
- $user->save();
- } else {
- if ($html) {echo '<p>';}
- echo 'Error: Specified user not found.';
- if ($html) {echo '</p>';}
- echo "\n";
- }
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Suspend a given user. The user will not be able to login until restored.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be updated.
- * @return void
- */
- function suspendUser($gapps, $html, $username)
- {
- if ($html) {echo "<h2>Suspend User</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($user !== null) {
- $user->login->suspended = true;
- $user->save();
- } else {
- if ($html) {echo '<p>';}
- echo 'Error: Specified user not found.';
- if ($html) {echo '</p>';}
- echo "\n";
- }
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Restore a given user after being suspended.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be updated.
- * @return void
- */
- function restoreUser($gapps, $html, $username)
- {
- if ($html) {echo "<h2>Restore User</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($user !== null) {
- $user->login->suspended = false;
- $user->save();
- } else {
- if ($html) {echo '<p>';}
- echo 'Error: Specified user not found.';
- if ($html) {echo '</p>';}
- echo "\n";
- }
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Give a user admin rights.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be updated.
- * @return void
- */
- function giveUserAdminRights($gapps, $html, $username)
- {
- if ($html) {echo "<h2>Grant Administrative Rights</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($user !== null) {
- $user->login->admin = true;
- $user->save();
- } else {
- if ($html) {echo '<p>';}
- echo 'Error: Specified user not found.';
- if ($html) {echo '</p>';}
- echo "\n";
- }
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Revoke a user's admin rights.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be updated.
- * @return void
- */
- function revokeUserAdminRights($gapps, $html, $username)
- {
- if ($html) {echo "<h2>Revoke Administrative Rights</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($user !== null) {
- $user->login->admin = false;
- $user->save();
- } else {
- if ($html) {echo '<p>';}
- echo 'Error: Specified user not found.';
- if ($html) {echo '</p>';}
- echo "\n";
- }
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Force a user to change their password at next login.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be updated.
- * @return void
- */
- function setUserMustChangePassword($gapps, $html, $username)
- {
- if ($html) {echo "<h2>Force User To Change Password</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($user !== null) {
- $user->login->changePasswordAtNextLogin = true;
- $user->save();
- } else {
- if ($html) {echo '<p>';}
- echo 'Error: Specified user not found.';
- if ($html) {echo '</p>';}
- echo "\n";
- }
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Undo forcing a user to change their password at next login.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be updated.
- * @return void
- */
- function clearUserMustChangePassword($gapps, $html, $username)
- {
- if ($html) {echo "<h2>Undo Force User To Change Password</h2>\n";}
- $user = $gapps->retrieveUser($username);
- if ($user !== null) {
- $user->login->changePasswordAtNextLogin = false;
- $user->save();
- } else {
- if ($html) {echo '<p>';}
- echo 'Error: Specified user not found.';
- if ($html) {echo '</p>';}
- echo "\n";
- }
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Delete the user who owns a given username.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username which should be deleted.
- * @return void
- */
- function deleteUser($gapps, $html, $username)
- {
- if ($html) {echo "<h2>Delete User</h2>\n";}
- $gapps->deleteUser($username);
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Create a new nickname.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username to which the nickname should be assigned.
- * @param string $nickname The name of the nickname to be created.
- * @return void
- */
- function createNickname($gapps, $html, $username, $nickname)
- {
- if ($html) {echo "<h2>Create Nickname</h2>\n";}
- $gapps->createNickname($username, $nickname);
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Retrieve a specified nickname and output its ownership information.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $nickname The name of the nickname to be retrieved.
- * @return void
- */
- function retrieveNickname($gapps, $html, $nickname)
- {
- if ($html) {echo "<h2>Nickname Information</h2>\n";}
- $nickname = $gapps->retrieveNickname($nickname);
- if ($html) {echo '<p>';}
- if ($nickname !== null) {
- echo ' Nickname: ' . $nickname->nickname->name;
- if ($html) {echo '<br />';}
- echo "\n";
- echo ' Owner: ' . $nickname->login->username;
- } else {
- echo 'Error: Specified nickname not found.';
- }
- if ($html) {echo '</p>';}
- echo "\n";
- }
- /**
- * Outputs all nicknames owned by a specific username.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $username The username whose nicknames should be displayed.
- * @return void
- */
- function retrieveNicknames($gapps, $html, $username)
- {
- if ($html) {echo "<h2>Registered Nicknames For {$username}</h2>\n";}
- $feed = $gapps->retrieveNicknames($username);
- if ($html) {echo "<ul>\n";}
- foreach ($feed as $nickname) {
- if ($html) {
- echo " <li>";
- } else {
- echo " * ";
- }
- echo $nickname->nickname->name;
- if ($html) {echo '</li>';}
- echo "\n";
- }
- if ($html) {echo "</ul>\n";}
- }
- /**
- * Retrieves the list of nicknames for the current domain and outputs
- * that list.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @return void
- */
- function retrieveAllNicknames($gapps, $html)
- {
- if ($html) {echo "<h2>Registered Nicknames</h2>\n";}
- $feed = $gapps->retrieveAllNicknames();
- if ($html) {echo "<ul>\n";}
- foreach ($feed as $nickname) {
- if ($html) {
- echo " <li>";
- } else {
- echo " * ";
- }
- echo $nickname->nickname->name . ' => ' . $nickname->login->username;
- if ($html) {echo '</li>';}
- echo "\n";
- }
- if ($html) {echo "</ul>\n";}
- }
- /**
- * Delete's a specific nickname from the current domain.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $nickname The nickname that should be deleted.
- * @return void
- */
- function deleteNickname($gapps, $html, $nickname)
- {
- if ($html) {echo "<h2>Delete Nickname</h2>\n";}
- $gapps->deleteNickname($nickname);
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Create a new email list.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $emailList The name of the email list to be created.
- * @return void
- */
- function createEmailList($gapps, $html, $emailList)
- {
- if ($html) {echo "<h2>Create Email List</h2>\n";}
- $gapps->createEmailList($emailList);
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Outputs the list of email lists to which the specified address is
- * subscribed.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $recipient The email address of the recipient whose subscriptions should
- * be retrieved. Only a username is required if the recipient is a
- * member of the current domain.
- * @return void
- */
- function retrieveEmailLists($gapps, $html, $recipient)
- {
- if ($html) {echo "<h2>Email List Subscriptions For {$recipient}</h2>\n";}
- $feed = $gapps->retrieveEmailLists($recipient);
- if ($html) {echo "<ul>\n";}
- foreach ($feed as $list) {
- if ($html) {
- echo " <li>";
- } else {
- echo " * ";
- }
- echo $list->emailList->name;
- if ($html) {echo '</li>';}
- echo "\n";
- }
- if ($html) {echo "</ul>\n";}
- }
- /**
- * Outputs the list of all email lists on the current domain.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @return void
- */
- function retrieveAllEmailLists($gapps, $html)
- {
- if ($html) {echo "<h2>Registered Email Lists</h2>\n";}
- $feed = $gapps->retrieveAllEmailLists();
- if ($html) {echo "<ul>\n";}
- foreach ($feed as $list) {
- if ($html) {
- echo " <li>";
- } else {
- echo " * ";
- }
- echo $list->emailList->name;
- if ($html) {echo '</li>';}
- echo "\n";
- }
- if ($html) {echo "</ul>\n";}
- }
- /**
- * Delete's a specific email list from the current domain.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $emailList The email list that should be deleted.
- * @return void
- */
- function deleteEmailList($gapps, $html, $emailList)
- {
- if ($html) {echo "<h2>Delete Email List</h2>\n";}
- $gapps->deleteEmailList($emailList);
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Add a recipient to an existing email list.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the
- * Google Apps server.
- * @param boolean $html True if output should be formatted for display in a
- * web browser.
- * @param string $recipientAddress The address of the recipient who should be added.
- * @param string $emailList The name of the email address the recipient be added to.
- * @return void
- */
- function addRecipientToEmailList($gapps, $html, $recipientAddress,
- $emailList)
- {
- if ($html) {echo "<h2>Subscribe Recipient</h2>\n";}
- $gapps->addRecipientToEmailList($recipientAddress, $emailList);
- if ($html) {echo "<p>Done.</p>\n";}
- }
- /**
- * Outputs the list of all recipients for a given email list.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the Google
- * Apps server.
- * @param boolean $html True if output should be formatted for display in a web browser.
- * @param string $emailList The email list whose recipients should be output.
- * @return void
- */
- function retrieveAllRecipients($gapps, $html, $emailList)
- {
- if ($html) {echo "<h2>Email List Recipients For {$emailList}</h2>\n";}
- $feed = $gapps->retrieveAllRecipients($emailList);
- if ($html) {echo "<ul>\n";}
- foreach ($feed as $recipient) {
- if ($html) {
- echo " <li>";
- } else {
- echo " * ";
- }
- echo $recipient->who->email;
- if ($html) {echo '</li>';}
- echo "\n";
- }
- if ($html) {echo "</ul>\n";}
- }
- /**
- * Remove an existing recipient from an email list.
- *
- * @param Zend_Gdata_Gapps $gapps The service object to use for communicating with the
- * Google Apps server.
- * @param boolean $html True if output should be formatted for display in a
- * web browser.
- * @param string $recipientAddress The address of the recipient who should be removed.
- * @param string $emailList The email list from which the recipient should be removed.
- * @return void
- */
- function removeRecipientFromEmailList($gapps, $html, $recipientAddress,
- $emailList)
- {
- if ($html) {echo "<h2>Unsubscribe Recipient</h2>\n";}
- $gapps->removeRecipientFromEmailList($recipientAddress, $emailList);
- if ($html) {echo "<p>Done.</p>\n";}
- }
- // ************************ BEGIN CLI SPECIFIC CODE ************************
- /**
- * Display list of valid commands.
- *
- * @param string $executable The name of the current script. This is usually available as $argv[0].
- * @return void
- */
- function displayHelp($executable)
- {
- echo "Usage: php {$executable} <action> [<username>] [<password>] " .
- "[<arg1> <arg2> ...]\n\n";
- echo "Possible action values include:\n" .
- "createUser\n" .
- "retrieveUser\n" .
- "retrieveAllUsers\n" .
- "updateUserName\n" .
- "updateUserPassword\n" .
- "suspendUser\n" .
- "restoreUser\n" .
- "giveUserAdminRights\n" .
- "revokeUserAdminRights\n" .
- "setUserMustChangePassword\n" .
- "clearUserMustChangePassword\n" .
- "deleteUser\n" .
- "createNickname\n" .
- "retrieveNickname\n" .
- "retrieveNicknames\n" .
- "retrieveAllNicknames\n" .
- "deleteNickname\n" .
- "createEmailList\n" .
- "retrieveEmailLists\n" .
- "retrieveAllEmailLists\n" .
- "deleteEmailList\n" .
- "addRecipientToEmailList\n" .
- "retrieveAllRecipients\n" .
- "removeRecipientFromEmailList\n";
- }
- /**
- * Parse command line arguments and execute appropriate function when
- * running from the command line.
- *
- * If no arguments are provided, usage information will be provided.
- *
- * @param array $argv The array of command line arguments provided by PHP.
- * $argv[0] should be the current executable name or '-' if not available.
- * @param integer $argc The size of $argv.
- * @return void
- */
- function runCLIVersion($argv, $argc)
- {
- if (isset($argc) && $argc >= 2) {
- # Prepare a server connection
- if ($argc >= 5) {
- try {
- $client = getClientLoginHttpClient($argv[2] . '@' . $argv[3], $argv[4]);
- $gapps = new Zend_Gdata_Gapps($client, $argv[3]);
- } catch (Zend_Gdata_App_AuthException $e) {
- echo "Error: Unable to authenticate. Please check your credentials.\n";
- exit(1);
- }
- }
- # Dispatch arguments to the desired method
- switch ($argv[1]) {
- case 'createUser':
- if ($argc == 9) {
- createUser($gapps, false, $argv[5], $argv[6], $argv[7], $argv[8]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username> <given name> <family name> <user's password>\n\n";
- echo "This creates a new user with the given username.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe John Doe p4ssw0rd\n";
- }
- break;
- case 'retrieveUser':
- if ($argc == 6) {
- retrieveUser($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "This retrieves the user with the specified " .
- "username and displays information about that user.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'retrieveAllUsers':
- if ($argc == 5) {
- retrieveAllUsers($gapps, false);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "\n\n";
- echo "This lists all users on the current domain.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password>\n";
- }
- break;
- case 'updateUserName':
- if ($argc == 8) {
- updateUserName($gapps, false, $argv[5], $argv[6], $argv[7]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username> <new given name> <new family name>\n\n";
- echo "Renames an existing user.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe Jane Doe\n";
- }
- break;
- case 'updateUserPassword':
- if ($argc == 7) {
- updateUserPassword($gapps, false, $argv[5], $argv[6]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username> <new user password>\n\n";
- echo "Changes the password for an existing user.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe password1\n";
- }
- break;
- case 'suspendUser':
- if ($argc == 6) {
- suspendUser($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "This suspends the given user.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'restoreUser':
- if ($argc == 6) {
- restoreUser($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "This restores the given user after being suspended.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'giveUserAdminRights':
- if ($argc == 6) {
- giveUserAdminRights($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "Give a user admin rights for this domain.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'revokeUserAdminRights':
- if ($argc == 6) {
- revokeUserAdminRights($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "Remove a user's admin rights for this domain.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'setUserMustChangePassword':
- if ($argc == 6) {
- setUserMustChangePassword($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "Force a user to change their password at next login.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'clearUserMustChangePassword':
- if ($argc == 6) {
- clearUserMustChangePassword($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "Clear the flag indicating that a user must change " .
- "their password at next login.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'deleteUser':
- if ($argc == 6) {
- deleteUser($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "Delete the user who owns a given username.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'createNickname':
- if ($argc == 7) {
- createNickname($gapps, false, $argv[5], $argv[6]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username> <nickname>\n\n";
- echo "Create a new nickname for the specified user.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe johnny\n";
- }
- break;
- case 'retrieveNickname':
- if ($argc == 6) {
- retrieveNickname($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<nickname>\n\n";
- echo "Retrieve a nickname and display its ownership " .
- "information.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "johnny\n";
- }
- break;
- case 'retrieveNicknames':
- if ($argc == 6) {
- retrieveNicknames($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<user's username>\n\n";
- echo "Output all nicknames owned by a specific username.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "jdoe\n";
- }
- break;
- case 'retrieveAllNicknames':
- if ($argc == 5) {
- retrieveAllNicknames($gapps, false);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "\n\n";
- echo "Output all registered nicknames on the system.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "\n";
- }
- break;
- case 'deleteNickname':
- if ($argc == 6) {
- deleteNickname($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<nickname>\n\n";
- echo "Delete a specific nickname.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "johnny\n";
- }
- break;
- case 'createEmailList':
- if ($argc == 6) {
- createEmailList($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<email list>\n\n";
- echo "Create a new email list with the specified name.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "friends\n";
- }
- break;
- case 'retrieveEmailLists':
- if ($argc == 6) {
- retrieveEmailLists($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<recipient>\n\n";
- echo "Retrieve all email lists to which the specified " .
- "address is subscribed.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "johnny@somewhere.com.invalid\n";
- }
- break;
- case 'retrieveAllEmailLists':
- if ($argc == 5) {
- retrieveAllEmailLists($gapps, false);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "\n\n";
- echo "Retrieve a list of all email lists on the current " .
- "domain.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "\n";
- }
- break;
- case 'deleteEmailList':
- if ($argc == 6) {
- deleteEmailList($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<email list>\n\n";
- echo "Delete a specified email list.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "friends\n";
- }
- break;
- case 'addRecipientToEmailList':
- if ($argc == 7) {
- addRecipientToEmailList($gapps, false, $argv[5], $argv[6]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<recipient> <email list>\n\n";
- echo "Add a recipient to an existing email list.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "johnny@somewhere.com.invalid friends\n";
- }
- break;
- case 'retrieveAllRecipients':
- if ($argc == 6) {
- retrieveAllRecipients($gapps, false, $argv[5]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<email list>\n\n";
- echo "Retrieve all recipients for an existing email list.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "friends\n";
- }
- break;
- case 'removeRecipientFromEmailList':
- if ($argc == 7) {
- removeRecipientFromEmailList($gapps, false, $argv[5], $argv[6]);
- } else {
- echo "Usage: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "<recipient> <email list>\n\n";
- echo "Remove an existing recipient from an email list.\n";
- echo "EXAMPLE: php {$argv[0]} {$argv[1]} <username> <domain> <password> " .
- "johnny@somewhere.com.invalid friends\n";
- }
- break;
- default:
- // Invalid action entered
- displayHelp($argv[0]);
- // End switch block
- }
- } else {
- // action left unspecified
- displayHelp($argv[0]);
- }
- }
- // ************************ BEGIN WWW SPECIFIC CODE ************************
- /**
- * Writes the HTML prologue for this app.
- *
- * NOTE: We would normally keep the HTML/CSS markup separate from the business
- * logic above, but have decided to include it here for simplicity of
- * having a single-file sample.
- *
- *
- * @param boolean $displayMenu (optional) If set to true, a navigation
- * menu is displayed at the top of the page. Default is true.
- * @return void
- */
- function startHTML($displayMenu = true)
- {
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title>Google Apps Provisioning API Demo</title>
- <style type="text/css" media="screen">
- body {
- font-family: Arial, Helvetica, sans-serif;
- font-size: small;
- }
- #header {
- background-color: #9cF;
- -moz-border-radius: 5px;
- -webkit-border-radius: 5px;
- padding-left: 5px;
- height: 2.4em;
- }
- #header h1 {
- width: 49%;
- display: inline;
- float: left;
- margin: 0;
- padding: 0;
- font-size: 2em;
- }
- #header p {
- width: 49%;
- margin: 0;
- padding-right: 15px;
- float: right;
- line-height: 2.4em;
- text-align: right;
- }
- .clear {
- clear:both;
- }
- h2 {
- background-color: #ccc;
- -moz-border-radius: 5px;
- -webkit-border-radius: 5px;
- margin-top: 1em;
- padding-left: 5px;
- }
- .error {
- color: red;
- }
- form {
- width: 500px;
- background: #ddf8cc;
- border: 1px solid #80c605;
- padding: 0 1em;
- margin: 1em auto;
- }
- .warning {
- width: 500px;
- background: #F4B5B4;
- border: 1px solid #900;
- padding: 0 1em;
- margin: 1em auto;
- }
- label {
- display: block;
- width: 130px;
- float: left;
- text-align: right;
- padding-top: 0.3em;
- padding-right: 3px;
- }
- .radio {
- margin: 0;
- padding-left: 130px;
- }
- #menuSelect {
- padding: 0;
- }
- #menuSelect li {
- display: block;
- width: 500px;
- background: #ddf8cc;
- border: 1px solid #80c605;
- margin: 1em auto;
- padding: 0;
- font-size: 1.3em;
- text-align: center;
- list-style-type: none;
- }
- #menuSelect li:hover {
- background: #c4faa2;
- }
- #menuSelect a {
- display: block;
- height: 2em;
- margin: 0px;
- padding-top: 0.75em;
- padding-bottom: -0.25em;
- text-decoration: none;
- }
- #content {
- width: 600px;
- margin: 0 auto;
- padding: 0;
- text-align: left;
- }
- </style>
- </head>
- <body>
- <div id="header">
- <h1>Google Apps API Demo</h1>
- <?php if ($displayMenu === true) { ?>
- <p><?php echo GAPPS_DOMAIN ?> | <a href="?">Main</a> | <a href="?menu=logout">Logout</a></p>
- <?php } ?>
- <div class="clear"></div>
- </div>
- <div id="content">
- <?php
- }
- /**
- * Writes the HTML epilogue for this app and exit.
- *
- * @param boolean $displayBackButton (optional) If true, displays a
- * link to go back at the bottom of the page. Defaults to false.
- * @return void
- */
- function endHTML($displayBackButton = false)
- {
- if ($displayBackButton === true) {
- echo '<a href="javascript:history.go(-1)">← Back</a>';
- }
- ?>
- </div>
- </body>
- </html>
- <?php
- exit();
- }
- /**
- * Displays a notice indicating that a login password needs to be
- * set before continuing.
- *
- * @return void
- */
- function displayPasswordNotSetNotice()
- {
- ?>
- <div class="warning">
- <h3>Almost there...</h3>
- <p>Before using this demo, you must set an application password
- to protect your account. You will also need to set your
- Google Apps credentials in order to communicate with the Google
- Apps servers.</p>
- <p>To continue, open this file in a text editor and fill
- out the information in the configuration section.</p>
- </div>
- <?php
- }
- /**
- * Displays a notice indicating that authentication to Google Apps failed.
- *
- * @return void
- */
- function displayAuthenticationFailedNotice()
- {
- ?>
- <div class="warning">
- <h3>Google Apps Authentication Failed</h3>
- <p>Authentication with the Google Apps servers failed.</p>
- <p>Please open this file in a text editor and make
- sure your credentials are correct.</p>
- </div>
- <?php
- }
- /**
- * Outputs a request to the user to enter their login password.
- *
- * @param string $errorText (optional) Error text to be displayed next to the login form.
- * @return void
- */
- function requestUserLogin($errorText = null)
- {
- ?>
- <form method="post" accept-charset="utf-8">
- <h3>Authentication Required</h3>
- <?php
- if ($errorText !== null) {
- echo '<span class="error">' . $errorText . "</span>\n";
- }
- ?>
- <p>Please enter your login password to continue.</p>
- <p><label for="password">Password: </label>
- <input type="password" name="password" value="" /></p>
- <p><strong>Notice:</strong> This application is for demonstration
- purposes only. Not for use in a production environment.</p>
- <p><input type="submit" value="Continue →"></p>
- </form>
- <?php
- }
- /**
- * Display the main menu for running in a web browser.
- *
- * @return void
- */
- function displayMenu()
- {
- ?>
- <h2>Main Menu</h2>
- <p>Welcome to the Google Apps Provisioning API demo page. Please select
- from one of the following three options to see a list of commands.</p>
- <ul id="menuSelect">
- <li><a class="menuSelect" href="?menu=user">User Maintenance Menu</a></li>
- <li><a class="menuSelect" href="?menu=nickname">Nickname Maintenance Menu</a></li>
- <li><a class="menuSelect" href="?menu=emailList">Email List Maintenance Menu</a></li>
- </ul>
- <p>Tip: You can also run this demo from the command line if your system
- has PHP CLI support enabled.</p>
- <?php
- }
- /**
- * Display the user maintenance menu for running in a web browser.
- *
- * @return void
- */
- function displayUserMenu()
- {
- ?>
- <h2>User Maintenance Menu</h2>
- <form method="post" accept-charset="utf-8">
- <h3>Create User</h3>
- <p>Create a new user with the given properties.</p>
- <p>
- <input type="hidden" name="command" value="createUser" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" /><br />
- <label for="givenName">Given Name: </label>
- <input type="text" name="givenName" value="" /><br />
- <label for="familyName">Family Name: </label>
- <input type="text" name="familyName" value="" /><br />
- <label for="pass">Password: </label>
- <input type="password" name="pass" value="" />
- </p>
- <p><input type="submit" value="Create User →"></p>
- </form>
- <form method="get" accept-charset="utf-8">
- <h3>Retrieve User</h3>
- <p>Retrieve the information for an existing user.</p>
- <p>
- <input type="hidden" name="command" value="retrieveUser" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" /><br />
- </p>
- <p><input type="submit" value="Retrieve User →"></p>
- </form>
- <form method="get" accept-charset="utf-8">
- <h3>Retrieve All Users</h3>
- <p>Retrieve the list of all users on the current domain.</p>
- <p>
- <input type="hidden" name="command" value="retrieveAllUsers" />
- </p>
- <p><input type="submit" value="Retrieve Users →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Update Name</h3>
- <p>Update the name for an existing user.</p>
- <p>
- <input type="hidden" name="command" value="updateUserName" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" /><br />
- <label for="givenName">New Given Name: </label>
- <input type="text" name="givenName" value="" /><br />
- <label for="familyName">New Family Name: </label>
- <input type="text" name="familyName" value="" /><br />
- </p>
- <p><input type="submit" value="Update User →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Update Password</h3>
- <p>Update the password for an existing user.</p>
- <p>
- <input type="hidden" name="command" value="updateUserPassword" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" /><br />
- <label for="pass">New Password: </label>
- <input type="password" name="pass" value="" /></p>
- </p>
- <p><input type="submit" value="Update User →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Suspend/Restore User</h3>
- <p>Mark an existing user as suspended or restore a suspended user.
- While suspended, the user will be prohibited from logging into
- this domain.</p>
- <p>
- <input type="hidden" name="command" value="setUserSuspended" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" />
- </p>
- <div class="radio">
- <input type="radio" name="mode" value="restore">User may log into
- this domain.</input><br />
- <input type="radio" name="mode" value="suspend" checked="true">User
- may <strong>not</strong> log into this domain.</input>
- </div>
- <p><input type="submit" value="Update User →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Issue/Revoke Admin Rights</h3>
- <p>Set whether an existing user has administrative rights for the current
- domain.</p>
- <p>
- <input type="hidden" name="command" value="setUserAdmin" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" />
- </p>
- <div class="radio">
- <input type="radio" name="mode" value="issue">User
- may administer this domain.</input><br />
- <input type="radio" name="mode" value="revoke" checked="true">User
- may <strong>not</strong> administer this domain.</input>
- </div>
- <p><input type="submit" value="Update User →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Force User To Change Password</h3>
- <p>Set whether an existing user must change their password at
- their next login.</p>
- <p>
- <input type="hidden" name="command" value="setForceChangePassword" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" />
- </p>
- <div class="radio">
- <input type="radio" name="mode" value="set">User is required to
- change their password at next login.</input><br />
- <input type="radio" name="mode" value="clear" checked="true">User is
- <strong>not</strong> required to change their password at next
- login.</input>
- </div>
- <p><input type="submit" value="Update User →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Delete User</h3>
- <p>Delete an existing user on the current domain.</p>
- <p>
- <input type="hidden" name="command" value="deleteUser" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" /><br />
- </p>
- <p><input type="submit" value="Delete User →"></p>
- </form>
- <?php
- }
- /**
- * Display the nickname maintenance menu for running in a web browser.
- *
- * @return void
- */
- function displayNicknameMenu()
- {
- ?>
- <h2>Nickname Maintenance Menu</h2>
- <form method="post" accept-charset="utf-8">
- <h3>Create Nickname</h3>
- <p>Create a nickname for an existing user.</p>
- <p>
- <input type="hidden" name="command" value="createNickname" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" /><br />
- <label for="nickname">Nickname: </label>
- <input type="text" name="nickname" value="" /><br />
- </p>
- <p><input type="submit" value="Create Nickname →"></p>
- </form>
- <form method="get" accept-charset="utf-8">
- <h3>Retrieve Nickname</h3>
- <p>Retrieve the information for an existing nickname.</p>
- <p>
- <input type="hidden" name="command" value="retrieveNickname" />
- <label for="nickname">Nickname: </label>
- <input type="text" name="nickname" value="" /><br />
- </p>
- <p><input type="submit" value="Retrieve Nickname →"></p>
- </form>
- <form method="get" accept-charset="utf-8">
- <h3>Retrieve Nicknames</h3>
- <p>Retrieve the nicknames associated with an existing username.</p>
- <p>
- <input type="hidden" name="command" value="retrieveNicknames" />
- <label for="user">Username: </label>
- <input type="text" name="user" value="" /><br />
- </p>
- <p><input type="submit" value="Retrieve Nicknames →"></p>
- </form>
- <form method="get" accept-charset="utf-8">
- <h3>Retrieve All Nicknames</h3>
- <p>Retrieve the nicknames on the current domain.</p>
- <p>
- <input type="hidden" name="command" value="retrieveAllNicknames" />
- </p>
- <p><input type="submit" value="Retrieve Nicknames →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Delete Nickname</h3>
- <p>Delete an existing nickname from the current domain.</p>
- <p>
- <input type="hidden" name="command" value="deleteNickname" />
- <label for="nickname">Nickname: </label>
- <input type="text" name="nickname" value="" /><br />
- </p>
- <p><input type="submit" value="Delete Nickname →"></p>
- </form>
- <?php
- }
- /**
- * Display the email list maintenance menu for running in a web browser.
- *
- * @return void
- */
- function displayEmailListMenu()
- {
- ?>
- <h2>Email List Maintenance Menu</h2>
- <form method="post" accept-charset="utf-8">
- <h3>Create Email List</h3>
- <p>Create a new email list for the current domain.</p>
- <p>
- <input type="hidden" name="command" value="createEmailList" />
- <label for="emailList">List Name: </label>
- <input type="text" name="emailList" value="" /><br />
- </p>
- <p><input type="submit" value="Create List →"></p>
- </form>
- <form method="get" accept-charset="utf-8">
- <h3>Retrieve Email Lists</h3>
- <p>Retrieve all email lists to which a given email address is
- subscribed.</p>
- <p>
- <input type="hidden" name="command" value="retrieveEmailLists" />
- <label for="recipient">Recipient Address: </label>
- <input type="text" name="recipient" value="" /><br />
- </p>
- <p><input type="submit" value="Retrieve Lists →"></p>
- </form>
- <form method="get" accept-charset="utf-8">
- <h3>Retrieve All Email Lists</h3>
- <p>Retrieve all email lists on the current domain.</p>
- <p>
- <input type="hidden" name="command" value="retrieveAllEmailLists" />
- </p>
- <p><input type="submit" value="Retrieve Lists →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Delete Email List</h3>
- <p>Delete an existing email list from the current domain.</p>
- <p>
- <input type="hidden" name="command" value="deleteEmailList" />
- <label for="emailList">List Name: </label>
- <input type="text" name="emailList" value="" /><br />
- </p>
- <p><input type="submit" value="Delete List →"></p>
- </form>
- <form method="post" accept-charset="utf-8">
- <h3>Add Recipient To Email List</h3>
- <p>Add or remove a recipient from an existing email list. A complete
- email address is required for recipients outside the current
- domain.</p>
- <p>
- <input type="hidden" name="command" value="modifySubscription" />
- <label for="emailList">List Name: </label>
- <input type="text" name="emailList" value="" /><br />
- <label for="recipient">Recipient Address: </label>
- <input type="text" name="recipient" value="" /><br />
- <div class="radio">
- <input type="radio" name="mode" value="subscribe">Subscribe
- recipient.</input><br />
- <input type="radio" name="mode" value="unsubscribe"
- checked="true">Unsubscribe recipient.</input>
- </div>
- </p>
- <p><input type="submit" value="Update Subscription →"></p>
- </form>
- <form method="get" accept-charset="utf-8">
- <h3>Retrieve All Recipients</h3>
- <p>Retrieve all recipients subscribed to an existing email list.</p>
- <p>
- <input type="hidden" name="command" value="retrieveAllRecipients" />
- <label for="emailList">List Name: </label>
- <input type="text" name="emailList" value="" /><br />
- </p>
- <p><input type="submit" value="Retrieve Recipients →"></p>
- </form>
- <?php
- }
- /**
- * Log the current user out of the application.
- *
- * @return void
- */
- function logout()
- {
- session_destroy();
- ?>
- <h2>Logout</h2>
- <p>Logout successful.</p>
- <ul id="menuSelect">
- <li><a class="menuSelect" href="?">Login</a></li>
- </ul>
- <?php
- }
- /**
- * Processes loading of this sample code through a web browser.
- *
- * @return void
- */
- function runWWWVersion()
- {
- session_start();
- // Note that all calls to endHTML() below end script execution!
- // Check to make sure that the user has set a password.
- $p = LOGIN_PASSWORD;
- if (empty($p)) {
- startHTML(false);
- displayPasswordNotSetNotice();
- endHTML();
- }
- // Grab any login credentials that might be waiting in the request
- if (!empty($_POST['password'])) {
- if ($_POST['password'] == LOGIN_PASSWORD) {
- $_SESSION['authenticated'] = 'true';
- } else {
- // Invalid password. Stop and display a login screen.
- startHTML(false);
- requestUserLogin("Incorrect password.");
- endHTML();
- }
- }
- // If the user isn't authenticated, display a login screen
- if (!isset($_SESSION['authenticated'])) {
- startHTML(false);
- requestUserLogin();
- endHTML();
- }
- // Try to login. If login fails, log the user out and display an
- // error message.
- try {
- $client = getClientLoginHttpClient(GAPPS_USERNAME . '@' .
- GAPPS_DOMAIN, GAPPS_PASSWORD);
- $gapps = new Zend_Gdata_Gapps($client, GAPPS_DOMAIN);
- } catch (Zend_Gdata_App_AuthException $e) {
- session_destroy();
- startHTML(false);
- displayAuthenticationFailedNotice();
- endHTML();
- }
- // Success! We're logged in.
- // First we check for commands that can be submitted either though
- // POST or GET (they don't make any changes).
- if (!empty($_REQUEST['command'])) {
- switch ($_REQUEST['command']) {
- case 'retrieveUser':
- startHTML();
- retrieveUser($gapps, true, $_REQUEST['user']);
- endHTML(true);
- case 'retrieveAllUsers':
- startHTML();
- retrieveAllUsers($gapps, true);
- endHTML(true);
- case 'retrieveNickname':
- startHTML();
- retrieveNickname($gapps, true, $_REQUEST['nickname']);
- endHTML(true);
- case 'retrieveNicknames':
- startHTML();
- retrieveNicknames($gapps, true, $_REQUEST['user']);
- endHTML(true);
- case 'retrieveAllNicknames':
- startHTML();
- retrieveAllNicknames($gapps, true);
- endHTML(true);
- case 'retrieveEmailLists':
- startHTML();
- retrieveEmailLists($gapps, true, $_REQUEST['recipient']);
- endHTML(true);
- case 'retrieveAllEmailLists':
- startHTML();
- retrieveAllEmailLists($gapps, true);
- endHTML(true);
- case 'retrieveAllRecipients':
- startHTML();
- retrieveAllRecipients($gapps, true, $_REQUEST['emailList']);
- endHTML(true);
- }
- }
- // Now we handle the potentially destructive commands, which have to
- // be submitted by POST only.
- if (!empty($_POST['command'])) {
- switch ($_POST['command']) {
- case 'createUser':
- startHTML();
- createUser($gapps, true, $_POST['user'],
- $_POST['givenName'], $_POST['familyName'],
- $_POST['pass']);
- endHTML(true);
- case 'updateUserName':
- startHTML();
- updateUserName($gapps, true, $_POST['user'],
- $_POST['givenName'], $_POST['familyName']);
- endHTML(true);
- case 'updateUserPassword':
- startHTML();
- updateUserPassword($gapps, true, $_POST['user'],
- $_POST['pass']);
- endHTML(true);
- case 'setUserSuspended':
- if ($_POST['mode'] == 'suspend') {
- startHTML();
- suspendUser($gapps, true, $_POST['user']);
- endHTML(true);
- } elseif ($_POST['mode'] == 'restore') {
- startHTML();
- restoreUser($gapps, true, $_POST['user']);
- endHTML(true);
- } else {
- header('HTTP/1.1 400 Bad Request');
- startHTML();
- echo "<h2>Invalid mode.</h2>\n";
- echo "<p>Please check your request and try again.</p>";
- endHTML(true);
- }
- case 'setUserAdmin':
- if ($_POST['mode'] == 'issue') {
- startHTML();
- giveUserAdminRights($gapps, true, $_POST['user']);
- endHTML(true);
- } elseif ($_POST['mode'] == 'revoke') {
- startHTML();
- revokeUserAdminRights($gapps, true, $_POST['user']);
- endHTML(true);
- } else {
- header('HTTP/1.1 400 Bad Request');
- startHTML();
- echo "<h2>Invalid mode.</h2>\n";
- echo "<p>Please check your request and try again.</p>";
- endHTML(true);
- }
- case 'setForceChangePassword':
- if ($_POST['mode'] == 'set') {
- startHTML();
- setUserMustChangePassword($gapps, true, $_POST['user']);
- endHTML(true);
- } elseif ($_POST['mode'] == 'clear') {
- startHTML();
- clearUserMustChangePassword($gapps, true, $_POST['user']);
- endHTML(true);
- } else {
- header('HTTP/1.1 400 Bad Request');
- startHTML();
- echo "<h2>Invalid mode.</h2>\n";
- echo "<p>Please check your request and try again.</p>";
- endHTML(true);
- }
- case 'deleteUser':
- startHTML();
- deleteUser($gapps, true, $_POST['user']);
- endHTML(true);
- case 'createNickname':
- startHTML();
- createNickname($gapps, true, $_POST['user'],
- $_POST['nickname']);
- endHTML(true);
- case 'deleteNickname':
- startHTML();
- deleteNickname($gapps, true, $_POST['nickname']);
- endHTML(true);
- case 'createEmailList':
- startHTML();
- createEmailList($gapps, true, $_POST['emailList']);
- endHTML(true);
- case 'deleteEmailList':
- startHTML();
- deleteEmailList($gapps, true, $_POST['emailList']);
- endHTML(true);
- case 'modifySubscription':
- if ($_POST['mode'] == 'subscribe') {
- startHTML();
- addRecipientToEmailList($gapps, true, $_POST['recipient'],
- $_POST['emailList']);
- endHTML(true);
- } elseif ($_POST['mode'] == 'unsubscribe') {
- startHTML();
- removeRecipientFromEmailList($gapps, true,
- $_POST['recipient'], $_POST['emailList']);
- endHTML(true);
- } else {
- header('HTTP/1.1 400 Bad Request');
- startHTML();
- echo "<h2>Invalid mode.</h2>\n";
- echo "<p>Please check your request and try again.</p>";
- endHTML(true);
- }
- }
- }
- // Check for an invalid command. If so, display an error and exit.
- if (!empty($_REQUEST['command'])) {
- header('HTTP/1.1 400 Bad Request');
- startHTML();
- echo "<h2>Invalid command.</h2>\n";
- echo "<p>Please check your request and try again.</p>";
- endHTML(true);
- }
- // If a menu parameter is available, display a submenu.
- if (!empty($_REQUEST['menu'])) {
- switch ($_REQUEST['menu']) {
- case 'user':
- startHTML();
- displayUserMenu();
- endHTML();
- case 'nickname':
- startHTML();
- displayNicknameMenu();
- endHTML();
- case 'emailList':
- startHTML();
- displayEmailListMenu();
- endHTML();
- case 'logout':
- startHTML(false);
- logout();
- endHTML();
- default:
- header('HTTP/1.1 400 Bad Request');
- startHTML();
- echo "<h2>Invalid menu selection.</h2>\n";
- echo "<p>Please check your request and try again.</p>";
- endHTML(true);
- }
- }
- // If we get this far, that means there's nothing to do. Display
- // the main menu.
- // If no command was issued and no menu was selected, display the
- // main menu.
- startHTML();
- displayMenu();
- endHTML();
- }
- // ************************** PROGRAM ENTRY POINT **************************
- if (!isset($_SERVER["HTTP_HOST"])) {
- // running through command line
- runCLIVersion($argv, $argc);
- } else {
- // running through web server
- try {
- runWWWVersion();
- } catch (Zend_Gdata_Gapps_ServiceException $e) {
- // Try to recover gracefully from a service exception.
- // The HTML prologue will have already been sent.
- echo "<p><strong>Service Error Encountered</strong></p>\n";
- echo "<pre>" . htmlspecialchars($e->__toString()) . "</pre>";
- endHTML(true);
- }
- }
|