Wednesday, December 16, 2009

Simple way to prevent printing of web page

Basically, there is no way to prevent a user who really wants to print a web page out, it is a simple as them hitting their "Print Screen" button, etc...

But for intranet purposes, letting your users know that some pages are not to be printed, you can add the following code to the head section:

{{Code is changed slightly by removing "<" in front of tags for display here:}}

head>
style type="text/css" media="print">
body { visibility: hidden; display: none }
/style>
/head>

This will only print out a blank page when the user goes to "file"--> "print" (print conventionally)

A user can still print out by unconventional methods but, by doing so, is understanding the company does not want it printed, and he is behaving improperly.

Enable thumbnail view and photo editor in Windows Server 2008

When trying to use Server 2008 more like a desktop, you will find some options need to be enabled so that it behaves more like a workstation.

Two things that come to mind are thumnail view which is disabled and Microsoft Windows Photo and Fax viewer (so that you can view the pictures with something other than "Paint")

For Thumbnails:
Click on "start" --> "run", then type in "SystemPropertiesPerformance" Check off "show thumbnails instead of icons and then "OK"

For "Photo and Fax viewer", you need to enable the "Desktop Experience" in the Server Manager, go to "Features" --> "Add Features" and choose "Desktop Experience". the Windows Photo and Fax viewer will then be enabled.

Wednesday, December 9, 2009

Sharing HP Deskjet 5600 series (HPA) on Windows 7

Just finished sharing my HP 5850 printer on my home network in Windows 7 with my Windows XP machine. Sounds easy yes?. Well it took me a while to do this, here is what I went through.

USB connection to the 5850 from Windows 7 machine, whoops, no real driver for this so you need the 5600 Series (HPA) driver for it to function. Ok now sharing it out, well you have to enable sharing for people who do not have an account on that machine; (hey, this is a home network) another step. now to add additional drivers (like, for XP but nope, can't do that cause it asks for .inf file and I can't find it 0k didn't really investigate if it was there, but i am fairly sure the lay-person won't find it)

