Microsoft Visio save as EPS

February 8, 2008 2:04 pm UTC | In Tech | 3 Comments | hide

I wrote the following procedure on 2008.02.08:

To convert a Microsoft Visio document to EPS without losing scalable vector format (and without installing 3rd-party software…):

  1. Install Microsoft Save as PDF or XPS Add-in for 2007 Microsoft Office programs (only available for Office 2007?).
  2. Save Visio document as PDF in Visio 2007.
  3. Convert PDF to Postscript (.ps) with pdf2ps utility.
  4. Open .ps file with gsview, and select File -> PS to EPS, be sure to check “Automatically calculate Bounding Box”.

Now you have an EPS file to be embedded into your LaTeX document. Many other converting methods exist, see also Visio and EPS.

Here are some updates (edited on 2009.01.30):

  1. In theory, you should be able to open that saved PDF directly in gsview and convert to EPS, but gsview either crashes or refuses to accept the PDF.
  2. In some cases, e.g. when you compile LaTeX directly to PDF using pdflatex, you just need a PDF figure with correct size. In that case, you can set the document size in Visio: File -> Page Setup -> Page Size (tab) -> Size to fit drawing contents, and then save the Visio document to PDF, which will then be in correct size ready to be embedded into LaTeX.
  3. To create a Postscript file, you don’t necessarily need to save as PDF and convert to .ps using pdf2ps. All you need to do is to use a postscript printer (most modern printers are, including most PDF writers) and print to file. That would create a postscript file which can then be passed to gsview and converted to EPS by adding a bounding box. Note: this is in fact a generic way of converting anything to (vector-format) EPS/PDF with bounding box.

Tags: , , , ,

Convert WordPress database from Latin1 to UTF-8

January 12, 2008 5:39 pm UTC | In Tech | 3 Comments | hide

Some early WordPress databases use raw Latin1 encoding to represent UTF-8 characters. The following seems to be an O.K. way to convert those databases to native UTF-8 databases (at least it works for me, Mysql 5.0.45):

  1. Stop/restrict web service.
  2. Dump the database:
    $ mysqldump --default-character-set=latin1 --databases wordpress > m.sql
  3. Change encoding settings in m.sql, including table default encoding and client communication encoding:
    $ replace "CHARSET=latin1" "CHARSET=utf8" \
        "SET NAMES latin1" "SET NAMES utf8" < m.sql > m2.sql
  4. Import the “converted” sql:
    $ mysql < m2.sql
  5. Add the following lines to WordPress wp-config.php
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');
  6. Reopen web service. That’s it.

Note: For future convenience, you might as well change the database default encoding to utf8.

Ref to WordPress documentation for details: here and here.

Tags: , , , ,

Windows XP 设置开机自动登录

September 16, 2007 4:03 pm UTC | In Tech | 1 Comment | hide

每次要用都忘,记一下:control userpasswords2

Tags: ,

rsyncrypto: rsync + encryption

September 7, 2007 1:04 am UTC | In Tech | Comments Off | hide

rsyncrypto is basically rsync plus encryption. It’s not feature-complete I guess, but it works for me. Ubuntu source has binary package but compiling isn’t hard at all. Alright, so obviously man page has most of what you need, here I’ll write simple outlines.

Suppose your data source folder is ~/src, sync destination is ~/dst (this could be a mounted nfs or smb share), and rsyncrypto working directory is ~/rr.

A. Encryption

First of all, create backup keys:

openssl req -nodes -newkey rsa:1536 -x509 \
  -keyout ~/rr/backup.key -out ~/rr/backup.crt

Then the actual sync command is:

rsyncrypto --ne-nesting=2 --trim=3 -n ~/rr/map \
  -cvr ~/src/ ~/dst/ ~/rr/keys ~/rr/backup.crt

