Strict Standards: Redefining already defined constructor for class wpdb in /var/www/myfoto.se/jbits.se/blog/wp-includes/wp-db.php on line 56

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/myfoto.se/jbits.se/blog/wp-includes/cache.php on line 36

Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /var/www/myfoto.se/jbits.se/blog/wp-includes/cache.php on line 384

Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 541

Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 541

Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 541

Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 541

Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 560

Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 659

Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 659

Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 659

Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 659

Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 684

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/myfoto.se/jbits.se/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/myfoto.se/jbits.se/blog/wp-content/plugins/code-highlighter/codehighlighter.php on line 42

Deprecated: preg_replace() [function.preg-replace]: The /e modifier is deprecated, use preg_replace_callback instead in /var/www/myfoto.se/jbits.se/blog/wp-includes/formatting.php on line 82
jbits.se <br /> <b>Deprecated</b>: preg_replace() [<a href='http://php.net/manual/en/function.preg-replace'>function.preg-replace</a>]: The /e modifier is deprecated, use preg_replace_callback instead in <b>/var/www/myfoto.se/jbits.se/blog/wp-includes/formatting.php</b> on line <b>82</b><br /> » OS

jbits.se

Jörgen Björkmans blog

Archive for the ‘
Deprecated: preg_replace() [function.preg-replace]: The /e modifier is deprecated, use preg_replace_callback instead in /var/www/myfoto.se/jbits.se/blog/wp-includes/formatting.php on line 82
OS’ Category

Apr
19

Microsoft iSCSI Software Target 3.3 released for download

Posted by jbjorkman on April 19, 2011 under Windows

Download from the following link, note that it's only supported on W2k8R2
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=45105d7f-8c6c-4666-a305-c8189062a0d0

Feb
24

Prevent W2k8+ from registering all adapter IPs in DNS

Posted by jbjorkman on February 24, 2011 under Network, Windows

Normal behaviour for Windows 2008 onwards is to register all IPs for a certain adapter in DNS if dynamic dns registration is enabled.
To prevent this behaviour you need to install below mentioned hotfix and add the addresses using the following netsh syntax:

Netsh int ipv4 add address skipassource=true
http://support.microsoft.com/kb/975808/EN-US

Feb
23

Disable IIS Socketpooling

Posted by jbjorkman on February 23, 2011 under Uncategorized, Windows

By default, IIS will bind a certain port to all IPs sharing NIC.
To disable this behaviour you need to disable socket pooling.
You do this providing a list of ip:port pairs to listen to, with socket pooling enabled the list is usually empty

For IIS6 you can use httpcfg.exe from support tools.
httpcfg.exe set iplisten -i 0.0.0.0:80
httpcfg.exe set iplisten -i 10.0.0.1:443

For IIS7 you use netsh
netsh http add iplisten ipaddress=0.0.0.0:80
netsh http add iplisten ipaddress=10.0.0.1:443

http://support.microsoft.com/kb/238131

Feb
10

PowerShell WMI Eventsink example

Posted by jbjorkman on February 10, 2011 under Powershell, Windows

To clear all currently registered eventhandlers:
Get-EventSubscriber | % {Unregister-Event $_.SubscriptionID}

Capture Service Status changes (Example uses Wireless Zero Configuration):
Register-WmiEvent -Query "select * from __InstanceModificationEvent within 2 where targetinstance isa 'win32_service' and targetinstance.name= 'WZCSVC'" -sourceIdentifier "WZCSVC Status" -action { $evt=$event.SourceEventArgs.newEvent.TargetInstance ; Write-Host $evt.DisplayName $evt.State on $evt.Systemname}

Jan
26

Eventlog XML XPath filtering example

Posted by jbjorkman on January 26, 2011 under Windows

<QueryList>
  <Query Id="0" Path="Security">
    <Select Path="Security">
 *[EventData[(Data[@Name="TargetUserName"])="uname"]]
 </Select>
  </Query>
</QueryList>

Nov
03

Convert certificates using openssl

Posted by jbjorkman on November 3, 2010 under Windows

