All posts by shiji

Remove the Loop Icon for VOX

VOX is the best music players on OSX I’ve ever used.

The Loop becomes one of it’s features to store unlimited music on it’s platform. It’s a good feature, and the only way for the developer to get some pay back for the wonderful applet.

I just don’t need it, and try to save some space for my menu bar.

On the VOX’s preference page, uncheck “Keep Loop Agent Running when” just doesn’t make any sense. Neither for “launchctl remove com.coppertino.VOXCloud” as the developer mentioned.

My way to close that:

Finder – Application – VOX – right click – Show package contents – Contents – Library – LoginItems

You can find the Loop.app here, but things like deleting/renaming/[removing permission] will all prevent VOX from launching.

 

Loop.app – Show package contents – Contents – Resources – Base.lproj

Then rename “MainMenu.nib” to something else for example: “MainMenu.nib.bye”

Quit Loop and restart VOX, Done.

Install PHP7 on Debian 8 Jessie (with Apache)

Important:

Double check your operate system: ONLY  Debian 8 (Jessie) works with this instruction

Apache version: 2.4 which is the default version comes with Debian 8 (Not working with Apache 2.2 or lower)

Install Apache2:

Update package list and upgrade outdated packages:

sudo apt-get update && sudo apt-get upgrade

Install Apache2:

sudo apt-get install apache2

Install PHP7:

Since PHP7 is not included in any Debian official source list, we gonna use the version compiled by Dotdeb.org, which is pretty widely used.

Add source:

sudo nano /etc/apt/sources.list

Add the following two lines to the end of the file:

deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all

If you server is far from US, try find the nearest mirror: https://www.dotdeb.org/mirrors/

Get and Install GnuPG key:

wget https://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg

Update packages again

sudo apt-get update

Install PHP7:

here is a list of available packages currently: (By the way, Swoole also work with php7, use ‘pecl install swoole to install’)

php7.0-apcu       php7.0-dbg        php7.0-imagick    php7.0-memcached  php7.0-phpdbg     php7.0-sybase
php7.0-apcu-bc    php7.0-dev        php7.0-imap       php7.0-mongodb    php7.0-pspell     php7.0-tidy
php7.0-bz2        php7.0-enchant    php7.0-interbase  php7.0-msgpack    php7.0-readline   php7.0-xdebug
php7.0-cgi        php7.0-fpm        php7.0-intl       php7.0-mysql      php7.0-recode     php7.0-xmlrpc
php7.0-cli        php7.0-gd         php7.0-json       php7.0-odbc       php7.0-redis      php7.0-xsl
php7.0-common     php7.0-gmp        php7.0-ldap       php7.0-opcache    php7.0-snmp
php7.0-curl       php7.0-igbinary   php7.0-mcrypt     php7.0-pgsql      php7.0-sqlite3

Choose your list of mod, install with php

sudo apt-get install php7.0 php7.0-common php-pear #add your list of mods here

Install mod_php7 for Apache 2.4 and restart apache:

sudo apt-get install libapache2-mod-php7.0
sudo service apache2 restart

That’s it! Done!

 

Note on sshd_config Setup

What’s sshd_config?

It’s “OpenSSH SSH daemon configuration file”

Simply means the config file for OpenSSH Server.

Located at /etc/ssh/sshd_config

My reference

http://www.freebsd.org/cgi/man.cgi?query=sshd_config

ListenAddress and Port

By default, OpenSSH will listen on port 22 for all address(0.0.0.0 and ::)

There can be multiple Port defined, for example:

Port 22
Port 622

OpenSSH will listen on both ports

ListenAddress specify the address to listen, the address can be hostname, ipv4 or ipv6

You may also add an optional port number, for example:

ListenAddress 192.168.1.120
ListenAddress 1.2.3.4:922
ListenAddress ddns.example.com

OpenSSH will listen on 192.168.1.120 and ddns.example.com at port 22, plus 1.2.3.4 port 922

If there are multiple “Port” specified:

Port 22
Port 622
ListenAddress 192.168.1.120
ListenAddress 1.2.3.4:922
ListenAddress ddns.example.com

