April 29, 2024, 10:41:34 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


My first real program with aurora

Started by Rock Ridge Farm (Larry), January 15, 2006, 09:26:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

This is my first effort. I am posting the source and and sample data files.
It can be used as an example but nor reproduced or used without my expressed
consent.
To test create system.dat and user.dat from the supplied example.
Feel free to let me know if you see somewhere I did stuff wrong or could be done
better.
Clicking and item in the first window will populate the second window.
Clicking an item in the second window will populate the third window.


/*
+--------------------------------------------------------------------------+
| OS Acct Admin System/User Viewer                                         |
| (c) 2006 Larry Sikes - All Rights Reserved                               |
| No part of this code may be reporduced or used without prior consent.    |
+--------------------------------------------------------------------------+
| Compile as a windows exe                                                 |
+--------------------------------------------------------------------------+
| Load data (file or database) and allow viewing of systems and users      |
+--------------------------------------------------------------------------+
*/

#AutoDefine "off"

// *************************************************************************
// *                          DEFINITIONS                                  *
// *************************************************************************

#define NMCLICK 0xFFFFFFFE
#define LISTVIEW_1 1
#define LISTVIEW_2 2
#define LISTVIEW_3 3

#define STATIC_10 10
#define STATIC_11 11
#define SYS_COUNT 12
#define USR_COUNT 13


// **************************************************************************
// *                           API DECLARATIONS                             *
// **************************************************************************

DECLARE IMPORT,OutputDebugStringA(lpOuputString as STRING);

// **************************************************************************
// *                              Structures                                *
// **************************************************************************

struct NMLISTVIEW {
def hwndFrom as unsigned int;
def idFrom as INT;
def code as INT;
    def iItem as INT;
    def iSubItem as INT ;
    def uNewState as unsigned int;
    def uOldState as unsigned int;
    def uChanged as unsigned int;
    def ptActionx as INT;
def ptActiony as INT;
    def lParam as INT;
}

// The following are used for DB functions
struct pwdata {
def sys as string;
def uname as string;
def pwflg as string;
def uid as string;
def gid as string;
def gcos as string;
def home as string;
def shell as string;
}

struct sysdata {
def systemname as string;
def location as string;
def certified as string;
def ip as string;
def os as string;
}

struct usrdata{
def systemname as string;
def user_id as string;
def home as string;
def shell as string;
def gcos as string;
}

// ************************************************************************
// *                             DATA STORAGE                             *
// ************************************************************************

pwdata pwdat[1000];
sysdata sysdat[1000];
usrdata usrdat[40000];


// *************************************************************************
// *                         GLOBAL DEFINITIONS                            *
// *************************************************************************

def filename as string;
def sysbuf as string;
def usrbuf as string;
def syscnt as int;
def usrcnt as int;
def lodcnt as int;
def pwcnt as int;
def file1 as unsigned int;
def file2 as unsigned int;

// Menu constants
const FILE_QUIT   =  1;
const HELP_ABOUT  =  2;

// **************************************************************************
// *                          CLASS DEFINITIONS                             *
// **************************************************************************

class dlg:dialog {
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnNotify(int code,int nID,NMHDR *pnmhdr),int;
declare loadList(int listno, ClistView *plist),int;
declare OnMenuPick(int nID),int;
declare ShowAbout(), int;
}

global sub main()
{
dlg d1;
d1.Create(0,0,520,550,0x80C80080,0,"OS Acct Admin System Viewer",0);
d1.AddControl(CTLISTVIEW,"",10,10,500,145,AWS_VISIBLE|ALVS_REPORT|AWS_BORDER|AWS_HSCROLL|AWS_VSCROLL,AWS_EX_CLIENTEDGE,LISTVIEW_1);
d1.AddControl(CTLISTVIEW,"",10,160,500,145,AWS_VISIBLE|ALVS_REPORT|AWS_BORDER|AWS_HSCROLL|AWS_VSCROLL,AWS_EX_CLIENTEDGE,LISTVIEW_2);
d1.AddControl(CTLISTVIEW,"",10,310,500,145,AWS_VISIBLE|ALVS_REPORT|AWS_BORDER|AWS_HSCROLL|AWS_VSCROLL,AWS_EX_CLIENTEDGE,LISTVIEW_3);
d1.AddControl(CTSTATIC,"System Count:",80,490,210,490,0x5000010B,0x0,STATIC_10);
d1.AddControl(CTEDIT,"",170,485,50,20,0x50800800,0x200,SYS_COUNT);
d1.AddControl(CTSTATIC,"User Count:",300,490,210,490,0x5000010B,0x0,STATIC_11);
d1.AddControl(CTEDIT,"",375,485,50,20,0x50800800,0x200,USR_COUNT);

d1.DoModal();
return 0;
}