Download and install OpenSSL for windows from here (Light version is sufficient)
http://www.slproweb.com/products/Win32OpenSSL.html

Convert PFX to PEM 
openssl pkcs12 -in privcert.pfx -out privcert.pem -nodes

Convert CER to PEM 
openssl x509 -inform DER -in pubcert.cer -out pubcert.pem

Oct
30

Microsoft posters

Posted by jbjorkman on October 30, 2010 under OS, Windows

Windows 2008 RDS
http://download.microsoft.com/download/7/9/5/795935E3-C3BE-4F63-A621-513858951911/Remote-Desktop-Services-Component-Architecture.pdf

Windows 2008 Hyper-V
http://download.microsoft.com/download/C/A/9/CA9292AD-3A33-4984-A9CF-82B08FCEFE77/WindowsServer2008R2Hyper-VComponentArchitecture.pdf

Windows 2008R2
http://download.microsoft.com/download/8/2/3/823871D1-819F-446D-ADD5-3049B78F020F/Windows_Server_2008_R2_Feature_Components.pdf

Windows 2008 Active Directory
http://download.microsoft.com/download/2/e/8/2e88c004-3b10-446f-9d5a-58af27deafc4/Windows%20Server%202008%20Active%20Directory%20Components.pdf

Windows 2008 features
http://download.microsoft.com/download/2/e/8/2e88c004-3b10-446f-9d5a-58af27deafc4/Windows%20Server%202008%20Feature%20Components.pdf

Exchange 2010
http://download.microsoft.com/download/1/D/5/1D5ED82D-7E65-4C5A-A605-A9ABCDE56DFC/Exchange%202010%20Poster.pdf

Exchange 2007
http://download.microsoft.com/download/b/2/0/b20ed7c4-4c29-4e8c-8bce-02f3a7bc0071/ExchangePoster.pdf

Add the following text to OS Boot Parameters under your VMs Startup options: rw init=/bin/bash
Boot your Access Gateway VPX VM, you'll be presented with a bash prompt.
Run the following to change specified text in the default (english) logonpage:

sed -i 's/User name:/Anv\&auml;ndarnamn:/g' /runtime/S0/etc/en/login.html
sed -i 's/Password:/L\&ouml;senord:/g' /runtime/S0/etc/en/login.html
sed -i 's/Welcome/V\&auml;lkommen/g' /runtime/S0/etc/en/login.html
sed -i 's/Log On/Logga in/g' /runtime/S0/etc/en/login.html

Remove the OS Boot Parameters and reboot your AG VPX.

Oct
07

Get Vendor and Device Info for Devices in Error State

Posted by jbjorkman on October 7, 2010 under Windows

List Device and vendorIDs for PCI devices in error state.
wmic path Win32_PNPEntity where (DeviceID like "PCI%" and Status like "Error") get Description, DeviceID

Lookup the troublesome devices Vendor and Device ID here: http://www.pcidatabase.com/

Oct
01

Override DisableCMD GPO oneliner.

Posted by jbjorkman on October 1, 2010 under Citrix, OS, Windows

Wmic /namespace:\\root\default class stdregprov call SetDWORDValue hDefKey="&H80000001" sSubKeyName="Software\Policies\Microsoft\Windows\System" sValueName="DisableCMD" uValue="&h0" & cmd

Sep
30

Find out domain functional level and Schema Version from command line

Posted by jbjorkman on September 30, 2010 under Windows

Show Active Directory Domain Functional level

dsquery * "DC=xxx, DC=xxx" -scope base -attr msDS-Behavior-Version ntMixedDomain
0, 0                      Windows 2000 Native domain Level
0, 1                      Windows 2000 Mixed domain Level
2, 0                      Windows 2003 Domain Level
3, 0                      Windows 2008 Domain Level
4, 0                      Windows 2008 R2 Domain Level 

Show Active Directory Schema Version

dsquery * "CN=Schema,CN=Configuration,DC=xxx, DC=xxx" -scope base -attr objectversion
13                        Windows 2000
30                        Windows 2003
31                        Windows 2003 R2
44                        Windows 2008
47                        Windows 2008 R2

