GPG Basic Tasks 
//encrypting a message
gpg -r "destination_email@example.net" --encrypt --armor
"message"
enter+ctrl+d

//decrypting a message
gpg --decrypt
"armored message"
ctrl+d

//importing public/private keys
gpg --import "key-name"

//listing keys
gpg -k
gpg -K

//create new key pair
gpg --gen-key


[acool@localhost ~]$ date
Fri Apr 12 12:44:41 PM PDT 2024
[acool@localhost ~]$
[acool@localhost ~]$ gpg --list-keys
...


[ view entry ] ( 1814 views )   |  print article
MySQL SSL Setup 
//Server and client "Common Name" in certificates must be different than CA's :
http://stackoverflow.com/questions/2045 ... 4#23599624

1.- generate CA key and certificate(2 commands create 2 files)
openssl genrsa 2048 >ca.key //creates ca.key
openssl req -new -x509 -nodes -days 3600 -key 'ca.key' > 'ca.crt' //creates certificate


2.- generate server key and signed certificate(2 commands create 3 files)
openssl req -newkey rsa:2048 -days 3600 -nodes -keyout 'server.key' > server.csr' //create key and csr
openssl x509 -req -in 'server.csr' -days 3600 -CA 'ca.crt' -CAkey 'ca.key' -set_serial 01 > 'server.crt' //creates certificate


3.- generate client key and certificate (2 commands create 3 files)
openssl req -newkey rsa:2048 -days 3600 -nodes -keyout 'client.key' > 'client.csr' //creates key and csr
openssl x509 -req -in 'client.csr' -days 3600 -CA 'ca.crt' -CAkey 'ca.key' -set_serial 01 > 'client.crt'


4.- create SSL user:
GRANT ALL PRIVILEGES ON *.* TO 'ssluser'@'%' IDENTIFIED BY 'secret-passwd' REQUIRE SSL;


5.- update my.cnf

[mysqld]
ssl-ca = "ca.crt"
ssl-cert = "server.crt"
ssl-key = "server.key"

[client]
ssl-ca=ca.crt
ssl-cert=client.crt
ssl-key=client.key



//MySQL workbench, use: ca.key, client.crt and client.key without password:
openssl rsa -in client.key -out client-nopasswd.key


[ view entry ] ( 7225 views )   |  print article
Nginx: Setting Up HTTP authentication 
Prompting users for a password before accessing a page.

Place the following two entries in nginx configuration file:

auth_basic "Restricted";                                
auth_basic_user_file /var/www/mywebsite.com/.htpasswd;

Eg:
  location / {
root /var/www/mywebsite.com;
index index.html index.htm;
auth_basic "Restricted"; #For Basic Auth
auth_basic_user_file /var/www/mywebsite.com/.htpasswd; #For Basic Auth
}


The .htpasswd must contain:
username:password

Generate the password with this command:
[root@IBM ~]#printf "USERNAME:$(openssl passwd -crypt PASSWORD)\n" >> htpasswd


[ view entry ] ( 1255 views )   |  print article
ASA (8.0): Natting inside hosts using outside interface (NAT overload in router lingo) 
All hosts in 192.168.1.0/24 will be seen with source 172.16.1.192 in the internet. May also be known as PAT.
interface Ethernet0
nameif outside
security-level 0
ip address 172.16.1.192 255.255.255.0

interface Ethernet1
nameif inside
security-level 100
ip address 192.168.1.1 255.255.255.0

global (outside) 1 interface
nat (inside) 1 192.168.1.0 255.255.255.0

//bonus: configure dns client in asa
dns domain-lookup outside
dns server-group DefaultDNS
name-server 8.8.8.8


[ view entry ] ( 1308 views )   |  print article
Minicom: Connecting to Cisco router console port 
1)yum install minicom

2)dmesg|grep ttyp //see what serial ports are available

2)minicom -s //configuration mode

3)select "Serial port setup" option

4)select "A" and enter desired serial port

5)select "E" and specify "C" and "Q" options (9600 8N1)

6)make sure "F" is YES and "G" is NO (hardware flow control only),on previous screen

7)save setup as CISCO

8)run it: [root@localhost ~]# minicom CISCO

======================================================================
2/2016

For step 2 /dev/ttyS0 worked (that's a zero), and NO Hardware Flow control made pressing enter work, restarted AP and I notice messages were appearing on screen, but hitting enter will not have any results, changing Hardware Flow Control to NO fixed it.

/dev/ttyUSB0 also worked :)

