Monday, December 12, 2011

Connecting OTRS into Active Directory.

I was testing out OTRS for work and got it to connect to and integrate with out Active Directory server.  All the Customers and Agents are pulled in from AD, bassed on group membership, along with their contact information.  This took quite a bit of trial and error but here is the config file I ended up with.  Note that this isn't the full file but rather goes into the load method where indicated.

How to retain a users default printer in Citrix when using Session Printers.

Update: 2/27/2011
Rewrote the scripts as they didnt work is some situations and caused some very strange errors.
Aslo to remove some potential errors with client session printers a network printer shuold now be set in the policies though this will get changed by the scripts.

I just covered how to push down Session Printers in Citrix based on Active Directory membership in my last post.  This method does however have one problem and that is that the users Default Printer preference will be discarded upon logout.  To get around that the with some scripts can be set up in the users login script to restore the previous default printer.  Also the free Defset utility will also need to be added as a published application for the users to use to change their default printer instead of the normal way.

You will need to download and save theDefSet utility onto each citrix server available form  In my case I just saved it to %windir%.

Once downloaded you will need to add a plublished application for the user to run this tool and set their default printer.  It should use the following command line to execute.
%windir%\defset.exe /PA

Also save the following  VBScript onto your Citrix servers where you put DefSet. The Adobe PDF printer is a default that will be used if no preference is set of if there is some error in the proccess though it can be changed here.

On Error Resume Next
Set WSHNetwork = CreateObject("WScript.Network")
Set ArgObj = WScript.Arguments
if ArgObj(0) = "Document" then
WSHNetwork.SetDefaultPrinter "Adobe PDF"
WSHNetwork.SetDefaultPrinter ArgObj(0)
End if
if Err.Number <> 0 then
WSHNetwork.SetDefaultPrinter "Adobe PDF"
End if

After that you will need to create a Group Policy that will apply to all the Citrix users.  In this policy you will need to add the following login scripts.

rem @echo off
echo Waiting for network printers to appear.
timeout 15
echo Setting user default printer.
FOR /F "eol=; tokens=3 delims=\" %%i in (%userprofile%\Windows\defset.ini) do (
cscript.exe %windir%\SetPrinterDefault.vbs "%%i"

 This will in essence work now but any client side printers published to the session will not save properly.  To fix this add the following Citrix Policy to the Group Policy we already created.
Policy: Client printer names
Value: Legacy printer names

We also need to set a default printer in the policy so that client side printers not cause errors durring startup.  Specificly what will happen is that if one of them gets assigned as a default durring the normal winodws logon proccess then the utilities will not work properly.  To get around this we will set a server side default printer and then the login script will change it.  This printer will need to be a session printer shared out to all the citrix users, though the default will just be changed so they won't really be printing to it.  We just use our support printer but you could jsut as easily use a fake printer. Add the following Citrix Policy to the Group Policy we already created.
Policy: Default Printer
Value: \\PrintServer\GlobalSharedPrinter

Please note that changing the default printer must be done with the DefSet tool and changing the printer in Windows will still be ignored on logoff.

Granting users Session Printers bassed on Active Directory Membership with Citrix.

I have been setting up the new Citrix environment where I work on one of the biggest problems we have run into is that of printing.  In the end I set the system up to use Citrix Group Policies to configure Session Printers at login time.  Furthermore I have it configured to discard the printers at log off.  The primary benefit to this approach is a one to one relationship between the printers a user has access to and the group membership in Active Directory.  There is one group for each printer in AD those groups are granted to user/department groups as needed. 

The Active Directory groups are named to match the printer names.
Printer - PNT001, Printer - PNT002-Color, Etc.

The Citrix Policies can be configured in the GPO or the Citrix Delivery Services Console as User Policies, one entry per printer. and look like so.
Name: Printer - PNT001
Setting: Session Printers   \\print01\PNT001
Filter:  Allow when user is in DOMIAN\Printer - PNT001 

When the user logs in the Citrix policy is applied.  It has one session printer line for each printer that is only applied if the user is a member of that printers security group.  As a result when adding or removing printers in AD any changes will be reflected when the users log in again.  This does not set or force down a default printer and any default set by the user will be lost on log out as the printers are discarded.  Please see the next post for dealing with allowing users to set and store their default printer preference.