Sep
10

Microsoft AppLocale

Posted by jbjorkman on September 10, 2010 under Windows

Microsoft AppLocale is a utility that allows Unicode (UTF-16) based Windows XP and 2003 users to run non-Unicode legacy (code-page based) applications without changing the current system locale.
It can be installed on later operating systems by starting the msi from an elevated command prompt.

http://www.microsoft.com/downloads/en/details.aspx?FamilyId=8C4E8E0D-45D1-4D9B-B7C0-8430C1AC89AB&displaylang=en

May
21

Netsh Technical Reference

Posted by jbjorkman on May 21, 2010 under Network, Windows

http://download.microsoft.com/download/D/4/8/D485CEF3-25D3-4F70-8504-9F13E225F539/Netsh_TechnicalReference.zip

Mar
27

Posted by jbjorkman on March 27, 2010 under Windows

Show available wireless networks using netsh (Provides more info than GUI):

netsh wlan show networks mode=bssid

Mar
19

Microsoft DNS Server - List cache entries

Posted by jbjorkman on March 19, 2010 under Windows

Use the following command to list MS DNS Server cache entries: 

dnscmd DNS_Server_IP /enumrecords /cache domainname

Use /detail for additional info

Mar
03

Create counter eventlog from commandline

Posted by jbjorkman on March 3, 2010 under Windows

Example of createing a counter eventlog from commandline using logman

md d:\Perflogs
cacls d:\perflogs /e /g "NT AUTHORITY\NETWORK SERVICE":C
logman create counter PerfLog2010 -o D:\Perflogs\ -rf 168:0:0 -si 0:0:15 -f bin -max 512 -v mmddhhmm
logman update PerfLog2010  -c "\Processor(_Total)\% Processor Time" "\Processor(_Total)\Interrupts/sec" "\System\Processor Queue Length" "\System\Context Switches/sec" "\Memory\Available MBytes" "\Memory\Pages Input/sec" "\PhysicalDisk(_Total)\Avg. Disk Queue Length" "\Process(_Total)\Working Set"

Feb
19

TcpDump - Output to file AND console

Posted by jbjorkman on February 19, 2010 under Linux, Network

tcpdump -s 0 -i eth0 -c 10 -w - -U | tee capture.pcap | tcpdump -n -r -
Full packets are written to capture.pcap, at the same time tcpdump -r decodes the stream to console.

-s 0 (Whole packets)
-w - (Write output to console)
-U (Do not buffer output)

Feb
16

Checkpoint SPLAT - Install & Configure HP Agents

Posted by jbjorkman on February 16, 2010 under Checkpoint, Linux, Network, OS


Preparations

Allow HP SMH (TCP2381) and SNMP to the modules from selected stations

Log in and create a temporary directory (e.g. /var/HPAgents)

Download the following packages from www.hp.com for your hardware / RHEL3

  • hpasm (System Health Application and Insight Management Agents)
    201002, latest version: hpasm-7.8.1-116.rhel3.i386.rpm
  • cmanic (HP NIC agent), and the optional
    201002, latest version: cmanic-7.7.0-5.rhel3.linux.rpm
  • hpsmh (System Management Homepage)
    201002, latest version: hpsmh-2.1.8-177.linux.i386.rpm

Download the splat_hpasm_support_files.tgz support files
http://www.opsec.com/solutions/partners/hpasm.html

 

Installing System Management Homepage (optional)

Login as expert on SPLAT and create the following file:
    echo "Red Hat Enterprise Linux ES release 3 (Taroon)" > /etc/redhat-release

Install the hpsmh package:
    rpm -ivh hpsmh-2.1.8-177.linux.i386.rpm

Install support files for HPASM

Extract the Splat hpasm supportfiles:
    tar xzvf splat_hpasm_support_files.tgz splat_hpasm

Copy the IPMI sysconfig file (If your system has an iLO2 Mgmt Controller)
    cp splat_hpasm/init_scripts/sysconfig_ipmi /etc/sysconfig/ipmi

