Tuesday, December 27, 2011

New security feature in facebook

My account was locked and after spending many suspicious hours finally it got unlocked.
To reopen my account it asked me to give a name of my device. It’s for security so that if anyone hacked your account and open it from some where you will be alerted.  No doubt it is a good security enhancement. However it’s a bad side. Whenever your system IP get changed by DHCP or else you will get an alert mail though still you are opening your account from the same device.
I assume the PHP page get client IP and mapped it with the device name that you provide. Next time, if IP get changed face book identifies the difference and send that alert mail.
Today I have made a suggestion to map Device name with Mac Address instead of Ip.
Through PHP its difficult finding client side Mac address. Using JavaScript it is possible to get client Mac and therefore PHP embedded JavaScript can solve it.

Tuesday, May 10, 2011

ADAM alert – password is about to expire…..

Depending on our ADAM password policy, the support staff must be informed in advance about the date of password expiration. To accomplish it we need to determine if a user’s
-         Account password is set to expire,
-         When the user last changed their password,
-         The maximum password age in the domain and
-         Current date and time.
As a normal user we can retrieve date and time “when the user last changed their password”.

But normal user may not able to see all the attributes in a particular user object. I feel if ADAM uses the password policy and expiry times same as the domain then the values of above attributes would not be configured in ADAM itself. On the other hand a normal user may not get all information using LDAP browser.

However, if maxPwdAge is fixed for all users, we can complete the script and configured a cron job to send “Password_Expirre_Alart” before a week.

Here we assume maxPwdAge is three month. This script will run five minutes after midnight, every day.
#Crontab -e
5 0 * * * usr/bin/php –f /path/to/script
The script :
#!/usr/bin/php
< ?php
// basic sequence with ADAM is connect, bind, search, interpret search result and close connection

function convert_AD_date($ad_date) {
        if ($ad_date == 0) {
                return '0000-00-00';
        }
        $secsAfterADEpoch = $ad_date / (10000000);
        $AD2Unix=((1970-1601) * 365 - 3 + round((1970-1601)/4) ) * 86400;
        // Why -3 ?
        // "If the year is the last year of a century, eg. 1700, 1800, 1900, 2000,
        // then it is only a leap year if it is exactly divisible by 400.
        // Therefore, 1900 wasn't a leap year but 2000 was."
        $unixTimeStamp=intval($secsAfterADEpoch-$AD2Unix);
        $myDate = date("Y-m-d H:i:s", $unixTimeStamp); // formatted date
        return $myDate;
}
//ADAM query test
//Connecting ...
$ds=ldap_connect("Your ADAM server"); // must be a valid ADAM server!
#echo "connect result is ".$ds." ";
if ($ds) {
//Binding ...
$r=ldap_bind($ds, "CN=(Your's CN), OU=(your's OU), OU=Users, DC=(Your's DC), DC=(your's dc)", "(password)"); 
// this is an "anonymous" bind, typically read-only access
//Searching for (sn=S*) ...
// Search surname entry
$sr=ldap_search($ds,"OU=(OU),OU=Users,DC=(DC),DC=(DC)", "uid=*");
//Getting entries ...
$info = ldap_get_entries($ds, $sr);
for ($i=0; $i<$info["count"]; $i++) {
$dn=$info[$i]["dn"];
$first_cn_entry_is=$info[$i]["cn"][0];
$first_email_entry_is=$info[$i]["mail"][0];
$ad_date=utf8_decode($info[$i]["pwdlastset"][0]);
convert_AD_date("$ad_date");
        $myDate=convert_AD_date("$ad_date");
        $pos=strpos($myDate, " ");
        $firstField=substr($myDate, 0, $pos+1);
        $ExpireDate = strtotime(date("Y-m-d", strtotime($firstField)). "+3 month");
// Calculate the occurance to shoot a mail
        $mail_month = strtotime(date("Y-m-d", strtotime($firstField)). "+2 month");
        $mail_week = strtotime('-3 week', strtotime(date("Y-m-d", $ExpireDate)));
        $mail_day = strtotime('-4 days', strtotime(date("Y-m-d", $ExpireDate)));
        $Month=date("Y-m-d", $mail_month);
        $Week=date("Y-m-d", $mail_week);
        $Days=date("Y-m-d", $mail_day);
// Calculate Expiry date as per password policy
        $Passwd_expire_on=date('l dS \o\f F Y', $ExpireDate);
// Here we'll check validity
        $todayDate = date("Y-m-d");
        $expDate = date("Y-m-d", $ExpireDate);
        $today = strtotime($todayDate);
        $exp_date = strtotime($expDate);
        if ($exp_date < $today) {
        $valid="yes";
        //$valid = "Allready Expired..........";
        } else {
        $valid="no";
        //$valid = "Will Expire on $expDate ";
}
// Send a mail to the user before one month/three weeks and before 4days (three times) expiry date. 
$subject="ADAM password will expired on $Passwd_expire_on";
$message = "Hello  $first_cn_entry_is \n Please use the following link and change your ADAM password before it got expired. \n  (Mention URL to change password)";
$headers = 'From: ADAM_Admin@yourDomain.com' . "\r\n" .
    'Reply-To: ADAM_Admin@yourDomain.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
if ($valid==no && $todayDate == $Month)
         mail($first_email_entry_is, $subject, $message, $headers);
   elseif ($valid==no && $todayDate == $Week)
         mail($first_email_entry_is, $subject, $message, $headers);
   elseif ($valid==no && $todayDate == $Days)
          mail($first_email_entry_is, $subject, $message, $headers);
else
          $ans="\nWill mail latter";
}
//Closing connection
ldap_close($ds);
} else {
//Unable to connect to ADAM server
}
?>