This command will encrypt filename and folder structure. So obviously folder modification time will not be preserved, and empty folder will be lost. Parameter --trim depends on your folder location. --ne-nesting depends on the number of files you will have in the future. In general, you may want less than 1024 files per folder, so you need 1024*16^n > total number of files, --ne-nesting=2 is enough for 200,000 files. After this encrypted sync, and suppose you lose everything except files in the ~/dst/, then you’ll need backup.key to cold decrypt all files. So be sure to keep backup.key at another place, preferably at another physical location. You can put the above command into crontab if -v is removed. Also, syncing files without ownership might result in errors, and it may be hard to debug because rsyncrypto does not have very friendly error messages – in which case you may try to fix the file permission problem, or you may run the command by root.

If you want a parameter similar to --delete in rsync, the corresponding parameter in rsyncrypto is --delete-keys. The parameter --delete alone in rsyncrypto does not remove filename mapping in ~/rr/map.

B. Decryption

Suppose you want to cold decrypt to folder ~/rec/. First you need to decrypt filename mapping:

rsyncrypto -d ~/dst/filemap ~/rec/filemap \
  ~/rec/filemap-keys ~/rr/backup.key

The above command generates ~/rec/filemap, so then you can decrypt all files:

rsyncrypto --trim=3 -n ~/rec/filemap \
  -vrd ~/dst ~/rec/files ~/rec/keys ~/rr/backup.key

Tags: , , , ,

TeraStation Pro II 使用手记

August 30, 2007 11:06 pm UTC | In Tech | 1 Comment | hide

English Translation: A quick summary

  • to get root privilege: compile acp_commander.java and run
    java acp_commander -o -t TeraStation_ip

    You may need to temporarily disable firewall on the machine that executes this command. You can then telnet in with empty root password, and set a password. Start sshd to have secure connection. Because it’s so easy to hack TeraStation, I think it can only be used in trustworthy local network.

  • Every time you restart TeraStation, you have to use acp_commander to start sshd, but root password is preserved.
    java acp_commander -c 'sshd' -t TeraStation_ip
  • To have special characters in the windows sharing password, just run passwd and smbpasswd under shell.
  • TeraStation supports rsync but rsync is only intended to be used between TeraStations. You could change /etc/rsyncd.conf to configure rsyncd server. Also, you can setup crontab job to rsync from TeraStation main disk to a USB disk plugged into TeraStation. This is obviously the best local backup method.

小日本作了一堆 TeraStation 文件服务器(民间 wiki民间论坛),卖得还不错。这玩意没什么特别的高科技成分,嵌入式 linux,加一堆软 raid。唯一比较赞的是机箱工艺比较好,体积也比较小。对于一般的应用,默认启动起来的 TeraStation 已经足够能用,但是没有 root 权限总是一件很不愉快的事情。下面简略记一下我对我们买的 TeraStation Pro II 的一些 hack。

默认的 TeraStation 对外只开了 web 管理界面和 smb 文件共享。但是它留了一个洞,可能是为了升级 firmware 方便。有人琢磨出来利用这个洞获得 root 权限,google acp_commander 就可以找到详细说明。acp_commander.java 源代码在 这里 备份一下。acp_commander 可以给 TeraStation 发送命令。执行

java acp_commander -o -t TeraStation_ip

清空 root 密码并启动 telnetd,然后 telnet 进去使用空密码登录 root 并设置密码。然后启动 sshd 就可以登录 ssh shell 了。一个要注意的问题是 acp_commander 需要接收 UDP 包,所以执行命令的这台机器需要临时关掉防火墙。

TeraStation 每次重启动会 reset 一些设置,所以需要重新用 acp_commander 来启动 sshd。注意 root 密码是不会被 reset 的,所以以后每次只要启动 sshd 即可,不需要清空 root 密码,也不需要再启动 telnetd 了。

java acp_commander -c 'sshd' -t TeraStation_ip

当然最彻底的方法是换掉 TeraStation 的 firmware,人民群众也已经创造了稳定的内核。不过我比较懒,所以还是用老的 firmware,反正我需要的功能都已经有了。另外,因为这个默认的 TeraStation fireware 这么容易被黑掉,所以建议只在可信赖的内网使用小日本的这个玩意儿。