dlg::OnClose(),int{
CloseDialog(1);
return true;
}


dlg::ShowAbout(),int{
string msg;
msg = "OS Acct Admin Viewer\n\n"   +
"(c) 2006 Lawrence H. Sikes\n" +
"All Rights Reserved";
MessageBox(0,msg,"About...",0);
return true;
}

dlg::OnInitDialog(),int
{
menu m;

CListView *pList1 = GetControl(LISTVIEW_1);
CListView *pList2 = GetControl(LISTVIEW_2);
CListView *pList3 = GetControl(LISTVIEW_3);
LoadList(1,pList1);
LoadList(2,pList2);
LoadList(3,pList3);
m.BeginMenu();
    m.MenuTitle("&File");
    m.MenuItem("Quit",0,1);
    m.MenuTitle("&Help");
    m.MenuItem("About",0,2);
m.EndMenu();
SetMenu(m.Detach());
CenterWindow();
return true;
}

dlg::OnNotify(int code,int nID,NMHDR *pnmhdr),int {
CListView *pList1 = GetControl(1);
CListView *pList2 = GetControl(2);
CListView *pList3 = GetControl(3);
string sysbfr;

if(code = 0xFFFFFFFE){
if(nID = 1) {
sysbfr = pList1->GetItemText(*(NMLISTVIEW)pnmhdr.iItem,0);
pList2->DeleteAllItems();
pList3->DeleteAllItems();
DoShowUsr(sysbfr,pList2);
}
if(nID = 2){
sysbfr = pList2->GetItemText(*(NMLISTVIEW)pnmhdr.iItem,0);
pList3->DeleteAllItems();
DoShowXref(sysbfr,pList3);
}
}
return true;
}
dlg::loadlist(int listno, ClistView *Plist),int
{
CEdit *pEdit;
if(listno = 1){
pList->InsertColumn(0,"   System Name   ");
pList->InsertColumn(1,"       Location       ");
pList->InsertColumn(2,"Certified");
pList->InsertColumn(3,"   IP Address   ");
pList->InsertColumn(4,"   Op Sys   ");
syscnt = 0;
DoLoadsys(pList);
pEdit = GetControl(SYS_COUNT);
pEdit->SetText(str$(syscnt));
pList->SetExtendedStyle(ALVS_EX_FLATSB|ALVS_EX_FULLROWSELECT|ALVS_EX_GRIDLINES|ALVS_EX_LABELTIP);
}

else if(listno = 2){
pList->InsertColumn(0,"  User ID   ");
pList->InsertColumn(1,"             Home Dir            ");
pList->InsertColumn(2,"        Shell        ");
pList->InsertColumn(3,"              Comment             ");
DoLoadUsr(pList);
pEdit = GetControl(USR_COUNT);
pEdit->SetText(str$(usrcnt));
pList->SetExtendedStyle(ALVS_EX_FLATSB|ALVS_EX_FULLROWSELECT|ALVS_EX_GRIDLINES|ALVS_EX_LABELTIP);
}
else if(listno = 3){
pList->InsertColumn(0,"   System Name   ");
pList->InsertColumn(1,"  User ID   ");
pList->InsertColumn(2,"             Home Dir             ");
pList->InsertColumn(3,"        Shell       ");
pList->SetExtendedStyle(ALVS_EX_FLATSB|ALVS_EX_FULLROWSELECT|ALVS_EX_GRIDLINES|ALVS_EX_LABELTIP);
}
return 0;
}

dlg::OnMenuPick(int nID),int
{
select nID {
case FILE_QUIT:
CloseDialog(1);
case HELP_ABOUT:
ShowAbout();
}
return true;
}

// ***********************************************************************
// *                             SUBROUTINES                             *
// ***********************************************************************

SUB DoLoadsys(ClistView *Plist){
filename = "system.dat";
// Format of data in systems file:
// System Name|Location|Lockdown Certified|IP address|Operating System
if(len(filename) > 0){
file1 = OpenFile(filename,MODE_READ);
if(file1 = -1) {
MessageBox(0,"No System Data Loaded","Information");
} else {
do{
if(ReadString(file1,sysbuf,255)<>0){
DoParseSys(Plist);
}
} until Eof(file1);
CloseFile(file1);
}
}
return;
}