Friday, September 16, 2011

Using a single Windows 7 install with Boot Camp and VMware Fusion

09/17/2011- Update: Updated the power on-vm-custom script to add /persistent:yes.  Without this extra parameter the drive mapping immediately disconnects when the login scripts finish which is not what we are looking for.

I recently put a SSD drive into my iMac running OSX Lion. When I did this I also decided to create a single Windows 7 install for use in Boot camp and VMware Fusion. Below is a brief overview of the process and the decisions I made along the way.

I started out by using the Boot Camp Assistant to create a 20 GB(Probably should have been closer to 30GB) partition on the SSD drive(120 GB) I installed. I will only be using this partition for the operating system and drivers and have a 700GB external Firewire drive for all other data.

I installed Windows 7 64bit on this volume and loaded it with the proper Windows 7 Boot camp drivers and all the Windows Updates.

Next I installed VMware Fusion 3 created a new Virtual Machine with the Boot Camp partition.  This is only a pointer to the partition and not a copy and as such the VM itself is only a few megabytes.  After this was done I booted up the VM and configured the VMware tools.

I now have a single operating system that can be used in the VM or as a native OS.  To simplify the switching between the two Operating Systems I also installed BootCamp.

Next I configured Windows to automatically log in when booting to speed the startup/reboot times.  To do this open Window, press Command-R, and enter control userpassword2. not uncheck the option to require users to login and enter the username and password you want to automatically log in with.

Setting up shared access to a NTFS partition from both Boot Camp and VMware Fusion.

Next up is tackling the problem of the second hard drive.  I could have just created one large partition and been done now but the SSD eliminates the option.  Also I can't directly attach the external firewire drive to Windows XP become there is another partition on is for use in OSX.  As a result I am limited to make a few modifications to make it usable.  First off I configured the drive with two large partitions with Disk Utility(The first is a HFS+ volume with my OSX home directory and documents).  Then I Booted into Boot Camp and formatted the second column as NTFS for use in windows.  This drive will now automatically connet when booting in Boot Camp as E:\.

This was only half the battle though as previously mentioned when booting in VMware this column isn't accessible.  The solution to this is to enable Sharing in the Virtual Machine settings.  Now click Add, select the proper volume, and make sure it is set to Read & Write.  Note that you definitely want to leave Mirrored folders off here or you will have problems when booting back to Boot Camp.  You can also add other folders to share here like tour home folder or other external volumes.

Now you may have noticed that this volume is Read Only.  This is a limitation of OSX but there is a NTFS-3G Driver that will enable write access to the drive.  When installing be sure to chose the Cache option as the performance is needed and on a power failure only the programs will be vulnerable, not the OS itself.  Once installed you don't need to reboot, just click the X at the last screen then un mount the column and user Disk Utility to re-mount it.  You can now write to the NTFS volume all be it as a slightly reduced speed.

Upon booting VMware we not get a Z:\ shared folder with this external drive listed within it.  This will not work though as the applications will not be installed in the same location in both modes.  To fix this we need to create a login and logout scrip in VMware.  Open up C:\Program Files\VMware\VMware Tools  and make copies of the poweron-vm-default and poweroff-vm-default scripts.  Now open up My Computer, Z:\, and the shared external volume.  Copy the full path from the address bar at the top of the window.

Edit the poweron-vm-copy script and add the following line where DRIVE is the drive letter expected in windows and PATH is the path copied previously.
net use DRIVE: "PATH" /persistent:yes
Edit the poweroff-vm-copy script and add the following line where DRIVE is the same drive letter again.
net use DRIVE: /delete

For example here are mine:
net use e: "\\vmware-host\Shared Folders\Windows HD" /persistent:yes
net use e: /delete

Finally open up VMware tools and change the Shut Down Guest and Power On Guest scripts to point to the appropriate files we just created.  Now reboot and enjoy seamless reboots and convenience.