TeraStation 的 web 界面相当的土鳖,不支持含有特殊字符的密码。大概看了一下貌似是因为 cgi 程序懒得处理这些特殊字符所以干脆禁止掉。当然,有了 shell 之后只要在 shell 下执行 passwd 和 smbpasswd 修改即可。ps 发现脚本到处都有日文注释,看来小日本写程序和有些中国人一样,也喜欢用母语注释。

TeraStation 本身支持 rsync 协议但是只是为了 TeraStation 之间备份用。有了 shell 之后可以修改 /etc/rsyncd.conf 来配置 rsync 服务器。当然也可以用 rsync over ssh,但是 TeraStation 的处理器不够强劲,高速解码 ssl 还是会影响一些性能。另外,从 raid 主盘往接在 TeraStation 上的 USB 盘备份可以在 crontab 设置 rsync,这应该是本地备份 TeraStation 最高效的方法。

Tags: , , ,

lftp+ssh-socks4 tunnel memo

January 31, 2007 1:40 am UTC | In Tech | No Comments | hide

dante-1.1.19:

./configure --with-socks-conf=/home/vv/dante-1.1.19/socks.conf

socks.conf:

route {
    from: 0.0.0.0/0   to: 0.0.0.0/0   via:127.0.0.1  port = 4444
    protocol: tcp           # server supports tcp and udp.
    proxyprotocol: socks_v4 # server supports socks v4 and v5.
    method: none #username  # we are willing to authenticate via
                            # method "none", not "username".
}

lftp-3.5.9:

./configure --with-socksdante=/home/vv/dante-1.1.19

establish ssh-socks4 tunnel:

$ ssh -N -D4444 vv@**** -p**
[vv@XX ~]$ lftp-3.5.9/src/lftp ftp://166.111.18.101/
cd ok, cwd=/
lftp 166.111.18.101:/> set ftp:fix-pasv-address no
lftp 166.111.18.101:/> ls
drwxrwxr-x   6 HAPPY    HAPPY         416 Dec 30 16:59 incoming
-rw-r--r--   1 HAPPY    HAPPY      218031 Jan 31 06:08 ls-lR.gz
drwxrwxr-x   5 HAPPY    HAPPY         120 Nov 24  2005 pub
-rw-r--r--   1 HAPPY    HAPPY      107198 Jan 31 06:08 tree.txt

Tags: , , , , , ,

LaTeX quick start

January 12, 2007 10:00 pm UTC | In Tech | 1 Comment | hide

There are many different ways to compile a LaTeX source file to a PDF. Following is one of the many ways to create a such LaTeX working environment on a completely new Windows box:

  1. Without saying, you need a PDF viewer, e.g. Adobe Reader.
  2. Install Ghostscript and GSview
  3. Install MiKTeX. A basic MiKTeX system is enough for most purpose.
  4. Install TeXnicCenter. This is an integrated LaTeX editor, by which you will compile your LaTeX source and view result using tools installed above.
  5. When you start TeXnicCenter:
    1. A configuration wizard may ask for a LaTeX distribution location, select where file latex.exe is. In my case, it’s “C:\Program Files\MiKTeX 2.6\miktex\bin”.
    2. Next, wizard may ask PDF viewer location, select your viewer. Mine is “C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe”.
    3. Wizard will then create output profiles (compile/view commands) for DVI/PS/PDF.
  6. Compile your first LaTeX:
    1. Create a new file and save to a new directory.
    2. Type in a simple document, like:
      \documentclass{article}
      \begin{document}
      \[
      x_{1,2}=\frac{-b\pm\sqrt{b^2-4ac}}{2a}.
      \]
      I can do math!
      \end{document}
    3. In the toolbar, select “LaTeX => PDF” output profile, and click “Build current file” right next to it.
    4. Click “View Output” in the same toolbar. You should have math in your PDF. Congratulation!

LaTeX: easy to start, hard to master…

Tags: , ,

This weblog is licensed under a Creative Commons License.
Powered by WordPress. Theme based on Pool by Borja Fernandez.