diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2009-03-31 23:45:03 +0200 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-03-31 23:45:03 +0200 |
commit | afdfa16296a9879c6c8fa1e0b8aebe8d1cddc2d6 (patch) | |
tree | 3c21cb027635a335034e0b332a72cc381b4deb60 | |
parent | e729a4b80c79a80b9acfd58c0f45707572eb1861 (diff) | |
download | eurephia-afdfa16296a9879c6c8fa1e0b8aebe8d1cddc2d6.tar.gz eurephia-afdfa16296a9879c6c8fa1e0b8aebe8d1cddc2d6.tar.xz eurephia-afdfa16296a9879c6c8fa1e0b8aebe8d1cddc2d6.zip |
Rewrote eurephiadm/adminaccess to use XSLT for listing
-rw-r--r-- | eurephiadm/commands/adminaccess.c | 37 | ||||
-rw-r--r-- | xslt/eurephiadm/adminaccess.xsl | 74 |
2 files changed, 77 insertions, 34 deletions
diff --git a/eurephiadm/commands/adminaccess.c b/eurephiadm/commands/adminaccess.c index 79c8a71..056b314 100644 --- a/eurephiadm/commands/adminaccess.c +++ b/eurephiadm/commands/adminaccess.c @@ -43,7 +43,7 @@ #include "../argparser.h" #include "../field_print.h" - +#include "../xsltparser.h" void display_adminaccess_help(int page) { switch( page ) { @@ -105,7 +105,7 @@ int help_AdminAccess2(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *c int list_adminaccess(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { xmlDoc *list_xml = NULL, *srch_xml = NULL; - xmlNode *list_n = NULL, *srch_n = NULL, *tmp_n = NULL, *acl_n = NULL; + xmlNode *srch_n = NULL, *tmp_n = NULL; int i = 0; char *uid = NULL, *username = NULL, *intf = NULL, *acl = NULL; @@ -172,38 +172,7 @@ int list_adminaccess(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cf return 1; } - list_n = eurephiaXML_getRoot(ctx, list_xml, "admin_access_list", 1); - if( list_n == NULL ) { - fprintf(stderr, "%s: Error retrieving user access list\n", MODULE); - xmlFreeDoc(list_xml); - return 1; - } - - printf(" [uid] Username Intf. Access level\n"); - printf("----------------------------------------------------------------------------\n"); - for( list_n = list_n->children; list_n != NULL; list_n = list_n->next ) { - tmp_n = xmlFindNode(list_n, "username"); - printf(" [%3.3s] %-30.30s ", - xmlGetAttrValue(tmp_n->properties, "uid"), - xmlGetNodeContent(list_n, "username")); - - int first = 1; - acl_n = xmlFindNode(list_n, "access_levels"); - for( acl_n = acl_n->children ; acl_n != NULL; acl_n = acl_n->next ) { - if( !first ) { - printf(" "); - } else { - first = 0; - } - printf("%s %s\n", - xmlGetAttrValue(acl_n->properties, "interface"), - acl_n->children->content); - } - if( list_n->next != NULL ) { - printf("\n"); - } - } - printf("----------------------------------------------------------------------------\n"); + xslt_print_xmldoc(stdout, cfg, list_xml, "adminaccess.xsl", NULL); xmlFreeDoc(list_xml); return 0; } diff --git a/xslt/eurephiadm/adminaccess.xsl b/xslt/eurephiadm/adminaccess.xsl new file mode 100644 index 0000000..2edfdd7 --- /dev/null +++ b/xslt/eurephiadm/adminaccess.xsl @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<!-- + * + * GPLv2 only - Copyright (C) 2009 + * David Sommerseth <dazo@users.sourceforge.net> + * + * 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; version 2 + * of the License. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * +--> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:output method="text" encoding="UTF-8"/> + <xsl:strip-space elements="*"/> + + <xsl:template match="/eurephia"> + <xsl:text> [uid] Username Intf. Access level </xsl:text> + <xsl:text> ------------------------------------------------------------------------------ </xsl:text> + <xsl:apply-templates select="admin_access_list/user_access"/> + <xsl:text> ------------------------------------------------------------------------------ </xsl:text> + </xsl:template> + + <xsl:template match="/eurephia/admin_access_list/user_access"> + <xsl:text> [</xsl:text> + <xsl:call-template name="right-align"> + <xsl:with-param name="value" select="username/@uid"/> + <xsl:with-param name="width" select="3"/> + </xsl:call-template> + <xsl:text>] </xsl:text> + + <xsl:call-template name="left-align"> + <xsl:with-param name="value" select="username"/> + <xsl:with-param name="width" select="30"/> + </xsl:call-template> + <xsl:text> </xsl:text> + + <xsl:for-each select="access_levels/access"> + <xsl:if test="position() > 1"> + <xsl:text> </xsl:text> + </xsl:if> + <xsl:value-of select="substring(@interface, 1)"/> + <xsl:text> </xsl:text> + <xsl:value-of select="."/> + <xsl:text> </xsl:text> + </xsl:for-each> + <xsl:if test="(last() > position()) and (count(access_levels/access)>1)"> + <xsl:text> </xsl:text> + </xsl:if> + </xsl:template> + + + <xsl:template name="left-align"> + <xsl:param name="value"/> + <xsl:param name="width"/> + <xsl:value-of select="substring(concat($value, ' '), 1, $width)"/> + </xsl:template> + + <xsl:template name="right-align"> + <xsl:param name="value"/> + <xsl:param name="width"/> + <xsl:value-of select="concat(substring(' ', 1, $width - string-length($value)), $value)"/> + </xsl:template> + +</xsl:stylesheet> |