Copy the IPMI init script for your kernel version (Check with uname –r)
    cp splat_hpasm/init_scripts/2.4_init_ipmi /etc/init.d/ipmi

Copy the libstdc++-3-libc6.2-2-2.10.0.so file to /usr/lib and set up a link
    cp splat_hpasm/libstdc++-3-libc6.2-2-2.10.0.so /usr/lib
    ln -s /usr/lib/libstdc++-3-libc6.2-2-2.10.0.so /usr/lib/libstdc++-libc6.2-2.so.3
    chmod 755 /usr/lib/libstdc++-3-libc6.2-2-2.10.0.so


Enable SNMP

Snmp service enable

Install HPASM

Remove any previous versions if present:
   
rpm -e hponcfg
    rpm -e cmanic
    rpm -e hprsm
    rpm -e hpasm

Install the HPASM package
    rpm -ivh hpasm-7.8.1-116.rhel3.i386.rpm

Install the NIC Agents
    rpm -ivh cmanic-7.7.0-5.rhel3.linux.rpm

Configuration

Backup your snmp config files
    cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf-pre-`/bin/date +%Y%m%d`
    cp /etc/snmp/snmpd.users.conf /etc/snmp/snmpd.users.conf-pre-`/bin/date +%Y%m%d`

For first time configuration run:
    hpasm activate

To reconfigure run:
    /etc/init.d/hpasm configure or /etc/init.d/hpasm reconfigure

Do you wish to continue? <y/n> (blank is y) y
Do you want to load the hp modules even though they may "taint" your kernel? <y/n> (Blank is y) n
Do you wish to use an existing snmpd.conf (y/n) (Blank is n):
n

Do you require SNMP agents (y/n) ? (Blank is y): y
Do you require Storage Agent support (y/n) ? (Blank is y):
y
Do you require performance agent support (y/n) ? (Blank is y): y

Enter the localhost SNMP Read/Write community string
(one word, required, no default):
********
Re-enter the same input to confirm:********

Enter localhost SNMP Read Only community string
(one word, Blank to skip):
********
Re-enter the same input to confirm:
********

Enter Read/Write Authorized Management Station IP or DNS name
(Blank to skip):
[Blank]

Enter Read Only Authorized Management Station IP or DNS name
(Blank to skip):
[Blank]

Enter default SNMP trap community string
(One word; Blank to skip):
[Blank]

Enter SNMP trap destination IP or DNS name
(One word; Blank to skip):
[Blank]

Enter system contact information
(Name, phone, room, etc; Blank to skip):
[Blank]

Enter system location information
Building, room, etc; Blank to skip):
[Blank]

Do you wish to disable hpsmh support (y/n) (Blank is n):n

Do you wish to keep CCISS device handle open (y/n): y

Restore snmpd.users.conf:
    mv /etc/snmp/snmpd.users.conf.bak /etc/snmp/snmpd.users.conf

Restart SNMP Daemon
    service snmpd restart

Feb
12

NTP Time Synchronizing on Windows machines.

Posted by jbjorkman on February 12, 2010 under Windows

Use the following command to setup ntp time sync on a windows machine:
w32tm /config /manualpeerlist:"ntp1.example.com,0x8 ntp2.example.com,0x8" /syncfromflags:MANUAL
Note the 0x8 flag after the ntp server name, this is needed to set 'ntp client mode'.

Restart the Windows Time service:
net stop w32time & net start w32time

Forced resync:
w32tm /resync /rediscover

Check status:
w32tm /monitor

Nov
18

Sysprep on W2k8

Posted by jbjorkman on November 18, 2009 under Windows

Located in %systemroot%\system32\sysprep

sysprep /generalize /oobe /shutdown /unattend:sysprep.xml