SUB DoLoadUsr(ClistView *Plist){
filename = "user.dat";
// Format of data in user file:
// System Name:uname:!:uid:gid:gcos:home:shell
if(len(filename) > 0){
file2 = OpenFile(filename,MODE_READ);
if(file2 = -1) {
MessageBox(0,"No User Data Loaded","Information");
} else {
do{
if(ReadString(file2,usrbuf,255)<>0){
DoParseUsr(Plist);
}
} until Eof(file1);
CloseFile(file1);
}
}
return;
}

SUB DoParseSys(ClistView *Plist){
unsigned int pos;
unsigned int curpos;

curpos = 1;
pos = instr(sysbuf,"|",curpos);
pList->InsertItem(syscnt,mid$(sysbuf,curpos,pos - 1));
sysdat[syscnt].systemname = mid$(sysbuf,curpos,pos - 1);
curpos = pos + 1;
pos = instr(sysbuf,"|",curpos);
pList->SetItemText(syscnt,1,mid$(sysbuf,curpos,pos - curpos));
sysdat[syscnt].location = mid$(sysbuf,curpos,pos - curpos);
curpos = pos + 1;
pos = instr(sysbuf,"|",curpos);
pList->SetItemText(syscnt,2,mid$(sysbuf,curpos,pos - curpos));
sysdat[syscnt].certified = mid$(sysbuf,curpos,pos - curpos);
curpos = pos + 1;
pos = instr(sysbuf,"|",curpos);
pList->SetItemText(syscnt,3,mid$(sysbuf,curpos,pos - curpos));
sysdat[syscnt].ip = mid$(sysbuf,curpos,pos - curpos);
curpos = pos + 1;
pos = instr(sysbuf,"|",curpos);
pList->SetItemText(syscnt,4,mid$(sysbuf,curpos,pos - curpos));
sysdat[syscnt].os = mid$(sysbuf,curpos,pos - curpos);
syscnt++;
return;
}

SUB DoParseUsr(ClistView *plist){
unsigned int pos;
unsigned int curpos;

curpos = 1;
if(usrcnt > 39000)
return;
pos = instr(usrbuf,":",curpos);
usrdat[usrcnt].systemname = mid$(usrbuf,curpos,pos - 1);
curpos = pos + 1;
pos = instr(usrbuf,":",curpos);
usrdat[usrcnt].user_id = mid$(usrbuf,curpos,pos - curpos);
// Skip 3 fields
curpos = pos + 1;
pos = instr(usrbuf,":",curpos);
curpos = pos + 1;
pos = instr(usrbuf,":",curpos);
curpos = pos + 1;
pos = instr(usrbuf,":",curpos);
curpos = pos + 1;
pos = instr(usrbuf,":",curpos);
usrdat[usrcnt].gcos = mid$(usrbuf,curpos,pos - curpos);
curpos = pos + 1;
pos = instr(usrbuf,":",curpos);
usrdat[usrcnt].home = mid$(usrbuf,curpos,pos - curpos);
curpos = pos + 1;
pos = instr(usrbuf,":",curpos);
usrdat[usrcnt].shell = mid$(usrbuf,curpos,pos - curpos);
usrcnt++;
return;
}

SUB DoShowUsr(string sysbfr, CListView *pList) {
unsigned int i,lodcnt;

lodcnt = 0;
i = 0;
do {
if(usrdat[i].systemname = sysbfr) {
pList->InsertItem(lodcnt,usrdat[i].user_id);
pList->SetItemText(lodcnt,1,usrdat[i].home);
pList->SetItemText(lodcnt,2,usrdat[i].shell);
pList->SetItemText(lodcnt,3,usrdat[i].gcos);
lodcnt++;
}
i++;
} until(i = usrcnt);
if(lodcnt = 0){
messagebox(0,"No user data for this system","User Data");
}
return;
}


SUB DoShowXref(string sysbfr, CListView *pList) {
unsigned int i,lodcnt;

lodcnt = 0;
i = 0;
do {
if(usrdat[i].user_id = sysbfr) {
pList->InsertItem(lodcnt,usrdat[i].systemname);
pList->SetItemText(lodcnt,1,usrdat[i].user_id);
pList->SetItemText(lodcnt,2,usrdat[i].home);
pList->SetItemText(lodcnt,3,usrdat[i].shell);
pList->SetItemText(lodcnt,4,usrdat[i].gcos);
lodcnt++;
}
i++;
} until(i = usrcnt);
if(lodcnt = 0){
messagebox(0,"No additional systems for this user","User Data");
}
return;
}


