Apache HTTPD Virtual Host,what is %1+ in a document root? - apache

So I have a Virtual Host set up and I snagged this as my Document Root
VirtualDocumentRoot "/sites/%1+/www"
Everything works great but this one thing has been killing me. Does anyone have any idea what %1+ means? Could someone breakdown exactly what it is and how it works. I understand it is pointing the server to where to look but what is %1+ doing?

Read the documentation: http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
All the directives in this module interpolate a string into a
pathname. The interpolated string [...] may be either the server name
[...] or the IP address of the virtual host on the server in
dotted-quad format. The interpolation is controlled by specifiers
inspired by printf which have a number of formats:
[...]
%N.M insert (part of) the name
N and M are used to specify substrings of the name. N selects from the
dot-separated components of the name, and M selects characters within
whatever N has selected. M is optional and defaults to zero if it
isn't present; the dot must be present if and only if M is present.
The interpretation is as follows:
0 the whole name
1 the first part
[...]
2+ the second and all subsequent parts
[...]
For a very large number of virtual hosts it is a good idea to arrange
the files to reduce the size of the vhosts directory. To do this you
might use the following in your configuration file:
UseCanonicalName Off
VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2
A request for http://www.domain.example.com/directory/file.html will
be satisfied by the file
/usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html.
So, in
VirtualDocumentRoot "/sites/%1+/www"
the request
www.example.com
would resolve to
/sites/www.example.com/www

Related

create ACL in exim deny senders but exclude localdomains

reading material on the internet, I found a way to block extensions (TLD) or e-mail accounts, it's an excellent option since I make the mail never get the antispam, so I save resources.
discard senders = /opt/exim/deny_senders
message = your are blacklisted
Into the file deny_senders contain this:
*.ru
*.online
*.bid
In to the file /opt/exim/localdomains are the local domains of the server.
One of the local domains ends with the extension "bla.online" is it possible to create a rule to exclude the local?
You need to ensure that you have the line in your exim's config like that:
acl_smtp_rcpt = acl_rcpt
That directive declare that you want to filter out the messages on the RCPT stage. Then you have to find the exact part of config defined the ACL for RCPT and add this two rules:
acl_rcpt:
. . . . .
accept condition = ${lookup{\$sender_address}nwildlsearch{/path/to/white.list}{yes}}
reject condition = ${lookup{\$sender_address}nwildlsearch{/path/to/black.list}{yes}}
message = Go mail yourself you unsolicited sender!
. . . . .
Those two conditions checks the sender address in the files containing regular expressions one per line like that:
## WHITE.LIST
^.*\.bla\.online
and
## BLACK.LIST
^.*\.ru
^.*\.online
^.*\.bid
Regular expressions should conform the PCRE syntax:
^ mean the beginning of line
.* mean any sequence of any symbols
\. mean the dot itself
You have to place the whitelist above the blacklist because the ACL terminates on the first match. So more specific white regexps should be tested first. Also this two rules should be placed before any other rules that can accept messages for delivery.

What is the difference between ${var} and %{VAR} in apache?

