Objective
1. Forbid others to browse folder in my web server
I don't know why the default configuration of the apache2 allows others to browse your directory contents. For security reasons, I am going to turn this feature off. As a result, others will get a 403 if they are trying to access my web directory.
Step
1. Modify /etc/apache2/sites-available/default
Delete the indexes in the Options under directory /var/www/
2. Restart your apache2
3. Done
Reference
https://help.ubuntu.com/12.04/serverguide/httpd.html#http-configuration
2013/10/31
2013/10/30
Setup a git server via http protocol
Background
1. apached2 installed
2. Ubuntu 12.04 LTS
3. git installed
4. You are root
Steps
Enable git on http (git push should be work after that)
Follow the 2nd reference link, to summarize
1. Import dav module (I have no idea what dav is at this point)
2. Modify directory configuration so that others can access your git directory on your web server
3. Actually I use following config on git.conf since I don't need authentication
Create git repository on your web server (git clone should be work after that)
Follow the 1st reference link.
(EDIT
/* create from existing project */
$ cd /var/www/htdocs/ $ git clone --bare /path/to/git_project gitproject.git
$ chown -R www-data:www-data ./gitproject.git $ cd gitproject.git $ mv hooks/post-update.sample hooks/post-update $ chmod a+x hooks/post-update
$ git update-server-info
/* create from scratch */
$ cd /var/www/htdocs/ $ git init --bare gitproject.git
$ chown -R www-data:www-data ./gitproject.git $ cd gitproject.git $ mv hooks/post-update.sample hooks/post-update $ chmod a+x hooks/post-update
$ git update-server-info
)
Testing
git clone http://<hostname>/<dir>.git
$(some work)
git push
Linking up ticket system Bugzilla with git
https://github.com/gera/gitzilla seems to be a solution. However I cannot make them work. Leave me a message if you know how :'(
Enjoy :D
Reference
1. http://git-scm.com/book/en/Git-on-the-Server-The-Protocols
2. http://www.kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt
1. apached2 installed
2. Ubuntu 12.04 LTS
3. git installed
4. You are root
Steps
Enable git on http (git push should be work after that)
Follow the 2nd reference link, to summarize
1. Import dav module (I have no idea what dav is at this point)
2. Modify directory configuration so that others can access your git directory on your web server
3. Actually I use following config on git.conf since I don't need authentication
<Location /my-new-repo.git> DAV on </Location>4. Restart your apache
Create git repository on your web server (git clone should be work after that)
Follow the 1st reference link.
(EDIT
/* create from existing project */
$ cd /var/www/htdocs/ $ git clone --bare /path/to/git_project gitproject.git
$ chown -R www-data:www-data ./gitproject.git $ cd gitproject.git $ mv hooks/post-update.sample hooks/post-update $ chmod a+x hooks/post-update
$ git update-server-info
/* create from scratch */
$ cd /var/www/htdocs/ $ git init --bare gitproject.git
$ chown -R www-data:www-data ./gitproject.git $ cd gitproject.git $ mv hooks/post-update.sample hooks/post-update $ chmod a+x hooks/post-update
$ git update-server-info
)
Testing
git clone http://<hostname>/<dir>.git
$(some work)
git push
Linking up ticket system Bugzilla with git
https://github.com/gera/gitzilla seems to be a solution. However I cannot make them work. Leave me a message if you know how :'(
Enjoy :D
Reference
1. http://git-scm.com/book/en/Git-on-the-Server-The-Protocols
2. http://www.kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt
2013/10/28
Upgrade php from 5.3 to 5.4 in Ubuntu 12.04 LTS
By default, The version of PHP in Ubuntu 12.04 LTS is 5.3. Somehow, I need the features in 5.4 so that's why I wrote it down for future reference.
Commands
`sudo add-apt-repository ppa:ondrej/php5-oldstable`
`sudo apt-get update`
`sudo apt-get install php5`
Commands
`sudo add-apt-repository ppa:ondrej/php5-oldstable`
`sudo apt-get update`
`sudo apt-get install php5`
If there is warning about missing a SSH module,
clear the contents in /etc/php5/cgi/conf.d/ssh2.ini in order to eliminate the warning
2013/10/25
Mount FTP/NFS in ubuntu
Abstract
Mounting a FTP or NFS into a local directory.Background
Ubuntu 12.04 LTSLet's start
NFS
`sudo apt-get install nfs-common`
`showmount -e NFS_IP`PS. this will show a mountable directory on your NFS
`mount -o soft NFS_IP:<dir in last command> <local_directory>`
FTP
`sudo apt-get install curlftpfs`
`curlftpfs user:pass@ftp.yourdomain.com ~/ftpfolder/`If you want to un-mount the directory,
`sudo umount <dir>`
Permanent mounting
add following line into /etc/fstabcurlftpfs#ftpUsername:ftpPassword@ftp://ftpUrl /localDirectory fuserw,uid=1000,umask=0777,user,suid,allow_other,exec,auto,utf8 0 1
Reference
2013/10/21
Learning u-boot Part 2
My goal
I need to some how implement a feature for loading firmwares via ethernet cable only (IE fading out no SERIAL CONSOLE RS232). A suggestion from my supervisor is starting from bootloader. Basically, that's why this thread coming out :D
1. Direction
According to the /doc/README.Netconsole, u-boot provides an access via netcat. So, this is my starting point.
2. Enable netconsole
Netconsole is disabled by default of my board setting due to minimize the files size of that executable file (I guess). So, the following recording how I enable netconsole.
According to
/common/device.c:240~242
240 #ifdef CONFIG_NETCONSOLE
241 drv_nc_init ();
242 #endif
It is clear that we need to define that constant in order to enable netconsole.
Add lines
#define CONFIG_NETCONSOLE /* enable nc */
into /includes/configs/<board>.h
Recompile the u-boot binary and loading into the device.
PS. How to load bootloader into the device will not be discussed here.
For now, bootloader should be able to use nc.
3. Follow up
Keep following the README.Netconsole, execute following commands via serial console.
setenv nc setenv stdin nc\; setenv stdout nc
setenv ncip <YOUR_SERVER>
setenv netmask <YOUR_SERVER_NETMASK>
saveenv
run nc
In your server run the following script file,
#! /bin/bash
[ $# = 1 ] || { echo "Usage: $0 target_ip" >&2 ; exit 1 ; }
TARGET_IP=$1
stty -icanon -echo intr ^T
nc -u -l 6666 < /dev/null &
nc -u ${TARGET_IP} 6666
stty icanon echo intr ^C
# interupt by CTRL+T
# $1 is your device ip
For now, magic happen :D
You can interact with the device as if you are using serial console cable.
4. Summery
I can setup a network link between embedded device and my pc. The rest of the tasks are putting things together. For example, when and how to enable netconsole on the embedded device. I will cover these stuffs later on (I hope) since I have no progress till now.
I need to some how implement a feature for loading firmwares via ethernet cable only (IE fading out no SERIAL CONSOLE RS232). A suggestion from my supervisor is starting from bootloader. Basically, that's why this thread coming out :D
1. Direction
According to the /doc/README.Netconsole, u-boot provides an access via netcat. So, this is my starting point.
2. Enable netconsole
Netconsole is disabled by default of my board setting due to minimize the files size of that executable file (I guess). So, the following recording how I enable netconsole.
According to
/common/device.c:240~242
240 #ifdef CONFIG_NETCONSOLE
241 drv_nc_init ();
242 #endif
It is clear that we need to define that constant in order to enable netconsole.
Add lines
#define CONFIG_NETCONSOLE /* enable nc */
into /includes/configs/<board>.h
Recompile the u-boot binary and loading into the device.
PS. How to load bootloader into the device will not be discussed here.
For now, bootloader should be able to use nc.
3. Follow up
Keep following the README.Netconsole, execute following commands via serial console.
setenv nc setenv stdin nc\; setenv stdout nc
setenv ncip <YOUR_SERVER>
setenv netmask <YOUR_SERVER_NETMASK>
saveenv
run nc
In your server run the following script file,
#! /bin/bash
[ $# = 1 ] || { echo "Usage: $0 target_ip" >&2 ; exit 1 ; }
TARGET_IP=$1
stty -icanon -echo intr ^T
nc -u -l 6666 < /dev/null &
nc -u ${TARGET_IP} 6666
stty icanon echo intr ^C
# $1 is your device ip
For now, magic happen :D
You can interact with the device as if you are using serial console cable.
4. Summery
I can setup a network link between embedded device and my pc. The rest of the tasks are putting things together. For example, when and how to enable netconsole on the embedded device. I will cover these stuffs later on (I hope) since I have no progress till now.
Learning u-boot Part1
Firstly, I have no idea how many parts I will write on this topic "Learning uboot".
Introduction
Namely part 1, let's take a look what u-boot is. Official website for u-boot is http://www.denx.de/wiki/U-Boot/WebHome.
u-boot is a kind of bootloader on embedded device (eg. routers). Mother Board initialization is what it suppose to do.
What happen after powering on your device
Power on -> bootloader (ROM) -> firmware (STORAGE somewhere) -> user-space interface ( COMMAND LINE or something like that)
My goal
My job is implementing a function for loading firmwares via cat5 cable (IE no SERIAL CONSOLE RS232). A suggestion from my supervisor is starting from bootloader. Basically, that's why this thread coming out :D
1. Browsing the u-boot project
Since I have no expereince on related topics, I can only read documentations, tutorials, googling etc....
Here is my summery for files useful for my goal.
Assume prefix <u-boot project> is presented
/include/configs/cavium_cns3000.h /* u-boot console default environment variable value */
/board/cavium/cns3000/vega.c /* board manufacturer info */
/common/env_common.c /* where environment variable will be assign */
/common/devices.c /* How devices will be enabled */
/common/main.c /* How Interactive Shell implemented */
/net/net.c /* How tftp, arp, ping implemented */
2a. Execution flow
cpu/..../start.S
board/.../lowlevel_init.S
board/.../lowlevel_init.c
cpu/.../start.S
lib_.../board.c
2b. Command flow
/common/main.c
main_loop() -> readline() -> run_command() ->
/common/command.c
find_cmd() -> corresponding function()
3. Short summery
Compile issue:
Make sure your board model is supported by u-boot. (Ask your board manufacturer what to do for bootloader issue)
U-boot provides you a way to build relevant configuration files. (`make <board>_config`)
Make sure your tool chain directory is presented in $PATH.
Script issue:
Following commands are useful for scripting in u-boot.
setenv; setting environment variable
saveenv: saving environment variable permanently on rom
printenv: printing environment variable
run <var>: run the variable contents
coninfo: list of available devices
Script example:
setenv loader tftpboot 0x800000 loader.bin\;erase 0x10000000 +\$(filesize)\;cp.b 0x800000 0x10000000 \$(filesize)\;reset
run loader
Reference
Illustrate the u-boot project hierarchy in chinese
http://gordenhao.pixnet.net/blog/post/29189867-%5B%E8%B3%87%E6%96%99%5D-u-boot-%E7%B0%A1%E4%BB%8B
How to compile uboot
http://home.educities.edu.tw/fushiyun2000/gameconsole_snk_neogeox_hack_compile_official_uboot_program.htm
Execution flow
https://sites.google.com/site/myembededlife/Home/u-boot/u-boot-startup-sequence
Introduction
Namely part 1, let's take a look what u-boot is. Official website for u-boot is http://www.denx.de/wiki/U-Boot/WebHome.
u-boot is a kind of bootloader on embedded device (eg. routers). Mother Board initialization is what it suppose to do.
What happen after powering on your device
Power on -> bootloader (ROM) -> firmware (STORAGE somewhere) -> user-space interface ( COMMAND LINE or something like that)
My goal
My job is implementing a function for loading firmwares via cat5 cable (IE no SERIAL CONSOLE RS232). A suggestion from my supervisor is starting from bootloader. Basically, that's why this thread coming out :D
1. Browsing the u-boot project
Since I have no expereince on related topics, I can only read documentations, tutorials, googling etc....
Here is my summery for files useful for my goal.
Assume prefix <u-boot project> is presented
/include/configs/cavium_cns3000.h /* u-boot console default environment variable value */
/board/cavium/cns3000/vega.c /* board manufacturer info */
/common/env_common.c /* where environment variable will be assign */
/common/devices.c /* How devices will be enabled */
/common/main.c /* How Interactive Shell implemented */
/net/net.c /* How tftp, arp, ping implemented */
2a. Execution flow
cpu/..../start.S
board/.../lowlevel_init.S
board/.../lowlevel_init.c
cpu/.../start.S
lib_.../board.c
2b. Command flow
/common/main.c
main_loop() -> readline() -> run_command() ->
/common/command.c
find_cmd() -> corresponding function()
3. Short summery
Compile issue:
Make sure your board model is supported by u-boot. (Ask your board manufacturer what to do for bootloader issue)
U-boot provides you a way to build relevant configuration files. (`make <board>_config`)
Make sure your tool chain directory is presented in $PATH.
Script issue:
Following commands are useful for scripting in u-boot.
setenv; setting environment variable
saveenv: saving environment variable permanently on rom
printenv: printing environment variable
run <var>: run the variable contents
coninfo: list of available devices
Script example:
setenv loader tftpboot 0x800000 loader.bin\;erase 0x10000000 +\$(filesize)\;cp.b 0x800000 0x10000000 \$(filesize)\;reset
run loader
Reference
Illustrate the u-boot project hierarchy in chinese
http://gordenhao.pixnet.net/blog/post/29189867-%5B%E8%B3%87%E6%96%99%5D-u-boot-%E7%B0%A1%E4%BB%8B
How to compile uboot
http://home.educities.edu.tw/fushiyun2000/gameconsole_snk_neogeox_hack_compile_official_uboot_program.htm
Execution flow
https://sites.google.com/site/myembededlife/Home/u-boot/u-boot-startup-sequence
2013/10/18
"va_*()" in c programming
Quick and dirty summery
va_*() are macros helping you to implement functions with dynamic arguments numbers.
Dig deeper
what is va_*() ?
They are va_start(), va_arg(), va_end() respectively. Those macros will be used if you want to implement a function with vary arguments. For example, printf().
va_start(); /* call before va_arg(), otherwise va_arg() cannot function properly*/
va_arg(); /* return 1st, 2nd, 3rd.... arguments for 1st, 2nd, 3rd ...calls */
va_end(); /* call before returning value */
There are some examples codes on the reference link.
Reference
http://tw.myblog.yahoo.com/jw!kg_rIFWTHgO4kRtDoy15QxVeWQ--/article?mid=21&prev=22&l=f&fid=5
va_*() are macros helping you to implement functions with dynamic arguments numbers.
Dig deeper
what is va_*() ?
They are va_start(), va_arg(), va_end() respectively. Those macros will be used if you want to implement a function with vary arguments. For example, printf().
va_start(); /* call before va_arg(), otherwise va_arg() cannot function properly*/
va_arg(); /* return 1st, 2nd, 3rd.... arguments for 1st, 2nd, 3rd ...calls */
va_end(); /* call before returning value */
There are some examples codes on the reference link.
Reference
http://tw.myblog.yahoo.com/jw!kg_rIFWTHgO4kRtDoy15QxVeWQ--/article?mid=21&prev=22&l=f&fid=5
Network interface in Ubuntu
Here are notes about how to configure ubuntu's network setting without GUI.
Make sure you are root.
System: Ubuntu 12.04
Manual page: interfaces (5)
$>vi /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
dns-nameservers 8.8.8.8
address 192.168.0.22
netmask 255.255.255.0
gateway 192.168.0.1
$>/etc/init.d/networking restart
PS
1. auto eth0 is necessary otherwise your eth0 will not be up on system startup
2. dns-nameservers option will override /etc/resolvd.conf.
Reference link
https://help.ubuntu.com/10.04/serverguide/network-configuration.html
By the way, commands for run-time network interface's configuration
Make sure you are root.
System: Ubuntu 12.04
Manual page: interfaces (5)
$>vi /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
dns-nameservers 8.8.8.8
address 192.168.0.22
netmask 255.255.255.0
gateway 192.168.0.1
$>/etc/init.d/networking restart
PS
1. auto eth0 is necessary otherwise your eth0 will not be up on system startup
2. dns-nameservers option will override /etc/resolvd.conf.
Reference link
https://help.ubuntu.com/10.04/serverguide/network-configuration.html
By the way, commands for run-time network interface's configuration
#Static sudo ifconfig eth0 10.0.0.100 netmask 255.255.255.0
#DHCP sudo dhclient eth0
#STOP DHCP
ps aux | grep dhcli kill .....
2013/10/16
"extern" in c programming
Quick and dirty summery
1. extends the visibility for a variable or function
2. While using with variable, it declares a variable but not defining it.
3. Special case for (2) is "extern int bar=0;", it treat as definition
Dig deeper
Declaration := A variable or function signature exists somewhere in the program but the memory is not allocated for them.
Definition := Despite the stuff declaration does, it also allocates memory for that variable/function.
PS.
/* function */
int foo (int arg1, int arg2); /* Declaration */
int foo (int arg1, int arg2){
/* Definition */
return 0;
}
/* variable */
extern int bar; /* Declaration */
int bar=0; /* Definition */
Reference:
http://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
1. extends the visibility for a variable or function
2. While using with variable, it declares a variable but not defining it.
3. Special case for (2) is "extern int bar=0;", it treat as definition
Dig deeper
Declaration := A variable or function signature exists somewhere in the program but the memory is not allocated for them.
Definition := Despite the stuff declaration does, it also allocates memory for that variable/function.
PS.
/* function */
int foo (int arg1, int arg2); /* Declaration */
int foo (int arg1, int arg2){
/* Definition */
return 0;
}
/* variable */
extern int bar; /* Declaration */
int bar=0; /* Definition */
Reference:
http://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
"volatile" in c programming
Quick and dirty summery
"volatile" is a keyword to force compile to fetch a variable's value from memory every-time it reads this variable during the variable's life time.
Dig deeper
Since there maybe optimizations on the C compiler (maybe true or not), compiler will cache the value of a variable if there are no obvious side effects on that variable. "volatile" is a keyword to tell compiler not to do optimization on that variable.
Reference:
http://cboard.cprogramming.com/c-programming/73163-volatile-keyword.html
"volatile" is a keyword to force compile to fetch a variable's value from memory every-time it reads this variable during the variable's life time.
Dig deeper
Since there maybe optimizations on the C compiler (maybe true or not), compiler will cache the value of a variable if there are no obvious side effects on that variable. "volatile" is a keyword to tell compiler not to do optimization on that variable.
Reference:
http://cboard.cprogramming.com/c-programming/73163-volatile-keyword.html
2013/10/15
Hello World
Hello World!!!
That's my first post on my blogger. As the name of this blogger, I will see this blog as a place for me to manage and drop down notes :D
That's my first post on my blogger. As the name of this blogger, I will see this blog as a place for me to manage and drop down notes :D
訂閱:
文章 (Atom)