Exchange 2007 Mail Contact going to Gmail and Calendar Integration

A mail contact in Exchange 2007 that points to a Gmail account and the complaint was that they did not get proper calendar invites, they got a text email with the dreaded winmail.dat

The fix is to edit the mail contact in Exchange and change the Rich Text Format to Never for the contact.

Whatsup Gold public satus page

Here is a simple example of a WhatsUp Gold public status page to show to end users. It will show the status of devices without giving them extra information they do not need.


<% @LANGUAGE="VBScript"%>

<% publicview = "Group To Show" Set adoCon = Server.CreateObject("ADODB.Connection") adoCon.Open "DSN=WhatsUp" Set rs = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT * FROM DeviceGroup where sGroupName = '" & publicview & "';" rs.open strSQL,adoCon groupid = rs("nDeviceGroupID") rs.close strSQL = "Select * from PivotDeviceToGroup where nDeviceGroupID = " & groupid rs.open strSQL,adoCon deviceswewant = "" do while not rs.eof if not deviceswewant = "" then deviceswewant = deviceswewant & " OR " end if deviceswewant = deviceswewant & "(nDeviceID=" & rs("nDeviceID") & ")" rs.movenext loop rs.close strSQL = "select * from Device where " & deviceswewant & ";" rs.open strSQL,adoCon %>
<% do while not rs.eof 'accessing null data seems to corrupt the recordset. Put all your values into variabled before checking maintenacemode status = rs("sStatus") name = rs("sDisplayName") maintenancemode = rs("bManualMaintenanceMode") response.write "" response.write "" if not isnull(maintenancemode) then response.write "" elseif status = "" then response.write "" else response.write "" end if response.write "" rs.movenext loop rs.close %>
name status
" & name & "" & "Maintenace Mode :|" & "" & "Happy Camper :)" & "" & "Experiencing Problems :(" & "



Knowledgetree Command Line Drop Box in Perl

I needed an easy way to push documents to the KT implementation. After looking at how KT’s windows drop box software works I wrote something similar in Perl that works from the command line.

I plan to wrap an Automator action around this to upload documents easily.

#stephen
#www.stephenjc.com
#ktdrop.pl
#command line drop box
#usage: ./ktdrop.pl username password fullpath_to_file

use SOAP::Lite;
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Request::Common;
use XML::Simple;

#username and password for KT
$username = $ARGV[0];
$password = $ARGV[1];

#prefix http or https
$serverPre = 'https://';

#full server url with port
$serverUrl = 'server.com:port/kt';

#document type for uploaded documents, make sure nothing is required because we will not send any metadata
$ktDocumenttype = 'default';

#if you have http basic leave this, otherwise change it to ''
$httpAuth = $username . ':' . $password . '@';
$fullUrl = $serverPre.$httpAuth.$serverUrl.'/ktwebservice/';
$session = SOAP::Lite->new(proxy => $fullUrl . 'webservice.php?wsdl');

$file = $ARGV[2];

#login
$r = $session->login($username,$password,'127.0.0.1');
$ktsessionid = $r->valueof('//message');

#dropbox folder id for user
$r = $session->get_folder_detail_by_name($ktsessionid,"DroppedDocuments/$username");
$dropboxid = $r->valueof('//id');

#upload document
$uploadRes = ktUpload();

#move file to dms
$r = $session->add_document($ktsessionid,$dropboxid,$uploadRes->{name},$uploadRes->{name},$ktDocumenttype,$uploadRes->{filename});
if ($r->valueof('//status_code') == 0)
{
$r = $session->logout($ktsessionid);
exit(0);
}
else
{
print "The upload did not work\n";
exit(1);
}

sub ktUpload
{
my $ua = LWP::UserAgent->new;
my $browser = HTTP::Request->new();
my $response = $ua->request(POST $fullUrl . 'upload.php',
Content_Type => 'form-data',
Content =>[
session_id => $ktsessionid,
action => "A",
output => "xml",
file => [$file]
]
);
my $uploadres = XMLin($response->content);
#print Dumper($uploadres->{upload_status}->{file});
return $uploadres->{upload_status}->{file};
}

Knowledgetree Document Management System on a WHS

I setup Knowledgetree on my WHS because I didn’t like other options and it was free. I didnt want to use the canned installation because I didn’t want Apache and openoffice running in the background taking up my ram.

KT = Knowledgetree
WHS = Windows Home Server

  1. Setup a shared directory for kt with duplication, in my example I am going to use DMS you can use DMS$ if you want it hidden from browsing
    1. Add the users that are going to use KT
  2. Install the WHS PHP Extension
    1. http://www.mediasmartserver.net/downloads/add-ins/WHSPHP_1.0.4.zip
  3. Install WHS MySql Extension
    1. http://www.mediasmartserver.net/downloads/add-ins/MySqlInstallerForWHS_0.0.8.zip
    2. Change your mysql root password at http://localhost/pma
  4. Enable curl in php.ini
    1. Edit c:\php5\php.ini and add extension=php_curl.dll under the other extensions
  5. Install SUN Java 1.6
    1. http://www.java.com/en/download/manual.jsp
  6. Download the KT Source Code its about 60mb, the Windows version.
    1. http://www.knowledgetree.com/products/opensource/downloadopensource
  7. Extract KT to d:\dms
    1. Add full rights for the “Windows Home Server Users” group to d:\dms
  8. Create a virtual directory under the default website in IIS called DMS and using d:\dms as the document root
    1. Disable anonymous authentication and enabled basic authentication
  9. Run the KT setup at http://localhost/dms
  10. Setup the httpsso for single sign-on to your whs users.
    1. http://forge.knowledgetree.com/gf/project/httpsso/
    2. you must first manually make the matching user in KT first.
  11.  Scheduled Tasks 
    1.  ktscheduler – runs internal tasks
      1. Run: c:\php5\php.exe d:\dms\bin\scheduler.php
      2. Start in: d:\dms\bin
      3. Run As: NT AUTHORITY\SYSTEM
      4. Run every 15 minutes for 24 hours
    2. ktlucene
      1. Run: “C:\Program Files\Java\jre6\bin\java.exe” -jar D:\DMS\bin\luceneserver\ktlucene.jar
      2. Start in: D:\DMS\bin\luceneserver
      3. Run As: NT AUTHORITY\SYSTEM 
      4. Run at system startup
      5. Uncheck the stop the task if it runs for 72 hours
    3. ktDbBackup
      1. Run: C:\php5\php.exe d:\dms\ktdbbackup.php
      2. Start In: d:\dms
      3. Run As: Administrator (needs network access for backups)
      4. Run every 12 hours for 24 hours

    
    #stephen
    #www.stephenjc.com
    #kt backup for whs
    #dump sql backup of kt to document root
    #dump a quick csv to help convert files back to their original names
    
    #ktconfig
    $ktconfig = parse_ini_file("config/config.ini");
    
    $mysqlLink = mysql_connect($ktconfig["dbHost"],$ktconfig["dbUser"],$ktconfig["dbPass"]);
    if (!$mysqlLink) {
        echo "Unable to connect to DB: " . mysql_error();
        exit;
    } 
    if (!mysql_select_db($ktconfig["dbName"])) {
        echo "Unable to select mydbname: " . mysql_error();
        exit;
    }
    
    #get document location from db
    
    $sql = 'SELECT * FROM `config_settings` WHERE item = \'documentRoot\'';
    $result = mysql_query($sql);
    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting";
        exit;
    }
    $row = mysql_fetch_assoc($result);
    $docHome = $row["value"];
    
    #dump database to document root
    system('mysqldump --user ' . $ktconfig["dbAdminUser"] . ' --password=' . $ktconfig["dbAdminPass"] . ' ' . $ktconfig["dbName"] . ' >' . $docHome . '\ktdbbackup.sql');

    #create csv to restore original documents just in case
    $sql = 'select * from documents, document_content_version, users where documents.status_id = 1 and document_content_version.document_id = documents.id and documents.creator_id = users.id';
    $result = mysql_query($sql);
    if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
    }
    if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
    }

    $mycsvBackup = $docHome . "\ktbackup.csv";
    $fh = fopen($mycsvBackup, 'w');
    fwrite($fh,"Original_Name,KT_StoragePath,Owner,md5hash\n");
    while ($row = mysql_fetch_assoc($result)) {
    fwrite($fh,$row["filename"] . "," . $row["storage_path"] . "," . $row["username"] . "," . $row["md5hash"] . " \n");
    }
    fclose($fh);
    ?>

    Create exchange accounts from Perl

    I have not been able to create MS Exchange 2007 accounts from perl, the only method i have found that works is to call the PowerShell command to create the account. Below is an example.

    system qq[PowerShell.exe -PSConsoleFile "C:\\Program Files\\Microsoft\\Exchange Server\\Bin\\ExShell.psc1" -Command ". {Enable-Mailbox -Identity fitsuny\\] . $adUser->samaccountname . qq[ -Alias ] . $adUser->samaccountname . qq[ -Database $database] . $value. qq[}"];
    

    Windows Log file compression in perl

    This script will search the location for all .log files and compress them using NTFS.

    #!perl
    #Search osbLocations for *.log files and ntfs compress them.
    
    use File::Find;
    use Win32::OLE;
    
    @osbLocations = (
      'E:/obs-win-mthosting2',
      'E:/obsr-win-mthosting3',
      );
    
    $strComputer = '.';
    $objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
    
    
    foreach (@osbLocations) 
    {
     find(\&processFile, $_);
    } 
    
    
    sub processFile()
    {
     if ( -f and /.log$/ )
     {
      $objFile = $objWMI->Get('Cim_Datafile=\'' . $File::Find::name . '\'');
      if ($objFile->Compressed != 1)
      {
       print $objFile->Name, "\n";
       $intRC = $objFile->Compress;
       # To uncompress change this to objFile.Uncompress
       if ($intRC != 0) {
           print 'There was an error compressing the file: ' . $intRC, "\n";
       }
       else {
           print "File compression successful\n";
       }
      }
     }
    }