To use Registry Editor to disable the Allow the computer to turn off this device to save power network adapter setting for a single computer, follow these steps:

  1. Click Start, click Run, type regedit in the Open box, and then click OK.
  2. Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\DeviceNumberNoteDeviceNumber is the network adapter number. If a single network adapter is installed on the computer, the DeviceNumber is 0001.
  3. Click PnPCapabilities.
  4. On the Edit menu, click Modify.
  5. In the Value data box, type 38, and then click OK.Note By default, a value of 20 indicates that power management of the network adapter is enabled. A value of 38 will prevent Windows XP from turning off the network adapter or let the network adapter wake the computer from standby.
  6. On the File menu, click Exit.
Aug
19

postfix & bcc_maps

Posted by jbjorkman on August 19, 2009 under Linux

--- main.cf --------------------------
recipient_bcc_maps = hash:/etc/postfix/map_bcc
sender_bcc_maps = hash:/etc/postfix/map_bcc

# cat /etc/postfix/bcc_map
@capture.domain bccto@recipient.domain

--- Compile map_bcc

# postmap /etc/postfix/bcc_map

Aug
01

CertBackup.vbs

Posted by jbjorkman on August 1, 2009 under VBScript, Windows

'************ You have to have capicom.dll downloaded and registered...
' Download and install: http://www.microsoft.com/DownLoads/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6&displaylang=en
' run regsvr32 "C:\Program Files\Microsoft CAPICOM 2.1.0.2 SDK\Lib\X86\capicom.dll"

Option Explicit ' Explicit Declaration of Variables

' *** CAPICOM Constants
Const CAPICOM_CERTIFICATE_SAVE_AS_CER = 1
Const CAPICOM_CERTIFICATE_SAVE_AS_PFX = 0
Const CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN = 1
Const CAPICOM_MEMORY_STORE  = 0 ' The store is a memory store. Any changes in the contents of the store are not persisted.
Const CAPICOM_LOCAL_MACHINE_STORE  = 1 ' The store is a local machine store. Local machine stores can be read/write stores only if the user has read/write permissions. If the user has read/write permissions and if the store is opened read/write, then changes in the contents of the store are persisted.
Const CAPICOM_CURRENT_USER_STORE  = 2 ' The store is a current user store. A current user store may be a read/write store. If it is, changes in the contents of the store are persisted.
Const CAPICOM_ACTIVE_DIRECTORY_USER_STORE  = 3 ' The store is an Active Directory store. Active Directory stores can be opened only in read-only mode. Certificates cannot be added to or removed from Active Directory stores.
Const CAPICOM_SMART_CARD_USER_STORE  = 4 ' Stores support smart card–based certificate stores. The store is the group of present smart cards. Introduced in CAPICOM 2.0.
Const CAPICOM_MY_STORE = "My" ' This store is used for a user's personal certificates.
Const CAPICOM_CA_STORE = "CA" ' CA store. This store is used to store intermediate CA certificates.
Const CAPICOM_ROOT_STORE = "Root" ' Root store. This store is used to store the root CA and self-signed, trusted certificates.
Const CAPICOM_OTHER_STORE = "AddressBook" ' AddressBook store. This store is used to keep the certificates of others.
Const CAPICOM_STORE_OPEN_READ_ONLY = 0

' *** Script Constants
Const Title="CertBack (c) JBjorkman 2009"
Const Version="0.9"

' *** Script variable declarations
Public IE        ' Declare Public Variable for events
Dim oStore        ' CAPICOM Store object variable

Dim strPFXPasswd
Dim strPath
Dim oFolder

Dim StatusHTML

' *** Setup CAPICOM Store object
on error resume next
Set oStore = CreateObject ("CAPICOM.Store")
if Err.Number <> 0 Then
MsgBox "CAPICOM not detected" & vbCRLF & "You have to have capicom.dll downloaded and registered, see script header for details."
Wscript.Quit(1)
End if

' *** Show browse for folder dialog to select where to save Certificates

Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0,"Select where to dump certificates",0)

If oFolder Is Nothing Then ' User clicked Cancel
Wscript.Quit
End If

strPath=oFolder.Self.Path

GetPasswd "Enter password for pfx encryption",strPFXPasswd

' *** Setup IE Window
IEGUISetup
CreateObject("WScript.Shell").AppActivate IE.Document.Title

