Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Thursday, August 28, 2014

ASP - Cheap Debug Input Dumper

I call it: Dave's Dastardly Diabolical Debugging Dumbass Dumper, or just Debug Dump for short.  It simply prints out any form inputs and querystring inputs and then stops the page rendering process dead.  That allows you to structure a processing page to capture inputs and then dump them before proceeding to process them; allowing you a chance to see what may be going in the wrong direction before you go further into the debug abyss.

[asp]
<%
Sub Show_InputParams ()
   Dim fn, qv, fc, qc
    fc = 0
    qc = 0
    Response.Write "

Form Inputs

"

    For each fn in Request.Form()
        Response.Write "" & fn & " = " & Request.Form(fn) & "
"

        fc = fc + 1
    Next
    Response.Write "

QueryString Inputs

"

    For each qv in Request.QueryString()
        Response.Write "" & qv & " = " & Request.QueryString(qv) & "
"

        qc = qc + 1
    Next
    Response.Write "

(processing halted)

"

    Response.End
End Sub
%>
[asp]

To try this out the quickest way, paste that mess above into a new file and save it as "dumbass.asp".  Then access it via your browser along with some test parameters (querystring inputs for now).  something like "/mysite/dumbass.asp?test1=123&a=def&x=4321"

It should print out something like the following...

Form Inputs
(no form inputs found)

QueryString Inputs

test1 = 123
a = def
x = 4321
3 querystring inputs found

(processing halted)


ASP - Function to Get Windows Logon UserName

This requires that you have some form of authentication enabled on the web site configuration.  I prefer Windows Authentication, but forms or basic might also suffice.  Basically, regardless of the web browser, as long as some form of authentication is required, and the user provides it (or the browser hands it over silently, like IE usually does, cough-cough), it will spew forth the "logon_user" or "remote_user" server variable.  Using that, you can parse out a NetBIOS domain prefix, such as "contoso\dumbass" to return just the "dumbass" part.

