<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AskApache &#187; Search Results  &#187;  files</title>
	<atom:link href="http://www.askapache.com/search/files/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Thu, 26 Apr 2012 11:29:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Optimized Vimrc with 256 Colorscheme</title>
		<link>http://www.askapache.com/linux/fast-vimrc.html</link>
		<comments>http://www.askapache.com/linux/fast-vimrc.html#comments</comments>
		<pubDate>Sun, 26 Feb 2012 18:15:32 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=7062</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/linux/fast-vimrc.html"><img src="http://uploads.askapache.com/2012/02/vimrc-colorscheme.png" alt="askapachecode 256color colorscheme and vimrc screenshot" title="askapachecode 256color colorscheme and vimrc screenshot" width="525" height="277" class="size-full wp-image-7074" /></a><strong>This is not your everyday vimrc</strong>.  This is <em>my</em> personalized vimrc.. works especially great on remote servers, in tmux, screen, etc. <br /><br />This doesn't require a git checkout, a vim update, a bash update, an OS update, a plugin.  No.  1 vimrc, 1 colorscheme, just use curl to download and it's on.  I use this on <a href="http://archlinux.org/">Arch Linux</a>, NetBSD, FreeBSD, OpenBSD, Debian, Ubuntu, Cent OS, Red Hat, and that's mostly it so far. <br />If you aren't already using vim as your primary editor in a powerful way, you are gonna owe me for this.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/linux/fast-vimrc.html"></a><a href="http://www.askapache.com/linux/fast-vimrc.html"><cite>AskApache.com</cite></a></p><p>This is 90% geared for purely console/terminal/pty/tty/ssh/putty/telnet/tmux/screen users.  I've only just the past couple years started understanding why it was key to learn vim, in the past I never had the patience for it and preferred nano-like editors.  Now vim is all I use when on linux, it's so much more productive.. especially with a customized vimrc file.  This doesn't require a git checkout, a vim update, a bash update, an OS update, a plugin.  No.  This is a single file that I use on <a href="http://archlinux.org/">Arch Linux</a>, NetBSD, FreeBSD, OpenBSD, Debian, Ubuntu, Cent OS, Red Hat, and that's it so far.  This is geared for users who use SSH more than anything else.  Of course, it works perfect on an X enabled box locally as well.</p>

<h2>ScreenShot</h2>
<p><a href="http://uploads.askapache.com/2012/02/vimrc-screenshot.png"><img src="http://uploads.askapache.com/2012/02/vimrc-screenshot.png" alt="Screenshot of this vimrc in action" title="Screenshot of this vimrc in action" width="911" height="987" class="size-full wp-image-7073" /></a></p>

<h2>Setup</h2>
<p>I install this as <code>/etc/vimrc</code> if possible.  Individual users can use a vim config file in their home directories.</p>
<pre>source /etc/vimrc</pre>
<p>To install for a single user just save it in their home dir at <code>/home/username/.vimrc</code></p>

<h2>Portability</h2>
<p>For the portability needed to work on many different systems, this doesn't rely on any plugins other than those built into the default installation of vim 7.0.
It works well on all types of consoles, and depending on the TERM environment variable (and whether it has the right term capabilities) it will load 256 color support or not.  Usually on a new system I just scp this right over and it works without any modifications.  But an ongoing Work in progress.</p>