DumpCerts CAPICOM_CURRENT_USER_STORE, CAPICOM_MY_STORE
DumpCerts CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_MY_STORE
DumpCerts CAPICOM_CURRENT_USER_STORE, CAPICOM_CA_STORE
DumpCerts CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_CA_STORE
DumpCerts CAPICOM_CURRENT_USER_STORE, CAPICOM_ROOT_STORE
DumpCerts CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_ROOT_STORE

' *** Loop until false
CreateObject("WScript.Shell").popUp "Finished dumping certificates...",2

IE.Quit
Set oStore=Nothing
Set IE=Nothing
WScript.Quit

' ***** End of Main Program *****

' ***** Handle user closing IE Window
Sub IE_onQuit
Set oStore=Nothing
Set IE=Nothing
WScript.Quit
End Sub

' ***** Init IE GUI
Sub IEGUISetup()
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Navigate "about:blank"
WScript.Sleep 100
Do until IE.ReadyState = 4    ' Wait until Complete (READYSTATE_COMPLETE=4)
WScript.Sleep 100
Loop

IE.MenuBar=False
IE.ToolBar=False
IE.StatusBar=False
IE.Resizable=False
IE.AddressBar=False
IE.Width=975
IE.Height=IE.Document.ParentWindow.Screen.Height-50
IE.Left=(IE.Document.ParentWindow.Screen.Width-IE.Width)/2
IE.Top=10

IE.Document.Title = title

IE.Document.Open
IE.Document.Writeln "<html>"
IE.Document.Writeln "<head>"
IE.Document.Writeln "<title>" & title & "</title>"
IE.Document.Writeln "<meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"">"
IE.Document.Writeln "<style type=""text/css"">"
IE.Document.Writeln "<!--"
IE.Document.Writeln ".Title {"
IE.Document.Writeln "    color: #FFFFFF;"
IE.Document.Writeln "    font-family: Verdana, Arial, Helvetica, sans-serif;"
IE.Document.Writeln "    font-weight: bold;"
IE.Document.Writeln "}"
IE.Document.Writeln ".def {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; font-weight: bold; color: #f0f0c0; cursor: 'default';}"
IE.Document.Writeln ".status {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; font-weight: bold; color: #e0e0c0; cursor: 'default';}"
IE.Document.Writeln ".private {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; font-weight: bold; color: #e02020; cursor: 'default';}"
IE.Document.Writeln ".title {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #ffffff; cursor: 'default';}"
IE.Document.Writeln "-->"
IE.Document.Writeln "</style>"
IE.Document.Writeln "</head>"
IE.Document.Writeln "<body bgcolor=""#204020"">"
IE.Document.Writeln "<p align=""center""Title"">" & title & " v" & version & "</p>"
IE.Document.Writeln "<SPAN name=""MainTable"" id=""MainTable"">"
IE.Document.Writeln "<table name=""MainTable"" id=""MainTable"" width=""900"" border=""0"" cellpadding=""0"" cellspacing=""0"" bgcolor=""#e0e0c0"">"
IE.Document.Writeln "  <tr bgcolor=""#406040"" valign=""top"">"
IE.Document.Writeln "    <td width=""200""><div align=""left""><span name=""LOC"" id=""LOC""def"">Location</span></div></td>"
IE.Document.Writeln "    <td width=""600""><div align=""left""><span name=""CER"" id=""CER""def"">Certificate</span></div></td>"
IE.Document.Writeln "    <td width=""100""><div align=""left""><span name=""ACT"" id=""ACT""def"">Action</span></div></td>"
IE.Document.Writeln "  </tr>"
IE.Document.Writeln "</table>"
IE.Document.Writeln "</SPAN>"
IE.Document.Writeln "<SPAN name=""Status"" id=""Status""status"">"
IE.Document.Writeln "</SPAN>"
IE.Document.Writeln "</body>"
IE.Document.Writeln "</html>"
IE.Visible = True
End Sub

' *** Sub to dump certificates
Sub DumpCerts(store,storetype)
Dim oCert
Dim strCertName
Dim strfname
Dim strCompName
Dim strDate
Dim strType