Now, going to the XP machine I point to the windows 7 machine and low and behold it says "driver is not installed on that machine, so browse to it on your own machine", but then it is nowhere to be found on the machine (or I couldn't find the driver as I checked every $win inf$ file there was)...and also guess what, you won't find that HPA driver anywhere at HP.com either.

So... I installed a 5800 series printer on my xp machine, pointed it to the local port and said just install the driver even though the it cannot find the printer. Then I went to the newly created printer and changed the port; created new port and called it \\(windows7machine)\(sharedprintername)

Now I can print to the shared printer on the Windows 7 machine.

Anybody got a better way?

Wednesday, December 2, 2009

Remove User Account Control warning from Windows Vista

Vista allows you to turn off the UAC via -->Control Panel -->User Accounts -->"Turn off User Account Control" but then creates an annoying "warning User Account Control Turned off" pop-up balloon which you then can't shut off. I'd like to someday create a poll on which is more annoying....the User account control or the warning that it is turned off.

Anyway, turn it off in the registry by HKey_LOCAL_MACHINE\SOFTWARE\Microsoft\SecurityCenter
Add this value:
Data Type: DWORD
ValueName: UACDisableNotify
Value: 1 (dec)

Restart

Wednesday, November 18, 2009

install command line ssh client on Windows

It is necessary when communicating with Linux and Unix machines that it is done securely and no longer with telnet, so every Windows user should have a ssh client on their machines. I prefer a command line client and find that the Cygwin environment is almost a must for Windows users.

Go to http://www.cygwin.com/ and download the setup to install a "Linux-like" shell and make sure you choose "openssh". Now you will have a free ssh client to communicate with you Linux and Unix machines. Don't forget to put the directory path to the Cygwin bin directory in your Windows path statement so you don't have to "cd" to the right directory.

Monday, November 16, 2009

Windows 7- Windows Search Service does not start

If you have trouble searching for files, then your Search Service might not be on.
Follow these steps to rebuild your index and start up the service.

1/2 Go to :
Open Control Panel > System & Maintenance > Indexing Options. In the Advanced Options, Click on Restore Defaults and also Rebuild Index. Click OK.












2/2 Next go to :
Control Panel\All Control Panel Items\Administrative Tools\Services
Scroll down until you find windows search service.
Right click and choose start












Hope this helps you.

Thursday, October 29, 2009

ASP code to guard against SQL injection

It is necessary whenever you are writing a SQL query in your ASP code, to guard against SQL injection, here are examples to use when in production mode:

If the field dEmployeeNumber in the DB is *NOT* a number:

Code:
SQL = "SELECT tEmployeeNumber, tTopic, tDepartment, tTime FROM tblSurvey "
& " WHERE tEmployeeNumber='" & Replace(dEmployeeNumber,"'","''") & "'"

If it *IS* a number:

Code:
SQL = "SELECT tEmployeeNumber, tTopic, tDepartment, tTime FROM tblSurvey "
& " WHERE tEmployeeNumber=" & CLNG(dEmployeeNumber)


with proper credit to Bill W from 4guysfromrolla

Friday, October 9, 2009

function to format phone number field in form

Needed to format a phone number field as soon as the person typed it into the form, I like this solution:

(tag) script (endtag)
function formatPhone(fld)
{
var ph = fld.value.replace(/[^\d]/g, "" ); // zap all except digits
// if user entered the leading 1, just zap it
if ( ph.length == 11 && ph.charAt(0) == "1" ) ph=ph.substring(1);
if ( ph.length != 10 )
{
alert("Sorry, '" + fld.value + "' is not valid phone number");
return false;
}
fld.value = "(" + ph.substring(0,3) + ") " + ph.substring(3,6) + "-" + ph.substring(6);
return true;
}
(endtag)script(tag)

and it is called by:
onchange="formatPhone(this);" - or it could be used during validation....

Wednesday, October 7, 2009

Sending email using CDO and ASP on IIS7

Struggled with this one for a while, so I am posting here to remember the method.

Dim objMail, objMailConf
Set objMail = Server.CreateObject("CDO.Message")
Set objMailConf = Server.CreateObject("CDO.Configuration")

objMailConf.Fields.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 '2 for web server (1 is to sit in the pickup directory)
objMailConf.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
objMailConf.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "postoffice.test.com"
objMailConf.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMailConf.Fields.item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10

objMailConf.Fields.Update

Set objMail.Configuration = objMailConf
objMail.From = "webemail@somewhere.com"
objMail.To = "somemailbox@somewhere.com"
objMail.Cc = "someccuser@somewhere.com"
objMail.Subject = "Company Web Input"
objMail.htmlBody = EmailMessage
objMail.Fields.Update
objMail.Send
Set objMail = Nothing

Monday, September 21, 2009

Link Excel spreadsheet to SQL Server 2005

Create "New Linked Server" in the linked servers tree
* Name it
* Provider: Microsoft Jet 4.0 OLE DB Provider
* Product Name: Excel
* Data Source: c:\xxxx\xxxx\xx.xls
* Provider String: Excel 8.0

Then choose OK - make sure you have the file in the proper directory.

Thursday, September 17, 2009

display all fields from one database record

Here is a quick way, when debugging, to display all fields from one record
(courtesy of Bill W from 4GuysfromRolla)

strSQL = "SELECT * FROM requests WHERE ID = " & rID & ";"
Set RS = yourAlreadyOpenConnectionObject.Execute( strSQL )
For fnum = 0 TO RS.Fields.Count-1
Set fld = RS.Fields(fnum)
Response.Write fld.name & "=" & fld.value & "(begin tag)br/(end tag)" & vbNewLine
Next

Displaying all form fields submitted from page

I like this simple code when debugging or starting a new project where I need to see all the form fields submitted at once:

For Each fld In Request.Form
Response.Write fld & "=" & Request.Form(fld) & "(begin tag)br/(end tag)>" & vbNewLine
Next
Response.Write "(begin tag)hr(end tag)"

Friday, September 11, 2009

IDC Servco SCAM

Administrator at the office got a call on the phone today from someone claiming to be from Hewlett Packard and "needed to talk about the problem with the HP printer" The administrator sent me the call and when I picked up, the person on the line said "I'm calling for Hewlett Packard, this is about your HP2015 printer, we're sorry we were supposed to call about the price change on the toner it is going up to 748 dollars from its regular price of 698 dollars, we didn't get this information to you out in time." I'm thinking hmmm I don't even have a HP2015 printer and anyway, this is a lot of money for toner so I said "how much toner?", she said "a box" I am thinking this must be a carton of about 6 or something, I said "one box?" and she said "yes, now we will complete the order and ship it out at the lower cost" I said "what company are you?" and she said "IDC Servco", then I said "how come I have never heard of you and why are you quoting prices to me as if you were shipping it out?", the next thing she did was hang up.

I checked on the internet and found this is a common scam attempt from this company:
http://www.complaints.com/2007/september/14/IDCSERVCO_152345.htm That is a post from 2007 so this stuff has been happening for a long time.

Please tell your people in charge of the printing supplies to watch out for this, they are fast talkers....

Wednesday, August 5, 2009

Free pdf OCR solution using Microsoft tools

Came across an issue where I had to convert a poorly scanned pdf document to word. The steps I took were to print the pdf to the "Microsoft Office Document Image Writer", saved as a .mdi file, then open it up in Microsfot Office Document Imaging (in the tools section), then choose to OCR the document and save text to Word. Worked fairly nicely and simply had to clean up the text.

Wednesday, July 29, 2009

loop through dates, skip days

Had an issue where I needed to loop from a start date to an end date but for certain weekdays, (like fridays or mondays, information coming from a series of checkboxes; 1 for each weekday) I needed to skip whichever the user checked off....

Solution:

For dt = StartDate To EndDate
If InStr( shiftdays, CStr(Weekday(dt)) ) > 0 Then
... process this dt ...
End If
Next

Tuesday, July 28, 2009

COALESCE

This function was hard for me to first understand, but I have found it very useful:
COALESCE(expression1,expression2)
means if expression1 is null, then expression2

This was useful when a column originally contains null values and I needed to concatenate a value to it, not knowing if the value was still null

COALESCE(column1,'') means if column1 is null, then blank, otherwise column1

Friday, July 24, 2009

Taking on Nagios

OK,
I have been searching for an easy way to try out Nagios, even going to VMWare for a virtual machine, there is only 1 link worthwhile and it is dead, it is the same link that everyone in Google refers to as well, so I am convinced there is no easy way.

Maybe when I finish, I'll post the virtual machine at VMware or keep it at my site for visitors...

I am going to start from scratch; download Fedora 11, then the Nagios tarball. Then configure....

1. Downloaded Fedora 11 and installed to 15G hard drive
2. Download Nagios: nagios-3.0.6.tar.gz
3. un-tar Nagios: tar xzf nagios-version.tar.gz
4. add user nagios: adduser nagios
5. make installation directory: mkdir /usr/local/nagios
6. chown the directory: chown nagios.nagios /usr/local/nagios
7. creat a new group: /usr/sbin/groupadd nagcmd
8. add the web and nagios user to that group:
/usr/sbin/usermod -G nagcmd apache
/usr/sbin/usermod -G nagcmd nagios
9. run configure (include command group nagcmd):
./configure --with-command-group=nagcmd
10. now compile: make all
11. post init file to /etc/rc.d/initd:make install-init
12. now edit httpd.conf with the following 2 aliases so that the web pages get diverted to correct directories:

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user


Alias /nagios /usr/local/nagios/share


Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user


13. restart the web server: /etc/rc.d/init.d/httpd restart
14. OK - now trying to log into nagios via website, I get AVC denials all over the place, after searching, I find my best answer for now is to just disable SELinux - kind of like disabling the junk I don't like in Vista - this is not a recommendation, just something I do to move forward, I can enable SELinux later when I get everything running
15. Great, now a "Whoops" error, After fruitless "googling" I get nowhere so as a last resort, I actually read the error carefully, first, I run a nagios -v {config-file] command like they say: ./nagios -v /usr/local/nagios/etc/nagios.cfg
everything shows fine, so now I run it without the -v and I see that I get a weird error about not finding the nagios.cmd in the usr/local/nagios/var/rw directory. Understood, cause I don't even have an rw directory. So I go ahead and create it and set ownership and group to "nagios". Run the command again and yes, nagios now starts..... Log into the webpage and can now see everything. Next step will be to learn everything it can do and try the plugins...

OK - update 2 weeks later, I have configured nagios to monitor LAN servers as well as a few off-site servers. Had to work with windows.cfg, commands.cfg in the /usr/local/nagios/etc/objects directory and the nagios.cfg, cgi.cfg in the /usr/local/nagios/etc directory. Needed to download nsclient++ and install on all windows servers, configure the .ini file and poke holes for the listening port of choice in the .ini file.

Next was fighting with the horrible email notification documentation. Finally had to yum install ssmtp and configure the conf file to my email server and fight with the command line to get the correct user from, to and subject. Funny how important the alerting is, yet the documentation is a joke for this issue and don't try to go on the forums, all you get is some pompous advice to RTFM - hmmm I did read the manual and it was written horribly, that is what the forum is for; to help interpret the poorly written stuff that techies write and think is incredibly clear....

Well, after getting it all running, have to say it is pretty cool, and I even tracked back to re-enable all the security that I removed to get this up and runing.

Monday, July 20, 2009

Installing New Open-Source SSL VPN

Here I will document the complete installation of a new SSL VPN - Completely OpenSource and Free as in beer.

Download Adito
Download latest Java Development Kit
Download Apache ANT

Decompress ANT to c:\ANT
Change Environment Path to add c:\ant\bin

Issue 1. After issuing "ant install" in command prompt it could not find the tools.jar file because it was looking in the jre directory and not the jdk directory - I issued "set JAVA_HOME=c:\program files\java\jdk1.6.0_14" in command prompt. This allowed ant to find the tools.jar file and copy it back to the Adito home directory. Has to do this for legal reasons - Adito cannot package tools.jar into their install.

Great, everything starts to install and brings me first to a certificate creation or install - I create new cert with passphrase and company info.

Fill in info, decide whether to use Active Directory or built-in database, creae super user, decide port/protocols/ip addreses outside names, etc

Configure proxy

Finished install - now to keep it running between re-boots: go back to adito directory and issue "ant install-service" in command prompt

Now start the service and login at https://localhost

Adito doesn't seem to have any ready-made extensions so I copied RDP from old SSL-Explorer application - has to be a zipped file, complete with application.xml file. Went to extension store and uploaded it, failed twice before actually uploading, now it is there and I can choose it when I go to "create application".

Now I can't connect through the firewall - seems NAT is working fine however the windows firewall even though is set to allow https traffic, still blocks it. Added a rule to allow port 443 and now it allows Adito to work - can't understand why that is....

Well, now I have a complete functioning SSL VPN, available from anywhere.

I will experiment with Adito agent and maybe creating web folders, etc. - maybe a little later

Checklist for re-installing operating system on user's computer

Reinstalling Operating system:

Copy over folders:
• C-Drive
• My Documents
• Desktop

Get IP address and all network information

Get computer name, and user log-in and password (any other profiles?)

Get LAN card driver info
Get Video card driver info
Get mapped drives info

Get printer info
• IPaddress
• Driver

Get email info complete:
• PST file
• .nk2 file
• Signature
• Print out mail settings
• Get email password
• Contacts / address book

Get experience
• Display setting
• Default home page
• Favorites

Java download needed – most likely
AVG Free

What versions of software – office, etc.

MS Access - filter email addresses by domain name

The following will give me the information to the right of the "@" sign so that I can filter by domain name

Mid([address],InStr([address],'@')+1)

Thursday, July 16, 2009

check my open ports

netstat -o

Then to see what the PID is doing:

TaskList /FI "PID eq 4072" /FO LIST /V

SQL Server error converting nvarchar to float

Had numbers in my column like "1,298.05" when I was expecting 1298.05 So to get around this, whenever I refer to the column for calculations I use:
convert(money,REPLACE(t1.[TOTAL_AMOUNT_PAID],'"', ''))

Tuesday, July 14, 2009

Disable DEP for good

Don't bother posting the question on a forum, 90% of the time you will get answers like "why do you want to do that - here is a better way...." or " right-click on my computer, properties, advanced, performance,settings then Data Execution Protection tab.."

To shut it off completely from bothering you, which it eventually will (especially if you use legacy programs), edit your boot.ini file and add /noexecute=AlwaysOff at the end. Reboot, problem solved.

New ThinkMate Quad Core Xeon Server

Just took delivery on Server, now to install operating system, and configure:

Step 1 - Thank you ThinkMate, upon plugging it in and installing the CD, the machine found the 15K SAS drive and began to install.

Step 2 - Turn off Internet Explorer Enhanced Security Configuration: Go to server manager and click on Configure IE ESC. Turn it off there

Step 3 - disable hibernate - are you kidding me? hibernation on by default?
powercfg.exe /hibernate off

Wednesday, July 8, 2009

Gradient Background

This is only for microsoft IE browsers - good tip for captured audience intranets.

body style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"


For other browsers, best to create a 5 pixel wide by 800 height file using PhotoShop then the gradient tool - save as a gif or jpeg and use in css like this:

{
background-image:url(images/jjgradient.gif);
background-repeat:repeat-x;
background-position: top;

}

Wednesday, July 1, 2009

Open Source Changes

Just found out that Adito has merged with OpenVPN to create OpenVPN ALS. Adito has been a fantastic Open Source SSL VPN; totally replacing my Cisco PIX solutions I used to pitch (more on that later) Open VPN was also a great solution when I needed access to a whole network. The fact that these 2 have converged is fantastic news and I will be deploying this solution immediately to clients wishing for secure, opensource, inexpensive VPN's