[ view entry ] ( 1269 views )   |  print article
Slicing a Javascript array. 
array=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r'];
console.log(array.slice(0,3));
console.log(array.slice(3,6));
console.log(array.slice(6,9));
console.log(array.slice(9,12));

The above outputs:
["a", "b", "c"]
["d", "e", "f"]
["g", "h", "i"]
["j", "k", "l"]


Same output with PHP:
$input = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r');
print_r(array_slice($input,0,3));
print_r(array_slice($input,3,3));
print_r(array_slice($input,6,3));
print_r(array_slice($input,9,3));

//output

Array
(
[0] => a
[1] => b
[2] => c
)
Array
(
[0] => d
[1] => e
[2] => f
)
Array
(
[0] => g
[1] => h
[2] => i
)
Array
(
[0] => j
[1] => k
[2] => l
)




Misc stuff,

js:
array=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r'];

var Page=1;//page to display
var itemsPage=3;//items per page

var totalItems=array.length;
var totalPages=Math.ceil(totalItems/itemsPage);
var a=(Page-1)*itemsPage;
var b=a+itemsPage;
console.log(array.slice(a,b));//items


js:printing links. TESTED OK!
function coolpaging(item_count, limit, curpage, span)
{
let cur_page = Number(curpage);
let page_count = Math.ceil(item_count/limit);
let current_range = [((cur_page-span) < 1 ? 1 : cur_page-span), ((cur_page+span) > page_count ? page_count : cur_page+span)];

// First and Last pages
let first_page = (cur_page > (span+1)) ? '<a href="' + '1' + '">1</a>' + ((cur_page < (span+3) )? ', ' : ' ... ') : '';
let last_page = (cur_page < (page_count-span)) ? (cur_page > (page_count-(span+2)) ? ', ' : ' ... ') + '<a href="'+ page_count + '">'+page_count+'</a>' : '';

// Previous and next page
let previous_page = (cur_page > 1) ? '<a href="'+ (cur_page-1)+'">Previous</a> | ' : '';
let next_page = (cur_page < page_count) ? ' | <a href="'+ (cur_page+1)+'">Next</a>' : '';

let pages = [];

// Display pages that are in range
for (let x=current_range[0];x <= current_range[1]; ++x)
pages.push('<a href="'+ x+'">'+((x == cur_page) ? '<strong>'+x+'</strong>' : x)+'</a>');

if (page_count > 1)
return '<p class="entpagination">'+ previous_page+first_page+ pages.join(",")+last_page+next_page+'</p>';

return '';
}


php:
$array=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s');

$Page=2;//page to display
$itemsPage=3;//items per page

$totalItems=sizeof($array);
$totalPages=ceil($totalItems/$itemsPage);
$a=($Page-1)*$itemsPage;
var_dump(array_slice($array,$a,$itemsPage));//items

//printing links
function paginationLinks($item_count, $limit, $cur_page, $link,$span)
{
$page_count = ceil($item_count/$limit);
$current_range = array(($cur_page-$span < 1 ? 1 : $cur_page-$span), ($cur_page+$span > $page_count ? $page_count : $cur_page+$span));

// First and Last pages
$first_page = $cur_page > ($span+1) ? '<a href="'.sprintf($link, '1').'">1</a>'.($cur_page < ($span+3) ? ', ' : ' ... ') : null;
$last_page = $cur_page < $page_count-$span ? ($cur_page > $page_count-($span+2) ? ', ' : ' ... ').'<a href="'.sprintf($link, $page_count).'">'.$page_count.'</a>' : null;

// Previous and next page
$previous_page = $cur_page > 1 ? '<a href="'.sprintf($link, ($cur_page-1)).'">Previous</a> | ' : null;
$next_page = $cur_page < $page_count ? ' | <a href="'.sprintf($link, ($cur_page+1)).'">Next</a>' : null;

// Display pages that are in range
for ($x=$current_range[0];$x <= $current_range[1]; ++$x)
$pages[] = '<a href="'.sprintf($link, $x).'">'.($x == $cur_page ? '<strong>'.$x.'</strong>' : $x).'</a>';

if ($page_count > 1)
return '<p class="pagination"><strong>Pages:</strong> '.$previous_page.$first_page.implode(', ', $pages).$last_page.$next_page.'</p>';
}
echo paginationLinks(
400,//total amount of item/rows/whatever,
10,//limit of items per page
$_GET['p'],//current page number
'?p=%d',//url
5//items on each side of current page

);

