From 0089e5947ab47ba3f35f7a977884392adf3c6da5 Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Fri, 21 Mar 2008 17:17:42 +0100 Subject: [PATCH] Adds an admin interface for Google Apps accounts. Signed-off-by: Vincent Zanotti --- include/googleapps.inc.php | 4 +- modules/googleapps.php | 109 +++++++++++++++++++++++++++++++++++- templates/googleapps/admin.job.tpl | 86 ++++++++++++++++++++++++++++ templates/googleapps/admin.tpl | 100 +++++++++++++++++++++++++++++++++ templates/googleapps/admin.user.tpl | 105 ++++++++++++++++++++++++++++++++++ 5 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 templates/googleapps/admin.job.tpl create mode 100644 templates/googleapps/admin.tpl create mode 100644 templates/googleapps/admin.user.tpl diff --git a/include/googleapps.inc.php b/include/googleapps.inc.php index e6d6943..908083b 100644 --- a/include/googleapps.inc.php +++ b/include/googleapps.inc.php @@ -116,6 +116,7 @@ class GoogleAppsAccount public $activate_mail_redirection; // Account status, obtained from Google Apps provisioning & reporting APIs. + public $g_account_id; public $g_status; public $g_suspension; public $r_disk_usage; @@ -151,7 +152,7 @@ class GoogleAppsAccount $res = XDB::query( "SELECT l_sync_password, l_activate_mail_redirection, - g_account_name, g_status, g_suspension, r_disk_usage, + g_account_name, g_account_id, g_status, g_suspension, r_disk_usage, UNIX_TIMESTAMP(r_creation) as r_creation, UNIX_TIMESTAMP(r_last_login) as r_last_login, UNIX_TIMESTAMP(r_last_webmail) as r_last_webmail @@ -161,6 +162,7 @@ class GoogleAppsAccount if ($account = $res->fetchOneAssoc()) { $this->sync_password = $account['l_sync_password']; $this->activate_mail_redirection = $account['l_activate_mail_redirection']; + $this->g_account_id = $account['g_account_id']; $this->g_status = $account['g_status']; $this->g_suspension = $account['g_suspension']; $this->r_disk_usage = $account['r_disk_usage']; diff --git a/modules/googleapps.php b/modules/googleapps.php index 9dc333b..6eb41ba 100644 --- a/modules/googleapps.php +++ b/modules/googleapps.php @@ -29,7 +29,10 @@ class GoogleAppsModule extends PLModule } return array( - 'googleapps' => $this->make_hook('index', AUTH_MDP), + 'googleapps' => $this->make_hook('index', AUTH_MDP), + 'admin/googleapps' => $this->make_hook('admin', AUTH_MDP. 'admin'), + 'admin/googleapps/job' => $this->make_hook('admin_job', AUTH_MDP, 'admin'), + 'admin/googleapps/user' => $this->make_hook('admin_user', AUTH_MDP, 'admin'), ); } @@ -106,6 +109,110 @@ class GoogleAppsModule extends PLModule $page->assign('account', $account); } + + function handler_admin(&$page, $action = null) { + require_once("googleapps.inc.php"); + $page->changeTpl('googleapps/admin.tpl'); + $page->assign('xorg_title', 'Polytechnique.org - Administration Google Apps'); + $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); + + if ($action == 'ack') { + $qid = @func_get_arg(2); + if ($qid) { + XDB::execute( + "DELETE FROM gapps_queue + WHERE q_id = {?} AND p_status = 'hardfail'", $qid); + $page->trig("La requête échouée a bien été retirée."); + } + } + + // Retrieves latest pending administrative requests from the gappsd queue. + $res = XDB::iterator( + "SELECT q_id, q_recipient_id, a.alias, j_type, j_parameters, + UNIX_TIMESTAMP(q.p_entry_date) AS p_entry_date + FROM gapps_queue AS q + LEFT JOIN aliases AS a ON (a.id = q_recipient_id AND a.type = 'a_vie') + WHERE p_status IN ('idle', 'active', 'softfail') AND + p_admin_request IS TRUE + ORDER BY p_entry_date"); + while ($request = $res->next()) { + $j_parameters = json_decode($request['j_parameters'], true); + unset($j_parameters['username']); + $parameters = array_keys($j_parameters); + $request['parameters'] = implode(', ', $parameters); + + $page->append('admin_requests', $request); + } + + // Retrieves latest failed requests from the gappsd queue. + $res = XDB::iterator( + "SELECT q.q_id, q.q_recipient_id, a.alias, q.j_type, q.r_result, + UNIX_TIMESTAMP(q.p_entry_date) AS p_entry_date + FROM gapps_queue AS q + LEFT JOIN aliases AS a ON (a.id = q.q_recipient_id AND a.type = 'a_vie') + WHERE q.p_status = 'hardfail' + ORDER BY p_entry_date DESC + LIMIT 20"); + $page->assign('failed_requests', $res); + } + + function handler_admin_job(&$page, $job = null) { + require_once("googleapps.inc.php"); + $page->changeTpl('googleapps/admin.job.tpl'); + $page->assign('xorg_title', 'Polytechnique.org - Administration Google Apps'); + $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); + + if ($job) { + $res = XDB::query( + "SELECT q.*, ao.alias AS q_owner, ar.alias AS q_recipient + FROM gapps_queue AS q + LEFT JOIN aliases AS ao ON (ao.id = q.q_owner_id AND ao.type = 'a_vie') + LEFT JOIN aliases AS ar ON (ar.id = q.q_recipient_id AND ar.type = 'a_vie') + WHERE q_id = {?}", $job); + $sql_job = $res->fetchOneAssoc(); + $sql_job['decoded_parameters'] = var_export(json_decode($sql_job['j_parameters'], true), true); + $page->assign('job', $sql_job); + } + } + + function handler_admin_user(&$page, $user = null, $action = null) { + require_once("emails.inc.php"); + require_once("googleapps.inc.php"); + $page->changeTpl('googleapps/admin.user.tpl'); + $page->assign('xorg_title', 'Polytechnique.org - Administration Google Apps'); + $page->assign('googleapps_admin', GoogleAppsAccount::is_administrator(S::v('uid'))); + + if ($user && !is_numeric($user)) { + $res = XDB::query("SELECT id FROM aliases WHERE alias = {?} AND type != 'homonyme'", $user); + $user = $res->fetchOneCell(); + } + + if ($user) { + $account = new GoogleAppsAccount($user); + $storage = new MailStorageGoogleApps($user); + + // Force synchronization of plat/al and Google Apps passwords. + if ($action == 'forcesync' && $account->sync_password) { + $res = XDB::query("SELECT password FROM auth_user_md5 WHERE user_id = {?}", $user); + $account->set_password($res->fetchOneCell()); + $page->trig('Le mot de passe a été synchronisé.'); + } + + // Displays basic account information. + $page->assign('account', $account); + $page->assign('admin_account', GoogleAppsAccount::is_administrator($user)); + $page->assign('googleapps_storage', $storage->active()); + $page->assign('user', $user); + + // Retrieves user's pending requests. + $res = XDB::iterator( + "SELECT q_id, q_recipient_id, p_status, j_type, UNIX_TIMESTAMP(p_entry_date) AS p_entry_date + FROM gapps_queue + WHERE q_recipient_id = {?} + ORDER BY p_entry_date DESC", $user); + $page->assign('requests', $res); + } + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/templates/googleapps/admin.job.tpl b/templates/googleapps/admin.job.tpl new file mode 100644 index 0000000..56638c9 --- /dev/null +++ b/templates/googleapps/admin.job.tpl @@ -0,0 +1,86 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2008 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +

Requête de la queue Google Apps

+ +{if $job} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Queue id: {$job.q_id}
Propriétaire{if $job.q_owner}{$job.q_owner}{else}none{/if}
Destinataire{if $job.q_recipient}{$job.q_recipient}{else}none{/if}
Statut{$job.p_status}
Priorité{$job.p_priority}
Requête administrateur ?{if $job.p_admin_request}oui{else}non{/if}
Entrée dans la queue{$job.p_entry_date}
Date d'activation{$job.p_notbefore_date}
Début de traitement{if $job.p_start_date}{$job.p_start_date}{else}none{/if}
Fin de traitement{if $job.p_end_date}{$job.p_end_date}{else}none{/if}
Erreurs récupérables{$job.r_softfail_count}
Dernière erreur récupérable{if $job.r_softfail_date}{$job.r_softfail_date}{else}none{/if}
Résultat du traitement{if $job.r_result}{$job.r_result}{else}none{/if}
Type de requête{$job.j_type}
Paramètres
{$job.decoded_parameters}
+{else} +

Aucune requête n'a été trouvée.

+{/if} + +

Retourner à la page d'administration de Google Apps.

+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/googleapps/admin.tpl b/templates/googleapps/admin.tpl new file mode 100644 index 0000000..67e9ccb --- /dev/null +++ b/templates/googleapps/admin.tpl @@ -0,0 +1,100 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2008 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +

Gestion des utilisateurs

+ +
+ + + + + + + + + + +
Administrer un utilisateur (Google Apps)
+
+ +

Queue de requêtes vers Google Apps

+ +

+ Requête nécessitant l'intervention manuelle + d'un administrateur Google Apps {if $googleapps_admin}(tu en es un){/if} : +

+ + + + + + + + + {foreach from=$admin_requests item=r} + + + + + + + + {/foreach} +
qiddaterecipienttypeparameters
{$r.q_id}{$r.p_entry_date|date_format:"%Y-%m-%d %H:%M"}{if $r.alias}{$r.alias}{else}-{/if}{$r.j_type}{$r.parameters}
+ +

+ Requêtes ayant échoué récemment (plus d'information dans la documentation) : +

+ + + + + + + + + + {iterate from=$failed_requests item=r} + + + + + + + + + {/iterate} +
qiddaterecipienttypereason
{$r.q_id}{$r.p_entry_date|date_format:"%Y-%m-%d %H:%M"}{if $r.alias}{$r.alias}{else}-{/if}{$r.j_type}{$r.r_result}{icon name=cross title="Retirer cet échec"}
+ +

Statistiques d'utilisation de Google Apps

+ +
+ Activité Google Apps - 1 mois +
Utilisation des comptes Google Apps sur les 31 derniers jours. +
+ +
+ Activité Google Apps - 1 an +
Utilisation des comptes Google Apps sur les 12 derniers mois. +
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/googleapps/admin.user.tpl b/templates/googleapps/admin.user.tpl new file mode 100644 index 0000000..cb2af6f --- /dev/null +++ b/templates/googleapps/admin.user.tpl @@ -0,0 +1,105 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2008 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +

Compte Google Apps

+ +{if $account} +{assign var=a value=$account} + + + + + + + + + + + + {if $a->suspended()} + + + + {/if} + + + + + + + + + + + + + + + + + + + + +
+
+ Compte = {$a->g_account_name} +
+
+ Google id = {$a->g_account_id}
+ Plat/al id = {$user} +
+
Statut du compte + {$a->g_status} + {if $admin_account}
Compte administrateur de Google Apps{/if} +
Raison de suspension{$a->g_suspension}
Mots de passes synchronisés + {if $a->sync_password} + oui (lancer une synchronisation) + {else}non{/if} +
Redirection des mails{if $googleapps_storage}activée{else}désactivee{/if}
Date de création{$a->r_creation|date_format:"%Y-%m-%d"}
Dernière connexion{$a->r_last_login|date_format:"%Y-%m-%d"}
Dernière utilisation du webmail{$a->r_last_webmail|date_format:"%Y-%m-%d"}
Utilisation du quota mail{$a->r_disk_usage/1024/1024|string_format:"%.2f"}MB

+ + + + + + + + + + + + {iterate from=$requests item=r} + + + + + + + {/iterate} +
Requêtes en attente
qiddatestatuttype
{$r.q_id}{$r.p_entry_date|date_format:"%Y-%m-%d %H:%M"}{$r.p_status}{$r.j_type}
+{else} +

Aucun utilisateur n'a été trouvé.

+{/if} + +

Retourner à la page d'administration de Google Apps.

+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4