Satchelmouth’s Weblog
Repository of solutions for things I encounter in my field of work

Sep
13

Taken from http://www.vi-tips.com/2009/05/p2v-error-with-nic-after-migration-with.html?showComment=1252671478216#c3075236391451425784

When doing a P2V and the server has to have a static IP address after the migration, then you may recieve an error message stating that there’s an IP conflict and the ip is already configured on an existing NIC – even though only one VMware NIC is visible in network connections.

The reason is that the physical NICs have not been entirely uninstalled in Windows, they still exist in the device manager as hidden devices. Do the following to uninstall the hidden NICs:

Open a command prompt and type the following commands:

set devmgr_show_nonpresent_devices=1
start DEVMGMT.MSC

Click ‘View’ and then click ‘Show Hidden Devices’.
Expand the Network Adapters tree and right click the dimmed network adapter and click ‘Uninstall’ (You may also see a hidden RSA device under NICs. This cannot be uninstalled. However, it doesn’t matter as it doesn’t influence the NIC issue, so just leave it).

Now you can configure the static IP with no errors.

May
28

I have used David Wang’s original script and edited to include listing of physical path to website content and also write the results to a text file… Not written by me but my Developer, praise to be to him, saved me a ton of time fluffing about. I don’t know how elegant it is, but it definitely works.

Part of the script for listing home directory for website was taken from a sample script posted online, and then edited for my own use. I can’t remember exactly where it was from, so cannot give due credit😦

 

OPTION EXPLICIT

DIM CRLF, TAB
DIM strServer
DIM objWebService
dim myFSO, WriteStuff, txtToWrite

dim objWMIService, colItemz, objItem, sPath
Set objWMIService = GetObject("winmgmts:{authenticationLevel=pktPrivacy}\\.\root\microsoftiisv2")

TAB = CHR( 9 )
CRLF = CHR( 13 ) & CHR( 10 )

IF WScript.Arguments.Length = 1 THEN
strServer = WScript.Arguments( 0 )
ELSE
strServer = "localhost"
END IF

WScript.Echo "Enumerating websites on " & strServer & CRLF
SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )
EnumWebsites objWebService

SUB EnumWebsites( objWebService )
DIM objWebServer, strBindings

FOR EACH objWebServer IN objWebService
IF objWebserver.Class = "IIsWebServer" THEN

Set colItemz = objWMIService.ExecQuery ("Select * from IIsWebVirtualDirSetting where name = 'W3SVC/" & objWebserver.Name & "/root'")

For Each objItem in colItemz
sPath = objItem.Path
Next