[asp]
<%
Function Get_UserName()
    Dim tmp, result
    result = ""
    tmp = Trim(Request.ServerVariables("LOGON_USER"))
    If tmp = "" Then
        tmp = Trim(Request.ServerVariables("REMOTE_USER"))
    End If
    If tmp <> "" Then
        If InStr(tmp, "\") > 0 Then
            arrtmp = Split(tmp,"\")
            result = Lcase(arrtmp(1)
        Else
            result = Lcase(tmp)
        End If
    End If
    Get_UserName = result
End Function

' test it out...

If Get_UserName() = "dave" Then
    Response.Write "yay!  it's dave!"
Else
    Response.Write "boo.  it's not dave. bummer."
End If
%>
[/asp]

Thursday, July 29, 2010

Script to Auto-Update Your Sysinternals Tools

Jason Faulkner posted a very cool Batch script to freshen your library of Sysinternals tools over at SysAdminGeek.com.  It queries the live.sysinternals.com\tools repository and downloads matching tools in your library.  If you haven't already checked it out, you should (click here).

Here's a version I've done in VBScript.  You can tweak it for your needs and even schedule it to run periodically to keep your tools up to date.

Const livetools = "\\live.sysinternals.com\tools"
Const localtools = "c:\sysinternals"

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next
wscript.echo "info: connecting to live.sysinternal.com..."
Set objLiveFolder = objFSO.GetFolder(livetools)
If err.Number <> 0 Then
wscript.echo "fail: unable to connect"
wscript.quit(1)
End If

If objFSO.FolderExists(localTools) = False Then
wscript.echo "fail: local folder not found"
wscript.quit(2)
End If

For each objFile in objLiveFolder.Files
fileName = objFile.Name
If objFSO.FileExists(localtools & "\" & fileName) Then
wscript.echo "info: updating file " & fileName & "..."
sourceFile = liveTools & "\" & fileName
targetFile = localTools & "\" & fileName
objFSO.CopyFile sourceFile, targetFile, True
End If
Next

Set objFolder = Nothing
Set objFSO = Nothing


If I had more time I'd do this in KiXtart and Powershell, but I'll leave that to someone else.  Enjoy!

Friday, December 25, 2009

Scraping Web Pages with VBScript and KiXtart

Here’s a quick example of how to scrape HREF and IMG strings from a web page using VBScript and KiXtart with the InternetExplorer.Application COM object.  Thanks to Paul Sadowski for the basis of the VBScript example (with only very slight modifications).

VBScript Code

url = "http://www.textpad.com"

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate url

Wscript.Echo "DOCUMENT HYPERLINKS" & vbCRLF
Do Until ie.ReadyState = 4
Wscript.Sleep 2
Loop
For each link in ie.Document.Links
Wscript.Echo link, link.InnerText
Next

Wscript.Echo "------------------------------------"
Wscript.Echo "DOCUMENT IMAGE TAGS" & vbCRLF

For each img in ie.Document.Images
Wscript.Echo img.Src
Next

ie.Quit


KiXtart Code



break ON

$url = "http://www.textpad.com"

$ie = CreateObject("InternetExplorer.Application")
$ie.Navigate($url)
? "DOCUMENT HYPERLINKS"

While $ie.ReadyState <> 4
Sleep 2
Loop

For each $link in $ie.Document.Links
? $link+"="+$link.InnerText
Next

? "DOCUMENT IMAGE TAGS"

For each $pix in $ie.Document.Images
? $pix.Src
Next

$ie.Quit()

Sunday, July 12, 2009

PHP: Determine Zodiac Sign from Birth Date


function ZodiacSign($date){
list($year,$month,$day)=explode("-",$date);
if (($month==1 && $day>20)||($month==2 && $day<20)) {
return "Aquarius";
} else if (($month==2 && $day>18 )||($month==3 && $day<21)) {
return "Pisces";
} else if (($month==3 && $day>20)||($month==4 && $day<21)) {
return "Aries";
} else if (($month==4 && $day>20)||($month==5 && $day<22)) {
return "Taurus";
} else if (($month==5 && $day>21)||($month==6 && $day<22)) {
return "Gemini";
} else if (($month==6 && $day>21)||($month==7 && $day<24)) {
return "Cancer";
} else if (($month==7 && $day>23)||($month==8 && $day<24)) {
return "Leo";
} else if (($month==8 && $day>23)||($month==9 && $day<24)) {
return "Virgo";
} else if (($month==9 && $day>23)||($month==10 && $day<24)) {
return "Libra";
} else if (($month==10 && $day>23)||($month==11 && $day<23)) {
return "Scorpio";
} else if (($month==11 && $day>22)||($month==12 && $day<23)) {
return "Sagittarius";
} else if (($month==12 && $day>22)||($month==1 && $day<21)) {
return "Capricorn";
}
}

PHP: Generate List of U.S. State Abbreviations

For form select listbox populating...


function StateCodes($deft) {
$clist = "AL,AK,AS,AZ,AR,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,"
. "KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NY,"
. "OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY";
$tok = strtok($clist, ",");
while ($tok != false) {
if ($deft == $tok) {
echo "\n";
}
else {
echo "\n";
}
$tok = strtok(",");
}
}

Saturday, July 11, 2009

KiXtart: Open Browser / Display Web Page

Great for login banners and bulletins...


Function OpenWebPage($url, $show, Optional $height, $width, $fixed)
$ie = CreateObject("InternetExplorer.Application")
If $ie <> 0 and @ERROR = 0
$ie.Navigate($url)
If $show = 1
If $height > 0
$ie.Height = $height
EndIf
If $width > 0
$ie.Width = $width
EndIf
If $fixed = 1
$ie.Resizable = 0
$ie.StatusBar = 0
$ie.Toolbar = 0
EndIf
$ie.Visible = 1
Sleep 1
Else
? "(openwebpage): accessing document in silent-mode"
Sleep 1
$ie.Quit
$ie = 0
EndIf
Else
? "(openwebpage): error / unable to launch IE application object"
EndIf
EndFunction

Sunday, July 5, 2009

VBScript Scrape Links/IMG tags from URL


args = WScript.Arguments.Count

If args <> 1 Then
Wscript.Echo "usage: ScrapeLinks.vbs URL"
Wscript.Quit
End If

URL = WScript.Arguments.Item(0)

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate URL

Do Until ie.ReadyState = 4
Wscript.sleep 10
Loop

Wscript.Echo "DOCUMENT LINKS"
Wscript.Echo

For each link in ie.Document.Links
Wscript.Echo link, link.InnerText
Next

Wscript.Echo
Wscript.Echo "DOCUMENT IMAGE TAGS"
Wscript.Echo

For each pix in ie.Document.Images
Wscript.Echo pix.Src
Next

ie.Quit
Set ie = Nothing