Then 192.168.1.120:22   192.168.1.120:622   1.2.3.4:922  ddns.example.com:22  ddns.example.com:622 are listened

 

If port is not specified, sshd will listen on the address and all prior Port options specified.

Access Control:

Process order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups.

If none of the four is defined, login is allowed fro all users.

If Allow* is defined, login is only allowed to declared users and groups.

Only username and groupname are accepted, UID and GID are NOT.

In the following example, only ‘root’ and ‘user’ are allowed

PermitRootLogin yes
AllowUsers root user

In the following example, only ‘user2’ is denied.

DenyUsers user2

Limit user to specified destination address and port

Supposed the OpenSSH server is listening to multiple IPs (1.1.1.1 and 2.2.2.2)

At the end of sshd_config file: add:

# Only user'git' can access to server address 2.2.2.2
Match LocalAddress 2.2.2.2
AllowUsers git

You may also specify port

# Only user'git' can access to server at port 622
Match LocalPort 622
AllowUsers git

You may also specify address and port

# Only user'git' can access to server 2.2.2.2:622
Match LocalAddress 2.2.2.2 LocalPort 622
AllowUsers git

Note:

Match Introduces a conditional block. If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file. If a keyword appears in multiple Match blocks that are satisfied, only the first instance of the keyword is applied.

 

Limit user from specified source address

# Allow root only from client_ddns.example.com and Allow 'user from' 67.67.67.0/24
# Allow user2 from any host 
AllowUsers root@client_ddns.example.com [email protected].* user2

More details on HOST:

Host: Restricts the following declarations (up to the next Host or Match keyword) to be only for those hosts that match one of the patterns given after the keyword. If more than one pattern is provided, they should be separated by whitespace. A single *' as a pattern can be used to provide global defaults for all hosts. The host is the hostname argument given on the command line (i.e. the name is not converted to a canonicalized host name before matching). A pattern entry may be negated by prefixing it with an exclama- tion mark (!’). If a negated entry is matched, then the Host entry is ignored, regardless of whether any other patterns on the line match. Negated matches are therefore useful to provide exceptions for wildcard matches.

Here is another approach using Match:

At the end of sshd_config file: add:

# Only user'git' can access to server address 2.2.2.2
Match Address 67.67.67.0/24 User user
AllowUsers user

Bugs and Tips found recently

1: Teensy as a keyboard does not work properly in GRUB.

Solution: break your long input into parts (<=3 chars) and add delays (50ms is enough) between them.

 

2: In Debian and Ubuntu, your may install some PHP PECL modules just by using

sudo apt-get install php5-pecl-http php5-propro php5-raphf

(PHP run as an apache mod)

Restart Apache, php -m does not show any new module installed.

Try add ini files(propro.ini File Content: extension=propro.so) to /etc/php5/mod-available and make link (15-propro.ini for example) at /etc/php5/apache/conf.d pointing to /etc/php5/mod-available/propro.ini

restart Apache again, php module still not loading.

The solution:

use php5enmod propro instead :)
3: Dell PowerEdge RAID Controller (PERC) H730 and SSD.
Unable to build raid for Samsung 850 EVO SSD in the Lifecycle Manager.

Solution: goto BIOS and find device management- raid controller then build your RAID there.

My note on Installing OpenWRT on Banana Pi R1 (BPi-R1)

Today, I just got my Banana Pi R1.  Here is a simple guide to set it up as an OpenWRT router.

