Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic SYNERGY (steve huntington)
Decrease font size
Increase font size
Topic Title: Users and their Roles
Topic Summary: Displaying who has what power in HTML
Created On: 10-May-2007 22:07
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 10-May-2007 22:07
User is offline View Users Profile Print this message


Jacob Silvia

Posts: 4
Joined: 25-Oct-2006

(This is a crossposting of a post I made on CM Crossroads. I thought I'd share it here, too)

I was inspired by this old post from CM Crossroads to write the following script using the CSAPI: http://www.cmcrossroads.com/component/option,com_smf/Itemid,180/topic,48432.msg49188

(Special thanks to Bill M for his perl script)

This script opens the specified database (caveat emptor: there is some site-specific tailoring) and reads the user role information. It then outputs it to the file userroles_<db_alias>.html.

You would call it as such:

perl userroles.pl <database>
  or
userroles.pl <database>

In its current state, it's better as a cron job, but if you're 1337 enough (I'm only 1336...), then you can fashion it into a trigger that'll fire every time a user/role sort of thing gets updated.

I intentionally didn't use the CGI module, but you're welcome to modify the code in order to do so.

Feel free to modify this code to make it better. I'm sorry if any bits of it are outrageously JAPH-y.

--------------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl

use ChangeSynergy::csapi;

my $csapi     = new ChangeSynergy::csapi();
my $raw_data  = [];
my $roles     = {};
my $user_data = {};
my $db_alias  = shift;
$db_alias   ||= "cm_database"; # tailor this if you want it to automatically do a default
my $database  = "\\\\angler\\ccmdb\\" . $db_alias; # tailor to your site

my $secret_users = "(" . join("|", qw/ccm_root ChangeAdmin csuser/) . ")"; # feel free to change these to whatever names you don't want popping up

$csapi->setUpConnection("http", "angler", 8600); # Tailor this
my $aUser = $csapi->Login("u00001", 'u00001', "User", $database); # tailor this
my $tmp = $csapi->QueryData($aUser, "Basic Summary", "has_attr('users')", undef, undef, undef, "users");

for (my $i = 0; $i < $tmp->getDataSize(); $i++) {
  my $tmp2 = $tmp->getDataObject($i);
  $raw_data->[$i] = $tmp2->getDataObjectByName("users")->getValue();
}

foreach (sort @{$raw_data}) {
  my @raw_data = split(/\n+/, $_);
  foreach (@raw_data) {
    next unless $_ =~ /^user /;
    $_ =~ s/;$//;
    my @user_line = split(/\s+/, $_);
    foreach (@user_line[3..$#user_line]) {
 $roles->{$_} += 1;
 $user_data->{$user_line[1]}->{$_} += 1;
    }
  }
}

open HTMLOUT, ">userroles_${db_alias}.html";

select HTMLOUT;

print "<html>\n";
print "<head>\n";
print "<title>";
print "User list for ", $database;
print "</title>\n";
print "</head>\n";
print "<body bgcolor='aliceblue'>\n"; # this is my favorite HTML color...
print "<table cellspacing='0' cellpadding='5' align='center' style='border:1px solid black'>\n";
print "<caption>";
print "";
print $database;
print "
";
print "</caption>";
print "<tr bgcolor='black' style='color:aliceblue'>\n";
print "<td>\ </td>\n";
foreach (sort {uc($a) cmp uc($b)} keys %{$roles}) {
  print "<td>";
  print "";
  print $_;
  print "
";
  print "</td>\n";
}
print "</tr>\n";
my $bit;
foreach my $usr (sort {uc($a) cmp uc($b)} keys %{$user_data}) {
  next if $usr =~ /$secret_users/;
  print "<tr";
  if ($bit) {
    print " bgcolor='white'";
    $bit = not $bit;
  } else {
    print " bgcolor='palegreen'";
    $bit = not $bit;
  }
  print ">\n";
  print "<td>";
  print "";
  print $usr;
  print "
";
  print "</td>\n";
  foreach my $rol (sort {uc($a) cmp uc($b)} keys %{$roles}) {
    print "<td align='center' style='border-left:solid black 1px'>";
    if ($user_data->{$usr}->{$rol} > 0) {
      print "x";
    } else {
      print "\ ";
    }
    print "</td>\n";
  }
  print "</tr>\n";
}
print "</table>\n";
print "<div align='center'>\n";
print "Report Generated On: ";
print scalar(localtime);
print "</div>\n";
print "</body>\n";
print "</html>\n";

select STDOUT;

close HTMLOUT;



-------------------------
The comments and opinions expressed are my own and do not represent the view of United Space Alliance.
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic SYNERGY forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 15:34.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.