## NetScaler Backup by using Powershell

For quite some time it is possible to interact with a NetScaler by using the NITRO API. Since i got some a spare time i took a closer look at this and thought this could be cool way to backup my NetScaler config regularly. On a side note: I do not like running bash scripts started by crontab on my Appliance 😉 As a result of this I created a little Powershell script which does the following: At first the script connects to the Appliance and creates a session for the following tasks. The script saves the current NetScaler configuration and creates a new full system backup. After that we have to use a third party tool to copy the file from the NetScaler to a desired location in the network.  Sadly it is currently not possible to transfer files from or to the NetScaler by using the NITRO API except following file formats: .txt, .cert, .req, .xml, .key.

In the end the script deletes the created system backup file (the NetScaler can only store up to 50 backups at the same time) disconnects the session and sends a mail.

If want to use SSL but haven´t had time yet to configure your certificates right you can disable the SSL check.

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} Citrix also published a nice blog about configuring the NetScaler by using Powershell which can be found here. You can find the NITRO API documentation in the Citrix eDocs ###################################################################################################### # Purpose: # Automatically create and save a NetScaler Backup # Scriptname: # ns-backup.ps1 #$ScriptVersion =        "0.1"
#		Prerequisites:
#				- Powershell 3.0
#		Author:
#				Jens Trendelkamp, Jens.Trendelkamp@sepago.de, sepago GmbH
#		Change history:
#				06.01.2015, Jens Trendelkamp, Jens.Trendelkamp@sepago.de
#					- Initial version
#######################################################################################################
# $nsip = NetScaler NS IP Address #$nsprotocol = HTTP or HTTPS
# $nsuser = User #$nspass = Password
# $filename = How the backup file will be named #$level = full or basic | http://support.citrix.com/proddocs/topic/ns-system-10-5-map/ns-system-backup1-tsk.html
# $pathtopscp = Where to find pscp.exe #$savelocation = Where to save the backup
# $psemailserver = SMTP Address in case a mail should be send. If not leave this field empty #$mailto = Mail Recipient
#######################################################################################################
$nsip = "10.0.0.0"$nsprotocol = "https://"
$nsuser = "nsroot"$nspass = "nsroot"
$filename = "ns-backup-$(get-date -uformat "%d-%m-%Y-%H-%M")"
$level = "full"$pathtopscp = "C:\temp"
$savelocation = "\\10.0.0.2\Backups\NetScaler"$psemailserver = "10.0.0.3"
$mailto = "jens@trendelkamp.net"$payload = @{"login" = @{"username"=$nsuser;"password"=$nspass;"timeout"=60}}
$payloadjson = ConvertTo-Json$payload
Invoke-RestMethod -Uri "$nsprotocol$nsip/nitro/v1/config/login" -Body $payloadjson -Method POST -SessionVariable saveSession -ContentType application/json | out-null$nssession = New-Object -TypeName PSObject
$nssession | Add-Member -NotePropertyName WebSession -NotePropertyValue$saveSession -TypeName Microsoft.PowerShell.Commands.WebRequestSession
$payload = @{"nsconfig"=@{}}$payloadjson = ConvertTo-Json $payload Invoke-RestMethod -Uri "$nsprotocol$nsip/nitro/v1/config/nsconfig?action=save" -Body$payloadjson -Method POST -ContentType application/json -WebSession $nssession.WebSession | out-null$payload = @{"systembackup"=@{"level"="$level";"filename"="$filename"}}
$payloadjson = ConvertTo-Json$payload
Invoke-RestMethod -Uri "$nsprotocol$nsip/nitro/v1/config/systembackup?action=create" -Body $payloadjson -Method POST -ContentType application/json -WebSession$nssession.WebSession | out-null
& $pathtopscp\pscp.exe -pw$NSPASS $nsuser@"$nsip":/var/ns_sys_backup/$filename.tgz$savelocation | out-null
$payload = @{"systembackup"=@{"filename"="$filename.tgz"}}
$payloadjson = ConvertTo-Json$payload
Invoke-RestMethod -Uri "$nsprotocol$nsip/nitro/v1/config/systembackup?action=rm" -Body $payloadjson -Method POST -ContentType application/json -WebSession$nssession.WebSession | out-null
$payload = @{"logout"=@{}}$payloadjson = ConvertTo-Json $payload Invoke-RestMethod -Uri "$nsprotocol$nsip/nitro/v1/config/logout" -Body$payloadjson -Method POST -ContentType application/json -WebSession $nssession.WebSession | out-null$pathnfile = $savelocation + "\" +$filename + ".tgz"
if ($psemailserver) { if (test-path$pathnfile){
Send-MailMessage -to "$mailto" -from "NetScaler Backup <nsbackup@trendelkamp.net>" -Subject "NetScaler Backup successfull" -body "The scheduled NetScaler Backup has successfully finished and can be found here :$pathnfile"}
else {
Send-MailMessage -to "$mailto" -from "NetScaler Backup <nsbackup@trendelkamp.net>" -Subject "NetScaler Backup failed" -body "The NetScaler Backup has failed!"}}   ## Multiple WorxMail Instances ## Multiple WorxMail Instances There are several circumstances where you want to offer Multiple WorxMail Instances with preconfigured Application Settings. For example a WorxMail Version for your Microsoft Exchange Users and another Version for your Lotus Notes Users. If you just import a second Version of WorxMail in your AppController and only changing the Application Name you will experience some problems. With this hack you will be able to offer your Users preconfigured Multiple WorxMail Instances. But it is still not possible to use both Versions of this App on the same Device at the same Time. In this Case you will still get the usual behavior. This will work ofcourse with other WorksApps too, i.e. WorxWeb. We will start with downloading the latest Version of WorxMail from Citrix. You have to wrap this .ipa as you are used to by using the Citrix MDX Toolkit. After you have your .mdx file you need to extract the policy_metadata.xml file from the .mdx. You need to do this because after we modified the .ipa the Citrix MDX Toolkit will not recognize the .ipa as WorxMail anymore. Now to the fun part 🙂 Open the WorxMail.ipa file with WinZip or similar Tools and extract the PayLoad Folder somewhere where you will find it. Open the Folder and Right Click WorxMail.app. Open the app by selecting Show Package Content. Here you need to find the Info.plist File and copy it to Location where you can edit it i.e. the Desktop. Open the File with your Favorite Editor and search for CFBundleIdentifier. Below this entry you will see <string>com.citrix.mail</string>. If you are editing WorxWeb this string will be named “com.citrix.browser This Value needs to changed! If you want to deploy a second WorxMail Version for Example for Lotus Notes change the Value to com.citrix.maillotus. Save the Info.plist and copy the file back to the WorxMail.app File by using Drag&Drop. After that you can zip the Payload Folder again into WorxMail.ipa or just replace the Folder within the existing .ipa. Please be aware of the following fact; If you want to use the Update Function within the AppController when new Versions of WorxMail are available you need to edit the Info.plist again and replace the String with the same Value! If not it is not possible to update the App. Now it is time to wrap your modified .ipa file as usual. Before you can Upload the .mdx file to your AppController you need to replace the policy_metadata.xml within the .mdx from the beginning. After that you can upload the .mdx to your AppController give the Application a Name and start testing. ## Securing the Exchange Control Panel ## Securing the Exchange Control Panel using Netscaler Application Firewall For this Blogpost I assume that you are already Load Balancing your Exchange Servers by using the NetScaler. If not you can find here a great Deployment Guide by Citrix. In my Lab Environment I also use Content Switching. So eventually you have to adjust the Virtual Server where you will bind your Application Firewall Policy to. Let´s start! Navigate to Security -> Application Firewall -> Profiles Here we will create a new Application Firewall Profile. Enter a Profile Name as you like and click “Create”. Double Click that new created Profile and switch to the Security Checks Tab. Again Double Click Deny URL. Add a new Deny URL and enter the following Syntax: “^[^?]*/ecp” without quotes and mark the “Enabled” Check Box. In the General Tab enable at least the Block Check Box. Press OK. Within the “Configure Web Application Firewall Profile” Window switch to the Settings Tab. You can specify here what will happen if /ecp will be accessed. In my setup i decided to redirect the Person to my Blog. Obviously you can create a HTML Website and upload it to the NetScaler. After we successfully created a Profile we have to create a Policy and bind the Profile to Policy. To do this we switch to the Menu Security -> Application Firewall -> Policies -> Firewall. Here we click “Add”. Choose an appropriate name for the Policy. After that select the created Profile from the Dropdown Menu and as an expression simply enter “true”. Press OK. Exchange Control Panel To finish the setup we have to bind the Profile to an vServer, Content Switch vServer or Globally. In my Lab I decided to apply this Policy to the Content Switch vServer. We do this by starting the Application Firewall Policy Manager. You will find this Tool under Security -> Application Firewall -> Application Firewall Policy Manager. Switch to the Tab “CS Virtual Server”. Double Click your Content Switch vServer and insert your Policy. Click Apply Change and you are done. You can now start to test your newly created Application Firewall and try to access the Exchange Control Panel. ## Automated Application Wrapping ## Automated Application Wrapping If you are deploying and/or managing Citrix XenMobile Environments one small part of work you have to deal with is the Application Wrapping. If you do have to do this often because of new Application Versions or you have to wrap the Applications for multiple Customers you will be quite quickly annoyed by the Citrix MDX Toolkit GUI. Because of that (and because the GUI does not work on virtualized Macs running on Windows. Why does the GUI need OpenGL?! WindowServer: _CGXGLDisplayContextForDisplayDevice: No matching context for device – disabling OpenGL) i started to use to MDX Toolkit CLI. Since May the MDX Toolkit is very well documented! XenMobile MDX Toolkit Documentation But let´s get to the point. I created two little bash scripts for Automated Application Wrapping. One for iOS and one for Android. #### Android Version: ###################################################################################################### # Purpose: # Automatically wrap Android Applications for XenMobile # # Scriptname: # Android-wrapping.sh # #$ScriptVersion = “0.000.0002
#
#
# Prerequisites:
# – Citrix MDXToolkit
# – Java JDK 1.6 or 1.7
# – Android SDK 19.0.0 or later
# – Valid User Generated Keystore
#
# Author(s):
# Jens Trendelkamp, Jens.Trendelkamp@sepago.de, sepago GmbH
#
# Change history:
# 21.05.2014, Jens Trendelkamp, Jens.Trendelkamp@sepago.de
# – Initial version
# 24.08.2014, Jens Trendelkamp, Jens.Trendelkamp@sepago.de
# – Updated CLI Commands to work with the latest MDX Toolkit
#
#######################################################################################################
#
# KEYSTORE = Keystore Path
# ALIAS = Key Alias
# KEYPASS = Private Key Password
# APKDIR = Path to the unwrapped Android Applications
#######################################################################################################
#!/bin/sh
KEYSTORE=~/Keystore_path/appwrapping.keystore
ALIAS=appwrapping
APKDIR=/User/Jens/APKs