//links function:
//http://css-tricks.com/snippets/php/pagination-function/


paginationLinks function sample output:

Pages: Previous | 1 ... 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 | Next



[ view entry ] ( 1342 views )   |  print article
jQuery - Append a Value to an INPUT, keeping it a Comma Delimited list 

$('#attachment-uuids').val(function(i,val) {
return val + (!val ? '' : ', ') + '66666';
});


as of 3/4/2014 :)
http://stackoverflow.com/questions/4339 ... mited-list

[ view entry ] ( 1219 views )   |  print article
NFS Directory Mount/Share 
Tested on centos 6.4; the process is slightly different in Fedora 20 because it uses a different approach (starting with fedora 15) to start services:

systemctl start service_name.service

[root@nfsserver ~]# yum install nfs-utils nfs-utils-lib
[root@nfsserver ~]# yum install portmap (not required with NFSv4)

//server ip:192.168.0.100
//client ip:192.168.0.101

//start service on both machines
[root@nfsserver ~]# /etc/init.d/portmap start
[root@nfsserver ~]# /etc/init.d/nfs start
[root@nfsserver ~]# chkconfig --level 35 portmap on
[root@nfsserver ~]# chkconfig --level 35 nfs on


//setting up server
[root@nfsserver ~]# mkdir /nfsshare

[root@nfsserver ~]# vi /etc/exports

/nfsshare 192.168.0.101(rw,async,no_root_squash)


//setting up the client
[root@nfsclient ~]# showmount -e 192.168.0.100

Export list for 192.168.0.100:
/nfsshare 192.168.0.101

//temporary mount:
[root@nfsclient ~]# mount -t nfs 192.168.0.100:/nfsshare /mnt/nfsshare

//permanent mount (fstab) across reboots
[root@nfsclient ~]# vi /etc/fstab

192.168.0.100:/nfsshare /mnt nfs defaults 0 0

//misc
[root@nfsclient ~]# mount | grep nfs

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.0.100:/nfsshare on /mnt type nfs (rw,addr=192.168.0.100)

//on server open ports 2049 and 111,32803,32769

/*

may have to do:
vi /etc/sysconfig/nfs

uncomment:
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892

iptables -I INPUT -m state --state NEW -p tcp \
-m multiport --dport 111,892,2049,32803 -s 192.168.0.0/24 -j ACCEPT

iptables -I INPUT -m state --state NEW -p udp \
-m multiport --dport 111,892,2049,32769 -s 192.168.0.0/24 -j ACCEPT


*/

//mount in mac (ip is server's) (...and create a new user in mac to match nfs server uid)
sudo mount -t nfs -o resvport,nolocks,locallocks,intr,soft,wsize=32768,rsize=3276,async 172.16.1.46:/usr/share/nginx .


NFS Options

Some other options we can use in “/etc/exports” file for file sharing is as follows.

ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
rw: This option allows the client server to both read and write access within the shared directory.
sync: Sync confirms requests to the shared directory only once the changes have been committed.
no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
no_root_squash: This phrase allows root to connect to the designated directory.

as of 01/2014:
http://www.tecmint.com/how-to-setup-nfs ... -in-linux/


[ view entry ] ( 1460 views )   |  print article
MySQL Backups 
//dump a database
mysqldump -u UserName -p --host=dev.barney.com db_name > db_name_backup.sql
//compressed dump
mysqldump -u UserName -p --host=dev.barney.com db_name | gzip > db_name_backup.sql


//restore database
mysql -u UserName -p target_db_name < db_name_backup.sql

//dump and restore
mysqldump -u UserName -p --host=dev.barney.com db_name | mysql -u UserName -p target_db_name



[ view entry ] ( 1251 views )   |  print article
Riak: Tasks 101 
//list all buckets
curl -i riak1.barney.com:8098/buckets?buckets=true

//putting/storing JSON in riak
curl -v -XPUT riak1.barney.com:8098/buckets/my_bucket/keys/my_test?returnbody=true \
-H "Content-Type: application/json" \
-d '{"TestName":"Monday test"}'

//listing keys in bucket
curl -i riak1.barney.com:8098/buckets/my_bucket/keys?keys=true

//fetch a key
curl -v riak1.barney.com:8098/buckets/my_bucket/keys/my_test


http://docs.basho.com/riak/latest/dev/using/basics/

[ view entry ] ( 1356 views )   |  print article

<<First <Back | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Next> Last>>


2024 By Angel Cool