Step 1: Flash the TF(microSD) card.

  • Goto the download page of BPi-R1 (http://www.bananapi.com/index.php/download?layout=edit&id=65)
  • Find and download the latest OpenWRT Image, which is version 4.0 (01/09/2015) as I write this.
  • Write the OpenWRT image to the TF card. I use OS X, here is the code I used in Terminal:
  • Find the disk number of your TF card. Mine is disk2[Bold number may varies on your computer, wrong number will cause serious problem, you will lose your data on the wrong disk]:
    diskutil list

    Unmount it:

    diskutil unmountDisk /dev/disk<strong>2</strong>

    Write the image:

    sudo dd bs=1m if=~/Downloads/BPI-R1_OpenWrt_V4.0.img of=/dev/rdisk<strong>2</strong>
  • If you are using other OS, follow the guide here (From Raspberry Pi, their are all the same except the image)
  • Eject the TF card  from your computer and insert it into Banana Pi.

Step 2: Power On your Banana Pi R1.

  • Plug in the 5V power cord to the correct port, it will power on by itself.
  • HDMI is not working on OpenWRT(only works few seconds while booting)
  • Connect the BPI-R1’s WAN to your home router/switch’s LAN (Assume DHCP is enabled )
  • Find the BPI-R1’s IP address. You may find it in the web management interface of your home router. Scan port 80 and 22 for the whole subnet other wise.
  • use root/admin to login BPI-R1
  • Mostly Done.

After that, I found only 80M(VFAT) + 150M(EXT4) was used on BPI-R1, which waste pretty much space on my 32GB TF card.

Extra Step: Expand the ext4 partition. (Inspired by SaruMaaz)

  • Download Gparted Live
  • Write Image to a Flash Drive (Assume the flash drive is disk2)
    sudo dd bs=4m if=~/Downloads/gparted-live-0.24.0-2-i586.iso of=/dev/rdisk<strong>2</strong>;sync
  • Restart OS X and hold Option key while booting,
  • Chooes ‘EFI Disk’
  • Enter your language code
  • Enter 0 and get to the GUI
  • Plug in the TF card, Find the TF card (mine is sdd)
  • Find the 150M partition, right click, change the size…
  • Apply
  • Done

How to get a certification to sign PDFs

I’m trying to get a certification to sign my PDF files these days.

My Goal:

  1. It is a certification signed by a trusted CA in Adobe Acrobat (of course it can’t be self-signed)
  2. It is cheap

What I did:

Check the current list of Adobe Approved  Trusted CA (http://helpx.adobe.com/acrobat/kb/approved-trust-list1.html)

Check those CA’s website.

Many of those CA are used inside their company/organization only, Some “Widely known CA” like DigiCert, GlobalSign, Entrust cost a lot(200-800 USD/year) for the certification, and you maybe asked for purchasing a USB device for the cert, PLUS, some of them limit the number of files you signed.

Finally I found “CERTUM (Unizeto Technologies)” in Porland, they supply a certification for a low cost(~10USD/year)  https://en.sklep.unizeto.pl/data-safety/id-certificates/certyfikat-professional-id.html

Continue reading How to get a certification to sign PDFs

Netbeans 无法显示中文之解决方案

今天偶然发现Netbeans不能显示中文,本来以为是charset的问题,然后意识到错误的charset会导致乱码,而不是小方块。

经过测试,使用最常用的英文字体,例如Arial, New Times Roman 都可以正常显示中文。其余字体,比如编程常用的MonoSpace,Consolas,Monaco什么的会无法显示中文。如图:

乱码

经过一番搜索,找到原因,简单地说,原因在于这些字体里面不包含中文,fallback font也没有中文.

又搜了一大圈,发现了一个很好的第三方字体,使用Consolas+微软雅黑中文,非常漂亮,成功解决,如图:(如果细心就会发现字数不一样,所以只是我的一个例子么~)

After

 

下载链接:

http://ishare.iask.sina.com.cn/f/8965397.html

备用链接:

YaHei.Consolas.1.12

[Apache] Rewrite subdomain as subfolder

What You Want:

/path/to/www/root/
—————–/123/index.php ===> http://123.yourwebsite.com/
—————–/www/index.php ===> http://www.yourwebsite.com/
—————–/blog/index.php ===> http://blog.yourwebsite.com/
—————–/email/main/index.php ===> http://email.yourwebsite.com/main/

Set dns:

A (may be AAAA) * to your server’s IP address.

This is the rewrite code you should use:

RewriteEngine On
RewriteMap lowercase int:tolower
RewriteCond %{HTTP_HOST} ^(.*)\.yourwebsite\.com$
RewriteRule ^(.*)$     /path/to/www/root/${lowercase:%1}/$1 [L]

PS:

Options -Indexes

Will not working in this case. Since Apache can not find the subfolder if you hide them. All subdomains will return a 404 error.