The user data file format:
BLDFTTNV01:root:!:0:0::/:/usr/bin/ksh
BLDFTTNV01:daemon:!:1:7::/etc:
BLDFTTNV01:bin:!:2:2::/bin:
BLDFTTNV01:sys:!:3:3::/usr/sys:
BLDFTTNV01:adm:!:4:4::/var/adm:
BLDFTTNV01:uucp:!:5:5::/usr/lib/uucp:
BLDFTTNV01:nobody:!:-2:-2::/:
BLDFTTNV01:lpd:!:9:9::/:
BLDFTTNV01:nuucp:*:6:5::/var/spool/uucppublic:/usr/sbin/uucp/uucico
BLDFTTNV01:lp:*:11:11::/var/spool/lp:/bin/false
BLDFTTNV01:ipsec:*:203:1::/etc/ipsec:/usr/bin/ksh
BLDFTTXGW01:root:!:0:0::/:/usr/bin/ksh
BLDFTTXGW01:daemon:!:1:7::/etc:
BLDFTTXGW01:bin:!:2:2::/bin:
BLDFTTXGW01:sys:!:3:3::/usr/sys:
BLDFTTXGW01:adm:!:4:4::/var/adm:
BLDFTTXGW01:uucp:!:5:5::/usr/lib/uucp:
BLDFTTXGW01:nobody:!:-2:-2::/:
BLDFTTXGW01:lpd:!:9:9::/:
BLDFTTXGW01:snapp:*:224:12:snapp login user:/usr/sbin/snapp:/usr/sbin/snappd
BLDFTTXGW01:ipsec:*:225:1::/etc/ipsec:/usr/bin/ksh
BLDFTTXGW01:nuucp:*:6:5:uucp login user:/var/spool/uucppublic:/usr/sbin/uucp/uucico
SACRS29:root:!:0:0::/:/bin/ksh
SACRS29:daemon:!:1:1::/etc:/bin/false
SACRS29:bin:!:2:2::/bin:/bin/false
SACRS29:sys:!:3:3::/usr/sys:/bin/false
SACRS29:adm:!:4:4::/var/adm:/bin/false
SACRS29:uucp:!:5:5::/usr/lib/uucp:/bin/false
SACRS29:guest:!:100:100::/home/guest:
SACRS29:nobody:!:-2:-2::/:/bin/false
SACRS29:lpd:!:9:-2::/:/bin/false
SACSUN90:root:x:0:1:Super-User:/:/sbin/sh
SACSUN90:daemon:x:1:1::/:/bin/false
SACSUN90:bin:x:2:2::/usr/bin:/bin/false
SACSUN90:sys:x:3:3::/:/bin/false
SACSUN90:adm:x:4:4:Admin:/var/adm:/bin/false
SACSUN90:lp:x:71:8:Line Printer Admin:/usr/spool/lp:/bin/false
SACSUN90:uucp:x:5:5:uucp Admin:/usr/lib/uucp:/bin/false
SACSUN90:nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/bin/false
SACSUN90:listen:x:37:4:Network Admin:/usr/net/nls:/bin/false
SACSUN90:nobody:x:60001:60001:Nobody:/:/bin/false
SACSUN90:noaccess:x:60002:60002:No Access User:/:/bin/false

The system data file format:
BLDFTTXGW01|Boulder|yes|192.168.40.4|AIX
SACRS29|Rancho Cordova|yes|192.168.4.5.89|AIX
SACSUN90|Rancho Cordova|no|192.168.5.7|SunOS
SMOM01BDC04|San Mateo|no|191.180.4.1|WINNT
SMONAS2393|San Mateo|yes|191.168.4.18|W3K

Doc

Compiles and works like a charm on this end.

Pretty fancy stuff for a first project... I'm envious.   :P ;D

-Doc-

Bruce Peaslee

Quote from: docmann on January 15, 2006, 05:55:32 PM
Compiles and works like a charm on this end.

Pretty fancy stuff for a first project... I'm envious.ÂÃ,  ÂÃ, -Doc-

Same here. Not bad at all.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

It looks nice, now if only I could get my project to work :)

I might suggest adding the optional parameter 0 to STR$ unless you're counting on having decimal pieces of users ;)
For example, line 207 will change to pEdit->SetText(str$(syscnt,0)); and that will remove the decimal.

Rock Ridge Farm (Larry)

Added the ,0 to the str$ - thanks. Does look better.