summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-19 15:00:18 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-19 15:00:18 +0100
commitd2c2dab3607cf663c57d420ae0e08ca214d8297d (patch)
tree1ab4b9569dd256d23616734012c58eb292fa9896
parent6dbdc6f37600ec1bdc817c4dd8384e18ca344d07 (diff)
downloadeurephia-d2c2dab3607cf663c57d420ae0e08ca214d8297d.tar.gz
eurephia-d2c2dab3607cf663c57d420ae0e08ca214d8297d.tar.xz
eurephia-d2c2dab3607cf663c57d420ae0e08ca214d8297d.zip
users command: Added showing a users lastlog
-rw-r--r--eurephiadm/commands/users.c84
1 files changed, 83 insertions, 1 deletions
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c
index bc54eec..b90c49d 100644
--- a/eurephiadm/commands/users.c
+++ b/eurephiadm/commands/users.c
@@ -307,6 +307,87 @@ void xmlPrint_certs(xmlXPathContext *certsXP, const char *xpath) {
xmlXPathFreeObject(certsObj);
}
+void xmlPrint_lastlog(xmlXPathContext *xpathCTX, const char *xpath) {
+ xmlXPathObject *lastlogObj = NULL;
+ int i = 0;
+ char tmp[66];
+
+ // Find the certificates in the given XPath query
+ lastlogObj = xmlXPathEvalExpression((xmlChar *)xpath, xpathCTX);
+ if( lastlogObj == NULL ) {
+ fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpath);
+ return;
+ }
+
+ // If no certs were found, inform and exit
+ if( lastlogObj->nodesetval->nodeNr == 0 ) {
+ printf("No lastlog entries found.\n");
+ printf("\n");
+ xmlXPathFreeObject(lastlogObj);
+ return;
+ }
+
+ memset(&tmp, 0, 66);
+ printf(" %-10.10s %-22.22s %19.19s %19.19s\n",
+ "Status", "Login", "Logout", "Session closed");
+ printf(" %-10.10s %-22.22s %19.19s %19.19s\n",
+ "Protocol", "Remote:port", "VPN MAC", "VPN IP");
+ printf(" %-37.37s %37.37s\n", "Common name", "Organisation");
+#ifdef FIREWALL
+ printf(" %-37.37s %37.37s\n", "Firewall access profile", "FW Destination");
+#endif
+ printf(" --------------------------------------------------------------------"
+ "----------\n");
+
+ for( i = 0; i < lastlogObj->nodesetval->nodeNr; i++ ) {
+ xmlNode *session_n = lastlogObj->nodesetval->nodeTab[i];
+ xmlNode *conn = NULL, *cert = NULL, *acpr;
+
+ if( (session_n == NULL) || (session_n->type != XML_ELEMENT_NODE) ) {
+ continue;
+ }
+
+ conn = xmlFindNode(session_n, "connection");
+ cert = xmlFindNode(session_n, "certificate");
+ acpr = xmlFindNode(cert, "access_profile");
+
+ printf(" %-10.10s %-22.22s %19.19s %19.19s\n",
+ xmlGetAttrValue(session_n->properties, "session_status"),
+ xmlGetNodeContent(session_n, "login"),
+ defaultValue(xmlGetNodeContent(session_n, "logout"), "-"),
+ defaultValue(xmlGetNodeContent(session_n, "session_closed"), "-")
+ );
+
+ snprintf(tmp, 64, "%s:%s",
+ xmlGetNodeContent(conn, "remote_host"),
+ xmlGetNodeContent(conn, "remote_port"));
+ printf(" %-10.10s %-22.22s %19.19s %19.19s\n",
+ xmlGetNodeContent(conn, "protocol"),
+ tmp,
+ defaultValue(xmlGetNodeContent(conn, "vpn_macaddr"), "(not available)"),
+ xmlGetNodeContent(conn, "vpn_ipaddr")
+ );
+
+ printf(" %-37.37s %37.37s\n",
+ xmlGetNodeContent(cert, "common_name"),
+ xmlGetNodeContent(cert, "organisation")
+ );
+#ifdef FIREWALL
+ printf(" %-37.37s %37.37s\n",
+ defaultValue(xmlExtractContent(acpr), "(not set)"),
+ defaultValue(xmlGetAttrValue(acpr->properties, "fwdestination"), "-")
+ );
+#endif
+ printf("\n");
+
+ }
+
+ printf(" --------------------------------------------------------------------"
+ "----------\n");
+
+ xmlXPathFreeObject(lastlogObj);
+}
+
// Show account information for a particular user
int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
@@ -431,7 +512,8 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
}
if( show_info & USERINFO_lastlog ) {
- xmlSaveFormatFileEnc("-", user_xml, "UTF-8", 1);
+ printf("** Lastlog entries for %s\n\n", xmlGetNodeContent(user_n, "username"));
+ xmlPrint_lastlog(user_XP, "/eurephia/user/lastlog/session");
}
if( (show_info & USERINFO_attempts) || (show_info & USERINFO_blacklist) ) {