APKS=ls -r $APKDIR/*.apk rm -rf$APKDIR/wrapped && mkdir -p $APKDIR/wrapped for i in$APKS ; do
bname=basename -s .apk $i java -jar -Xmx1024M /Applications/Citrix/MDXToolkit/ManagedAppUtility.jar wrap \ -in$i \
-keystore $KEYSTORE \ -keyalias$ALIAS \
-keypass $KEYPASS \ -storepass$STOREPASS \
-out $APKDIR/wrapped/$bname.mdx
done

#### iOS Version:

######################################################################################################
# Purpose:
# Automatically wrap iOS Applications for XenMobile
#
# Scriptname:
# iOS-wrapping.sh
#
# $ScriptVersion = “0.000.0002” # # Comments: # # Prerequisites: # – Citrix MDXToolkit # – Xcode 5.0+ # – Xcode Command Line Tools # – Valid Certificate and Provisioning Profile # # Author(s): # Jens Trendelkamp, Jens.Trendelkamp@sepago.de, sepago GmbH # # Change history: # 21.05.2014, Jens Trendelkamp, Jens.Trendelkamp@sepago.de # – Initial version # 24.08.2014, Jens Trendelkamp, Jens.Trendelkamp@sepago.de # – Updated CLI Commands to work with the latest MDX Toolkit # ####################################################################################################### # # CERT = Name of the signing certificate # PROFILE = Path to the Provisioning Profile # IPADIR = Path to the unwrapped iOS Applications # ####################################################################################################### #!/bin/sh CERT=”iPhone Distribution: some company” PROFILE=/Users/Jens/provisioning_profile.mobileprovision IPADIR=/User/Jens/IPAs IPAS=ls -r$IPADIR/*.ipa
rm -rf $IPADIR/wrapped && mkdir -p$IPADIR/wrapped

for i in $IPAS ; do bname=basename -s .ipa$i
/Applications/Citrix/MDXToolkit/CGAppCLPrepTool Wrap \
-in $i \ -Cert “$CERT” \
-Profile $PROFILE \ -out$IPADIR/wrapped/$bname.mdx done If you modified the setting and start the script you will see something like this: Of Course these bash scripts are pretty simple but it´s a good way to start using the MDX Toolkit CLI 🙂 ## SSL Offloading / Content Switching with Citrix NetScaler and PRTG Network Monitor ## SSL Offloading / Content Switching with Citrix NetScaler and PRTG Network Monitor A quick one. I tried to publish the PRTG Webinterface through a NetScaler using SSL Offload and Content Switching. While testing my setup with a Webbrowser it all seemed to worked fine. But as I tried the iOS Application from Paessler I run into the following problem. PRTG iOS APP Since there are two Knowledge Base articles from Paessler available how to use an IIS or Apache as a Reverse Proxy (Link 1 Link 2) and I could access the Webinterface with my Browser I was pretty sure I made a mistake somewhere. So I connected my iPad to XCode and checked the Console Logfile while setting up My Account. XCode Error Log Content Switching Policy The App is trying to access prtg.trendelkamp.net:443. This got me thinking. I checked my NetScaler Content Switching policy. The policy says that the hostname needs to be the same as I configured, prtg.trendelkamp.net. And since the PRTG App adds the port at the end of the hostname there is no matching policy anymore. As soon as I changed the expression to HTTP.REQ.HOSTNAME.CONTAINS(“prtg.trendelkamp.net”) the App worked fine 🙂 ## How to change/modify Android WorxApp Icons ## How to change/modify Android WorxApp Icons Last week I explained how to modify WorxApp Icons on iOS Devices. This time I want to show you how to do this for the Android Apps since the necessary steps are slightly different. For Android we need to decompile the .apk files before we can edit them. To accomplish this we need the apktool. You can download the tool here. After you finished installing the apktool we can directly start with decompiling the .apk file. In this example I moved the .apk to the same folder as the apktool and run the following command: ./apktool d applicationname.apk After the decompiling is finished you´ll find a new directory within your apktool folder. Android WorxApp In this folder you can edit the Icons as you wish. Since the .png for different resolutions are spread across several folders I searched for launcher which will show all relevant files. As you can see I spent a lot of time to customize the files 😉 Android WorxApp After you are done you have to rebuild the .apk file. This will also be done by the apktool. You can start this process with the following command: ./apktool b applicationfolder applicationname.apk Android WorxApp Now you can wrap the newly created .apk as you are used to with the MDX Toolkit. ## How to change/modify iOS WorxApp Icons ## How to change/modify iOS WorxApp Icons I was asked how to modify the WorxApp Icons to match the Cooperate Identity Policy. To accomplish this you will need a Mac with XCode installed, an Image Editor like Gimp and of course the .ipa file you want to modify. Let´s start with extracting the icons from the .ipa file. If you do this by simply extracting the images from the .ipa file you will get the following error in Gimp and similar Programs. iOS WorxApp This is absolutely normal since these Images have been optimized. To undo this we need to “uncrush” them. I found a nice script by Peter Boctor which “uncrushes” whole .ipa files. The script can be found here. Start the script with the .ipa file you want to edit. iOS WorxApp After the script successful ended you will find a new folder named like the .ipa file and an Images at the end. For a better overview I move the files i need to edit to a separate folder. Now you can now start to edit/replace the images as you wish. iOS WorxApp After we have finished editing or replacing the images we want to “crush” them again. Since I ‘am a lazy guy I created a little script which “crushes” a whole directory. #!/bin/sh for png in find$1 -name “*.png”;

do

echo “crushing $png” pngcrush -rem allb -brute “$png” temp.png

mv -f temp.png \$png

done;

I also added the path to pngcrush binary to my Environment Variable

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/

iOS WorxApp

You´ll start the script with the following command: ./crush.sh foldername

iOS WorxApp

iOS WorxApp

Your folder (in my example it´s called “png”) now contains “crushed” .png files which need to be moved to your original .ipa file. To do this I extracted the WorxMail Application folder from the .ipa/Payload folder. After that I opened the WorxMail Package by clicking “Show Package Contents”. Copy the modified Icons from your folder to the WorxMail Package and make sure you replace the files.

iOS WorxApp

iOS WorxApp

Of course you need to put the WorxMail Application back to the .ipa file. In my case I used WinZip and simply dragged the file to the correct place.

iOS WorxApp

Now it´s time to wrap the app as usual with the MDX Toolkit and upload it to your AppController. If all worked well you can now install/update the customized app which hopefully looks better than mine J

iOS WorxApp

## How to deploy WorxMail and WorxWeb for Windows Phone 8.1

While upgrading our sepago XenMobile Environment to support WorxMail and WorxWeb for Windows Phone 8.1 i thought to write a blog post about this since its not easy to find all needed informations.

– You will need a Microsoft Developer Account. Register here http://dev.windows.com/

– A Symantec Enterprise Mobile Code Signing Certificate is required. This can be orderd athttps://products.websecurity.symantec.com/orders/enrollment/microsoftCert.do You can find your Symantec-Publisher-ID within your Microsoft  Developer Account. Navigate to the Windows Phone Store Dashboard –> Account. Here should your Symantecd-ID be listed. After the ordering process is finished and you followed the instructions provided within the mails you will receive a *.pfx certificate.

– A Windows 8.1 64-bit computer is needed. Also .NET 4.5, Silverlight 5 Runtime, SDK and at least Visual Studio Express 2013 have to be installed.

– The following files from your MyCitrix Account have to be downloaded – MDX Toolkit for Windows Phone 8.1, WorxMail for Windows Phone 8.1 v9, WorxWeb for Windows Phone 8.1 v9 and Worx Home for Windows Phone 8.1 v9

– And of course a fully working XenMobile v9 Enterprise Environment.

If the prerequisites are complete we can finally start doing things

– At first we create a *.aetx file. This one is needed to configure the Windows Phone Enterprise Hub Policy within the Device Management. We need to open the Visual Studio Command Line as an Administrator. We navigate to C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.1\Tools\AETGenerator and excute the following command “AetGenerator.exe “c:\Path\to\your\Symantec\Certificate.pfx” passwordforyourcertificate”. You should now find tree new files in the AETGenerator Directory. We only need the AET.aetx file.

– To create the Windows Phone Enterprise Hub Policy we also need to wrap the WorxHome App. We will stay in our Visual Studio Command Line an navigate to the Directory where the MDX Toolkit for Windows Phone 8.1 is located. Here we create two new Directorys. One for our unsigned apps and one for signed apps. You should put the three downloaded Apps from Citrix to the unsigned folder. To wrap the WorxHome App we will execute the following command:

The phonePulisherId can be found within the Microsoft Developer Account: Login and navigate to Windows Phone Store Dashboard –> Account.

– Now we can create our Windows Phone Enterprise Hub Policy. Login with your Adminstrator Account to your MDM Server and create a new Windows Phone 8.x Enterprise Hub Policy. Enter a Name and if you want a Comment and upload the created AET.aetx und your wrapped WorxHome.xap file. Don´t forget to add the created Policy to a Deployment Package

– To use WorxMail and WorxWeb we also have to wrap them. But the command is this time a bit different since we have to add the MDX Policies. Within the Visual Studio CL we execute the following command for WorxMail

and for WorxWeb

Make sure you copy the *.mdx file to a save place after you created them. With each new wrapping process the Preptool will emtpy the signed folder. You can upload both Apps now to your AppController and configure the MDX Policies as u used to.

– Finally you can enroll your Windows Phone. Citrix published a very nice Blog Article how to do thishttp://blogs.citrix.com/2014/07/03/windows-phone-8-1-device-enrollment-process-xenmobile-9-0/. But other mentioned in the Citrix Blog Auto Discover is not needed for this. We are the living proof