Nice piece of work on recent browsers resilience and dns round robin
Category : middleware
Problem
You want to add something flash to your site.
A color loads, which you then want to change
Solution
Well cool “Fade Anything Technique”!
Really simple implementation, just copy and then any divs, etc with an id
of fade-xxx will fade from that color. Many more options, check out these highly recommended articles.
Example
<head>
...
<script type="text/javascript" src="/fat.js">
</head>
...
<div style="width: 600px; border:1px dashed #23932B; padding: 10px;" id="fade-23932B" class="fade-23932B">
...
</div>
Reference
Check out the article hosted by axentric, written by Adam Michela
It was inspired by 37 signals
Problem
Here are a few tips, if you are having problems starting apache.
1. A common problem is trying to start Apache on a restricted port. This is where you configure apache to listen on port 80, changing the default 8080.
2. Another problem can be defining logging into directories that don’t exist.
3. If you get an error like User not allowed, or Group not recognized, etc – this is the User and Group statements within your apache configs.
Solution
1. On UNIX this is considered restricted and generally only available to the root user. On windows it is also commonly restricted, so requires an admin account.
2. This will generally output an error along those lines, into apache’s top level error log. Failing that you can try running apache with truss (search my site to find syntax) on Solaris, strace on Linux and trace on AIX.
3. You need to change to match the user running the command – or if root, the delegated user and group user is in.
Another tip is to run /etc/init.d/httpd configtest – which will effectively run httpd -t to syntax check the config. You can also perform a -S which checks and prints your virtual hosts.
If you getting compliants about modules, try running httpd -l to see compile in mods.
Example
Nothing here – please see Solution 🙂
Problem
You want to generate the current epoch offset for UNIX. The count forward since 8am on 1st Jan 1970.
Or conversely you want to see the date and time, for a given epoch offset.
Example
Or enter the date (plus time)
day | month | year |
---|---|---|
hr | mins | secs |
Enter the text to super-impose here and your colours
If you want to see the code here it is | Free online vertical text image creator
Problem
You want to generate a vertical image, with text over the top.
Solution
Here is some code I wrote, which is used extensively on my sites:
Example
Reference
Give it a blast on this site, like this: http://coding-school.com/common/label-up.php?label=your+text+here
Automatically calculates size required. You can also add font=# – where # is 1 to 5, like this:
http://coding-school.com/common/label-up.php?label=your+text+here&font=3
Problem
You notice for some hosts curl and/or libcurl are taking 7 or so secs to lookup the host. But nslookup or dig respond almost immediately.
Solution
Try doing curl -4 -w “time_namelookup: %{time_namelookup}n” …. and try without the -4. If you see drastic differences, you could be falling foul of the IPV6 bug. To work around this, you can either just use -4 with curl or set CURLOPT_IPRESOLVE with libcurl.
Example
I spents hours and hours and hours, trying to get this working with libcurl and perl. It turned out I need to upgrade to WWW::Curl::Easy version 3.0 – as opposed to version 2. Do a search on search.cpan.org for Curl and it will tell you how to check your version.
Then if you like me upgrade, you need to also modify all your code from: Curl::easy::setopt($curl, … to $curl->setopt( …
Reference
Problem
Don’t know about you, but I’m generally quite lazy. Why roll the mouse and click the screen,
when with a quick control c I can copy some text. 🙂
Solution
Learn 10 simple short cuts, which can save you hours.
Example
1.
Copy some text – select it then control c
Now it is in the clipboard.
2.
Click where you want to paste it and control v to paste it. 😉
You can also right click with your mouse to cut and paste.
3.
Minimise all windows, by holding down the windows key and press m
4.
Kick off explorer, by holding down windows key and press e
5.
Do a find by holding down windows key and press f
6.
Switch between windows by holding down alt and pressing tab
7.
Reverse tab through a HTML form, by holding down the shift key.
8.
Open a web link in a new window, by holding down shift and clicking it
9.
To type in a new web address, hold down alt and press d
10.
Save a document with control s, print it with control p, undo a change with control z – sorry got carry away. 🙂
Reference
Problem
Came across an interesting problem with curl.
For curl to perform HTTP Basic Authentication, it is easy to pass –user to the curl command, but harder with libcurl.
Suspect there is an attribute that can be set, but I monitor a multitude of web sites through some perl scripts and libcurl. I did n’t want to have to modify my wrapper scripts, which mesh perl hashes with the code that drives curl (via libcurl).
I do allow for headers though, having needed to pass different things through, like HTTP_REFERER, LAST_MODIFIED, etc.
Therefore I just needed to pass the HTTP BASIC Authentication through as a header.
Example
We then strip out the equals and pass following through to curl or libcurl:
@myheaders=('Authorization: Basic YWRtaW46YWRtaW4'); Curl::easy::setopt($curl, Curl::easy::CURLOPT_HTTPHEADER, @myheaders);
Or from the command line:
curl ... -H'Authorization: Basic YWRtaW46YWRtaW4'
Obviously you need to put your user, followed by a colon and your password – to obtain the correct base64 encoding back – strip the equals out and away you go.
Reference
Problem
Solution
Example
Reference
Symmetric Algo – one key to encrypt and decrypt.
Asymmetric Algo – separate key to encrypt and decrypt.
Stream ciphers – encrypt each bit in sequence.
Block ciphers – encrypt specific blocks of bits.
Hash/Message Digests – one way ciphers, create fingerprints of data.
Problem
Want to know the encryption short or long names.
Solution
DES – Digital Encryption Standard. Symmetric block encryption algorithm
3DES – Triple DES. Symmetric block algo – uses DES three times.
RC4 – Rivest Cipher #4. Symmetric algo uses stream encryption.
RSA – Rivest, Shamir, Adelman. Symmetric block algo.
IDEA – International Data Encryption Algo, symmetric block algo – used by PGP.
AES – Advanced Encryption Standard (Rijndael) – symmetric block algo.
Example
Demo of des3, rc4 and aes256 – using abc123 as password and thecatsatonthemat
$ echo thecatsatonthemat | openssl enc -des3 -a -e -k abc123 U2FsdGVkX1/I03dG1d8bGYycfojc4x/S5uU1YIf1QRPRw+9AgKhVCw== $ echo "U2FsdGVkX1/I03dG1d8bGYycfojc4x/S5uU1YIf1QRPRw+9AgKhVCw==" | openssl enc -des3 -a -d -k abc123 thecatsatonthemat $ echo thecatsatonthemat | openssl enc -rc4 -a -e -k abc123 U2FsdGVkX1+NuZk94r5kJdFfw8gsjlO9ZV7BDXLwm+3PNg== $ echo "U2FsdGVkX1+NuZk94r5kJdFfw8gsjlO9ZV7BDXLwm+3PNg==" | openssl enc -rc4 -a -d -k abc123 thecatsatonthemat $ echo thecatsatonthemat | openssl enc -aes256 -a -e -k abc123 U2FsdGVkX1/bGQ0rtpGi6CjkeAyyEgQjnxkSWBQ6q7XLgAApdWHA5BdEuK24r/NY $ echo "U2FsdGVkX1/bGQ0rtpGi6CjkeAyyEgQjnxkSWBQ6q7XLgAApdWHA5BdEuK24r/NY" | openssl enc -aes256 -a -d -k abc123 thecatsatonthemat
Problem
You want to create a favicon.ico from Unix.
Solution
- Open your image with GIMP
- If your image is not a square then resize the canvas with GIMP
- Scale the image to 16×16 pixel (Image, Scale image)
- Save as favicon.pnm or favicon.ppm with raw encoding
- Close GIMP
Example
Then to convert favicon.pnm or favicon.ppm using the command line utility ppmtowinicon:
$ ppmtowinicon -output favicon.ico favicon.pnm
Or
$ ppmtowinicon -output favicon.ico favicon.ppm
Reference
Kewl tip on creating a favicon.ico with ppmtowinico – thanks to linuxproblem.org. 🙂
Problem
One annoying thing I recently discovered, when copying code from my blogs (yes I use my own tips too! 🙂 ), quotes seem to turn into dots. Both for single and double quotes.
Solution
The answer to this was explained in a blogging book, that apparently the quotes on a keyboard refer to feet and inches – not speech! 😉
The solution is simply to use ASCII notation.
Example
Therefore a double quote becomes " and a single '
Reference
Problem
You want to perform command line display of mysql dbs with mysqlshow.
Solution
Is this demo, I show the options for mysqlshow.
mysqlshow is a real easy way to quickly view your dbs, tables and rows.
Example
Show Databases
$ mysqlshow -i -u'root' -p'xxxxxx' +---------------+ | Databases | +---------------+ | demo | | mysql | | test | +---------------+
Show number of tables under each db
$ mysqlshow -v -i -u'root' -p'xxxxx' +---------------+--------+ | Databases | Tables | +---------------+--------+ | demo | 1 | | mysql | 15 | | test | 0 | +---------------+--------+ 5 rows in set.
Show total number of rows for each db
[[email protected] ~]$ mysqlshow -v -v -i -u'root' -p'xxxxx' +---------------+--------+--------------+ | Databases | Tables | Total Rows | +---------------+--------+--------------+ | demo | 1 | 7 | | mysql | 15 | 1383 | | test | 0 | 0 | +---------------+--------+--------------+ 5 rows in set.
Reference
Problem
You want to know how to do the following, through mysql command line interface:
- Connect to the mysql daemon
- Show the databases your user has access
- Show tables defined under that db
- Show schema for given table
Solution
Example
mysql -u'username' -p'password' -h'mysql_host'
mysql_host is optional if the daemon is running on the same host.
Show databases
show databases;
Show tables
show tables;
Describe tables
use demo; describe demo;
For example:
mysql> show databases; +----------+ | Database | +----------+ | demo | | test | +----------+ 2 rows in set (0.00 sec) mysql> use demo; Database changed mysql> show tables; +----------------+ | Tables_in_demo | +----------------+ | demo_table | +----------------+ 1 row in set (0.00 sec) mysql> desc demo_table; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | id | mediumint(9) | | PRI | 0 | | | day | varchar(20) | | | | | | val | tinyint(4) | | | 0 | | +-------+--------------+------+-----+---------+-------+ 3 rows in set (0.10 sec)
Reference
Problem
You want a simple bit of java code that takes arguments from the command line and displays them.
Solution
Good demo on how to obtain and handle java arguments.
public class Arguments { public static void main(String argv[]) { if(argv.length > 0) { System.out.println("args exec w " + argv.length + " args"); for(int i=0;i...
Example
Here is a demo:
# java Arguments -a -x -y args exec w 3 args argv[0] = -a argv[1] = -x argv[2] = -y
Reference
Problem
Starting out with a new series of tips, getting started with vb scripting. Microsoft have an excellent guide on the site, which I’ve link at the bottom of this post.
Solution
Below is the typical ‘hello world’ script
Example
C:\Documents and Settings\Admin > copy con test.vbs Wscript.echo "Hello World." ^Z 1 file(s) copied.C:\Documents and Settings\Admin > cscript test.vbs Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.Hello World.
Problem
You want to switch user from the MS DOS prompt.
Solution
Use runas
runas /?
Example
Switch user to other id (Then just run explorer and browse to directory)
runas /user:[email protected] c:\winnt\system32\cmd.exe
Where user-id is the USER you wish to change to. For example Admin. xxx represents the hostname of the box or domain.
You can also just use local, if changing to user on the same box, like this:
C\:Documents and Settings\Admin runas /user:localmarcus "c:\WINDOWS\system32\cmd.exe" Enter the password for localmarcus: Attempting to start c\:WINDOWS\system32\cmd.exe as user "localmarcus" ...
Reference
Problem
You want to modify permissions in Windows from the DOS prompt command line.
Solution
Use cacls
cacls /?
Example
Here are the commands to modify MS Windows/DOS files and directories.
- Display file permissions. Replace filename with your file name.
> cacls filename ...filename NT AUTHORITYSYSTEM:F PCxxxxxxxxxxxxAdmin:F
- Modify permissions. Here we are granting full access to the user, replace user with desired user name.
> cacls filename /E /G user:F processed file: C:...filename
- Here we see the permissions have been reset:
> cacls filename ...filename PCxxxxxxxxxuser:F NT AUTHORITYSYSTEM:F PCxxxxxxxxxxxxxAdmin:F
Reference
Problem
You want to create an image text label.
Solution
Use GD library that can be built-in to PHP. Or just use my free on-line tool to create it, as shown in example below.
Once GD is built in – use this PHP code to generate the label.
Example
This shows the label .
You can use this to generate black blank images, with white superimposed text over the top:
.. click this link, change text "label" – then save to your machine.
Reference
ssh-keygen -t dsa -b 1024 [ -c comment ]
Problem
You want to back up your mysql database.
Solution
This script is good for backups, as it will generate a dump – zipped and as the day of the week is used (in the backup file name), automatically rolls every 7 days.
Run it daily or every other day. If you want a months worth, guess can just change the date command, etc.
Example
#!/bin/zsh [ $# -ne 1 ] && { echo "Usage: $0 db" exit 1 } db=$1 dbd="/PATH_TO_YOUR_BUS/$db.$(/bin/date +%a)" # set the path alias mysqldump="/usr/bin/mysqldump" # you may need to modify this alias gzip="/bin/gzip" # may need to change this too # set your password and user mysqldump --user=root --password=your_password $db > $dbd gzip --best --force $dbd exit 0
Reference
Problem
Sometimes there is an audit requirement, to let customers know a link is off your site and therefore you take no further responsibility for it. For example, a reference to an external associate site.
Solution
I’ve just used some simple javascript code, which is triggered by the click (onclick event). This pops up a warning, which can be accepted or rejected. Accepting goes to the desired site, whilst reject just aborts.
Example
Or you can see it in its own page here:
Here is the source code of the link:
<script> function Terms() { popup=window.open('/common/demoP/popup.html','windowName','width=500,height=300'); if (!popup.opener) popup.opener = self; } </script> Hi there - below you'll see a link to www.securityfocus.com. When you click it, a popup will appear that you need to accept to follow the link.
<a href="#" onClick="Terms()">www.securityfocus.com
Here is the source of the popup:
<script> function supressError() { return true; } function load(url) { window.onerror = supressError; opener.location.href = url; } </script> Warning you are about to leave my cool site,
only click 'Leave' if you absolutely want too! <form> <input type=submit value="Don't Leave!" onClick="javascript:self.close()"> <input type=submit value="Leave" onClick="javascript:load('http://www.securityfocus.com');self.close()"> </form>
Reference
Problem
You want to implement encryption between the web server and the backend Weblogic server.
Solution
Save yourself the 8 hours it took me to debug this one! 🙂
Handed to you on a plate – clear simple and proven. 😉
Generate a self signed cert as describe in my
One gotcha is if your WLS has only an export license, which then requires a maximum of 56bits encryption via a 512 byte cert.
Example
Therefore you need to generate the cert like this (2 years):
openssl req -newkey rsa:512 -days 730 -keyout newreq.pem -out newreq.pem
To check if you have an export license,
grep -i export /opt/bea/license.xml
– will show something like this:
license component="SSL/Export" expiration="never …
Another suggested tip by BEA is to ensure the files (cert, key and ca cert) should all end with the extension .pem.
Once you have the new key, cert and your CA cert (default demoCA/cacert.pem), copy it into /opt/bea/wlserver6.1/config/bpmdomain/myserver (or the location where you have Weblogic installed).
In our version we use wlintegration – so our path is /opt/bea/wlintegration2.1/config/bpmdomain/myserver
Reference
Subsequently these files are referenced from config.xml as explain below(replace file names with the ones you created and your ca):
ServerCertificateChainFileName="./config/bpmdomain/myserver/ca…..pem" ServerCertificateFileName="./config/bpmdomain/myserver/…crt…..pem" ServerKeyFileName="./config/bpmdomain/myserver/…key….pem" TrustedCAFileName="./config/bpmdomain/myserver/ca…..pem"/>
For apache to work, need to modify configs to look something like this (after copying your cacert file to location designated below):
...IfModule mod_weblogic.c... WebLogicHost hostname WebLogicPort 7002 SecureProxy On trustedCAFile yourcafile.pem RequireSSLHostMatch false ConnectTimeoutSecs 60 Debug Off ErrorPage https://xxxx/outage.html .../IfModule...
Notice the different port (7002) – default Weblogic SSL port. You need to ensure this is open from the firewall.
See my perl
You can use listenport code as well to listen on 7002 on application server, then scanport code to attempt to connect from the web server.
Therefore ensure it will work, even before entering change control! 🙂
Problem
You want to be able to view BEA Weblogic Server status from the command line.
Solution
Works beautifully with weblogic 6.1 and wlintegration 2.1 on Solaris – untested with Weblogic 7 or 8, etc.
Example
If your setenv.sh is different, update to correct path – same with password and port (7001).
To obtain the JVM stats, just run it like this:
./wladmin GET -pretty -type JVMRuntime
=================== wladmin script ========================== #!/bin/zsh # script to run command line weblogic stuff [ $# -eq 0 ] && { echo " Usage: $0 Command Examples: $0 HELP $0 GET -pretty -type Server $0 GET -pretty -type Server $0 GET -pretty -type Security $0 GET -pretty -type WebAppComponent $0 GET -pretty -type WebAppComponent Runtime -property Status $0 GET -pretty -type Application $0 GET -pretty -type Realm $0 GET -pretty -type ServletRuntime $0 GET -pretty -type JVMRuntime $0 GET -pretty -type JDBCConnectionPool $0 GET -pretty -type JDBCConnectionPoolRuntime $0 GET -pretty -type Machine $0 GET -pretty -type Cluster $0 GET -pretty -type ClusterRuntime $0 GET -pretty -type JTA $0 GET -pretty -type JTARuntime $0 GET -pretty -type ExecuteQueue $0 GET -pretty -type ExecuteQueueRuntime " exit 1 } . /opt/bea/wlserver6.1/setenv.sh > /dev/null java -cp $CLASSPATH weblogic.Admin -url localhost:7001 -username system -password YOUR_PASSWORD $* exit 0 =================== wladmin script ==========================
The HeapFreeCurrent is the value of interest.
Capture can then be automated with a script run by cron, that additionally pumps out the date to correlate timings with stats.