From the doc, the %{VAR} is in expression, ${VAR} is in the configuration.
But what is the difference between them actually, I saw some configuration file use %{VAR} in configuration too.
It depends of the context:
In regular configuration, ${VAR} can be an environment variable inherited by Apache process or, since Apache 2.4, defined by a Define directive.
But, in values of Rewrite* directives:
${MapName:LookupKey} (note the : to distinguish a variable to a RewriteMap): is intended to dynacially map a value to an other via RewriteMap (like lower case a substring)
%{VAR} designates a predefined variable (see the list under RewriteCond's documentation) used for and only by mod_rewrite.
EDIT : I should search first in Apache's documentation:
The values of variables defined with the Define of [new from 2.4] or shell environment variables can be used in configuration file lines using the syntax ${VAR}. If "VAR" is the name of a valid variable, the value of that variable is substituted into that spot in the configuration file line, and processing continues as if that text were found directly in the configuration file. Variables defined with Define take precedence over shell environment variables. If the "VAR" variable is not found, the characters ${VAR} are left unchanged, and a warning is logged. Variable names may not contain colon ":" characters, to avoid clashes with RewriteMap's syntax.
Only shell environment variables defined before the server is started can be used in expansions.
(source)

How to implement a sub-request in .htaccess?

In Apache I am trying to emulate the RewriteLog behaviour with a sub-request pointing to a simple cgi script
According to Apache 2.2 documentation:
%{LA-U:variable} can be used for look-aheads which perform an internal
(URL-based) sub-request to determine the final value of variable. This
can be used to access variable for rewriting which is not available at
the current stage, but will be set in a later phase.
%{LA-F:variable} can be used to perform an internal (filename-based)
sub-request, to determine the final value of variable. Most of the
time, this is the same as LA-U above.
According to a mail archive conversation in the case of using %{LA-F:variable} the request is passed directly to the next processing stage:
usr/local/webserver/doc_root/some/dir/som_file
cat /dev/world | perl -e "while (<>) {(/(^.*? \?) 42 \!/) && (print $1)}"
errors->(c)
but how to implement %{LA-U:variable} or %{LA-F:variable} in .htaccess?

Mod-Rewrite to variable ending file

I'm trying to get apache to serve any request for /uploaded/2 with the first file that starts with 2 in a certain directory (say /foo/bar/).
Basically, If I have directory /foo/bar with contents:
1-filenameclutter.wav
2-clutterinthefilename.mp3
3-someweirdtext.jpg
And a web browser makes a request for /uploaded/1, apache would return 1-filenameclutter.wav; a request for /uploaded/2 would return 2-clutterinthefilename.mp3; etc. (all files with the right mime-type).
As far as I can see, ModRewrite can only go from a source with extraneous data to a simplified file on the file system, not the other way around.
Do you guys know any way to do this, with ModRewrite or using apache in another way (no PHP)?
EDIT:
Two things to point out, 1) I'm not concerned with duplicate files starting with the same id. These files correspond to an object in a database, which has a primarykey, id. 2) The reason I'm doing this is because I won't know exactly what the extension of the file is, but I do know the id, so when I form these I just prepend the orignal filename to the end of {{id}}- (Don't worry, I replace all ".."'s with "~").
Mod-rewrite has the ability to check if a single specific file exists, but you can't search a directory for a file pattern. Note that what you are suggesting would have horrible scaling attributes because the system would have to search all the files to find the file you are looking for. Since you already have the file in the database, why don't you just name the file with the id and keep the real filename in the database? In that case, /uploaded/2 would return the file at that location. You don't even need mod_rewrite.

What does f+++++++++ mean in rsync logs?

