Showing posts with label compile. Show all posts
Showing posts with label compile. Show all posts

Apache: mod_proxy, mod_proxy_html 사용하기 edit

mod_proxy모듈로 내부 백엔드 서버에 Apache를 통해 접속할 수 있고 mod_proxy_html모듈로 그 서버의 내부 소스들(HTML, Javascript, etc)에서 링크된 상대/절대 경로들을 원하는 경로로 바꿀 수 있다.

데비안 Stable 패키지를 설치하거나 소스에서 빌드하여 바로 설치하거나 빌드된 바이너리를 패키징하여 설치할 수 있다.

Download & Build from source for Apache2 using apxs2

$ apt-get install apx2 libxml2-dev

mod_xml2enc

mod_xml2enc모듈은 지원하지 않는 인코딩들을 지원하게 해준다.

$ ./apxs -c -I/usr/include/libxml2 /usr/local/src/mod_xml2enc/mod_xml2enc.c

mod_proxy_html

$ ./apxs -c -I/usr/include/libxml2 -I/usr/local/src/mod_xml2enc /usr/local/src/mod_proxy_html/mod_proxy_html.c

Debian Packaging

각 디렉토리에 .libs라는 디렉토리가 생성되었을 것이다. 필요한것은 .so파일이다.

  1. libapache2-mod-proxy-html_3.1.2_i386디렉토리를 만들고 하위에 DEBIAN디렉토리를 생성한다.
  2. 생성한 DEBIAN디렉토리 안에 control파일을 만든다. 이 파일은 데비안 공식 패키지에서 추출하여 수정해도 된다.

    control:

    Package: libapache2-mod-proxy-html
    Source: mod-proxy-html
    Version: 3.1.2
    Architecture: i386
    Maintainer: me <me@localhost>
    Depends: libc6 (>= 2.7-1), apache2, apache2.2-common, libxml2 (>> 2.5.10)
    Section: web
    Priority: optional
    Description: Apache2 filter module for HTML links rewriting
     mod_proxy_html is an output filter to rewrite HTML links in a proxy
     situation, to ensure that links work for users outside the proxy. It
     serves the same purpose as Apache's ProxyPassReverse directive does for
     HTTP headers, and is an essential component of a reverse proxy.
    
  3. libapache2-mod-proxy-html_3.1.2_i386/usr/lib/apache2/modules/디렉토리들을 생성한다음 컴파일된 mod_proxy_html.so파일을 넣는다.
  4. libapache2-mod-proxy-html_3.1.2_i386/etc/apache2/mods-available/디렉토리들을 생성한다음 생성된 proxy_html.conf파일을 넣어주고 proxy_html.load파일을 만든다.

    proxy_html.load:

    LoadFile /usr/lib/libxml2.so.2
    LoadModule proxy_html_module /usr/lib/apache2/modules/mod_proxy_html.so
    
  5. 상위 디렉토리(../libapache2-mod-proxy-html_3.1.2_i386)에서 패키징한다.
    $ dpkg-deb --build libapache2-mod-proxy-html_3.1.2_i386
  6. 패키징한 libapache2-mod-proxy-html_3.1.2_i386.deb파일을 설치한다.
  7. $ sudo dpkg -i libapache2-mod-proxy-html_3.1.2_i386.deb
  8. mod_xml2enc모듈도 위와같이 패키징하면 된다.

Configuration

모듈 설치 이후 /etc/apache2/mods-enabled/에 ../mods-availalbe/하위에 필요한 모듈과 설정파일들을 심볼링 링크한다.

/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/proxy.load
/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/proxy.conf
/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/proxy_http.load
/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/proxy_html.load
/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/proxy_html.conf
/etc/apache2/mods-enabled$ sudo ln -s ../mods-available/xml2enc.load