WScript.Echo _
"Site ID = " & objWebserver.Name & CRLF & _
"Comment = """ & objWebServer.ServerComment & """ " & CRLF & _
"State = " & State2Desc( objWebserver.ServerState ) & CRLF & _
"LogDir = " & objWebServer.LogFileDirectory & CRLF & _
"Path = " & sPath & _
""

txtToWrite = txtToWrite & CRLF & "Site ID = " & objWebserver.Name & CRLF & _
"Comment = """ & objWebServer.ServerComment & """ " & CRLF & _
"State = " & State2Desc( objWebserver.ServerState ) & CRLF & _
"LogDir = " & objWebServer.LogFileDirectory & CRLF & _
"Path = " & sPath & _
""

' Enumerate the HTTP bindings (ServerBindings) and
' SSL bindings (SecureBindings)
strBindings = EnumBindings( objWebServer.ServerBindings ) & _
EnumBindings( objWebServer.SecureBindings )
IF NOT strBindings = "" THEN
WScript.Echo "IP Address" & TAB & _
"Port" & TAB & _
"Host" & CRLF & _
strBindings

txtToWrite = txtToWrite & CRLF & "IP Address" & TAB & _
"Port" & TAB & _
"Host" & CRLF & _
strBindings

END IF
END IF
NEXT

FileWriter txtToWrite

END SUB

sub FileWriter(WriteText)

Set myFSO = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = myFSO.OpenTextFile("OneOff.txt", 8, True)
WriteStuff.WriteLine(WriteText)
WriteStuff.Close

set WriteStuff = nothing
set myFSO = nothing

end sub

FUNCTION EnumBindings( objBindingList )
DIM i, strIP, strPort, strHost
DIM reBinding, reMatch, reMatches
SET reBinding = NEW RegExp
reBinding.Pattern = "([^:]*):([^:]*):(.*)"

FOR i = LBOUND( objBindingList ) TO UBOUND( objBindingList )
' objBindingList( i ) is a string looking like IP:Port:Host
SET reMatches = reBinding.Execute( objBindingList( i ) )
FOR EACH reMatch IN reMatches
strIP = reMatch.SubMatches( 0 )
strPort = reMatch.SubMatches( 1 )
strHost = reMatch.SubMatches( 2 )

' Do some pretty processing
IF strIP = "" THEN strIP = "All Unassigned"
IF strHost = "" THEN strHost = "*"
IF LEN( strIP ) < 8 THEN strIP = strIP & TAB

EnumBindings = EnumBindings & _
strIP & TAB & _
strPort & TAB & _
strHost & TAB & _
""
NEXT

EnumBindings = EnumBindings & CRLF
NEXT

END FUNCTION

FUNCTION State2Desc( nState )
SELECT CASE nState
CASE 1
State2Desc = "Starting (MD_SERVER_STATE_STARTING)"
CASE 2
State2Desc = "Started (MD_SERVER_STATE_STARTED)"
CASE 3
State2Desc = "Stopping (MD_SERVER_STATE_STOPPING)"
CASE 4
State2Desc = "Stopped (MD_SERVER_STATE_STOPPED)"
CASE 5
State2Desc = "Pausing (MD_SERVER_STATE_PAUSING)"
CASE 6
State2Desc = "Paused (MD_SERVER_STATE_PAUSED)"
CASE 7
State2Desc = "Continuing (MD_SERVER_STATE_CONTINUING)"
CASE ELSE
State2Desc = "Unknown state"
END SELECT

END FUNCTION

Aug
11

UPDATE : http://www.ikailo.com/94/url-modrewrite-workaround-iis-60/

// This is the default file for the site. Usually index.php

$default = ‘index.php’;

// The name of this file.

// Set this value for the URL in Custom Error Properties of your website in IIS.

// Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >

// 404 & 404;2 & 404;3 > URL (Requires a ‘/’ prefix in IIS).

$thisfile = ‘404-handler.php’;

$_SERVER[‘ORIG_PATH_TRANSLATED’] = str_replace($thisfile, $default, $_SERVER[‘ORIG_PATH_TRANSLATED’]);

$_SERVER[‘SCRIPT_FILENAME’] = str_replace($thisfile, $default, $_SERVER[‘SCRIPT_FILENAME’]);

$_SERVER[‘ORIG_PATH_INFO’] = str_replace($thisfile, $default, $_SERVER[‘ORIG_PATH_INFO’]);

$_SERVER[‘SCRIPT_NAME’] = str_replace($thisfile, $default, $_SERVER[‘SCRIPT_NAME’]);

$_SERVER[‘PHP_SELF’] = str_replace($thisfile, $default, $_SERVER[‘PHP_SELF’]);

$_SERVER[‘PATH_INFO’] = false;

$qs =& $_SERVER[‘QUERY_STRING’];

$ru =& $_SERVER[‘REQUEST_URI’];

$pos = strrpos($qs, ‘://’);

$pos = strpos($qs, ‘/’, $pos + 4);

$_SERVER[‘URL’] = $ru = substr($qs, $pos);

$qs = trim(stristr($ru, ‘?’), ‘?’);

// Required for WordPress 2.8+

$_SERVER[‘HTTP_X_ORIGINAL_URL’] = $ru;

// Fix GET vars

foreach ( $_GET as $var => $val ) {

if ( substr($var, 0, 3) == ‘404’) {

if ( strstr($var, “?”) ) {

$newvar = substr($var, strpos($var, ‘?’) + 1);

$_GET[$newvar] = $val;

}

unset($_GET[$var]);

}

break;

}

include($default);

END UPDATE

Originally From : http://tech.einaregilsson.com/2007/07/30/pretty-wordpress-permalinks-on-iis/

Create a 404 page and put the following 4 lines in it:

<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>

All this does is fix the REQUEST_URI and PATH_INFO variables and then include index.php, so WordPress will do the rest. It’s simple, it doesn’t duplicate functionality already in WordPress and it doesn’t have the overhead of another http request for every page hit. The installation steps are:

  1. Create the file wp-404-handler.php in your base WordPress folder.
  2. Set your sites 404 page to point to the wp-404-handler.php url. Most control panels at web hosts allow you to do this. If you’ve got the option to select between FILE and URL then choose URL.
  3. Go to Options -> Permalinks in your WordPress admin page, and choose an appropriate structure for your links. I chose Custom with this pattern:
    /%year%/%monthnum%/%day%/%postname%/ 
  4. Enjoy!
Jul
14

Courtesy of Bill Graziano at SQLteam.com. Script allows you to see the top 25 largest tables in your database. Pretty handy if you are trying to figure why your MDF file is 1.7GB !!

/**************************************************************************************
*
* BigTables.sql
* Bill Graziano (SQLTeam.com)
* graz@sqlteam.com
* v1.1
*
**************************************************************************************/

declare @id int
declare @type character(2)
declare @pages int
declare @dbname sysname
declare @dbsize dec(15,0)
declare @bytesperpage dec(15,0)
declare @pagesperMB dec(15,0)

create table #spt_space
(
objid int null,
rows int null,
reserved dec(15) null,
data dec(15) null,
indexp dec(15) null,
unused dec(15) null
)

set nocount on

— Create a cursor to loop through the user tables
declare c_tables cursor for
select id
from sysobjects
where xtype = ‘U’

open c_tables

fetch next from c_tables
into @id

while @@fetch_status = 0
begin

/* Code from sp_spaceused */
insert into #spt_space (objid, reserved)
select objid = @id, sum(reserved)
from sysindexes
where indid in (0, 1, 255)
and id = @id

select @pages = sum(dpages)
from sysindexes
where indid < 2
and id = @id
select @pages = @pages + isnull(sum(used), 0)
from sysindexes
where indid = 255
and id = @id
update #spt_space
set data = @pages
where objid = @id
/* index: sum(used) where indid in (0, 1, 255) – data */
update #spt_space
set indexp = (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id)
– data
where objid = @id

/* unused: sum(reserved) – sum(used) where indid in (0, 1, 255) */
update #spt_space
set unused = reserved
– (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id)
where objid = @id

update #spt_space
set rows = i.rows
from sysindexes i
where i.indid < 2
and i.id = @id
and objid = @id

fetch next from c_tables
into @id
end
select top 25
Table_Name = (select left(name,25) from sysobjects where id = objid),
rows = convert(char(11), rows),
reserved_KB = ltrim(str(reserved * d.low / 1024.,15,0) + ‘ ‘ + ‘KB’),
data_KB = ltrim(str(data * d.low / 1024.,15,0) + ‘ ‘ + ‘KB’),
index_size_KB = ltrim(str(indexp * d.low / 1024.,15,0) + ‘ ‘ + ‘KB’),
unused_KB = ltrim(str(unused * d.low / 1024.,15,0) + ‘ ‘ + ‘KB’)

from #spt_space, master.dbo.spt_values d
where d.number = 1
and d.type = ‘E’
order by reserved desc

drop table #spt_space
close c_tables
deallocate c_tables

Jul
08

I couldn’t find a concise guide on how to install PHP 5.x on Windows 2003 with FastCGI extensions until I found this blog.

To summarise, here is what is needed

1. Download FastCGI component and PHP5.x NTS zip ( NTS = non thread safe, and make sure you do NOT download the PHP installer .exe, just the zip file. )

Note : The installer seems to do the IIS / OS setup part for you, which is nice, but doesn’t include the extensions necessary for PHP. Why this is, I don’t know. I personally think it is better to set it up manually anyway. Someone correct me if I am wrong.

2. Unzip PHP to a directory of your choosing e.g. D:\PHP5.x

  • Once uninstalled, rename the “php-ini.recommended” to “php.ini”. You can then make your own modifications as per your specifications but at a minmum you probably want to enable PHP error logging

error_reporting = E_ALL
log_errors = On
error_log = ”d:\php\errors\error.log”’

3. Run the FastCGI installer and let it do its thing.

4. Run the following command from the installation directory for FastCGI c:\windows\system32\inetsrv\

cscript fcgiconfig.js -add -section:”PHP” -extension:php -path:”C:\PHP\php-cgi.exe”

5. Extra FastCGI configuration.

  • Make the following changes to your PHP.ini

cgi.fix_pathinfo=1

cgi.force_redirect = 0

fastcgi.impersonate =1

  • Set the FastCGI configuration settings for the PHP section by running fcgiconfig.js as follows:

cscript fcgiconfig.js -set -section:”PHP” -InstanceMaxRequests:10000

  • Configure the FastCGI extension to set PHP_FCGI_MAX_REQUESTS environment variables for the PHP process to 10000.This setting instructs php-cgi.exe to recycle itself after it has processed 10000 requests successfully.

cscript fcgiconfig.js -set -section:”PHP” -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000

6. Add appropriate MIME header types to IIS

Extension = .php   | MIME Type = text/html

7. Test with a php page ( e.g phpinfo(); )

DONE!!

Jul
07

Anyone who admins a Windows 2003 server with FTP access that must be opened to all ( e.g shared web hosting server ) will have encountered brute force FTP logins to the server. If you are using FTP via IIS ( which as shit as it is, is sometimes the only option ) then you will be very interested in the great scripting work by other bloggers.

Below are some links to excellent FTP ban scripts.

Instabans in IIS and also nullroutes on any “administrator” login attempts. Comments also include how to add extra usernames to instaban. ( tested and working on machines under my control )

Netnerds

Instabans based on failed logins and/or number of failed attempts.

Cheshire6

Enjoy

Follow

Get every new post delivered to your Inbox.