I'm using rsync to make a backup of my server files, and I have two questions:
In the middle of the process I need to stop and start rsync again.
Will rsync start from the point where it stopped or it will restart from the beginning?
In the log files I see "f+++++++++". What does it mean?
e.g.:
2010/12/21 08:28:37 [4537] >f.st...... iddd/logs/website-production-access_log
2010/12/21 08:29:11 [4537] >f.st...... iddd/web/website/production/shared/log/production.log
2010/12/21 08:29:14 [4537] .d..t...... iddd/web/website/production/shared/sessions/
2010/12/21 08:29:14 [4537] >f+++++++++ iddd/web/website/production/shared/sessions/ruby_sess.017a771cc19b18cd
2010/12/21 08:29:14 [4537] >f+++++++++ iddd/web/website/production/shared/sessions/ruby_sess.01eade9d317ca79a
Let's take a look at how rsync works and better understand the cryptic result lines:
1 - A huge advantage of rsync is that after an interruption the next time it continues smoothly.
The next rsync invocation will not transfer the files again, that it had already transferred, if they were not changed in the meantime. But it will start checking all the files again from the beginning to find out, as it is not aware that it had been interrupted.
2 - Each character is a code that can be translated if you read the section for -i, --itemize-changes in man rsync
Decoding your example log file from the question:
>f.st......
> - the item is received
f - it is a regular file
s - the file size is different
t - the time stamp is different
.d..t......
. - the item is not being updated (though it might have attributes
that are being modified)
d - it is a directory
t - the time stamp is different
>f+++++++++
> - the item is received
f - a regular file
+++++++++ - this is a newly created item
The relevant part of the rsync man page:
-i, --itemize-changes
Requests a simple itemized list of the changes that are being made to
each file, including attribute changes. This is exactly the same as
specifying --out-format='%i %n%L'. If you repeat the option, unchanged
files will also be output, but only if the receiving rsync is at least
version 2.6.7 (you can use -vv with older versions of rsync, but that
also turns on the output of other verbose messages).
The "%i" escape has a cryptic output that is 11 letters long. The
general format is like the string YXcstpoguax, where Y is replaced by
the type of update being done, X is replaced by the file-type, and the
other letters represent attributes that may be output if they are
being modified.
The update types that replace the Y are as follows:
A < means that a file is being transferred to the remote host (sent).
A > means that a file is being transferred to the local host (received).
A c means that a local change/creation is occurring for the item (such as the creation of a directory or the changing of a symlink,
etc.).
A h means that the item is a hard link to another item (requires --hard-links).
A . means that the item is not being updated (though it might have attributes that are being modified).
A * means that the rest of the itemized-output area contains a message (e.g. "deleting").
The file-types that replace the X are: f for a file, a d for a
directory, an L for a symlink, a D for a device, and a S for a
special file (e.g. named sockets and fifos).
The other letters in the string above are the actual letters that will
be output if the associated attribute for the item is being updated or
a "." for no change. Three exceptions to this are: (1) a newly created
item replaces each letter with a "+", (2) an identical item replaces
the dots with spaces, and (3) an unknown attribute replaces each
letter with a "?" (this can happen when talking to an older rsync).
The attribute that is associated with each letter is as follows:
A c means either that a regular file has a different checksum (requires --checksum) or that a symlink, device, or special file has a
changed value. Note that if you are sending files to an rsync prior to
3.0.1, this change flag will be present only for checksum-differing regular files.
A s means the size of a regular file is different and will be updated by the file transfer.
A t means the modification time is different and is being updated to the sender’s value (requires --times). An alternate value of T
means that the modification time will be set to the transfer time,
which happens when a file/symlink/device is updated without --times
and when a symlink is changed and the receiver can’t set its time.
(Note: when using an rsync 3.0.0 client, you might see the s flag
combined with t instead of the proper T flag for this time-setting
failure.)
A p means the permissions are different and are being updated to the sender’s value (requires --perms).
An o means the owner is different and is being updated to the sender’s value (requires --owner and super-user privileges).
A g means the group is different and is being updated to the sender’s value (requires --group and the authority to set the group).
The u slot is reserved for future use.
The a means that the ACL information changed.
The x means that the extended attribute information changed.
One other output is possible: when deleting files, the "%i" will
output the string "*deleting" for each item that is being removed
(assuming that you are talking to a recent enough rsync that it logs
deletions instead of outputting them as a verbose message).
Some time back, I needed to understand the rsync output for a script that I was writing. During the process of writing that script I googled around and came to what #mit had written above. I used that information, as well as documentation from other sources, to create my own primer on the bit flags and how to get rsync to output bit flags for all actions (it does not do this by default).
I am posting that information here in hopes that it helps others who (like me) stumble up on this page via search and need a better explanation of rsync.
With the combination of the --itemize-changes flag and the -vvv flag, rsync gives us detailed output of all file system changes that were identified in the source directory when compared to the target directory. The bit flags produced by rsync can then be decoded to determine what changed. To decode each bit's meaning, use the following table.
Explanation of each bit position and value in rsync's output:
YXcstpoguax path/to/file
|||||||||||
||||||||||╰- x: The extended attribute information changed
|||||||||╰-- a: The ACL information changed
||||||||╰--- u: The u slot is reserved for future use
|||||||╰---- g: Group is different
||||||╰----- o: Owner is different
|||||╰------ p: Permission are different
||||╰------- t: Modification time is different
|||╰-------- s: Size is different
||╰--------- c: Different checksum (for regular files), or
|| changed value (for symlinks, devices, and special files)
|╰---------- the file type:
| f: for a file,
| d: for a directory,
| L: for a symlink,
| D: for a device,
| S: for a special file (e.g. named sockets and fifos)
╰----------- the type of update being done::
<: file is being transferred to the remote host (sent)
>: file is being transferred to the local host (received)
c: local change/creation for the item, such as:
- the creation of a directory
- the changing of a symlink,
- etc.
h: the item is a hard link to another item (requires
--hard-links).
.: the item is not being updated (though it might have
attributes that are being modified)
*: means that the rest of the itemized-output area contains
a message (e.g. "deleting")
Some example output from rsync for various scenarios:
>f+++++++++ some/dir/new-file.txt
.f....og..x some/dir/existing-file-with-changed-owner-and-group.txt
.f........x some/dir/existing-file-with-changed-unnamed-attribute.txt
>f...p....x some/dir/existing-file-with-changed-permissions.txt
>f..t..g..x some/dir/existing-file-with-changed-time-and-group.txt
>f.s......x some/dir/existing-file-with-changed-size.txt
>f.st.....x some/dir/existing-file-with-changed-size-and-time-stamp.txt
cd+++++++++ some/dir/new-directory/
.d....og... some/dir/existing-directory-with-changed-owner-and-group/
.d..t...... some/dir/existing-directory-with-different-time-stamp/
Capturing rsync's output (focused on the bit flags):
In my experimentation, both the --itemize-changes flag and the -vvv flag are needed to get rsync to output an entry for all file system changes. Without the triple verbose (-vvv) flag, I was not seeing directory, link and device changes listed. It is worth experimenting with your version of rsync to make sure that it is observing and noting all that you expected.
One handy use of this technique is to add the --dry-run flag to the command and collect the change list, as determined by rsync, into a variable (without making any changes) so you can do some processing on the list yourself. Something like the following would capture the output in a variable:
file_system_changes=$(rsync --archive --acls --xattrs \
--checksum --dry-run \
--itemize-changes -vvv \
"/some/source-path/" \
"/some/destination-path/" \
| grep -E '^(\.|>|<|c|h|\*).......... .')
In the example above, the (stdout) output from rsync is redirected to grep (via stdin) so we can isolate only the lines that contain bit flags.
Processing the captured output:
The contents of the variable can then be logged for later use or immediately iterated over for items of interest. I use this exact tactic in the script I wrote during researching more about rsync. You can look at the script (https://github.com/jmmitchell/movestough) for examples of post-processing the captured output to isolate new files, duplicate files (same name, same contents), file collisions (same name, different contents), as well as the changes in subdirectory structures.
1.) It will "restart the sync", but it will not transfer files that are the same size and timestamp etc. It first builds up a list of files to transfer and during this stage it will see that it has already transferred some files and will skip them. You should tell rsync to preserve the timestamps etc. (e.g. using rsync -a ...)
While rsync is transferring a file, it will call it something like .filename.XYZABC instead of filename. Then when it has finished transferring that file it will rename it. So, if you kill rsync while it is transferring a large file, you will have to use the --partial option to continue the transfer instead of starting from scratch.
2.) I don't know what that is. Can you paste some examples?
EDIT: As per http://ubuntuforums.org/showthread.php?t=1342171 those codes are defined in the rsync man page in section for the the -i, --itemize-changes option.
Fixed part if my answer based on Joao's