Sunday 4 December 2011

Ubuntu secure

http://www.andrewault.net/2010/05/17/securing-an-ubuntu-server/

My Install:

apt-get install ssh
apt-get install apache2
apt-get install php5 libapache2-mod-php5
apt-get install php5-mysql
apt-get install denyhosts


Try to get desktop via vnc

apt-get install vnc4server
apt-get install ubuntu-desktop
apt-get install gnome-tweak-tool
apt-get install gnome-shell



To allow SSL on Apache

a2enmod ssl
a2ensite default-ssl
/etc/init.d/apache2 stop
/etc/init.d/apache2 start

good site: https://help.ubuntu.com/10.04/serverguide/C/httpd.html


To remove Apache Signature and custom 404


# vi /etc/apache2/apache2.conf add at the bottom

ServerTokens Prod
ServerSignature Off
ErrorDocument 404 /err.html
ErrorDocument 403 /err.html



Disable docroot / folder display, remove Indexes from Options like below

# vi sites-available/default-ssl and remove Indexes

[Directory /var/www/]
#Options Indexes FollowSymLinks MultiViews
Options FollowSymLinks MultiView
AllowOverride None
Order allow,deny
allow from all
[/Directory]

Thursday 17 November 2011

HP Server and Dell 3200i iScsi SAN

Good links

http://www.onejohn.org/wpjohn/2010/04/iscsi-on-a-dell-md3000i/

Multipat
http://www.linuxcertif.com/man/5/multipath.conf/



Partition larger that 2 TB?
http://sakafi.wordpress.com/2008/08/23/how-to-use-parted-for-creating-patition-larger-that-2-tb/

Command get WWID

scsi_id -g -u -s /block/sda



parted /dev/sda

(parted) p
Error: msdos labels do not support devices that have more than 4294967295 sectors.

(parted) mklabel gpt
(parted) print



parted /dev/sda

mkpart primary 0 3072000
p
mkpart primary 3072001 4072000
p
quit





mkfs.ext3 -m1 /dev/mapper/mpath0p1

mkfs.ext3 -m1 /dev/mapper/mpath0p2


Added in eth file following line (this is for performance)

vi /etc/sysconfig/network-scripts/ifcfg-eth2

MTU=9000

Thursday 10 November 2011

MAC software

After 3/4 weeks of JEdit 4.4.1, I have given up and removed the software, too buggy.

SVN tips

Backup your svn repo:
svnadmin dump /path/to/reponame > /path/to/reponame.svndump

svnadmin dump /path/to/reponame | gzip > reponame.svndump.gz

Sunday 23 October 2011

Dua for Bride & Groom after Marraige/Nikah

"Barak Allah hu laka wa baa rak Allah hu alaika wa jama'aa bainakuma fi khair"

"May Allah bless you and shower HIS blessings on you and place goodness between both of you"


"May Allah bless for you (your spouse) and bless you, and may He unite both of you in goodness."

See: Makedua.com

http://allahmohammad.blogspot.com/2008/06/dua-for-bride-groom-after-marraigenikah.html


This Dua and other important Dua are in this book(let) 'Fortress Of Muslim'.

Three types of self or states of spiritual development

There are three types of self or states of spiritual development that have been mentioned in the Qur’an.
The lowest of these is called Nafs Ammarah (12:53), the self that is prone to evil.
Nafs Lawwamah (75:2) is the self that feels conscious of doing evil, resists, repents and tries to amend.
The highest stage of all is Nafs Mutma’innah (89:27) which is when the self achieves full peace and happiness.
Our objectives is to control Nafs Ammarah that urges us to fulfill our baser instincts with no thought for the consequences and ultimately achieve the inner peace that comes Nafs Mutma’innah.


Imam Shafi has rightly said in one of his poetics verses:
“We blame time and the fault is in us,
There is no fault in time except us.”
(Diwan ash-Shafi)

Taken from ‘The Intelligent Heart, The Pure Hear’ by Dr Gohar Mushtaq (Ta Ha)

