2013年12月31日 星期二
Big Endian vs Little Endian
Data stores in memory split in Bytes
Big Endian stores Most significant byte First
2013年12月2日 星期一
PHP uninitialized variable evaluation
php > $user;
php > print var_dump(!$user);
PHP Notice: Undefined variable: user in php shell code on line 1
bool(true)
php > print var_dump($user);
PHP Notice: Undefined variable: user in php shell code on line 1
NULL
php > print var_dump(empty($user));
bool(true)
uninialized variable evaluates to NULL (with notice)
!$var evaluates to True
empty($var) evaluates to True
empty($var) evaluates to True
2013年11月27日 星期三
Python String Encoding Conversion (UTF-8/ANSI)
**Python String are recorded in UNICODE internally
Reading file encoded in UTF-8:
Reading file encoded in UTF-8:
with open(fileName,'r') as f:
for line in f.readlines():
print line.decode("UTF-8")
2013年9月12日 星期四
Bind bash keyboard shortcut to delete word to slash
add the following line in ~/.bashrc
bind '\C-f:unix-filename-rubout'
Ctrl+F is bound to delete till previous slash
2013年8月14日 星期三
2013年7月23日 星期二
bash_profile vs bashrc vs profile, environment variables
.bash_profile
--> login shell.bashrc
--> non-login shelllogin shell:
e.g. login via console, ssh
non-login shell:
e.g. new terminal windows in inside GNOME ( already logged in)
/bin/bash in terminal
When bash is invoked as an interactive login shell, or as a non-interac-
tive shell with the --login option, it first reads and executes commands
from the file /etc/profile, if that file exists. After reading that file,
it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
order, and reads and executes commands from the first one that exists and
is readable. The --noprofile option may be used when the shell is started
to inhibit this behavior.
/etc/profile --> ~/.bash_profile > ~/.bash_login > ~/.profile
Environment Variable
/etc/environment
- This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.
set
-- show environment variables + shell variablesenv
-- show environment variables2013年7月15日 星期一
CodeIgniter .htaccess mod_rewrite 404
CodeIgniter directory: /Document-root/[your-URL-path]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /[your-URL-path]
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php/$1 [L]
`---!! No heading slash
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /[your-URL-path]
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php/$1 [L]
`---!! No heading slash
</IfModule>
2013年7月12日 星期五
Javascript Prototype Chain / Inheritance
*Every Object has an internal link to another object called prototype
Creating an object:
Javascript Core Object ref:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Predefined_Core_Objects
Javascript Core Object ref:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Predefined_Core_Objects
syntax
constructs:
var
o = {a: 1};
//o ---> Object.prototype ---> null
var
a = ["yo", "whadup", "?"];
//a ---> Array.prototype ---> Object.prototype ---> null
function f(){
return 2;
}
//f ---> Function.prototype --->
Object.prototype ---> null
Constructor:
function Graph() {
this.vertexes = [];
this.edges = [];
}
Graph.prototype = {
addVertex: function(v){
this.vertexes.push(v);
}
};
var g = new Graph();
//Graph ---> Graph.prototype --->
Object.prototype
var a = {a: 1};
var b = Object.create(a);
// b ---> a ---> Object.prototype
---> null
var c = Object.create(b);
// c ---> b ---> a --->
Object.prototype ---> null
var d = Object.create(null);
// d ---> null
2013年7月7日 星期日
LINUX SYSTEM INITIALIZATION
DEBIAN
1.BIOS|--- POST (Power On Self Test)
`--- Load initial code (bootloader code/kernel code...etc) form DISK
2.Bootloader (Bootstrap Loader)
`--- load system kernel image and initrd image, hands over control
`-- Linux kernel `---- initramfs
* initrd : image of temporary root file system loaded into memory
do hardware detection,module loading, mnt root file sys
3. initrd (mini-Debian System (Started by bootloader))
`----- /init is executed
4. Debian-System
|----- 0. /sbin/init (init(8)) is executed
| |--- parent of all processes
| `--- create process from script /etc/inittab
|----- 1. System goes into runlevel N(none) by following /etc/inittab
|----- 2. System goes into runlevel S for initialization
`----- 3. System goes into runlevel 2-5(multi-user))(determined by /etc/inittab)
`-- rc.local is executed at the end of each multiuser runlevel
A Bootable Linux Image
2013年7月4日 星期四
BASIC APACHE
APACHE 2 ON **DEAIBN
# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf.d
# | `-- *
# `-- sites-enabled
# `-- *
**Struture of config in Debian is different from other linux dist.
** apache2.conf is the main config file
it includes other files (mods-enabled/*, conf.d/*, sites-enabled,ports.conf)
** ports.conf
ports to listen to
Directives: Timeout, Keepalive,AccessFileName ........
Configuration Section Containers:
|
|---evaluted each request : <VirtualHost> <Directory>....
| |
| |--Filesystem cotainer:<Directory> <Files>.....
| |
| `--Webspace Container: <Location>......
|
`---evaluated at startup: <IfDefine> <IfModule> ....
Directives Scoping: Limit the scope of effect of directives(w/SectionContainer)
.htaccess: Placed in DocumentDirectory, use directives to immediately affect access
Administrator can limit directives in .htaccess by AllowOverride Directive
Listen 8080 <--Listen directive should be placed here or in port.conf
Listen 9090
# /etc/apache2/
# |-- apache2.conf# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf.d
# | `-- *
# `-- sites-enabled
# `-- *
**Struture of config in Debian is different from other linux dist.
** apache2.conf is the main config file
it includes other files (mods-enabled/*, conf.d/*, sites-enabled,ports.conf)
** ports.conf
ports to listen to
Directives: Timeout, Keepalive,AccessFileName ........
Configuration Section Containers:
|
|---evaluted each request : <VirtualHost> <Directory>....
| |
| |--Filesystem cotainer:<Directory> <Files>.....
| |
| `--Webspace Container: <Location>......
|
`---evaluated at startup: <IfDefine> <IfModule> ....
Directives Scoping: Limit the scope of effect of directives(w/SectionContainer)
.htaccess: Placed in DocumentDirectory, use directives to immediately affect access
Administrator can limit directives in .htaccess by AllowOverride Directive
Virtual Hosting
How apache selects virtual to respond to request
1. Find best matching <VirtualHost> based on IP addr
2. More than 1 match--> compare ServerName and ServerAlias
3. No match found --> handled by global server config
#sites-available/000-example
How apache selects virtual to respond to request
1. Find best matching <VirtualHost> based on IP addr
2. More than 1 match--> compare ServerName and ServerAlias
3. No match found --> handled by global server config
#sites-available/000-example
<VirtualHost *:80>
`--- Placing IP rather than DN in this directive
ServerName www.example.org ß FQDN of server
`--- Placing IP rather than DN in this directive
ServerName www.example.org ß FQDN of server
ServerAdmin webmaster@localhost ß admin mail
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml
`--- index files to look for
DocumentRoot /var/www ß root directory of site
Alias /mydoc /var/local/lib/mydata
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
`----Additional option for Directory
AllowOverride None
`----.htaccess (Only available under Directory)
Order allow,deny
allow from all
|----.Search allow first, then deny, deny overwrites allow
`----Rule not found --> deny
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <--CGI Scripts location
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
|------ExecCGI à CGI script
|------MultiViews HTTP1.1 content negotiation
`------SymLinksIfOwnerMatch stricter symlink follow
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName other.example.com ßanother virtual host
ServerAlias other.example.com *.other.example.com
`--another way is set ServerAlias
DocumentRoot /www/otherdomain
</VirtualHost>
<VirtualHost _default_:80> <--catching request not matching any vhost
DocumentRoot /www/default
</VirtualHost>
Listen 8080 <--Listen directive should be placed here or in port.conf
Listen 9090
<VirtualHost *:8080 *:9090>
DocumentRoot /www/default
</VirtualHost>
UserDir Module
Mods-available/userdir.conf
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
</Directory>
</IfModule>
CGI Dynamic Content w/ PHP,Python,Perl
$apt-get install libapache2-mod-[php,perl,python]
.htaccess
.htaccess
*place directives
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Option +Indexes –FollowSymLinks
IndexOptions +FancyIndexing
IndexIgnore *.php *.exe
*Rewirte Request URL (Requires mod_rewrite and override allowed)
.htaccess
RewriteEngine on
RewriteBase /myApp <---- base URL for per-directory rewrites
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
`----only rewrite when HOST matches(NC flag = no case)
RewriteBase /myApp <---- base URL for per-directory rewrites
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
`----only rewrite when HOST matches(NC flag = no case)
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/?(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R,NE]
|----
|---- (flag: L -> Stop the rewriting process immediately and don't apply any more rules)
|---- (flag: R -> Forces an external redirect)
|----
$N
(0 <= N <= 9) -> back references|---- (flag: L -> Stop the rewriting process immediately and don't apply any more rules)
|---- (flag: R -> Forces an external redirect)
`----( flag: NE: noescap -> especial characters, such as
&
and ?
, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.)2013年7月3日 星期三
SQL
login
SELECT DATABASE
CREATING USERS/ GRANTING ACCESS TO DATABASE
Create new table:
Insert if not entry not existent or do nothing if entry is duplicate
Search for duplicate:
SELECT * FROM all_papers WHERE title IN(SELECT title FROM all_papers WHERE title NOT LIKE '%unavailable%' GROUP BY (title) HAVING COUNT( title ) >1)
PHP with SQL
$USER = [username];
$PASS = [password];
try {
$dsn = "mysql:dbname=$DBNAME;host=$HOST";
$dbh = new PDO($dsn, $USER, $PASS);
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage();
die();
}
$TABLE = [tablename];
$sql = "SELECT * FROM $TABLE";
foreach (self::$dbh->query($sql) as $row) {
.
.
.
}
use
mysql -hlocalhost -u[username] -p[password]
SELECT DATABASE
use [database]
CREATING USERS/ GRANTING ACCESS TO DATABASE
Create new table:
CREATE table [table name](
id int NOT NULL PRIMARY KEY,
title varchar(255) UNIQUE
.
.
.
);
**NOT NULL
**PRIMARY KEY
**UNIQUE
Insert if not entry not existent or do nothing if entry is duplicate
INSERT INTO table(c1,c2)VALUES(v1,v2) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)
Search for duplicate:
SELECT address, count(id) as cnt FROM list
GROUP BY address HAVING cnt > 1
SELECT * FROM all_papers WHERE title IN(SELECT title FROM all_papers WHERE title NOT LIKE '%unavailable%' GROUP BY (title) HAVING COUNT( title ) >1)
PHP with SQL
$USER = [username];
$PASS = [password];
try {
$dsn = "mysql:dbname=$DBNAME;host=$HOST";
$dbh = new PDO($dsn, $USER, $PASS);
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage();
die();
}
$TABLE = [tablename];
$sql = "SELECT * FROM $TABLE";
foreach (self::$dbh->query($sql) as $row) {
.
.
.
}
use
addslashes
to process string before INSERT
2013年4月21日 星期日
NFS
NFS user permissions are based on user ID (UID)
a user's access to files is determined by his/her membership of groups on the client, not on the server
nfs-common
rpcbind
a user's access to files is determined by his/her membership of groups on the client, not on the server
Server Side
Packages
nfs-kernel-servernfs-common
rpcbind
Server Install
apt-get install nfs-kernel-server
NFS Config
Config NFS exports so clients can mount the NFS drive
/etc/export
/home/ 192.168.100.0/24(rw,sync)
tips: Reload export config without restart NFS server
exportfs -a
restart services
/etc/init.d/rpcbind restart
/etc/init.d/nfs-kernel-server restart
Check local NFS config
showmount -e localhost
Client Side
Using autofs to mount NFS drive automatically
apt-get install autofs
File /etc/auto.master
/nfs /etc/auto.nfs
File /etc/auto.nfs
home -rw,fg,soft [IP of NFS server]:/[directory]
Mount with command manually
# mount -t nfs -o proto=tcp,port=2049 nfs-server:/ /mnt
Utililies
showmount
2013年3月26日 星期二
LDAP-NSS-PAM
LDAP
Everything is identified by dn
cn= Common Name
ou= Organizational Unit
dc= Domain Component
Schemas, objectClasses and Attributes
An objectClass is a collection of attributess:
Config Layout
**note:olcrootPW generated by
(which includes utilities too add/remove POSIX accounts)
modify /etc/ldapscripts/ldapscripts.conf
keep the rootPW in /etc/ldapscripts/ldapscripts.passwd
/etc/libnss-ldap.conf
add users and groups
update pam auth
auto create home directory
/etc/pam.d/common-account
Allow user change password
vim /etc/pam.d/common-password
Everything is identified by dn
cn= Common Name
ou= Organizational Unit
dc= Domain Component
Schemas, objectClasses and Attributes
An objectClass is a collection of attributess:
- An objectclass is defined within a Schema
- An objectclass may be a part of an objectclass hierarchy, in which case it inherits all the properties of its parents.
- An objectclass has a globally unique name or identifier
Attributes typically contain data:
- Every attribute is defined in a schema.
- Every attribute is included in one or moreobjectclasses.
- To use an attribute in an entry, itsobjectclass must be included in the entry definition and its objectclass must be included in a schema. In turn, the schema must be identified to the LDAP server.
Install LDAP
apt-get install slapd ldap-utils ldapvi
Config Layout
Setup backend database
Import schemas
$ cd /etc/ldap/schema
$ ldapadd -Y EXTERNAL -H ldapi:/// -f cosine.ldif
$ ldapadd -Y EXTERNAL -H ldapi:/// -f nis.ldif
(Provides linux account attributes)
$ ldapadd -Y EXTERNAL -H ldapi:/// -f inetorgperson.ldif
backend.ldif
# Load dynamic backend modules
dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulepath: /usr/lib/ldap
olcModuleload: back_hdb.la
# Database Setting
dn: olcDatabase={1}hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {1}hdb
olcSuffix: dc=[ID],dc=csie,dc=ntu,dc=edu,dc=tw
olcDbDirectory: /var/lib/ldap
olcRootDN: cn=admin,dc=[ID],dc=csie,dc=ntu,dc=edu,dc=tw
olcRootPW: {SSHA}HUpwPlcpSOwCNd8hRfiQsXFYYdyPewC2**
olcDbConfig: set_cachesize 0 2097152 0
olcDbConfig: set_lk_max_objects 1500
olcDbConfig: set_lk_max_locks 1500
olcDbConfig: set_lk_max_lockers 1500
olcDbIndex: objectClass eq
olcLastMod: TRUE
olcDbCheckpoint: 512 30
olcAccess: to attrs=userPassword,shadowLastChange
by dn="cn=admin,dc=[ID],dc=csie,dc=ntu,dc=edu,dc=tw" write
by anonymous auth
by self write
by * none
olcAccess: to attrs=homeDirectory
by dn="cn=admin,dc=[ID],dc=csie,dc=ntu,dc=edu,dc=tw" write
by anonymous auth
by self read
by * none
olcAccess: to dn.base=""
by * read
olcAccess: to *
by dn="cn=admin,dc=fate,dc=csie,dc=ntu,dc=edu,dc=tw" write
by * read
**note:olcrootPW generated by
slappasswd
import backend
ldapadd -v -Y EXTERNAL -H ldapi:/// -f backend.ldif
FRONTEND: Adding users and groups (by ldapscripts or frontend.ldif file)
for /etc/passwd
objectClass: posixAccount
id uid
password userPassword
uid uidNumber
gid gidNumber
full_name gecos
Home Directory homeDirectory
Login shell loginShell
for /etc/shadow
objectClass: shadowAccount
username uid
password userPassword
last shadowLastChange
may shadowMin
must shadowMax
warn shadowWarning
expire shadowExpire
disable shadowInactive
reserved shadowFlag
for /etc/group
objectClass: posixGroup
group name cn
password userPassword
group id gidNumber
other account memberUid
objectClass: posixAccount | |
id | uid |
password | userPassword |
uid | uidNumber |
gid | gidNumber |
full_name | gecos |
Home Directory | homeDirectory |
Login shell | loginShell |
objectClass: shadowAccount | |
username | uid |
password | userPassword |
last | shadowLastChange |
may | shadowMin |
must | shadowMax |
warn | shadowWarning |
expire | shadowExpire |
disable | shadowInactive |
reserved | shadowFlag |
objectClass: posixGroup | |
group name | cn |
password | userPassword |
group id | gidNumber |
other account | memberUid |
option 1: Use ldapscripts to add user
install ldapscripts(which includes utilities too add/remove POSIX accounts)
apt-get isntall ldapscripts
modify /etc/ldapscripts/ldapscripts.conf
SERVER=localhost
BINDDN='cn=admin,dc=,dc=csie,dc=ntu,dc=edu,dc=tw'
SUFFIX='dc=,dc=csie,dc=ntu,dc=edu,dc=tw'
GSUFFIX='ou=Groups'
USUFFIX='ou=Peolple'
MSUFFIX='ou=machines'
GIDSTART=10000
UIDSTART=10000
MIDSTART=10000
PASSWORDGEN="pwgen" // $ apt-get install pwgen
RECORDPASSWORDS="yes"
PASSWORDFILE="/var/log/ldapscripts_passwd.log"
BINDPWDFILE="/etc/ldapscripts/ldapscripts.passwd"
keep the rootPW in /etc/ldapscripts/ldapscripts.passwd
sh -c "echo -n '[password]' > /etc/ldapscripts/ldapscripts.passwd"
chmod 400 /etc/ldapscripts/ldapscripts.passwd
**Careful: if authentication failure happens after ldapadduser. Check LDAP database for user password encryption
try dpkg-reconfigure libpam-ldap and set encryption methodOption 2: use frontend.ldif
file frontend.ldif
# Create top-level object in domain
dn: dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw
objectClass: top
objectClass: dcObject
objectclass: organization
o: b99902120
dc: b99902120
description: b99902120
#people
dn: ou=people,dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw
objectClass: organizationalUnit
ou: people
#groups
dn: ou=groups,dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw
objectClass: organizationalUnit
ou: groups
#user setting: ta217, groups, b99902120.csie.ntu.edu.tw
dn: uid=ta217,ou=people,dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: ta217
displayName: ta217
uidNumber: 1001
gidNumber: 1001
userPassword: SAL2013
gecos: ta217
loginShell: /bin/bash
homeDirectory: /home/ta217
shadowExpire: -1
shadowFlag: 0
shadowWarning: 7
shadowMin: 8
shadowMax: 999999
shadowLastChange: 10877
givenName: 217
sn: ta
cn: ta217
mail: ta217@b99902120.csie.ntu.edu.tw
title: ta217
#group setting: ta217, groups, b99902120.csie.ntu.edu.tw
dn: cn=ta217,ou=groups,dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw
objectClass: posixGroup
cn: ta217
gidNumber: 1001
import frontend file ldapadd -v -x -D -W -f frontend.ldif
nss and pam
apt-get install libpam-ldap libnss-ldap libnss-db nslcd nscd
/etc/libnss-ldap.conf
base dc="dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw"
/etc/nsswitch.conf
passwd: files ldap
group: files ldap
shadow: files ldap
add users and groups
ldapadduser [user] [group]
ldapaddgroup [group]
update pam auth
pam-auth-update
auto create home directory
/etc/pam.d/common-account
session required pam_mkhomedir.so skel=/etc/skel/ umask=0022
Allow user change password
vim /etc/pam.d/common-password
password [success=1 user_unknown=ignore default=die]
pam_ldap.so use_authtok try_first_pass
change to
password [success=1 user_unknown=ignore default=die]
pam_ldap.so try_first_pass
client config
/etc/nslcd.conf
# The user and group nslcd should run as.
uid nslcd
gid nslcd
# The location at which the LDAP server(s) should be reachable.
uri ldap://192.168.50.119
# The search base that will be used for all queries.
base dc=b99902120,dc=csie,dc=ntu,dc=edu,dc=tw
/etc/nsswitch.conf
passwd: files ldap
group: files ldap
shadow: files ldap
2013年3月18日 星期一
iptables / DHCP / network interface
Interface config
/etc/network/interfacesauto eth0
iface eth0 inet static
address [IP]
netmask [mask]
gateway [gateway(if have one)]
DHCP
Package: DHCP3-serverSelect interface for DHCP server
/etc/default/dhcp3-serverINTERFACES="[interface_name]"
DHCP pools
dhcpd.confoption domain-name "[optional domain-name]"
option domain-name-servers [DNS server IP]
e.g.
subnet 192.168.0.0 netmask 255.255.255.0{
range 192.168.0.1 192.168.0.253;
option routers 192.168.0.254;
option broadcast-address 192.168.0.255;
}
iptables / NAT
#enable ip forwardingsysctl -w net.ipv4.ip_forward=1#flush tablesiptables -F -t natiptables -F INPUTiptables -F OUTPUTiptables -F FORWARDiptables -P INPUT ACCEPTiptables -P OUTPUT ACCEPTiptables -P FORWARD DROP#NATiptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE#firewalliptables -A FORWARD -p icmp -j ACCEPTiptables -A FORWARD -p udp --sport 53 -j ACCEPTiptables -A FORWARD -p udp --dport 53 -j ACCEPTiptables -A FORWARD -p tcp --sport 80 -j ACCEPTiptables -A FORWARD -p tcp --dport 80 -j ACCEPTiptables -A FORWARD -p tcp --sport 20:21 -j ACCEPTiptables -A FORWARD -p tcp --dport 20:21 -j ACCEPTiptables -A FORWARD -p tcp --sport 23 -j ACCEPTiptables -A FORWARD -p tcp --dport 23 -j ACCEPTiptables -A FORWARD -p tcp --sport 110 -j ACCEPTiptables -A FORWARD -p tcp --dport 110 -j ACCEPTiptables -A FORWARD -p tcp --sport 25 -j ACCEPTiptables -A FORWARD -p tcp --dport 25 -j ACCEPTiptables -A FORWARD -p tcp --sport 995 -j ACCEPTiptables -A FORWARD -p tcp --dport 995 -j ACCEPT
2013年3月1日 星期五
warning: setlocale LC_ALL
What is LC_ALL:
LC_ALL
is the environment variable that overrides all the other localisation settings
The value 'LC_ALL=C' is essentially an English-only environment that specifies the ANSI C locale.
You'll typically set $LANG
to your preference. The individual LC_xxx
variables override a certain aspect. LC_ALL
overrides them all. The locale
command, when called without argument gives a summary of the current settings.
LC_* var priority
LC_ALL
> LC_*
> LANG
LC_ALL
> LC_*
> LANG
locale def file:
/usr/share/i18n/locales
vi /etc/default/locale
LANG
& LANGUAGE
LANG
: specifies the default locale for all unset locale variables LANGUAGE
: most programs use this for the language of its interface warning: setlocale LC_ALL solution
export LC_ALL="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"
2013年2月28日 星期四
KVM-VIRSH
Create a domain
sudo virt-install \--name [KVM NAME] \
--ram=2048 \
--disk [DRIVE(LVM) IMAGE PATH]\
--network [bridge=[bridged interface]] \
--nographics \ #console only
--location=http://debian.csie.ntu.edu.tw/debian/dists/testing/main/installer-amd64/ \ #installer location
--extra-args "console=tty0 console=ttyS0,115200nn8" #extra kernel args, attaching console to VM
Delete a domain
sudo virsh undefine [KVM NAME]
Connect to local VM
virsh list --all
virsh console [VM domain name]
dump config to xml
virsh dumpxml [VM guest name]
error: operation failed: Active console session exists for this domain
virsh console --force [VM domain name]
2013年2月22日 星期五
Git Basics
Settings:
git config --global user.name "username"git config --global user.email "email"
*to check --> git config --list
*config file : ~/.gitconfig
initial:
ssh-keygen -C "username@email.com" -t rsa* Generate files to .ssh/, public key paste to Github setting
Initialize A Repo:
mkdircd
touch README
git add README
git commit -m 'first commit'
Clone A Repo:
git clone [url] [Target Directory]Staging/Tracking:
git add
Status:
git status
git diff --> changed but not staged
git diff --cache --> staged
git status -s (-s --> short)
(
? ? : untracked
A : new
M : Modified but not added
M : Modified and added
MM : Modified again after added
D : deleted project file
)
Commit:
git commit -m "[comment]"
git commit -a --> stage everyfile tracked
git commit --amend --> amend a previeous commmit
Ignore files:
.gitignore
Remove File:
git rm
git rm --cached [file] --> remove from staging area
Move File:
git mv [file_from] [file_to]
Commit History:
git log
git log -p --> show diff
git log -2 --> last 2 commit
git log --stat --> brief
git log --pretty --> foramtting
git log --graph --> branch & merge history
Unmodify:
git checkout -- [file]
Remote:
A remote-->
repo stored in other computer
origin --> default remote name
git
remote -v --> show remote URLs(for the repo)
git
remote add [remote-name] [repo URL]
git fetch [remote-name] --> fetch from remote
git pull [remote-name] --> fetch and merge from remote
git push [remote-name]
[local-branch-name] --> push to remote
git remote show
[remote-name]
git
remote rename [old-name] [new-name]
git remote rm [remote-name]
git tag:
git tag --> show tag in cur.
repo
git tag -a [tag] -m [comment] -->
annot. tag
git tag -s --> signed tag
git alias:
git config --global alias.[alias] '[command]'
Creating new repo for sync w/ github:
*create repo at
github first
*Push to the remote repo
e.g.:
git remote add [remote-name] https://github.com/[username]/[githubrepo] ([remote-name] is user defined)
git commit -m "first commit"
git push -u [remote-name] master
訂閱:
文章 (Atom)