Curtsy:  Many information / logic have taken directly from internet/forum. But the idea is came out from the requirement of my project and accordingly the logic has implemented.

Tuesday, December 21, 2010

testPool() methode -- Test Data Source from WLST command line

It was posted in oracle forum about how to test data source from wlst command line.
The script is fine and bit clear. The only concern is the output of testpool() method. It will print None unless we fetch the query and print the result. If we use default JDBC package and query “SELECT count( * ) FROM `systables`” to fetch data from default SYSTABLE the same result will be printed, unless we use fetchall() method.
Please try the below script and compare.

#!/bin/python
'''
Python Version - 2.*
@author : Jaydeb Chakraborty

?? Use WLST to test Data Source via python script

'''
from weblogic.security.internal import *
from weblogic.security.internal.encryption import *
from com.ziclix.python.sql import zxJDBC
from java.io import FileInputStream
from xml.dom import minidom
# Please put the correct path of DataSource Config xml.
doc = minidom.parse('d:/bea/Weblogic1033/user_projects/domains/weblogic1033_domain/config/jdbc/JDBC_Data_Source-0-3407-jdbc.xml')
s = doc.childNodes
t = s[0]
JDBC_DS_NAME = t.childNodes[1].firstChild.data
JDBC_URL = t.childNodes[3].childNodes[1].firstChild.data
JDBC_DRIVER = t.childNodes[3].childNodes[3].firstChild.data
JDBC_USER_NAME = t.childNodes[3].childNodes[5].childNodes[1].childNodes[3].firstChild.data
ENCRP_PASSWORD = t.childNodes[3].childNodes[7].firstChild.data

#Connect AdminServer where connection pool has been targeted
#We can keep these parameters in properties file to avoide hard coding
connect('weblogic','weblogic123','t3://localhost:7001')

#Get password of connectionpool 
encryptionService = SerializedSystemIni.getEncryptionService(".")
clearOrEncryptService = ClearOrEncryptedService(encryptionService)
pwd = ENCRP_PASSWORD
# Remove unnecessary escape characters
preppwd = pwd.replace("\\", "")
# Decrypt the password
psd=clearOrEncryptService.decrypt(preppwd)

#Connect with Database
con = zxJDBC.connect(JDBC_URL, JDBC_USER_NAME, psd, JDBC_DRIVER)
cursor = con.cursor()
result1=cursor.execute("SELECT count( * ) FROM `systables` WHERE 1")
result=cursor.fetchall()
#print number of row exist
print(result) # Print the output of "result1", the exact result you will received as you get exicuting testPool()
if result == None:
print("Check Table")
else:
print("The above number of row has been fetched")

Save this file by any name with extention .py and exicute from wlst.

Saturday, October 16, 2010

High CPU utilization of JAVA process...what is going on?