Other notes:
  • With this setup and the SSD I can switch back and forth between anteing and emulated environments in less them a minute.  
  • I also have both operating systems configured to load the majority of their applications and data onto the external drive and hold only the OS and working files on the SSD.  The only real exceptions to this are in OSX where most applications are acutely on the SSD as in both OS's the user profiles are still on the SSD.  I all detail my OSX setup in a future post.
  • You will notice that you can't use BootChamp to reboot when the VM is running.  You need to shut down Windows first before you can reboot to Boot Camp.  VMware does not acutely need to be exited and I tend to leave the application running and the VM set to auto start so that earn I boot back to OSX the VM automatically starts back up.

Thursday, July 28, 2011

Remotly Enable VNC/Remote Management on OSX by SSH

I had the VNC based remote access feature of OS X enabled on 10.7 but somehow it got switched off.  I fiddled around a bit and figured out how to enable remote access from a remote SSH shell.  Note that these instructions will lead to manual configuration and you will not be able to enable/disabled the services from the System Preferences anymore.  In my case I used this to get in when I needed to but latter switched it back off and used the System Preferences setting.

To manual switch on remote access from the terminal:
ssh username@mac_ip_address
cd /System/Library/CoreServices/RemoteManagement/

sudo ./kickstart -activate -configure -access -on -privs -all -restart -agent

To switch this override back off and thus allow the System Preferences to manage screen sharing again run the following. (This will disconnect any active sessions and require physical access to re-enable it.)
sudo ./kickstart -activate -restart -agent 

Monday, May 9, 2011

OSX Slow Boot / Can't Change Boot Volume

I recently had a very odd problem with my iMac. I have a after market SSD in it and have Boot Camp set up with Windows 7. It has been working fine for about a year now but all of the sudden my boot time tripped and I was no longer able to switch OS's with BootChamp nor set a startup volume in System Preferences.

After some investigation I found the following symptoms and error messages:
  • There were some scree rendering issues / I could mouse the mouse but not click or type.
  • I was able to use Remote Desktop / VNC to connect and interact with the computer properly.
  • In Activity Monitor the kernel_task process was using 100% of the CPU on one of the cores.
  • I could boot to Windows at startup and had no problems, errors, or lag there.
Could not find IODeviceTree:/options
EFI found at IODeviceTree:/efi Mount point for /Volumes/BOOTCAMP is /Volumes/BOOTCAMP
flushing fs disk buffer returned 0x5
IOHIDSystem: postEvent LLEventQueue overflow.
Can't access "efi-boot-device" NVRAM variable
no bootx creation request
nvram: nvram is not supported on this system

One of the messages when I was testing the Unix bless command indicated that the "efi-boot-device" NVRAM variable was not accessible. I then tried to examine it with the Unix nvram command only to get the "nvram: nvram is not supported on this system" error. I found the NVRAM error very odd And was surprised the computer was even booting if the nvram was defective. I then tried to reset the NVRAM as it was not operating properly.

As it turned out the problem all along was that the NVRAM had corrupted and was non-functional. I did a hard reset of the NVRAM and all the problems went away immediately. To reset the NVRAM you just reboot and hold down Command, Option, P, and R as the computer boots, or see this Apple Document.

Friday, April 15, 2011

Reading .NET JSON Date's in jQuery

ASP.Net writes out date objects to a JSON stream in the format { "\/Date(x)\/" } but jQuery will not automatically convert this to a JavaScript date but rather keeps it as a string. To fix that this simple converter script can be included in your global JavaScript header.

Note that this does requite jQuery 1.5+.

    // Add a custom converter to convert ASP.NET JSON dates to JS Date object
    // That is convert { "\/Date(...)\/" } to { new Date(...) }
    converters: {
        "text json": function( textValue ) {
            return jQuery.parseJSON(textValue.replace(/"\\\/Date\((-?\d*)\)\\\/"/g, "new Date($1)"));

Wednesday, April 13, 2011

Adding Better Ajax/JSON methods to HighCharts

I recently started using Highcharts as the charting options in Crystal Reports are rather limited. Here is a small patch I made to simplify the loading of chart data from JSON server calls via AJAX. This does not do anything incredibly unique, just simplifies the code to do so by adding an ajaxSource property to the chart and series configurations that is loaded on init and a reloadAjax method to automatically reload the data.

05/03/2011 - Rewrote the code as a extension instead of a patch and added support for setting multiple series via options.chart.ajaxSource.