Saturday 8 October 2011

Get image from mysql database and copy to file system.

Get image (or download image) from mysql database and copy to file system.




// Performing query on database
$querySelect = " select * from products where image is not null order by image limit 1, 5000";
$selectEposResult = mysql_query($querySelect, $link) or die("Query failed to get content.$querySelect");


// Looping through data of the query
while ($line = mysql_fetch_array($selectEposResult, MYSQL_ASSOC)) {

// Other way of loop thogur results, that worked, for colum had to use $line->NAME
//while ($row = mysql_fetch_object($selectEposResult)) {

echo "
Name: " . $line['NAME'];
$imgName = "img_".$line['CODE'];


if($line['IMAGE'] == "" || $line['IMAGE'] == NULL) {

echo $filename."
NULL data";

}
else {
$filename= "/Users/nidb/xxx/$imgName.gif";

$file=fopen($filename, 'w') or die("Can't open file");


if (fwrite($file, $line['IMAGE'])) {
echo $filename."
";
$counter++;
}

fclose($file);
}

}

?>

Friday 7 October 2011

Secure DB network config

Secure db settings

listener.ora

# listener.ora Network Configuration File: /u01/oracle/product/10.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools (NOT, ni).

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/oracle/product/10.2.0)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = N1DB.plum)
(ORACLE_HOME = /u01/oracle/product/10.2.0)
(SID_NAME = N1DB)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 80.185.40.40)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)

SUBSCRIBE_FOR_NODE_DOWN_EVENT_LISTENER=OFF
ADMIN_RESTRICTIONS_LISTENER=ON
PASSWORDS_LISTENER=mypass


sqlnet.ora

TCP.VALIDNODE_CHECKING=YES
TCP.INVITED_NODES=(80.185.40.80,80.185.40.80)

Saturday 24 September 2011

Good mac tools
* MacKeeper http://www.mac-uninstall.com/
* Sequel Pro http://www.sequelpro.com/

Move item to differnt space
1. Hold the item then Ctrl + arrow
2. or use Fn + F8


Apache webserver on Mac OS 10.6 (stop/start)

sudo /usr/sbin/apachectl start
sudo /usr/sbin/apachectl stop
sudo /usr/sbin/apachectl restart


Common change for php
Search and change (vi /etc/php.ini) From:
; short_open_tag = Off

To:
short_open_tag = On

Wednesday 14 September 2011

Size of blob

select sum(dbms_lob.getlength(IMAGE_BLOB))/1024/1024 from MY_TAB_WITH_IMAGE

Fie size in octal

stat -c '%A %a %n' *

Wednesday 17 August 2011

Oracle silent install

To record a response file:

/home/oracle/runInstaller -record -destinationFile response_filename

/home/oracle/runInstaller -record -destinationFile /tmp/response_10g_ni.rsp


When Oracle Installer displays the Summary screen, perform:

* Click Install to create the response file, then continue with the installation.

* Click Cancel and then Yes to create the response file or it will just exit (and create the file).

Tuesday 2 August 2011

Log Miner

Log miner, example code.
For prouction, I logmine and quickly make a copy of content and then stop logmining to minimize any impact on live.

[18 Apr 2013: Performed similar on live database, worked fine.]

[1 Aug 2011: Performed this on a restored prod database, worked fine. (was not open, open resetlog will allow you to mine)]


You need enable supplemental logging before generating log files that will be analyzed by LogMiner.

select SUPPLEMENTAL_LOG_DATA_MIN from V$DATABASE;
 

-- On live took around 4 - 6 minutes (depends on db)
alter database add SUPPLEMENTAL LOG DATA;



Specify Redo/Archive Log Files for Analysis (first line different)

EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149910_698844939.arc', options => DBMS_LOGMNR.NEW);

EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149911_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149912_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149913_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149914_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149915_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149916_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149917_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149918_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149919_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149920_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149921_698844939.arc', options => DBMS_LOGMNR.ADDFILE);
EXEC DBMS_LOGMNR.ADD_LOGFILE(logfilename => '/u11/oracle/arch_PRDB1/1_149922_698844939.arc', options => DBMS_LOGMNR.ADDFILE);


Then start Log Miner

EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);



Copy the content of Log Miner in a fixed table

create table ni_copy_logminer tablespace USERS as select * from V$LOGMNR_CONTENTS;
SELECT username AS USR, (XIDUSN || '.' || XIDSLT || '.' || XIDSQN) AS XID,SQL_REDO, SQL_UNDO FROM ni_copy_logminer WHERE username IN ('NISLAM_PROD');

SELECT username AS USR, (XIDUSN || '.' || XIDSLT || '.' || XIDSQN) AS XID,SQL_REDO, SQL_UNDO
FROM ni_copy_logminer


To properly end a LogMiner session

EXECUTE DBMS_LOGMNR.END_LOGMNR;


Disabling Supplemental Logging

ALTER DATABASE DROP SUPPLEMENTAL LOG DATA;



Examine the fixed log mining table e.g.

select SEG_OWNER, count(*) from ni_copy_logminer group by SEG_OWNER;

Friday 22 July 2011

Track DML statements and Monitoring DML

Check number of archive per hour

col day format a15;
col hour format a4;
col total format 999;

select
to_char(first_time,'yyyy-mm-dd') day,
to_char(first_time,'hh24') hour,
count(*) total
from
v$log_history
group by
to_char(first_time,'yyyy-mm-dd'),to_char(first_time,'hh24')
order by
to_char(first_time,'yyyy-mm-dd'),to_char(first_time,'hh24')
asc;


Clean up and create a monitoring table, check no triggers with name TRG_%

drop table log_dml;
purge recyclebin;

CREATE TABLE log_dml (dml_time timestamp, username varchar2(32), sid number, information varchar2(64));

select count(*) from user_triggers where trigger_name like 'TRG_%';


Create triggers for every table.

DECLARE
CURSOR all_tables
IS
SELECT object_name, object_id, object_type
FROM user_objects WHERE object_type = 'TABLE'
AND object_name not like 'LOG_DML';

BEGIN
FOR rec_cur IN all_tables
LOOP
EXECUTE IMMEDIATE 'create or replace trigger trg_'
|| rec_cur.object_id
|| ' before insert or update or delete on '
|| rec_cur.object_name
|| '
declare
begin
if UPDATING then
insert into log_dml values(sysdate, sys_context(''USERENV'',''CURRENT_SCHEMA''), sys_context(''USERENV'',''SID''), ''UPDATING on '||rec_cur.object_name||''');
elsif DELETING then
insert into log_dml values(sysdate, sys_context(''USERENV'',''CURRENT_SCHEMA''), sys_context(''USERENV'',''SID''), ''DELETING on '||rec_cur.object_name||''');
elsIF INSERTING then
insert into log_dml values(sysdate, sys_context(''USERENV'',''CURRENT_SCHEMA''), sys_context(''USERENV'',''SID''), ''INSERTING on '||rec_cur.object_name||''');
end if;
end;';
END LOOP;
END;
/


To check and remove the triggers.

select count(*) from user_triggers where trigger_name like 'TRG_%';

DECLARE
CURSOR all_triggers
IS
SELECT trigger_name
FROM user_triggers WHERE trigger_name like 'TRG_%';
BEGIN
FOR rec_cur IN all_triggers
LOOP
EXECUTE IMMEDIATE 'drop trigger '|| rec_cur.trigger_name ||'';
END LOOP;
END;
/

Wednesday 29 June 2011

block corrupted