데비안 Stable 패키지를 설치하였다면 xml2enc는 현재 squeeze배포판에서 지원하지 않는다.

  • 3.1 이전 버전의 mod_proxy_html에는 SetOutputFilter proxy-html를 사용하며 3.1 버전부터 ProxyHTMLEnable On를 사용한다.
  • 프락시 설정시 끝에 붙는 '/'(슬래시)에 주의.
  • mod_proxy_html모듈은 페이지를 필터링할때 모두 UTF-8로 변경하여 필터링하고 출력 인코딩의 기본값도 UTF-8이며 이것을 변경하려면 ProxyHTMLCharsetOut옵션을 사용해야 하지만 이 옵션을 사용하면 UTF-8 출력을 설정된 인코딩으로 다시 인코딩하기 때문에 오버헤드가 발생한다.
  • ProxyRequests옵션은 포워드 프록시를 켜는 옵션이며 이 옵션을 인증과정없이 켠다면 자신의 서버가 공개프락시가 되는셈이다.
  • RequestHeader unset Accept-Encoding옵션으로 압축되지 않은 응답을 백엔드 서버로부터 전송받아야 mod_proxy_html모듈이 필터링을 할 수 있다.
  • 백엔드 서버의 프로토콜이 HTTPS라면 SSLProxyEngine On옵션을 설정해야 한다.
  • mod_headers 모듈을 추가한다음 RequestHeader옵션으로 Authorization헤더를 추가함으로써 내부 백엔드 서버에 자동으로 로그인 할 수 있다. 혹은 백엔드 서버의 인증 아이디와 비밀번호가 웹서버와 같아도 헤더가 포워딩되서 자동으로 인증된다.
    • RequestHeader set Authorization "Basic BASE64(ID:PASSWORD)"
  • 설정에 대한 더 자세한 사항은 아파치 사이트나 모듈 사이트를 참고.

ZNC

ProxyRequests off
<Proxy *>
    Order Allow,Deny
    Allow from all
</Proxy>

Redirect /znc https://server.domain/znc/
ProxyPass /znc/ http://localhost:port/
ProxyHTMLURLMap http://localhost:port/ /znc/
<Location /znc>
    ProxyPassReverse /
    SetOutputFilter proxy-html
    ProxyHTMLURLMap / /znc/
    RequestHeader unset Accept-Encoding
    RequestHeader set Authorization "Basic BASE64(ID:PASSWORD)"
</Location>

최신버전의 mod_proxy_html과 mod_xml2enc모듈을 사용하였더니 인코딩이 부분적으로 깨져서 데비안 squeeze의 기본 패키지로 다운그레이드 하였다.

ZNC는 HTTPSock.cpp의 다음과 같은 소스에 의해 Authorization 헤더가 요청으로 들어온다면, 자동으로 아이디와 비밀번호를 BASE64로부터 산출하여 로그인한다. 이로인해 프록시를 설정한 루트도메인에서 다른 아이디와 비밀번호를 설정하였다면 ZNC Webadmin 페이지 접속시 다른 아이디와 비밀번호로 인해 Login Invalid라는 오류메시지가 출력된다.