StrCompName=WScript.CreateObject("WScript.Network").ComputerName  ' Get Computername
StrDate=Year(Now) & right("0" & Month(Now),2) & right("0" & Day(Now),2) ' Get date (YYYYMMDD)

oStore.Open store,storetype, CAPICOM_STORE_OPEN_READ_ONLY

Select case store
case 0 strType="Memory-" & storetype
case 1 strType="Machine-" & storetype
case 2 strType="User-" & storetype
case 3 strType="AD-" & storetype
case 4 strType="SmartCard-" & storetype
end select

For Each oCert in oStore.Certificates
on error resume next
strCErtName="Unknown"
strCertName=left(oCert.SubjectName,instr(oCert.SubjectName,",")-1)
strCertName=replace(strCertName,"CN=","")
strCertName=replace(strCertName,"OU=","")
strCertName=replace(strCertName,"*","x")
strCertName=replace(strCertName," ","-")
strCertName=replace(strCertName,"/","-")
strCertName=replace(strCertName,"\","-")
strCertName=replace(strCertName,"""","-")
strCertName=replace(strCertName,".","-")
on error goto 0

strfname=strCompName & "-" & strDate & "_" & strType & "_" & strCertName

if oCert.HasPrivateKey then ' These certificates we have a private key for, we'll save them as pfx
IE.Document.all.item("Status").innerHTML="<SPAN class='private'>Saving: " & strfname & ".pfx</SPAN><BR>" & IE.Document.all.item("Status").innerHTML
oCert.Save strPath & "\" & strfname & ".pfx", strPFXPasswd, CAPICOM_CERTIFICATE_SAVE_AS_PFX, CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN
else
IE.Document.all.item("Status").innerHTML="Saving: " & strfname & ".cer<BR>" & IE.Document.all.item("Status").innerHTML
oCert.Save strPath & "\" & strfname & ".cer",, CAPICOM_CERTIFICATE_SAVE_AS_CER
end if
Next
End Sub

Function GetPasswd( strPrompt, byref strPasswd)
Const CmplxRegExp="^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$" ' Complexity requirements regular expression
Dim oIEPwd
Dim oRegExp
Dim bFinished
Set oIEPwd = CreateObject( "InternetExplorer.Application" )
With oIEPwd
.Navigate "about:blank" : .Document.Title = strPrompt
.Toolbar = False : .Resizable = False : .StatusBar = False
.Width= 400 : .Height =150
.Left=(oIEPwd.Document.ParentWindow.Screen.Width-oIEPwd.width)\2
.Top=(oIEPwd.Document.ParentWindow.Screen.Height-oIEPwd.height)\2
End with
Do While oIEPwd.Busy
WScript.Sleep 100
Loop
oIEPwd.Document.Body.InnerHTML = "<DIV ALIGN=""center"">" & strPrompt & "<BR>" _
& "<INPUT TYPE=""password"" SIZE=""25"" ID=""Passwd""><BR>" _
& "<INPUT TYPE=""password"" SIZE=""25"" ID=""Passwd2""><BR>" _
& "<INPUT TYPE=""hidden"" ID=""OK"" NAME=""OK"" VALUE=""0"">" _
& "<INPUT TYPE=""submit"" VALUE="" OK "" OnClick=""VBScript:OK.Value=1""></DIV>"
oIEPwd.Visible = True

oIEPwd.document.all.Passwd.focus

On Error Resume Next

bFinished=False
Do
Do While oIEpWD.Document.All.OK.Value = 0
WScript.Sleep 100
If Err Then
GetPasswd=False : strPasswd="" : oIEPwd.Quit : Set oIEPwd = Nothing : Exit Function
End if
Loop
if oIEPwd.Document.All.Passwd.Value<>oIEPwd.Document.All.Passwd2.Value then
MsgBox "Passwords don't match, reenter please..." : oIEPwd.Document.All.Passwd.Value="" : oIEPwd.Document.All.Passwd2.Value="" : oIEpWD.Document.All.OK.Value=0 : oIEPwd.document.all.Passwd.focus
else
Set oRegExp = new RegExp
oRegExp.Pattern = CmplxRegExp
if oRegExp.Test(oIEPwd.Document.All.Passwd.Value) then ' Check our complexity requirements
GetPasswd = True
strPasswd=oIEPwd.Document.All.Passwd.Value
bFinished=True
else
MsgBox "Password does not meet complexity requirements, make sure it tests true against:" & vbCRLF & CmplxRegExp : oIEPwd.Document.All.Passwd.Value="" : oIEPwd.Document.All.Passwd2.Value="" : oIEpWD.Document.All.OK.Value=0 : oIEPwd.document.all.Passwd.focus

end if
end if
loop while bFinished=False

On Error Goto 0

oIEPwd.Quit
Set oIEPwd = Nothing
End Function

Apr
03

Cert Backup

Posted by jbjorkman on April 3, 2009 under VBScript, Windows

Option Explicit
'************ You have to have capicom.dll downloaded and registered...
on error resume next
Const SavePath="C:\System\ISA-Backups\Certs\"
Const CAPICOM_CERTIFICATE_SAVE_AS_PFX = 0
Const CAPICOM_CURRENT_USER_STORE  = 2
Const CAPICOM_EKU_CLIENT_AUTH = 2
Const CAPICOM_EKU_CODE_SIGNING = 3
Const CAPICOM_EKU_EMAIL_PROTECTION = 4
Const CAPICOM_EKU_SERVER_AUTH = 1
Const CAPICOM_EKU_OTHER = 0
Const CAPICOM_EXPORT_DEFAULT = 0
Const CAPICOM_CERTIFICATE_INCLUDE_CHAIN_EXCEPT_ROOT = 0
Const CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN = 1
Const CAPICOM_CERTIFICATE_INCLUDE_END_ENTITY_ONLY = 2
Const CAPICOM_LOCAL_MACHINE_STORE  = 1
Const CAPICOM_MY_STORE = "My"
Const CAPICOM_STORE_OPEN_EXISTING_ONLY = 128
Const CAPICOM_STORE_OPEN_READ_ONLY = 0
Const CAPICOM_STORE_SAVE_AS_PFX = 2
Const CR_DISP_ISSUED  = &H3
Const CR_OUT_CHAIN = &H100
Const CR_OUT_BASE64 = &H1
Const CERT_SYSTEM_STORE_LOCAL_MACHINE = &H20000
Const CR_IN_BASE64  = &H1
Const CR_IN_PKCS10  = &H100

Dim oCert, oStore
Dim strDate
Dim strCmp
Dim strCertName
Dim strfname
Dim strPasswd

Set oStore = CreateObject ("CAPICOM.Store")
if Err.Number <> 0 Then
wscript.echo "CAPICOM NOT detected"
Wscript.Quit(1)
End if

StrDate=Year(Now) & "-" & right("0" & Month(Now),2) & "-" & right("0" & Day(Now),2)
StrCmp=WScript.CreateObject("WScript.Network").ComputerName

oStore.Open CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_MY_STORE, CAPICOM_STORE_OPEN_READ_ONLY

strPasswd=Inputbox("Enter password to encrypt pfx with")

For Each oCert in oStore.Certificates
strCertName=left(oCert.SubjectName,instr(oCert.SubjectName,",")-1)
strCertName=replace(strCertName,"CN=","")
strCertName=replace(strCertName,"OU=","")
strCertName=replace(strCertName,"*","x")
strCertName=replace(strCertName," ","-")
strCertName=replace(strCertName,".","-")

strfname=strCmp & "-" & left(oCert.ValidtoDate,10) & "-" & strCertName

oCert.Save savePath & strfname & ".pfx", strPasswd, CAPICOM_CERTIFICATE_SAVE_AS_PFX, CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN
Next

Oct
14

Filter out comments from config files

Posted by jbjorkman on October 14, 2008 under Linux

sed -e 's/#.*//; /^$/d' filename.conf