1: java.sql.SQLException: ORA-01578: ORACLE data block corrupted (file # 10, block # 377287)
ORA-01110: data file 10: '/u21/oracle/oradata/P1AR/P1AR_INDX_02.dbf'


SELECT segment_type, owner||'.'||segment_name
FROM dba_extents
WHERE file_id = 10 AND 377287 BETWEEN block_id
AND block_id+blocks -1;

Tuesday 24 May 2011

Oracle 11g

Effective Tuning Goal
- Specific
- Measurable
- Achiveable
- Cost effective

Goals are also derived from related Service Level Agrements.

Key v$ views
============
V$sysstat
v$sesstat
v$system_event
v$session_event
v$session

5.2 Overview of the Automatic Workload Repository
=================================================
The Automatic Workload Repository (AWR) collects, processes, and maintains performance statistics for problem detection and self-tuning purposes. This data is both in memory and stored in the database. The gathered data can be displayed in both reports and views.

6.2 Automatic Database Diagnostic Monitor
=========================================
The Automatic Database Diagnostic Monitor (ADDM) provides a holistic tuning solution. ADDM analysis can be performed over any time period defined by a pair of AWR snapshots taken on a particular instance. Analysis is performed top down, first identifying symptoms and then refining them to reach the root causes of performance problems.


Unit 7
Automated Maintenance Tasks
===========================
In 11g auto stats gathering is more flexiable, allows you to change the % of staleness or auto etc.

Friday 4 March 2011

Javascript on keypress


[script language="javascript"]

function myCharKey(e) {

var e=window.event || e
var keyunicode=e.charCode || e.keyCode

//Allow alphabetical keys, plus BACKSPACE and SPACE
return (keyunicode>=65 && keyunicode<=122 || keyunicode==8 || keyunicode==32)? true : false
}

[/script]


[input type="text" name="myName" size="25" onkeypress="return myCharKey(event);" ]



Number only


var e=window.event || e;
var keyunicode=e.charCode || e.keyCode;

//Allow alphabetical keys, plus BACKSPACE and SPACE
//return (keyunicode>=48 && keyunicode<=57 || keyunicode==46)? true : false;

if((keyunicode>=48 && keyunicode<=57) || keyunicode==46 || keyunicode==8 || keyunicode==32){

var numIs = document.changeProfile.myName.value;

if((keyunicode>=48 && keyunicode<=57) || keyunicode==46){
numIs = numIs + String.fromCharCode(keyunicode);
}

alert(numIs);

return true;
}
else {
return false;
}

Tuesday 8 February 2011

Php MySQL images from db

Copy paste the below on a .php file, e.g. viewImg.php

Good site: http://www.phpriot.com/articles/images-in-mysql/7


$itemId = (ISSET($_GET["iid"])) ? $_GET["iid"] : "-99";

// just so we know it is broken
error_reporting(E_ALL);

// some basic sanity checks

$querySelect = " SELECT image from products where id = '$itemId' ";

// the result of the query
$result = mysql_query("$querySelect") or die("Invalid query: " . mysql_error());

// set the header for the image
header("Content-type: image/jpeg");
echo mysql_result($result, 0);
?>


If you want image as part of another page, use blow line of code, which calls the above:


Wednesday 26 January 2011

Android dev

Setup guide:

http://theunlockr.com/2011/01/03/android-application-development-101-getting-setup/

Live Wallpaper

Android Live Wallpaper

http://developer.android.com/resources/samples/CubeLiveWallpaper/src/com/example/android/livecubes/cube1/CubeWallpaper1.html

Thursday 20 January 2011

أَخَذَ ٱللَّهُ مِيثَ

أَخَذَ ٱللَّهُ مِيثَ

أَخَذَ ٱللَّهُ مِيثَ

أَخَذَ ٱللَّهُ مِيثَ

MySQL windows


set tt=%date%_%Time%
set bb=db_backup_%tt:~6,4%_%tt:~3,2%_%tt:~0,2%_%tt:~11,2%%tt:~14,2%.dmp
set bb=%bb: =0%

REM Note: ren is the rename command for DOS
ren test.dmp %bb%


C:\mysql\bin\mysqldump -u root -p'' nidb_test > c:\%bb%



Ref:
dos command
http://www.dostips.com/DtTipsStringManipulation.php