<h2>Optimized Vimrc</h2>
<p>Download - <a href='http://uploads.askapache.com/2012/02/vimrc.txt'>Optimized vimrc</a></p>
<pre>" Updated: Wed Feb 22 13:25:23 2012 by galileo@galileo
&nbsp;
" For all key mappings like &#039;, .&#039; to reload vimrc
let maplocalleader=&#039;,&#039;
&nbsp;
" BACKUPS, SWAPFILES, VIEWDIR, TMPDIR  "{{{1
" ================================================================================================================================================================
&nbsp;
" SET RUNTIMEPATH {{{3
if isdirectory(expand("$HOME/.vim"))
  let $VIMRUNTIME=expand("$HOME/.vim")
  set runtimepath=$VIMRUNTIME
endif
&nbsp;
" IF BKDIR IS NOT SET OR EMPTY, SET {{{3
if $BKDIR == ""
  let $BKDIR=expand("$HOME/.bk")
  if !isdirectory(expand("$BKDIR"))
    call mkdir(expand("$BKDIR"), "p", 0700)
  endif
endif
&nbsp;
" MAKE DIRS IF mkdir exists {{{3
if exists("*mkdir")
  if !isdirectory(expand("$BKDIR/.vim/viewdir"))|call mkdir(expand("$BKDIR/.vim/viewdir"), "p", 0700)|endif
  if !isdirectory(expand("$BKDIR/.vim/tmp"))|call mkdir(expand("$BKDIR/.vim/tmp"), "p", 0700)|endif
  if !isdirectory(expand("$BKDIR/.vim/backups"))|call mkdir(expand("$BKDIR/.vim/backups"), "p", 0700)|endif
endif
&nbsp;
" SETTINGS USING NEW DIRS {{{3
let &amp;dir=expand("$BKDIR") . "/.vim"
let &amp;viewdir=expand("$BKDIR") . "/.vim/viewdir"
let &amp;backupdir=expand("$BKDIR") . "/.vim/backups"
"let &amp;verbosefile=expand("$BKDIR") . "/.vim/vim-messages.
&nbsp;
" VIMINFO {{{3
" COMMENTED OUT {{{4
"  "       Maximum number of lines saved for each register
"  %       When included, save and restore the buffer lis
"  &#039;       Maximum number of previously edited files for which the marks are remembere
"  /       Maximum number of items in the search pattern history to be saved
"  :        Maximum number of items in the command-line history
"  &lt;       Maximum number of lines saved for each register.
"   @       Maximum number of items in the input-line history
"  h       Disable the effect of &#039;hlsearch&#039; when loading the viminfo
"  n       Name of the viminfo file.  The name must immediately follow the &#039;n&#039;.  Must be the last oneEnvironment variables are expanded when opening the file, not when setting the option
"  r       Removable media.  The argument is a string
"  s       Maximum size of an item in Kbyte
"   }}}4 COMMENTED OUT
let &amp;viminfo="%200,&#039;200,/800,h,&lt;500,:500,s150,r/tmp,r" . expand("$BKDIR") . "/.vim/tmp,n" . expand("$BKDIR") ."/.vim/.vinfo"
&nbsp;
" CUSTOM FUNCTIONS "{{{1
" ================================================================================================================================================================
if !exists("AskApacheLoaded")
  let AskApacheLoaded=1
&nbsp;
  " FUNCTION - LastMod {{{3
  " Warning, this is controlled by an autocmd triggered when closing the file that updates the file (in a great way)
  " Updated: Wed Feb 22 13:25:23 2012 by galileo@galileo
  function! LastMod()
    exe "silent! 1,20s/Updated: .*/" . printf(&#039;Updated: %s by %s@%s&#039;, strftime("%c"), expand("$LOGNAME"), hostname()) . "/e"
  endfunction
&nbsp;
  " FUNCTION - LastModNow {{{3
  " An even better version than LastMod()
  function! LastModNow()
    call setline(line(&#039;.&#039;), printf(&#039;%sUpdated: %s by %s@%s&#039;, printf(&amp;commentstring, &#039; &#039;), strftime("%c"), expand("$LOGNAME"), hostname()))
    "printf(&#039;%sUpdated: %s by %s@%s&#039;, printf(&amp;commentstring, &#039; &#039;), strftime("%c"), expand("$LOGNAME"), hostname())\|dd\|j\|dd&lt;CR&gt;&lt;ESC&gt;
    "printf(&#039;Updated: %s by %s %s&#039;, strftime("%c"), expand("$LOGNAME@$HOSTNAME")) ."/e"
  endfunction
&nbsp;
  " FUNCTION - AppendModeline {{{3
  " Append modeline after last line in buffer.  Use substitute() instead of printf() to handle &#039;%%s&#039; modeline
  function! AppendModeline()
    let l:modeline = printf(" vim: set ft=%s ts=%d sw=%d tw=%d foldmethod=%s :", &amp;filetype, &amp;tabstop, &amp;shiftwidth, &amp;textwidth, &amp;foldmethod)
    let l:modeline = substitute(&amp;commentstring, "%s", l:modeline, "")
    call append(line("$"), l:modeline)
  endfunction
&nbsp;
  " FUNCTION - LastModAAZZZ {{{3
  " AA_UPDATED=&#039;01/24/12-00:56:00&#039;
  function! LastModAAZZZ()
    exe "1,50s/AA_UPDATED=.*/AA_UPDATED=&#039;" . strftime("%c") . "&#039;"
  endfunction
&nbsp;
  " FUNCTION - StripTrailingWhitespace {{{3
  " automatically remove trailing whitespace before write
  function! StripTrailingWhitespace()
    normal mZ
    %s/\s\+$//e
    if line("&#039;Z") != line(".")|echo "Stripped whitespace\n"|endif
    normal `Z
  endfunction
&nbsp;
  " FUNCTION - MyTabL {{{3
  function! MyTabL()
    let s = &#039;&#039;|let t = tabpagenr()|let i = 1
    while i &lt;= tabpagenr(&#039;$&#039;)
      let bl = tabpagebuflist(i)|let wn = tabpagewinnr(i)
      let s .= &#039;%&#039; . i . &#039;T&#039;. (i == t ? &#039;%1*&#039; : &#039;%2*&#039;) . &#039;%*&#039; . (i == t ? &#039; %#TabLineSel# &#039; : &#039;%#TabLine#&#039;)
      let file = (i == t ? fnamemodify(bufname(bl[wn - 1]), &#039;:p&#039;) : fnamemodify(bufname(bl[wn - 1]), &#039;:t&#039;) )|if file == &#039;&#039;|let file = &#039;[No Name]&#039;|endif
      let s .= i.&#039; &#039;. file .(i == t ? &#039; &#039; : &#039;&#039;)|let i += 1
    endwhile
    let s .= &#039;%T%#TabLineFill#%=&#039; . (tabpagenr(&#039;$&#039;) &gt; 1 ? &#039;%999XX&#039; : &#039;X&#039;)
    return s
  endfunction
&nbsp;
  " FUNCTION - DiffWithSaved {{{3
  " Diff with saved version of the file
  function! s:DiffWithSaved()
    let filetype=&amp;ft
    diffthis
    vnew | r # | normal! 1Gdd
    diffthis
    exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
  endfunction
  com! DiffSaved call s:DiffWithSaved()
&nbsp;
  " FUNCTION - ShowWhitespace() {{{3
  function! ShowWhitespace(flags)
    let bad = &#039;&#039;
    let pat = []
    for c in split(a:flags, &#039;\zs&#039;)
      if c == &#039;e&#039;
        call add(pat, &#039;\s\+$&#039;)
      elseif c == &#039;i&#039;
        call add(pat, &#039;^\t*\zs \+&#039;)
      elseif c == &#039;s&#039;
        call add(pat, &#039; \+\ze\t&#039;)
      elseif c == &#039;t&#039;
        call add(pat, &#039;[^\t]\zs\t\+&#039;)
      else
        let bad .= c
      endif
    endfor
&nbsp;
    if len(pat) &gt; 0
      let s = join(pat, &#039;\|&#039;)
      exec &#039;syntax match ExtraWhitespace "&#039;.s.&#039;" containedin=ALL&#039;
    else
      syntax clear ExtraWhitespace
    endif
&nbsp;
    if len(bad) &gt; 0|echo &#039;ShowWhitespace ignored: &#039;.bad|endif
  endfunction
&nbsp;
  " FUNCTION - ToggleShowWhitespace {{{3
  " I use this all the time, it&#039;s mapped to , ts
  function! ToggleShowWhitespace()
    if !exists(&#039;b:ws_show&#039;)|let b:ws_show = 0|endif
    if !exists(&#039;b:ws_flags&#039;)|let b:ws_flags = &#039;est&#039;|endif
    let b:ws_show = !b:ws_show
    if b:ws_show|call ShowWhitespace(b:ws_flags)|else|call ShowWhitespace(&#039;&#039;)|endif
  endfunction
&nbsp;
endif
&nbsp;
" DYNAMIC SETTINGS / COLORS / TERMINAL {{{1
" ================================================================================================================================================================
&nbsp;
" DISABLE MOUSE NO GOOEYS {{{3
if has(&#039;mouse&#039;)|set mouse=|endif
&nbsp;
" SET TITLESTRING {{{3
if has(&#039;title&#039;)|set titlestring=%t%(\ [%R%M]%)|endif
&nbsp;
" SET TABLINE {{{3
if exists("*s:MyTabL")|set tabline=%!MyTabL()|endif
&nbsp;
let g:vimsyn_folding=&#039;af&#039;
&nbsp;
"DISABLE FILETYPE-SPECIFIC MAPS {{{3
let no_plugin_maps=1
&nbsp;
"}}}1 DYNAMIC SETTINGS / COLORS / TERMINAL
&nbsp;
" OPTIONS "{{{1
" ===========================================================================================================================================================================
&nbsp;
" BACKUP, FILE OPTIONS {{{2
" ================================================================================
set backup        " Make a backup before overwriting a file.  Leave it around after the file has been successfully written.
set backupcopy=auto " When writing a file and a backup is made, this option tells how it&#039;s done.  This is a comma separated list of words. - value: yes,no,auto - no:rename the file and write a new one
&nbsp;
set swapfile
set swapsync=fsync
&nbsp;
"}}}2 BACKUP, FILE OPTIONS
&nbsp;
" BASIC SETTINGS "{{{2
" ================================================================================
set nocompatible    " vim, not vi.. must be first, because it changes other options as a side effect
set modeline
&nbsp;
set statusline=%M%h%y\ %t\ %F\ %p%%\ %l/%L\ %=[%{&amp;ff},%{&amp;ft}]\ [a=\%03.3b]\ [h=\%02.2B]\ [%l,%v]
set title titlelen=150 titlestring=%(\ %M%)%(\ (%{expand(\"%:p:h\")})%)%(\ %a%)\ -\ %{v:servername}
&nbsp;
"set tags=tags;/      " search recursively up for tags
&nbsp;
set ttyfast        " we have a fast terminal
set scrolljump=5    " when scrolling up down, show at least 5 lines
"set ttyscroll=999    " make vim redraw screen instead of scrolling when there are more than 3 lines to be scrolled
&nbsp;
"set tw=500        " default textwidth is a max of 5
&nbsp;
set undolevels=10    " 50 undos - saved in memory
set updatecount=250    " switch every 250 chars, save swap
&nbsp;
set whichwrap+=b,s,&lt;,&gt;,h,l,[,]      " backspaces and cursor keys wrap to
"set wildignore+=*.o,*~,.lo,*.exe,*.bak  " ignore object files
"set wildmenu              " menu has tab completion
"set wildmode=longest:full        " *wild* mode
set nowrap
&nbsp;
set autoindent smartindent    " auto/smart indent
&nbsp;
set autoread          " watch for file changes
&nbsp;
set backspace=indent,eol,start  " backspace over all kinds of things
&nbsp;
set cmdheight=1          " command line two lines high
set complete=.,w,b,u,U,t,i,d  " do lots of scanning on tab completion
set cursorline          " show the cursor line
"set enc=utf-8 fenc=utf-8    " utf-8
&nbsp;
set history=3000        " keep 3000 lines of command line history
&nbsp;
set keywordprg=TERM=mostlike\ man\ -s\ -Pless
&nbsp;
set laststatus=2
&nbsp;
"set lazyredraw          " don&#039;t redraw when don&#039;t have to
set linebreak          " wrap at &#039;breakat&#039; instead of last char
set magic            " Enable the "magic"
&nbsp;
set maxmem=25123  " 24 MB -  max mem in Kbyte to use for one buffer.  Max is 2000000
&nbsp;
set noautowrite          " don&#039;t automagically write on :next
&nbsp;
set noexpandtab          " no expand tabs to spaces"
set noruler          " show the line number on the bar
set nospell
set nohidden          " close the buffer when I close a tab (I use tabs more than buffers)
&nbsp;
set noerrorbells visualbell t_vb= " Disable ALL bells
&nbsp;
set number          " line numbers
&nbsp;
set pastetoggle=&lt;F11&gt;
&nbsp;
set scrolloff=3        " keep at least 3 lines above/below
set shiftwidth=3      " shift width
&nbsp;
set showcmd          " Show us the command we&#039;re typing
set showfulltag        " show full completion tags
set showmode        " show the mode all the time
&nbsp;
set sidescroll=2      " if wrap is off, this is fasster for horizontal scrolling
set sidescrolloff=2      "keep at least 5 lines left/right
&nbsp;
set noguipty
&nbsp;
set splitright
set splitbelow
&nbsp;
set restorescreen=on " restore screen contents when vim exits -  disable withset t_ti= t_te=
&nbsp;
"set sessionoptions=word,blank,buffers,curdir,folds,globals,help,localoptions,resize,sesdir,tabpages,winpos,winsize
set winheight=25
set winminheight=1  " minimal value for window height
"set winheight=30  " set the minimal window height
set equalalways    " all the windows are automatically sized same
set eadirection=both  " only equalalways for horizontally split windows
&nbsp;
set hlsearch
&nbsp;
set laststatus=2
&nbsp;
set tabstop=4
set softtabstop=4
&nbsp;
set shiftwidth=3
set switchbuf=usetab
&nbsp;
set commentstring=#%s
&nbsp;
set tabpagemax=55
set showtabline=2    " 2 always, 1 only if multiple tabs
set smarttab      " tab and backspace are smart
&nbsp;
set foldmethod=marker
set foldenable
set foldcolumn=6        " the blank left-most bar left of the numbered lines
&nbsp;
set incsearch          " incremental search
"set ignorecase          " search ignoring case
set sc              " override &#039;ignorecase&#039; when pattern has upper case characters
set smartcase          " Ignore case when searching lowercase
&nbsp;
set showmatch          " show matching bracket
set diffopt=filler,iwhite    " ignore all whitespace and sync"
set stal=2
&nbsp;
"}}}1 OPTIONS
&nbsp;
" PLUGIN SETTINGS {{{1
" ================================================================================================================================================================
" Settings for :TOhtml "{{{3
let html_number_lines=1
let html_use_css=1
let use_xhtml=1
"}}}1 PLUGIN SETTINGS
&nbsp;
" COLORSCHEME IF MORE THAN 2 COLORS lol {{{1
" ================================================================================================================================================================
if &amp;t_Co &gt; 2
&nbsp;
  if &amp;term =~ "256"
&nbsp;
    set bg=dark t_Co=256 vb
    let &amp;t_vb="\&lt;Esc&gt;[?5h\&lt;Esc&gt;[?5l"  " flash screen for visual bell
&nbsp;
    if filereadable(expand("$VIMRUNTIME/colors/askapachecode.vim"))
      colorscheme askapachecode
    elseif filereadable(expand("$HOME/.vim/colors/askapachecode.vim"))
      colorscheme askapachecode
    else
      colorscheme default
    endif
&nbsp;
    filetype indent plugin on
    syntax on
&nbsp;
  else
    " things like cfdisk, crontab -e, visudo, vless, etc.
    set term=linux
    set t_Co=8
    syntax off
    filetype indent plugin off
&nbsp;
  endif
&nbsp;
endif
&nbsp;
"}}}1
&nbsp;
" AUTOCOMMANDS "{{{1
" ===========================================================================================================================================================================
"if !exists(":DiffOrig") | command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis | endif
&nbsp;
" auto load extensions for different file types
if has(&#039;autocmd&#039;)
&nbsp;
  if !exists("autocommands_loaded")
    let autocommands_loaded = 1
&nbsp;
    " JUMP TO LAST POS {{{3
    " When editing a file, always jump to the last known cursor position. Don&#039;t do it when the position is invalid or when inside an event handler
    " (happens when dropping a file on gvim). Also don&#039;t do it when the mark is in the first line, that is the default position when opening a file.
    au BufReadPost * if line("&#039;\"") &gt; 1 &amp;&amp; line("&#039;\"") &lt;= line("$") | exe "normal! g`\"" | endif
&nbsp;
    " CLEARMATCHES ON BUFWINLEAVE {{{3
    au BufWinLeave * call clearmatches()
&nbsp;
    " STRIP TRAILING WHITESPACE {{{3
    autocmd BufWritePre *.cpp,*.hpp,*.i :call StripTrailingWhitespace()
&nbsp;
    " AA_ZZZ LAST MOD {{{3
    autocmd BufWritePre,FileWritePre,TabLeave zzz_askapache-bash.sh ks|call LastModAAZZZ()|&#039;s
&nbsp;
    " SET VIM SETTINGS FOR AA_ZZZ SCRIPTS {{{3
    autocmd BufRead /etc/ZZZ/*.sh,.bash_profile,.bash_login,.bashrc,.bash_login_user,.bash_logout setlocal ts=4 sw=3 ft=sh foldmethod=marker tw=500 foldcolumn=7
&nbsp;
    " INSERT CURRENT DATE AND TIME IN A *.SH FILE WHEN WRITING IT {{{3
    autocmd BufWritePre,FileWritePre *.*   ks|call LastMod()|&#039;s
&nbsp;
    " IMPROVE LEGIBILITY {{{3
    autocmd BufRead quickfix setlocal nobuflisted wrap number
&nbsp;
    " SAVE BACKUPFILE AS BACKUPDIR/FILENAME-06-13-1331 {{{3
    autocmd BufWritePre * let &amp;bex = strftime("-%m-%d-%H%M")
&nbsp;
    " TMUX FILETYPE {{{3
    autocmd BufRead tmux.conf,.tmux.conf,.tmux*,*/tmux-sessions/* setlocal filetype=tmux foldmethod=marker
&nbsp;
    " APACHE2 FILETYPE {{{3
    autocmd BufRead /opt/a*/conf/*,/etc/httpd/*.conf setlocal filetype=apache
&nbsp;
    " SH FILETYPES {{{3
    autocmd BufRead *.sh,*.cron,*.bash setlocal filetype=sh
&nbsp;
    " SYSLOG-NG FILETYPE {{{3
    autocmd BufRead syslog-ng.conf setlocal filetype=syslog-ng
&nbsp;
    " COMMENTSTRING FOR VIM "{{{3
    au FileType vim setlocal commentstring="%s
&nbsp;
    " COMMENTSTRING FOR XDEFAULTS "{{{3
    au FileType xdefaults setlocal foldmethod=marker foldlevel=2 commentstring=!%s
&nbsp;
    " VIMRC {{{3
    augroup vimrc
      au BufReadPre * setlocal foldmethod=indent
      au BufWinEnter * if &amp;fdm == &#039;indent&#039; | set foldmethod=manual | endif
      au BufRead *.vim,vimrc,*.vimrc set filetype=vim ts=3 sw=3 tw=500 foldmethod=marker foldcolumn=6
    augroup END
&nbsp;
    " AUTOMKVIEWS {{{3
    " Warning - this will save your settings for each file you edit and restore those settings when opened again - can fill up quick
    au BufWinLeave *.sh,*.conf,*.vim,*.c,*.txt,.htaccess,*.cgi,*.php,*.html,*.conf,vimrc mkview
    au BufWinEnter *.sh,*.conf,*.vim,*.c,*.txt,.htaccess,*.cgi,*.php,*.html,*.conf,vimrc silent loadview
    " }}}3
&nbsp;
    " MAN RUNTIME - TODO REPLACE WITH TMUXES CTRL-M BINDING {{{3
    " Lets you type :Man anymanpage and it will load in vim, color-coded and searchable
    "runtime ftplugin/man.vim
&nbsp;
  endif
&nbsp;
endif
"}}}1
&nbsp;
" MAPS "{{{1
" ===========================================================================================================================================================================
&nbsp;
" FUNCTION MAPS {{{2
" ---------------------------------
" APPEND MODELINE {{{3
map &lt;silent&gt; &lt;LocalLeader&gt;ml :call AppendModeline()&lt;CR&gt;
&nbsp;
" SHOW WHITESPACE {{{3
nnoremap &lt;LocalLeader&gt;ts :call ToggleShowWhitespace()&lt;CR&gt;
&nbsp;
" SUDO A WRITE {{{3
command! W :execute &#039;:silent w !sudo tee % &gt; /dev/null&#039; | :edit!
"cmap w!! %!sudo tee &gt; /dev/null %
" :w !sudo tee &gt; /dev/null %
&nbsp;
" SET TABLINE {{{3
" My Personal Fav, inserts last-modified manually on current line when you press &lt;F12&gt; key
" call setline(1, printf(&#039;%sUpdated: %s by %s@%s&#039;, printf(&amp;commentstring, &#039; &#039;), strftime("%c"), expand("$LOGNAME"), hostname()))
if exists("*s:LastModNow")
  map &lt;silent&gt; &lt;F12&gt; :call LastModNow()&lt;CR&gt;
endif
&nbsp;
" RELOAD VIMRC FILES {{{3
map &lt;LocalLeader&gt;. :mkview&lt;CR&gt;:unlet! AskApacheLoaded autocommands_loaded&lt;CR&gt;:mapclear&lt;CR&gt;:source /etc/vimrc&lt;CR&gt;:echoerr &#039;VIMRC RELOADED&#039;&lt;CR&gt;
&nbsp;
" SCROLLING MAPS {{{3
map &lt;PageDown&gt; :set scroll=0&lt;CR&gt;:set scroll^=2&lt;CR&gt;:set scroll-=1&lt;CR&gt;&lt;C-D&gt;:set scroll=0&lt;CR&gt;
map &lt;PageUp&gt; :set scroll=0&lt;CR&gt;:set scroll^=2&lt;CR&gt;:set scroll-=1&lt;CR&gt;&lt;C-U&gt;:set scroll=0&lt;CR&gt;
nnoremap &lt;silent&gt; &lt;PageUp&gt; &lt;C-U&gt;&lt;C-U&gt;
vnoremap &lt;silent&gt; &lt;PageUp&gt; &lt;C-U&gt;&lt;C-U&gt;
inoremap &lt;silent&gt; &lt;PageUp&gt; &lt;C-\&gt;&lt;C-O&gt;&lt;C-U&gt;&lt;C-\&gt;&lt;C-O&gt;&lt;C-U&gt;
nnoremap &lt;silent&gt; &lt;PageDown&gt; &lt;C-D&gt;&lt;C-D&gt;
vnoremap &lt;silent&gt; &lt;PageDown&gt; &lt;C-D&gt;&lt;C-D&gt;
inoremap &lt;silent&gt; &lt;PageDown&gt; &lt;C-\&gt;&lt;C-O&gt;&lt;C-D&gt;&lt;C-\&gt;&lt;C-O&gt;&lt;C-D&gt;
"}}}3
&nbsp;
" KEY MAPS {{{2
" physically map keys to produce different key, type CTRL-V in insert mode followed by any key to see how vim sees it
" ----------------------------------------
imap &lt;ESC&gt;[8~ &lt;End&gt;
map &lt;ESC&gt;[8~ &lt;End&gt;
&nbsp;
imap &lt;ESC&gt;[7~ &lt;Home&gt;
map &lt;ESC&gt;[7~ &lt;Home&gt;
&nbsp;
" Basic Maps  {{{2
" ----------------------------------------
" TOGGLE PASTE MODE {{{3
map &lt;LocalLeader&gt;pm :set nonumber! foldcolumn=0&lt;CR&gt;
&nbsp;
" REINDENT FILE {{{3
map &lt;LocalLeader&gt;ri G=gg&lt;CR&gt;
&nbsp;
" CLEAR SPACES AT END OF LINE {{{3
map &lt;LocalLeader&gt;cs :%s/\s\+$//e&lt;CR&gt;
&nbsp;
" Y YANKS FROM CURSOR TO $ {{{3
map Y y$
&nbsp;
" DON&#039;T USE EX MODE, USE Q FOR FORMATTING {{{3
map Q gq
map! ^H ^?
&nbsp;
" NEXT SEARCH RESULT {{{3
map &lt;silent&gt; &lt;LocalLeader&gt;cn :cn&lt;CR&gt;
&nbsp;
" WRAP? {{{3
map &lt;silent&gt; &lt;LocalLeader&gt;ww :ww
&nbsp;
" ERR INSERTION {{{3
"map &lt;silent&gt; &lt;LocalLeader&gt;e &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s&#039;, &#039;_err "$0 $FUNCNAME:$LINENO FAILED WITH ARGS= $*"&#039;)&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
&nbsp;
" CUSTOM LINES FOR CODING {{{3
map &lt;silent&gt; &lt;LocalLeader&gt;l1 &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s%s&#039;, printf(&amp;commentstring, &#039; &#039;), repeat(&#039;=&#039;, 160))&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
map &lt;silent&gt; &lt;LocalLeader&gt;l2 &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s%s&#039;, printf(&amp;commentstring, &#039; &#039;), repeat(&#039;=&#039;, 80))&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
map &lt;silent&gt; &lt;LocalLeader&gt;l3 &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s%s&#039;, printf(&amp;commentstring, &#039; &#039;), repeat(&#039;-&#039;, 40))&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
map &lt;silent&gt; &lt;LocalLeader&gt;l4 &lt;Home&gt;A&lt;C-R&gt;=printf(&#039;%s%s&#039;, printf(&amp;commentstring, &#039; &#039;), repeat(&#039;-&#039;, 20))&lt;CR&gt;&lt;Home&gt;&lt;Esc&gt;
&nbsp;
" CHANGE DIRECTORY TO THAT OF CURRENT FILE {{{3
nmap &lt;LocalLeader&gt;cd :cd%:p:h&lt;CR&gt;
&nbsp;
" CHANGE LOCAL DIRECTORY TO THAT OF CURRENT FILE {{{3
nmap &lt;LocalLeader&gt;lcd :lcd%:p:h&lt;CR&gt;
&nbsp;
" TOGGLE WRAPPING {{{3
nmap &lt;LocalLeader&gt;ww :set wrap!&lt;CR&gt;
nmap &lt;LocalLeader&gt;wo :set wrap&lt;CR&gt;
&nbsp;
" TABS "{{{2
" ---------------------------------
&nbsp;
" CREATE A NEW TAB {{{3
map &lt;LocalLeader&gt;tc :tabnew %&lt;CR&gt;
&nbsp;
" LAST TAB {{{3
map &lt;LocalLeader&gt;t&lt;Space&gt; :tablast&lt;CR&gt;
&nbsp;
" CLOSE A TAB {{{3
map &lt;LocalLeader&gt;tk :tabclose&lt;CR&gt;
&nbsp;
" NEXT TAB {{{3
map &lt;LocalLeader&gt;tn :tabnext&lt;CR&gt;
&nbsp;
" PREVIOUS TAB {{{3
map &lt;LocalLeader&gt;tp :tabprev&lt;CR&gt;
&nbsp;
" FOLDS   "{{{2
" ---------------------------------
" Fold with paren begin/end matching
nmap F zf%
&nbsp;
" When I use ,sf - return to syntax folding with a big foldcolumn
nmap &lt;LocalLeader&gt;sf :set foldcolumn=6 foldmethod=syntax&lt;cr&gt;
"}}}2
&nbsp;
"}}}1
&nbsp;
" HILITE "{{{1
" ===========================================================================================================================================================================
hi NonText cterm=NONE ctermfg=NONE
hi Search cterm=bold ctermbg=99 ctermfg=17
"}}}
&nbsp;
</pre>


<h2>Colorscheme</h2>
<p>Here is a colorscheme file optimized for 256 colors.  It will work if saved in <code>~/.vim/colors/askapachecode.vim</code> or likewise in your runtimepath.  Additionally, you could just paste it in the bottom of the above vimrc.  The code really needs to be cleaned up, but it looks awesome.</p>
<p>Download - <a href='http://uploads.askapache.com/2012/02/askapachecode.txt'>askapachecode - 256 Colors Vim Colorscheme</a></p>
<p><code>~/.vim/colors/askapachecode.vim</code></p>
<pre>
" Vim color file -- askapachecode
" Maintainer: AskApache &lt;webmaster@askapache.com&gt;
" Updated: Wed Feb 22 14:10:54 2012 by galileo@galileo
&nbsp;
set background=dark
hi clear
&nbsp;
if exists("syntax_on")|syntax reset|endif
&nbsp;
let g:colors_name="askapachecode"
&nbsp;
" Vim &gt;= 7.0 specific colors
if version &gt;= 700
 hi CursorLine ctermbg=236
 hi CursorColumn ctermbg=236
 hi MatchParen ctermfg=157 ctermbg=237 cterm=bold
 hi Pmenu ctermfg=255 ctermbg=238
 hi PmenuSel ctermfg=0 ctermbg=148
endif
&nbsp;
" General colors
hi Cursor ctermbg=241
hi Normal ctermfg=253 ctermbg=232
hi NonText ctermfg=244 ctermbg=235
hi LineNr ctermfg=244 ctermbg=232
hi StatusLine ctermfg=253 ctermbg=238 cterm=italic
hi StatusLineNC ctermfg=246 ctermbg=238
hi VertSplit ctermfg=238 ctermbg=238
hi Folded ctermbg=4 ctermfg=248
hi Title ctermfg=254 cterm=bold
hi Visual ctermfg=254 ctermbg=4
hi SpecialKey ctermfg=244 ctermbg=236
&nbsp;
hi pythonOperator ctermfg=103
&nbsp;
hi Search cterm=NONE  
&nbsp;
" basic highlight groups (:help highlight-groups) {{{1
&nbsp;
" text {{{2
hi Normal ctermfg=white ctermbg=black cterm=NONE
hi Folded ctermfg=lightgray ctermbg=black cterm=underline
hi LineNr ctermfg=darkgray ctermbg=NONE cterm=NONE
hi Directory ctermfg=cyan ctermbg=NONE cterm=NONE
hi NonText ctermfg=yellow ctermbg=NONE cterm=NONE
hi SpecialKey ctermfg=green ctermbg=NONE cterm=NONE
&nbsp;
hi DiffAdd ctermfg=white ctermbg=darkblue cterm=NONE
hi DiffChange ctermfg=black ctermbg=darkmagenta cterm=NONE
hi DiffDelete ctermfg=black ctermbg=red cterm=bold
hi DiffText ctermfg=white ctermbg=green cterm=bold
&nbsp;
" borders / separators / menus {{{2
hi FoldColumn ctermfg=lightgray ctermbg=darkgray cterm=NONE
hi SignColumn ctermfg=lightgray ctermbg=darkgray cterm=NONE
hi Pmenu ctermfg=white ctermbg=darkgray cterm=NONE
hi PmenuSel ctermfg=white ctermbg=lightblue cterm=NONE
hi PmenuSbar ctermfg=black ctermbg=black cterm=NONE
hi PmenuThumb ctermfg=gray ctermbg=gray cterm=NONE
&nbsp;
hi StatusLine ctermfg=black ctermbg=white cterm=bold
hi StatusLineNC ctermfg=darkgray ctermbg=white cterm=NONE
hi WildMenu ctermfg=white ctermbg=darkblue cterm=bold
hi VertSplit ctermfg=white ctermbg=white cterm=NONE
&nbsp;
if &amp;t_Co == 256|hi TabLine ctermfg=15 ctermbg=242 term=underline|else|hi TabLine ctermfg=grey ctermbg=white term=underline|endif
"hi TabLine ctermfg=white ctermbg=white cterm=NONE
hi TabLineFill ctermfg=grey ctermbg=white cterm=NONE
"hi TabLineSel ctermfg=black ctermbg=green cterm=NONE
hi TabLineSel ctermfg=green ctermbg=black term=bold
"hi TabLineSel term=bold cterm=bold
"hi TabLineFill term=reverse cterm=reverse 
"hi TabLine term=underline cterm=underline ctermfg=15 ctermbg=242
&nbsp;
"hi Menu
"hi Scrollbar
"hi Tooltip
&nbsp;
" cursor / dynamic / other {{{2
hi Cursor ctermfg=black ctermbg=white cterm=NONE
hi CursorIM ctermfg=black ctermbg=white cterm=reverse
hi CursorLine ctermfg=NONE ctermbg=NONE cterm=NONE
hi CursorColumn ctermfg=NONE ctermbg=NONE cterm=NONE
&nbsp;
hi Visual ctermfg=white ctermbg=lightblue cterm=NONE
hi IncSearch ctermfg=white ctermbg=yellow cterm=NONE
hi Search ctermfg=white ctermbg=darkgreen cterm=NONE
&nbsp;
" LISTINGS / MESSAGES {{{2
hi ModeMsg ctermfg=yellow ctermbg=NONE cterm=NONE
hi Title ctermfg=red ctermbg=NONE cterm=bold
hi Question ctermfg=green ctermbg=NONE cterm=NONE
hi MoreMsg ctermfg=green ctermbg=NONE cterm=NONE
hi ErrorMsg ctermfg=white ctermbg=red cterm=bold
hi WarningMsg ctermfg=yellow ctermbg=NONE cterm=bold
&nbsp;
hi Directory term=bold ctermfg=4 "{{{
hi ErrorMsg term=standout ctermfg=15 ctermbg=1  
hi IncSearch term=reverse cterm=reverse 
hi Search term=NONE ctermfg=255 ctermbg=135
hi MoreMsg term=bold ctermfg=2  
hi ModeMsg term=bold cterm=bold 
hi LineNr term=underline ctermfg=244 ctermbg=232  
hi Question term=standout ctermfg=2  
hi StatusLine term=bold,reverse cterm=italic ctermfg=253 ctermbg=238   
hi StatusLineNC term=reverse cterm=reverse ctermfg=246 ctermbg=238  
hi VertSplit term=reverse cterm=reverse ctermfg=238 ctermbg=238  
hi Title term=bold cterm=bold ctermfg=254  
hi Visual term=reverse ctermfg=254 ctermbg=4  
hi VisualNOS term=bold,underline cterm=bold,underline
hi WarningMsg term=standout ctermfg=1 
hi WildMenu term=standout ctermfg=0 ctermbg=11  
hi Folded term=standout cterm=BOLD ctermfg=7 ctermbg=27
hi FoldColumn term=NONE cterm=NONE ctermfg=75 ctermbg=16
hi IncSearch term=bold,underline cterm=bold,underline ctermfg=7 ctermbg=9
hi DiffAdd term=bold ctermbg=12 
hi DiffChange term=bold ctermbg=13 
hi DiffDelete term=bold ctermfg=12 ctermbg=14   
hi DiffText term=reverse cterm=bold ctermbg=9  
hi SpellBad term=reverse ctermbg=9  
hi SpellCap term=reverse ctermbg=12  
hi SpellRare term=reverse ctermbg=13  
hi SpellLocal term=underline ctermbg=14  
hi Pmenu ctermfg=255 ctermbg=238  
hi PmenuSel ctermfg=0 ctermbg=148  
hi PmenuSbar ctermbg=7 
hi PmenuThumb cterm=reverse 
hi TabLine term=underline cterm=underline ctermfg=0 ctermbg=7  
hi TabLineSel term=bold cterm=bold 
hi TabLineFill term=reverse cterm=reverse 
hi CursorLine term=underline cterm=bold ctermbg=234
hi Cursor ctermbg=241 
hi MatchParen term=reverse cterm=bold ctermfg=157 ctermbg=237   
hi Error term=reverse ctermfg=15 ctermbg=9  
&nbsp;
" :hi TabLineSel|hi TabLineFill|hi TabLine
"hi TabLineSel term=bold cterm=bold 
"hi TabLineFill term=reverse cterm=reverse 
"hi TabLine term=underline cterm=underline ctermfg=15 ctermbg=242 
hi ExtraWhitespace ctermbg=red
hi Comment term=none ctermfg=darkgrey 
hi Constant term=underline ctermfg=Magenta 
hi Special term=bold ctermfg=DarkMagenta 
hi Identifier term=underline cterm=bold ctermfg=Cyan 
hi Statement term=bold ctermfg=Yellow 
hi PreProc term=underline ctermfg=LightBlue 
hi Type term=underline ctermfg=LightGreen 
hi Repeat term=underline ctermfg=White 
hi Operator ctermfg=Red 
hi Ignore ctermfg=black 
hi Error term=reverse ctermbg=Red ctermfg=White 
hi Todo term=standout ctermbg=Yellow ctermfg=Black 
&nbsp;
" COMMON GROUPS THAT LINK TO DEFAULT HIGHLIGHTING.
&nbsp;
hi Function ctermfg=85
hi String ctermfg=204
hi Statement term=bold cterm=bold ctermfg=81
hi Function term=bold cterm=bold ctermfg=32
hi Number ctermfg=129
hi Conditional term=bold cterm=bold ctermfg=47
hi Special term=underline ctermfg=191
hi Normal ctermfg=7
hi PreProc ctermfg=141
" Syntax highlighting
hi Comment ctermfg=244
hi Todo ctermfg=245
hi Boolean ctermfg=148
hi String ctermfg=148
hi Identifier ctermfg=148
hi Function ctermfg=124
hi Type ctermfg=103
hi Statement ctermfg=103
hi Keyword ctermfg=81
hi Constant ctermfg=81
hi Number ctermfg=81
hi Special ctermfg=81
hi PreProc ctermfg=230
" Code-specific colors
 
&nbsp;
" SYNTAX HIGHLIGHTING GROUPS (:HELP GROUP-NAME) {{{2
hi FoldColumn ctermbg=0 ctermfg=2
hi Folded cterm=none ctermfg=2
hi NonText cterm=NONE ctermfg=NONE 
hi StatusLine ctermfg=black ctermbg=White cterm=bold
hi StatusLineNC ctermfg=White ctermbg=green cterm=NONE
hi CursorLine cterm=bold term=bold
&nbsp;
" FINAL THOUGHTS "{{{2
"syn region myFold start="{" end="}" transparent fold
hi Search term=reverse ctermfg=0 ctermbg=11
hi LineNr term=underline ctermfg=244 ctermbg=232
hi MatchParen ctermfg=15 ctermbg=242
hi String ctermfg=10
hi Constant ctermfg=14
hi Identifier ctermfg=14
hi Operator ctermfg=13
hi NonText cterm=NONE ctermfg=NONE
hi Search cterm=bold ctermbg=99 ctermfg=17
</pre>


<h2>Additional Resources</h2>
<ol>
<li><a href="http://spf13.com/post/perfect-vimrc-vim-config-file">The perfect .vimrc vim config file</a></li>
</ol><p><a href="http://www.askapache.com/linux/fast-vimrc.html"></a><a href="http://www.askapache.com/linux/fast-vimrc.html">Optimized Vimrc with 256 Colorscheme</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/linux/fast-vimrc.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Mod_Rewrite Security</title>
		<link>http://www.askapache.com/security/mod_rewrite.html</link>
		<comments>http://www.askapache.com/security/mod_rewrite.html#comments</comments>
		<pubDate>Sat, 18 Feb 2012 06:54:18 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[RewriteCond]]></category>
		<category><![CDATA[RewriteRule]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=7045</guid>
		<description><![CDATA[<p><a class="hs hs13" href="http://www.askapache.com/security/mod_rewrite.html" title="Mod_Rewrite Artwork"></a>These are a few of the mod_rewrite uses that <a href="http://blogsecurity.net/">BlogSecurity</a> declared <strong>pushed the boundaries of Mod_Rewrite!</strong>  Some of these snippets are quite exotic and unlike anything you may have seen before, also only for those who understand them as they can kill a website pretty quick.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/security/mod_rewrite.html"></a><a href="http://www.askapache.com/security/mod_rewrite.html"><cite>AskApache.com</cite></a></p><p>Here are some <a href="http://www.askapache.com/htaccess/htaccess.html" title="Htaccess Tutorial">specific htaccess</a> examples taken mostly from my WordPress Password Protection plugin, which does alot more than password protection as you will see from the following mod_rewrite examples. These are a few of the mod_rewrite uses that <a href="http://blogsecurity.net/">BlogSecurity</a> declared <strong>pushed the boundaries of Mod_Rewrite!</strong>  Some of these snippets are quite exotic and unlike anything you may have seen before, also only for those who understand them as they can kill a website pretty quick.</p>

<h4>Directory Protection</h4>
<p>Enable the DirectoryIndex Protection, preventing directory index listings and defaulting. [<a href="/htaccess/htaccess.html">Disable</a>]</p>
<pre>
Options -Indexes
DirectoryIndex index.html index.php /index.php
</pre>

<h4>Password Protect wp-login.php</h4>
<p>Requires a valid user/pass to access the login page[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
&lt;Files wp-login.php&gt;
Order Deny,Allow
Deny from All
Satisfy Any
AuthName "Protected By AskApache"
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;/Files&gt;
</pre>


<h4>Password Protect wp-admin</h4>
<p>Requires a valid user/pass to access any non-static (css, js, images) file in this directory.[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
Options -ExecCGI -Indexes +FollowSymLinks -Includes
DirectoryIndex index.php /index.php
Order Deny,Allow
Deny from All
Satisfy Any
AuthName "Protected By AskApache"
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$"&gt;
Allow from All
&lt;/FilesMatch&gt;
&lt;FilesMatch "(async-upload)\.php$"&gt;
&lt;IfModule mod_security.c&gt;
SecFilterEngine Off
&lt;/IfModule&gt;
Allow from All
&lt;/FilesMatch&gt;
</pre>

<h4>Protect wp-content</h4>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-content/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !^.+flexible-upload-wp25js.php$
RewriteCond %{REQUEST_FILENAME} ^.+\.(php|html|htm|txt)$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Protect wp-includes</h4>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-includes/.*$ [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /wp-includes/js/.+/.+\ HTTP/ [NC]
RewriteCond %{REQUEST_FILENAME} ^.+\.php$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Common Exploits</h4>
<p>Block common exploit requests with 403 Forbidden. These can help alot, may break some plugins. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ///.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\=?(http|ftp|ssl|https):/.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\?.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(asp|ini|dll).*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(htpasswd|htaccess|aahtpasswd).*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Stop Hotlinking</h4>
<p>Denies any request for static files (images, css, etc) if referrer is not local site or empty. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_REFERER} !^http://www.askapache.com.*$ [NC]
RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]
</pre>

<h4>Safe Request Methods</h4>
<p>Denies any request not using <a href="http://www.askapache.com/online-tools/request-method-scanner/">GET,PROPFIND,POST,OPTIONS,PUT,HEAD</a>[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST|PROPFIND|OPTIONS|PUT)$ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Forbid Proxies</h4>
<p>Denies any POST Request using a Proxy Server. Can still access site, but not comment.  See <a href="http://perishablepress.com/press/2008/04/20/how-to-block-proxy-servers-via-htaccess/">Perishable Press</a> [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Real wp-comments-post.php</h4>
<p>Denies any POST attempt made to a non-existing wp-comments-post.php[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>HTTP PROTOCOL</h4>
<p>Denies any badly formed HTTP PROTOCOL in the request, 0.9, 1.0, and 1.1 only[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>SPECIFY CHARACTERS</h4>
<p>Denies any request for a url containing characters other than "a-zA-Z0-9.+/-?=&amp;"  - REALLY helps but may break your site depending on your links. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;amp;]+\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>BAD Content Length</h4>
<p>Denies any POST request that doesnt have a Content-Length Header[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Length} ^$
RewriteCond %{REQUEST_URI} !^/(wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>BAD Content Type</h4>
<p>Denies any POST request with a content type other than application/x-www-form-urlencoded|multipart/form-data[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Type} !^(application/x-www-form-urlencoded|multipart/form-data.*(boundary.*)?)$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Missing HTTP_HOST</h4>
<p>Denies requests that dont contain a HTTP HOST Header.[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_HOST} ^$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Bogus Graphics Exploit</h4>
<p>Denies obvious exploit using bogus graphics[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{HTTP:Content-Disposition} \.php [NC]
RewriteCond %{HTTP:Content-Type} image/.+ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>No UserAgent, Not POST</h4>
<p>Denies POST requests by blank user-agents.  May prevent a small number of visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>No Referer, No Comment</h4>
<p>Denies any comment attempt with a blank HTTP_REFERER field, highly indicative of spam.  May prevent some visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteCond %{HTTP_REFERER} ^-?$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Trackback Spam</h4>
<p>Denies obvious trackback spam.  See Holy Shmoly! [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^.*(opera|mozilla|firefox|msie|safari).*$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.+/trackback/?\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Map all URIs except those corresponding to existing files to a handler</h4>
<pre>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule . /script.php
</pre>

<h4>Map any request to a handler</h4>
<p>In the case where all URIs should be sent to the same place (including potentially requests for static content) the method to use depends on the type of the handler. For php scripts, use:
For other handlers such as php scripts, use:</p>
<pre>
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php
</pre>

<h4>And for CGI scripts:</h4>
<pre>
ScriptAliasMatch .* /var/www/script.cgi
</pre>

<h4>Map URIs corresponding to existing files to a handler instead</h4>
<pre>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php
</pre>
<p>If the existing files you wish to have handled by your script have a common set of file extensions distinct from that of the hander, you can bypass mod_rewrite and use instead mod_actions. Let's say you want all .html and .tpl files to be dealt with by your script:</p>
<pre>
Action foo-action /script.php
AddHandler foo-action html tpl
</pre>

<h4>Deny access if var=val contains the string foo.</h4>
<pre>
RewriteCond %{QUERY_STRING} foo
RewriteRule ^/url - [F]
</pre>

<h4>Removing the Query String</h4>
<pre>
RewriteRule ^/url /url?
</pre>

<h4>Adding to the Query String</h4>
<p>Keep the existing query string using the Query String Append flag, but add var=val to the end.</p>
<pre>
RewriteRule ^/url /url?var=val [QSA]
</pre>

<h4>Rewriting For Certain Query Strings</h4>
<p>Rewrite URLs like http://askapache.com/url1?var=val to http://askapache.com/url2?var=val but don't rewrite if val isn't present.</p>
<pre>
RewriteCond %{QUERY_STRING} val
RewriteRule ^/url1 /url2
</pre>

<h4>Modifying the Query String</h4>
<p>Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.</p>
<pre>
RewriteCond %{QUERY_STRING} ^(.*)val(.*)$
RewriteRule /path /path?%1other_val%2
</pre>
<hr class="C" />
<p><a href="http://www.askapache.com/security/mod_rewrite.html"></a><a href="http://www.askapache.com/security/mod_rewrite.html">Mod_Rewrite Security</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/security/mod_rewrite.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Chmod, Umask, Stat, Fileperms, and File Permissions</title>
		<link>http://www.askapache.com/security/chmod-stat.html</link>
		<comments>http://www.askapache.com/security/chmod-stat.html#comments</comments>
		<pubDate>Fri, 17 Feb 2012 11:16:56 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[File Permissions]]></category>
		<category><![CDATA[umask]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1800</guid>
		<description><![CDATA[<p><a class="IFL" id="id8" href="http://www.askapache.com/security/chmod-umask-fileperms-stat-tricks.html"></a>Unix file permissions are one of the more difficult subjects to grasp.. Well, ok maybe "grasp" isn't the word.. Master is the right word.. Unix file permissions is a hard topic to fully master, mainly I think because there aren't many instances when a computer user encounters them seriously, and bitwise is oldschool.  This contains a listing of all possible permission masks and bits from a linux, php, and web hosting view.... cuz you guys <em>AskApache Regs</em> Rock! <br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/security/chmod-stat.html"></a><a href="http://www.askapache.com/security/chmod-stat.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" id="id8" href="http://www.askapache.com/security/chmod-stat.html"></a>Unix file permissions are one of the more difficult subjects to grasp.. Well, ok maybe "grasp" isn't the word.. Master is the right word.. Unix file permissions is a hard topic to fully master, mainly I think because there aren't many instances when a computer user encounters them.   Windows has been trying to figure it out for decades with little progress, so don't feel bad if you don't know much about it.  <strong>Unless you're with the program</strong> and running Mac or any other <a href="http://www.archlinux.org/">BSD/Unix</a> based OS you've never had the ability to secure your system in this most basic and fundamental way.  Usually the first time someone encounters file permissions it's because their website was cracked.. <br class="C" /></p>

<h3>.htaccess</h3>
<p><kbd>$ chmod 604 .htaccess</kbd></p>
<pre>
604 -rw----r--  /home/askapache/cgi-bin/.htaccess
</pre>


<h3>php.cgi</h3>
<p><kbd>$ chmod 711 php.cgi</kbd></p>
<pre>
$ 711 -rwx--x--x  /home/askapache/cgi-bin/php.cgi
</pre>


<h3>.php.ini</h3>
<p><kbd>$ chmod 600 php.ini</kbd></p>
<pre>
$ 600 -rw-------  /home/askapache/cgi-bin/php.ini
</pre>

<p>I'm in the process of developing an updated version of the .htaccess security plugin, and one thing I have been working on is file permissions.  Some people had problems trying to create files on their server and I realized it was bad programming on my part..  so I began researching permissions in detail. I went deep into the source code of Apache (<em>which is why this site is called AskApache, BTW</em>), PHP, Python, Ocaml, Perl, Ruby, and POSIX operating systems and got a pretty good handle on it now..</p>

<h2>Tips before we dig in</h2>
<p>Here's a few things I've learned that I didn't know before (using php).</p>

<h3>Deleting Files and Directories</h3>
<p>Deleting a file may require chmodding the file to 666 or even 777 before you are able to delete it.  You also might have to chmod the parent directory of the file as well.  Also, you may have to chdir to the directory the file is in.  And lastly you may have to change the owner or group of the file.  Further than that you can try renaming the file first then deleting it..</p>
<p>Deleting a directory means you need to remove every file in it first.  It needs to be empty.  And if your file system uses NFS or some other networked FS you might have even more problems deleting files.  If the file you are trying to delete is being used by say, Apache or php then you might have to kill that process first.</p>

<h3>Creating Files in Restrictive Environments</h3>
<p>My research has been geared to try and make my code as robust as possible, I'm throwing everything but the kitchen sink into some of these functions because so many people are on such different types of servers.  To create a file in a restrictive environment is a fun excercise to take.. You can write a file using many different functions, but there are some tricks if they all fail.  One trick is instead of trying to "write" the data to the file, you can UPLOAD the data to the server and let PHP handle the file as if you used an upload form.  I like to use fsockopen to do it, as some installations have been setup to prevent this type of fake upload.</p>
<p>Then there are the various other hacks like using an ftp connection (if you know the user/pass) to send the file from php, using ssh from php, whatever is available on the hosts php installation.  In addition to those more involved workarounds you can often get around this problem by doing little hacks discussed at php.net in the comments for various functions.  Such as changing the umask, changing directories with chdir first, creating a temporary file using a function like tempfile and then renaming or copying the tempfile to your desired file which sometimes gives you the permissions needed to write to the location.</p>
<p>If the php installation is newer than you can also look into creating your own stream context to pass write the data direct.</p>


<h2>Stat Function</h2>
<p>I've created a stat function in php that goes farther than the normal stat function... Just give the function a file to stat, and it returns an array of information.  </p>
<pre>
function askapache_stat($filename) {
 clearstatcache();
 $ss=@stat($filename);
 if(!$ss) die("Couldnt stat {$filename}");
 $file_convert=array(0140000=&gt;&#039;ssocket&#039;,0120000=&gt;&#039;llink&#039;,0100000=&gt;&#039;-file&#039;,0060000=&gt;&#039;bblock&#039;,0040000=&gt;&#039;ddir&#039;,0020000=&gt;&#039;cchar&#039;,0010000=&gt;&#039;pfifo&#039;);
 $p=$ss[&#039;mode&#039;];
 $t=decoct($ss[&#039;mode&#039;] &amp; 0170000);
 $str = (array_key_exists(octdec($t),$file_convert)) ? $file_convert[octdec($t)]{0} : &#039;u&#039;;
 $str.=(($p&amp;0x0100)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0080)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0040)?(($p&amp;0x0800)?&#039;s&#039;:&#039;x&#039;):(($p&amp;0x0800)?&#039;S&#039;:&#039;-&#039;));
 $str.=(($p&amp;0x0020)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0010)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0008)?(($p&amp;0x0400)?&#039;s&#039;:&#039;x&#039;):(($p&amp;0x0400)?&#039;S&#039;:&#039;-&#039;));
 $str.=(($p&amp;0x0004)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0002)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0001)?(($p&amp;0x0200)?&#039;t&#039;:&#039;x&#039;):(($p&amp;0x0200)?&#039;T&#039;:&#039;-&#039;));
&nbsp;
 $s=array(
 &#039;perms&#039;=&gt;array(
  &#039;umask&#039;=&gt;sprintf("%04o",umask()),
  &#039;human&#039;=&gt;$str,
  &#039;octal1&#039;=&gt;sprintf("%o", ($ss[&#039;mode&#039;] &amp; 000777)),
  &#039;octal2&#039;=&gt;sprintf("0%o", 0777 &amp; $p),
  &#039;decimal&#039;=&gt;sprintf("%04o", $p),
  &#039;fileperms&#039;=&gt;@fileperms($filename),
  &#039;mode1&#039;=&gt;$p,
  &#039;mode2&#039;=&gt;$ss[&#039;mode&#039;]),
&nbsp;
 &#039;filetype&#039;=&gt;array(
  &#039;type&#039;=&gt;substr($file_convert[octdec($t)],1),
  &#039;type_octal&#039;=&gt;sprintf("%07o", octdec($t)),
  &#039;is_file&#039;=&gt;@is_file($filename),
  &#039;is_dir&#039;=&gt;@is_dir($filename),
  &#039;is_link&#039;=&gt;@is_link($filename),
  &#039;is_readable&#039;=&gt; @is_readable($filename),
  &#039;is_writable&#039;=&gt; @is_writable($filename)),
&nbsp;
 &#039;owner&#039;=&gt;array(
  &#039;fileowner&#039;=&gt;$ss[&#039;uid&#039;],
  &#039;filegroup&#039;=&gt;$ss[&#039;gid&#039;],
  &#039;owner_name&#039;=&gt;(function_exists(&#039;posix_getpwuid&#039;)) ? @reset(@posix_getpwuid($ss[&#039;uid&#039;])) : &#039;&#039;,
  &#039;group_name&#039;=&gt;(function_exists(&#039;posix_getgrgid&#039;)) ? @reset(@posix_getgrgid($ss[&#039;gid&#039;])) : &#039;&#039;),
&nbsp;
 &#039;file&#039;=&gt;array(
  &#039;filename&#039;=&gt;$filename,
  &#039;realpath&#039;=&gt;(@realpath($filename) != $filename) ? @realpath($filename) : &#039;&#039;,
  &#039;dirname&#039;=&gt;@dirname($filename),
  &#039;basename&#039;=&gt;@basename($filename)),
&nbsp;
 &#039;device&#039;=&gt;array(
  &#039;device&#039;=&gt;$ss[&#039;dev&#039;], //Device
  &#039;device_number&#039;=&gt;$ss[&#039;rdev&#039;], //Device number, if device.
  &#039;inode&#039;=&gt;$ss[&#039;ino&#039;], //File serial number
  &#039;link_count&#039;=&gt;$ss[&#039;nlink&#039;], //link count
  &#039;link_to&#039;=&gt;($s[&#039;type&#039;]==&#039;link&#039;) ? @readlink($filename) : &#039;&#039;),
&nbsp;
 &#039;size&#039;=&gt;array(
  &#039;size&#039;=&gt;$ss[&#039;size&#039;], //Size of file, in bytes.
  &#039;blocks&#039;=&gt;$ss[&#039;blocks&#039;], //Number 512-byte blocks allocated
  &#039;block_size&#039;=&gt; $ss[&#039;blksize&#039;]), //Optimal block size for I/O.
&nbsp;
 &#039;time&#039;=&gt;array(
  &#039;mtime&#039;=&gt;$ss[&#039;mtime&#039;], //Time of last modification
  &#039;atime&#039;=&gt;$ss[&#039;atime&#039;], //Time of last access.
  &#039;ctime&#039;=&gt;$ss[&#039;ctime&#039;], //Time of last status change
  &#039;accessed&#039;=&gt;@date(&#039;Y M D H:i:s&#039;,$ss[&#039;atime&#039;]),
  &#039;modified&#039;=&gt;@date(&#039;Y M D H:i:s&#039;,$ss[&#039;mtime&#039;]),
  &#039;created&#039;=&gt;@date(&#039;Y M D H:i:s&#039;,$ss[&#039;ctime&#039;])),
 );
&nbsp;
 clearstatcache();
 return $s;
}
</pre>


<h3>PHP Stat Function Output</h2>
<p>Example output, say from <code>print_r(askapache_stat( __FILE__ ) );</code></p>
<pre>
Array(
[perms] =&gt; Array
  (
  [umask] =&gt; 0022
  [human] =&gt; -rw-r--r--
  [octal1] =&gt; 644
  [octal2] =&gt; 0644
  [decimal] =&gt; 100644
  [fileperms] =&gt; 33188
  [mode1] =&gt; 33188
  [mode2] =&gt; 33188
  )
&nbsp;
[filetype] =&gt; Array
  (
  [type] =&gt; file
  [type_octal] =&gt; 0100000
  [is_file] =&gt; 1
  [is_dir] =&gt;
  [is_link] =&gt;
  [is_readable] =&gt; 1
  [is_writable] =&gt; 1
  )
&nbsp;
[owner] =&gt; Array
  (
  [fileowner] =&gt; 035483
  [filegroup] =&gt; 23472
  [owner_name] =&gt; askapache
  [group_name] =&gt; grp22558
  )
&nbsp;
[file] =&gt; Array
  (
  [filename] =&gt; /home/askapache/askapache-stat/public_html/ok/g.php
  [realpath] =&gt;
  [dirname] =&gt; /home/askapache/askapache-stat/public_html/ok
  [basename] =&gt; g.php
  )
&nbsp;
[device] =&gt; Array
  (
  [device] =&gt; 25
  [device_number] =&gt; 0
  [inode] =&gt; 92455020
  [link_count] =&gt; 1
  [link_to] =&gt;
  )
&nbsp;
[size] =&gt; Array
  (
  [size] =&gt; 2652
  [blocks] =&gt; 8
  [block_size] =&gt; 8192
  )
&nbsp;
[time] =&gt; Array
  (
  [mtime] =&gt; 1227685253
  [atime] =&gt; 1227685138
  [ctime] =&gt; 1227685253
  [accessed] =&gt; 2008 Nov Tue 23:38:58
  [modified] =&gt; 2008 Nov Tue 23:40:53
  [created] =&gt; 2008 Nov Tue 23:40:53
  )
)
</pre>






<h2><a id="chmod-0-to-7777"></a>Every Permission 0000 to 0777</h2>
<p><a class="IFL" href="http://uploads.askapache.com/2008/11/danger-chmod-screenshot.png"><img src="http://uploads.askapache.com/2008/11/danger-chmod-screenshot.png" alt="chmod, umask, file permissions test" title="chmod, umask, file permissions test" /></a>This shows what each numeric permission does to a REGULAR file.  I'll provide the code to do this below so you can do the same thing on your server.<br class="C" /></p>
<dl class="dlsm" style="border-right:1px solid #CCC;">
<dt><kbd>chmod 0</kbd></dt>
<dd><code>----------</code></dd>
<dt><kbd>chmod 1</kbd></dt>
<dd><code>---------x</code></dd>
<dt><kbd>chmod 2</kbd></dt>
<dd><code>--------w-</code></dd>
<dt><kbd>chmod 3</kbd></dt>
<dd><code>--------wx</code></dd>
<dt><kbd>chmod 4</kbd></dt>
<dd><code>-------r--</code></dd>
<dt><kbd>chmod 5</kbd></dt>
<dd><code>-------r-x</code></dd>
<dt><kbd>chmod 6</kbd></dt>
<dd><code>-------rw-</code></dd>
<dt><kbd>chmod 7</kbd></dt>
<dd><code>-------rwx</code></dd>
<dt><kbd>chmod 10</kbd></dt>
<dd><code>------x---</code></dd>
<dt><kbd>chmod 11</kbd></dt>
<dd><code>------x--x</code></dd>
<dt><kbd>chmod 12</kbd></dt>
<dd><code>------x-w-</code></dd>
<dt><kbd>chmod 13</kbd></dt>
<dd><code>------x-wx</code></dd>
<dt><kbd>chmod 14</kbd></dt>
<dd><code>------xr--</code></dd>
<dt><kbd>chmod 15</kbd></dt>
<dd><code>------xr-x</code></dd>
<dt><kbd>chmod 16</kbd></dt>
<dd><code>------xrw-</code></dd>
<dt><kbd>chmod 17</kbd></dt>
<dd><code>------xrwx</code></dd>
<dt><kbd>chmod 20</kbd></dt>
<dd><code>-----w----</code></dd>
<dt><kbd>chmod 21</kbd></dt>
<dd><code>-----w---x</code></dd>
<dt><kbd>chmod 22</kbd></dt>
<dd><code>-----w--w-</code></dd>
<dt><kbd>chmod 23</kbd></dt>
<dd><code>-----w--wx</code></dd>
<dt><kbd>chmod 24</kbd></dt>
<dd><code>-----w-r--</code></dd>
<dt><kbd>chmod 25</kbd></dt>
<dd><code>-----w-r-x</code></dd>
<dt><kbd>chmod 26</kbd></dt>
<dd><code>-----w-rw-</code></dd>
<dt><kbd>chmod 27</kbd></dt>
<dd><code>-----w-rwx</code></dd>
<dt><kbd>chmod 30</kbd></dt>
<dd><code>-----wx---</code></dd>
<dt><kbd>chmod 31</kbd></dt>
<dd><code>-----wx--x</code></dd>
<dt><kbd>chmod 32</kbd></dt>
<dd><code>-----wx-w-</code></dd>
<dt><kbd>chmod 33</kbd></dt>
<dd><code>-----wx-wx</code></dd>
<dt><kbd>chmod 34</kbd></dt>
<dd><code>-----wxr--</code></dd>
<dt><kbd>chmod 35</kbd></dt>
<dd><code>-----wxr-x</code></dd>
<dt><kbd>chmod 36</kbd></dt>
<dd><code>-----wxrw-</code></dd>
<dt><kbd>chmod 37</kbd></dt>
<dd><code>-----wxrwx</code></dd>
<dt><kbd>chmod 40</kbd></dt>
<dd><code>----r-----</code></dd>
<dt><kbd>chmod 41</kbd></dt>
<dd><code>----r----x</code></dd>
<dt><kbd>chmod 42</kbd></dt>
<dd><code>----r---w-</code></dd>
<dt><kbd>chmod 43</kbd></dt>
<dd><code>----r---wx</code></dd>
<dt><kbd>chmod 44</kbd></dt>
<dd><code>----r--r--</code></dd>
<dt><kbd>chmod 45</kbd></dt>
<dd><code>----r--r-x</code></dd>
<dt><kbd>chmod 46</kbd></dt>
<dd><code>----r--rw-</code></dd>
<dt><kbd>chmod 47</kbd></dt>
<dd><code>----r--rwx</code></dd>
<dt><kbd>chmod 50</kbd></dt>
<dd><code>----r-x---</code></dd>
<dt><kbd>chmod 51</kbd></dt>
<dd><code>----r-x--x</code></dd>
<dt><kbd>chmod 52</kbd></dt>
<dd><code>----r-x-w-</code></dd>
<dt><kbd>chmod 53</kbd></dt>
<dd><code>----r-x-wx</code></dd>
<dt><kbd>chmod 54</kbd></dt>
<dd><code>----r-xr--</code></dd>
<dt><kbd>chmod 55</kbd></dt>
<dd><code>----r-xr-x</code></dd>
<dt><kbd>chmod 56</kbd></dt>
<dd><code>----r-xrw-</code></dd>
<dt><kbd>chmod 57</kbd></dt>
<dd><code>----r-xrwx</code></dd>
<dt><kbd>chmod 60</kbd></dt>
<dd><code>----rw----</code></dd>
<dt><kbd>chmod 61</kbd></dt>
<dd><code>----rw---x</code></dd>
<dt><kbd>chmod 62</kbd></dt>
<dd><code>----rw--w-</code></dd>
<dt><kbd>chmod 63</kbd></dt>
<dd><code>----rw--wx</code></dd>
<dt><kbd>chmod 64</kbd></dt>
<dd><code>----rw-r--</code></dd>
<dt><kbd>chmod 65</kbd></dt>
<dd><code>----rw-r-x</code></dd>
<dt><kbd>chmod 66</kbd></dt>
<dd><code>----rw-rw-</code></dd>
<dt><kbd>chmod 67</kbd></dt>
<dd><code>----rw-rwx</code></dd>
<dt><kbd>chmod 70</kbd></dt>
<dd><code>----rwx---</code></dd>
<dt><kbd>chmod 71</kbd></dt>
<dd><code>----rwx--x</code></dd>
<dt><kbd>chmod 72</kbd></dt>
<dd><code>----rwx-w-</code></dd>
<dt><kbd>chmod 73</kbd></dt>
<dd><code>----rwx-wx</code></dd>
<dt><kbd>chmod 74</kbd></dt>
<dd><code>----rwxr--</code></dd>
<dt><kbd>chmod 75</kbd></dt>
<dd><code>----rwxr-x</code></dd>
<dt><kbd>chmod 76</kbd></dt>
<dd><code>----rwxrw-</code></dd>
<dt><kbd>chmod 77</kbd></dt>
<dd><code>----rwxrwx</code></dd>
<dt><kbd>chmod 100</kbd></dt>
<dd><code>---x------</code></dd>
<dt><kbd>chmod 101</kbd></dt>
<dd><code>---x-----x</code></dd>
<dt><kbd>chmod 102</kbd></dt>
<dd><code>---x----w-</code></dd>
<dt><kbd>chmod 103</kbd></dt>
<dd><code>---x----wx</code></dd>
<dt><kbd>chmod 104</kbd></dt>
<dd><code>---x---r--</code></dd>
<dt><kbd>chmod 105</kbd></dt>
<dd><code>---x---r-x</code></dd>
<dt><kbd>chmod 106</kbd></dt>
<dd><code>---x---rw-</code></dd>
<dt><kbd>chmod 107</kbd></dt>
<dd><code>---x---rwx</code></dd>
<dt><kbd>chmod 110</kbd></dt>
<dd><code>---x--x---</code></dd>
<dt><kbd>chmod 111</kbd></dt>
<dd><code>---x--x--x</code></dd>
<dt><kbd>chmod 112</kbd></dt>
<dd><code>---x--x-w-</code></dd>
<dt><kbd>chmod 113</kbd></dt>
<dd><code>---x--x-wx</code></dd>
<dt><kbd>chmod 114</kbd></dt>
<dd><code>---x--xr--</code></dd>
<dt><kbd>chmod 115</kbd></dt>
<dd><code>---x--xr-x</code></dd>
<dt><kbd>chmod 116</kbd></dt>
<dd><code>---x--xrw-</code></dd>
<dt><kbd>chmod 117</kbd></dt>
<dd><code>---x--xrwx</code></dd>
<dt><kbd>chmod 120</kbd></dt>
<dd><code>---x-w----</code></dd>
<dt><kbd>chmod 121</kbd></dt>
<dd><code>---x-w---x</code></dd>
<dt><kbd>chmod 122</kbd></dt>
<dd><code>---x-w--w-</code></dd>
<dt><kbd>chmod 123</kbd></dt>
<dd><code>---x-w--wx</code></dd>
<dt><kbd>chmod 124</kbd></dt>
<dd><code>---x-w-r--</code></dd>
<dt><kbd>chmod 125</kbd></dt>
<dd><code>---x-w-r-x</code></dd>
<dt><kbd>chmod 126</kbd></dt>
<dd><code>---x-w-rw-</code></dd>
<dt><kbd>chmod 127</kbd></dt>
<dd><code>---x-w-rwx</code></dd>
<dt><kbd>chmod 130</kbd></dt>
<dd><code>---x-wx---</code></dd>
<dt><kbd>chmod 131</kbd></dt>
<dd><code>---x-wx--x</code></dd>
<dt><kbd>chmod 132</kbd></dt>
<dd><code>---x-wx-w-</code></dd>
<dt><kbd>chmod 133</kbd></dt>
<dd><code>---x-wx-wx</code></dd>
<dt><kbd>chmod 134</kbd></dt>
<dd><code>---x-wxr--</code></dd>
<dt><kbd>chmod 135</kbd></dt>
<dd><code>---x-wxr-x</code></dd>
<dt><kbd>chmod 136</kbd></dt>
<dd><code>---x-wxrw-</code></dd>
<dt><kbd>chmod 137</kbd></dt>
<dd><code>---x-wxrwx</code></dd>
<dt><kbd>chmod 140</kbd></dt>
<dd><code>---xr-----</code></dd>
<dt><kbd>chmod 141</kbd></dt>
<dd><code>---xr----x</code></dd>
<dt><kbd>chmod 142</kbd></dt>
<dd><code>---xr---w-</code></dd>
<dt><kbd>chmod 143</kbd></dt>
<dd><code>---xr---wx</code></dd>
<dt><kbd>chmod 144</kbd></dt>
<dd><code>---xr--r--</code></dd>
<dt><kbd>chmod 145</kbd></dt>
<dd><code>---xr--r-x</code></dd>
<dt><kbd>chmod 146</kbd></dt>
<dd><code>---xr--rw-</code></dd>
<dt><kbd>chmod 147</kbd></dt>
<dd><code>---xr--rwx</code></dd>
<dt><kbd>chmod 150</kbd></dt>
<dd><code>---xr-x---</code></dd>
<dt><kbd>chmod 151</kbd></dt>
<dd><code>---xr-x--x</code></dd>
<dt><kbd>chmod 152</kbd></dt>
<dd><code>---xr-x-w-</code></dd>
<dt><kbd>chmod 153</kbd></dt>
<dd><code>---xr-x-wx</code></dd>
<dt><kbd>chmod 154</kbd></dt>
<dd><code>---xr-xr--</code></dd>
<dt><kbd>chmod 155</kbd></dt>
<dd><code>---xr-xr-x</code></dd>
<dt><kbd>chmod 156</kbd></dt>
<dd><code>---xr-xrw-</code></dd>
<dt><kbd>chmod 157</kbd></dt>
<dd><code>---xr-xrwx</code></dd>
<dt><kbd>chmod 160</kbd></dt>
<dd><code>---xrw----</code></dd>
<dt><kbd>chmod 161</kbd></dt>
<dd><code>---xrw---x</code></dd>
<dt><kbd>chmod 162</kbd></dt>
<dd><code>---xrw--w-</code></dd>
<dt><kbd>chmod 163</kbd></dt>
<dd><code>---xrw--wx</code></dd>
<dt><kbd>chmod 164</kbd></dt>
<dd><code>---xrw-r--</code></dd>
<dt><kbd>chmod 165</kbd></dt>
<dd><code>---xrw-r-x</code></dd>
<dt><kbd>chmod 166</kbd></dt>
<dd><code>---xrw-rw-</code></dd>
<dt><kbd>chmod 167</kbd></dt>
<dd><code>---xrw-rwx</code></dd>
<dt><kbd>chmod 170</kbd></dt>
<dd><code>---xrwx---</code></dd>
<dt><kbd>chmod 171</kbd></dt>
<dd><code>---xrwx--x</code></dd>
<dt><kbd>chmod 172</kbd></dt>
<dd><code>---xrwx-w-</code></dd>
<dt><kbd>chmod 173</kbd></dt>
<dd><code>---xrwx-wx</code></dd>
<dt><kbd>chmod 174</kbd></dt>
<dd><code>---xrwxr--</code></dd>
<dt><kbd>chmod 175</kbd></dt>
<dd><code>---xrwxr-x</code></dd>
<dt><kbd>chmod 176</kbd></dt>
<dd><code>---xrwxrw-</code></dd>
<dt><kbd>chmod 177</kbd></dt>
<dd><code>---xrwxrwx</code></dd>
<dt><kbd>chmod 200</kbd></dt>
<dd><code>--w-------</code></dd>
<dt><kbd>chmod 201</kbd></dt>
<dd><code>--w------x</code></dd>
<dt><kbd>chmod 202</kbd></dt>
<dd><code>--w-----w-</code></dd>
<dt><kbd>chmod 203</kbd></dt>
<dd><code>--w-----wx</code></dd>
<dt><kbd>chmod 204</kbd></dt>
<dd><code>--w----r--</code></dd>
<dt><kbd>chmod 205</kbd></dt>
<dd><code>--w----r-x</code></dd>
<dt><kbd>chmod 206</kbd></dt>
<dd><code>--w----rw-</code></dd>
<dt><kbd>chmod 207</kbd></dt>
<dd><code>--w----rwx</code></dd>
<dt><kbd>chmod 210</kbd></dt>
<dd><code>--w---x---</code></dd>
<dt><kbd>chmod 211</kbd></dt>
<dd><code>--w---x--x</code></dd>
<dt><kbd>chmod 212</kbd></dt>
<dd><code>--w---x-w-</code></dd>
<dt><kbd>chmod 213</kbd></dt>
<dd><code>--w---x-wx</code></dd>
<dt><kbd>chmod 214</kbd></dt>
<dd><code>--w---xr--</code></dd>
<dt><kbd>chmod 215</kbd></dt>
<dd><code>--w---xr-x</code></dd>
<dt><kbd>chmod 216</kbd></dt>
<dd><code>--w---xrw-</code></dd>
<dt><kbd>chmod 217</kbd></dt>
<dd><code>--w---xrwx</code></dd>
<dt><kbd>chmod 220</kbd></dt>
<dd><code>--w--w----</code></dd>
<dt><kbd>chmod 221</kbd></dt>
<dd><code>--w--w---x</code></dd>
<dt><kbd>chmod 222</kbd></dt>
<dd><code>--w--w--w-</code></dd>
<dt><kbd>chmod 223</kbd></dt>
<dd><code>--w--w--wx</code></dd>
<dt><kbd>chmod 224</kbd></dt>
<dd><code>--w--w-r--</code></dd>
<dt><kbd>chmod 225</kbd></dt>
<dd><code>--w--w-r-x</code></dd>
<dt><kbd>chmod 226</kbd></dt>
<dd><code>--w--w-rw-</code></dd>
<dt><kbd>chmod 227</kbd></dt>
<dd><code>--w--w-rwx</code></dd>
<dt><kbd>chmod 230</kbd></dt>
<dd><code>--w--wx---</code></dd>
<dt><kbd>chmod 231</kbd></dt>
<dd><code>--w--wx--x</code></dd>
<dt><kbd>chmod 232</kbd></dt>
<dd><code>--w--wx-w-</code></dd>
<dt><kbd>chmod 233</kbd></dt>
<dd><code>--w--wx-wx</code></dd>
<dt><kbd>chmod 234</kbd></dt>
<dd><code>--w--wxr--</code></dd>
<dt><kbd>chmod 235</kbd></dt>
<dd><code>--w--wxr-x</code></dd>
<dt><kbd>chmod 236</kbd></dt>
<dd><code>--w--wxrw-</code></dd>
<dt><kbd>chmod 237</kbd></dt>
<dd><code>--w--wxrwx</code></dd>
<dt><kbd>chmod 240</kbd></dt>
<dd><code>--w-r-----</code></dd>
<dt><kbd>chmod 241</kbd></dt>
<dd><code>--w-r----x</code></dd>
<dt><kbd>chmod 242</kbd></dt>
<dd><code>--w-r---w-</code></dd>
<dt><kbd>chmod 243</kbd></dt>
<dd><code>--w-r---wx</code></dd>
<dt><kbd>chmod 244</kbd></dt>
<dd><code>--w-r--r--</code></dd>
<dt><kbd>chmod 245</kbd></dt>
<dd><code>--w-r--r-x</code></dd>
<dt><kbd>chmod 246</kbd></dt>
<dd><code>--w-r--rw-</code></dd>
<dt><kbd>chmod 247</kbd></dt>
<dd><code>--w-r--rwx</code></dd>
<dt><kbd>chmod 250</kbd></dt>
<dd><code>--w-r-x---</code></dd>
<dt><kbd>chmod 251</kbd></dt>
<dd><code>--w-r-x--x</code></dd>
<dt><kbd>chmod 252</kbd></dt>
<dd><code>--w-r-x-w-</code></dd>
<dt><kbd>chmod 253</kbd></dt>
<dd><code>--w-r-x-wx</code></dd>
<dt><kbd>chmod 254</kbd></dt>
<dd><code>--w-r-xr--</code></dd>
<dt><kbd>chmod 255</kbd></dt>
<dd><code>--w-r-xr-x</code></dd>
<dt><kbd>chmod 256</kbd></dt>
<dd><code>--w-r-xrw-</code></dd>
<dt><kbd>chmod 257</kbd></dt>
<dd><code>--w-r-xrwx</code></dd>
<dt><kbd>chmod 260</kbd></dt>
<dd><code>--w-rw----</code></dd>
<dt><kbd>chmod 261</kbd></dt>
<dd><code>--w-rw---x</code></dd>
<dt><kbd>chmod 262</kbd></dt>
<dd><code>--w-rw--w-</code></dd>
<dt><kbd>chmod 263</kbd></dt>
<dd><code>--w-rw--wx</code></dd>
<dt><kbd>chmod 264</kbd></dt>
<dd><code>--w-rw-r--</code></dd>
<dt><kbd>chmod 265</kbd></dt>
<dd><code>--w-rw-r-x</code></dd>
<dt><kbd>chmod 266</kbd></dt>
<dd><code>--w-rw-rw-</code></dd>
<dt><kbd>chmod 267</kbd></dt>
<dd><code>--w-rw-rwx</code></dd>
<dt><kbd>chmod 270</kbd></dt>
<dd><code>--w-rwx---</code></dd>
<dt><kbd>chmod 271</kbd></dt>
<dd><code>--w-rwx--x</code></dd>
<dt><kbd>chmod 272</kbd></dt>
<dd><code>--w-rwx-w-</code></dd>
<dt><kbd>chmod 273</kbd></dt>
<dd><code>--w-rwx-wx</code></dd>
<dt><kbd>chmod 274</kbd></dt>
<dd><code>--w-rwxr--</code></dd>
<dt><kbd>chmod 275</kbd></dt>
<dd><code>--w-rwxr-x</code></dd>
<dt><kbd>chmod 276</kbd></dt>
<dd><code>--w-rwxrw-</code></dd>
<dt><kbd>chmod 277</kbd></dt>
<dd><code>--w-rwxrwx</code></dd>
<dt><kbd>chmod 300</kbd></dt>
<dd><code>--wx------</code></dd>
<dt><kbd>chmod 301</kbd></dt>
<dd><code>--wx-----x</code></dd>
<dt><kbd>chmod 302</kbd></dt>
<dd><code>--wx----w-</code></dd>
<dt><kbd>chmod 303</kbd></dt>
<dd><code>--wx----wx</code></dd>
<dt><kbd>chmod 304</kbd></dt>
<dd><code>--wx---r--</code></dd>
<dt><kbd>chmod 305</kbd></dt>
<dd><code>--wx---r-x</code></dd>
<dt><kbd>chmod 306</kbd></dt>
<dd><code>--wx---rw-</code></dd>
<dt><kbd>chmod 307</kbd></dt>
<dd><code>--wx---rwx</code></dd>
<dt><kbd>chmod 310</kbd></dt>
<dd><code>--wx--x---</code></dd>
<dt><kbd>chmod 311</kbd></dt>
<dd><code>--wx--x--x</code></dd>
<dt><kbd>chmod 312</kbd></dt>
<dd><code>--wx--x-w-</code></dd>
<dt><kbd>chmod 313</kbd></dt>
<dd><code>--wx--x-wx</code></dd>
<dt><kbd>chmod 314</kbd></dt>
<dd><code>--wx--xr--</code></dd>
<dt><kbd>chmod 315</kbd></dt>
<dd><code>--wx--xr-x</code></dd>
<dt><kbd>chmod 316</kbd></dt>
<dd><code>--wx--xrw-</code></dd>
<dt><kbd>chmod 317</kbd></dt>
<dd><code>--wx--xrwx</code></dd>
<dt><kbd>chmod 320</kbd></dt>
<dd><code>--wx-w----</code></dd>
<dt><kbd>chmod 321</kbd></dt>
<dd><code>--wx-w---x</code></dd>
<dt><kbd>chmod 322</kbd></dt>
<dd><code>--wx-w--w-</code></dd>
<dt><kbd>chmod 323</kbd></dt>
<dd><code>--wx-w--wx</code></dd>
<dt><kbd>chmod 324</kbd></dt>
<dd><code>--wx-w-r--</code></dd>
<dt><kbd>chmod 325</kbd></dt>
<dd><code>--wx-w-r-x</code></dd>
<dt><kbd>chmod 326</kbd></dt>
<dd><code>--wx-w-rw-</code></dd>
<dt><kbd>chmod 327</kbd></dt>
<dd><code>--wx-w-rwx</code></dd>
<dt><kbd>chmod 330</kbd></dt>
<dd><code>--wx-wx---</code></dd>
<dt><kbd>chmod 331</kbd></dt>
<dd><code>--wx-wx--x</code></dd>
<dt><kbd>chmod 332</kbd></dt>
<dd><code>--wx-wx-w-</code></dd>
<dt><kbd>chmod 333</kbd></dt>
<dd><code>--wx-wx-wx</code></dd>
<dt><kbd>chmod 334</kbd></dt>
<dd><code>--wx-wxr--</code></dd>
<dt><kbd>chmod 335</kbd></dt>
<dd><code>--wx-wxr-x</code></dd>
<dt><kbd>chmod 336</kbd></dt>
<dd><code>--wx-wxrw-</code></dd>
<dt><kbd>chmod 337</kbd></dt>
<dd><code>--wx-wxrwx</code></dd>
<dt><kbd>chmod 340</kbd></dt>
<dd><code>--wxr-----</code></dd>
<dt><kbd>chmod 341</kbd></dt>
<dd><code>--wxr----x</code></dd>
<dt><kbd>chmod 342</kbd></dt>
<dd><code>--wxr---w-</code></dd>
<dt><kbd>chmod 343</kbd></dt>
<dd><code>--wxr---wx</code></dd>
<dt><kbd>chmod 344</kbd></dt>
<dd><code>--wxr--r--</code></dd>
<dt><kbd>chmod 345</kbd></dt>
<dd><code>--wxr--r-x</code></dd>
<dt><kbd>chmod 346</kbd></dt>
<dd><code>--wxr--rw-</code></dd>
<dt><kbd>chmod 347</kbd></dt>
<dd><code>--wxr--rwx</code></dd>
<dt><kbd>chmod 350</kbd></dt>
<dd><code>--wxr-x---</code></dd>
<dt><kbd>chmod 351</kbd></dt>
<dd><code>--wxr-x--x</code></dd>
<dt><kbd>chmod 352</kbd></dt>
<dd><code>--wxr-x-w-</code></dd>
<dt><kbd>chmod 353</kbd></dt>
<dd><code>--wxr-x-wx</code></dd>
<dt><kbd>chmod 354</kbd></dt>
<dd><code>--wxr-xr--</code></dd>
<dt><kbd>chmod 355</kbd></dt>
<dd><code>--wxr-xr-x</code></dd>
<dt><kbd>chmod 356</kbd></dt>
<dd><code>--wxr-xrw-</code></dd>
<dt><kbd>chmod 357</kbd></dt>
<dd><code>--wxr-xrwx</code></dd>
<dt><kbd>chmod 360</kbd></dt>
<dd><code>--wxrw----</code></dd>
<dt><kbd>chmod 361</kbd></dt>
<dd><code>--wxrw---x</code></dd>
<dt><kbd>chmod 362</kbd></dt>
<dd><code>--wxrw--w-</code></dd>
<dt><kbd>chmod 363</kbd></dt>
<dd><code>--wxrw--wx</code></dd>
<dt><kbd>chmod 364</kbd></dt>
<dd><code>--wxrw-r--</code></dd>
<dt><kbd>chmod 365</kbd></dt>
<dd><code>--wxrw-r-x</code></dd>
<dt><kbd>chmod 366</kbd></dt>
<dd><code>--wxrw-rw-</code></dd>
<dt><kbd>chmod 367</kbd></dt>
<dd><code>--wxrw-rwx</code></dd>
<dt><kbd>chmod 370</kbd></dt>
<dd><code>--wxrwx---</code></dd>
<dt><kbd>chmod 371</kbd></dt>
<dd><code>--wxrwx--x</code></dd>
<dt><kbd>chmod 372</kbd></dt>
<dd><code>--wxrwx-w-</code></dd>
<dt><kbd>chmod 373</kbd></dt>
<dd><code>--wxrwx-wx</code></dd>
<dt><kbd>chmod 374</kbd></dt>
<dd><code>--wxrwxr--</code></dd>
<dt><kbd>chmod 375</kbd></dt>
<dd><code>--wxrwxr-x</code></dd>
<dt><kbd>chmod 376</kbd></dt>
<dd><code>--wxrwxrw-</code></dd>
<dt><kbd>chmod 377</kbd></dt>
<dd><code>--wxrwxrwx</code></dd>
<dt><kbd>chmod 400</kbd></dt>
<dd><code>-r--------</code></dd>
<dt><kbd>chmod 401</kbd></dt>
<dd><code>-r-------x</code></dd>
<dt><kbd>chmod 402</kbd></dt>
<dd><code>-r------w-</code></dd>
<dt><kbd>chmod 403</kbd></dt>
<dd><code>-r------wx</code></dd>
<dt><kbd>chmod 404</kbd></dt>
<dd><code>-r-----r--</code></dd>
<dt><kbd>chmod 405</kbd></dt>
<dd><code>-r-----r-x</code></dd>
<dt><kbd>chmod 406</kbd></dt>
<dd><code>-r-----rw-</code></dd>
<dt><kbd>chmod 407</kbd></dt>
<dd><code>-r-----rwx</code></dd>
<dt><kbd>chmod 410</kbd></dt>
<dd><code>-r----x---</code></dd>
<dt><kbd>chmod 411</kbd></dt>
<dd><code>-r----x--x</code></dd>
<dt><kbd>chmod 412</kbd></dt>
<dd><code>-r----x-w-</code></dd>
<dt><kbd>chmod 413</kbd></dt>
<dd><code>-r----x-wx</code></dd>
<dt><kbd>chmod 414</kbd></dt>
<dd><code>-r----xr--</code></dd>
<dt><kbd>chmod 415</kbd></dt>
<dd><code>-r----xr-x</code></dd>
<dt><kbd>chmod 416</kbd></dt>
<dd><code>-r----xrw-</code></dd>
<dt><kbd>chmod 417</kbd></dt>
<dd><code>-r----xrwx</code></dd>
<dt><kbd>chmod 420</kbd></dt>
<dd><code>-r---w----</code></dd>
<dt><kbd>chmod 421</kbd></dt>
<dd><code>-r---w---x</code></dd>
<dt><kbd>chmod 422</kbd></dt>
<dd><code>-r---w--w-</code></dd>
<dt><kbd>chmod 423</kbd></dt>
<dd><code>-r---w--wx</code></dd>
<dt><kbd>chmod 424</kbd></dt>
<dd><code>-r---w-r--</code></dd>
<dt><kbd>chmod 425</kbd></dt>
<dd><code>-r---w-r-x</code></dd>
<dt><kbd>chmod 426</kbd></dt>
<dd><code>-r---w-rw-</code></dd>
<dt><kbd>chmod 427</kbd></dt>
<dd><code>-r---w-rwx</code></dd>
<dt><kbd>chmod 430</kbd></dt>
<dd><code>-r---wx---</code></dd>
<dt><kbd>chmod 431</kbd></dt>
<dd><code>-r---wx--x</code></dd>
<dt><kbd>chmod 432</kbd></dt>
<dd><code>-r---wx-w-</code></dd>
<dt><kbd>chmod 433</kbd></dt>
<dd><code>-r---wx-wx</code></dd>
<dt><kbd>chmod 434</kbd></dt>
<dd><code>-r---wxr--</code></dd>
<dt><kbd>chmod 435</kbd></dt>
<dd><code>-r---wxr-x</code></dd>
<dt><kbd>chmod 436</kbd></dt>
<dd><code>-r---wxrw-</code></dd>
<dt><kbd>chmod 437</kbd></dt>
<dd><code>-r---wxrwx</code></dd>
<dt><kbd>chmod 440</kbd></dt>
<dd><code>-r--r-----</code></dd>
<dt><kbd>chmod 441</kbd></dt>
<dd><code>-r--r----x</code></dd>
<dt><kbd>chmod 442</kbd></dt>
<dd><code>-r--r---w-</code></dd>
<dt><kbd>chmod 443</kbd></dt>
<dd><code>-r--r---wx</code></dd>
<dt><kbd>chmod 444</kbd></dt>
<dd><code>-r--r--r--</code></dd>
<dt><kbd>chmod 445</kbd></dt>
<dd><code>-r--r--r-x</code></dd>
<dt><kbd>chmod 446</kbd></dt>
<dd><code>-r--r--rw-</code></dd>
<dt><kbd>chmod 447</kbd></dt>
<dd><code>-r--r--rwx</code></dd>
<dt><kbd>chmod 450</kbd></dt>
<dd><code>-r--r-x---</code></dd>
<dt><kbd>chmod 451</kbd></dt>
<dd><code>-r--r-x--x</code></dd>
<dt><kbd>chmod 452</kbd></dt>
<dd><code>-r--r-x-w-</code></dd>
<dt><kbd>chmod 453</kbd></dt>
<dd><code>-r--r-x-wx</code></dd>
<dt><kbd>chmod 454</kbd></dt>
<dd><code>-r--r-xr--</code></dd>
<dt><kbd>chmod 455</kbd></dt>
<dd><code>-r--r-xr-x</code></dd>
<dt><kbd>chmod 456</kbd></dt>
<dd><code>-r--r-xrw-</code></dd>
<dt><kbd>chmod 457</kbd></dt>
<dd><code>-r--r-xrwx</code></dd>
<dt><kbd>chmod 460</kbd></dt>
<dd><code>-r--rw----</code></dd>
<dt><kbd>chmod 461</kbd></dt>
<dd><code>-r--rw---x</code></dd>
<dt><kbd>chmod 462</kbd></dt>
<dd><code>-r--rw--w-</code></dd>
<dt><kbd>chmod 463</kbd></dt>
<dd><code>-r--rw--wx</code></dd>
<dt><kbd>chmod 464</kbd></dt>
<dd><code>-r--rw-r--</code></dd>
<dt><kbd>chmod 465</kbd></dt>
<dd><code>-r--rw-r-x</code></dd>
<dt><kbd>chmod 466</kbd></dt>
<dd><code>-r--rw-rw-</code></dd>
<dt><kbd>chmod 467</kbd></dt>
<dd><code>-r--rw-rwx</code></dd>
<dt><kbd>chmod 470</kbd></dt>
<dd><code>-r--rwx---</code></dd>
<dt><kbd>chmod 471</kbd></dt>
<dd><code>-r--rwx--x</code></dd>
<dt><kbd>chmod 472</kbd></dt>
<dd><code>-r--rwx-w-</code></dd>
<dt><kbd>chmod 473</kbd></dt>
<dd><code>-r--rwx-wx</code></dd>
<dt><kbd>chmod 474</kbd></dt>
<dd><code>-r--rwxr--</code></dd>
<dt><kbd>chmod 475</kbd></dt>
<dd><code>-r--rwxr-x</code></dd>
<dt><kbd>chmod 476</kbd></dt>
<dd><code>-r--rwxrw-</code></dd>
<dt><kbd>chmod 477</kbd></dt>
<dd><code>-r--rwxrwx</code></dd>
<dt><kbd>chmod 500</kbd></dt>
<dd><code>-r-x------</code></dd>
<dt><kbd>chmod 501</kbd></dt>
<dd><code>-r-x-----x</code></dd>
<dt><kbd>chmod 502</kbd></dt>
<dd><code>-r-x----w-</code></dd>
<dt><kbd>chmod 503</kbd></dt>
<dd><code>-r-x----wx</code></dd>
<dt><kbd>chmod 504</kbd></dt>
<dd><code>-r-x---r--</code></dd>
<dt><kbd>chmod 505</kbd></dt>
<dd><code>-r-x---r-x</code></dd>
<dt><kbd>chmod 506</kbd></dt>
<dd><code>-r-x---rw-</code></dd>
<dt><kbd>chmod 507</kbd></dt>
<dd><code>-r-x---rwx</code></dd>
<dt><kbd>chmod 510</kbd></dt>
<dd><code>-r-x--x---</code></dd>
<dt><kbd>chmod 511</kbd></dt>
<dd><code>-r-x--x--x</code></dd>
<dt><kbd>chmod 512</kbd></dt>
<dd><code>-r-x--x-w-</code></dd>
<dt><kbd>chmod 513</kbd></dt>
<dd><code>-r-x--x-wx</code></dd>
<dt><kbd>chmod 514</kbd></dt>
<dd><code>-r-x--xr--</code></dd>
<dt><kbd>chmod 515</kbd></dt>
<dd><code>-r-x--xr-x</code></dd>
<dt><kbd>chmod 516</kbd></dt>
<dd><code>-r-x--xrw-</code></dd>
<dt><kbd>chmod 517</kbd></dt>
<dd><code>-r-x--xrwx</code></dd>
<dt><kbd>chmod 520</kbd></dt>
<dd><code>-r-x-w----</code></dd>
<dt><kbd>chmod 521</kbd></dt>
<dd><code>-r-x-w---x</code></dd>
<dt><kbd>chmod 522</kbd></dt>
<dd><code>-r-x-w--w-</code></dd>
<dt><kbd>chmod 523</kbd></dt>
<dd><code>-r-x-w--wx</code></dd>
<dt><kbd>chmod 524</kbd></dt>
<dd><code>-r-x-w-r--</code></dd>
<dt><kbd>chmod 525</kbd></dt>
<dd><code>-r-x-w-r-x</code></dd>
<dt><kbd>chmod 526</kbd></dt>
<dd><code>-r-x-w-rw-</code></dd>
<dt><kbd>chmod 527</kbd></dt>
<dd><code>-r-x-w-rwx</code></dd>
<dt><kbd>chmod 530</kbd></dt>
<dd><code>-r-x-wx---</code></dd>
<dt><kbd>chmod 531</kbd></dt>
<dd><code>-r-x-wx--x</code></dd>
<dt><kbd>chmod 532</kbd></dt>
<dd><code>-r-x-wx-w-</code></dd>
<dt><kbd>chmod 533</kbd></dt>
<dd><code>-r-x-wx-wx</code></dd>
<dt><kbd>chmod 534</kbd></dt>
<dd><code>-r-x-wxr--</code></dd>
<dt><kbd>chmod 535</kbd></dt>
<dd><code>-r-x-wxr-x</code></dd>
<dt><kbd>chmod 536</kbd></dt>
<dd><code>-r-x-wxrw-</code></dd>
<dt><kbd>chmod 537</kbd></dt>
<dd><code>-r-x-wxrwx</code></dd>
<dt><kbd>chmod 540</kbd></dt>
<dd><code>-r-xr-----</code></dd>
<dt><kbd>chmod 541</kbd></dt>
<dd><code>-r-xr----x</code></dd>
<dt><kbd>chmod 542</kbd></dt>
<dd><code>-r-xr---w-</code></dd>
<dt><kbd>chmod 543</kbd></dt>
<dd><code>-r-xr---wx</code></dd>
<dt><kbd>chmod 544</kbd></dt>
<dd><code>-r-xr--r--</code></dd>
<dt><kbd>chmod 545</kbd></dt>
<dd><code>-r-xr--r-x</code></dd>
<dt><kbd>chmod 546</kbd></dt>
<dd><code>-r-xr--rw-</code></dd>
<dt><kbd>chmod 547</kbd></dt>
<dd><code>-r-xr--rwx</code></dd>
<dt><kbd>chmod 550</kbd></dt>
<dd><code>-r-xr-x---</code></dd>
<dt><kbd>chmod 551</kbd></dt>
<dd><code>-r-xr-x--x</code></dd>
<dt><kbd>chmod 552</kbd></dt>
<dd><code>-r-xr-x-w-</code></dd>
<dt><kbd>chmod 553</kbd></dt>
<dd><code>-r-xr-x-wx</code></dd>
<dt><kbd>chmod 554</kbd></dt>
<dd><code>-r-xr-xr--</code></dd>
<dt><kbd>chmod 555</kbd></dt>
<dd><code>-r-xr-xr-x</code></dd>
<dt><kbd>chmod 556</kbd></dt>
<dd><code>-r-xr-xrw-</code></dd>
<dt><kbd>chmod 557</kbd></dt>
<dd><code>-r-xr-xrwx</code></dd>
<dt><kbd>chmod 560</kbd></dt>
<dd><code>-r-xrw----</code></dd>
<dt><kbd>chmod 561</kbd></dt>
<dd><code>-r-xrw---x</code></dd>
<dt><kbd>chmod 562</kbd></dt>
<dd><code>-r-xrw--w-</code></dd>
<dt><kbd>chmod 563</kbd></dt>
<dd><code>-r-xrw--wx</code></dd>
<dt><kbd>chmod 564</kbd></dt>
<dd><code>-r-xrw-r--</code></dd>
<dt><kbd>chmod 565</kbd></dt>
<dd><code>-r-xrw-r-x</code></dd>
<dt><kbd>chmod 566</kbd></dt>
<dd><code>-r-xrw-rw-</code></dd>
<dt><kbd>chmod 567</kbd></dt>
<dd><code>-r-xrw-rwx</code></dd>
<dt><kbd>chmod 570</kbd></dt>
<dd><code>-r-xrwx---</code></dd>
<dt><kbd>chmod 571</kbd></dt>
<dd><code>-r-xrwx--x</code></dd>
<dt><kbd>chmod 572</kbd></dt>
<dd><code>-r-xrwx-w-</code></dd>
<dt><kbd>chmod 573</kbd></dt>
<dd><code>-r-xrwx-wx</code></dd>
<dt><kbd>chmod 574</kbd></dt>
<dd><code>-r-xrwxr--</code></dd>
<dt><kbd>chmod 575</kbd></dt>
<dd><code>-r-xrwxr-x</code></dd>
<dt><kbd>chmod 576</kbd></dt>
<dd><code>-r-xrwxrw-</code></dd>
<dt><kbd>chmod 577</kbd></dt>
<dd><code>-r-xrwxrwx</code></dd>
<dt><kbd>chmod 600</kbd></dt>
<dd><code>-rw-------</code></dd>
<dt><kbd>chmod 601</kbd></dt>
<dd><code>-rw------x</code></dd>
<dt><kbd>chmod 602</kbd></dt>
<dd><code>-rw-----w-</code></dd>
<dt><kbd>chmod 603</kbd></dt>
<dd><code>-rw-----wx</code></dd>
<dt><kbd>chmod 604</kbd></dt>
<dd><code>-rw----r--</code></dd>
<dt><kbd>chmod 605</kbd></dt>
<dd><code>-rw----r-x</code></dd>
<dt><kbd>chmod 606</kbd></dt>
<dd><code>-rw----rw-</code></dd>
<dt><kbd>chmod 607</kbd></dt>
<dd><code>-rw----rwx</code></dd>
<dt><kbd>chmod 610</kbd></dt>
<dd><code>-rw---x---</code></dd>
<dt><kbd>chmod 611</kbd></dt>
<dd><code>-rw---x--x</code></dd>
<dt><kbd>chmod 612</kbd></dt>
<dd><code>-rw---x-w-</code></dd>
<dt><kbd>chmod 613</kbd></dt>
<dd><code>-rw---x-wx</code></dd>
<dt><kbd>chmod 614</kbd></dt>
<dd><code>-rw---xr--</code></dd>
<dt><kbd>chmod 615</kbd></dt>
<dd><code>-rw---xr-x</code></dd>
<dt><kbd>chmod 616</kbd></dt>
<dd><code>-rw---xrw-</code></dd>
<dt><kbd>chmod 617</kbd></dt>
<dd><code>-rw---xrwx</code></dd>
<dt><kbd>chmod 620</kbd></dt>
<dd><code>-rw--w----</code></dd>
<dt><kbd>chmod 621</kbd></dt>
<dd><code>-rw--w---x</code></dd>
<dt><kbd>chmod 622</kbd></dt>
<dd><code>-rw--w--w-</code></dd>
<dt><kbd>chmod 623</kbd></dt>
<dd><code>-rw--w--wx</code></dd>
<dt><kbd>chmod 624</kbd></dt>
<dd><code>-rw--w-r--</code></dd>
<dt><kbd>chmod 625</kbd></dt>
<dd><code>-rw--w-r-x</code></dd>
<dt><kbd>chmod 626</kbd></dt>
<dd><code>-rw--w-rw-</code></dd>
<dt><kbd>chmod 627</kbd></dt>
<dd><code>-rw--w-rwx</code></dd>
<dt><kbd>chmod 630</kbd></dt>
<dd><code>-rw--wx---</code></dd>
<dt><kbd>chmod 631</kbd></dt>
<dd><code>-rw--wx--x</code></dd>
<dt><kbd>chmod 632</kbd></dt>
<dd><code>-rw--wx-w-</code></dd>
<dt><kbd>chmod 633</kbd></dt>
<dd><code>-rw--wx-wx</code></dd>
<dt><kbd>chmod 634</kbd></dt>
<dd><code>-rw--wxr--</code></dd>
<dt><kbd>chmod 635</kbd></dt>
<dd><code>-rw--wxr-x</code></dd>
<dt><kbd>chmod 636</kbd></dt>
<dd><code>-rw--wxrw-</code></dd>
<dt><kbd>chmod 637</kbd></dt>
<dd><code>-rw--wxrwx</code></dd>
<dt><kbd>chmod 640</kbd></dt>
<dd><code>-rw-r-----</code></dd>
<dt><kbd>chmod 641</kbd></dt>
<dd><code>-rw-r----x</code></dd>
<dt><kbd>chmod 642</kbd></dt>
<dd><code>-rw-r---w-</code></dd>
<dt><kbd>chmod 643</kbd></dt>
<dd><code>-rw-r---wx</code></dd>
<dt><kbd>chmod 644</kbd></dt>
<dd><code>-rw-r--r--</code></dd>
<dt><kbd>chmod 645</kbd></dt>
<dd><code>-rw-r--r-x</code></dd>
<dt><kbd>chmod 646</kbd></dt>
<dd><code>-rw-r--rw-</code></dd>
<dt><kbd>chmod 647</kbd></dt>
<dd><code>-rw-r--rwx</code></dd>
<dt><kbd>chmod 650</kbd></dt>
<dd><code>-rw-r-x---</code></dd>
<dt><kbd>chmod 651</kbd></dt>
<dd><code>-rw-r-x--x</code></dd>
<dt><kbd>chmod 652</kbd></dt>
<dd><code>-rw-r-x-w-</code></dd>
<dt><kbd>chmod 653</kbd></dt>
<dd><code>-rw-r-x-wx</code></dd>
<dt><kbd>chmod 654</kbd></dt>
<dd><code>-rw-r-xr--</code></dd>
<dt><kbd>chmod 655</kbd></dt>
<dd><code>-rw-r-xr-x</code></dd>
<dt><kbd>chmod 656</kbd></dt>
<dd><code>-rw-r-xrw-</code></dd>
<dt><kbd>chmod 657</kbd></dt>
<dd><code>-rw-r-xrwx</code></dd>
<dt><kbd>chmod 660</kbd></dt>
<dd><code>-rw-rw----</code></dd>
<dt><kbd>chmod 661</kbd></dt>
<dd><code>-rw-rw---x</code></dd>
<dt><kbd>chmod 662</kbd></dt>
<dd><code>-rw-rw--w-</code></dd>
<dt><kbd>chmod 663</kbd></dt>
<dd><code>-rw-rw--wx</code></dd>
<dt><kbd>chmod 664</kbd></dt>
<dd><code>-rw-rw-r--</code></dd>
<dt><kbd>chmod 665</kbd></dt>
<dd><code>-rw-rw-r-x</code></dd>
<dt><kbd>chmod 666</kbd></dt>
<dd><code>-rw-rw-rw-</code></dd>
<dt><kbd>chmod 667</kbd></dt>
<dd><code>-rw-rw-rwx</code></dd>
<dt><kbd>chmod 670</kbd></dt>
<dd><code>-rw-rwx---</code></dd>
<dt><kbd>chmod 671</kbd></dt>
<dd><code>-rw-rwx--x</code></dd>
<dt><kbd>chmod 672</kbd></dt>
<dd><code>-rw-rwx-w-</code></dd>
<dt><kbd>chmod 673</kbd></dt>
<dd><code>-rw-rwx-wx</code></dd>
<dt><kbd>chmod 674</kbd></dt>
<dd><code>-rw-rwxr--</code></dd>
<dt><kbd>chmod 675</kbd></dt>
<dd><code>-rw-rwxr-x</code></dd>
<dt><kbd>chmod 676</kbd></dt>
<dd><code>-rw-rwxrw-</code></dd>
<dt><kbd>chmod 677</kbd></dt>
<dd><code>-rw-rwxrwx</code></dd>
<dt><kbd>chmod 700</kbd></dt>
<dd><code>-rwx------</code></dd>
<dt><kbd>chmod 701</kbd></dt>
<dd><code>-rwx-----x</code></dd>
<dt><kbd>chmod 702</kbd></dt>
<dd><code>-rwx----w-</code></dd>
<dt><kbd>chmod 703</kbd></dt>
<dd><code>-rwx----wx</code></dd>
<dt><kbd>chmod 704</kbd></dt>
<dd><code>-rwx---r--</code></dd>
<dt><kbd>chmod 705</kbd></dt>
<dd><code>-rwx---r-x</code></dd>
<dt><kbd>chmod 706</kbd></dt>
<dd><code>-rwx---rw-</code></dd>
<dt><kbd>chmod 707</kbd></dt>
<dd><code>-rwx---rwx</code></dd>
<dt><kbd>chmod 710</kbd></dt>
<dd><code>-rwx--x---</code></dd>
<dt><kbd>chmod 711</kbd></dt>
<dd><code>-rwx--x--x</code></dd>
<dt><kbd>chmod 712</kbd></dt>
<dd><code>-rwx--x-w-</code></dd>
<dt><kbd>chmod 713</kbd></dt>
<dd><code>-rwx--x-wx</code></dd>
<dt><kbd>chmod 714</kbd></dt>
<dd><code>-rwx--xr--</code></dd>
<dt><kbd>chmod 715</kbd></dt>
<dd><code>-rwx--xr-x</code></dd>
<dt><kbd>chmod 716</kbd></dt>
<dd><code>-rwx--xrw-</code></dd>
<dt><kbd>chmod 717</kbd></dt>
<dd><code>-rwx--xrwx</code></dd>
<dt><kbd>chmod 720</kbd></dt>
<dd><code>-rwx-w----</code></dd>
<dt><kbd>chmod 721</kbd></dt>
<dd><code>-rwx-w---x</code></dd>
<dt><kbd>chmod 722</kbd></dt>
<dd><code>-rwx-w--w-</code></dd>
<dt><kbd>chmod 723</kbd></dt>
<dd><code>-rwx-w--wx</code></dd>
<dt><kbd>chmod 724</kbd></dt>
<dd><code>-rwx-w-r--</code></dd>
<dt><kbd>chmod 725</kbd></dt>
<dd><code>-rwx-w-r-x</code></dd>
<dt><kbd>chmod 726</kbd></dt>
<dd><code>-rwx-w-rw-</code></dd>
<dt><kbd>chmod 727</kbd></dt>
<dd><code>-rwx-w-rwx</code></dd>
<dt><kbd>chmod 730</kbd></dt>
<dd><code>-rwx-wx---</code></dd>
<dt><kbd>chmod 731</kbd></dt>
<dd><code>-rwx-wx--x</code></dd>
<dt><kbd>chmod 732</kbd></dt>
<dd><code>-rwx-wx-w-</code></dd>
<dt><kbd>chmod 733</kbd></dt>
<dd><code>-rwx-wx-wx</code></dd>
<dt><kbd>chmod 734</kbd></dt>
<dd><code>-rwx-wxr--</code></dd>
<dt><kbd>chmod 735</kbd></dt>
<dd><code>-rwx-wxr-x</code></dd>
<dt><kbd>chmod 736</kbd></dt>
<dd><code>-rwx-wxrw-</code></dd>
<dt><kbd>chmod 737</kbd></dt>
<dd><code>-rwx-wxrwx</code></dd>
<dt><kbd>chmod 740</kbd></dt>
<dd><code>-rwxr-----</code></dd>
<dt><kbd>chmod 741</kbd></dt>
<dd><code>-rwxr----x</code></dd>
<dt><kbd>chmod 742</kbd></dt>
<dd><code>-rwxr---w-</code></dd>
<dt><kbd>chmod 743</kbd></dt>
<dd><code>-rwxr---wx</code></dd>
<dt><kbd>chmod 744</kbd></dt>
<dd><code>-rwxr--r--</code></dd>
<dt><kbd>chmod 745</kbd></dt>
<dd><code>-rwxr--r-x</code></dd>
<dt><kbd>chmod 746</kbd></dt>
<dd><code>-rwxr--rw-</code></dd>
<dt><kbd>chmod 747</kbd></dt>
<dd><code>-rwxr--rwx</code></dd>
<dt><kbd>chmod 750</kbd></dt>
<dd><code>-rwxr-x---</code></dd>
<dt><kbd>chmod 751</kbd></dt>
<dd><code>-rwxr-x--x</code></dd>
<dt><kbd>chmod 752</kbd></dt>
<dd><code>-rwxr-x-w-</code></dd>
<dt><kbd>chmod 753</kbd></dt>
<dd><code>-rwxr-x-wx</code></dd>
<dt><kbd>chmod 754</kbd></dt>
<dd><code>-rwxr-xr--</code></dd>
<dt><kbd>chmod 755</kbd></dt>
<dd><code>-rwxr-xr-x</code></dd>
<dt><kbd>chmod 756</kbd></dt>
<dd><code>-rwxr-xrw-</code></dd>
<dt><kbd>chmod 757</kbd></dt>
<dd><code>-rwxr-xrwx</code></dd>
<dt><kbd>chmod 760</kbd></dt>
<dd><code>-rwxrw----</code></dd>
<dt><kbd>chmod 761</kbd></dt>
<dd><code>-rwxrw---x</code></dd>
<dt><kbd>chmod 762</kbd></dt>
<dd><code>-rwxrw--w-</code></dd>
<dt><kbd>chmod 763</kbd></dt>
<dd><code>-rwxrw--wx</code></dd>
<dt><kbd>chmod 764</kbd></dt>
<dd><code>-rwxrw-r--</code></dd>
<dt><kbd>chmod 765</kbd></dt>
<dd><code>-rwxrw-r-x</code></dd>
<dt><kbd>chmod 766</kbd></dt>
<dd><code>-rwxrw-rw-</code></dd>
<dt><kbd>chmod 767</kbd></dt>
<dd><code>-rwxrw-rwx</code></dd>
<dt><kbd>chmod 770</kbd></dt>
<dd><code>-rwxrwx---</code></dd>
<dt><kbd>chmod 771</kbd></dt>
<dd><code>-rwxrwx--x</code></dd>
<dt><kbd>chmod 772</kbd></dt>
<dd><code>-rwxrwx-w-</code></dd>
<dt><kbd>chmod 773</kbd></dt>
<dd><code>-rwxrwx-wx</code></dd>
<dt><kbd>chmod 774</kbd></dt>
<dd><code>-rwxrwxr--</code></dd>
<dt><kbd>chmod 775</kbd></dt>
<dd><code>-rwxrwxr-x</code></dd>
<dt><kbd>chmod 776</kbd></dt>
<dd><code>-rwxrwxrw-</code></dd>
<dt><kbd>chmod 777</kbd></dt>
<dd><code>-rwxrwxrwx</code></dd>
</dl>
<hr class="C" />




<h2>Congratulations!</h2>
<p>Here's my custom stat function, which I am definately not finished with, so check back in a couple days and if you find any improvements please hook me up with a comment!</p>

<pre>
function askapache_stat( $filename ) {
$p=@fileperms($filename);
$s=@stat($filename);
$str=&#039;&#039;;
$t=decoct($s[&#039;mode&#039;] &amp; 0170000);
&nbsp;
switch (octdec($t)) {
case 0140000: $str = &#039;s&#039;; $stat[&#039;type&#039;]=&#039;socket&#039;; break;
case 0120000: $str = &#039;l&#039;; $stat[&#039;type&#039;]=&#039;link&#039;; break;
case 0100000: $str = &#039;-&#039;; $stat[&#039;type&#039;]=&#039;file&#039;; break;
case 0060000: $str = &#039;b&#039;; $stat[&#039;type&#039;]=&#039;block&#039;; break;
case 0040000: $str = &#039;d&#039;; $stat[&#039;type&#039;]=&#039;dir&#039;; break;
case 0020000: $str = &#039;c&#039;; $stat[&#039;type&#039;]=&#039;char&#039;; break;
case 0010000: $str = &#039;p&#039;; $stat[&#039;type&#039;]=&#039;fifo&#039;; break;
default: $str = &#039;u&#039;; $stat[&#039;type&#039;]=&#039;unknown&#039;; break;
}
&nbsp;
$stat[&#039;type_octal&#039;] = sprintf("%07o", octdec($t));
&nbsp;
$str .= (($p&amp;0x0100)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0080)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0040)?(($p&amp;0x0800)?&#039;s&#039;:&#039;x&#039;):(($p&amp;0x0800)?&#039;S&#039;:&#039;-&#039;));
$str .= (($p&amp;0x0020)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0010)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0008)?(($p&amp;0x0400)?&#039;s&#039;:&#039;x&#039;):(($p&amp;0x0400)?&#039;S&#039;:&#039;-&#039;));
$str .= (($p&amp;0x0004)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0002)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0001)?(($p&amp;0x0200)?&#039;t&#039;:&#039;x&#039;):(($p&amp;0x0200)?&#039;T&#039;:&#039;-&#039;));
&nbsp;
$stat[&#039;default_umask&#039;]=sprintf("%04o",umask());
$stat[&#039;perm_human&#039;]=$str;
$stat[&#039;perm_octal1&#039;] = sprintf( "%o", ( $s[&#039;mode&#039;] &amp; 00777 ) );
$stat[&#039;perm_octal2&#039;] = sprintf("0%o", 0777 &amp; $p);
$stat[&#039;perm_dec&#039;] = sprintf("%04o", $p);
$stat[&#039;perm_mode&#039;]=$s[&#039;mode&#039;];   // File mode.
&nbsp;
$stat[&#039;file&#039;] = @realpath($filename);
$stat[&#039;basename&#039;] = basename( $filename );
&nbsp;
$stat[&#039;user_id&#039;] = $s[&#039;uid&#039;];
$stat[&#039;group_id&#039;] = $s[&#039;gid&#039;];
&nbsp;
$stat[&#039;device&#039;]=$s[&#039;dev&#039;];      // Device
$stat[&#039;device_number&#039;]=$s[&#039;rdev&#039;];    // Device number, if device.
$stat[&#039;inode&#039;]=$s[&#039;ino&#039;];      // File serial number
$stat[&#039;link_count&#039;]=$s[&#039;nlink&#039;];    // link count
if($stat[&#039;type&#039;]==&#039;link&#039;)$stat[&#039;link_to&#039;]=@readlink( $filename );
&nbsp;
$stat[&#039;size&#039;]=$s[&#039;size&#039;];    // Size of file, in bytes.
$stat[&#039;block_size&#039;]=$s[&#039;blksize&#039;];  // Optimal block size for I/O.
$stat[&#039;blocks&#039;]=$s[&#039;blocks&#039;];  // Number 512-byte blocks allocated
&nbsp;
$stat[&#039;time_access&#039;]=@date( &#039;Y M D H:i:s&#039;,$s[&#039;atime&#039;]);    // Time of last access.
$stat[&#039;time_modified&#039;]=@date( &#039;Y M D H:i:s&#039;,$s[&#039;mtime&#039;]);    // Time of last modification
$stat[&#039;time_created&#039;]=@date( &#039;Y M D H:i:s&#039;,$s[&#039;ctime&#039;]);    // Time of last status change
&nbsp;
clearstatcache();
return $stat;
}
&nbsp;
header(&#039;Content-Type: text/plain&#039;);
$stat=askapache_stat(__FILE__);
print_r($stat);
</pre>






<h3>Defining Permission Bits</h3>
<pre>
!defined(&#039;S_IFMT&#039;) &amp;&amp; define(&#039;S_IFMT&#039;, 0170000); //  mask for all types
!defined(&#039;S_IFSOCK&#039;) &amp;&amp; define(&#039;S_IFSOCK&#039;, 0140000); // type: socket
!defined(&#039;S_IFLNK&#039;) &amp;&amp; define(&#039;S_IFLNK&#039;, 0120000); // type:  symbolic link
!defined(&#039;S_IFREG&#039;) &amp;&amp; define(&#039;S_IFREG&#039;, 0100000); // type:  regular file
!defined(&#039;S_IFBLK&#039;) &amp;&amp; define(&#039;S_IFBLK&#039;, 0060000); // type:  block device
!defined(&#039;S_IFDIR&#039;) &amp;&amp; define(&#039;S_IFDIR&#039;, 0040000); // type:  directory
!defined(&#039;S_IFCHR&#039;) &amp;&amp; define(&#039;S_IFCHR&#039;, 0020000); // type:  character device
!defined(&#039;S_IFIFO&#039;) &amp;&amp; define(&#039;S_IFIFO&#039;, 0010000); // type:  fifo
&nbsp;
!defined(&#039;S_ISUID&#039;) &amp;&amp; define(&#039;S_ISUID&#039;, 0004000); // set-uid bit
!defined(&#039;S_ISGID&#039;) &amp;&amp; define(&#039;S_ISGID&#039;, 0002000); // set-gid bit
!defined(&#039;S_ISVTX&#039;) &amp;&amp; define(&#039;S_ISVTX&#039;, 0001000); // sticky bit
!defined(&#039;S_IRWXU&#039;) &amp;&amp; define(&#039;S_IRWXU&#039;, 00700); //  mask for owner permissions
!defined(&#039;S_IRUSR&#039;) &amp;&amp; define(&#039;S_IRUSR&#039;, 00400); //  owner: read permission
!defined(&#039;S_IWUSR&#039;) &amp;&amp; define(&#039;S_IWUSR&#039;, 00200); //  owner: write permission
!defined(&#039;S_IXUSR&#039;) &amp;&amp; define(&#039;S_IXUSR&#039;, 00100); //  owner: execute permission
!defined(&#039;S_IRWXG&#039;) &amp;&amp; define(&#039;S_IRWXG&#039;, 00070); //  mask for group permissions
!defined(&#039;S_IRGRP&#039;) &amp;&amp; define(&#039;S_IRGRP&#039;, 00040); //  group: read permission
!defined(&#039;S_IWGRP&#039;) &amp;&amp; define(&#039;S_IWGRP&#039;, 00020); //  group: write permission
!defined(&#039;S_IXGRP&#039;) &amp;&amp; define(&#039;S_IXGRP&#039;, 00010); //  group: execute permission
!defined(&#039;S_IRWXO&#039;) &amp;&amp; define(&#039;S_IRWXO&#039;, 00007); //  mask for others permissions
!defined(&#039;S_IROTH&#039;) &amp;&amp; define(&#039;S_IROTH&#039;, 00004); //  others:  read permission
!defined(&#039;S_IWOTH&#039;) &amp;&amp; define(&#039;S_IWOTH&#039;, 00002); //  others:  write permission
!defined(&#039;S_IXOTH&#039;) &amp;&amp; define(&#039;S_IXOTH&#039;, 00001); //  others:  execute permission
&nbsp;
!defined(&#039;S_IRWXUGO&#039;) &amp;&amp; define(&#039;S_IRWXUGO&#039;, (S_IRWXU | S_IRWXG | S_IRWXO));
!defined(&#039;S_IALLUGO&#039;) &amp;&amp; define(&#039;S_IALLUGO&#039;, (S_ISUID | S_ISGID | S_ISVTX | S_IRWXUGO));
!defined(&#039;S_IRUGO&#039;) &amp;&amp; define(&#039;S_IRUGO&#039;, (S_IRUSR | S_IRGRP | S_IROTH));
!defined(&#039;S_IWUGO&#039;) &amp;&amp; define(&#039;S_IWUGO&#039;, (S_IWUSR | S_IWGRP | S_IWOTH));
!defined(&#039;S_IXUGO&#039;) &amp;&amp; define(&#039;S_IXUGO&#039;, (S_IXUSR | S_IXGRP | S_IXOTH));
!defined(&#039;S_IRWUGO&#039;) &amp;&amp; define(&#039;S_IRWUGO&#039;, (S_IRUGO | S_IWUGO));
</pre>




<h2>How File Permissions Work</h2>
<p>When PHP is installed on your server by you or whoever runs the server, it uses the file permissions that are used by the Operating System running the server..  If you are smart or just lucky than you are running some type of BSD/Unix/Solaris/Linux/Sun based Operating system and PHP won't have any problems.  If you are running on a Locked, proprietary OS like Windows, PHP will still work but it has to use a lot of shortcuts and hacks to basically "Pretend" to act like the OS is BSD/Unix, and some key features just won't be available.</p>

<h2>The OS Permission Bits</h2>
<p>Here's the file permissions my Linux server uses, and which PHP automatically uses.  The code basically just defines the default permissions for files, and defines the file atributes for each file that you can access by using the stat function, which I've improved upon to make things easier.</p>
<p>Download: <a href='http://uploads.askapache.com/2008/11/stat.h' title="POSIX Standard: 5.6 File Characteristics">POSIX Standard: 5.6 File Characteristics<code>sys/stat.h</code></a></p>
<h3>Protection bits for File Owner</h3>
<pre>
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
</pre>

<h3>Protection bits for File Group</h3>
<pre>
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
</pre>

<h3>Protection bits for All Others</h3>
<pre>
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
</pre>


<h2>Some Example Permissions</h2>
<p><code>0477</code>  // owner has read only, other and group has rwx
<code>0677</code>  // owner has rw only, other and group has rwx</p>

<p><code>0444</code>  // all have read only
<code>0666</code>  // all have rw only</p>

<p><code>0400</code>  // owner has read only, group and others have no permission
<code>0600</code> // owner has rw only, group and others have no permission</p>

<p><code>0470</code>  // owner has read only, group has rwx, others have no permission
<code>0407</code>  // owner has read only, other has rwx, group has no permission</p>

<p><code>0670</code>  // owner has rw only, group has rwx, others have no permission
<code>0607</code>  // owner has rw only, group has no permission and others have rwx</p>


<h2>What's a File</h2>
<p>A file is not merely its contents, a name, and a file type. A file also has an owner (a user ID), a group (a group ID), permissions (what the owner can do with the file, what people in the group can do, and what everyone else can do), various timestamps, and other information. Collectively, we call these a file's attributes.</p>

<h2>Structure of File Mode Bits</h2>
<p>The file mode bits have two parts: the file permission bits, which control ordinary access to the file, and special mode bits, which affect only some files.</p>
<p>There are three kinds of permissions that a user can have for a file:</p>
<ol>
<li>permission to read the file. For directories, this means permission to list the contents of the directory.</li>
<li>permission to write to (change) the file. For directories, this means permission to create and remove files in the directory.</li>
<li>permission to execute the file (run it as a program). For directories, this means permission to access files in the directory.</li>
</ol>

<p>There are three categories of users who may have different permissions to perform any of the above operations on a file:</p>
<ol>
<li>the file's owner.</li>
<li>other users who are in the file's group</li>
<li>everyone else.</li>
</ol>

<p>Files are given an owner and group when they are created. Usually the owner is the current user and the group is the group of the directory the file is in, but this varies with the operating system, the file system the file is created on, and the way the file is created. You can change the owner and group of a file by using the <strong>chown</strong> and <strong>chgrp</strong> commands.</p>
<p>In addition to the three sets of three permissions listed above, the file mode bits have three special components, which affect only executable files (programs) and, on most systems, directories:</p>
<ol>
<li>Set the process's effective user ID to that of the file upon execution (called the set-user-ID bit, or sometimes the setuid bit). For directories on a few systems, give files created in the directory the same owner as the directory, no matter who creates them, and set the set-user-ID bit of newly-created subdirectories.</li>
<li>Set the process's effective group ID to that of the file upon execution (called the set-group-ID bit, or sometimes the setgid bit). For directories on most systems, give files created in the directory the same group as the directory, no matter what group the user who creates them is in, and set the set-group-ID bit of newly-created subdirectories.</li>
<li>Prevent unprivileged users from removing or renaming a file in a directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp.</li>
</ol>

<p>For regular files on some older systems, save the program's text image on the swap device so it will load more quickly when run; this is called the <code>sticky bit</code>.</p>



<h2>Setting Permissions</h2>
<p>The basic symbolic operations on a file's permissions are adding, removing, and setting the permission that certain users have to read, write, and execute or search the file. These operations have the following format:</p>
<p><code>users operation permissions</code></p>

<p>The spaces between the three parts above are shown for readability only; symbolic modes cannot contain spaces.  The users part tells which users' access to the file is changed. It consists of one or more of the following letters (or it can be empty). When more than one of these letters is given, the order that they are in does not matter.</p>
<ul>
<li><strong>u</strong> - the user who owns the file.</li>
<li><strong>g</strong> - other users who are in the file's group.</li>
<li><strong>o</strong> - all other users.</li>
<li><strong>a</strong> - all users; the same as ugo.</li>
</ul>

<p>The operation part tells how to change the affected users' access to the file, and is one of the following symbols:</p>
<ul>
<li><strong>+</strong> - to add the permissions to whatever permissions the users already have for the file.</li>
<li><strong>-</strong> - to remove the permissions from whatever permissions the users already have for the file.</li>
<li><strong>=</strong> - to make the permissions the only permissions that the users have for the file.</li>
</ul>

<p>The permissions part tells what kind of access to the file should be changed; it is normally zero or more of the following letters. As with the users part, the order does not matter when more than one letter is given. Omitting the permissions part is useful only with the = operation, where it gives the specified users no access at all to the file.</p>

<ul>
<li><strong>r</strong> - the permission the users have to read the file.</li>
<li><strong>w</strong> - the permission the users have to write to the file.</li>
<li><strong>x</strong> - the permission the users have to execute the file, or search it if it is a directory.</li>
</ul>

<p>For example, to give everyone permission to read and write a regular file, but not to execute it, use:</p>
<pre>
a=rw
</pre>

<p>To remove write permission for all users other than the file's owner, use:</p>
<pre>
go-w
</pre>

<p>The above command does not affect the access that the owner of the file has to it, nor does it affect whether other users can read or execute the file.</p>

<p>To give everyone except a file's owner no permission to do anything with that file, use the mode below. Other users could still remove the file, if they have write permission on the directory it is in.</p>
<pre>
go=
</pre>

<p>Another way to specify the same thing is:</p>
<pre>
og-rwx
</pre>



<h2>Copying Existing Permissions</h2>
<p>You can base a file's permissions on its existing permissions. To do this, instead of using a series of <strong>r, w, or x</strong> letters after the operator, you use the letter <strong>u, g, or o</strong>. For example, the mode</p>
<pre>
o+g
</pre>

<p>adds the permissions for users who are in a file's group to the permissions that other users have for the file. Thus, if the file started out as mode 664 (rw-rw-r--), the above mode would change it to mode 666 (rw-rw-rw-). If the file had started out as mode 741 (rwxr----x), the above mode would change it to mode 745 (rwxr--r-x). The - and = operations work analogously.</p>






<h2>Umask and Protection</h2>
<p>If the users part of a symbolic mode is omitted, it defaults to a (affect all users), except that any permissions that are set in the system variable umask are not affected. The value of umask can be set using the umask command. Its default value varies from system to system.</p>

<p>Omitting the users part of a symbolic mode is generally not useful with operations other than +. It is useful with + because it allows you to use umask as an easily customizable protection against giving away more permission to files than you intended to.  As an example, if umask has the value 2, which removes write permission for users who are not in the file's group, then the mode:</p>
<pre>
+w
</pre>

<p>adds permission to write to the file to its owner and to other users who are in the file's group, but not to other users. In contrast, the mode:</p>
<pre>
a+w
</pre>

<p>ignores umask, and does give write permission for the file to all users.</p>




<h2>Directories, Set-User-ID and Set-Group-ID Bits</h2>
<p>On most systems, if a directory's set-group-ID bit is set, newly created subfiles inherit the same group as the directory, and newly created subdirectories inherit the set-group-ID bit of the parent directory. On a few systems, a directory's set-user-ID bit has a similar effect on the ownership of new subfiles and the set-user-ID bits of new subdirectories. These mechanisms let users share files more easily, by lessening the need to use chmod or chown to share new files.</p>

<p>These convenience mechanisms rely on the set-user-ID and set-group-ID bits of directories. If commands like chmod and mkdir routinely cleared these bits on directories, the mechanisms would be less convenient and it would be harder to share files. Therefore, a command like chmod does not affect the set-user-ID or set-group-ID bits of a directory unless the user specifically mentions them in a symbolic mode, or sets them in a numeric mode. For example, on systems that support set-group-ID inheritance:</p>

<pre>
# These commands leave the set-user-ID and
# set-group-ID bits of the subdirectories alone,
# so that they retain their default values.
mkdir A B C
chmod 755 A
chmod 0755 B
chmod u=rwx,go=rx C
mkdir -m 755 D
mkdir -m 0755 E
mkdir -m u=rwx,go=rx F
</pre>

<p>If you want to try to set these bits, you must mention them explicitly in the symbolic or numeric modes, e.g.:</p>
<pre>
# These commands try to set the set-user-ID
# and set-group-ID bits of the subdirectories.
mkdir G H
chmod 6755 G
chmod u=rwx,go=rx,a+s H
mkdir -m 6755 I
mkdir -m u=rwx,go=rx,a+s J
</pre>

<p>If you want to try to clear these bits, you must mention them explicitly in a symbolic mode, e.g.:</p>
<pre>
# This command tries to clear the set-user-ID
# and set-group-ID bits of the directory D.
chmod a-s D
</pre>











<h2>Numeric Modes</h2>
<p>The permissions granted to the user, to other users in the file's group, and to other users not in the file's group each require three bits, which are represented as one octal digit. The three special mode bits also require one bit each, and they are as a group represented as another octal digit. Here is how the bits are arranged, starting with the lowest valued bit:</p>

<h3>Other users not in the file's group:</h3>
<pre>
1 Execute/search
2 Write
4 Read
</pre>

<h3>Other users in the file's group:</h3>
<pre>
10 Execute/search
20 Write
40 Read
</pre>

<h3>The file's owner:</h3>
<pre>
100 Execute/search
200 Write
400 Read
</pre>

<h3>Special mode bits:</h3>
<pre>
1000 Restricted deletion flag or sticky bit
2000 Set group ID on execution
4000 Set user ID on execution
</pre>

<p>For example, numeric <code>mode 4755</code> corresponds to symbolic mode <code>u=rwxs,go=rx</code>, and numeric m<code>ode 664</code> corresponds to symbolic mode <code>ug=rw,o=r</code>. Numeric <code>mode 0</code> corresponds to symbolic mode <code>a=</code>.</p>




<h2>Apache's Internal Bits (hex)</h2>
<pre>
#define APR_FPROT_USETID   0x8000 /* Set user id */
#define APR_FPROT_UREAD   0x0400 /* Read by user */
#define APR_FPROT_UWRITE   0x0200 /* Write by user */
#define APR_FPROT_UEXECUTE 0x0100 /* Execute by user */
&nbsp;
#define APR_FPROT_GSETID   0x4000 /* Set group id */
#define APR_FPROT_GREAD   0x0040 /* Read by group */
#define APR_FPROT_GWRITE   0x0020 /* Write by group */
#define APR_FPROT_GEXECUTE 0x0010 /* Execute by group */
&nbsp;
#define APR_FPROT_WSTICKY 0x2000 /* Sticky bit */
#define APR_FPROT_WREAD   0x0004 /* Read by others */
#define APR_FPROT_WWRITE 0x0002 /* Write by others */
#define APR_FPROT_WEXECUTE 0x0001 /* Execute by others */
&nbsp;
#define APR_FPROT_OS_DEFAULT  0x0FFF /* use OS&#039;s default permissions */
&nbsp;
/* additional permission flags for apr_file_copy  and apr_file_append */
#define APR_FPROT_FILE_SOURCE_PERMS 0x1000 /* Copy source file&#039;s permissions */
</pre>


<p>Download: <a href='http://uploads.askapache.com/2008/11/fileacc.c' title="A file to put ALL of the accessor functions for apr_file_t types"><code>httpd-2.2.10/srclib/apr/file_io/unix/fileacc.c</code></a> Here's some interesting bitmasking done by Apache that uses the defined bits set earlier by stat.h</p>
<pre>
apr_unix_perms2mode(perms){
 mode=0;
 if (perms &amp; APR_USETID) mode |= S_ISUID;
 if (perms &amp; APR_UREAD)  mode |= S_IRUSR;
 if (perms &amp; APR_UWRITE) mode |= S_IWUSR;
 if (perms &amp; APR_UEXECUTE) mode |= S_IXUSR;
&nbsp;
 if (perms &amp; APR_GSETID) mode |= S_ISGID;
 if (perms &amp; APR_GREAD)  mode |= S_IRGRP;
 if (perms &amp; APR_GWRITE) mode |= S_IWGRP;
 if (perms &amp; APR_GEXECUTE) mode |= S_IXGRP;
&nbsp;
 if (perms &amp; APR_WSTICKY) mode |= S_ISVTX;
 if (perms &amp; APR_WREAD)  mode |= S_IROTH;
 if (perms &amp; APR_WWRITE) mode |= S_IWOTH;
 if (perms &amp; APR_WEXECUTE) mode |= S_IXOTH;
 return mode;
}
&nbsp;
apr_unix_mode2perms(mode){
 perms = 0;
 if (mode &amp; S_ISUID)perms |= APR_USETID;
 if (mode &amp; S_IRUSR)perms |= APR_UREAD;
 if (mode &amp; S_IWUSR)perms |= APR_UWRITE;
 if (mode &amp; S_IXUSR)perms |= APR_UEXECUTE;
&nbsp;
 if (mode &amp; S_ISGID)perms |= APR_GSETID;
 if (mode &amp; S_IRGRP)perms |= APR_GREAD;
 if (mode &amp; S_IWGRP)perms |= APR_GWRITE;
 if (mode &amp; S_IXGRP)perms |= APR_GEXECUTE;
&nbsp;
 if (mode &amp; S_ISVTX)perms |= APR_WSTICKY;
 if (mode &amp; S_IROTH)perms |= APR_WREAD;
 if (mode &amp; S_IWOTH)perms |= APR_WWRITE;
 if (mode &amp; S_IXOTH)perms |= APR_WEXECUTE;
 return perms;
}
</pre>





<h2>umask</h2>
<pre>
umask(int mask){
 arg1;
 int oldumask;
 int arg_count = ZEND_NUM_ARGS();
 oldumask = umask(077);
&nbsp;
 if (BG(umask) == -1) BG(umask) = oldumask;
 if (arg_count == 0) umask(oldumask);
&nbsp;
 convert_to_long_ex(arg1);
 umask(Z_LVAL_PP(arg1));
 RETURN_LONG(oldumask);
}
</pre>

















<h2>File Attributes</h2>
<p>Each file will have attributes based on the type of OS.. Using the stat command you can view them.</p>

<h3>Viewing stat results</h3>
<pre>
* %a - Access rights in octal
* %A - Access rights in human readable form
* %b - Number of blocks allocated (see %B)
* %B - The size in bytes of each block reported by %b
* %d - Device number in decimal
* %D - Device number in hex
* %f - Raw mode in hex
* %F - File type
* %g - Group ID of owner
* %G - Group name of owner
* %h - Number of hard links
* %i - Inode number
* %n - File name
* %N - Quoted file name with dereference if symbolic link
* %o - I/O block size
* %s - Total size, in bytes
* %t - Major device type in hex
* %T - Minor device type in hex
* %u - User ID of owner
* %U - User name of owner
* %x - Time of last access
* %X - Time of last access as seconds since Epoch
* %y - Time of last modification
* %Y - Time of last modification as seconds since Epoch
* %z - Time of last change
* %Z - Time of last change as seconds since Epoch
</pre>




<h2>The OS Attribute Bits</h2>
<p>These defined values are what allows your operating system to determine the type of file being accessed. </p>
<pre>
#define S_IFMT   00170000  /* These bits determine file type. */
#define S_IFSOCK 0140000  /* Socket file */
#define S_IFLNK   0120000  /* Symbolic Link */
#define S_IFREG   0100000  /* Regular file */
#define S_IFDIR   0040000  /* Directory */
#define S_IFIFO  0010000   /* FIFO first-in-first-out file */
&nbsp;
/* Such devices can be read either a character at a time or a "block" (many characters) at a time,
hence we say there are block special files and character special files. */
#define S_IFBLK   0060000  /* Block device */
#define S_IFCHR  0020000  /* Character device */
</pre>

<h3>Special Permission Bits</h3>
<pre>
#define S_ISUID  0004000  /* Set user ID on execution.  */
#define S_ISGID  0002000  /* Set group ID on execution.  */
#define S_ISVTX  0001000 /* Save swapped text after use (sticky).  */
</pre>

<h3>Bitmasking to determine Filetype</h3>
<pre>
#define S_ISLNK(m) (((m) &amp; S_IFMT) == S_IFLNK)
#define S_ISREG(m) (((m) &amp; S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) &amp; S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) &amp; S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) &amp; S_IFMT) == S_IFBLK)
#define S_ISFIFO(m) (((m) &amp; S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) &amp; S_IFMT) == S_IFSOCK)
</pre>

<h3>Default Permission Masks</h3>
<pre>
#define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
#define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
#define S_IRUGO  (S_IRUSR|S_IRGRP|S_IROTH)
#define S_IWUGO  (S_IWUSR|S_IWGRP|S_IWOTH)
#define S_IXUGO  (S_IXUSR|S_IXGRP|S_IXOTH)
</pre>


<p>Download: <a href='http://uploads.askapache.com/2008/11/filestat.c' title="handles file stat"><code>httpd-2.2.10/srclib/apr/file_io/unix/filestat.c</code></a>, this file shows a simple way to determine the type of file.</p>
<pre>
filetype_from_mode(mode){
 type;
 switch (mode &amp; S_IFMT) {
  case S_IFREG:  type = APR_REG;  break;
  case S_IFDIR:  type = APR_DIR;  break;
  case S_IFLNK:  type = APR_LNK;  break;
&nbsp;
  case S_IFCHR:  type = APR_CHR;  break;
  case S_IFBLK:  type = APR_BLK;  break;
  case S_IFFIFO: type = APR_PIPE; break;
  case S_IFSOCK: type = APR_SOCK; break;
  default: type = APR_UNKFILE;
 }
 return type;
}
</pre>

<h3>Apache Stat Bits</h3>
<pre>
#define APR_FINFO_LINK  0x00000001 /* Stat the link not the file itself if it is a link */
#define APR_FINFO_MTIME  0x00000010 /* Modification Time */
#define APR_FINFO_CTIME  0x00000020 /* Creation or inode-changed time */
#define APR_FINFO_ATIME  0x00000040 /* Access Time */
#define APR_FINFO_SIZE  0x00000100 /* Size of the file */
#define APR_FINFO_CSIZE  0x00000200 /* Storage size consumed by the file */
#define APR_FINFO_DEV  0x00001000 /* Device */
#define APR_FINFO_INODE  0x00002000 /* Inode */
#define APR_FINFO_NLINK  0x00004000 /* Number of links */
#define APR_FINFO_TYPE  0x00008000 /* Type */
#define APR_FINFO_USER  0x00010000 /* User */
#define APR_FINFO_GROUP  0x00020000 /* Group */
#define APR_FINFO_UPROT  0x00100000 /* User protection bits */
#define APR_FINFO_GPROT  0x00200000 /* Group protection bits */
#define APR_FINFO_WPROT  0x00400000 /* World protection bits */
#define APR_FINFO_ICASE  0x01000000 /* if dev is case insensitive */
#define APR_FINFO_NAME  0x02000000 /* name in proper case */
#define APR_FINFO_MIN  0x00008170 /* type, mtime, ctime, atime, size */
#define APR_FINFO_IDENT  0x00003000 /* dev and inode */
#define APR_FINFO_OWNER  0x00030000 /* user and group */
#define APR_FINFO_PROT  0x00700000 /* all protections */
#define APR_FINFO_NORM  0x0073b170 /* an atomic unix apr_stat() */
#define APR_FINFO_DIRENT 0x02000000 /* an atomic unix apr_dir_read() */
</pre>

<h3>The Apache file information structure.</h3>
<pre>
apr_uid_t user;  /* The user id that owns the file */
apr_gid_t group;  /* The group id that owns the file */
apr_ino_t inode; /* The inode of the file. */
apr_dev_t device; /* The id of the device the file is on. */
apr_int32_t nlink; /* The number of hard links to the file. */
apr_off_t size;  /* The size of the file */
apr_off_t csize; /* The storage size consumed by the file */
apr_time_t atime; /* The time the file was last accessed */
apr_time_t mtime; /* The time the file was last modified */
apr_time_t ctime; /* The time the file was created, or the inode was last changed */
const char *fname; /* The pathname of the file (possibly unrooted) */
const char *name; /* The file&#039;s name (no path) in filesystem case */
</pre>



<h3>File Time Attributes</h3>
<blockquote><cite><a href="http://php.net/manual/en/function.touch.php">touch</a></cite>
<p>If changing both the access and modification times to the current time, touch can change the timestamps for files that the user running it does not own but has write permission for. Otherwise, the user must own the files.</p>
</blockquote>

<p>Although touch provides options for changing two of the times the times of last access and modification of a file, there is actually a third one as well: the inode change time. This is often referred to as a file's ctime. The inode change time represents the time when the file's meta-information last changed. One common example of this is when the permissions of a file change. Changing the permissions doesn't access the file, so the atime doesn't change, nor does it modify the file, so the mtime doesn't change. Yet, something about the file itself has changed, and this must be noted somewhere. This is the job of the ctime field. This is necessary, so that, for example, a backup program can make a fresh copy of the file, including the new permissions value. Another operation that modifies a file's ctime without affecting the others is renaming. In any case, it is not possible, in normal operations, for a user to change the ctime field to a user-specified value.</p>
</blockquote>













<a name="Shared_hosting_user_security"></a>
<h2>Shared hosting user security </h2>
<ul>
	<li><a href="#Shared_hosting_user_security">Shared hosting user security</a></li>
	<li><a href="#Apache_Security">Apache Security</a></li>
	<li><a href="#Multiuser_security_setup_example">Multiuser security setup example</a></li>
	<li><a href="#SSH_key_fingerprints">SSH key fingerprints</a></li>
	<li><a href="#External_Links">External Links</a></li>
</ul>
<p>WebHost allows you to create multiple users per account. Each user can have domain assigned to its home home directory accessible via FTP or SSH/SCP. The problem with multiple users on the same account is that they share the same default unix group, and default permissions allow their files to be easily modified by the members of this group. Usually this doesn't pose a problem as each user is probably trusted by account owner to not to mess with others files, but if one of the users have their web application hacked then all other users on the same account will be in danger. </p>
<p>By default all files in your account are created with 644 privileges and directories are with 775. That means any user can read your files and any user from the same account can move and add files in your freshly made directories. Your home directory is different, though. By default it carries 751 attribute meaning that only members of your group can see your files, but can't add any new. These group access schemes are possible, because every user in your account has its primary/default group set to "pgxxxxxx", which is assigned to every new file you create by default. The normal way to secure users from web-intrusion is to assign a separate group to the web-server user, removing it from default group. This way, exploited scripts will not be able to traverse into home directories of other users on your account. To allow account users to update centralized web-site they could be added to web-site group explicitly. But this "normal way" doesn't work with DreamHost, because you can't delete web-user from the default group and unless you set access for every new file explicitly, it will be possible for an intruder to read it. </p>
<p>To make managing privileges easier in interactive sessions "umask 007" command can be specified in your .bash_profile - this makes all new files carry xx0 mask. You also need to control your scripts (web based or cron/shell) so that they set mask for critical files explicitly. To secure account users from access by means of hacked user script you would also like to define another group for every user in your account and change group ownership of the user's home directory to that group with "set gid" bit set (and optional umask 007 in .bash_profile). </p>
<p>Therefore, to secure your users from web-intrusion you need to: </p>
<ol>
	<li>Add a separate user and group for every domain where apache will be running </li>
	<li>Add a separate group for other user accounts </li>
	<li>Change the default group for new files created by your users by changing the group of their home directory and setting "set gid" bit for it (it is impossible to do this with FTP accounts, therefore you will need to login in each account via SSH) </li>
	<li>Add users who need access to web-site into the web-user group </li>
	<li>Optionally set umask 007 in .bash_profile for every user to tweak default WebHost775/664 permissions to something like 770/660 for directories and files that are not meant to be read by Apache (660 could also be used for all web scripts including .php as they are not read by dhapache CGI, but merely executed) </li>
</ol>
<h2><a name="Apache_Security"></a>Apache Security </h2>
<p>All your web files that need to be read by Apache should be readable by everyone as Apache itself is run under dhapache user. However, executable scripts like .php are executed under your own user and do not have to be world readable as they are not actually read by Apache, but executed via <a href="http://en.wikipedia.org/wiki/suEXEC">suEXEC</a>. Quite the opposite - to prevent your code or database settings from being messed by any third-parties you SHOULD set permissions to these files explicitly to something like 640 or even 600 depending on who do you trust. </p>
<a name="Multiuser_security_setup_example"></a>
<h2>Multiuser security setup example </h2>
<p>For our example, we will create a <em>rainforce_www</em> user and a <em>aapp_www</em> group for serving web files with apache and setup a <em>rainforce</em> user with a 'aapp<em> group to manage mail and keep other files on DH privately. Since these records already exist, you will need to subsitute your own names.</em> </p>
<ul>
	<li>Login to create the users <em>rainforce_www</em> and <em>rainforce</em> with shell access. </li>
	<li>Create two groups - <em>aapp_www</em> and <em>aapp</em>. Note that users created in previous step are still members of the same default <em>pg</em>xxxxxx group. </li>
	<li>Add <em>rainforce_www</em> to 'the 'aapp_www<em> group and </em>rainforce<em> to both the </em>aapp_www<em> and </em>aapp<em> groups</em> </li>
	<li>Move your domain to <em>rainforce_www</em> account (mine is rainforce.org) </li>
	<li>Now login to SSH with your <em>rainforce_www</em> user and change the default group for your home directory with "sgid" bit set to make all current and new files/directories created in this directory have the same <em>aapp_www</em> group. </li>
</ul>
<pre>
 $ chgrp -R aapp_www .
 $ chmod 2751 .
 $ chmod 2771 rainforce.org
</pre>
<p>By setting 2771 the directory will be writable by the owner, the group and will be only executable by others. The contents of an executable only directory cannot be listed, but the files inside it can be read (if the permissions of the file allow it). It is important that the directory can be executable in order to allow static content (e.g. .html files) inside it to be read. Remember that directories you don't want anyone to have web access to, should be 0770 (writable by the owner and group, or 0750 writable by the owner and readable by group). Such strict permissions should by applied to password files, php include files or databases files (such as SQLite, BDB, etc). </p>
<ul>
	<li>Do the same for <em>rainforce</em> user, but specify <em>aapp</em> group instead. </li>
</ul>
<pre>
 $ chgrp -R aapp .
 $ chmod 2751 .
</pre>
<ul>
	<li>Optionally modify umask in .bash_profile in user's home to 007 to make all files created by this user have 660 permissions set by default. If you want that newly created files by accessible by the web, you need to manually setup it's permissions to 664. </li>
</ul>
<p>Now I can login as the user "rainforce" and update the web-site in the ../rainforce_www/rainforce.org directory. There is one more setup needed. Because files copied from other accounts can have 644 permissions set instead of 664, you need a script which will update permissions to 664 or 660 to allow other group members modify such files. </p>
<h2><a name="SSH_key_fingerprints"></a>SSH key fingerprints </h2>
<p>Just gen your own I guess </p>
<h2>External Links </h2>
<ul>
	<li><a href="http://oldfield.wattle.id.au/luv/permissions.html" title="http://oldfield.wattle.id.au/luv/permissions.html" rel="nofollow">Introduction to Unix file permissions</a> </li>
	<li><a href="http://www.perlfect.com/articles/chmod.shtml" title="http://www.perlfect.com/articles/chmod.shtml" rel="nofollow">Understanding UNIX permission and chmod</a> </li>
</ul>
<p>Original Article from <a href="http://wiki.dreamhost.com/index.php?title=Security">DreamHost Wiki</a></p>
<p>Content is available under <a href="http://www.gnu.org/copyleft/fdl.html" class="external " title="http://www.gnu.org/copyleft/fdl.html" rel="nofollow">GNU Free Documentation License 1.2</a>.</p>





<h2>Example File Permission Bits</h2>

<h3><code>/usr/lib/w3m/cgi-bin/dirlist.cgi</code></h3>
<pre>
sub utype {
  local($_) = @_;
  local(%T) = (
    0010000, &#039;PIPE&#039;,
    0020000, &#039;CHR&#039;,
    0040000, &#039;DIR&#039;,
    0060000, &#039;BLK&#039;,
    0100000, &#039;FILE&#039;,
    0120000, &#039;LINK&#039;,
    0140000, &#039;SOCK&#039;,
  );
  return $T{($_ &amp; 0170000)} || &#039;FILE&#039;;
}
&nbsp;
sub umode {
  local($_) = @_;
  local(%T) = (
    0010000, &#039;p&#039;,
    0020000, &#039;c&#039;,
    0040000, &#039;d&#039;,
    0060000, &#039;b&#039;,
    0100000, &#039;-&#039;,
    0120000, &#039;l&#039;,
    0140000, &#039;s&#039;,
  );
&nbsp;
  return ($T{($_ &amp; 0170000)} || &#039;-&#039;)
     . (($_ &amp; 00400) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00200) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 04000) ? &#039;s&#039; :
       (($_ &amp; 00100) ? &#039;x&#039; : &#039;-&#039;))
     . (($_ &amp; 00040) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00020) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 02000) ? &#039;s&#039; :
       (($_ &amp; 00010) ? &#039;x&#039; : &#039;-&#039;))
     . (($_ &amp; 00004) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00002) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 01000) ? &#039;t&#039; :
       (($_ &amp; 00001) ? &#039;x&#039; : &#039;-&#039;));
}
</pre>

<h3><code>/usr/lib/perl/5.8.4/linux/stat.ph</code></h3>
<pre>
        eval &#039;sub S_IFMT () {00170000;}&#039; unless defined(&amp;S_IFMT);
        eval &#039;sub S_IFSOCK () {0140000;}&#039; unless defined(&amp;S_IFSOCK);
        eval &#039;sub S_IFLNK () {0120000;}&#039; unless defined(&amp;S_IFLNK);
        eval &#039;sub S_IFREG () {0100000;}&#039; unless defined(&amp;S_IFREG);
        eval &#039;sub S_IFBLK () {0060000;}&#039; unless defined(&amp;S_IFBLK);
        eval &#039;sub S_IFDIR () {0040000;}&#039; unless defined(&amp;S_IFDIR);
        eval &#039;sub S_IFCHR () {0020000;}&#039; unless defined(&amp;S_IFCHR);
        eval &#039;sub S_IFIFO () {0010000;}&#039; unless defined(&amp;S_IFIFO);
        eval &#039;sub S_ISUID () {0004000;}&#039; unless defined(&amp;S_ISUID);
        eval &#039;sub S_ISGID () {0002000;}&#039; unless defined(&amp;S_ISGID);
        eval &#039;sub S_ISVTX () {0001000;}&#039; unless defined(&amp;S_ISVTX);
        eval &#039;sub S_ISLNK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFLNK));
        }&#039; unless defined(&amp;S_ISLNK);
        eval &#039;sub S_ISREG {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFREG));
        }&#039; unless defined(&amp;S_ISREG);
        eval &#039;sub S_ISDIR {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFDIR));
        }&#039; unless defined(&amp;S_ISDIR);
        eval &#039;sub S_ISCHR {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFCHR));
        }&#039; unless defined(&amp;S_ISCHR);
        eval &#039;sub S_ISBLK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFBLK));
        }&#039; unless defined(&amp;S_ISBLK);
        eval &#039;sub S_ISFIFO {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFIFO));
        }&#039; unless defined(&amp;S_ISFIFO);
        eval &#039;sub S_ISSOCK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFSOCK));
        }&#039; unless defined(&amp;S_ISSOCK);
        eval &#039;sub S_IRWXU () {00700;}&#039; unless defined(&amp;S_IRWXU);
        eval &#039;sub S_IRUSR () {00400;}&#039; unless defined(&amp;S_IRUSR);
        eval &#039;sub S_IWUSR () {00200;}&#039; unless defined(&amp;S_IWUSR);
        eval &#039;sub S_IXUSR () {00100;}&#039; unless defined(&amp;S_IXUSR);
        eval &#039;sub S_IRWXG () {00070;}&#039; unless defined(&amp;S_IRWXG);
        eval &#039;sub S_IRGRP () {00040;}&#039; unless defined(&amp;S_IRGRP);
        eval &#039;sub S_IWGRP () {00020;}&#039; unless defined(&amp;S_IWGRP);
        eval &#039;sub S_IXGRP () {00010;}&#039; unless defined(&amp;S_IXGRP);
        eval &#039;sub S_IRWXO () {00007;}&#039; unless defined(&amp;S_IRWXO);
        eval &#039;sub S_IROTH () {00004;}&#039; unless defined(&amp;S_IROTH);
        eval &#039;sub S_IWOTH () {00002;}&#039; unless defined(&amp;S_IWOTH);
        eval &#039;sub S_IXOTH () {00001;}&#039; unless defined(&amp;S_IXOTH);
    }
    if(defined(&amp;__KERNEL__)) {
        eval &#039;sub S_IRWXUGO () {( &amp;S_IRWXU| &amp;S_IRWXG| &amp;S_IRWXO);}&#039; unless defined(&amp;S_IRWXUGO);
        eval &#039;sub S_IALLUGO () {( &amp;S_ISUID| &amp;S_ISGID| &amp;S_ISVTX| &amp;S_IRWXUGO);}&#039; unless defined(&amp;S_IALLUGO);
        eval &#039;sub S_IRUGO () {( &amp;S_IRUSR| &amp;S_IRGRP| &amp;S_IROTH);}&#039; unless defined(&amp;S_IRUGO);
        eval &#039;sub S_IWUGO () {( &amp;S_IWUSR| &amp;S_IWGRP| &amp;S_IWOTH);}&#039; unless defined(&amp;S_IWUGO);
        eval &#039;sub S_IXUGO () {( &amp;S_IXUSR| &amp;S_IXGRP| &amp;S_IXOTH);}&#039; unless defined(&amp;S_IXUGO);
        require &#039;linux/types.ph&#039;;
        require &#039;linux/time.ph&#039;;
    }
&nbsp;
</pre>

<p><a href="http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.8a2/src/mozilla-source-1.8a2.tar.bz2 ">Mozilla-Source 1.8a2</a></p>
<pre>
/* notice that these valuse are octal. */
const PERM_IRWXU = 00700;  /* read, write, execute/search by owner */
const PERM_IRUSR = 00400;  /* read permission, owner */
const PERM_IWUSR = 00200;  /* write permission, owner */
const PERM_IXUSR = 00100;  /* execute/search permission, owner */
const PERM_IRWXG = 00070;  /* read, write, execute/search by group */
const PERM_IRGRP = 00040;  /* read permission, group */
const PERM_IWGRP = 00020;  /* write permission, group */
const PERM_IXGRP = 00010;  /* execute/search permission, group */
const PERM_IRWXO = 00007;  /* read, write, execute/search by others */
const PERM_IROTH = 00004;  /* read permission, others */
const PERM_IWOTH = 00002;  /* write permission, others */
const PERM_IXOTH = 00001;  /* execute/search permission, others */
&nbsp;
const MODE_RDONLY   = 0x01;
const MODE_WRONLY   = 0x02;
const MODE_RDWR     = 0x04;
const MODE_CREATE   = 0x08;
const MODE_APPEND   = 0x10;
const MODE_TRUNCATE = 0x20;
const MODE_SYNC     = 0x40;
const MODE_EXCL     = 0x80;
</pre>


<h3><code>/usr/include/libpng12/png.h</code></h3>
<pre>
/* Transform masks for the high-level interface */
#define PNG_TRANSFORM_IDENTITY       0x0000    /* read and write */
#define PNG_TRANSFORM_STRIP_16       0x0001    /* read only */
#define PNG_TRANSFORM_STRIP_ALPHA    0x0002    /* read only */
#define PNG_TRANSFORM_PACKING        0x0004    /* read and write */
#define PNG_TRANSFORM_PACKSWAP       0x0008    /* read and write */
#define PNG_TRANSFORM_EXPAND         0x0010    /* read only */
#define PNG_TRANSFORM_INVERT_MONO    0x0020    /* read and write */
#define PNG_TRANSFORM_SHIFT          0x0040    /* read and write */
#define PNG_TRANSFORM_BGR            0x0080    /* read and write */
#define PNG_TRANSFORM_SWAP_ALPHA     0x0100    /* read and write */
#define PNG_TRANSFORM_SWAP_ENDIAN    0x0200    /* read and write */
#define PNG_TRANSFORM_INVERT_ALPHA   0x0400    /* read and write */
#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* WRITE only */
</pre>


<h3><code>/usr/lib/python2.4/stat.py</code></h3>
<pre>
# Extract bits from the mode
&nbsp;
def S_IMODE(mode):
    return mode &amp; 07777
&nbsp;
def S_IFMT(mode):
    return mode &amp; 0170000
&nbsp;
# Constants used as S_IFMT() for various file types
# (not all are implemented on all systems)
&nbsp;
S_IFDIR  = 0040000
S_IFCHR  = 0020000
S_IFBLK  = 0060000
S_IFREG  = 0100000
S_IFIFO  = 0010000
S_IFLNK  = 0120000
S_IFSOCK = 0140000
&nbsp;
# Functions to test for each file type
&nbsp;
def S_ISDIR(mode):
    return S_IFMT(mode) == S_IFDIR
&nbsp;
def S_ISCHR(mode):
    return S_IFMT(mode) == S_IFCHR
&nbsp;
def S_ISBLK(mode):
    return S_IFMT(mode) == S_IFBLK
&nbsp;
def S_ISREG(mode):
    return S_IFMT(mode) == S_IFREG
&nbsp;
def S_ISFIFO(mode):
    return S_IFMT(mode) == S_IFIFO
&nbsp;
def S_ISLNK(mode):
    return S_IFMT(mode) == S_IFLNK
&nbsp;
def S_ISSOCK(mode):
    return S_IFMT(mode) == S_IFSOCK
&nbsp;
# Names for permission bits
&nbsp;
S_ISUID = 04000
S_ISGID = 02000
S_ENFMT = S_ISGID
S_ISVTX = 01000
S_IREAD = 00400
S_IWRITE = 00200
S_IEXEC = 00100
S_IRWXU = 00700
S_IRUSR = 00400
S_IWUSR = 00200
S_IXUSR = 00100
S_IRWXG = 00070
S_IRGRP = 00040
S_IWGRP = 00020
S_IXGRP = 00010
S_IRWXO = 00007
S_IROTH = 00004
S_IWOTH = 00002
S_IXOTH = 00001
</pre>


<h3><code>/usr/include/bits/stat.h</code></h3>
<pre>
/* Encoding of the file mode.  */
&nbsp;
#define __S_IFMT        0170000 /* These bits determine file type.  */
&nbsp;
/* File types.  */
#define __S_IFDIR       0040000 /* Directory.  */
#define __S_IFCHR       0020000 /* Character device.  */
#define __S_IFBLK       0060000 /* Block device.  */
#define __S_IFREG       0100000 /* Regular file.  */
#define __S_IFIFO       0010000 /* FIFO.  */
#define __S_IFLNK       0120000 /* Symbolic link.  */
#define __S_IFSOCK      0140000 /* Socket.  */
&nbsp;
/* POSIX.1b objects.  Note that these macros always evaluate to zero.  But
   they do it by enforcing the correct use of the macros.  */
#define __S_TYPEISMQ(buf)  ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
#define __S_TYPEISSEM(buf) ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
#define __S_TYPEISSHM(buf) ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
&nbsp;
/* Protection bits.  */
&nbsp;
#define __S_ISUID       04000   /* Set user ID on execution.  */
#define __S_ISGID       02000   /* Set group ID on execution.  */
#define __S_ISVTX       01000   /* Save swapped text after use (sticky).  */
#define __S_IREAD       0400    /* Read by owner.  */
#define __S_IWRITE      0200    /* Write by owner.  */
#define __S_IEXEC       0100    /* Execute by owner.  */
</pre>



<h3><code>/usr/include/linux/nfs.h</code></h3>
<pre>
#define NFS_FIFO_DEV    (-1)
#define NFSMODE_FMT     0170000
#define NFSMODE_DIR     0040000
#define NFSMODE_CHR     0020000
#define NFSMODE_BLK     0060000
#define NFSMODE_REG     0100000
#define NFSMODE_LNK     0120000
#define NFSMODE_SOCK    0140000
#define NFSMODE_FIFO    0010000
</pre>


<h3><code>/usr/include/linux/nfs3.h</code></h3>
<pre>
#define NFS3_FIFO_DEV           (-1)
#define NFS3MODE_FMT            0170000
#define NFS3MODE_DIR            0040000
#define NFS3MODE_CHR            0020000
#define NFS3MODE_BLK            0060000
#define NFS3MODE_REG            0100000
#define NFS3MODE_LNK            0120000
#define NFS3MODE_SOCK           0140000
#define NFS3MODE_FIFO           0010000
&nbsp;
/* Flags for access() call */
#define NFS3_ACCESS_READ        0x0001
#define NFS3_ACCESS_LOOKUP      0x0002
#define NFS3_ACCESS_MODIFY      0x0004
#define NFS3_ACCESS_EXTEND      0x0008
#define NFS3_ACCESS_DELETE      0x0010
#define NFS3_ACCESS_EXECUTE     0x0020
#define NFS3_ACCESS_FULL        0x003f
</pre>


<h3><code>/usr/include/linux/stat.h</code></h3>
<pre>
#define S_IFMT  00170000
#define S_IFSOCK 0140000
#define S_IFLNK  0120000
#define S_IFREG  0100000
#define S_IFBLK  0060000
#define S_IFDIR  0040000
#define S_IFCHR  0020000
#define S_IFIFO  0010000
#define S_ISUID  0004000
#define S_ISGID  0002000
#define S_ISVTX  0001000
&nbsp;
#define S_ISLNK(m)      (((m) &amp; S_IFMT) == S_IFLNK)
#define S_ISREG(m)      (((m) &amp; S_IFMT) == S_IFREG)
#define S_ISDIR(m)      (((m) &amp; S_IFMT) == S_IFDIR)
#define S_ISCHR(m)      (((m) &amp; S_IFMT) == S_IFCHR)
#define S_ISBLK(m)      (((m) &amp; S_IFMT) == S_IFBLK)
#define S_ISFIFO(m)     (((m) &amp; S_IFMT) == S_IFIFO)
#define S_ISSOCK(m)     (((m) &amp; S_IFMT) == S_IFSOCK)
&nbsp;
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
&nbsp;
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
&nbsp;
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
</pre>











<h2>Further File Permissions Reading</h2>
<h3>Related PHP Functions</h3>
<ul>
<li><a href="http://php.net/manual/en/function.fileperms.php">fileperms</a></li>
<li><a href="http://php.net/manual/en/function.stat.php">stat</a></li>
<li><a href="http://php.net/manual/en/function.chmod.php">chmod</a></li>
<li><a href="http://php.net/manual/en/function.clearstatcache.php">clearstatcache</a></li>
<li><a href="http://php.net/manual/en/function.chown.php">chown</a></li>
<li><a href="http://php.net/manual/en/function.chgrp.php">chgrp</a></li>
<li><a href="http://php.net/manual/en/function.lchown.php">lchown</a></li>
<li><a href="http://php.net/manual/en/function.lchgrp.php">lchgrp</a></li>
<li><a href="http://php.net/manual/en/function.touch.php">touch</a></li>
<li><a href="http://php.net/manual/en/function.lstat.php">lstat</a></li>
<li><a href="http://php.net/manual/en/function.fstat.php">filestat</a></li>
<li><a href="http://php.net/manual/en/function.fileatime.php">fileatime</a></li>
<li><a href="http://php.net/manual/en/function.filectime.php">filectime</a></li>
<li><a href="http://php.net/manual/en/function.filegroup.php">filegroup</a></li>
<li><a href="http://php.net/manual/en/function.fileinode.php">fileinode</a></li>
<li><a href="http://php.net/manual/en/function.filemtime.php">filemtime</a></li>
<li><a href="http://php.net/manual/en/function.fileowner.php">fileowner</a></li>
<li><a href="http://php.net/manual/en/function.filesize.php">filesize</a></li>
<li><a href="http://php.net/manual/en/function.filetype.php">filetype</a></li>
<li><a href="http://php.net/manual/en/function.is-writable.php">is_writable</a></li>
<li><a href="http://php.net/manual/en/function.is-readable.php">is_readable</a></li>
<li><a href="http://php.net/manual/en/function.is-executable.php">is_executable</a></li>
<li><a href="http://php.net/manual/en/function.is-file.php">is_file</a></li>
<li><a href="http://php.net/manual/en/function.is-dir.php">is_dir</a></li>
<li><a href="http://php.net/manual/en/function.is-link.php">is_link</a></li>
<li><a href="http://php.net/manual/en/function.file-exists.php">file_exists</a></li>
<li><a href="http://php.net/manual/en/function.disk-total-space.php">disk_total_space</a></li>
<li><a href="http://php.net/manual/en/function.disk-free-space.php">disk_free_space</a></li>
</ul>


<h3>Special file types</h3>
<ul>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#link-invocation">link invocation</a>:  Make a hard link via the link syscall</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#ln-invocation">ln invocation</a>: Make links between files</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mkdir-invocation">mkdir invocation</a>: Make directories</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mkfifo-invocation">mkfifo invocation</a>: Make FIFOs (named pipes)</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mknod-invocation">mknod invocation</a>: Make block or character special files</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#readlink-invocation">readlink invocation</a>: Print the referent of a symbolic link</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#rmdir-invocation">rmdir invocation</a>: Remove empty directories</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#unlink-invocation">unlink invocation</a>: Remove files via unlink syscall</li>
</ul>


<h3>Changing file attributes</h3>
<ul>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chown-invocation">chown invocation</a>: Change file owner and group</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chgrp-invocation">chgrp invocation</a>: Change group ownership</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chmod-invocation">chmod invocation</a>: Change access permissions</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#touch-invocation">touch invocation</a>: Change file timestamps</li>
</ul><p><a href="http://www.askapache.com/security/chmod-stat.html"></a><a href="http://www.askapache.com/security/chmod-stat.html">Chmod, Umask, Stat, Fileperms, and File Permissions</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/security/chmod-stat.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Htaccess Rewrites for Moving Urls</title>
		<link>http://www.askapache.com/htaccess/htaccess-rewrites.html</link>
		<comments>http://www.askapache.com/htaccess/htaccess-rewrites.html#comments</comments>
		<pubDate>Sat, 29 Oct 2011 14:41:55 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[301 Redirects]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=5231</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/htaccess-rewrites.html"></a><a href="http://www.askapache.com/htaccess/htaccess-rewrites.html"><cite>AskApache.com</cite></a></p><p>This is part 2 of the <a href="http://www.askapache.com/htaccess/htaccess.html" title="Htaccess Tutorial like no other">exhaustive Htaccess Tutorial</a>.  I realized it was so lengthy that search engines and visitors were having real problems with it, so I moved half of it here.  But this gave me the opportunity to add a ton of new stuff that I hadn't been able to add to the main htaccess tutorial.  And now this new part 2 is already twice as big as the original!  To sum up, this is a work in progress.</p>


<h2>Moving Half of Original Tutorial to a new URL - SEO Rewriting</h2>
<p>Well, the original tutorial was at /htaccess/apache-htaccess.html, but it was such a huge article that search engines were dropping it!  So I split it into 3 new urls.</p>
<ol>
<li>/htaccess/htaccess.html - 1</li>
<li>/htaccess/htaccess-rewrites.html - Rewrites</li>
<li>/htaccess/apache-htaccess-2.html - Part 2</li>
</ol>

<p>The /htaccess/apache-htaccess-2.html is a lot of unfinished new stuff, and the /htaccess/htaccess-rewrites.html (this very page) still needs to be split several times to get the filesize down.</p>

<h3>301 Link Juice</h3>
<p>The /apache-htaccess.html url has been around since 2006, and it was full of original ideas and examples for using htaccess.  Almost every htaccess guide or tutorial published since then has many of the examples and ideas from that tutorial, (I encourage people to modify and republish everything on this site according to copyright).  I know it, the authors sometimes know it, but the main point is Google for sure knows it.  That's the beauty of creating unique content, Google sees that.  So that /apache-htaccess.html link has extreme link juice, from all the sites, books, papers, and presentations that have linked to it since 2006.</p>

<h4>Filesize Is important</h4>
<p>I like to use my blog as a way to keep notes about my research organized, and I am extremely good at doing research, unfortunately, that means I have a huge article.  The filesize for the html alone is larger than all the other resources like javascript and images, combined.</p>
<ul>
<li>So that means it is very difficult to view on a mobile device, or a slow connection.</li>
<li>For google-bot and other search engine crawlers and robots, this is a huge problem (I made a big mistake letting it get that size).</li>
<li>The robot has to parse an enormous single html file, containing hundreds/thousands of external and internal links, and its such an issue they can decide to just skip indexing that url until the filesize is manageable.</li>
<li>Once again, it's all about the human experience, a huge single file is not good for anyone who isn't printing it out to read offline.</li>
</ul>

<h4>Starting Fresh without losing juice</h4>
<p>So since the page wasn't being indexed much since it was so huge, I decided to split up the content into new separate urls and utilize a 301 Redirect to transfer all the link juice from /apache-htaccess.html to /htaccess.html.</p>


<h2>301 Redirect Timeline</h2>
<ol>
<li>Now, the idea is to take the first pages from the original multi-page guide, do a little improvement on that content, and save it to the new url /htaccess.html.</li>
<li>Then just continue taking the next page from the remaining original guide and creating new pages using the original links structure.  /apache-htaccess-2.html, /apache-htaccess-3.html, etc.. This is a secondary backup to the new /htaccess.html url, which will receive the 301 link juice from the old url, but these secondary pages will help keep the links on external sites good.</li>
<li>Then, I setup a 301 Redirect in my .htaccess file to redirect the old url to the new /htaccess.html url.</li>
<li>Finally, I delete the old url and it is replaced forever by a 301 Redirect pointing to my new location, filesize problems eliminated.</li>
</ol>

<h3>301 Redirect Code Used</h3>
<p>This is so easy to do with RedirectMatch, way faster and easier than using mod_rewrite to handle this, and much less overhead.  Note that this is a general command that I will leave up for a few weeks and slowly tighten it up by looking at my Google Analytics and Apache Logs.  For instance, this first redirectmatch rule is an older RedirectMatch I still have active to redirect all the old links pointing at /2006/htaccess/apache-htaccess.html to /htaccess/apache-htaccess.html from when I ditched the date-based permalinks back in 2007, and you can see it is a little tighter than the 2nd one which also redirects requests for apache-htaccess.html/feed/ or trackback or whatever.</p>
<pre>RedirectMatch 301 ^/2006/.*apache-htaccess.html$ http://www.askapache.com/htaccess/apache-htaccess.html
RedirectMatch 301 ^/.*apache-htaccess.html(.*)$ http://www.askapache.com/htaccess/htaccess.html$1</pre>



<h2>Advanced 301 Redirects for SEO</h2>
<p>I wrote a couple of articles that go into detail about maximizing the SEO with linking and redirects, it remains one of my most helpful articles to anyone trying to rank higher the right way, the Google way.. <a href="http://www.askapache.com/seo/seo-advanced-pagerank-indexing.html">SEO Secrets of AskApache Part 2</a></p><p><a href="http://www.askapache.com/htaccess/htaccess-rewrites.html"></a><a href="http://www.askapache.com/htaccess/htaccess-rewrites.html">Htaccess Rewrites for Moving Urls</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/htaccess-rewrites.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>3 Ways to Serve PDF Files using Htaccess Cookies, Headers, Rewrites</title>
		<link>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html</link>
		<comments>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html#comments</comments>
		<pubDate>Sun, 21 Aug 2011 03:07:53 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=2328</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"><img height="60" width="45" src='http://uploads.askapache.com/2007/11/60x45_acrobat_trefoil.gif' alt='Adobe PDF' /></a>FYI, using the <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">Mod_Rewrite Variables Cheatsheet</a> makes this example, and all advanced .htaccess code easier to understand.  This demo lets you set a cookie with 1 of 3 values, then you just request the pdf file with a normal link click and get 1 of 3 different responses. This is accomplished with a nice bit of <a href="http://www.askapache.com/htaccess/htaccess.html">.htaccess</a> code.<br class="C" /></p>
<div class="cnote">
<p><strong>Set PDF Viewing Mode</strong> - <kbd id="pdfr">Make a selection, then click the view pdf button.</kbd></p>
<p><span id="pdfi" class="FL btnn">Inline</span> <span id="pdfa" class="FL btnn">Download</span> <span id="pdfs" class="FL btnn">Save As</span> <a class="FL btnn" style="margin-left:10px; border-top:1px solid #96F8AF; background:-moz-linear-gradient(center top , #3E9D43, #6ED766) repeat scroll 0 0 transparent;margin-left:20px;" rel="nofollow" href="http://www.askapache.com/storage/pdf/AskApache-Test.pdf">View PDF using selected mode &#187;</a><br class="C" /></p>
</div>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"></a><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" id="id10" href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"></a>FYI, using the <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">Mod_Rewrite Variables Cheatsheet</a> makes this example, and all advanced .htaccess code easier to understand.  This demo lets you set a cookie with 1 of 3 values, then you just request the pdf file with a normal link click and get 1 of 3 different responses. This is accomplished with a nice bit of <a href="http://www.askapache.com/htaccess/htaccess.html">.htaccess</a> code.<br /><br />As I explain the htaccess code that achieves this, keep in mind this is merely one simple application for this code.  It's much more advanced than your basic htaccess trick, notice how this htaccess acts like a php script, very unusual..  I really wanted to share this trick after I created it for one of my clients because this is the tip of the iceberg.  Another use would be to display an alternate style sheet depending on a users theme preference.  The coolest thing is that it uses multiple advanced .htaccess ideas.  This code uses mod_headers to set the Content-Disposition header for forcing a download and uses mod_rewrite to: Send different Content-Type headers, Check the value of a cookie, Set environment variables for use later by mod_headers header directive<br class="C" /></p>

<div class="cnote">
<p><strong>Set PDF Viewing Mode</strong> - <kbd id="pdfr">Make a selection, then click the view pdf button.</kbd></p>
<p><span id="pdfi" class="FL btnn">Inline</span> <span id="pdfa" class="FL btnn">Download</span> <span id="pdfs" class="FL btnn">Save As</span> <a class="FL btnn" style="margin-left:10px; border-top:1px solid #96F8AF; background:-moz-linear-gradient(center top , #3E9D43, #6ED766) repeat scroll 0 0 transparent;margin-left:20px;" rel="nofollow" href="http://www.askapache.com/storage/pdf/AskApache-Test.pdf">View PDF using selected mode &raquo;</a><br class="C" /></p>
</div>


<h2>What's Going On</h2>
<p>There are 3 different ways for a server to send a pdf file in response to a request for one.  This causes 3 different ways to open/view the pdf file in the clients browser.</p>
<ol>
<li>The browser display's a <strong>"Save File As"</strong> dialog, allowing you to save the file or open.</li>
<li>The browser opens the pdf file <strong>"Inline"</strong>, opening the pdf file in the browser like a web page.</li>
<li>The browser "<strong>Downloads</strong>" the pdf file automatically as an "<strong>Attachment</strong>" and then causes an external pdf reader program like adobe reader to open the file.</li>
</ol>
<p>Some people prefer to have the option of saving the file to view later, some prefer opening it with an external program, and some just like the pdf file to load right in the browser...  The point is that by using .htaccess, we can let them choose any of the 3 methods and save their preference for all further pdf files requested from our site by that user.</p>





<h2>How It Works</h2>
<p>When you click on one of the 3 demo buttons above, "Inline", "Save As", or "Download", a cookie named <code>askapache_pdf</code> is saved in your browser using the javascript below, with the value being set to which button you clicked.  Then when you request the pdf file the .htaccess code below uses mod_rewrite to read the value of the askapache_pdf cookie, and depending on which was your preference it will send alternate HTTP Headers that control how your browser handles the file.</p>


<h3>Unique HTTP Headers Returned</h3>
<p>When it comes down to it, the following information is the 3 modes.  Notice each one is different, because these headers are the only thing controlling how your browser handles the file.</p>
<h4>Save As Mode (askapache_pdf=s)</h4>
<pre>Content-Disposition: attachment
Content-Type: application/pdf</pre>
<h4>Inline Mode (askapache_pdf=i)</h4>
<pre>Content-Type: application/pdf</pre>
<h4>Download Mode (askapache_pdf=a)</h4>
<pre>Content-Type: application/octet-stream</pre>


<h3>Htaccess Demo File</h3>
<p>For the demo I created the folder /storage/pdf/ and this is the .htaccess file at /storage/pdf/.htaccess</p>
<p>The default Content-Type for .pdf files.  This will make .pdf files default Content-Type header have  the value 'application/pdf' - but the default can be overridden by using RewriteRule with the <code>[T=&#039;different/type&#039;]</code></p>
<pre>AddType application/pdf .pdf</pre>

<p>Turn on the rewrite engine if its already on you dont need this </p>
<pre>RewriteEngine On</pre>

<p>Skip RewriteRules if not .pdf request, like autoindexing. The next [2] RewriteRule directives are specific for .pdf files so if the filename requested does not end in .pdf then the <code>[S=2]</code> instructs the next 2 RewriteRule  directives to be completely skipped.</p>
<pre>RewriteRule !.*\.pdf$ - [S=2]</pre>


<p>The first RewriteCond checks to see if the askapache_pdf cookie is NOT set.  The second RewriteCond checks to see if the askapche_pdf cookie has the value of s, which is the value corresponding to someone clicking the "Save As" button.</p>
<p>The <code>[NC,OR]</code> flag means that if the cookie askapache_pdf does not exist, OR (next cond) if the askapache_pdf cookie does exist and is set to 's' then process the RewriteRule.  If neither cond is true the rewriterule is skipped.</p>
<p>If one of the RewriteCond is true, then the RewriteRule is processed.   The RewriteRule applies to any/all requests (.*) but doesn't rewrite anything (-) This RewriteRule sets an Apache environment variable ASKAPACHE_PDFS to have the value of 1 if either rewritecond is true.  The variable can be checked by any directives following the rewriterule in the whole htaccess file.  The ASKAPACHE_PDFS ends in S because if this variable exists then it means the users preference is 'Save As'</p>
<p>Notice that if the user requested the pdf file without selecting a preference i.e. no cookie exists, then the ASKAPACHE_PDFS variable is still set. This just lets us pick the default preference for them, in this example the default is 'Save As'</p>
<pre>RewriteCond %{HTTP_COOKIE} !^.*askapache_pdf.*$ [NC,OR]
RewriteCond %{HTTP_COOKIE} ^.*askapache_pdf=s.*$ [NC]
RewriteRule .* - [E=ASKAPACHE_PDFS:1]</pre>

<p>The RewriteCond checks the askapache_pdf cookie for the value 'a' which 'a' represents 'Download'</p>
<p>If the cookies value is 'a' then the RewriteRule overrides the default Content-Type from 'application/pdf' set with AddType earlier, to 'application/octet-stream', which is a special content-type that tells the browser that the file cannot be loaded by the browser 'Inline', but must be saved which will be opened by an external viewer depending on browser configuration and plugins.</p>
<pre>RewriteCond %{HTTP_COOKIE} ^.*askapache_pdf=a.*$
RewriteRule .* - [T=application/octet-stream]</pre>

<p>This is superfly.  If the cookie/users-preference was 'Save As' (s) then the RewriteRule above the last one set the environment variable ASKAPACHE_PDFS to have the value 1.  The Header directive here is ONLY processed in that variable ASKAPACHE_PDFS exists.  That is what the end 'env=ASKAPACHE_PDFS' does, it is the condition that must be met or the Header directive is skipped.  If the ASKAPACHE_PDFS environment variable set by RewriteRule does exist then the header directive adds the header '<code>Content-Disposition: attachment</code>' to  the normal Response Headers.  The 'Content-Disposition: attachment' header instructs your browser to present you with the 'Save As' dialog box allowing you to choose whether you want to save or open.</p>
<pre>Header set Content-Disposition "attachment" env=ASKAPACHE_PDFS</pre>






<h2>Javascript used by Demo</h2>
<p>The best place for javascript is quirksmode, here is a definitive article on setting, reading, parsing, etc.. <a title="I am a javascript cookie monster" href="http://www.quirksmode.org/js/cookies.html">COOKIES</a>.</p>
<p>Note, I now prefer using jQuery over my AAJS javascript library.  Also, the whole using cookies aspect is just to highlight some advanced htaccess, you can accomplish this much easier without javascript or cookies.</p>
<pre>if(!gi(&#039;pdfr&#039;))return;
var pdfr=gi(&#039;pdfr&#039;);
var cval=getCookie(&#039;askapache_pdf&#039;);
&nbsp;
if(cval==&#039;i&#039;){pdfr.innerHTML=&#039;Currently set to "Inline".&#039;;}
else if(cval==&#039;a&#039;){pdfr.innerHTML=&#039;Currently set to "Download" mode.&#039;;}
else if(cval==&#039;s&#039;){pdfr.innerHTML=&#039;Currently set to "Save As" mode.&#039;;}
&nbsp;
addMyEvent(gi(&#039;pdfi&#039;),"mousedown",function(){
  setCookie("askapache_pdf", "i", "", "/", "www.askapache.com"); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to "Inline".&#039;; return false; });
addMyEvent(gi(&#039;pdfa&#039;),"mousedown",function(){
  setCookie("askapache_pdf", "a", "", "/", "www.askapache.com"); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to "Download".&#039;; return false; });
addMyEvent(gi(&#039;pdfs&#039;),"mousedown",function(){
  setCookie("askapache_pdf", "s", "", "/", "www.askapache.com"); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to "Save As".&#039;; return false; });</pre>

<h2>Alternative Method - No Cookies + PHP</h2>
<p>This is what I came up with first for my client, and then while programming the php I noticed.. Hey!  I think I can do the same thing using .htaccess, which would save me on cpu/memory/potential security/etc.. but this works great too.  Though you will need to hack the code to get it working probably..</p>
<p>Note that the .htaccess rewrite code I used here used FILENAME-i.pdf or FILENAME-s.pdf to pass the preference to the pdf-dl.php script, it also worked for FILENAME.pdf?i=i</p>

<h3>pdf-dl.php</h3>
<pre>&lt;?php
if (
  !isset($_GET[&#039;file&#039;])
  || ($f=$_GET[&#039;file&#039;])===false
  || ($fp=@fopen($f,"rb"))===false
  || ($fi=pathinfo($f))===false
  || ($fi[&#039;fsize&#039;]=filesize($f))===false
  || strtolower($fi["extension"])!=&#039;pdf&#039;
) die(&#039;Failed&#039;);
&nbsp;
ob_start();
header(&#039;Accept-Ranges: bytes&#039;);
header("Content-Length: {$fi[&#039;fsize&#039;]}");
header(&#039;Content-Type: application/pdf&#039;);
if(!isset($_GET[&#039;i&#039;])) header("Content-Disposition: attachment; filename=\"{$fi[&#039;basename&#039;]}\"");
&nbsp;
$sent = 0;
while ( !feof($fp) &amp;&amp; $sent &lt; $fi[&#039;fsize&#039;] &amp;&amp; ($buf = fread($fp, 8192)) != &#039;&#039; ){
  echo $buf;
  $sent += strlen($buf);
  flush();  ob_flush();
}
fclose($fp);
exit;
?&gt;</pre>


<h3>Alternate Method .htaccess</h3>
<p>Deny direct request to pdf-dl.php file</p>
<pre>RewriteCond %{THE_REQUEST} ^.*pdf-dl\.php.*$ [NC]
RewriteRule .* - [F]</pre>
<p>Handle PDF files named anything-i.pdf as inline</p>
<pre>RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*)-i\.pdf$  /cgi-bin/pdf-dl.php?i=i&amp;file=%{DOCUMENT_ROOT}/storage/pdf/$1.pdf [L,NC,QSA,S=1]</pre>
<p>Handle PDF files without -i.pdf as attachments</p>
<pre>RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*)\.pdf$  /cgi-bin/pdf-dl.php?file=%{DOCUMENT_ROOT}/storage/pdf/$1.pdf [L,NC,QSA]</pre>




<h2>More Info</h2>
<p>The following is more information about the Content-Dispositon header and related subjects for fast readers.</p>

<h3>Interesting Reading</h3>
<p>Here is the thread of the original draft proposal for the Content-Disposition header.</p>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03620.html">Content-Disposition Header</a>, <em>Rens Troost - 22 Jun 1993</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03629.html">Re: Content-Disposition Header</a>, <em>Nathaniel Borenstein</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03630.html">Re: Content-Disposition Header</a>, <em>Gabe Beged-Dov</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03631.html">Re: Content-Disposition Header</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03635.html">Re: Content-Disposition Header</a>, <em>Gabe Beged-Dov</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03641.html">Content-Disposition Header and multipart/alternative</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03645.html">Re: Content-Disposition Header and multipart/alternative</a>, <em>Nathaniel Borenstein</em></li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03632.html">Re: Content-Disposition Header</a>, <em>Keith Moore</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03633.html">Re: Content-Disposition Header</a>, <em>Nathaniel Borenstein</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03634.html">Re: Content-Disposition Header</a>, <em>Ed Levinson (Contractor)</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03636.html">Re: Content-Disposition Header</a>, <em>Keith Moore</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03640.html">Re: Content-Disposition Header</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03650.html">Re: Content-Disposition Header</a>, <em>Harald Tveit Alvestrand</em></li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03621.html">Re: Content-Disposition Header</a>, <em>Steve Dorner</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03622.html">Re: Content-Disposition Header</a>, <em>Rens Troost</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03624.html">Re: Content-Disposition Header</a>, <em>Keith Moore</em></li>
</ul>
</li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03652.html">Re: Content-Disposition Header</a>, <em>Carlyn M. Lowery</em></li>
</ul>
</li>
</ul>
</li>
</ul>



<h3>Intense Reading</h3>
<ul>
<li><a href="http://www2.roguewave.com/support/docs/leif/sourcepro/html/protocolsug/10-1.html">Using the MIME Headers Effectively</a></li>
<li><a href="http://www.iana.org/assignments/mail-cont-disp">Mail Content Disposition Values and Parameters</a></li>
<li><cite><a href="http://rfc.askapache.com/rfc1766/rfc1766.txt">Tags for the Identification of Languages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1436/rfc1436.txt">The Internet Gopher Protocol (a distributed document search and retrieval protocol)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1630/rfc1630.txt">Universal Resource Identifiers in WWW</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1738/rfc1738.txt">Uniform Resource Locators (URL)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1866/rfc1866.txt">Hypertext Markup Language - 2.0</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1945/rfc1945.txt">Hypertext Transfer Protocol -- HTTP/1.0</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2045/rfc2045.txt">Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1123/rfc1123.txt">Requirements for Internet Hosts -- Communication Layers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc822/rfc822.txt">Standard for The Format of ARPA Internet Text Messages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1808/rfc1808.txt">Relative Uniform Resource Locators</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1036/rfc1036.txt">Standard for Interchange of USENET Messages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc977/rfc977.txt">Network News Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2047/rfc2047.txt">MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1867/rfc1867.txt">Form-based File Upload in HTML</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc821/rfc821.txt">Simple Mail Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1590/rfc1590.txt">Media Type Registration Procedure</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc959/rfc959.txt">File Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1700/rfc1700.txt">Assigned Numbers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1737/rfc1737.txt">Functional Requirements for Uniform Resource Names</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1864/rfc1864.txt">The Content-MD5 Header Field</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1900/rfc1900.txt">Renumbering Needs Work</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1952/rfc1952.txt">GZIP file format specification version 4.3</a></cite></li>
<li><cite>Improving HTTP Latency</cite></li>
<li><cite><a href="http://www.isi.edu/touch/pubs/http-perf96/">Analysis of HTTP Performance</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1305/rfc1305.txt">Network Time Protocol (Version 3) Specification, Implementation and Analysis</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1951/rfc1951.txt">DEFLATE Compressed Data Format Specification version 1.3</a></cite></li>
<li><cite><a href="http://sunsite.unc.edu/mdma-release/http-prob.html">Analysis of HTTP Performance Problems,</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1950/rfc1950.txt">ZLIB Compressed Data Format Specification version 3.3</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2069/rfc2069.txt">An Extension to HTTP: Digest Access Authentication</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2068/rfc2068.txt">Hypertext Transfer Protocol -- HTTP/1.1</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2119/rfc2119.txt">Key words for use in RFCs to Indicate Requirement Levels</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1806/rfc1806.txt">Communicating Presentation Information in Internet Messages: The Content-Disposition Header</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2145/rfc2145.txt">Use and Interpretation of HTTP Version Numbers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2076/rfc2076.txt">Common Internet Message Headers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2279/rfc2279.txt">UTF-8, a transformation format of Unicode and ISO-10646</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2046/rfc2046.txt">Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2277/rfc2277.txt">IETF Policy on Character Sets and Languages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2396/rfc2396.txt">Uniform Resource Identifiers (URI): Generic Syntax and Semantics</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2617/rfc2617.txt">HTTP Authentication: Basic and Digest Access Authentication</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2110/rfc2110.txt">MIME E-mail Encapsulation of Aggregate Documents, such as HTML (MHTML)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2026/rfc2026.txt">The Internet Standards Process -- Revision 3</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2324/rfc2324.txt">Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2049/rfc2049.txt">Multipurpose Internet Mail Extensions (MIME) Part Five: Conformance Criteria and Examples</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2183/rfc2183.txt">Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field</a></cite></li>
</ul><p><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"></a><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html">3 Ways to Serve PDF Files using Htaccess Cookies, Headers, Rewrites</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>HOWTO: Uninstall CPANEL over SSH</title>
		<link>http://www.askapache.com/hacking/uninstall-cpanel.html</link>
		<comments>http://www.askapache.com/hacking/uninstall-cpanel.html#comments</comments>
		<pubDate>Mon, 04 Jul 2011 18:55:40 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4404</guid>
		<description><![CDATA[<p>The following is just a quick reference of some of the commands I used to successfully uninstall cpanel.  This is for advanced users of the shell.  If you aren't that advanced and you run a single one of these commands without fully understanding it, you will probably kill your server, probably lose everything on it permanently, probably not have a website or email for weeks..  So backup all your data FIRST.  Also, if you aren't 100% sure you won't run into problems, you should contact your hosts technical support - but be prepared for some MAJOR negativity..  cpanel makes things very easy for hosts, you are just a drop in their bucket.</p>

<blockquote cite="http://www.askapache.com/server-administration/uninstall-cpanel.html#comment-168222">
<p><strong>Wow!</strong></p>
<p>You sure gotta bigger set that *I* do. . . . - for real! I've been known to do some abysmally stupid things in my day - and actually had them work the way I wanted them to! - but this takes the <strong>titanium, gadolinium, rhodium alloy cake</strong>!</p>
<p>Me, I'd try something like that and find out later that the fire-trucks showed up right after I hit the "Enter" key. It's a REALLY interesting post, and a real eye-opener - especially for someone who is relatively new to the whole web-hosting-service paradigm.  I know, no guts, no glory - but THIS is WAY over the top!  I'm reading this and thinking <em>"Why not just put a couple of sticks of dynamite under the thing?"</em></p>
<p>Seriously now, this was an excellent read - and for someone who is just now looking into the whole web-hosting paradigm, it's a real eye-opener.  Though I think I'll just tiptoe past this <strong>REAL QUIETLY</strong> for now. . . .  (laughing!)</p>
<p><a href="http://www.qatechtips.com/">Jim</a></p>
</blockquote>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"></a><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"><cite>AskApache.com</cite></a></p><p><strong>WARNING!</strong> This is for advanced users of the shell, this is NOT a howto or tutorial.  The thing is, I googled <strong>how to uninstall cpanel</strong> and for once in my life I came up empty.. And certainly the cpanel official sites themselves don't provide any instructions other than to say "Dont uninstall it, reinstall your entire operating system without it."..   they sure don't seem confident that they know exactly what their code is doing.  Cpanel is great for most people, perfect for many situations, so don't get me wrong.. this is just for fun.</p>

<h2>Why Uninstall?</h2>
<p>Why?  Because I have always built my servers, php installations, perl installs, ruby, iptables, everything from source.  I read the INSTALL/README docs, I read the man pages, and I read the info pages as well.  I google for configuration advice, I google for tips, and I don't need a web-based perl script messing my stuff up!</p>
<p>The main problems I had with cpanel, which really is a great bit of software for millions of website developers, is that it was incredibly sneaky!  I used it for about 6 months and spent that entire time trying to figure out what the heck it was doing.  A couple issues that I really disliked, it takes over your bind install, it takes over your apache install, it takes over your php install.  And although it does let you configure some things (very few) for custom configurations and the like, I just don't need any of that.  By removing the darn thing I am saving GIGS of space on my server, tons of bandwidth, and most importantly to me I am saving CPU and processing time along with RAM and IO speed.</p>
<h3>Anything Else</h3>
<p>Please.. I could go on for DAYS!  Another reason I have wanted to be rid of cpanel is that I like my servers to be as lean and mean as possible.  This means I like as few files and processes as possible.  There are many benefits to this, like it's much easier for my integrity checking software and rootkit/antivirus software to run and drastically reduces the false positives.  And there is that glaring security issue of constantly having cpanel run it's own software to create the WHM/Cpanel web interface, which is accessible online.  I haven't researched cpanel security at all, it's possible that it never has security problems that are published, but for me, why take the chance?</p>


<h2>Warning - Caution!</h2>
<p>The following is just a quick reference of some of the commands I used to uninstall cpanel.  This is for advanced users of the shell.  If you aren't that advanced and you run a single one of these commands without fully understanding it, you will probably kill your server, probably lose everything on it permanently, probably not have a website or email for weeks..  So backup all your data FIRST.  Also, if you aren't 100% sure you won't run into problems, you should contact your hosts technical support - but be prepared for some MAJOR negativity..  cpanel makes things very easy for hosts, and the last thing tech support wants is to fix a server broken by someone who doesn't know what they are doing.</p>

<h2>Last Warning!</h2>
<p>Unless you understand what theses commands do and the purpose they serve, do not try any of this.  These are not the exact commands I used verbatim, they are also not in order.  I only put them up here because I was so amazed that google didn't have any uninstall cpanel intructions.  Hopefully it's not a conspiracy that will get my site taken down.. ;)</p>
<p>That said and out of the way, it really only took me about 10 minutes to uninstall cpanel completely.  But keep in mind I have been closely monitoring and debugging cpanel for 6 months, so I knew what I was doing.  And finally, I do apologize for not having better instructions.. but hey, if you don't get this then you have no business trying to figure out how to uninstall cpanel!  It's great software and shouldn't be removed unless you are fully capable of managing email/dns/www/ftp and any/all other servers and services on your machine by hand.</p>

<h2>Do This First</h2>
<p>I have a few drafts I'm working on at the moment with specifics, but for now you will have to figure it out with google.  Basically you want to make sure you don't totally knock your machine offline without being able to reconnect.  What I do is compile a static version of openssh and a few other security-type shell tools, and configure this binary sshd to run by using inittab, which is the file run by init (pid 1) and makes sure if it dies it is restarted.  Here is my /etc/inittab to run the static sshd binary:</p>
<pre>hh:12345:respawn:/failover/os/sbin/aassh -D -q -u0 -f /failover/os/etc/aassh</pre>

<p>Another trick is to keep a detached screen logged in to root.  That way if you mess up your sudoers or securetty or pam or whatever, you can just reattach and fix it.</p>
<p>Finally, you may want to setup your syslog to start earlier than usual, and set up more than normal verbosity.  ( I take it to the max ).  Then you should setup a 2nd server or machine somewhere to act as a syslog server.  Lastly, configure your web server syslog to copy all messages to the remote syslog you set up.  I use a reverse ssh tunnel to encrypt the syslog packets, but when I do something serious like reboot after uninstalling cpanel, I prepare for it by adding additional networking routes on my machine to make sure I will get some logs even if sshd cant start or even if my network addresses aren't brought up correctly.</p>
<p>If that sounds easy to you, please continue.   If you are saying: Wha??? Continue in read-only mode.</p>

<p class="cnote">Also, you can't just uninstall cpanel, I have replaced a lot of cpanel already, like building my own bind, apache, php, syslog and making sure they work and aren't being tampered with by cpanel.  Basically cpanel runs everything on your server in most cases, so you should prepare by creating your own static software to replace cpanel, and make sure it works.</p>


<h2>Find files Accessing /var/cpanel</h2>
<p>More than likely these will need to be killed.</p>
<pre>lsof +w -Rg -nP +c15 -x f +D /var/cpanel
lsof +w -Rg -nP +c15 -x f +D /usr/local/cpanel</pre>

<h2>Killing cpanel</h2>
<p>Just an example, your machine may have a lot more than these, I have been slowly taking control of my machine back from cpanel for 6 months, so it was easier for me.</p>
<pre>for P in tailwatchd queueprocd cpanellogd exim; do pkill -9 $P; done</pre>

<h2>Commands and Shortcuts</h2>
<pre>alias NF=&#039;nice find $PWD -mount -depth ! -type d&#039;
alias NFF=&#039;nice find $PWD -mount -depth ! -type d | xargs -IF87 file F87&#039;
alias NA=&#039;nice find $PWD -mount -depth&#039;
alias NAF=&#039;nice find $PWD -mount -depth | xargs -IF87 file F87&#039;</pre>


<h2>Watch out for crontab</h2>
<p>An example of the sneakiness (from my POV, from most it's called builtin robustness) that cpanel does is automagically adding crontab entries that make it behave similarly to a self-propagating virus.  If you don't disable the cronjobs and kill the right processes within a short period of time, be prepared for a magic resurrection.</p>

<p>Here's my awesome crontab information function, you will need to check every file, it lists the default crons on my box, and every users crontab, but it can't account for other cron software like at and other crons.</p>
<pre>function askapache_crontab()
{
  local GG i;
  for i in `getent passwd|cut -d ":" -f1`;
  do
    GG=$(sudo crontab -u $i -l 2&gt;$N6 | tr -s &#039;\n\000&#039; | sed &#039;/^#/d&#039;);
    [[ ${#GG} -gt 3 ]] &amp;&amp; sleep 1 &amp;&amp; echo -e "$i \n\n${GG}"
  done;
   sleep 4;
   ls -aLls1ch --color=always /etc/cron.{hourly,daily,weekly,monthly,d} | sed &#039;/^total/d; /\ drwxr-xr-x/d&#039;;
}</pre>



<pre>grep -ir /var/spool cpan</pre>
<pre>#6 3 * * * /scripts/upcp
#0 1 * * * /scripts/cpbackup
#0 2 * * * /scripts/mailman_chown_archives
#35 * * * * /usr/bin/test -x /usr/local/cpanel/bin/tail-check &amp;&amp; /usr/local/cpanel/bin/tail-check
#11,26,41,56 * * * * /usr/local/cpanel/whostmgr/bin/dnsqueue &gt; /dev/null 2&gt;&amp;1
#30 */4 * * * /usr/bin/test -x /scripts/update_db_cache &amp;&amp; /scripts/update_db_cache
#45 */8 * * * /usr/bin/test -x /usr/local/cpanel/bin/optimizefs &amp;&amp; /usr/local/cpanel/bin/optimizefs
#*/5 * * * * /usr/local/cpanel/bin/dcpumon &gt;/dev/null 2&gt;&amp;1
#25 1 * * * /usr/local/cpanel/whostmgr/docroot/cgi/cpaddons_report.pl --notify</pre>



<h2>Delete Crontabs</h2>
<pre>sudo crontab -u mailman -r</pre>


<h2>Find INIT scripts with cpanel</h2>
<p>This is the main startup script: <code>/usr/local/cpanel/etc/init/startup</code></p>
<p>I had no idea ruby-on-rails was being controlled by cpanel.. sneaky bugger.  You can tell by all of these advanced unix commands just how difficult it would be to uninstall cpanel, its totally like the Alien!</p>
<pre>(1:3744)# find . ! -type d -print0|xargs -0 -I&#039;F87&#039; grep -Hi "cpan\|tailwat\|chkser" F87
./fastmail:# Author:       cPanel, Inc. &lt;nick@cpanel.net&gt;
./httpd:        HTTPD=/usr/local/cpanel/bin/chroothttpd
./cpanel:# cpanel8       Start Cpanel Services
./cpanel:# Author:       cPanel, Inc. &lt;nick@cpanel.net&gt;
./cpanel:# description: This is the cpanel webserver and chat.
./cpanel:# processname: cpaneld
./cpanel:# pidfile: /var/run/cpanel.pid
./cpanel:[ -f /usr/local/cpanel/etc/init/startup ] || exit 0
./cpanel:       if [ -f "/var/cpanel/smtpgidonlytweak" ]; then
./cpanel:       echo -n "Starting cPanel services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcpsrvd
./cpanel:       echo -n "Starting cPanel brute force detector services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcphulkd
./cpanel:    echo -n "Starting cPanel dav services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcpdavd
./cpanel:               daemon /usr/local/cpanel/etc/init/startcppop
./cpanel:       echo -n "Starting cPanel Chat services: "
./cpanel:               daemon /usr/local/cpanel/entropychat/entropychat
./cpanel:               daemon /usr/local/cpanel/bin/startmelange
./cpanel:                       /usr/local/cpanel/bin/startinterchange
./cpanel:       echo -n "Starting cPanel ssl services: "
./cpanel:       daemon /usr/local/cpanel/startstunnel
./cpanel:    echo -n "Starting cPanel Queue services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startqueueprocd
./cpanel:    echo -n "Starting tailwatchd: "
./cpanel:    daemon /usr/local/cpanel/libexec/tailwatchd --start
./cpanel:       echo -n "Starting cPanel Log services: "
./cpanel:       daemon /usr/local/cpanel/cpanellogd
./cpanel:    action "Starting mailman services: " /usr/local/cpanel/etc/init/startmailman
./cpanel:    action "Stopping tailwatchd: " /usr/local/cpanel/libexec/tailwatchd --stop
./cpanel:    action "Stopping cPanel services: " /usr/local/cpanel/etc/init/stopcpsrvd
./cpanel:       action "Stopping cPanel dav services: " /usr/local/cpanel/etc/init/stopcpdavd
./cpanel:       action "Stopping cPanel queue services: " /usr/local/cpanel/etc/init/stopqueueprocd
./cpanel:       action "Stopping cPanel brute force detector services: " /usr/local/cpanel/etc/init/stopcphulkd
./cpanel:               action "Stopping pop3 services: " /usr/local/cpanel/etc/init/stopcppop
./cpanel:       echo -n "Stopping cPanel log services: "
./cpanel:       killproc cpanellogd
./cpanel:       echo -n "Stopping cPanel Chat services: "
./cpanel:       action "Stopping cPanel ssl services: " /usr/local/cpanel/etc/init/stopstunnel
./cpanel:       action "Stopping mailman services: " /usr/local/cpanel/etc/init/stopmailman
./cpanel:       if [ -e "/usr/local/cpanel/3rdparty/mailman/bin/mailmanctl" ]; then
./exim:if [ -e "/etc/chkserv.d" ]; then
./exim:        for file in `ls /etc/chkserv.d`
./exim:            if [ ! -e "/usr/local/cpanel/libexec/tailwatchd" ]; then
./exim:    if [ -x "/usr/local/cpanel/etc/init/startspamd" ]; then
./exim:        /usr/local/cpanel/etc/init/startspamd
./exim:        if [ ! -e "/usr/local/cpanel/libexec/tailwatchd" ]; then
./ror:  /usr/local/cpanel/bin/rormgr --startboot
./ror:  /usr/local/cpanel/bin/rormgr --stopall
./ror:  /usr/local/cpanel/bin/rormgr --stopall
./ror:  /usr/local/cpanel/bin/rormgr --startboot
./ror:  /usr/local/cpanel/bin/rormgr --statusall
./securetmp:# Author:       cPanel, Inc. &lt;copyright@cpanel.net&gt;</pre>

<h3>Turn off cpanel services</h3>
<p>You should remove the below delete command and start by just disabling the inits by turning them off.  Then reboot. Then delete.  If your machine won't reboot, I told you so, Cpanel told you so, and likely your host told you so.</p>
<pre>for S in cpanel ror securetmp fastmail exim; do R=$(command chkconfig --level 123456 $S off ||echo); R=$(command chkconfig --del $S ||echo); done</pre>


<h4>HTTPD</h4>
<p>If you are running chrooted httpd then you'll need to make sure you don't delete your entire webserver on accident.  Here's a relevant part from the /etc/init.d/httpd script.</p>
<pre># the path to your httpd binary, including options if necessary
if [ -e "/etc/chroothttpd" ]; then
        HTTPD=/usr/local/cpanel/bin/chroothttpd
else
        HTTPD=/usr/local/apache/bin/httpd
fi</pre>




<h2>Finding files owned by cpanel</h2>
<p>Some super cool bash commands in this post.. let's start with one to find all the files and folders on your machine owned by cpanel.  Check your /etc/passwd file for your machines specific usernames and groups.  This command saves all the filenames to ~/cpanel-files-backup.txt, which is used by tar next to create a backup of all of them.</p>
<pre>{ find / -mount -depth -maxdepth 150 \( -group cpanel -o   -group cpanel-phpmyadmin -o -group cpanel-phppgadmin   -o -group cpanelphpmyadmin   -o -group cpanelphppgadmin   -o -group cpanelhorde   -o -group cpanelroundcube \) -print; find / -mount -depth -maxdepth 150 \( -user cpanel -o   -user cpanel-phpmyadmin -o -user cpanel-phppgadmin   -o -user cpanelphpmyadmin   -o -user cpanelphppgadmin   -o -user cpanelhorde   -o -user cpanelroundcube \) -print; } &gt; ~/cpanel-files-backup.txt</pre>

<p>Here's another way to search directories.</p>
<pre> grep --color=always -Hir cpanel /var</pre>

<h2>Create the Backup</h2>
<p>Note that you must have the latest version of tar for this exact command, also you should backup /var/cpanel and /usr/local/cpanel and /etc and heck the whole machine why dontcha!</p>
<pre>tar -T ~/cpanel-files-backup.txt -cvz --checkpoint=1000 --checkpoint-action="ttyout=\rHit %s checkpoint #%u" -f /cpanel-files-backup.tgz --totals</pre>


<h2>Remove Files</h2>
<p>Once you do this your upstream without a paddle, you better make sure you know what you're doing with this.  This removes all those files.</p>
<pre>cat ~/cpanel-files-backup.txt | xargs -I&#039;F87&#039; rm -vfr F87</pre>

<p>Additionally you will want to remove /usr/local/cpanel and /var/cpanel - What I always do when running as root is alias my rm command to instead simply move the files to a .trash folder.  That way if something goes bork you have a better chance at fixing it.</p>


<h2>Find Group-Owned Files</h2>
<pre>find / -mount -depth -maxdepth 150 \
\(  -group cpanel -o \
  -group cpanel-phpmyadmin \
  -o -group cpanel-phppgadmin \
  -o -group cpanelphpmyadmin \
  -o -group cpanelphppgadmin \
  -o -group mailman \
  -o -group cpanelhorde \
  -o -group cpanelroundcube \
\) -fprintf /root/cpanel-group-files.log &#039;%#8k %#5m %11M %#10u:%-10g %-5U:%-5G %p %f %Y %F\n&#039;</pre>

<h2>Find User-Owned Files</h2>
<pre>find / -mount -depth -maxdepth 150 \(
  -user cpanel \
  -o -user cpanel-phpmyadmin \
  -o -user cpanel-phppgadmin \
  -o -user cpanelphpmyadmin \
  -o -user cpanelphppgadmin \
  -o -user mailman \
  -o -user cpanelhorde \
  -o -user cpanelroundcube
\) -fprintf /root/cpanel-users-files.log &#039;%#8k %#5m %11M %#10u:%-10g %-5U:%-5G %p %f %Y %F\n&#039;</pre>



<pre>       4  0755  drwxr-xr-x     cpanel:cpanel     32002:32004 /var/cpanel/userhomes/cpanel cpanel d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/tmp tmp d reiserfs
       4  0644  -rw-r--r-- cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches caches d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel .cpanel d reiserfs
       4  0750  drwxr-x--- cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/mail mail d reiserfs
       4  0711  drwx--x--x cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin cpanel-phpmyadmin d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/sessions sessions d reiserfs
       4  0644  -rw-r--r-- cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches caches d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel .cpanel d reiserfs
       4  0750  drwxr-x--- cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/mail mail d reiserfs
       4  0711  drwx--x--x cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin cpanelphppgadmin d reiserfs
       4  0750  drwxr-x--- cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube/mail mail d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube/sessions sessions d reiserfs
       4  0711  drwx--x--x cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube cpanelroundcube d reiserfs
       4  0644  -rw-r--r--     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches caches d reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel .cpanel d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/roundcube/tmp tmp d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/roundcube/log log d reiserfs</pre>


<h3>Find Permissions</h3>
<pre>cat ~/cpanel-group-files.log ~/cpanel-users-files.log |tr -s &#039;\000 \t&#039;|cut -d&#039; &#039; -f3|sort -u</pre>






<h3>Find files tailwatchd</h3>
<pre>(1:3732)# $NICE find ${1:-`pwd`} -mount -name &#039;*tailwatch*&#039;
/usr/local/cpanel/libexec/tailwatchd
/usr/local/cpanel/libexec/tailwatch
/usr/local/cpanel/libexec/tailwatch/tailwatchd
/usr/local/cpanel/etc/init/scripts/freebsd/tailwatchd.sh
/usr/local/cpanel/etc/init/scripts/trustix/tailwatchd
/usr/local/cpanel/etc/init/scripts/centos/tailwatchd
/usr/local/cpanel/etc/init/scripts/suse/tailwatchd
/usr/local/cpanel/etc/init/scripts/caos/tailwatchd
/usr/local/cpanel/etc/init/scripts/whitebox/tailwatchd
/usr/local/cpanel/etc/init/scripts/mandrake/tailwatchd
/usr/local/cpanel/etc/init/scripts/debian/tailwatchd
/usr/local/cpanel/etc/init/scripts/redhat/tailwatchd
/usr/local/cpanel/etc/init/scripts/fedora/tailwatchd
/usr/local/cpanel/etc/init/stoptailwatchd
/usr/local/cpanel/etc/init/starttailwatchd
/usr/local/cpanel/bin/tailwatchd
/usr/local/cpanel/logs/tailwatchd_log
/var/log/cpanel/tailwatchd_log
/var/cpanel/log_rotation/cp_tailwatchd_log.cpanellogd
/var/cpanel/tailwatch.positions
/var/run/tailwatchd.pid
/etc/chkserv.d/tailwatchd
/scripts/restartsrv_tailwatchd</pre>


<h2>Delete cpanel Users/Groups</h2>
<pre>for U in cpanel-phpmyadmin cpanel-phppgadmin cpanelphpmyadmin cpanelphppgadmin cpanelhorde cpanelroundcube machbuild; do userdel -fr $U; groupdel $U; done</pre>

<h2>Check for broken symlinks</h2>
<pre>find / -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039;</pre>
<p>Especially check /etc</p>
<pre>$ find /etc -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039;
/etc/ftpd-rsa.pem                   broken symbolic link to `/var/cpanel/ssl/ftp/ftpd-rsa.pem&#039;
/etc/rc.d/rc1.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc1.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc1.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc3.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc3.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc3.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc6.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc6.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc6.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc5.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc5.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc5.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc2.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc2.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc2.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc4.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc4.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc4.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc0.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc0.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc0.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/authlib/authProg               broken symbolic link to `/usr/local/cpanel/bin/courier-auth&#039;</pre>

<p>And delete if you are sure</p>
<pre>find /etc -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039; |cut -d&#039; &#039; -f1|xargs -I&#039;F87&#039; rm -rvf &#039;F87&#039;</pre>


<h2>Reinstall CSF</h2>
<p>The only thing I actually used that came with cpanel is the CSF/LFD Firewall package, which is a fantastic piece of software.  I had to reinstall this, and to get it working without cpanel add the following line to the csf.conf</p>
<pre>GENERIC = "1"</pre>

<h2>Thats It</h2>
<p>Now once you've cleaned up everything, you should try everything conceivable to get an error before rebooting.  Like you should start and stop every service in /etc/init.d/, you should use telinit to check various runlevels (which keeps your sshd connection still live).  Go all out, should take at least a full hour.</p>
<p>Another thing I like to do is rebuild alot of my source-built software again in case anything got messed up.  I upgrade perl from cpanels 5.8.8 to 5.10, which is pretty thorough, and you know, reinstall anything else I think I might need.  One of the benefits of compiling your own software is all I have to do is cd to the source directory and type <code>make -B &amp;&amp; ( { make test || make check || make checks || make tests; } || echo  ) &amp;&amp; sudo make install</code> and that's it.  The tests/checks are optional of course.</p>


<p>If anyone actually ever reads this and does it, please share your advice here.. everybody knows we need it!  Good Luck</p><p><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"></a><a href="http://www.askapache.com/hacking/uninstall-cpanel.html">HOWTO: Uninstall CPANEL over SSH</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/hacking/uninstall-cpanel.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Enhanced printenv Script for Server Debugging</title>
		<link>http://www.askapache.com/hosting/enhanced-printenv.html</link>
		<comments>http://www.askapache.com/hosting/enhanced-printenv.html#comments</comments>
		<pubDate>Thu, 14 Apr 2011 19:05:17 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Hosting]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4920</guid>
		<description><![CDATA[<p>A souped-up version of the Apache printenv script for hard-core server environment debuggery.</p>
<pre>#!/bin/sh
echo -e "Content-type: text/plain\n\n"
...
  __T "CURRENT PROCESS CMDLINE"
  {
   for p in `echo /proc/[0-9]*/cmdline`;
   do
    pid=${p:6:$((${#p}-13))}
    [[ $pid == $PPID &#124;&#124; $pid == $$ ]] &#38;amp;&#38;amp; continue;
    __M "[ /proc/$pid ]";
    sed &#039;s/\x00/ /g;G&#039; $p 2&#62;/dev/null
   done
  }
 fi</pre>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/hosting/enhanced-printenv.html"></a><a href="http://www.askapache.com/hosting/enhanced-printenv.html"><cite>AskApache.com</cite></a></p><p>Every Apache server comes pre-shipped with an old cgi script named <tt>printenv</tt>.  It's useful and used for printing out the environment variables from your servers point of view.  Basically you save this file where you can then call it from your browser, like <code>site.com/printenv.cgi</code> -- then it will be executing as the user running the web server, <tt>nobody</tt>, <tt>apache</tt>, etc..   So this tells you all sorts of interesting things about your server, especially if you want/need to know about the users, groups, and file permissions.</p>

<h2>Enabling CGI</h2>
<p>You need to do 1 of 2 things to use this:</p>
<ol><li>Make it executable and in your server directory</li>
<li>Use a trick to cause your server to execute it regardless</li></ol>

<h2>Htaccess CGI</h2>
<p>If you have htaccess then you most likely can get this to work by giving it an execute bit with chmod or from your ftp client, and then use htaccess like this:</p>
<pre>Options +ExecCGI Indexes +FollowSymLinks
AddHandler cgi-script .cgi .pl .sh
&nbsp;
Order Deny,Allow
Deny from All
Allow from 127.0.0.1 ADDYOURIPHERE env=REDIRECT_STATUS
Satisfy All</pre>
<p>Search around on this site for php.cgi tricks if you can't seem to get it.  Basically you can try stuff like making it an errordocument, using other directives like forcetype, AddType, and even try stuff like mod_security's upload binary setting.</p>

<p class="cnote">You do not want anyone other than you ever looking at the output of this.  It's so full of details about your machine that it would be a huge security problem.</p>

<h2>The AskApache Printenv</h2>
<pre>#!/bin/sh
echo -e "Content-type: text/plain\n\n"
&nbsp;
# FUNCTIONS
################################################################################################################
function __A ()
{ local __a __i __z;for __a;do __z=\${!${__a}*};for __i in `eval echo "${__z}"`;do echo -e "$__i: ${!__i}";done;done; }
&nbsp;
function __S ()
{ local L IFS=&#039;;&#039;;while read -r L;do builtin printf "${#L}@%s\n" "$L";done|sort -n|sed -u &#039;s/^[^@]*//&#039;; }
&nbsp;
function __P ()
{ local l=`builtin printf %${2:-$__WIDTH}s` &amp;&amp; echo -e "${l// /${1:-=}}"; }
&nbsp;
function __T ()
{ echo -e "\n\n+`__P -`+\n| $*\n+`__P &#039;=&#039;`+"; }
&nbsp;
function __M ()
{ echo -e " &gt;&gt;&gt; $M" $*; }
&nbsp;
function __H ()
{ command builtin type $1 &amp;&gt;/dev/null &amp;&amp; local a="yes" || return 1; }
&nbsp;
function LE ()
{
 [[ ! -r /proc/${1:-$$}/limits ]] &amp;&amp; return;
 sed -e &#039;1z;s/ *$//;:a;$!N;s/\nM.. [a-z]* [a-z]* [a-z]* \{1,\}\([^ ]*\) *\([^ ]*\) *[a-z]* */\1:\2 /;ta;s/u\w\+d/u/g;s/ *$//;s/ / | /g;s/\([^:]\+\):\1/\1:=/g&#039; /proc/${1:-$$}/limits;
}
function LH ()
{
 [[ ! -r /proc/${1:-$$}/limits ]] &amp;&amp; return;
 sed -e &#039;1z;s/ *$//;:a;$!N;s/\nM.. \([a-z]\+ [a-z]* [a-z]*\) \{1,\}\([^ ]*\) *\([^ ]*\) *\([a-z]*\) */:\1/;ta;s/ *:/:/g;s/size/sz/g;s/file/f/g;s/ p\w\+y/ pri/g;s/memory/mem/g;s/p\w\+s/procs/g;s/^://;s/:/ | /g&#039; /proc/${1:-$$}/limits
}
&nbsp;
# CUSTOM SETTINGS
################################################################################################################
__WIDTH=170
LC_COLLATE=C LC_CTYPE=C LC_ALL=C
&nbsp;
# RUNTIME SETUP
#################################################################################################################
shopt -s dotglob nocaseglob extglob
&nbsp;
# -C If set, disallow existing regular files to be overwritte
# -f Disable file name generation (globbing
# -e Exit immediately if a command exits with a non-zero status
# -B enable brace expansion
# +H disable History
set -C +f +H -B
&nbsp;
# make sure we dont create any files
umask 0177
&nbsp;
# redirect everything to output (no logs or stderr is used)
exec 2&gt;/dev/null
&nbsp;
# MAIN EXECUTION
#################################################################################################################
{
 __T "EXPANDING PATH"
 {
  __M "ORIG PATH:$PATH"
  PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/libexec:/usr/local/apache/bin
  for t in ${PATH//:/ };
  do
   [[ -d "$t" ]] &amp;&amp; sed -n -e "/:${t//\//\\/}:/Q1" &lt;&lt;&lt; ":${p:=}:" &amp;&amp; p=$p:$t || continue;
  done
  PATH=${p/:/}:.
  __M "NEW PATH:$PATH"
 }
&nbsp;
 __T "USER INFO"
 {
  __M "UMASK: `(umask 2&gt;/dev/null)` ( `(umask -S 2&gt;/dev/null)` )"
  __H uname &amp;&amp; __M "UNAME: `eval echo $(uname -a 2&gt;/dev/null)`"
  __H whoami &amp;&amp; __M "WHOAMI: `(whoami 2&gt;/dev/null)`"
  __H id &amp;&amp; __M "ID: `(id 2&gt;/dev/null)`"
  __H logname &amp;&amp; __M "LOGNAME: `(logname 2&gt;/dev/null)`"
  __H groups &amp;&amp; __M "GROUPS: `(groups 2&gt;/dev/null)`"
  echo -e "\n\n"
 }
&nbsp;
 if __H who;
 then
  __T "LOGGED ON USERS"
  {
   (who -a 2&gt;/dev/null)
  }
 fi;
&nbsp;
 if [[ -r /etc/passwd ]];
 then
  __T "/etc/passwd"
  {
   (cat /etc/passwd)
  }
 fi;
&nbsp;
 if __H ulimit;
 then
  __T "USER LIMITS"
  {
   ulimit -a
  }
 fi
&nbsp;
 if [[ -d /dev ]] &amp;&amp; __H ls;
 then
  __T "/dev Directory"
  {
   ( ls -vlaph /dev 2&gt;/dev/null )
  }
 fi;
&nbsp;
 if [[ -d /proc ]];
 then
  __T "CURRENT PROCESS LIMITS"
  {
   for p in `echo /proc/[0-9]*/limits`
   do
    pid=${p:6:$((${#p}-13))}
    [[ $pid == $PPID || $pid == $$ ]] &amp;&amp; continue;
    echo -e "\n/proc/$pid:"
    sed &#039;1s/\x00/ /g;n;s/\x00/\n/g;/.\{2,\}/!d&#039; /proc/$pid/cmdline $p 2&gt;/dev/null
   done
  }
&nbsp;
  __T "CURRENT PROCESS CMDLINE"
  {
   for p in `echo /proc/[0-9]*/cmdline`;
   do
    pid=${p:6:$((${#p}-13))}
    [[ $pid == $PPID || $pid == $$ ]] &amp;&amp; continue;
    __M "[ /proc/$pid ]";
    sed &#039;s/\x00/ /g;G&#039; $p 2&gt;/dev/null
   done
  }
 fi
&nbsp;
 __T "IP INFORMATION"
 {
  __H ip &amp;&amp; __M "IP:" &amp;&amp; (ip -o -f inet addr 2&gt;/dev/null) | sed &#039;s/^.*inet \([0-9.]*\).*$/\1/g&#039;;
  __H nmap &amp;&amp; __M "NMAP:" &amp;&amp; (nmap --iflist 2&gt;/dev/null) | sed 1,4d | sed -n &#039;/ethernet/s/^.*) \([0-9.]*\).*$/\1/gp&#039;;
  __H ifconfig &amp;&amp; __M "IFCONFIG:" &amp;&amp; (ifconfig -a 2&gt;/dev/null) | sed -n &#039;/inet a/s/^.*addr:\([0-9.]*\).*$/\1/gp&#039;;
  [[ -f "$HOME/.cpanel/datastore/_sbin_ifconfig_-a" ]] &amp;&amp; __M "CPANEL CACHE:" &amp;&amp; sed -e &#039;/inet/!d; s/.*addr:\([0-9\.]*\).*/\1/g&#039; "$HOME/.cpanel/datastore/_sbin_ifconfig_-a" | sort -u
 }
&nbsp;
 __T "ROUTE / INTERFACE INFO"
 {
  __H route &amp;&amp; __M "ROUTE" &amp;&amp; (route -nv 2&gt;/dev/null)
  __H ip &amp;&amp; ( ip rule &amp;&amp; ip route &amp;&amp; ip address ) 2&gt;/dev/null
  __H ifconfig &amp;&amp; (ifconfig -a 2&gt;/dev/null)
 }
&nbsp;
 __T "CGI/1.0 test script report:"
 {
  __A SERVER REQUEST GET SERVER PATH REMOTE AUTH CONTENT HTTP TZ GATEWAY QUERY MO
  echo -e "\n\n"
 }
&nbsp;
 __T "HIDDEN VARIABLES"
 {
  __A {a..z} {A..Z} _{0..9} _{A..Z} _{a..z} | cat -Tsv 2&gt;/dev/null
  echo -e "\n\n"
 }
&nbsp;
 __T "DECLARE INFO"
 {
  for i in "r" "i" "a" "x" "t" "-";
  do
   builtin eval declare -$i &amp;&amp; echo;
  done | sed &#039;s/^declare //&#039; | cat -Tsv 2&gt;/dev/null
  echo -e "\n\n"
 }
&nbsp;
 __T "SHELL OPTIONS"
 {
  __A SHELLOPTS BASHOPTS
  echo -e "\$-: $-"
  __P &#039;-&#039; &amp;&amp; builtin shopt -s -p
  __P &#039;-&#039; &amp;&amp; builtin shopt -u -p
  echo -e "\n\n"
 }
&nbsp;
 __T "ENV AND EXPORT"
 {
  __H env &amp;&amp; command env | cat -Tsv 2&gt;/dev/null &amp;&amp; __P &#039;-&#039;
  builtin export | cat -Tsv 2&gt;/dev/null
  echo -e "\n\n"
 }
&nbsp;
 if __H perl;
 then
  __T "PERL VARIABLES"
  {
   perl -e&#039;foreach $v (sort(keys(%ENV))) {$vv = $ENV{$v};$vv =~ s|\n|\\n|g;$vv =~ s|"|\\"|g;print "${v}=\"${vv}\"\n"}&#039; | cat -Tsv 2&gt;/dev/null
   echo -e "\n\n"
  }
 fi
&nbsp;
} | fold - -w$(($__WIDTH+3))
exit $?</pre><p><a href="http://www.askapache.com/hosting/enhanced-printenv.html"></a><a href="http://www.askapache.com/hosting/enhanced-printenv.html">Enhanced printenv Script for Server Debugging</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/hosting/enhanced-printenv.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

