Announcement

Collapse
No announcement yet.

Show who's logged onto domain and display as a table in HTML

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Show who's logged onto domain and display as a table in HTML

    Hi all,

    It has been a while since I have visited these forums to post a question but that time has come once again!

    I have been working on a very simple way to display who is logged onto our network at any one time, export a list of these data to a csv file and then import that csv to a HTML file so that it can be viewed by our receptionist. (A kind of rudimentary In-Out board.

    Heres what I have: (bear with me please, I know it's a long post!)

    Using psloggedon for this. I have one batchfile that exports the results of the following batch file to a csv:


    Code:
    @echo off
    setlocal
    for /f "Tokens=1" %%c in ('net view /domain:"%USERDOMAIN%"^|Findstr /L /C:"\\"') do (
     for /f "Tokens=*" %%u in ('PsLoggedOn -L %%c^|find /i "%USERDOMAIN%\"') do (
      call :report %%c "%%u"
     )
    )
    endlocal
    goto :EOF
    :report
    set work=%1
    set comp=%work:~2%
    set user=%2
    set user=%user:"=%
    call set user=%%user:*%USERDOMAIN%\=%%
    @echo %comp%,%user%
    I realise that on a large network this would take an extreme amount of time to run but on our network it only takes a minute or so. Again if anyone can throw any better ideas in I am always willing to listen.

    Anyway, The csv uses commas as its delimiter. The part I am stuck on is a way of importing the newly generated csv file into an HTML document. Currently I have found some sources on the net that do this using java. I have been using the code below:


    Code:
     
    /**
     *      Name:       csv2html.js
     *      Author:     Daren Thiel
     *      Date:       5/30/00
     *      Website:    http://www.winscripter.com
     *
     *      Comments:   Converts a comma separated Values (CSV)
     *      file into an HTML table
     *
     **/
    var src   = "userlist.csv";
    var dest  = "results.html";
    var fso, fin, fout;
    var data = new Array();
    var forReading   = 1;
    var forWriting   = 2;
    var forAppending = 8;
    fso  = new ActiveXObject( "Scripting.FileSystemObject" );
    fin  = fso.OpenTextFile( src, forReading );
    fout = fso.OpenTextFile( dest, forWriting, true );
    fout.WriteLine( htmlHeader() );
    fout.WriteLine( "<table border='0' cellpadding='1' cellspacing='0' width='100%'>" );
    while( !fin.AtEndOfStream )
    {
     try
     {
      var line = fin.ReadLine();
      if( line == "" )
        continue;
      data = line.split( "," );
      fout.WriteLine( "<tr>" );
      for( i = 0; i < data.length; i++ )
      {
       fout.WriteLine( "<td>" + data[i] + "</td>" );
      }
      fout.WriteLine( "</tr\r\n" );
     }
     catch( e )
     {
      WScript.Echo( "Error: " + e.description );
     }
    }
    fout.WriteLine( "</table>" );
    fout.WriteLine( htmlFooter() );
    fin.Close();
    fout.Close();
     
    /*******************************
     HTML Header data
    ********************************/
    function htmlHeader()
    {
     var title = "CSV2HTML";
     var head = "<html>\r\n<head\r\n";
     head += "<title>" + title + "</title>\r\n";
     head += "<style>\r\n";
     head += " TD { \r\n";
     head += "    font-family: verdana;\r\n";
     head += "    font-size: 10pt; \r\n";
     head += "    border-bottom: thin groove lightyellow;\r\n";
     head += "    border-top: thin groove lightyellow;\r\n";
     head += "    color: blue; background: lightgrey;\r\n";
     head += " }\r\n";
     head += "</style>\r\n";
     head += "</head>\r\n<body\r\n";
     return( head );
    }
    /*******************************
     HTML Footer data
    ********************************/
    function htmlFooter()
    {
     var foot = "\r\n</body>\r\n</html>";
     return( foot );
    }

    I copied the above code into a textfile, relabling it csv2html.js.

    I then triggered this from an html document using the following source:

    Code:
     
    <html>
    <body>
    <script type="text/javascript" src="csv2html.js"></script>
    </body>
    </html>
    The problem I am having is that the java keeps failing at 'line 23 character 1 (highlighted in red on the above java source.

    Does anyone have any ideas here. I have puzzled over this until I'm cross eyed!

    Thanks a lot all

    Dave

  • #2
    Re: Show who's logged onto domain and display as a table in HTML

    It appears (e.g. http://programming.top54u.com/post/J...le-Method.aspx) that a path and filename are needed.
    Try giving a full path and name to src e.g. C:\files\userlist.csv
    Alternatively get the working directory and prepend that to the file name
    Last edited by Ossian; 18th January 2010, 14:29.
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Show who's logged onto domain and display as a table in HTML

      Thanks Ossian,

      See I knew it was something incredibly simple! With the full paths to the source and destination files in place it works perfectly.

      Thanks once again

      Dave

      Comment


      • #4
        Re: Show who's logged onto domain and display as a table in HTML

        No problem -- glad you got it working
        I may have to pinch your code myself!!!!
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment

        Working...
        X