pax_global_header 0000666 0000000 0000000 00000000064 12205242615 0014511 g ustar 00root root 0000000 0000000 52 comment=e744b1cc4da74b965246e2a1825e40ee1fe3ae80
rdiffweb-v0.6.5/ 0000775 0000000 0000000 00000000000 12205242615 0013477 5 ustar 00root root 0000000 0000000 rdiffweb-v0.6.5/.gitignore 0000664 0000000 0000000 00000000350 12205242615 0015465 0 ustar 00root root 0000000 0000000 *.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
rdiffweb-v0.6.5/.project 0000664 0000000 0000000 00000000552 12205242615 0015150 0 ustar 00root root 0000000 0000000
rdiffweb
org.python.pydev.PyDevBuilder
org.python.pydev.pythonNature
rdiffweb-v0.6.5/.pydevproject 0000664 0000000 0000000 00000000460 12205242615 0016216 0 ustar 00root root 0000000 0000000
Default
python 2.7
rdiffweb-v0.6.5/LICENSE 0000664 0000000 0000000 00000104512 12205242615 0014507 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
. rdiffweb-v0.6.5/PKG-INFO 0000664 0000000 0000000 00000000373 12205242615 0014577 0 ustar 00root root 0000000 0000000 Metadata-Version: 1.0
Name: rdiffWeb
Version: 0.6.4
Summary: A web interface to rdiff-backup repositories
Home-page: http://www.rdiffweb.org
Author: Josh Nisly
Author-email: rdiffweb@joshnisly.com
License: GPLv3
Description: UNKNOWN
Platform: UNKNOWN
rdiffweb-v0.6.5/README.md 0000664 0000000 0000000 00000001725 12205242615 0014763 0 ustar 00root root 0000000 0000000 rdiffweb
========
Release under GPLv3
Installation
------------
ref.: http://www.rdiffweb.org/wiki/index.php?title=Installation
To install rdifWeb, you need to install the the prerequisites. On Debian distribution you may proceed as follow.
sudo apt-get install python-cherrypy3 python-pysqlite2 libsqlite3-dev
Then you may download a snapshot of the repository and proceed with the installation on your system.
wget --no-check-certificate -O ikus060-rdiffweb.tar.gz https://github.com/ikus060/rdiffweb/archive/v0.6.5.tar.gz
tar zxf ikus060-rdiffweb.tar.gz
cd rdiffweb-*
python setup.py build
sudo python setup.py install
Configure rdiffWeb using the command line tool. Then follow the instruction.
sudo rdiff-web-config
Then stat rdiffWeb server using this command line.
sudo /etc/init.d/rdiff-web start
By default, the web server is listening on port 8080 and is accessible via the following URL.
http://server_name:8080
rdiffweb-v0.6.5/init/ 0000775 0000000 0000000 00000000000 12205242615 0014442 5 ustar 00root root 0000000 0000000 rdiffweb-v0.6.5/init/rdiff-web 0000775 0000000 0000000 00000004611 12205242615 0016237 0 ustar 00root root 0000000 0000000 #!/bin/sh
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# Basic support for the Linux Standard Base Specification 3.1.0
### BEGIN INIT INFO
# Provides: rdiff_web
# Required-Start: $network $local_fs
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop: 0 6
# Description: Manages the rdiffWeb daemon
### END INIT INFO
PIDFILE="/var/run/rdiff-web"
LOGFILE="/var/log/rdiff-web.log"
SUCCESS_MSG="[71G done"
ERROR_MSG="[71Gfailed"
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
# This script won't be able to run without root privileges.
if [ `id -u` -ne 0 ]; then
echo "Error: this script must be run as root."
exit 1
fi
# See how we were called.
case "$1" in
start)
if [ ! -f /etc/rdiffweb/rdw.conf ]; then
echo -n "rdiffWeb is not configured! Please run 'rdiff-web-config'."
echo $ERROR_MSG
exit 1
fi
echo -n "Starting rdiffWeb..."
/usr/bin/rdiff-web --pid-file="$PIDFILE" \
--log-file="$LOGFILE" \
--background > /dev/null 2>&1
echo $SUCCESS_MSG
exit 0
;;
stop)
if [ -e "$PIDFILE" ]; then
echo -n "Stopping rdiffWeb..."
kill `cat "$PIDFILE" 2>/dev/null` > /dev/null 2>&1
rm $PIDFILE > /dev/null 2>&1
echo $SUCCESS_MSG
exit 0
else
echo -n "rdiffWeb is not running"
echo $ERROR_MSG
exit 1
fi
;;
status)
echo -n "rdiffWeb "
if [ -e "$PIDFILE" ]; then
echo "is running."
exit 0
else
echo "is not running."
exit 1
fi
;;
restart)
"$0" stop && "$0" start
;;
*)
echo "Usage: `basename "$0"` {start|stop|status|restart}"
exit 1
esac
exit 0 rdiffweb-v0.6.5/rdiff-web 0000775 0000000 0000000 00000012273 12205242615 0015277 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import cherrypy
import getopt
import os
import sys
import threading
import rdiffWeb.rdw_config
import rdiffWeb.rdw_spider_repos
import rdiffWeb.email_notification
import rdiffWeb.page_error
import rdiffWeb.filter_authentication
import rdiffWeb.filter_setup
import rdiffWeb.page_admin
import rdiffWeb.page_browse
import rdiffWeb.page_history
import rdiffWeb.page_locations
import rdiffWeb.page_restore
import rdiffWeb.page_setup
import rdiffWeb.page_status
import rdiffWeb.page_prefs
if __name__ == "__main__":
# Parse command line options
verbose = True
debug = False
autoReload = False
pidFile = ""
logFile = ""
opts, extraparams = getopt.getopt(sys.argv[1:], 'vdr', ['debug', 'log-file=', 'pid-file=', 'background', 'autoreload'])
for option, value in opts:
if option in ['-d', '--debug']:
debug = True
if option in ['-r', '--autoreload']:
autoReload = True
elif option in ['--log-file']:
logFile = value
elif option in ['--pid-file']:
pidFile = value
elif option in ['--background']:
import rdiffWeb.rdw_helpers
rdiffWeb.rdw_helpers.daemonize()
verbose = False
# Wait to write out to the pidfile until after we've (possibly) been daemonized
if pidFile:
# Write our process id to specified file, so we can be killed later
open(pidFile, 'a').write(str(os.getpid()) + "\n")
serverPort = 8080
if rdiffWeb.rdw_config.getConfigSetting("ServerPort") != "":
serverPort = int(rdiffWeb.rdw_config.getConfigSetting("ServerPort"))
environment = "development"
if not debug:
environment = "production"
global_settings = {
'tools.encode.on': True,
'tools.encode.encoding': 'utf-8',
'tools.gzip.on': True,
'tools.sessions.on' : True,
'tools.authenticate.on' : True,
'autoreload.on' : autoReload,
'server.socket_host' : rdiffWeb.rdw_config.getConfigSetting("ServerHost"),
'server.socket_port' : serverPort,
'server.log_file' : logFile,
'server.ssl_certificate': rdiffWeb.rdw_config.getConfigSetting("SslCertificate"),
'server.ssl_private_key': rdiffWeb.rdw_config.getConfigSetting("SslPrivateKey"),
'log.screen': True,
'server.environment': environment,
}
page_settings = {
'/': {
'tools.authenticate.checkAuth' : rdiffWeb.page_locations.rdiffLocationsPage().checkAuthentication,
'tools.authenticate.on' : True,
'tools.setup.on': True,
},
'/status/feed': {
'tools.authenticate.authMethod' : 'HTTP Header'
},
'/static' : {
'tools.staticdir.on' : True,
'tools.staticdir.root': rdiffWeb.rdw_helpers.getStaticRootPath(),
'tools.staticdir.dir': "static",
'tools.authenticate.on' : False,
'tools.setup.on': False,
},
'/setup': {
'tools.setup.on': False,
'tools.authenticate.on' : False,
'tools.sessions.on' : False,
}
}
if rdiffWeb.rdw_config.getConfigSetting("SessionStorage").lower() == "disk":
sessionDir = rdiffWeb.rdw_config.getConfigSetting("SessionDir")
if os.path.exists(sessionDir) and os.path.isdir(sessionDir) and os.access(sessionDir, os.W_OK):
cherrypy.log("Setting session mode to disk in directory %s" % sessionDir)
global_settings['tools.sessions.on'] = True
global_settings['tools.sessions.storage_type'] = 'file'
global_settings['tools.sessions.storage_path'] = sessionDir
cherrypy.config.update(global_settings)
root = rdiffWeb.page_locations.rdiffLocationsPage()
root.setup = rdiffWeb.page_setup.rdiffSetupPage()
root.browse = rdiffWeb.page_browse.rdiffBrowsePage()
root.restore = rdiffWeb.page_restore.rdiffRestorePage()
root.history = rdiffWeb.page_history.rdiffHistoryPage()
root.status = rdiffWeb.page_status.rdiffStatusPage()
root.admin = rdiffWeb.page_admin.rdiffAdminPage()
root.prefs = rdiffWeb.page_prefs.rdiffPreferencesPage()
# Start repo spider thread
if not debug:
killEvent = threading.Event()
rdiffWeb.rdw_spider_repos.startRepoSpiderThread(killEvent)
rdiffWeb.email_notification.startEmailNotificationThread(killEvent)
if hasattr(cherrypy.engine, 'subscribe'): # CherryPy >= 3.1
cherrypy.engine.subscribe('stop', lambda: killEvent.set())
else:
cherrypy.engine.on_stop_engine_list.append(lambda: killEvent.set())
cherrypy.quickstart(root, config=page_settings)
rdiffweb-v0.6.5/rdiff-web-config 0000775 0000000 0000000 00000013711 12205242615 0016540 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import os
import sys
import stat
import rdiffWeb.rdw_config
import rdiffWeb.db_sqlite
import rdiffWeb.rdw_spider_repos
# legalOptions should be a list of legal values. An empty list means all values are legal
def promptUser(promptText, legalOptions, defaultOption, isNumericOption):
if defaultOption:
promptText = promptText + " [%s]" % str(defaultOption)
response = raw_input(promptText + ": ")
if not response:
return defaultOption
option = None
while True:
try:
if isNumericOption:
option = int(response)
else:
option = response
if legalOptions and not option in legalOptions:
raise ValueError
break
except ValueError:
response = raw_input(""""%s" is not a valid option. Please enter your choice again: """ % response)
return option
def addConfigFileLine(lineText):
configFilePath = "/etc/rdiffweb/rdw.conf"
open(configFilePath, "a").write(lineText + "\n")
os.chmod(configFilePath, stat.S_IRWXU)
def addUser(username, password, userRoot, isAdmin):
userDB = rdiffWeb.db_sqlite.sqliteUserDB(rdiffWeb.rdw_config.getDatabasePath())
userDB.addUser(username)
userDB.setUserPassword(username, password)
userDB.setUserInfo(username, userRoot, isAdmin)
def sqlSetup():
# TODO: load default answers from existing config file, if any
try:
import sqlite3
except ImportError:
from pysqlite2 import dbapi2 as sqlite3
except ImportError:
print "Unable to load the python bindings for sqlite (sometimes packaged as python-sqlite). Please install this module and try again."
sys.exit(2)
userDB = rdiffWeb.db_sqlite.sqliteUserDB(rdiffWeb.rdw_config.getDatabasePath())
print "\nLet's add the first user account. This user will have admin privileges, including the ability to add/delete other users."
username = promptUser("Enter the username", [], "", False)
password = promptUser("Enter the password", [], "", False)
userDB._executeQuery("BEGIN")
userDB.addUser(username)
userDB.setUserPassword(username, password)
print "\nEach user has a user root directory. This root directory acts much as the system root directory. All backup repositories must be within this directory.\nExamples: /var/backup/repos"
userRoot = ""
while True:
userRoot = promptUser("Enter the root directory for '%s'" % username, [], "", False)
if not os.access(userRoot, os.F_OK):
if promptUser("The entered directory does not exist. Do you want to continue?", ["yes", "no"], "no", False) == "yes":
break
break
userDB.setUserInfo(username, userRoot, True)
print "User added successfully."
prompt = "\nDo you want me to automatically search the user's root directory for backup repositories?"
response = promptUser(prompt, ["yes", "no"], "yes", False)
if response == "yes":
try:
repos = rdiffWeb.rdw_spider_repos.findReposForUser(username, userDB)
except OSError, error:
print "Unable to search repository: " + str(error)
else:
print "Repository search complete."
userDB._executeQuery("END")
def doMainSetup():
try:
import cherrypy
except:
print "Unable to load the CherryPy python module. This is most likely because it has not been installed. Please install this module and run the configuration again."
sys.exit(2)
addConfigFileLine("ServerHost=0.0.0.0")
addConfigFileLine("ServerPort=8080")
sqlSetup()
print "Configuration complete!"
def doAddUser():
if len(sys.argv) != 5:
print "Usage: rdiff-web-config adduser "
sys.exit(2)
addUser(sys.argv[2], sys.argv[3], sys.argv[4], False)
def doSpiderRepos():
rdiffWeb.rdw_spider_repos.findReposForAllUsers()
def createNeededFolders():
# We can't just check for root privileges, since cygwin doesn't support the "root" user.
# So we poke around at folders/files, to make sure that we have the required permissions.
# The configuration directory is supposed to be readable only by root.
configDir = "/etc/rdiffweb"
if not os.path.exists(configDir):
os.mkdir("/etc/rdiffweb", stat.S_IRWXU)
os.chmod("/etc/rdiffweb", stat.S_IRWXU)
# If the configuration path exists, make sure that we can look inside
files = os.listdir(configDir)
# See if the config file already exists, and if it does, if we can write to it.
configFile = os.path.join(configDir, "rdw.conf")
open(configFile, "a")
os.chmod(configFile, stat.S_IRWXU)
if __name__ == "__main__":
# Because this script manipulates files in the /etc directory, it must be run with root privileges.
# Validate this before the user has spent a lot of time entering data.
try:
createNeededFolders()
except (IOError, OSError), error:
if error.errno != 13 and error.errno != 1: # Only catch "permission denied" errors
raise
print "Error: this script must be run with root privileges."
sys.exit(2)
if len(sys.argv) > 1:
if sys.argv[1] == "adduser":
doAddUser()
elif sys.argv[1] == "spiderrepos":
doSpiderRepos()
else:
print "Error: unrecognized command."
sys.exit(2)
else:
doMainSetup()
rdiffweb-v0.6.5/rdiffWeb/ 0000775 0000000 0000000 00000000000 12205242615 0015227 5 ustar 00root root 0000000 0000000 rdiffweb-v0.6.5/rdiffWeb/__init__.py 0000664 0000000 0000000 00000000000 12205242615 0017326 0 ustar 00root root 0000000 0000000 rdiffweb-v0.6.5/rdiffWeb/db.py 0000775 0000000 0000000 00000001614 12205242615 0016173 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import rdw_config
class userDB:
def getUserDBModule(self):
import db_sqlite
return db_sqlite.sqliteUserDB(rdw_config.getDatabasePath())
rdiffweb-v0.6.5/rdiffWeb/db_file.py 0000775 0000000 0000000 00000010400 12205242615 0017163 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import rdw_config
import db
class fileUserDB(db.userDB):
def __init__(self, configFilePath=None):
self.configFilePath = configFilePath
def userExists(self, username):
valid_username = rdw_config.getConfigSetting("username", self.configFilePath)
return valid_username == username
def areUserCredentialsValid(self, username, password):
"""The valid users string in the config file is in the form:
username=bill
password=frank """
valid_username = rdw_config.getConfigSetting("username", self.configFilePath)
valid_password = rdw_config.getConfigSetting("password", self.configFilePath)
return valid_username == username and valid_password == password
def getUserRoot(self, username):
if not self.userExists(username): return None
return rdw_config.getConfigSetting("UserRoot", self.configFilePath)
def getUserRepoPaths(self, username):
"""The user home dirs string in the config file is in the form of username:/data/dir|/data/dir2..."""
if not self.userExists(username): return None
return rdw_config.getConfigSetting("UserRepoPaths", self.configFilePath).split("|")
def userIsAdmin(self, username):
return False
##################### Unit Tests #########################
import unittest, os
class fileUserDataTest(unittest.TestCase):
"""Unit tests for the fileUserData class"""
validUsersString = """username=test
password=user
UserRoot=/data
UserRepoPaths=/data/bill|/data/frank"""
configFilePath = "/tmp/rdw_config.conf"
def setUp(self):
file = open(self.configFilePath, "w")
file.write(self.validUsersString)
file.close()
def tearDown(self):
if (os.access(self.configFilePath, os.F_OK)):
os.remove(self.configFilePath)
def testValidUser(self):
authModule = fileUserDB(self.configFilePath)
assert(authModule.userExists("test"))
assert(authModule.areUserCredentialsValid("test", "user"))
def testBadPassword(self):
authModule = fileUserDB(self.configFilePath)
assert(not authModule.areUserCredentialsValid("test", "user2")) # Basic test
assert(not authModule.areUserCredentialsValid("test", "User")) # password is case sensitive
assert(not authModule.areUserCredentialsValid("test", "use")) # Match entire password
assert(not authModule.areUserCredentialsValid("test", "")) # Make sure pipe at end doesn't allow blank username/password
def testBadUser(self):
authModule = fileUserDB(self.configFilePath)
assert(not authModule.userExists("Test")) # username is case sensitive
assert(not authModule.userExists("tes")) # Match entire username
assert(not authModule.userExists("")) # Make sure blank username is disallowed
def testGoodUserDir(self):
userDataModule = fileUserDB(self.configFilePath)
assert(userDataModule.getUserRepoPaths("test") == ["/data/bill", "/data/frank"])
assert(userDataModule.getUserRoot("test") == "/data")
def testBadUser(self):
userDataModule = fileUserDB(self.configFilePath)
assert(not userDataModule.getUserRepoPaths("test2")) # should return None if user doesn't exist
assert(not userDataModule.getUserRoot("")) # should return None if user doesn't exist
if __name__ == "__main__":
print "Called as standalone program; running unit tests..."
fileUserDataTest = unittest.makeSuite(fileUserDataTest, 'test')
testRunner = unittest.TextTestRunner()
testRunner.run(fileUserDataTest)
rdiffweb-v0.6.5/rdiffWeb/db_mysql.py 0000775 0000000 0000000 00000026212 12205242615 0017421 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import db_sql
import rdw_config
import warnings
"""We do no length validation for incoming parameters, since truncated values will
at worst lead to slightly confusing results, but no security risks"""
class mysqlUserDB:
def __init__(self, configFilePath=None):
import MySQLdb
self.configFilePath = configFilePath
MySQLdb.paramstyle = "pyformat"
self.userRootCache = {}
self._connect()
self._updateToLatestFormat()
def modificationsSupported(self):
return True
def userExists(self, username):
results = self._executeQuery("SELECT Username FROM users WHERE Username = %(user)s", user=username)
return len(results) == 1
def areUserCredentialsValid(self, username, password):
results = self._executeQuery("SELECT Username FROM users WHERE Username = %(user)s AND Password = %(password)s", user=username, password=self._hashPassword(password))
return len(results) == 1
def getUserRoot(self, username):
if not username in self.userRootCache:
self.userRootCache[username] = self._getUserField(username, "UserRoot")
return self.userRootCache[username]
def getUserRepoPaths(self, username):
if not self.userExists(username): return None
query = "SELECT RepoPath FROM repos WHERE UserID = %d" % self._getUserID(username)
repos = [ row[0] for row in self._executeQuery(query)]
repos.sort(lambda x, y: cmp(x.upper(), y.upper()))
return repos
def getUserEmail(self, username):
if not self.userExists(username): return None
return self._getUserField(username, "userEmail")
def useZipFormat(self, username):
if not self.userExists(username): return False
return bool(self._getUserField(username, "restoreFormat"))
def getUserList(self):
query = "SELECT UserName FROM users"
users = [x[0] for x in self._executeQuery(query)]
return users
def addUser(self, username):
if self.userExists(username): raise ValueError
query = "INSERT INTO users (Username) values (%(user)s)"
self._executeQuery(query, user=username)
def deleteUser(self, username):
if not self.userExists(username): raise ValueError
self._deleteUserRepos(username)
query = "DELETE FROM users WHERE Username = %(user)s"
self._executeQuery(query, user=username)
def setUserInfo(self, username, userRoot, isAdmin):
if not self.userExists(username): raise ValueError
if isAdmin:
adminInt = 1
else:
adminInt = 0
query = "UPDATE users SET UserRoot=%(userRoot)s, IsAdmin=" + str(adminInt) + " WHERE Username = %(user)s"
self._executeQuery(query, userRoot=userRoot, user=username)
self.userRootCache[username] = userRoot # update cache
def setUserEmail(self, username, userEmail):
if not self.userExists(username): raise ValueError
self._setUserField(username, 'UserEmail', userEmail)
def setUserRepos(self, username, repoPaths):
if not self.userExists(username): raise ValueError
userID = self._getUserID(username)
# We don't want to just delete and recreate the repos, since that
# would lose notification information.
existingRepos = self.getUserRepoPaths(username)
reposToDelete = filter(lambda x: not x in repoPaths, existingRepos)
reposToAdd = filter(lambda x: not x in existingRepos, repoPaths)
# delete any obsolete repos
for repo in reposToDelete:
query = "DELETE FROM repos WHERE UserID=%(userID)s AND RepoPath= BINARY %(repo)s"
self._executeQuery(query, repo=repo, userID=str(userID))
# add in new repos
query = "INSERT INTO repos (UserID, RepoPath) values (%s, %s)"
repoPaths = [ (str(userID), repo) for repo in reposToAdd ]
cursor = self.sqlConnection.cursor()
cursor.executemany(query, repoPaths)
def setUserPassword(self, username, password):
if not self.userExists(username): raise ValueError
self._setUserField(username, 'Password', self._hashPassword(password))
def setUseZipFormat(self, username, useZip):
if not self.userExists(username): raise ValueError
self._setUserField(username, 'RestoreFormat', bool(useZip))
def setRepoMaxAge(self, username, repoPath, maxAge):
if not repoPath in self.getUserRepoPaths(username): raise ValueError
query = "UPDATE repos SET MaxAge=%(maxAge)s WHERE RepoPath = BINARY %(repoPath)s AND UserID = " + str(self._getUserID(username))
self._executeQuery(query, maxAge=maxAge, repoPath=repoPath)
def getRepoMaxAge(self, username, repoPath):
query = "SELECT MaxAge FROM repos WHERE RepoPath = BINARY %(repoPath)s AND UserID = " + str(self._getUserID(username))
results = self._executeQuery(query, repoPath=repoPath)
assert len(results) == 1
return int(results[0][0])
def userIsAdmin(self, username):
return bool(self._getUserField(username, "IsAdmin"))
########## Helper functions ###########
def _deleteUserRepos(self, username):
if not self.userExists(username): raise ValueError
self._executeQuery("DELETE FROM repos WHERE UserID=%d" % self._getUserID(username))
def _getUserID(self, username):
assert self.userExists(username)
return self._getUserField(username, 'UserID')
def _getUserField(self, username, fieldName):
if not self.userExists(username): return None
query = "SELECT " + fieldName + " FROM users WHERE Username = %(user)s"
results = self._executeQuery(query, user=username)
assert len(results) == 1
return results[0][0]
def _setUserField(self, username, fieldName, value):
if not self.userExists(username): raise ValueError
if isinstance(value, bool):
if value:
valueStr = '1'
else:
valueStr = '0'
else:
valueStr = str(value)
query = 'UPDATE users SET ' + fieldName + '=%(value)s WHERE Username=%(user)s'
self._executeQuery(query, value=valueStr, user=username)
def _internalExecuteQuery(self, query, **kwargs):
cursor = self.sqlConnection.cursor()
cursor.execute(query, kwargs)
return cursor.fetchall()
def _executeQuery(self, query, **kwargs):
# The mysql server connection times out after a while. Catch this, and try again
import MySQLdb
try:
return self._internalExecuteQuery(query, **kwargs)
except MySQLdb.OperationalError:
self._connect()
return self._internalExecuteQuery(query, **kwargs)
def _connect(self):
import MySQLdb
sqlHost = rdw_config.getConfigSetting("sqlHost", self.configFilePath)
sqlUsername = rdw_config.getConfigSetting("sqlUsername", self.configFilePath)
sqlPassword = rdw_config.getConfigSetting("sqlPassword", self.configFilePath)
sqlDatabaseName = rdw_config.getConfigSetting("sqlDatabase", self.configFilePath)
self.sqlConnection = MySQLdb.connect(host=sqlHost, user=sqlUsername, passwd=sqlPassword, db=sqlDatabaseName)
def _hashPassword(self, password):
import sha
hasher = sha.new()
hasher.update(password)
return hasher.hexdigest()
def _getCreateStatements(self):
return [
"""create table users (
UserID int(11) NOT NULL auto_increment,
Username varchar (50) binary unique NOT NULL,
Password varchar (40) NOT NULL DEFAULT "",
UserRoot varchar (255) NOT NULL DEFAULT "",
IsAdmin tinyint NOT NULL DEFAULT FALSE,
UserEmail varchar (255) NOT NULL DEFAULT "",
RestoreFormat tinyint NOT NULL DEFAULT TRUE,
primary key (UserID) )""",
"""create table repos (
RepoID int(11) NOT NULL auto_increment,
UserID int(11) NOT NULL,
RepoPath varchar (255) NOT NULL,
MaxAge tinyint NOT NULL DEFAULT 0,
primary key (RepoID))"""
]
def _updateToLatestFormat(self):
# Make sure that we have tables. If we don't, just quit.
tableNames = [table[0].lower() for table in self._executeQuery("show tables")]
if not tableNames: return
# Make sure that the users table has a "email" column
columnNames = [column[0].lower() for column in self._executeQuery("describe users")]
if not "useremail" in columnNames:
self._executeQuery('alter table users add column UserEmail varchar (255) NOT NULL DEFAULT ""')
# Make sure that the repos table has a "MaxAge" column
columnNames = [column[0].lower() for column in self._executeQuery("describe repos")]
if not "maxage" in columnNames:
self._executeQuery('alter table repos add column MaxAge tinyint NOT NULL DEFAULT 0')
# Make sure that the users table has a "restoreFormat" column
columnNames = [column[0].lower() for column in self._executeQuery("describe users")]
if not "restoreformat" in columnNames:
self._executeQuery('alter table users add column RestoreFormat tinyint NOT NULL DEFAULT TRUE')
def _getTables(self):
return [table[0].lower() for table in self._executeQuery("show tables")]
##################### Unit Tests #########################
import unittest, os
class mysqlUserDBTest(db_sql.sqlUserDBTest):
"""Unit tests for the mysqlUserDBTest class"""
configFileData = """sqlHost=localhost
sqlUsername=
sqlPassword=
sqlDatabase=test"""
configFilePath = "/tmp/rdw_config.conf"
def _getUserDBObject(self):
return mysqlUserDB(self.configFilePath)
def setUp(self):
file = open(self.configFilePath, "w")
file.write(self.configFileData)
file.close()
self.tearDown()
file = open(self.configFilePath, "w")
file.write(self.configFileData)
file.close()
def tearDown(self):
userData = mysqlUserDB(self.configFilePath)
tableNames = [table[0].lower() for table in userData._executeQuery("show tables")]
if 'users' in tableNames:
userData._executeQuery("DROP TABLE IF EXISTS users;")
if 'repos' in tableNames:
userData._executeQuery("DROP TABLE IF EXISTS repos;")
if (os.access(self.configFilePath, os.F_OK)):
os.remove(self.configFilePath)
def testUserTruncation(self):
warnings.filterwarnings('ignore', message='Data truncated')
import MySQLdb
authModule = self._getUserDB()
authModule.addUser("bill" * 1000)
try:
authModule.addUser("bill" * 1000 + "test")
except MySQLdb.IntegrityError:
pass
else:
assert(false)
warnings.resetwarnings()
rdiffweb-v0.6.5/rdiffWeb/db_sql.py 0000664 0000000 0000000 00000010745 12205242615 0017054 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
##################### Unit Tests #########################
import unittest
class sqlUserDBTest(unittest.TestCase):
"""Generic unit tests for sql backends"""
def _getUserDB(self):
userData = self._getUserDBObject()
if not userData._getTables():
for statement in userData._getCreateStatements():
userData._executeQuery(statement)
userData.addUser("test")
userData.setUserInfo("test", "/data", False)
userData.setUserPassword("test", "user")
userData.setUserRepos("test", ["/data/bill", "/data/frank"])
return userData
def tearDown(self):
userData = self._getUserDB()
tableNames = userData._getTables()
print tableNames
if 'users' in tableNames:
userData._executeQuery("DROP TABLE users")
if 'repos' in tableNames:
userData._executeQuery("DROP TABLE repos")
def testValidUser(self):
authModule = self._getUserDB()
assert(authModule.userExists("test"))
assert(authModule.areUserCredentialsValid("test", "user"))
def testUserTruncation(self):
raise NotImplementedError
def testUserList(self):
authModule = self._getUserDB()
assert(authModule.getUserList() == ["test"])
def testDeleteUser(self):
authModule = self._getUserDB()
assert(authModule.getUserList() == ["test"])
authModule.deleteUser("test")
assert(authModule.getUserList() == [])
def testUserInfo(self):
authModule = self._getUserDB()
assert(authModule.getUserRoot("test") == "/data")
assert(authModule.userIsAdmin("test") == False)
def testBadPassword(self):
authModule = self._getUserDB()
assert(not authModule.areUserCredentialsValid("test", "user2")) # Basic test
assert(not authModule.areUserCredentialsValid("test", "User")) # password is case sensitive
assert(not authModule.areUserCredentialsValid("test", "use")) # Match entire password
assert(not authModule.areUserCredentialsValid("test", "")) # Match entire password
def testBadUser(self):
authModule = self._getUserDB()
assert(not authModule.userExists("Test")) # username is case sensitive
assert(not authModule.userExists("tes")) # Match entire username
def testGoodUserDir(self):
userDataModule = self._getUserDB()
assert(userDataModule.getUserRepoPaths("test") == ["/data/bill", "/data/frank"])
assert(userDataModule.getUserRoot("test") == "/data")
def testBadUserReturn(self):
userDataModule = self._getUserDB()
assert(not userDataModule.getUserRepoPaths("test2")) # should return None if user doesn't exist
assert(not userDataModule.getUserRoot("")) # should return None if user doesn't exist
def testUserRepos(self):
userDataModule = self._getUserDB()
userDataModule.setUserRepos("test", [])
userDataModule.setUserRepos("test", ["a", "b", "c"])
self.assertEquals(userDataModule.getUserRepoPaths("test"), ["a", "b", "c"])
# Make sure that repo max ages are initialized to 0
maxAges = [ userDataModule.getRepoMaxAge("test", x) for x in userDataModule.getUserRepoPaths("test") ]
self.assertEquals(maxAges, [0, 0, 0])
userDataModule.setRepoMaxAge("test", "b", 1)
self.assertEquals(userDataModule.getRepoMaxAge("test", "b"), 1)
userDataModule.setUserRepos("test", ["b", "c", "d"])
self.assertEquals(userDataModule.getRepoMaxAge("test", "b"), 1)
self.assertEquals(userDataModule.getUserRepoPaths("test"), ["b", "c", "d"])
def testRestoreFormat(self):
userDataModule = self._getUserDB()
assert(userDataModule.useZipFormat('test')) # Should default to using zip format
userDataModule.setUseZipFormat('test', False)
assert(not userDataModule.useZipFormat('test'))
rdiffweb-v0.6.5/rdiffWeb/db_sqlite.py 0000775 0000000 0000000 00000024133 12205242615 0017555 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import rdw_config
import db_sql
"""We do no length validation for incoming parameters, since truncated values will
at worst lead to slightly confusing results, but no security risks"""
class sqliteUserDB:
def __init__(self, databaseFilePath, autoConvertDatabase=True):
self._databaseFilePath = databaseFilePath
self._autoConvertDatabase = autoConvertDatabase
self.userRootCache = {}
self._connect()
self._migrateExistingData()
def modificationsSupported(self):
return True
def userExists(self, username):
results = self._executeQuery("SELECT Username FROM users WHERE Username = ?", (username,))
return len(results) == 1
def areUserCredentialsValid(self, username, password):
results = self._executeQuery("SELECT Username FROM users WHERE Username = ? AND Password = ?", (username, self._hashPassword(password)))
return len(results) == 1
def getUserRoot(self, username):
if not username in self.userRootCache:
self.userRootCache[username] = self._encodePath(self._getUserField(username, "UserRoot"))
return self.userRootCache[username]
def getUserRepoPaths(self, username):
if not self.userExists(username): return None
query = "SELECT RepoPath FROM repos WHERE UserID = %d" % self._getUserID(username)
repos = [ self._encodePath(row[0]) for row in self._executeQuery(query)]
repos.sort(lambda x, y: cmp(x.upper(), y.upper()))
return repos
def getUserEmail(self, username):
if not self.userExists(username): return None
return self._getUserField(username, "userEmail")
def useZipFormat(self, username):
if not self.userExists(username): return False
return bool(self._getUserField(username, "restoreFormat"))
def getUserList(self):
query = "SELECT UserName FROM users"
users = [x[0] for x in self._executeQuery(query)]
return users
def addUser(self, username):
if self.userExists(username): raise ValueError
query = "INSERT INTO users (Username) values (?)"
self._executeQuery(query, (username,))
def deleteUser(self, username):
if not self.userExists(username): raise ValueError
self._deleteUserRepos(username)
query = "DELETE FROM users WHERE Username = ?"
self._executeQuery(query, (username,))
def setUserInfo(self, username, userRoot, isAdmin):
if not self.userExists(username): raise ValueError
if isAdmin:
adminInt = 1
else:
adminInt = 0
query = "UPDATE users SET UserRoot=?, IsAdmin=" + str(adminInt) + " WHERE Username = ?"
self._executeQuery(query, (userRoot, username))
self.userRootCache[username] = userRoot # update cache
def setUserEmail(self, username, userEmail):
if not self.userExists(username): raise ValueError
self._setUserField(username, 'UserEmail', userEmail)
def setUserRepos(self, username, repoPaths):
if not self.userExists(username): raise ValueError
userID = self._getUserID(username)
# We don't want to just delete and recreate the repos, since that
# would lose notification information.
existingRepos = self.getUserRepoPaths(username)
reposToDelete = filter(lambda x: not x in repoPaths, existingRepos)
reposToAdd = filter(lambda x: not x in existingRepos, repoPaths)
# delete any obsolete repos
for repo in reposToDelete:
query = "DELETE FROM repos WHERE UserID=? AND RepoPath=?"
self._executeQuery(query, (str(userID), repo))
# add in new repos
query = "INSERT INTO repos (UserID, RepoPath) values (?, ?)"
repoPaths = [ [str(userID), repo] for repo in reposToAdd ]
cursor = self.sqlConnection.cursor()
cursor.executemany(query, repoPaths)
def setUserPassword(self, username, password):
if not self.userExists(username): raise ValueError
self._setUserField(username, 'Password', self._hashPassword(password))
def setUseZipFormat(self, username, useZip):
if not self.userExists(username): raise ValueError
self._setUserField(username, 'RestoreFormat', bool(useZip))
def setRepoMaxAge(self, username, repoPath, maxAge):
if not repoPath in self.getUserRepoPaths(username): raise ValueError
query = "UPDATE repos SET MaxAge=? WHERE RepoPath=? AND UserID = " + str(self._getUserID(username))
self._executeQuery(query, (maxAge, repoPath))
def getRepoMaxAge(self, username, repoPath):
query = "SELECT MaxAge FROM repos WHERE RepoPath=? AND UserID = " + str(self._getUserID(username))
results = self._executeQuery(query, (repoPath,))
assert len(results) == 1
return int(results[0][0])
def userIsAdmin(self, username):
return bool(self._getUserField(username, "IsAdmin"))
########## Helper functions ###########
def _encodePath(self, path):
if isinstance(path, unicode):
return path.encode('utf-8')
return path
def _deleteUserRepos(self, username):
if not self.userExists(username): raise ValueError
self._executeQuery("DELETE FROM repos WHERE UserID=%d" % self._getUserID(username))
def _getUserID(self, username):
assert self.userExists(username)
return self._getUserField(username, 'UserID')
def _getUserField(self, username, fieldName):
if not self.userExists(username): return None
query = "SELECT " + fieldName + " FROM users WHERE Username = ?"
results = self._executeQuery(query, (username,))
assert len(results) == 1
return results[0][0]
def _setUserField(self, username, fieldName, value):
if not self.userExists(username): raise ValueError
if isinstance(value, bool):
if value:
valueStr = '1'
else:
valueStr = '0'
else:
valueStr = str(value)
query = 'UPDATE users SET ' + fieldName + '=? WHERE Username=?'
self._executeQuery(query, (valueStr, username))
def _hashPassword(self, password):
import sha
hasher = sha.new()
hasher.update(password)
return hasher.hexdigest()
def _executeQuery(self, query, args=()):
cursor = self.sqlConnection.cursor()
cursor.execute(query, args)
results = cursor.fetchall()
return results
def _connect(self):
try:
import sqlite3
except ImportError:
from pysqlite2 import dbapi2 as sqlite3
connectPath = self._databaseFilePath
if not connectPath:
connectPath = ":memory:"
self.sqlConnection = sqlite3.connect(connectPath)
self.sqlConnection.isolation_level = None
def _getTables(self):
return [column[0] for column in self._executeQuery('select name from sqlite_master where type="table"')]
def _getCreateStatements(self):
return [
"""create table users (
UserID integer primary key autoincrement,
Username varchar (50) unique NOT NULL,
Password varchar (40) NOT NULL DEFAULT "",
UserRoot varchar (255) NOT NULL DEFAULT "",
IsAdmin tinyint NOT NULL DEFAULT FALSE,
UserEmail varchar (255) NOT NULL DEFAULT "",
RestoreFormat tinyint NOT NULL DEFAULT TRUE)""",
"""create table repos (
RepoID integer primary key autoincrement,
UserID int(11) NOT NULL,
RepoPath varchar (255) NOT NULL,
MaxAge tinyint NOT NULL DEFAULT 0)"""
]
def _migrateExistingData(self):
""" If we don't have any data, we may be using a sqlite interface for the first time.
See if they have another database backend specified, and if they do, try to migrate the data."""
if self._getTables(): return
cursor = self.sqlConnection.cursor()
cursor.execute("BEGIN TRANSACTION")
for statement in self._getCreateStatements():
cursor.execute(statement)
if self._autoConvertDatabase:
prevDBType = rdw_config.getConfigSetting("UserDB")
if prevDBType.lower() == "mysql":
print 'Converting database from mysql...'
import db_mysql
prevDB = db_mysql.mysqlUserDB()
users = prevDB._executeQuery("SELECT UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat FROM users")
cursor.executemany("INSERT INTO users (UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat) values (?, ?, ?, ?, ?, ?, ?)", users)
repos = prevDB._executeQuery("SELECT UserID, RepoPath, MaxAge FROM repos")
cursor.executemany("INSERT INTO repos (UserID, RepoPath, MaxAge) values (?, ?, ?)", repos)
elif prevDBType.lower() == "file":
print 'Converting database from file...'
import db_file
prevDB = db_file.fileUserDB()
username = rdw_config.getConfigSetting("username")
password = rdw_config.getConfigSetting("password")
self.addUser(username)
self.setUserPassword(username, password)
self.setUserInfo(username, prevDB.getUserRoot(username), True)
self.setUserRepos(username, prevDB.getUserRepoPaths(username))
cursor.execute("COMMIT TRANSACTION")
class sqliteUserDBTest(db_sql.sqlUserDBTest):
"""Unit tests for the sqliteUserDBTeste class"""
def _getUserDBObject(self):
return sqliteUserDB(":memory:", autoConvertDatabase=False)
def setUp(self):
super(sqliteUserDBTest, self).setUp()
def tearDown(self):
pass
def testUserTruncation(self):
pass
rdiffweb-v0.6.5/rdiffWeb/email_notification.py 0000664 0000000 0000000 00000010111 12205242615 0021430 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import smtplib
import rdw_config
import db
import librdiff
import rdw_helpers
import datetime
import threading
import time
def startEmailNotificationThread(killEvent):
newThread = emailNotifyThread(killEvent)
newThread.start()
class emailNotifyThread(threading.Thread):
def __init__(self, killEvent):
self.killEvent = killEvent
threading.Thread.__init__(self)
def run(self):
self.notifier = emailNotifier()
if not self.notifier.notificationsEnabled():
return;
emailTimeStr = rdw_config.getConfigSetting("emailNotificationTime")
while True:
emailTime = time.strptime(emailTimeStr, "%H:%M")
now = datetime.datetime.now()
nextEmailTime = now.replace(hour=emailTime.tm_hour, minute=emailTime.tm_min, second=0, microsecond=0)
if nextEmailTime < now:
nextEmailTime = nextEmailTime.replace(day=nextEmailTime.day + 1)
delta = (nextEmailTime - now).seconds
self.killEvent.wait(delta)
if self.killEvent.isSet():
return
self.notifier.sendEmails()
class emailNotifier:
def __init__(self):
self.userDB = db.userDB().getUserDBModule()
def notificationsEnabled(self):
return self._getEmailHost() != "" and\
self._getEmailSender() != "" and\
self._getNotificationTimeStr() != "" and\
self.userDB.modificationsSupported()
def sendEmails(self):
for user in self.userDB.getUserList():
userRepos = self.userDB.getUserRepoPaths(user)
oldRepos = []
for repo in userRepos:
maxDaysOld = self.userDB.getRepoMaxAge(user, repo)
if maxDaysOld != 0:
# get the last backup date
try:
lastBackup = librdiff.getLastBackupHistoryEntry(rdw_helpers.joinPaths(self.userDB.getUserRoot(user), repo), False)
except librdiff.FileError:
pass # Skip repos that have never been successfully backed up
else:
if lastBackup:
oldestGoodBackupTime = rdw_helpers.rdwTime()
oldestGoodBackupTime.initFromMidnightUTC(-maxDaysOld)
if lastBackup.date < oldestGoodBackupTime:
oldRepos.append({"repo" : repo, "lastBackupDate" : lastBackup.date.getDisplayString(), "maxAge" : maxDaysOld })
if oldRepos:
userEmailAddress = self.userDB.getUserEmail(user)
emailText = rdw_helpers.compileTemplate("email_notification.txt", repos=oldRepos, sender=self._getEmailSender(), user=user)
session = smtplib.SMTP(self._getEmailHost())
session.login(self._getEmailUsername(), self._getEmailPassword())
smtpresult = session.sendmail(self._getEmailSender(), userEmailAddress.split(";"), emailText)
session.quit()
def _getEmailHost(self):
return rdw_config.getConfigSetting("emailHost")
def _getEmailSender(self):
return rdw_config.getConfigSetting("emailSender")
def _getEmailUsername(self):
return rdw_config.getConfigSetting("emailUsername")
def _getEmailPassword(self):
return rdw_config.getConfigSetting("emailPassword")
def _getNotificationTimeStr(self):
return rdw_config.getConfigSetting("emailNotificationTime")
rdiffweb-v0.6.5/rdiffWeb/filter_authentication.py 0000664 0000000 0000000 00000011303 12205242615 0022163 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import cherrypy
import page_main
import rdw_helpers
import base64
_loginUrl = "/login"
_logoutUrl = "/logout"
_sessionUserNameKey = "username"
def handle_authentication(authMethod='', checkAuth=None):
checkLoginAndPassword = checkAuth
if not checkLoginAndPassword:
checkLoginAndPassword = (lambda username, password: u"Invalid username or password")
if cherrypy.request.path_info == _logoutUrl:
cherrypy.session[_sessionUserNameKey] = None
cherrypy.request.user = None
raise cherrypy.HTTPRedirect("/")
elif cherrypy.session.get(_sessionUserNameKey):
# page passes credentials; allow to be processed
if cherrypy.request.path_info == _loginUrl:
raise cherrypy.HTTPRedirect("/")
return False
if authMethod == "HTTP Header":
# if not already authenticated, authenticate via the Authorization header
httpAuth = _getHTTPAuthorizationCredentials(cherrypy.request.headers.get("Authorization", ""))
if httpAuth:
error = checkLoginAndPassword(httpAuth["login"], httpAuth["password"])
if not error:
return False
else:
error = ""
cherrypy.response.status = "401 Unauthorized"
cherrypy.response.body = "Not Authorized\n" + error
cherrypy.response.headers["WWW-Authenticate"] = 'Basic realm="rdiffWeb"'
return True
loginKey = "login"
passwordKey = "password"
redirectKey = "redirect"
loginParms = {"message": "", "action": _loginUrl,
"loginKey": loginKey, "passwordKey": passwordKey, "redirectKey": redirectKey,
"loginValue": "", "redirectValue": cherrypy.request.path_info + "?" + cherrypy.request.query_string }
if cherrypy.request.path_info == _loginUrl and cherrypy.request.method == "POST":
# check for login credentials
loginValue = cherrypy.request.params[loginKey]
passwordValue = cherrypy.request.params[passwordKey]
redirectValue = cherrypy.request.params[redirectKey]
errorMsg = checkLoginAndPassword(loginValue, passwordValue)
if not errorMsg:
cherrypy.session[_sessionUserNameKey] = loginValue
if not redirectValue:
redirectValue = "/"
raise cherrypy.HTTPRedirect(redirectValue)
# update form values
loginParms["message"] = errorMsg
loginParms["loginValue"] = loginValue
loginParms["redirectValue"] = redirectValue
# write login page
loginPage = page_main.rdiffPage()
cherrypy.response.body = loginPage.compileTemplate("page_start.html", title="Login Required - rdiffWeb", rssLink='', rssTitle='', **loginParms) + loginPage.compileTemplate("login.html", **loginParms)
return True
cherrypy.tools.authenticate = cherrypy._cptools.HandlerTool(handle_authentication)
def _getHTTPAuthorizationCredentials(authHeader):
try:
(realm, authEnc) = authHeader.split()
except ValueError:
return None
if realm.lower() == "basic":
auth = base64.decodestring(authEnc)
colon = auth.find(":")
if colon != -1:
return { "login": auth[:colon], "password": auth[colon + 1:] }
else:
return { "login": auth, "password": "" }
return None
##################### Unit Tests #########################
import unittest, os
class rdwAuthenticationFilterTest(unittest.TestCase):
"""Unit tests for the rdwAuthenticationFilter class"""
def testAuthorization(self):
assert not _getHTTPAuthorizationCredentials("")
assert not _getHTTPAuthorizationCredentials("Basic Username Password")
assert not _getHTTPAuthorizationCredentials("Digest " + base64.encodestring("username"))
assert _getHTTPAuthorizationCredentials("Basic " + base64.encodestring("username")) == { "login": "username", "password": "" }
assert _getHTTPAuthorizationCredentials("Basic " + base64.encodestring("user:pass")) == { "login": "user", "password": "pass" }
assert _getHTTPAuthorizationCredentials("Basic " + base64.encodestring("user:pass:word")) == { "login": "user", "password": "pass:word" }
rdiffweb-v0.6.5/rdiffWeb/filter_https.py 0000664 0000000 0000000 00000002232 12205242615 0020307 0 ustar 00root root 0000000 0000000 # rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import cherrypy
try:
from cherrypy.filters.basefilter import BaseFilter
except:
from cherrypy.lib.filter.basefilter import BaseFilter
class rdwHttpsFilter(BaseFilter):
def onStartResource(self):
cherrypy.request.scheme = 'https'
def beforeRequestBody(self):
if cherrypy.request.browserUrl.startswith("http://"):
cherrypy.request.browserUrl = cherrypy.request.browserUrl.replace("http://", "https://")
rdiffweb-v0.6.5/rdiffWeb/filter_setup.py 0000664 0000000 0000000 00000001676 12205242615 0020320 0 ustar 00root root 0000000 0000000 # rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import cherrypy
import rdw_config
def handle_setup():
if not rdw_config.getConfigFile():
print
raise cherrypy.HTTPRedirect("/setup/")
cherrypy.tools.setup = cherrypy.Tool('before_handler', handle_setup)
rdiffweb-v0.6.5/rdiffWeb/json.py 0000664 0000000 0000000 00000023776 12205242615 0016571 0 ustar 00root root 0000000 0000000 import string
import types
## json.py implements a JSON (http://json.org) reader and writer.
## Copyright (C) 2005 Patrick D. Logan
## Contact mailto:patrickdlogan@stardecisions.com
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
class _StringGenerator(object):
def __init__(self, string):
self.string = string
self.index = -1
def peek(self):
i = self.index + 1
if i < len(self.string):
return self.string[i]
else:
return None
def next(self):
self.index += 1
if self.index < len(self.string):
return self.string[self.index]
else:
raise StopIteration
def all(self):
return self.string
class WriteException(Exception):
pass
class ReadException(Exception):
pass
class JsonReader(object):
hex_digits = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F':15}
escapes = {'t':'\t', 'n':'\n', 'f':'\f', 'r':'\r', 'b':'\b'}
def read(self, s):
self._generator = _StringGenerator(s)
result = self._read()
return result
def _read(self):
self._eatWhitespace()
peek = self._peek()
if peek is None:
raise ReadException, "Nothing to read: '%s'" % self._generator.all()
if peek == '{':
return self._readObject()
elif peek == '[':
return self._readArray()
elif peek == '"':
return self._readString()
elif peek == '-' or peek.isdigit():
return self._readNumber()
elif peek == 't':
return self._readTrue()
elif peek == 'f':
return self._readFalse()
elif peek == 'n':
return self._readNull()
elif peek == '/':
self._readComment()
return self._read()
else:
raise ReadException, "Input is not valid JSON: '%s'" % self._generator.all()
def _readTrue(self):
self._assertNext('t', "true")
self._assertNext('r', "true")
self._assertNext('u', "true")
self._assertNext('e', "true")
return True
def _readFalse(self):
self._assertNext('f', "false")
self._assertNext('a', "false")
self._assertNext('l', "false")
self._assertNext('s', "false")
self._assertNext('e', "false")
return False
def _readNull(self):
self._assertNext('n', "null")
self._assertNext('u', "null")
self._assertNext('l', "null")
self._assertNext('l', "null")
return None
def _assertNext(self, ch, target):
if self._next() != ch:
raise ReadException, "Trying to read %s: '%s'" % (target, self._generator.all())
def _readNumber(self):
isfloat = False
result = self._next()
peek = self._peek()
while peek is not None and (peek.isdigit() or peek == "."):
isfloat = isfloat or peek == "."
result = result + self._next()
peek = self._peek()
try:
if isfloat:
return float(result)
else:
return int(result)
except ValueError:
raise ReadException, "Not a valid JSON number: '%s'" % result
def _readString(self):
result = ""
assert self._next() == '"'
try:
while self._peek() != '"':
ch = self._next()
if ch == "\\":
ch = self._next()
if ch in 'brnft':
ch = self.escapes[ch]
elif ch == "u":
ch4096 = self._next()
ch256 = self._next()
ch16 = self._next()
ch1 = self._next()
n = 4096 * self._hexDigitToInt(ch4096)
n += 256 * self._hexDigitToInt(ch256)
n += 16 * self._hexDigitToInt(ch16)
n += self._hexDigitToInt(ch1)
ch = unichr(n)
elif ch not in '"/\\':
raise ReadException, "Not a valid escaped JSON character: '%s' in %s" % (ch, self._generator.all())
result = result + ch
except StopIteration:
raise ReadException, "Not a valid JSON string: '%s'" % self._generator.all()
assert self._next() == '"'
return result
def _hexDigitToInt(self, ch):
try:
result = self.hex_digits[ch.upper()]
except KeyError:
try:
result = int(ch)
except ValueError:
raise ReadException, "The character %s is not a hex digit." % ch
return result
def _readComment(self):
assert self._next() == "/"
second = self._next()
if second == "/":
self._readDoubleSolidusComment()
elif second == '*':
self._readCStyleComment()
else:
raise ReadException, "Not a valid JSON comment: %s" % self._generator.all()
def _readCStyleComment(self):
try:
done = False
while not done:
ch = self._next()
done = (ch == "*" and self._peek() == "/")
if not done and ch == "/" and self._peek() == "*":
raise ReadException, "Not a valid JSON comment: %s, '/*' cannot be embedded in the comment." % self._generator.all()
self._next()
except StopIteration:
raise ReadException, "Not a valid JSON comment: %s, expected */" % self._generator.all()
def _readDoubleSolidusComment(self):
try:
ch = self._next()
while ch != "\r" and ch != "\n":
ch = self._next()
except StopIteration:
pass
def _readArray(self):
result = []
assert self._next() == '['
done = self._peek() == ']'
while not done:
item = self._read()
result.append(item)
self._eatWhitespace()
done = self._peek() == ']'
if not done:
ch = self._next()
if ch != ",":
raise ReadException, "Not a valid JSON array: '%s' due to: '%s'" % (self._generator.all(), ch)
assert ']' == self._next()
return result
def _readObject(self):
result = {}
assert self._next() == '{'
done = self._peek() == '}'
while not done:
key = self._read()
if type(key) is not types.StringType:
raise ReadException, "Not a valid JSON object key (should be a string): %s" % key
self._eatWhitespace()
ch = self._next()
if ch != ":":
raise ReadException, "Not a valid JSON object: '%s' due to: '%s'" % (self._generator.all(), ch)
self._eatWhitespace()
val = self._read()
result[key] = val
self._eatWhitespace()
done = self._peek() == '}'
if not done:
ch = self._next()
if ch != ",":
raise ReadException, "Not a valid JSON array: '%s' due to: '%s'" % (self._generator.all(), ch)
assert self._next() == "}"
return result
def _eatWhitespace(self):
p = self._peek()
while p is not None and p in string.whitespace or p == '/':
if p == '/':
self._readComment()
else:
self._next()
p = self._peek()
def _peek(self):
return self._generator.peek()
def _next(self):
return self._generator.next()
class JsonWriter(object):
def _append(self, s):
self._results.append(s)
def write(self, obj, escaped_forward_slash=False):
self._escaped_forward_slash = escaped_forward_slash
self._results = []
self._write(obj)
return "".join(self._results)
def _write(self, obj):
ty = type(obj)
if ty is types.DictType:
n = len(obj)
self._append("{")
for k, v in obj.items():
self._write(k)
self._append(":")
self._write(v)
n = n - 1
if n > 0:
self._append(",")
self._append("}")
elif ty is types.ListType or ty is types.TupleType:
n = len(obj)
self._append("[")
for item in obj:
self._write(item)
n = n - 1
if n > 0:
self._append(",")
self._append("]")
elif ty is types.StringType or ty is types.UnicodeType:
self._append('"')
obj = obj.replace('\\', r'\\')
if self._escaped_forward_slash:
obj = obj.replace('/', r'\/')
obj = obj.replace('"', r'\"')
obj = obj.replace('\b', r'\b')
obj = obj.replace('\f', r'\f')
obj = obj.replace('\n', r'\n')
obj = obj.replace('\r', r'\r')
obj = obj.replace('\t', r'\t')
self._append(obj)
self._append('"')
elif ty is types.IntType or ty is types.LongType:
self._append(str(obj))
elif ty is types.FloatType:
self._append("%f" % obj)
elif obj is True:
self._append("true")
elif obj is False:
self._append("false")
elif obj is None:
self._append("null")
else:
raise WriteException, "Cannot write in JSON: %s" % repr(obj)
def write(obj, escaped_forward_slash=False):
return JsonWriter().write(obj, escaped_forward_slash)
def read(s):
return JsonReader().read(s)
rdiffweb-v0.6.5/rdiffWeb/librdiff.py 0000775 0000000 0000000 00000075657 12205242615 0017411 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""All functions throw on error."""
import os
import bisect
import gzip
import re
from rdw_helpers import joinPaths, removeDir
import rdw_helpers
import logging
import tempfile
RDIFF_BACKUP_DATA = "rdiff-backup-data"
#Constant for the rdiff-backup-data folder name.
INCREMENTS = joinPaths(RDIFF_BACKUP_DATA, "increments")
#Constant for the increments folder name.
ZIP_SUFFIX = ".zip"
# Zip file extension
TARGZ_SUFFIX = ".tar.gz"
# Tar gz extension
class FileError:
def getErrorString(self):
return self.error
def __str__(self):
return self.getErrorString()
class AccessDeniedError(FileError):
def __init__(self):
self.error = "Access is denied."
class DoesNotExistError(FileError):
def __init__(self):
self.error = "The backup location does not exist."
class UnknownError(FileError):
def __init__(self, error=None):
self.error = error
if not self.error:
self.error = "An unknown error occurred."
##### Helper Functions #####
def rsplit(string, sep, count= -1):
L = [part[::-1] for part in string[::-1].split(sep[::-1], count)]
L.reverse()
return L
##### Interfaced objects #####
class DirEntry:
"""Includes name, isDir, fileSize, exists, and dict (changeDates) of sorted local dates when backed up"""
def __init__(self, name, quoter, isDir, fileSize, exists, changeDates):
self.name = quoter.getUnquotedPath(name)
self.isDir = isDir
self.fileSize = fileSize
self.exists = exists
self.changeDates = changeDates
class BackupHistoryEntry:
def __init__(self):
self.date = None
self.size = None
self.errors = None
self.incrementSize = None
self.inProgress = None
pass
class BackupHistoryEntries:
"""Instance of this class represent a collection of backup entry for a
single repository. Roughtly their is one entry for each
'current_mirror.*' files."""
def __init__(self, repoRoot):
checkRepoPath(repoRoot, "")
self.repoRoot = repoRoot
# List all the files within the rdiff-backup-data
self.dirEntries = os.listdir(os.path.join(repoRoot, RDIFF_BACKUP_DATA))
self.dirEntries.sort()
def getBackupHistory(self, numLatestEntries= -1, earliestDate=None, latestDate=None, includeInProgress=True):
"""Returns a list of backupHistoryEntry's
earliestDate and latestDate are inclusive."""
# Get a listing of error log files, and use that to build backup history
curEntries = filter(lambda x: x.startswith("error_log."), self.dirEntries)
curEntries.reverse()
entries = []
for entryFile in curEntries:
entry = IncrementEntry(self.repoRoot, entryFile)
# compare local times because of discrepency between client/server time zones
if earliestDate and entry.getDate().getLocalSeconds() < earliestDate.getLocalSeconds():
continue
if latestDate and entry.getDate().getLocalSeconds() > latestDate.getLocalSeconds():
continue
try:
errors = entry.getErrors()
except IOError:
logging.exception("Can't retrieved errors.")
errors = "[Unable to read errors file.]"
try:
fileSize = entry.getSourceFileSize()
incrementSize = entry.getIncrementFileSize()
except IOError:
logging.exception("Can't get session stats.")
fileSize = 0
incrementSize = 0
# Create the backup history entry using data from the increment entry
newEntry = BackupHistoryEntry()
newEntry.date = entry.getDate()
newEntry.inProgress = self._backupIsInProgress(entry.getDate())
if not includeInProgress and newEntry.inProgress:
continue
if newEntry.inProgress:
newEntry.errors = ""
else:
newEntry.errors = errors
newEntry.size = int(fileSize) if fileSize else 0
newEntry.incrementSize = int(incrementSize) if incrementSize else 0
entries.insert(0, newEntry)
if numLatestEntries != -1 and len(entries) == numLatestEntries:
return entries
return entries
def _backupIsInProgress(self, date):
# Filter the files to keep current_mirror.* files
mirrorMarkers = filter(lambda x: x.startswith("current_mirror."), self.dirEntries)
if not mirrorMarkers:
return True
for marker in mirrorMarkers[1:]:
if IncrementEntry(self.repoRoot, marker).getDate().getSeconds() == date.getSeconds():
return True
return False
class IncrementEntry:
"""Instance of the class represent one increment at a specific date for one
repository. The base repository is provided in the default constructor
and the date is provided using an error_log.* file"""
MISSING_SUFFIX = ".missing"
SUFFIXES = [".missing", ".snapshot.gz", ".snapshot", ".diff.gz", ".data.gz", ".data", ".dir", ".diff"];
def __init__(self, repoRoot, entryName):
"""Default constructor for an increment entry. User must provide the
repository directory and an entry name. The entry name correspond to
an error_log.* filename."""
# Keep reference to the repository location
self.repoRoot = repoRoot
# The given entry name may has quote charater, replace them
self.entryName = RdiffQuotedPath(repoRoot).getQuotedPath(entryName)
def getDate(self):
timeString = self.getDateString()
returnTime = rdw_helpers.rdwTime()
try:
returnTime.initFromString(timeString)
return returnTime
except ValueError:
return None
def getDateString(self):
filename = self._removeSuffix(self.entryName)
return rsplit(filename, ".", 1)[1]
def getDateStringNoTZ(self, tzOffset=0):
filename = self._removeSuffix(self.entryName)
incrDate = self.getDate()
if not incrDate:
print "Warning: unintelligible date string! Filename:", self.entryName, " Filetitle:", filename, " Date String:", self.getDateString()
return "" # avoid crashing on invalid date strings
incrDate.timeInSeconds += tzOffset
return incrDate.getUrlStringNoTZ()
def getErrors(self):
"""Read the error file and return it's content. Raise exception if the
file can't be read."""
if self.isCompressed():
return gzip.open(os.path.join(self.repoRoot, RDIFF_BACKUP_DATA, self.entryName), "r").read()
return open(os.path.join(self.repoRoot, RDIFF_BACKUP_DATA, self.entryName), "r").read()
def getFilename(self):
filename = self._removeSuffix(self.entryName)
return rsplit(filename, ".", 1)[0]
def getIncrementFileSize(self):
"""This function return the value of the IncrementFileSize define in the
session_statistics.* file for the current increment or None if the
file can't be found."""
stats = self._getSessionStatistics()
if not stats:
return None
return re.compile("IncrementFileSize ([0-9]+) ").findall(stats)[0]
def _getSessionStatsFile(self):
"""Return the filepath of the sessions statistics file for a given backup
entry. This function search for file 'session_statistics.*'"""
# Get the date of the current entry
entryDate = self.getDate()
# List all the session_statistics file foir the current repository
statFiles = filter(lambda x: x.startswith("session_statistics."), os.listdir(os.path.join(self.repoRoot, RDIFF_BACKUP_DATA)))
# For each file, check if the date matches.
for file in statFiles:
time = self._parseDate(file)
if time == entryDate:
return os.path.join(self.repoRoot, RDIFF_BACKUP_DATA, file)
# Can't find the file
return None
def _getSessionStatistics(self):
"""Return the content of the session_statistics.* file for the current
increment."""
if hasattr(self, "statistics"):
return self.statistics
filename = self._getSessionStatsFile()
if not filename:
self.statistics = None
return None
self.statistics = open(filename, 'r').read()
return self.statistics
def getSize(self):
return 0 #TODO: use gzip to figure out increment size for snapshot increments
def getSourceFileSize(self):
"""This function return the value of the SourceFileSize define in the
session_statistics.* file for the current increment or None if the
file can't be found."""
stats = self._getSessionStatistics()
if not stats:
return None
return re.compile("SourceFileSize ([0-9]+) ").findall(stats)[0]
def hasIncrementSuffix(self, filename):
for suffix in self.SUFFIXES:
if filename.endswith(suffix):
return True
return False
def isCompressed(self):
return self.entryName.endswith(".gz")
def isMissingIncrement(self):
return self.entryName.endswith(self.MISSING_SUFFIX)
def isSnapshotIncrement(self):
return self.entryName.endswith(".snapshot.gz") or self.entryName.endswith(".snapshot")
def shouldShowIncrement(self):
return self.hasIncrementSuffix(self.entryName) and not self.isMissingIncrement()
def _parseDate(self, filename):
"""Return a date object from a filename."""
# Parse the date of the file
filename = self._removeSuffix(filename)
filename = rsplit(filename, ".", 1)[1]
time = rdw_helpers.rdwTime()
try:
time.initFromString(filename)
return time
except ValueError:
return None
def _removeSuffix(self, filename):
""" returns None if there was no suffix to remove. """
for suffix in self.SUFFIXES:
if filename.endswith(suffix):
return filename[:-len(suffix)]
return filename
class RdiffQuotedPath:
"""This class may be used to convert quoted file name. Ridff-backup may
convert special charater using the following pattern ;000. This is used
to ensure compatibility between filesystem."""
def __init__(self, repoRoot):
self.unquoteRegex = re.compile(";[0-9]{3}", re.S)
charsToQuotePath = joinPaths(repoRoot, RDIFF_BACKUP_DATA, "chars_to_quote")
if os.path.exists(charsToQuotePath):
charsToQuoteStr = open(charsToQuotePath).read()
if charsToQuoteStr:
self.quoteRegex = re.compile("[^/%s]|;" % charsToQuoteStr, re.S)
def getUnquotedPath(self, quotedPath):
return self.unquoteRegex.sub(self.getUnquotedChar, quotedPath)
def getQuotedPath(self, unQuotedPath):
if not hasattr(self, "quoteRegex"): return unQuotedPath
return self.quoteRegex.sub(self.getQuotedChar, unQuotedPath)
# This function just gives back the original text if it can decode it
def getUnquotedChar(self, match):
if not len(match.group()) == 4:
return match.group
try:
return chr(int(match.group()[1:]))
except ValueError:
return match.group
def getQuotedChar(self, match):
return ";%03d" % (ord(match.group()))
class RdiffDirEntries:
"""This class is responsible for building a listing of directory entries.
All knowledge of how increments work is contained in this class."""
# dirPath must be quoted!
def __init__(self, repo, dirPath):
# Var assignment and validation
self.pathQuoter = RdiffQuotedPath(repo)
self.repo = repo
self.dirPath = dirPath
self.completePath = joinPaths(repo, dirPath)
dataPath = joinPaths(repo, RDIFF_BACKUP_DATA)
# cache dir listings
self.entries = []
if os.access(self.completePath, os.F_OK):
self.entries = os.listdir(self.completePath) # the directory may not exist if it has been deleted
self.dataDirEntries = os.listdir(dataPath)
incrementsDir = joinPaths(repo, INCREMENTS, dirPath)
self.incrementEntries = []
if os.access(incrementsDir, os.F_OK): # the increments may not exist if the folder has existed forever and never been changed
self.incrementEntries = filter(lambda x: not os.path.isdir(joinPaths(incrementsDir, x)), os.listdir(incrementsDir)) # ignore directories
self.groupedIncrementEntries = rdw_helpers.groupby(self.incrementEntries, lambda x: IncrementEntry(repo, x).getFilename())
self.backupTimes = [ IncrementEntry(repo, x).getDate() for x in filter(lambda x: x.startswith("mirror_metadata"), self.dataDirEntries) ]
self.backupTimes.sort()
def getDirEntries(self):
""" returns dictionary of dir entries, keyed by dir name """
entriesDict = {}
# First, we grab a dir listing of the target, setting entry attributes
for entryName in self.entries:
if entryName == RDIFF_BACKUP_DATA: continue
entryPath = joinPaths(self.repo, self.dirPath, entryName)
newEntry = DirEntry(entryName, self.pathQuoter, os.path.isdir(entryPath), os.lstat(entryPath)[6], True,
[self._getLastChangedBackupTime(entryName)])
entriesDict[newEntry.name] = newEntry
# Go through the increments dir. If we find any files that didn't exist in dirPath (i.e. have been deleted), add them
for entryFile in self.incrementEntries:
entry = IncrementEntry(self.repo, entryFile)
entryName = entry.getFilename()
if entry.shouldShowIncrement() or entry.isMissingIncrement():
entryDate = entry.getDate()
if not entry.isSnapshotIncrement():
if entry.isMissingIncrement():
entryDate = self._getFirstBackupAfterDate(entry.getDate())
else:
entryDate = entry.getDate()
if not entryName in entriesDict.keys():
entryPath = joinPaths(self.repo, INCREMENTS, self.dirPath, entryName)
newEntry = DirEntry(entryName, self.pathQuoter, os.path.isdir(entryPath), 0, False, [entryDate])
entriesDict[entryName] = newEntry
else:
if not entryDate in entriesDict[entryName].changeDates:
bisect.insort_left(entriesDict[entryName].changeDates, entryDate)
return entriesDict
def _getFirstBackupAfterDate(self, date):
""" Iterates the mirror_metadata files in the rdiff data dir """
if not date:
return self.backupTimes[0]
return self.backupTimes[bisect.bisect_right(self.backupTimes, date)]
def _getLastChangedBackupTime(self, filename):
files = self.groupedIncrementEntries.get(filename, [])
if os.path.isdir(joinPaths(self.completePath, filename)):
files = filter(lambda x: x.endswith(".dir") or x.endswith(".missing"), files)
files.sort()
if not files:
return self._getFirstBackupAfterDate(None)
return self._getFirstBackupAfterDate(IncrementEntry(self.repo, files[-1]).getDate())
def checkRepoPath(repoRoot, filePath):
"""Check if the file path specified is valid within the a repository."""
# Make sure repoRoot is a valid rdiff-backup repository
dataPath = joinPaths(repoRoot, RDIFF_BACKUP_DATA)
if not os.access(dataPath, os.F_OK) or not os.path.isdir(dataPath):
raise DoesNotExistError()
# Make sure there are no symlinks in the path
pathToCheck = joinPaths(repoRoot, filePath)
while True:
pathToCheck = pathToCheck.rstrip("/")
if os.path.islink(pathToCheck):
raise AccessDeniedError()
(pathToCheck, file) = os.path.split(pathToCheck)
if not file:
break
# Make sure that the folder/file exists somewhere - either in the current folder, or in the incrementsDir
if not os.access(joinPaths(repoRoot, filePath), os.F_OK):
(parentFolder, filename) = os.path.split(joinPaths(repoRoot, INCREMENTS, filePath))
try:
increments = os.listdir(parentFolder)
except OSError:
increments = []
increments = filter(lambda x: x.startswith(filename), increments)
if not increments:
raise DoesNotExistError()
##### Interfaced Functions #####
def getDirEntries(repoRoot, dirPath):
"""Returns list of rdiffDirEntry objects for the directory path specified within a repository."""
dirPath = RdiffQuotedPath(repoRoot).getQuotedPath(dirPath)
checkRepoPath(repoRoot, dirPath)
entryLister = RdiffDirEntries(repoRoot, dirPath)
entries = entryLister.getDirEntries()
entriesList = entries.values()
def sortDirEntries(entry1, entry2):
if entry1.isDir and not entry2.isDir: return -1
if not entry1.isDir and entry2.isDir: return 1
return cmp(entry1.name.upper(), entry2.name.upper())
entriesList.sort(sortDirEntries)
return entriesList
def restoreFileOrDir(repoRoot, dirPath, filename, restoreDate, useZip):
"""This function is used to restore a directory tree or a file from the
given respository. Users may specified the restore date and the
archive format."""
# Format the specified file name / repository path for validation
filePath = joinPaths(dirPath, filename)
filePath = RdiffQuotedPath(repoRoot).getQuotedPath(filePath)
checkRepoPath(repoRoot, filePath)
restoredFilename = filename
if restoredFilename == "/":
restoredFilename = "(root)"
fileToRestore = joinPaths(repoRoot, dirPath, filename)
dateString = str(restoreDate.getSeconds())
rdiffOutputFile = joinPaths(tempfile.mkdtemp(), restoredFilename) # TODO: make so this includes the username
# Use rdiff-backup executable to restore the data into a specified location
results = rdw_helpers.execute("rdiff-backup", "--restore-as-of=" + dateString, fileToRestore, rdiffOutputFile)
# Check the result
if results['exitCode'] != 0 or not os.access(rdiffOutputFile, os.F_OK):
error = results['stderr']
if not error:
error = 'rdiff-backup claimed success, but did not restore anything. This indicates a bug in rdiffWeb. Please report this to a developer.'
raise UnknownError('Unable to restore! rdiff-backup output:\n' + error)
# The path restored is a directory and need to be archived using zip or tar
if os.path.isdir(rdiffOutputFile):
rdiffOutputDirectory = rdiffOutputFile
try:
if useZip:
rdiffOutputFile = rdiffOutputFile + ZIP_SUFFIX
_recursiveZipDir(rdiffOutputDirectory, rdiffOutputFile)
else:
rdiffOutputFile = rdiffOutputFile + TARGZ_SUFFIX
_recursiveTarDir(rdiffOutputDirectory, rdiffOutputFile)
finally:
rdw_helpers.removeDir(rdiffOutputDirectory)
return rdiffOutputFile
def backupIsInProgressForRepo(repo):
rdiffDir = joinPaths(repo, RDIFF_BACKUP_DATA)
mirrorMarkers = os.listdir(rdiffDir)
mirrorMarkers = filter(lambda x: x.startswith("current_mirror."), mirrorMarkers)
return not mirrorMarkers or len(mirrorMarkers) > 1
def getBackupHistory(repoRoot):
"""Return a list of BackupHistoryEntry for the respository specified."""
historyEntries = BackupHistoryEntries(repoRoot)
return historyEntries.getBackupHistory()
def getLastBackupHistoryEntry(repoRoot, includeInProgress=True):
"""Return the most recent instance of BackupHistoryEntry for the repository
specified."""
historyEntries = BackupHistoryEntries(repoRoot)
history = historyEntries.getBackupHistory(1, None, None, includeInProgress)
if not history:
# We may not have any backup entries if the first backup
# for the repository is in progress
raise FileError
return history[0]
def getBackupHistoryForDay(repoRoot, date):
historyEntries = BackupHistoryEntries(repoRoot)
return historyEntries.getBackupHistory(-1, date)
def getBackupHistorySinceDate(repoRoot, date):
historyEntries = BackupHistoryEntries(repoRoot)
return historyEntries.getBackupHistory(-1, date)
def getBackupHistoryForDateRange(repoRoot, earliestDate, latestDate):
historyEntries = BackupHistoryEntries(repoRoot)
return historyEntries.getBackupHistory(-1, earliestDate, latestDate, False)
def getDirRestoreDates(repo, path):
backupHistory = [ x.date for x in getBackupHistory(repo) ]
if path != "/":
(parentPath, dirName) = os.path.split(path)
dirListing = getDirEntries(repo, parentPath)
entries = filter(lambda x: x.name == dirName, dirListing)
if not entries:
raise DoesNotExistError
entry = entries[0]
# Don't allow restores before the dir existed
backupHistory = filter(lambda x: x >= entry.changeDates[0], backupHistory)
if not entry.exists:
# If the dir has been deleted, don't allow restores after its deletion
backupHistory = filter(lambda x: x <= entry.changeDates[-1], backupHistory)
return backupHistory
def _recursiveTarDir(dirPath, tarFilename):
"""This function is used during to archive a restored directory. It will
create a tar gz archive with the specified directory."""
assert os.path.isdir(dirPath)
import tarfile
dirPath = os.path.normpath(dirPath)
# Create a tar.gz archive
tar = tarfile.open(tarFilename, "w:gz")
files = os.listdir(dirPath)
# Add files to the archive
for file in files:
tar.add(joinPaths(dirPath, file), file) # Pass in file as name explicitly so we get relative paths
# Close the archive
tar.close()
def _recursiveZipDir(dirPath, zipFilename):
"""This function is used during to archive a restored directory. It will
create a zip archive with the specified directory."""
assert os.path.isdir(dirPath)
import zipfile
dirPath = os.path.normpath(dirPath)
# Create the archive
zipObj = zipfile.ZipFile(zipFilename, "w", zipfile.ZIP_DEFLATED)
# Add files to archive
for root, dirs, files in os.walk(dirPath, topdown=True):
for name in files:
fullPath = joinPaths(root, name)
assert fullPath.startswith(dirPath)
relPath = fullPath[len(dirPath) + 1:]
zipObj.write(fullPath, relPath)
zipObj.close()
##################### Unit Tests #########################
def runRdiff(src, dest, time):
# Force a null TZ for backups, to keep rdiff-backup from mangling the times
environ = os.environ;
environ['TZ'] = ""
os.spawnlp(os.P_WAIT, "rdiff-backup", "rdiff-backup", "--no-compare-inode", "--current-time=" + str(time.getSeconds()), src, dest)
def getMatchingDirEntry(entries, filename):
# for entry in entries:
# print entry.name
matchingEntries = filter(lambda x: x.name == filename, entries)
assert len(matchingEntries) == 1, entries
return matchingEntries[0]
import unittest, time
class LibRdiffTest(unittest.TestCase):
# The dirs containing source data for automated tests are set up in the following format:
# one folder for each test, named to describe the test
# one folder for each state in the backup, named using the rdiff-backup time format (e.g. "2006-01-04T01:49:50Z")
# folder contents at given state. Subdirs are not really handled
# The setUp function is responsible for backing up data for each backup test case and test case state, rooted at self.destRoot
def setUp(self):
# The temp dir on Mac OS X is a symlink; expand it because of validation against symlinks in paths
self.destRoot = joinPaths(os.path.realpath(tempfile.gettempdir()), "rdiffWeb")
self.masterDirPath = joinPaths("..", "tests") # TODO: do this right, including tying tests into "python setup.py test"
self.tearDown()
os.makedirs(self.destRoot)
# Set up each scenario
tests = self.getBackupTests()
for testDir in tests:
# Iterate through the backup states
origStateDir = joinPaths(self.masterDirPath, testDir)
backupStates = self.getBackupStates(origStateDir)
backupStates.sort(lambda x, y: cmp(x, y))
for backupState in backupStates:
# Try to parse the folder name as a date. If we can't, raise
backupTime = rdw_helpers.rdwTime()
backupTime.initFromString(backupState)
# Backup the data as it should be at that state
#print " State", backupState
runRdiff(joinPaths(origStateDir, backupState), joinPaths(self.destRoot, testDir), backupTime)
def tearDown(self):
if (os.access(self.destRoot, os.F_OK)):
removeDir(self.destRoot)
def getBackupTests(self):
return filter(lambda x: not x.startswith("."), os.listdir(self.masterDirPath))
def getBackupStates(self, backupTestDir):
return filter(lambda x: not x.startswith(".") and x != "results", os.listdir(backupTestDir))
def hasDirEntriesResults(self, testname):
return os.access(joinPaths(self.masterDirPath, testname, "results", "dir_entries.txt"), os.F_OK)
def hasDirRestoreDates(self, testname):
return os.access(joinPaths(self.masterDirPath, testname, "results", "dir_restore_dates.txt"), os.F_OK)
def getExpectedDirRestoreDates(self, testName):
return open(joinPaths(self.masterDirPath, testName, "results", "dir_restore_dates.txt")).read()
def getExpectedDirEntriesResults(self, testName):
return open(joinPaths(self.masterDirPath, testName, "results", "dir_entries.txt")).read()
################ Start actual tests ###################
def testGetDirEntries(self):
tests = self.getBackupTests()
for testDir in tests:
if self.hasDirEntriesResults(testDir):
# Get a list of backup entries for the root folder
rdiffDestDir = joinPaths(self.destRoot, testDir)
entries = getDirEntries(rdiffDestDir, "/")
statusText = ""
for entry in entries:
if entry.name != ".svn":
for changeDate in entry.changeDates:
size = entry.fileSize
if entry.isDir: size = 0
statusText = statusText + entry.name + "\t" + str(entry.isDir) + "\t" + str(size) + "\t" + str(entry.exists) + "\t" + changeDate.getUrlString() + "\n"
assert statusText.replace("\n", "") == self.getExpectedDirEntriesResults(testDir).replace("\n", ""), "Got: " + statusText + "\nExpected:" + self.getExpectedDirEntriesResults(testDir)
def testGetDirRestoreDates(self):
tests = self.getBackupTests()
for testDir in tests:
if self.hasDirRestoreDates(testDir):
rdiffDestDir = joinPaths(self.destRoot, testDir)
#print rdiffDestDir
dates = getDirRestoreDates(rdiffDestDir, "/testdir2")
statusText = ""
for date in dates:
statusText = statusText + date.getUrlString() + "\n"
assert statusText.replace("\n", "") == self.getExpectedDirRestoreDates(testDir).replace("\n", ""), "Got: " + statusText + "\nExpected:" + self.getExpectedDirRestoreDates(testDir)
def testGetBackupHistory(self):
tests = self.getBackupTests()
for testDir in tests:
# Get a list of backup entries for the root folder
origBackupDir = joinPaths(self.masterDirPath, testDir)
backupStates = self.getBackupStates(origBackupDir)
backupStates.sort(lambda x, y: cmp(x, y))
rdiffDestDir = joinPaths(self.destRoot, testDir)
entries = getBackupHistory(rdiffDestDir)
assert len(entries) == len(backupStates)
backupNum = 0
for backup in backupStates:
origBackupStateDir = joinPaths(origBackupDir, backup)
totalBackupSize = 0
for file in os.listdir(origBackupStateDir):
totalBackupSize = totalBackupSize + os.lstat(joinPaths(origBackupStateDir, file))[6]
#TODO: fix this to handle subdirs
#assert totalBackupSize == entries[backupNum].size, "Calculated: "+str(totalBackupSize)+" Reported: "+str(entries[backupNum].size)+" State: "+str(backupNum)
backupNum = backupNum + 1
# Test that the last backup entry works correctly
lastEntry = getLastBackupHistoryEntry(rdiffDestDir)
lastBackupTime = rdw_helpers.rdwTime()
lastBackupTime.initFromString(backupStates[-1])
assert lastEntry.date == lastBackupTime
# Test that timezone differences are ignored
historyAsOf = lastEntry.date.getUrlString()
lastBackupTime = rdw_helpers.rdwTime()
lastBackupTime.initFromString(historyAsOf)
entries = getBackupHistorySinceDate(rdiffDestDir, lastBackupTime)
assert len(entries) == 1
# Test that no backups are returned one second after the last backup
historyAsOf = historyAsOf[:18] + "1" + historyAsOf[19:]
postBackupTime = rdw_helpers.rdwTime()
postBackupTime.initFromString(historyAsOf)
assert lastBackupTime.getLocalSeconds() + 1 == postBackupTime.getLocalSeconds()
entries = getBackupHistorySinceDate(rdiffDestDir, postBackupTime)
assert len(entries) == 0
def testRestoreFile(self):
tests = self.getBackupTests()
for testDir in tests:
# Get a list of backup entries for the root folder
rdiffDestDir = joinPaths(self.destRoot, testDir)
entries = getDirEntries(rdiffDestDir, "/")
# Go back through all backup states and make sure that the backup entries match the files that exist
origStateDir = joinPaths(self.masterDirPath, testDir)
backupStates = self.getBackupStates(origStateDir)
backupStates.sort(lambda x, y: cmp(x, y))
for backupState in backupStates:
backupTime = rdw_helpers.rdwTime()
backupTime.initFromString(backupState)
# Go through each file, and make sure that the restored file looks the same as the orig file
origStateDir = joinPaths(self.masterDirPath, testDir, backupState)
files = self.getBackupStates(origStateDir)
for file in files:
origFilePath = joinPaths(origStateDir, file)
if not os.path.isdir(origFilePath):
restoredFilePath = restoreFileOrDir(rdiffDestDir, "/", file, backupTime)
assert open(restoredFilePath, "r").read() == open(origFilePath, "r").read()
os.remove(restoredFilePath)
if __name__ == "__main__":
print "Called as standalone program; running unit tests..."
testSuite = unittest.makeSuite(LibRdiffTest, 'test')
testRunner = unittest.TextTestRunner()
testRunner.run(testSuite)
# import profile
# profile.run("getDirEntries('/', '/')", "results.txt")
rdiffweb-v0.6.5/rdiffWeb/page_admin.py 0000664 0000000 0000000 00000007322 12205242615 0017671 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import rdw_helpers
import page_main
import rdw_templating
import cherrypy
import rdw_spider_repos
class rdiffAdminPage(page_main.rdiffPage):
def index(self, **kwargs):
if not self._userIsAdmin(): return self.writeErrorPage("Access denied.")
# If we're just showing the initial page, just do that
if not self._isSubmit():
return self._generatePageHtml("", "")
# We need to change values. Change them, then give back that main page again, with a message
action = cherrypy.request.params["action"]
username = cherrypy.request.params["username"]
userRoot = cherrypy.request.params["userRoot"]
userIsAdmin = cherrypy.request.params.get("isAdmin", False) != False
if action == "edit":
if not self.getUserDB().userExists(username):
return self._generatePageHtml("", "The user does not exist.")
self.getUserDB().setUserInfo(username, userRoot, userIsAdmin)
return self._generatePageHtml("User information modified successfully", "")
elif action == "add":
if self.getUserDB().userExists(username):
return self._generatePageHtml("", "The specified user already exists.", username, userRoot, userIsAdmin)
if username == "":
return self._generatePageHtml("", "The username is invalid.", username, userRoot, userIsAdmin)
self.getUserDB().addUser(username)
self.getUserDB().setUserPassword(username, cherrypy.request.params["password"])
self.getUserDB().setUserInfo(username, userRoot, userIsAdmin)
return self._generatePageHtml("User added successfully.", "")
index.exposed = True
def deleteUser(self, user):
if not self._userIsAdmin(): return self.writeErrorPage("Access denied.")
if not self.getUserDB().userExists(user):
return self._generatePageHtml("", "The user does not exist.")
if user == self.getUsername():
return self._generatePageHtml("", "You cannot remove your own account!.")
self.getUserDB().deleteUser(user)
return self._generatePageHtml("User account removed.", "")
deleteUser.exposed = True
############### HELPER FUNCTIONS #####################
def _userIsAdmin(self):
return self.getUserDB().userIsAdmin(self.getUsername())
def _isSubmit(self):
return cherrypy.request.method == "POST"
def _generatePageHtml(self, message, error, username="", userRoot="", isAdmin=False):
userNames = self.getUserDB().getUserList()
users = [ { "username" : user, "isAdmin" : self.getUserDB().userIsAdmin(user), "userRoot" : self.getUserDB().getUserRoot(user) } for user in userNames ]
parms = { "users" : users,
"username" : username,
"userRoot" : userRoot,
"isAdmin" : isAdmin,
"message" : message,
"error" : error }
return self.startPage("Administration") + self.compileTemplate("admin_main.html", **parms) + self.endPage()
rdiffweb-v0.6.5/rdiffWeb/page_browse.py 0000664 0000000 0000000 00000013555 12205242615 0020107 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from rdw_helpers import joinPaths, encodePath
import rdw_helpers, page_main, librdiff
import os
import urllib
class rdiffBrowsePage(page_main.rdiffPage):
def index(self, repo="", path="", restore=""):
try:
self.validateUserPath(joinPaths(repo, path))
except rdw_helpers.accessDeniedError, error:
return self.writeErrorPage(str(error))
# NOTE: a blank path parm is allowed, since that just results in a listing of the repo root
if not repo: return self.writeErrorPage("Backup location not specified.")
if not repo in self.getUserDB().getUserRepoPaths(self.getUsername()):
return self.writeErrorPage("Access is denied.")
try:
parms = self.getParmsForPage(self.getUserDB().getUserRoot(self.getUsername()), repo, path, restore)
except librdiff.FileError, error:
return self.writeErrorPage(str(error))
page = self.startPage(parms["title"])
page = page + self.compileTemplate("dir_listing.html", **parms)
page = page + self.endPage()
return page
index.exposed = True
def getParmsForPage(self, userRoot, repo="", path="", restore=""):
repo = encodePath(repo)
path = encodePath(path)
# Build "parent directories" links
parentDirs = []
parentDirs.append({ "parentPath" : self.buildBrowseUrl(repo, "/", False), "parentDir" : repo.lstrip("/") })
parentDirPath = "/"
for parentDir in path.split("/"):
if parentDir:
parentDirPath = joinPaths(parentDirPath, parentDir)
parentDirs.append({ "parentPath" : self.buildBrowseUrl(repo, parentDirPath, False), "parentDir" : parentDir })
parentDirs[-1]["parentPath"] = "" # Clear link for last parent, so it doesn't show it as a link
# Set up warning about in-progress backups, if necessary
if librdiff.backupIsInProgressForRepo(joinPaths(userRoot, repo)):
backupWarning = "Warning: a backup is currently in progress to this location. The displayed data may be inconsistent."
else:
backupWarning = ""
restoreUrl = ""
viewUrl = ""
if restore == "T":
title = "Restore"
viewUrl = self.buildBrowseUrl(repo, path, False)
tempDates = librdiff.getDirRestoreDates(joinPaths(userRoot, repo), path)
tempDates.reverse() # sort latest first
restoreDates = []
for x in tempDates:
restoreDates.append({ "dateStr" : x.getDisplayString(),
"dirRestoreUrl" : self.buildRestoreUrl(repo, path, x) })
entries = []
else:
title = "Browse"
restoreUrl = self.buildBrowseUrl(repo, path, True)
restoreDates = []
# Get list of actual directory entries
fullRepoPath = joinPaths(userRoot, repo)
libEntries = librdiff.getDirEntries(fullRepoPath, path)
entries = []
for libEntry in libEntries:
entryLink = ""
if libEntry.isDir:
entryLink = self.buildBrowseUrl(repo, joinPaths(path, libEntry.name), False)
fileType = "folder"
size = " "
sizeinbytes = 0
changeDates = []
else:
entryLink = self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), libEntry.changeDates[-1])
fileType = "file"
entryChangeDates = libEntry.changeDates[:-1]
entryChangeDates.reverse()
size = rdw_helpers.formatFileSizeStr(libEntry.fileSize)
sizeinbytes = libEntry.fileSize
changeDates = [ { "changeDateUrl" : self.buildRestoreUrl(repo, joinPaths(path, libEntry.name), x),
"changeDateStr" : x.getDisplayString() } for x in entryChangeDates]
showRevisionsText = (len(changeDates) > 0) or libEntry.isDir
entries.append({ "filename" : libEntry.name,
"fileRestoreUrl" : entryLink,
"filetype" : fileType,
"exists" : libEntry.exists,
"date" : libEntry.changeDates[-1].getDisplayString(),
"dateinseconds" : libEntry.changeDates[-1].getLocalSeconds(),
"size" : size,
"sizeinbytes" : sizeinbytes,
"hasPrevRevisions" : len(changeDates) > 0,
"numPrevRevisions" : str(len(changeDates)),
"hasMultipleRevisions" : len(changeDates) > 1,
"showRevisionsText" : showRevisionsText,
"changeDates" : changeDates})
return { "title" : title, "files" : entries, "parentDirs" : parentDirs, "restoreUrl" : restoreUrl, "viewUrl" : viewUrl, "restoreDates" : restoreDates, "warning" : backupWarning }
class browsePageTest(page_main.pageTest, rdiffBrowsePage):
def getTemplateName(self):
return "browse_template.txt"
def getExpectedResultsName(self):
return "browse_results.txt"
def getParmsForTemplate(self, repoParentPath, repoName):
return self.getParmsForPage(repoParentPath, repoName)
rdiffweb-v0.6.5/rdiffWeb/page_error.py 0000664 0000000 0000000 00000002500 12205242615 0017723 0 ustar 00root root 0000000 0000000 # rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import rdw_helpers
class rdiffErrorPage:
''' Shows a very simple error message. Divorced
as much as possible from the rest of the system.'''
def __init__(self, error):
self.error = error
def index(self):
page = rdw_helpers.compileTemplate("page_start.html",
title="rdiffWeb - Error",
rssLink="",
rssTitle="")
page = page + self.error
page = page + rdw_helpers.compileTemplate("page_end.html")
return page
index.exposed = True
rdiffweb-v0.6.5/rdiffWeb/page_history.py 0000664 0000000 0000000 00000006457 12205242615 0020312 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from rdw_helpers import joinPaths
import rdw_helpers, page_main, librdiff
import os, urllib
class rdiffHistoryPage(page_main.rdiffPage):
def index(self, repo):
try:
self.validateUserPath(repo)
except rdw_helpers.accessDeniedError, error:
return self.writeErrorPage(str(error))
if not repo: return self.writeErrorPage("Backup location not specified.")
if not repo in self.getUserDB().getUserRepoPaths(self.getUsername()):
return self.writeErrorPage("Access is denied.")
parms = {}
try:
parms = self.getParmsForPage(joinPaths(self.getUserDB().getUserRoot(self.getUsername()), repo), repo)
except librdiff.FileError, error:
return self.writeErrorPage(error.getErrorString())
return self.startPage("Backup History") + self.compileTemplate("history.html", **parms) + self.endPage()
index.exposed = True
def getParmsForPage(self, repoPath, repoName):
rdiffHistory = librdiff.getBackupHistory(repoPath)
rdiffHistory.reverse()
entries = []
cumulativeSize = 0
if len(rdiffHistory) > 0: cumulativeSize = rdiffHistory[0].size
for historyItem in rdiffHistory:
fileSize = ""
incrementSize = ""
cumulativeSizeStr = ""
if not historyItem.inProgress:
fileSize = rdw_helpers.formatFileSizeStr(historyItem.size)
incrementSize = rdw_helpers.formatFileSizeStr(historyItem.incrementSize)
cumulativeSize += historyItem.incrementSize
cumulativeSizeStr = rdw_helpers.formatFileSizeStr(cumulativeSize)
entries.append({ "date" : historyItem.date.getDisplayString(),
"dateinseconds" : historyItem.date.getLocalSeconds(),
"inProgress" : historyItem.inProgress,
"errors" : historyItem.errors,
"cumulativesize" : cumulativeSizeStr,
"cumulativesizeinbytes" : cumulativeSize,
"size" : fileSize,
"sizeinbytes" : historyItem.size })
return {"title" : "Backup history for " + repoName, "history" : entries, "totalBackups" : len(rdiffHistory)}
class historyPageTest(page_main.pageTest, rdiffHistoryPage):
def getTemplateName(self):
return "history_template.txt"
def getExpectedResultsName(self):
return "history_results.txt"
def getParmsForTemplate(self, repoParentPath, repoName):
return self.getParmsForPage(rdw_helpers.joinPaths(repoParentPath, repoName), repoName)
rdiffweb-v0.6.5/rdiffWeb/page_locations.py 0000664 0000000 0000000 00000006513 12205242615 0020575 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import librdiff
import logging
import page_main
import rdw_helpers
class rdiffLocationsPage(page_main.rdiffPage):
''' Shows the locations page. Will show all available destination
backup directories. This is the root (/) page '''
def index(self):
page = self.startPage("Backup Locations")
page = page + self.compileTemplate("repo_listing.html", **self.getParmsForPage(self.getUserDB().getUserRoot(self.getUsername()), self.getUserDB().getUserRepoPaths(self.getUsername())))
page = page + self.endPage()
return page
index.exposed = True
def getParmsForPage(self, root, repos):
repoList = []
for reponame in repos:
try:
repoHistory = librdiff.getLastBackupHistoryEntry(rdw_helpers.joinPaths(root, reponame))
reposize = rdw_helpers.formatFileSizeStr(repoHistory.size)
reposizeinbytes = repoHistory.size
if repoHistory.inProgress:
reposize = "In Progress"
repoDate = repoHistory.date.getDisplayString()
repodateinseconds = repoHistory.date.getLocalSeconds()
failed = False
except librdiff.FileError:
logging.exception("Can't get reference on the last backup history for %s" % reponame)
reposize = "0"
reposizeinbytes = 0
repoDate = "Error"
repodateinseconds = 0
failed = True
repoList.append({ "reponame" : reponame,
"reposize" : reposize,
"reposizeinbytes" : reposizeinbytes,
"repodate" : repoDate,
"repodateinseconds" : repodateinseconds,
"repoBrowseUrl" : self.buildBrowseUrl(reponame, "/", False),
"repoHistoryUrl" : self.buildHistoryUrl(reponame),
'failed': failed})
self._sortLocations(repoList)
return { "title" : "browse", "repos" : repoList }
def _sortLocations(self, locations):
def compare(left, right):
if left['failed'] != right['failed']:
return cmp(left['failed'], right['failed'])
return cmp(left['reponame'], right['reponame'])
locations.sort(compare)
class locationsPageTest(page_main.pageTest, rdiffLocationsPage):
def getTemplateName(self):
return "locations_template.txt"
def getExpectedResultsName(self):
return "locations_results.txt"
def getParmsForTemplate(self, repoParentPath, repoName):
return self.getParmsForPage(repoParentPath, [repoName])
rdiffweb-v0.6.5/rdiffWeb/page_main.py 0000664 0000000 0000000 00000014614 12205242615 0017527 0 ustar 00root root 0000000 0000000 # rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import cherrypy
import urllib
import os.path
import db
import rdw_templating
import rdw_helpers
import rdw_config
class rdiffPage:
############################## HELPER FUNCTIONS ###################################
def buildBrowseUrl(self, repo, path, isRestoreView):
url = "/browse/?repo=" + rdw_helpers.encodeUrl(repo, "/") + "&path=" + rdw_helpers.encodeUrl(path, "/")
if isRestoreView:
url = url + "&restore=T"
return url
def buildRestoreUrl(self, repo, path, date):
return "/restore/?repo=" + rdw_helpers.encodeUrl(repo, "/") + "&path=" + rdw_helpers.encodeUrl(path, "/") + "&date=" + rdw_helpers.encodeUrl(date.getUrlString())
def buildHistoryUrl(self, repo):
return "/history/?repo=" + rdw_helpers.encodeUrl(repo, "/")
def buildLocationsUrl(self):
return "/"
def compileTemplate(self, templatePath, **kwargs):
return rdw_helpers.compileTemplate(templatePath, **kwargs)
def validateUserPath(self, path):
'''Takes a path relative to the user's root dir and validates that it is valid and within the user's root'''
path = rdw_helpers.joinPaths(self.getUserDB().getUserRoot(self.getUsername()), rdw_helpers.encodePath(path))
path = path.rstrip("/")
realPath = os.path.realpath(path)
if realPath != path:
raise rdw_helpers.accessDeniedError
# Make sure that the path starts with the user root
# This check should be accomplished by ensurePathValid, but adding for a sanity check
if realPath.find(rdw_helpers.encodePath(self.getUserDB().getUserRoot(self.getUsername()))) != 0:
raise rdw_helpers.accessDeniedError
def getUserDB(self):
if not hasattr(cherrypy.thread_data, 'db'):
cherrypy.thread_data.db = db.userDB().getUserDBModule()
return cherrypy.thread_data.db
########################## PAGE HELPER FUNCTIONS ##################################
def startPage(self, title, rssUrl="", rssTitle=""):
return self.compileTemplate("page_start.html", title=title, rssLink=rssUrl, rssTitle=rssTitle) + self.writeTopLinks()
def endPage(self):
return self.compileTemplate("page_end.html")
def writeTopLinks(self):
pages = [("/status/", "Status")]
if self.getUserDB().modificationsSupported():
pages.append(("/prefs", "Preferences"))
if self.getUserDB().userIsAdmin(self.getUsername()):
pages.append(("/admin", "Admin"))
pages.append(("/logout", "Logout"))
links = []
for page in pages:
(url, title) = page
links.append({"linkText" : title, "title": title, "linkUrl" : url})
return self.compileTemplate("nav_bar.html", topLinks=links)
def writeErrorPage(self, error):
page = self.startPage("Error")
page = page + self.compileTemplate("error.html", title="Error", error=error)
page = page + self.endPage()
return page
def writeMessagePage(self, title, message):
page = self.startPage(title)
page = page + message
page = page + self.endPage()
return page
########## SESSION INFORMATION #############
def checkAuthentication(self, username, password):
if self.getUserDB().areUserCredentialsValid(username, password):
cherrypy.session['username'] = username
return None
return "Invalid username or password."
def getUsername(self):
username = cherrypy.session['username']
return username
import unittest, shutil, tempfile, os.path
class pageTest(unittest.TestCase):
# The dirs containing source data for automated tests are set up in the following format:
# one folder for each test, named to describe the test
# one folder, called repo. This contains the sample rdiff-backup repository
# expected results for each of the page templates
# templates for each of the pages to test
def _getBackupTests(self):
tests = filter(lambda x: not x.startswith(".") and os.path.isdir(rdw_helpers.joinPaths(self.destRoot, x)), os.listdir(self.destRoot))
tests.sort()
return tests
def _getFileText(self, testName, templateName):
return open(rdw_helpers.joinPaths(self.destRoot, testName, templateName)).read()
def _copyDirWithoutSvn(self, src, dest):
names = filter(lambda x: x != ".svn", os.listdir(src))
os.makedirs(dest)
for name in names:
srcname = os.path.join(src, name)
destname = os.path.join(dest, name)
if os.path.isdir(srcname):
self._copyDirWithoutSvn(srcname, destname)
else:
shutil.copy2(srcname, destname)
def setUp(self):
self.destRoot = rdw_helpers.joinPaths(os.path.realpath(tempfile.gettempdir()), "rdiffWeb")
self.masterDirPath = os.path.realpath("tests")
self.tearDown()
# Copy and set up each test
self._copyDirWithoutSvn(self.masterDirPath, self.destRoot)
def tearDown(self):
if (os.access(self.destRoot, os.F_OK)):
rdw_helpers.removeDir(self.destRoot)
def testCompileTemplate(self):
for test in self._getBackupTests():
parms = self.getParmsForTemplate(rdw_helpers.joinPaths(self.destRoot, test), "repo")
#print parms
encounteredText = rdw_templating.templateParser().parseTemplate(self._getFileText("", self.getTemplateName()), **parms)
expectedText = self._getFileText(test, self.getExpectedResultsName())
encounteredText = encounteredText.replace('\n', '')
expectedText = expectedText.replace('\n', '')
self.assertEquals(encounteredText, expectedText)
assert encounteredText == expectedText, "Got:\n" + encounteredText + "\nExpected:\n" + expectedText + "\nEnd"
rdiffweb-v0.6.5/rdiffWeb/page_prefs.py 0000664 0000000 0000000 00000013032 12205242615 0017713 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from rdw_helpers import joinPaths
import rdw_helpers, page_main, librdiff
import os
import urllib
import rdw_spider_repos
import email_notification
class rdiffPreferencesPage(page_main.rdiffPage):
sampleEmail = 'joe@example.com'
def index(self, **parms):
if parms:
action = parms['form']
if action == 'setPassword':
return self._changePassword(parms['current'], parms['new'], parms['confirm'])
elif action == 'updateRepos':
return self._updateRepos()
elif action == 'setNotifications':
return self._setNotifications(parms)
elif action == 'setRestoreType':
return self._setRestoreType(parms['restoreType'])
else:
return self._getPrefsPage(errorMessage='Invalid setting.')
return self._getPrefsPage('', '')
index.exposed = True
def _changePassword(self, currentPassword, newPassword, confirmPassword):
if not self.getUserDB().modificationsSupported():
return self._getPrefsPage(errorMessage="Password changing is not supported with the active user database.")
if not self.getUserDB().areUserCredentialsValid(self.getUsername(), currentPassword):
return self._getPrefsPage(errorMessage="The 'Current Password' is invalid.")
if newPassword != confirmPassword:
return self._getPrefsPage(errorMessage="The passwords do not match.")
self.getUserDB().setUserPassword(self.getUsername(), newPassword)
return self._getPrefsPage(statusMessage="Password updated successfully.")
def _updateRepos(self):
rdw_spider_repos.findReposForUser(self.getUsername(), self.getUserDB())
return self._getPrefsPage(statusMessage="Successfully updated backup locations.")
def _setNotifications(self, parms):
if not self.getUserDB().modificationsSupported():
return self._getPrefsPage(errorMessage="Email notification is not supported with the active user database.")
repos = self.getUserDB().getUserRepoPaths(self.getUsername())
for parmName in parms.keys():
if parmName == "userEmail":
if parms[parmName] == self.sampleEmail:
parms[parmName] = ''
self.getUserDB().setUserEmail(self.getUsername(), parms[parmName])
if parmName.endswith("numDays"):
backupName = parmName[:-7]
if backupName in repos:
if parms[parmName] == "Don't notify":
maxDays = 0
else:
maxDays = int(parms[parmName][0])
self.getUserDB().setRepoMaxAge(self.getUsername(), backupName, maxDays)
return self._getPrefsPage(statusMessage="Successfully changed notification settings.")
def _setRestoreType(self, restoreType):
if not self.getUserDB().modificationsSupported():
return self.getPrefsPage(errorMessage="Setting the restore format is not supported with the active user database.")
if restoreType == 'zip' or restoreType == 'tgz':
self.getUserDB().setUseZipFormat(self.getUsername(), restoreType == 'zip')
else:
return self._getPrefsPage(errorMessage='Invalid restore format.')
return self._getPrefsPage(statusMessage="Successfully set restore format.")
def _getPrefsPage(self, errorMessage="", statusMessage=""):
title = "User Preferences"
email = self.getUserDB().getUserEmail(self.getUsername());
parms = {
"title" : title,
"error" : errorMessage,
"message" : statusMessage,
"userEmail" : email,
"notificationsEnabled" : False,
"backups" : [],
"useZipFormat": self.getUserDB().useZipFormat(self.getUsername()),
"sampleEmail": self.sampleEmail
}
if email_notification.emailNotifier().notificationsEnabled():
repos = self.getUserDB().getUserRepoPaths(self.getUsername())
backups = []
for repo in repos:
maxAge = self.getUserDB().getRepoMaxAge(self.getUsername(), repo)
notifyOptions = []
for i in range(0, 8):
notifyStr = "Don't notify"
if i == 1:
notifyStr = "1 day"
elif i > 1:
notifyStr = str(i) + " days"
selectedStr = ""
if i == maxAge:
selectedStr = "selected"
notifyOptions.append({ "optionStr": notifyStr, "selectedStr": selectedStr })
backups.append({ "backupName" : repo, "notifyOptions" : notifyOptions })
parms.update({ "notificationsEnabled" : True, "backups" : backups })
return self.startPage(title) + self.compileTemplate("user_prefs.html", **parms) + self.endPage()
rdiffweb-v0.6.5/rdiffWeb/page_restore.py 0000664 0000000 0000000 00000005255 12205242615 0020267 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from cherrypy.lib.static import serve_file, serve_download
import rdw_helpers, page_main, librdiff
import os
class autoDeleteDir:
def __init__(self, dirPath):
self.dirPath = dirPath
def __del__(self):
rdw_helpers.removeDir(self.dirPath)
class rdiffRestorePage(page_main.rdiffPage):
_cp_config = {"response.stream": True, "response.timeout": 3000 }
def index(self, repo, path, date):
try:
self.validateUserPath(rdw_helpers.joinPaths(repo, path))
except rdw_helpers.accessDeniedError, error:
return self.writeErrorPage(str(error))
if not repo: return self.writeErrorPage("Backup location not specified.")
if not repo in self.getUserDB().getUserRepoPaths(self.getUsername()):
return self.writeErrorPage("Access is denied.")
if librdiff.backupIsInProgressForRepo(rdw_helpers.joinPaths(self.getUserDB().getUserRoot(self.getUsername()), repo)):
return self.writeErrorPage("A backup is currently in progress to this location. Restores are disabled until this backup is complete.")
try:
restoreTime = rdw_helpers.rdwTime()
restoreTime.initFromString(date)
(path, file) = os.path.split(path)
if not file:
file = path
path = "/"
fullPath = rdw_helpers.joinPaths(self.getUserDB().getUserRoot(self.getUsername()), repo)
useZipFormat = self.getUserDB().useZipFormat(self.getUsername())
filePath = librdiff.restoreFileOrDir(fullPath, path, file, restoreTime, useZipFormat)
except librdiff.FileError, error:
return self.writeErrorPage(error.getErrorString())
except ValueError:
return self.writeErrorPage("Invalid date parameter.")
(directory, filename) = os.path.split(filePath)
filename = filename.replace("\"", "\\\"") # Escape quotes in filename
return serve_file(filePath, None, disposition="attachment", name=filename)
index.exposed = True
rdiffweb-v0.6.5/rdiffWeb/page_setup.py 0000664 0000000 0000000 00000011574 12205242615 0017745 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import cherrypy
import json
import os
import stat
import crypt
import page_main
import rdw_helpers
class rdiffSetupPage(page_main.rdiffPage):
"""Helps the user through initial rdiffWeb setup.
This page is displayed with rdiffWeb is not yet configured.
"""
@cherrypy.expose
def index(self):
page = rdw_helpers.compileTemplate("page_start.html", title='Set up rdiffWeb', rssLink='', rssTitle='')
rootEnabled = False
error = ""
try:
rootEnabled = self._rootAccountEnabled()
except KeyError:
error = "rdiffWeb setup must be run with root privileges."
page += rdw_helpers.compileTemplate("setup.html", rootEnabled=rootEnabled, error=error)
page += rdw_helpers.compileTemplate("page_end.html")
return page
@cherrypy.expose
def ajax(self):
postData = cherrypy.request.body.read()
request = json.JsonReader().read(postData)
print request
if not 'rootPassword' in request:
return json.JsonWriter().write({"error": "No password specified."})
try:
self._ensureConfigFileExists()
self._validatePassword(request['rootPassword'])
if 'adminUsername' in request:
self._setAdminUser(request['adminUsername'], request['adminPassword'], request['adminConfirmPassword'])
if 'adminRoot' in request:
self._setAdminRoot(request['adminUsername'], request['adminRoot'])
except ValueError, error:
return json.JsonWriter().write({"error": str(error)})
return json.JsonWriter().write({})
def _validatePassword(self, password):
if self._rootAccountEnabled():
# Check the root account
if (self._checkSystemPassword("root", password)):
return
else:
raise ValueError, "The root account has been disabled. Web-based setup is not supported."
# If the root account is disabled, check to see if another
# user set up the account, in which case their password is valid.
if password != "billfrank":
raise ValueError, "The password is invalid."
def _checkSystemPassword(self, username, password):
cryptedpasswd = self._getCryptedPassword(username)
if crypt.crypt(password, cryptedpasswd) != cryptedpasswd:
raise ValueError, "Invalid password."
def _setAdminUser(self, username, password, confirmPassword):
if not username:
raise ValueError, "A username was not specified."
if not password:
raise ValueError, "The administrative user must have a password."
if password != confirmPassword:
raise ValueError, "The passwords do not match."
self.getUserDB().addUser(username)
self.getUserDB().setUserPassword(username, password)
def _setAdminRoot(self, username, userRoot):
if not username:
raise ValueError, "A username was not specified."
if not userRoot:
raise ValueError, "A root directory was not specified."
if not os.path.exists(userRoot):
raise ValueError, "The specified directory does not exist."
self.getUserDB().setUserRoot(username, userRoot)
def _rootAccountEnabled(self):
cryptedpasswd = self._getCryptedPassword("root")
return cryptedpasswd != '!'
def _ensureConfigFileExists(self):
try:
if not os.path.exists("/etc/rdiffweb"):
os.mkdir("/etc/rdiffweb", stat.S_IRWXU)
if not os.path.exists("/etc/rdiffweb/rdw.conf"):
open("/etc/rdiffweb/rdw.conf", "a").close()
os.chmod("/etc/rdiffweb/rdw.conf", stat.S_IRWXU)
except OSError, error:
raise ValueError, str(error)
def _getCryptedPassword(self, username):
try:
import spwd
except ImportError:
return self._manualGetCryptedPassword(username)
else:
return spwd.getspnam(username)[1]
def _manualGetCryptedPassword(self, username):
pwlines = open("/etc/shadow").readlines()
for line in pwlines:
entryParts = line.split(":")
if len(entryParts) == 9 and entryParts[0] == username:
return entryParts[1]
rdiffweb-v0.6.5/rdiffWeb/page_status.py 0000664 0000000 0000000 00000015623 12205242615 0020127 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import page_main
import librdiff
import rdw_helpers
import cherrypy
class rdiffStatusPage(page_main.rdiffPage):
def index(self, failures=""):
userMessages = self._getRecentUserMessages(failures != "")
return self._compileStatusPageTemplate(True, userMessages, failures != "")
index.exposed = True
def entry(self, date="", repo=""):
# Validate date
try:
entryTime = rdw_helpers.rdwTime()
entryTime.initFromString(date)
except ValueError:
return self.writeErrorPage("Invalid date parameter.")
if not repo:
userMessages = self._getUserMessagesForDay(entryTime)
else:
# Validate repo parameter
if not repo in self.getUserDB().getUserRepoPaths(self.getUsername()):
return self.writeErrorPage("Access is denied.")
try:
self.validateUserPath(repo)
except rdw_helpers.accessDeniedError, error:
return self.writeErrorPage(str(error))
userMessages = self._getUserMessages([repo], False, True, entryTime, entryTime)
return self._compileStatusPageTemplate(False, userMessages, False)
entry.exposed = True
def feed(self, failures=""):
cherrypy.response.headers["Content-Type"] = "text/xml"
userMessages = self._getRecentUserMessages(failures != "")
statusUrl = self._buildAbsolutePageUrl(failures != "")
return self.compileTemplate("status.xml", username=self.getUsername(), link=statusUrl, messages=userMessages)
feed.exposed = True
def _compileStatusPageTemplate(self, isMainPage, messages, failuresOnly):
if isMainPage: title = "Backup Status"
else: title = "Backup Status Entry"
feedLink = ""
feedTitle = ""
if isMainPage:
feedLink = self._buildStatusFeedUrl(failuresOnly)
feedTitle = "Backup status for " + self.getUsername()
page = self.startPage("Backup Status", rssUrl=feedLink, rssTitle=feedTitle)
page = page + self.compileTemplate("status.html",
messages=messages,
feedLink=feedLink,
failuresOnly=failuresOnly,
title=title,
isEntry=not isMainPage)
return page + self.endPage()
def _buildAbsolutePageUrl(self, failuresOnly):
url = cherrypy.request.base + "/status/"
if failuresOnly:
url = url + "?failures=T"
return url
def _buildStatusFeedUrl(self, failuresOnly):
url = "/status/feed"
if failuresOnly:
url = url + "?failures=T"
return url
def _buildStatusEntryUrl(self, repo, date):
return "entry?repo=" + rdw_helpers.encodeUrl(repo) + "&date=" + rdw_helpers.encodeUrl(date.getUrlString())
def _getUserMessagesForDay(self, date):
userRepos = self.getUserDB().getUserRepoPaths(self.getUsername())
# Set the start and end time to be the start and end of the day, respectively, to get all entries for that day
startTime = rdw_helpers.rdwTime()
startTime.timeInSeconds = date.timeInSeconds
startTime.tzOffset = date.tzOffset
startTime.setTime(0, 0, 0)
endTime = rdw_helpers.rdwTime()
endTime.timeInSeconds = date.timeInSeconds
endTime.tzOffset = date.tzOffset
endTime.setTime(23, 59, 59)
return self._getUserMessages(userRepos, True, False, startTime, endTime)
def _getRecentUserMessages(self, failuresOnly):
userRepos = self.getUserDB().getUserRepoPaths(self.getUsername())
asOfDate = rdw_helpers.rdwTime()
asOfDate.initFromMidnightUTC(-5)
return self._getUserMessages(userRepos, not failuresOnly, True, asOfDate, None)
def _getUserMessages(self, repos, includeSuccess, includeFailure, earliestDate, latestDate):
userRoot = self.getUserDB().getUserRoot(self.getUsername())
repoErrors = []
allBackups = []
for repo in repos:
try:
backups = librdiff.getBackupHistoryForDateRange(rdw_helpers.joinPaths(userRoot, repo), earliestDate, latestDate);
allBackups += [{"repo": repo, "date": backup.date, "displayDate": backup.date.getDisplayString(),
"size": rdw_helpers.formatFileSizeStr(backup.size), "errors": backup.errors,
"repoLink" : self.buildBrowseUrl(repo, "/", False)} for backup in backups]
except librdiff.FileError, error:
repoErrors.append({"repo": repo, "error": error.getErrorString(), "repoLink" : self.buildBrowseUrl(repo, "/", False)})
allBackups.sort(lambda x, y: cmp(y["date"], x["date"]))
failedBackups = filter(lambda x: x["errors"], allBackups)
# group successful backups by day
successfulBackups = filter(lambda x: not x["errors"], allBackups)
if successfulBackups:
lastSuccessDate = successfulBackups[0]["date"]
successfulBackups = rdw_helpers.groupby(successfulBackups, lambda x: x["date"].getLocalDaysSinceEpoch())
userMessages = []
# generate failure messages
if includeFailure:
for job in failedBackups:
date = job["date"]
job.update({"isSuccess": False, "date": date, "dateString": date.getDisplayString(), "pubDate": date.getRSSPubDateString(),
"link": self._buildStatusEntryUrl(job["repo"], date), "repoErrors": [], "backups": [], "repo": job["repo"]})
userMessages.append(job)
# generate success messages (publish date is most recent backup date)
if includeSuccess:
for day in successfulBackups.keys():
date = successfulBackups[day][0]["date"]
# include repository errors in most recent entry
if date == lastSuccessDate: repoErrorsForMsg = repoErrors
else: repoErrorsForMsg = []
userMessages.append({"isSuccess": 1, "date": date, "dateString": date.getDateDisplayString(), "pubDate": date.getRSSPubDateString(),
"link": self._buildStatusEntryUrl("", date), "repoErrors": repoErrorsForMsg, "backups":successfulBackups[day]})
# sort messages by date
userMessages.sort(lambda x, y: cmp(y["date"], x["date"]))
return userMessages
rdiffweb-v0.6.5/rdiffWeb/rdw_config.py 0000775 0000000 0000000 00000010770 12205242615 0017732 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
class SettingsError:
def __str__(self):
return "Invalid configuration file syntax"
class ParameterError:
def __str__(self):
return "Invalid parameters"
def getConfigFile():
settingsFiles = ["rdw.conf", "/etc/rdiffweb/rdw.conf" ] # TODO: there *has* to be a better way to get the /etc config file path...
for settingsFile in settingsFiles:
if os.access(settingsFile, os.F_OK):
return settingsFile
return ""
def getDatabasePath():
if os.access("/etc/rdiffweb/rdw.conf", os.F_OK):
return "/etc/rdiffweb/rdw.db"
return "rdw.db"
import os, re
def getConfigSetting(settingName, settingsFile=None):
if ('=' in settingName): raise ParameterError
if settingsFile == None:
settingsFile = getConfigFile()
if (not os.access(settingsFile, os.F_OK)): return ""
settingsStrings = open(settingsFile, "r").readlines()
for setting in settingsStrings:
setting = re.compile("(.*)#.*").sub(r'\1', setting)
setting = setting.rstrip()
setting = setting.lstrip()
if not setting: continue
if not '=' in setting:
raise SettingsError
splitSetting = setting.split('=')
if not len(splitSetting) == 2:
raise SettingsError
if splitSetting[0].lower() == settingName.lower(): # Lower-case both vars for case-insensitive compare
return splitSetting[1]
return ""
##################### Unit Tests #########################
import unittest
class configFileTest(unittest.TestCase):
"""Unit tests for the getConfigSetting() function"""
goodConfigText = """ #This=is a comment
SpacesValue=is a setting with spaces
spaces setting=withspaces
CommentInValue=Value#this is a comment
NoValue=#This is a setting with no value
"""
badConfigTexts = ['This#doesnt have an equals', 'This=more=than one equals']
configFilePath = "/tmp/rdw_config.conf"
def writeGoodFile(self):
file = open(self.configFilePath, "w")
file.write(self.goodConfigText)
file.close()
def writeBadFile(self, badSettingNum):
self.writeGoodFile()
file = open(self.configFilePath, "w")
file.write(self.badConfigTexts[badSettingNum])
file.close()
def tearDown(self):
if (os.access(self.configFilePath, os.F_OK)):
os.remove(self.configFilePath)
def testBadParms(self):
value = getConfigSetting("setting", "/tmp/rdw_bogus.conf")
assert(value == "")
self.writeGoodFile()
try:
getConfigSetting("setting=", "/tmp/rdw_config.conf")
except ParameterError: pass
else: assert(False)
def testSpacesInValue(self):
self.writeGoodFile()
assert(getConfigSetting("SpacesValue", "/tmp/rdw_config.conf") == "is a setting with spaces")
def testSpacesInSetting(self):
self.writeGoodFile()
assert(getConfigSetting("spaces setting", "/tmp/rdw_config.conf") == "withspaces")
def testCommentInValue(self):
self.writeGoodFile()
assert(getConfigSetting("CommentInValue", "/tmp/rdw_config.conf") == "Value")
def testEmptyValue(self):
self.writeGoodFile()
assert(getConfigSetting("NoValue", "/tmp/rdw_config.conf") == "")
def testCaseInsensitivity(self):
self.writeGoodFile()
assert(getConfigSetting("commentinvalue", "/tmp/rdw_config.conf") == "Value")
def testMissingSetting(self):
self.writeGoodFile()
assert(getConfigSetting("SettingThatDoesntExist", "/tmp/rdw_config.conf") == "")
def testBadFile(self):
self.writeBadFile(0)
try:
getConfigSetting("SpacesValue", "/tmp/rdw_config.conf")
except SettingsError: pass
else: assert(False)
self.writeBadFile(1)
try:
getConfigSetting("SpacesValue", "/tmp/rdw_config.conf")
except SettingsError: pass
else: assert(False)
rdiffweb-v0.6.5/rdiffWeb/rdw_helpers.py 0000775 0000000 0000000 00000034360 12205242615 0020130 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import calendar
import datetime
import os
import re
import time
import urllib
import zipfile
import tarfile
import subprocess
import rdw_templating
def encodePath(path):
if isinstance(path, unicode):
return path.encode('utf-8')
return path
def joinPaths(parentPath, *args):
parentPath = encodePath(parentPath)
args = [x.lstrip("/") for x in args]
return os.path.join(parentPath, *args)
def getStaticRootPath():
return os.path.abspath(os.path.dirname(__file__))
class accessDeniedError:
def __str__(self):
return "Access is denied."
def encodeUrl(url, safeChars=""):
if not url: return url
url = encodePath(url)
return urllib.quote_plus(url, safeChars)
def decodeUrl(encodedUrl):
if not encodedUrl: return encodedUrl
return urllib.unquote_plus(encodedUrl)
def encodeText(text):
if not text: return text
text = text.replace("&", "&")
text = text.replace("<", "<")
text = text.replace(">", ">")
text = text.replace("\"", """)
return text
def removeDir(dir):
for root, dirs, files in os.walk(dir, topdown=False):
for name in files:
filePath = os.path.join(root, name)
if os.path.islink(filePath):
os.unlink(filePath)
else:
os.remove(filePath)
for name in dirs:
dirPath = os.path.join(root, name)
if os.path.islink(dirPath):
os.unlink(dirPath)
else:
os.rmdir(dirPath)
os.rmdir(dir)
def formatNumStr(num, maxDecimals):
numStr = "%.*f" % (maxDecimals, num)
def replaceFunc(match):
if match.group(1):
return "." + match.group(1)
return ""
return re.compile("\.([^0]*)[0]+$").sub(replaceFunc, numStr)
def formatFileSizeStr(filesize):
if filesize == 0: return "0 bytes"
sizeNames = [(1024 * 1024 * 1024 * 1024, "TB"), (1024 * 1024 * 1024, "GB"), (1024 * 1024, "MB"), (1024, "KB"), (1, "bytes")]
for (size, name) in sizeNames:
if 1.0 * filesize / size >= 1.0:
return formatNumStr(1.0 * filesize / size, 2) + " " + name
(filesize, name) = sizeNames[-1]
return formatNumStr(1.0 * filesize / size, 2) + " " + name
def compileTemplate(templatePath, **kwargs):
(packageDir, ignored) = os.path.split(__file__)
templateText = open(joinPaths(packageDir, "templates", templatePath), "r").read()
return rdw_templating.templateParser().parseTemplate(templateText, **kwargs)
class rdwTime:
"""Time information has two components: the local time, stored in GMT as seconds since Epoch,
and the timezone, stored as a seconds offset. Since the server may not be in the same timezone
as the user, we cannot rely on the built-in localtime() functions, but look at the rdiff-backup string
for timezone information. As a general rule, we always display the "local" time, but pass the timezone
information on to rdiff-backup, so it can restore to the correct state"""
def __init__(self):
self.timeInSeconds = 0
self.tzOffset = 0
def initFromCurrentUTC(self):
self.timeInSeconds = time.time()
self.tzOffset = 0
def initFromMidnightUTC(self, daysFromToday):
self.timeInSeconds = time.time()
self.timeInSeconds -= self.timeInSeconds % (24 * 60 * 60)
self.timeInSeconds += daysFromToday * 24 * 60 * 60
self.tzOffset = 0
def initFromString(self, timeString):
try:
date, daytime = timeString[:19].split("T")
year, month, day = map(int, date.split("-"))
hour, minute, second = map(int, daytime.split(":"))
assert 1900 < year < 2100, year
assert 1 <= month <= 12
assert 1 <= day <= 31
assert 0 <= hour <= 23
assert 0 <= minute <= 59
assert 0 <= second <= 61 # leap seconds
timetuple = (year, month, day, hour, minute, second, -1, -1, 0)
self.timeInSeconds = calendar.timegm(timetuple)
self.tzOffset = self._tzdtoseconds(timeString[19:])
self.getTimeZoneString() # to get assertions there
except (TypeError, ValueError, AssertionError):
raise ValueError, timeString
def getLocalDaysSinceEpoch(self):
return self.getLocalSeconds() // (24 * 60 * 60)
def getDaysSinceEpoch(self):
return self.getSeconds() // (24 * 60 * 60)
def getLocalSeconds(self):
return self.timeInSeconds
def getSeconds(self):
return self.timeInSeconds - self.tzOffset
def getDateDisplayString(self):
return time.strftime("%Y-%m-%d", time.gmtime(self.timeInSeconds))
def getDisplayString(self):
return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(self.getLocalSeconds()))
def getUrlString(self):
return time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(self.getLocalSeconds())) + self.getTimeZoneString()
def getUrlStringNoTZ(self):
return time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(self.getSeconds())) + "Z"
def getRSSPubDateString(self):
tzinfo = self._getTimeZoneDisplayInfo()
timeZone = tzinfo["plusMinus"] + tzinfo["hours"] + tzinfo["minutes"]
return time.strftime("%a, %d %b %Y %H:%M:%S ", time.gmtime(self.getLocalSeconds())) + timeZone
def getTimeZoneString(self):
if self.tzOffset:
tzinfo = self._getTimeZoneDisplayInfo()
return tzinfo["plusMinus"] + tzinfo["hours"] + ":" + tzinfo["minutes"]
else:
return "Z"
def setTime(self, hour, minute, second):
year = time.gmtime(self.timeInSeconds)[0]
month = time.gmtime(self.timeInSeconds)[1]
day = time.gmtime(self.timeInSeconds)[2]
self.timeInSeconds = calendar.timegm((year, month, day, hour, minute, second, -1, -1, 0))
def _getTimeZoneDisplayInfo(self):
hours, minutes = divmod(abs(self.tzOffset) / 60, 60)
assert 0 <= hours <= 23
assert 0 <= minutes <= 59
if self.tzOffset > 0:
plusMinus = "+"
else:
plusMinus = "-"
return {"plusMinus": plusMinus, "hours": "%02d" % hours, "minutes": "%02d" % minutes}
def _tzdtoseconds(self, tzd):
"""Given w3 compliant TZD, converts it to number of seconds from UTC"""
if tzd == "Z": return 0
assert len(tzd) == 6 # only accept forms like +08:00 for now
assert (tzd[0] == "-" or tzd[0] == "+") and tzd[3] == ":"
if tzd[0] == "+":
plusMinus = 1
else:
plusMinus = -1
return plusMinus * 60 * (60 * int(tzd[1:3]) + int(tzd[4:]))
def __cmp__(self, other):
return cmp(self.getSeconds(), other.getSeconds())
# Taken from ASPN: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259173
class groupby(dict):
def __init__(self, seq, key=lambda x:x):
for value in seq:
k = key(value)
self.setdefault(k, []).append(value)
__iter__ = dict.iteritems
# Taken from ASPN: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731
def daemonize():
"""Detach a process from the controlling terminal and run it in the
background as a daemon. """
if (hasattr(os, "devnull")):
REDIRECT_TO = os.devnull
else:
REDIRECT_TO = "/dev/null"
MAXFD = 1024
UMASK = 0
try:
pid = os.fork()
except OSError, e:
raise Exception, "%s [%d]" % (e.strerror, e.errno)
if (pid == 0): # The first child.
os.setsid()
try:
pid = os.fork() # Fork a second child.
except OSError, e:
raise Exception, "%s [%d]" % (e.strerror, e.errno)
if (pid == 0): # The second child.
os.umask(UMASK)
else:
os._exit(0) # Exit parent (the first child) of the second child.
else:
os._exit(0) # Exit parent of the first child.
# Redirecting output to /dev/null fails when called from a script, for some reason...
# import resource # Resource usage information.
# maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
# if (maxfd == resource.RLIM_INFINITY):
# maxfd = MAXFD
# for fd in range(0, maxfd):
# try:
# os.close(fd)
# except OSError: # ERROR, fd wasn't open to begin with (ignored)
# pass
# os.open(REDIRECT_TO, os.O_RDWR) # standard input (0)
# os.dup2(0, 1) # standard output (1)
# os.dup2(0, 2) # standard error (2)
return(0)
def execute(command, *args):
parms = [command]
parms.extend(args)
execution = subprocess.Popen(parms, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
results = {}
results['exitCode'] = execution.wait()
(results['stdout'], results['stderr']) = execution.communicate()
return results
import unittest
class helpersTest(unittest.TestCase):
def testJoinPaths(self):
assert(joinPaths("/", "/test", "/temp.txt") == "/test/temp.txt")
assert(joinPaths("/", "test", "/temp.txt") == "/test/temp.txt")
assert(joinPaths("/", "/test", "temp.txt") == "/test/temp.txt")
assert(joinPaths("/", "//test", "/temp.txt") == "/test/temp.txt")
assert(joinPaths("/", "", "/temp.txt") == "/temp.txt")
assert(joinPaths("test", "", "/temp.txt") == "test/temp.txt")
def testRdwTime(self):
# Test initialization
myTime = rdwTime()
assert myTime.getSeconds() == 0
goodTimeString = "2005-12-25T23:34:15-05:00"
goodTimeStringNoTZ = "2005-12-26T04:34:15Z"
myTime.initFromString(goodTimeString)
myTimeNoTZ = rdwTime()
myTimeNoTZ.initFromString(goodTimeStringNoTZ)
assert myTimeNoTZ.getSeconds() == myTimeNoTZ.getLocalSeconds()
assert myTime.getSeconds() == myTimeNoTZ.getSeconds()
# Test correct load and retrieval
assert myTime.getUrlString() == goodTimeString
assert myTime.getUrlStringNoTZ() == goodTimeStringNoTZ
assert myTime.getDisplayString() == "2005-12-25 23:34:15"
assert myTime.getRSSPubDateString() == "Sun, 25 Dec 2005 23:34:15 -0500"
assert myTime.getDateDisplayString() == "2005-12-25"
assert myTime.getLocalSeconds() < myTime.getSeconds()
assert myTime.getLocalSeconds() == 1135571655 - 5 * 60 * 60
assert myTime.getSeconds() == 1135571655
assert myTime.getLocalDaysSinceEpoch() <= myTime.getDaysSinceEpoch()
assert myTime.getLocalDaysSinceEpoch() == 13142
assert myTime.getDaysSinceEpoch() == 13143
goodTimeString = "2005-12-25T23:04:15-05:30"
myTime.initFromString(goodTimeString)
assert myTime.getUrlString() == goodTimeString
assert myTime.getUrlStringNoTZ() == goodTimeStringNoTZ
goodTimeString = "2005-12-26T09:34:15+05:00"
myTime.initFromString(goodTimeString)
assert myTime.getUrlString() == goodTimeString
assert myTime.getUrlStringNoTZ() == goodTimeStringNoTZ
goodTimeString = "2005-12-26T10:04:15+05:30"
myTime.initFromString(goodTimeString)
assert myTime.getUrlString() == goodTimeString
assert myTime.getUrlStringNoTZ() == goodTimeStringNoTZ
# Test boundaries on days since epoch
myTime.initFromString("2005-12-31T18:59:59-05:00")
assert myTime.getUrlStringNoTZ() == "2005-12-31T23:59:59Z"
assert myTime.getDaysSinceEpoch() == 13148
assert myTime.getLocalDaysSinceEpoch() == 13148
myTime.initFromString("2005-12-31T19:00:00-05:00")
assert myTime.getUrlStringNoTZ() == "2006-01-01T00:00:00Z"
assert myTime.getDaysSinceEpoch() == 13149
assert myTime.getLocalDaysSinceEpoch() == 13148
# Test UTC
myTime.initFromCurrentUTC()
assert myTime.getSeconds() == myTime.getLocalSeconds()
todayAsString = myTime.getDateDisplayString()
# Test midnight UTC
myTime.initFromMidnightUTC(0)
assert myTime.getSeconds() == myTime.getLocalSeconds()
assert myTime.getUrlString().find("T00:00:00Z") != -1
assert myTime.getDateDisplayString() == todayAsString
myTime.initFromCurrentUTC()
midnightTime = rdwTime()
midnightTime.initFromMidnightUTC(0)
assert myTime.getSeconds() != midnightTime.getSeconds()
myTime.setTime(0, 0, 0)
assert myTime.getSeconds() == midnightTime.getSeconds()
# Make sure it rejects bad strings with the appropriate exceptions
badTimeStrings = ["2005-12X25T23:34:15-05:00", "20005-12-25T23:34:15-05:00", "2005-12-25", "2005-12-25 23:34:15"]
for badTime in badTimeStrings:
try:
myTime.initFromString(badTime)
except ValueError:
pass
else:
assert False
def testFormatSizeStr(self):
# Test simple values
assert(formatFileSizeStr(1024) == "1 KB")
assert(formatFileSizeStr(1024 * 1024 * 1024) == "1 GB")
assert(formatFileSizeStr(1024 * 1024 * 1024 * 1024) == "1 TB")
assert(formatFileSizeStr(0) == "0 bytes")
assert(formatFileSizeStr(980) == "980 bytes")
assert(formatFileSizeStr(1024 * 980) == "980 KB")
assert(formatFileSizeStr(1024 * 1024 * 1024 * 1.2) == "1.2 GB")
assert(formatFileSizeStr(1024 * 1024 * 1024 * 1.243) == "1.24 GB") # Round to one decimal
assert(formatFileSizeStr(1024 * 1024 * 1024 * 1024 * 120) == "120 TB") # Round to one decimal
def testGroupBy(self):
numbers = [1, 2, 3, 4, 5, 6, 0, 0, 5, 5]
groupedNumbers = groupby(numbers)
assert groupedNumbers == {0: [0, 0], 1: [1], 2: [2], 3: [3], 4: [4], 5: [5, 5, 5], 6: [6]}
projects = [{"name": "rdiffWeb", "language": "python"}, {"name": "CherryPy", "language": "python"},
{"name": "librsync", "language": "C"}]
projectsByLanguage = groupby(projects, lambda x: x["language"])
assert projectsByLanguage == {"C": [{"name": "librsync", "language": "C"}],
"python": [{"name": "rdiffWeb", "language": "python"}, {"name": "CherryPy", "language": "python"}]}
def testEncodeText(self):
assert encodeText("<>&\"") == "<>&""
rdiffweb-v0.6.5/rdiffWeb/rdw_spider_repos.py 0000775 0000000 0000000 00000004722 12205242615 0021163 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import os
import db
import rdw_helpers
import librdiff
import rdw_config
import time
import threading
# Returns pid of started process, or 0 if no process was started
def startRepoSpiderThread(killEvent):
newThread = spiderReposThread(killEvent)
newThread.start()
class spiderReposThread(threading.Thread):
def __init__(self, killEvent):
self.killEvent = killEvent
threading.Thread.__init__(self)
def run(self):
spiderInterval = rdw_config.getConfigSetting("autoUpdateRepos")
if spiderInterval:
spiderInterval = int(spiderInterval)
while True:
findReposForAllUsers()
self.killEvent.wait(60 * spiderInterval)
if self.killEvent.isSet():
return
def _findRdiffRepos(dirToSearch, outRepoPaths):
dirEntries = os.listdir(dirToSearch)
if librdiff.RDIFF_BACKUP_DATA in dirEntries:
outRepoPaths.append(dirToSearch)
return
for entry in dirEntries:
entryPath = rdw_helpers.joinPaths(dirToSearch, entry)
if os.path.isdir(entryPath) and not os.path.islink(entryPath):
_findRdiffRepos(entryPath, outRepoPaths)
def findReposForUser(user, userDBModule):
userRoot = userDBModule.getUserRoot(user)
repoPaths = []
_findRdiffRepos(userRoot, repoPaths)
def stripRoot(path):
if not path[len(userRoot):]:
return "/"
return path[len(userRoot):]
repoPaths = map(stripRoot, repoPaths)
userDBModule.setUserRepos(user, repoPaths)
def findReposForAllUsers():
userDBModule = db.userDB().getUserDBModule()
if not userDBModule.modificationsSupported(): return
users = userDBModule.getUserList()
for user in users:
findReposForUser(user, userDBModule)
rdiffweb-v0.6.5/rdiffWeb/rdw_templating.py 0000775 0000000 0000000 00000024213 12205242615 0020626 0 ustar 00root root 0000000 0000000 #!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import rdw_helpers
import re
class templateError(Exception):
pass
class templateDataError(templateError):
pass
class templateDefinitionError(templateError):
pass
class templateParser:
def __init__(self):
self.deleteIfRegexes = [re.compile(r"(.*?)", re.S),
re.compile(r"StartDeleteIf:(.*?)-(.*?)EndDeleteIf:\1-", re.S)]
self.includeIfRegexes = [re.compile(r"(.*?)", re.S),
re.compile(r"StartIncludeIf:(.*?)-(.*?)EndIncludeIf:\1-", re.S)]
self.replacements = []
def parseTemplate(self, templateString, **kwargs):
self.replacements.append(kwargs)
# Remove any Delete sections
templateString = re.compile(r".*?", re.S).sub("", templateString)
# Handle repeating templates first
regEx = re.compile(r"(.*?)", re.S)
workingText = regEx.sub(self._handleListMatch, templateString)
if "
^linkText$
^linkText$"""
parmsDict = {"linkUrl":"http://www.google.com", "linkText":"Google"}
parser = templateParser()
parseResult = parser.parseTemplate(template, **parmsDict)
assert(parseResult == "Google")
def testConditionalInclude(self):
template = """text"""
assert(templateParser().parseTemplate(template, include=True) == "text")
assert(templateParser().parseTemplate(template, include=False) == "")
template = """text"""
self.assertEquals(templateParser().parseTemplate(template, include=False), "text")
assert(templateParser().parseTemplate(template, include=True) == "")
def testAttributeStyleDirectives(self):
template = """StartIncludeIf:include- text EndIncludeIf:include-"""
assert(templateParser().parseTemplate(template, include=True) == " text ")
assert(templateParser().parseTemplate(template, include=False) == "")
template = """StartDeleteIf:include- text EndDeleteIf:include-"""
self.assertEquals(templateParser().parseTemplate(template, include=False), " text ")
assert(templateParser().parseTemplate(template, include=True) == "")
def testNestedIncludes(self):
template = """should be deletedtext"""
self.assertEquals(templateParser().parseTemplate(template, include=True, delete=True), "text")
self.assertEquals(templateParser().parseTemplate(template, include=False, delete=True), "")
def testGoodListReplace(self):
template = """
^linkText$ |
"""
linksArray = [{"linkUrl":"http://www.google.com", "linkText":"Google"}]
linksArray.append({"linkUrl":"http://www.python.org", "linkText":"Python"})
linksArray.append({"linkUrl":"http://www.python.org", "linkText":"$$Lots of money^^"})
parser = templateParser()
parseResult = parser.parseTemplate(template, links=linksArray)
expectedResult = """Google |
Python |
$$Lots of money^^ | """
assert(parseResult == expectedResult)
linksArray = [{"linkUrl":"http://www.google.com", "linkText":"Google"}]
parseResult = parser.parseTemplate(template, links=linksArray)
expectedResult = """Google | """
assert(parseResult == expectedResult)
def testRecursiveListReplace(self):
template = """>^char$< | """
innerData = { "chars" : [{"char":"char1"}, {"char":"char2"}]}
linksArray = [ innerData ]
parser = templateParser()
parseResult = parser.parseTemplate(template, links=linksArray)
expectedResult = """>char1<>char2< | """
assert(parseResult == expectedResult)
def testNonGreedyReplace(self):
template = """fooshould see mebar"""
parmsDict = {"linkUrl":"http://www.google.com", "linkText":"Google"}
parser = templateParser()
parseResult = parser.parseTemplate(template, **parmsDict)
assert(parseResult == "should see me")
def testBadListNameReplace(self):
template = """^linkText$ | """
linksArray = [{"linkUrl":"http://www.google.com", "linkText":"Google"}]
parmsDict = {"bogus":linksArray}
try: templateParser().parseTemplate(template, **parmsDict)
except templateDataError: pass
else: assert(False)
def testBadListContentsReplace(self):
template = """^linkText$ | """
linksArray = [{"linkText":"Google"}]
parmsDict = {"links":linksArray}
try: templateParser().parseTemplate(template, **parmsDict)
except templateDataError: pass
else: assert(False)
def testBadTemplateReplace(self):
template = "^linkText$ | "
try: templateParser().parseTemplate(template)
except templateError: pass
else: assert(False)
rdiffweb-v0.6.5/rdiffWeb/static/ 0000775 0000000 0000000 00000000000 12205242615 0016516 5 ustar 00root root 0000000 0000000 rdiffweb-v0.6.5/rdiffWeb/static/images/ 0000775 0000000 0000000 00000000000 12205242615 0017763 5 ustar 00root root 0000000 0000000 rdiffweb-v0.6.5/rdiffWeb/static/images/close.png 0000664 0000000 0000000 00000003714 12205242615 0021603 0 ustar 00root root 0000000 0000000 ‰PNG
IHDR $ $ á ˜˜ tEXtSoftware Adobe ImageReadyqÉe<