HTTPSock.cpp:

} else if (sName.Equals("Authorization:")) {
    CString sUnhashed;
    sLine.Token(2).Base64Decode(sUnhashed);
    m_sUser = sUnhashed.Token(0, false, ":");
    m_sPass = sUnhashed.Token(1, true, ":");
    m_bLoggedIn = OnLogin(m_sUser, m_sPass);

Transmission

ProxyRequests off
<Proxy *>
    Order Allow,Deny
    Allow from all
</Proxy>

Redirect /transmission https://server.domain/transmission/web/
ProxyPass /transmission/ http://localhost:port/transmission/
<Location /transmission>
    ProxyPassReverse /
    RequestHeader set Authorization "Basic BASE64(ID:PASSWORD)"
</Location>

IPTIME 공유기

IPTIME 공유기 웹어드민 페이지를 프록시로 아파치를 통해 HTTPS로 접속하여 사용하려고 하였으나, mod_proxy_html사용시 한글 인코딩이 모두 깨지고 페이지가 자바스크립트로 매우 복잡하게 되어있어서 이를 위한 도메인을 따로 독립적으로 사용하여 mod_proxy_html의 필터링 없이 mod_proxy만 사용하여 도메인의 루트경로에서 사용하였다.

인코딩이 깨지는 원인이 공유기 웹어드민 페이지가 응답을 chunked로 주어서 여기에 버그가 있기때문인줄 알았으나 설치된 Apache 데비안 패키지의 버전과 소스를 보니 이미 해당 버그가 패치된 Apache를 사용하고 있었다.(http://grokbase.com/t/apache/dev/074bj0x0kr/mod-proxy-buffering-small-chunks)

특히 mod_proxy_html모듈이 공유기 웹어드민 최상위 경로 접속시 자동으로 /login/login.cgi로 리다이렉션 하는데 이는 HTML의 META태그에 의한것이며 이를 필터링하는데 실패하였다.

독립된 도메인을 사용하면서 크로스 도메인으로 본래의 도메인과 인증없이 연동하여 사용하려고 HTTP Digest Authentication 인증 메쏘드를 사용해 보았지만 대부분의 거의 모든 브라우저가 이를 지원하지 않는다.

Most browsers do not respect the Digest "domain" directive and will not resend credentials for other URIs. As far as I know, Opera is the only browser that honors it. For Opera, the server(s) must respond with the same "realm" string for each URI in the domain list. In other words, if domain="/test /example", the server needs to send "Test Realm - example.com" in the WWW-Authenticate header for both of those URIs. I assume Opera does this because it stores H(A1) instead of the actual password for security. Read into RFC2617 for more on this. Here's my cross-browser solution to this problem: http://travisce.com/arest/

HTTP Digest Authentication 인증 메쏘드에 대한 설정법은 따로 포스팅 한다.

References

PyCrypto 윈도우즈 환경에서 컴파일하기 edit

PyCrypto는 파이썬 암호화 툴킷이다.

MinGW 설치

C로 작성된 소스들을 컴파일하기위해 MinGW를 설치하였고 설치도중 MSYS 설치해야 autoconf 에러가 안난다.

MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. It is intended to supplement MinGW and the deficiencies of the cmd shell.

시스템 환경 변수 수정

설치 이후 환경 변수(컴퓨터 > 고급 시스템 설정 > 고급 탭 > 환경 변수)의 시스템 변수 Path에 아래 경로를 새로 추가해준다. ';'는 경로들을 구분짓기위한 문자이다.

;C:\MinGW\bin;C:\MinGW\msys\1.0\bin

만약 바로 적용이 안된다면 시스템을 재부팅 하거나 레지스트리 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment의 Path값을 직접 수정한다.

빌드(설치) 하기

컴파일러 옵션 없이 setup.py를 실행하면 vcvarsall.bat를 찾을 수 없다는 에러가 난다. 옵션 --compiler=mingw32를 붙여준다.

python setup.py install --compiler=mingw32

gcc: error: unrecognized command line option '-mno-cygwin'

컴파일 도중 위와 같은 에러가 난다면 C:\python2.x\distutils\cygwinccompiler.py를 직접 수정하여 -mno-cygwin를 찾아 바꿔 모조리 지워버린다.

It sounds like GCC 4.7.0 has finally removed the deprecated -mno-cygwin option, but distutils has not yet caught up with it. Either install a slightly older version of MinGW, or edit distutils\cygwinccompiler.py in your Python directory to remove all instances of -mno-cygwin.

-mno-cygwin옵션은 더이상 사용되지 않는 옵션이며 파이썬 버그리포트 참조.

finch(pidgin) compile cf.sh edit

pidgin compile options to use finch only. (disable GUI and audio related features)

cf.sh:
#!/bin/bash

PREFIX="/home/me/usr"

export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PREFIX/libxml/lib/pkgconfig"

PATH="$PATH:$PREFIX/intltool/bin" \

./configure \
--disable-gtkui \
--disable-screensaver \
--disable-sm \
--disable-gtkspell \
--disable-gestures \
--disable-gstreamer \
--disable-gstreamer-interfaces \
--disable-farsight \
--disable-vv \
--disable-idn \
--disable-meanwhile \
--disable-avahi \
--disable-tcl \
--disable-tk \
--disable-pixmaps-install \
--disable-doxygen \
--disable-dot \
--disable-devhelp \
--with-ncurses-headers=$PREFIX/ncurses/include \
--disable-nm \
--disable-perl \

$ make DESTDIR="$PWD/build" install

다른위치에 설치된 'pkg-config'의 '.pc'파일 'PKG_CONFIG_PATH'환경변수로 컴파일시 인식시키기 edit

http://kldp.org/node/52070

참고로 위 환경 변수 내용을 바꾸기 전에 pkg-config를 실행해서, pkg-config가 제대로 설정 파일을 인식했는지 확인할 수도 있습니다:

$ pkg-config --list-all

문제


libxml을 다른위치에 설치했더니 pidgin 컴파일시 아무리 CFLAG, LDFLAG, LIBS, LIBXML_CFLAGS, LIBXML_LIBS 환경변수들을 설정해줘도 인식하질 못했다.

libxml/lib/ 하위에 pkgconfig 디렉토리가 있는것을 발견하고, 인식시키려고 configure 실행시 환경변수 'PKG_CONFIG_PATH'에 경로를 환경변수 'PATH'처럼 ':'로 구별하여 평소에 하던대로 실행시만 적용되게끔 아래와 같이 실행해도 인식되지 않았다.

$ PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/home/me/usr/libxml/lib/pkgconfig" ./configure

해결방법


아래와같이 환경변수를 export 시킨 후 configure 해보니 인식성공.

$ export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/home/me/usr/libxml/lib/pkgconfig"

/2011/08/finchpidgin-compile-cfsh.html

원인예상


configure 도중 내부적으로 pkg-config 를 호출하는데 처음의 방법은 환경변수를 ./configure 에만 전달하고 pkg-config 에는 전달하지 못해서 생기는 문제일까?

finch에 pidgin-nateon 플러그인을 deb 패키징 후 설치 edit

서버에서 메신저를 돌려볼려던 생각은 옛날부터 해왔었는데 검색하던중 찾아낸 finch는 공교롭게도 pidgin의 CLI 버전이다.

pidgin-nateon 패키지의 의존성인 pidgin 대신(콘솔에선 설치해도 못씀) finch를 사용하기 위해서 finch 의존성으로 다시 패키징한다.

libpurple 설치


플러그인을 빌드하는데 libpurple이 필요. 데비안 lenny 기준 백포트로 설치

$ sudo aptitude -t lenny-backports install libpurple0

pidgin-nateon 플러그인 다운로드


svn에서 최신 리비전을 받는다

$ svn export http://dev.haz3.com/svn/nateon/trunk/ pidgin-nateon

pidgin-nateon 빌드


control 파일 추출을 위한 pidgin-nateon deb 패키지 빌드 (/2011/05/deb.html)


control 파일을 직접 만들 수 있다면 생략.

pidgin-nateon$ dpkg-buildpackage -rfakeroot -uc -b

control 파일을 만들 수 있다면 소스 빌드


pidgin-nateon$ ./configure --prefix=/usr
pidgin-nateon$ make
pidgin-nateon$ make DESTDIR="$PWD/build" install

(!) configure할때 prefix를 /usr 가 아닌 다른경로로 설정한다면 finch가 locale을 인식 못하는 문제가 발생한다.

finch-nateon deb 패키지 빌드


finch-nateon, finch-nateon/DEBIAN 디렉토리를 생성한다.

pidgin-nateon deb 패키지 빌드 하였다면


pidgin-nateon/debian/pidgin-nateon/DEBIAN/control -> finch-nateon/DEBIAN/control 복사 후 수정

...
Package: pidgin-nateon -> finch-nateon
...
Depends: pidgin -> finch
...

pidgin-nateon/debian/pidgin-nateon/usr -> finch-nateon/usr 복사한다.

pidgin-nateon 소스를 빌드하였다면


control 파일을 finch-nateon/DEBIAN/ 에 넣고 빌드된 바이너리들을 finch-nateon/ 에 넣어준다.

CUI인 finch에서는 필요없는것들을 제거해준다.

  • finch-nateon/usr/share/pixmaps (finch는 콘솔 인터페이스이므로 이미지는 필요없다.)
  • finch-nateon/usr/share/doc (문서따위..)

finch-nateon 상위 디렉토리(pidgin-nateon)에서 dpkg-deb으로 빌드

pidgin-nateon$ dpkg-deb --build finch-nateon

생성된 finch-nateon.deb 의 이름을 알맞게 수정

finch-nateon.deb -> finch-nateon_2.5.6-svn143_i386.deb

패키지 설치


$ sudo dpkg -i finch-nateon_2.5.6-svn143_i386.deb

빌드된 finch-nateon 플러그인 deb 패키지 파일 다운로드 링크



참고 링크



스크린샷



ncurses cf.sh edit

cf.sh:

#!/bin/bash

HOMEDEV="/home/usr"

./configure \
--prefix="$HOMEDEV/ncurses" \
--without-manpages \
--enable-widec \

libncursesw? edit

libncursesw5 - 터미널 처리 공유 라이브러리 (와이드 문자 지원)

ncurses 컴파일시 아래 옵션을 추가하면 ncurses를 사용하는 프로그램에서 한글이나 다른 글자가 깨지지 않음.

와이드 문자 지원 옵션:

--enable-widec          compile with wide-char/UTF-8 code
<- Older