On top of one kernel space thread LWP is running and user space threads are running on top of LWP.
It may be 1:1 or one: many. I just tried out finding thread ID (LWPID) of java process. The CPU utilization of java PID was too high. Usually I use following command
ps -Leo pid,ruser,vsz,rss,state,priority,nice,time,%cpu,comm,lwp,psr,nlwp
pid = Process ID
ruser = Real user ID
vsz = virtual memory size of the process in KiB (1024-byte units).
rss = resident set size, the non-swapped physical memory that a task has used (in kiloBytes).
state = Process state
priority = kernel scheduling priority.
nice = Nice value.
time = cumulative CPU time,
%cpu = cpu utilization of the process in "##.#" format. Currently, it is the CPU time used divided by the time the process has been running (cputime/realtime ratio), expressed as a percentage. It will not add up to 100% unless you are lucky. (alias pcpu).
comm = command name (only the executable name). Modifications to the command name will not be shown. A process marked is partly dead, waiting to be fully destroyed by its parent. The output in this column may contain spaces. (alias ucmd, ucomm). See also the args format keyword, the -f option, and the c option. When specified last, this column will extend to the edge of the display. If ps can not determine display width, as when output is redirected (piped) into a file or another command, the output width is undefined. (it may be 80, unlimited, determined by the TERM variable, and so on) The COLUMNS environment variable or --cols option may be used to exactly determine the width in this case. The w or -w option may be also be used to adjust width.
lwp and nlwp = lwp (light weight process, or thread) ID of the lwp being reported and number of lwp.
psr = processor that process is currently assigned to.
I have just kept it here for my own convenience. use man to get help of command.
As it was Weblogic server and java processes were owned by weblogic user, I used “| grep weblogic” and then filter with “ grep -v ' 0.0 '” to minimize output.
The above command gives us thread ID and CPU utilization of each thread. Many ways we can accomplish this task.
Use “ps –eo user,pid,%cpu,cmd | grep java” and then “ps u –Lp ” or “top –H –p .
Now we have to search thread id in process thread dump. Before that create thread dump using “kill -3 ” or JVM specific command (JDK/Jrokit).
#jstack > threadDump.txt
OR
#jrcmd print_threads > threadDump.txt
Search lwp ID as tid in thread dump that has taken from Jrokit JVM. Use hex value of lwp ID if java process uses jdk.

Friday, October 15, 2010

Process, child process and thread in Linux

Threading in Linux is (or was!!!) bit confusing.

Before coming to the main point, we need to have clear idea about process and thread. A process is an instance of a computer program that is being sequentially executed. A single process may contain several executable programs (threads) that work together concurrently to carry out the main function of the process. Threads share global data and address space with other threads running in the same process. On the other hand processes do not share address space. Child process has a own copy of data space (VM) of the parent process. Threads can directly communicate with other threads of its process; processes must use interprocess communication to communicate with child processes. Prior to Linux kernel 2.6, Linux OS was not good for JAVA multithreaded applications.
Introduction of NPTL offers performance improvement in the area of thread creation and destruction. With the new lightweight implementation, creating threads is fast and scalable.
Administrator use LWP id finding thread activity in java application. However, there are specific command in Solaris to get PID and associated lightweight process id.

Thursday, September 30, 2010

Use VMware Server to explore Oracle Weblogic

For My system:
--------------
Created 3 VMware Instances on Windows platform
configured network adapter with Nat enabled
installed RHEL 5
installed weblogic cluster on first node and 2nd node
updated host table to communicate each other, pinged each server to test communication
exicuted wlst.sh
startNodeManager()
startserver('AdminServer')
nmConnect('weblogic','weblogic123','MyHost1','5556','vwr','/home/weblogic/Oracle/Middleware/user_projects/domains/vwr','ssl')
start('','Server')
login to anather node and started node manager
from Admin server connected node manager of 2nd server and started managed server 2

Issue:
Weblogic can not started :-> created boot.properties with new
username=weblogic
password=weblogic123
and started weblogic.....did not sarted....LDAP file issue
found one LDAP file's woner was changed to root user
changed that file to weblogic owner
started server

on 3rd server I installed apache 2.2
copied mod_wl_22.so to module folder
in httpd.conf file added following line

LoadModule weblogic_module modules/mod_wl_22.so

edited httpd-vhost.conf file

ServerName MyHost3:80

WeblogicCluster MyHost1:7003,MyHost2:7003
MatchExpression *.jsp PathPrepend /NewApp
MatchExpression *.html PathPrepend /NewApp

SetHandler weblogic-handler

started Apache with following command
./httpd -f conf/httpd.conf -k start

accessed application /NewApp

it was not connected....Issue Network Bridge was not established

configured Network adapter to NAT and enabled DHCP for all 3 host
configured VMware Network adapter with static IP from windows platform andd enabled Automatic bridge from program->vmware->vmware server-> Manage Virtual Network

Everything started working