Index: branches/stable/COPYING
===================================================================
--- branches/stable/COPYING	(revision 445)
+++ branches/stable/COPYING	(revision 445)
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ 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.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    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 <http://www.gnu.org/licenses/>.
+
+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:
+
+    <program>  Copyright (C) <year>  <name of author>
+    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
+<http://www.gnu.org/licenses/>.
+
+  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
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
Index: branches/stable/INSTALL
===================================================================
--- branches/stable/INSTALL	(revision 445)
+++ branches/stable/INSTALL	(revision 445)
@@ -0,0 +1,129 @@
+$Id$
+
+Requirements
+============
+
+- Any CGI-capable web server that can execute arbitrary files or 
+  files with administrator-defineable extensions
+- PostgreSQL >= 7.4.  It should be possible to (fairly) trivially patch 
+  the code for any other DBMS that supports:
+  - an IP address/CIDR netblock data type
+  - higher/greater, lower/less than, contains, and is-contained-by 
+    operators
+- Perl >= 5.6
+  - Standard modules:
+    These should be included in any base Perl install
+    - File::Path
+    - CGI::Carp
+    - POSIX
+    - Sys::Syslog
+  - Extra modules:
+    - NetAddr::IP >= 4.x.  3.x may work, however 4.x has been out for 
+      more than 4 years.
+    - DBI
+    - DBD::Pg
+    - Sys::SigAction.  This isn't strictly required;  it's used in an 
+      example hook for validating customer IDs against an external 
+      database.  It could arguably be replaced with sigaction() from the 
+      POSIX module when using Perl >= 5.8.2.  See eg Sys::SigAction on 
+      CPAN (http://search.cpan.org/~lbaxter/Sys-SigAction-0.11/lib/Sys/SigAction.pm) 
+      for some thoughts on the gritty details.
+
+Installing the IPDB
+===================
+
+1) Untar in a convenient location.  You should be able to simply use the 
+unpacked tarball as-is, or you can run "make install" to install files 
+in /usr/local/lib/ipdb-#VERSION#, with configuration modules in 
+/usr/local/etc/ipdb-#VERSION#.
+
+The Makefile supports substitution on most standard 
+GNU/FHS-ish paths, so you could also run:
+
+  make install prefix=/opt
+
+to install it under /opt.
+
+The Makefile also supports DESTDIR for packaging, so you can use:
+
+  make install libdir=/usr/lib sysconfdir=/etc DESTDIR=/tmp/ipdbpkgroot
+
+to install for packaging under /tmp/ipdbpkgroot with the core scripts 
+and HTML packaged under /usr/lib/ipdb-#VERSION#, and the configuration 
+modules packaged under /etc/ipdb-#VERSION#.
+
+2) Configuration:  These module files will either be in the cgi-bin/ 
+directory from the unpacked tarball, or /usr/local/etc/ipdb-#VERSION# 
+if installed with 'make install'.
+  a) Edit MyIPDB.pm:  you need to set the database DSN and 
+    company info.  You should probably also set the syslog facility and 
+    default custid.
+  b) Edit CustIDCK.pm as needed to validate customer IDs.
+
+4) Create the database, and the inital tables using cgi-bin/ipdb.psql.
+
+5) Configure your webserver to call the IPDB scripts at an appropriate 
+web path.  A webroot pointing to the HTML files (first level under 
+the ipdb-#VERSION#/ tarball directory, or /usr/local/lib/ipdb-#VERSION#) 
+with a symlink or alias for ip/ -> . should work fine;  a server alias 
+under an existing virtual host should work as well.
+
+Note that all URLs referenced internally currently assume they will be 
+presented at http://host/ip/;  you cannot put the IPDB at 
+http://host/noc/misc/ipdb/.
+
+The directory containing the HTML and scripts must have at least the 
+following Apache directives (or other server equivalent) set:
+
+  Options ExecCGI IncludesNoEXEC FollowSymlinks
+
+6) User lists can be maintained two basic ways:
+
+  a) Use the built-in user manager to add and remove users.  This 
+    requires mod_auth_pgsql, configured with read/write access to the 
+    IPDB users table.  A default user admin, password admin, is created 
+    in step 4 above - make sure to create a new user as an admin, and 
+    remove the default user (or at least change its password).
+
+  b) Maintain an external .htpasswd file of your own, configured and 
+    maintained however you like.  In this case the access-pwd-update.pl 
+    script should edited to match the .htpasswd filename/path and should 
+    be called from cron to make sure new users get added to the 
+    database, and old ones get deleted.  This extra maintenance of user 
+    lists is necessary to support the access controls, which are stored 
+    in the database.
+
+You will have to either temporarily create a user "admin", so that user
+can grant other users priviledges, or run the following on the database:
+
+  UPDATE users SET acl='bacdsA' WHERE username='newadminuser';
+
+Replace 'newadminuser' as appropriate.
+
+If you don't do this, nobody will be able to make any changes;  
+access-pwd-update.pl only grants minimal read access to new users.
+
+7) (optional) Pick a log facility by setting $IPDB::syslog_facility in 
+MyIPDB.pm, and tweak your syslog configuration to direct IPDB logging 
+to a custom log.  Most logging is at the level of "info" or "warn".  
+Full changes are not logged.  Logging verbosity isn't very high, so it 
+may be acceptable to leave the log stream at the defaults.
+
+---
+
+Basic installation should now be complete!  Log in as an admin user, 
+add your ARIN, RIPE, LACNIC, AfriNIC, or APNIC allocations and start 
+documenting your netblock usage.
+
+If you want to export rWHOIS data, see http://www.unixadmin.cc/rwhois/ 
+for a place to start on setting up an rWHOIS server.  Note that 
+db2rwhois.pl creates and maintains the net-<cidr> trees, all you have 
+to do is configure the daemon itself.  Schedule runs of 
+cgi-bin/extras/db2rwhois.pl followed by rwhois_indexer (every hour 
+should be plenty often).  You'll need to fill in correct organization 
+contact info in MyIPDB.pm.
+
+If you're just running from the unpacked tarball directory, you may need 
+to create symlinks in cgi-bin/extras/ for IPDB.pm and MyIPDB.pm, 
+pointing to ../IPDB.pm and ../MyIPDB.pm respectively.  Otherwise 
+db2rwhois.pl won't be able to find these modules.
Index: branches/stable/Makefile
===================================================================
--- branches/stable/Makefile	(revision 445)
+++ branches/stable/Makefile	(revision 445)
@@ -0,0 +1,110 @@
+# $Id$
+# IPDB makefile
+
+PKGNAME=ipdb
+VERSION=2.6
+RELEASE=1
+
+# Include some boilerplate Gnu makefile definitions.
+prefix = /usr/local
+
+exec_prefix = ${prefix}
+bindir = ${exec_prefix}/bin
+libdir = ${exec_prefix}/lib
+infodir = ${prefix}/info
+includedir = ${prefix}/include
+datadir = ${prefix}/share
+localedir = $(datadir)/locale
+sysconfdir = ${prefix}/etc
+mandir = ${prefix}/man
+
+INSTALL = /usr/bin/install -c
+INSTALL_PROGRAM = ${INSTALL}
+INSTALL_SCRIPT = ${INSTALL}
+INSTALL_DATA = ${INSTALL} -m 644
+INSTALLMODE= -m 0755
+INSTALLMODE2 = -m 0555
+
+DESTDIR =
+
+MANIFEST = \
+	INSTALL COPYING Makefile ipdb.spec \
+	\
+	addmaster.html alloctypes.html assign.html compsearch.html \
+	confirm.html confirmRemove.html editDisplay.html fb-assign.html footer.inc \
+	header.inc help.html index.shtml ipdb.css \
+	newcity.html newnode.html nodesearch.html startsn.html updated.html \
+	images/logo.png \
+	\
+	cgi-bin/combineblocks.pl cgi-bin/access-pwd-update.pl \
+	cgi-bin/newnode.cgi cgi-bin/CustIDCK.pm cgi-bin/freespace.pl \
+	cgi-bin/admin.cgi cgi-bin/MyIPDB.pm cgi-bin/IPDB.pm \
+	cgi-bin/main.cgi cgi-bin/checkcusts.pl cgi-bin/newcity.cgi \
+	cgi-bin/allocate.pl cgi-bin/search.cgi \
+	cgi-bin/snCalc.cgi cgi-bin/CommonWeb.pm cgi-bin/ipdb.psql \
+	cgi-bin/consistency-check.pl \
+	\
+	cgi-bin/extras/db2rwhois.pl cgi-bin/extras/rwhois-net-skel.tar.gz cgi-bin/extras/rwhois-config \
+	cgi-bin/extras/network.tmpl
+
+HTML = \
+	addmaster.html alloctypes.html assign.html changes.html compsearch.html \
+	confirm.html confirmRemove.html editDisplay.html fb-assign.html footer.inc \
+	header.inc help.html index.shtml ipdb.css \
+	newcity.html newnode.html nodesearch.html startsn.html updated.html
+
+IMAGES = images/logo.png
+
+SCRIPTS = \
+	cgi-bin/extras/db2rwhois.pl cgi-bin/combineblocks.pl cgi-bin/access-pwd-update.pl \
+	cgi-bin/newnode.cgi cgi-bin/freespace.pl cgi-bin/admin.cgi \
+	cgi-bin/main.cgi cgi-bin/newcity.cgi cgi-bin/allocate.pl \
+	cgi-bin/search.cgi cgi-bin/consistency-check.pl
+
+MODULES = cgi-bin/IPDB.pm
+
+CONFIGMODULES = cgi-bin/MyIPDB.pm cgi-bin/CustIDCK.pm
+
+RWHOIS = \
+	cgi-bin/extras/db2rwhois.pl cgi-bin/extras/rwhois-net-skel.tar.gz cgi-bin/extras/rwhois-config \
+	cgi-bin/extras/network.tmpl
+
+DIRS = images cgi-bin cgi-bin/extras
+
+# hmm.  not sure what do do about you, m'friend...
+#ip@
+
+all:
+	# nullop
+
+install:
+	@for i in $(HTML) $(IMAGES); do \
+		$(INSTALL_DATA) -D $$i $(DESTDIR)${libdir}/ipdb-$(VERSION)/$$i ; \
+	done
+	# munge in necessary 'use lib ...' bits so scripts can find MyIPDB.pm...
+	@for i in $(SCRIPTS) $(MODULES) $(RWHOIS); do \
+		$(INSTALL_SCRIPT) -D $$i $(DESTDIR)${libdir}/ipdb-$(VERSION)/$$i ; \
+		perl -pi -e 's|##uselib##|use lib "${sysconfdir}/ipdb-$(VERSION)/";|;' $(DESTDIR)${libdir}/ipdb-$(VERSION)/$$i ; \
+	done
+	$(INSTALL) -d $(DESTDIR)${sysconfdir}/ipdb-$(VERSION)/
+	@for i in $(CONFIGMODULES) ; do \
+		$(INSTALL_DATA) $$i $(DESTDIR)${sysconfdir}/ipdb-$(VERSION)/ ; \
+	done
+	# and now munge MyIPDB.pm so it can find the core library
+	perl -pi -e 's|##uselib##|use lib "${libdir}/ipdb-$(VERSION)";|;' $(DESTDIR)${sysconfdir}/ipdb-$(VERSION)/MyIPDB.pm
+
+#clean:
+#	@for i in $(DIRS) ; do \
+#		$(MAKE) -C $$i clean ; \
+#	done
+
+dist:
+	mkdir $(PKGNAME)-$(VERSION)
+	tar cf - $(MANIFEST) | (cd $(PKGNAME)-$(VERSION); tar xf -)
+	/usr/bin/perl -p -e 's/#VERSION#/$(VERSION)/;s/#RELEASE#/$(RELEASE)/;s/#BETA#//g' < $(PKGNAME).spec > $(PKGNAME)-$(VERSION)/$(PKGNAME).spec
+	/usr/bin/perl -p -e 's/#VERSION#/$(VERSION)/;s/#RELEASE#/$(RELEASE)/;s/#BETA#//g' < INSTALL > $(PKGNAME)-$(VERSION)/INSTALL
+	perl -pi -e 's/[\d.]+;\s*##VERSION##/$(VERSION);/;' $(PKGNAME)-$(VERSION)/cgi-bin/IPDB.pm
+	tar cf $(PKGNAME)-$(VERSION).tar $(PKGNAME)-$(VERSION)
+	gzip -v -f -9 $(PKGNAME)-$(VERSION).tar
+	rm -rf $(PKGNAME)-$(VERSION)
+	# gpg --detach-sign $(PKGNAME)-$(VERSION).tar.gz
Index: branches/stable/alloctypes.html
===================================================================
--- branches/stable/alloctypes.html	(revision 444)
+++ branches/stable/alloctypes.html	(revision 445)
@@ -11,97 +11,190 @@
 <table class="regular">
 
-<tr><td colspan=2 class="heading">Allocation Types:</td><tr>
-
-<tr class="color1">
-<td>Customer netblock (default)</td><td>A direct allocation /30 or larger to a
-customer.  Note that this does NOT include RADIUS-routed "netblocks".  Internal systems
-should use the "End-use netblock" type.</td>
-</tr>
-
-<tr class="color2">
-<td>Static IP - Server pool</td><td>A single IP from a pool designated for
-servers</td>
-</tr><tr class="color1">
-<td>Static IP - Cable</td><td>A single IP address from a designated pool
-on the cable network.</td>
-</tr><tr class="color2">
-<td>Static IP - DSL</td><td>A single IP address from a designated pool
-on the DSL network.  Note that these are nominally in Sudbury or North Bay,
-even if the customer isn't.</td>
-</tr><tr class="color1">
-<td>Static IP - Dialup</td><td>A single IP address from a designated pool
-on a dialup RAS.</td>
-</tr><tr class="color2">
-<td>Static IP - Wireless</td><td>A single IP address from a designated pool
-on one of our wireless networks.</td>
-</tr>
-
-<tr class="color1">
-<td>Static pool - Servers</td><td>A pool of IP addresses available for one-by-one
-assignment to servers in a POP.  This will usually only be in Sudbury.</td>
-</tr><tr class="color2">
-<td>Static pool - Cable</td><td>A pool of IP addresses available for one-by-one assignment
-to customers on cable.</td>
-</tr><tr class="color1">
-<td>Static pool - DSL</td><td>A pool of IP addresses available for one-by-one assignment to
-customers on DSL.  Note that individual IPs will be "assigned" to the customer's
-city, but the pool they are a part of will normally be "assigned" to Sudbury or
-North Bay.</td>
-</tr><tr class="color2">
-<td>Static pool - Dialup</td><td>A pool of IP addresses available for one-by-one
-assignment to dialup customers.</td>
-</tr><tr class="color1">
-<td>Static pool - Wireless</td><td>A pool of IP addresses available for one-by-one
-assignment to customers on one of our wireless networks.</td>
-</tr>
-
-<tr class="color2">
-<td>End-use netblock</td><td>A /30 or larger allocation for arbitrary services (LAN
-management, servers we want fully subnet-isolated, etc)</td>
-
-</tr><tr class="color1">
-<td>Dialup netblock</td><td>Netblock assigned to one or more RAS units in a POP</td>
-</tr><tr class="color2">
-<td>Dynamic DSL block</td><td>Netblock for (mostly residential) PPPoE DSL.  Nominally
-"assigned" to Sudbury</td>
-</tr><tr class="color1">
-<td>Dynamic cable block</td><td>Netblock for (mostly residential) DHCP cable.</td>
-</tr><tr class="color2">
-<td>Dynamic WiFi block</td><td>Netblock for (mostly residential) (mostly) PPPoE wireless.</td>
-</tr><tr class="color1">
-<td>Dynamic VoIP block</td><td>Netblock for DHCP-assigned VoIP services.</td>
-
-</tr><tr class="color2">
-<td>Static IP - LAN/POP</td><td>A single IP address from a designated pool for our
-internal LANs - either at a single POP or for a VPN.</td>
-</tr><tr class="color1">
-<td>Static pool - LAN/POP</td><td>A pool of IP addresses available for one-by-one
-assignment to our internal LAN systems or VPNs.</td>
-
-</tr><tr class="color2">
-<td>Reserve for WAN blocks</td><td>Reserve a chunk of IP space for core routers/etc.</td>
-</tr><tr class="color1">
-<td>Reserve for dynamic-route DSL netblocks</td><td>Reserve a chunk of IP space for
-RADIUS-assigned "netblocks" from a PPPoE pool.  Note that this is similar to the static DSL
-pool, but IP space is to be allocated as /30 and larger netblocks, not single static IPs.</td>
-</tr><tr class="color2">
-<td>Reserve for ATM</td><td>Reserve a chunk of IP space for allocation to customers on ATM</td>
-</tr><tr class="color1">
-<td>WAN block</td><td>Individual netblock assignment for a core router.  Always taken from a
+<tr><td colspan=2 class="heading">Preseeded Allocation Types:</td><tr>
+
+<tr class="color1">
+<td>Customer netblock (default)</td>
+<td>A direct allocation /30 or larger to a customer.  Note that this does NOT 
+include RADIUS-routed "netblocks".  Non-customer systems should use the 
+"End-use netblock" type.</td>
+</tr>
+
+<tr class="color2">
+<td>Static IP - Server pool</td>
+<td>A single IP from a pool designated for servers</td>
+</tr>
+
+<tr class="color1">
+<td>Static IP - Cable</td>
+<td>A single IP address from a designated pool on the cable network.</td>
+</tr>
+
+<tr class="color2">
+<td>Static IP - DSL</td>
+<td>A single IP address from a designated pool on the DSL network.</td>
+</tr>
+
+<tr class="color1">
+<td>Static IP - Dialup</td>
+<td>A single IP address from a designated pool on a dialup RAS.</td>
+</tr>
+
+<tr class="color2">
+<td>Static IP - Wireless</td>
+<td>A single IP address from a designated pool on a wireless connection.</td>
+</tr>
+
+<tr class="color1">
+<td>Static pool - Servers</td>
+<td>A pool of IP addresses available for one-by-one assignment to servers in a 
+POP.</td>
+</tr>
+
+<tr class="color2">
+<td>Static pool - Cable</td>
+<td>A pool of IP addresses available for one-by-one assignment to customers on 
+cable.</td>
+</tr>
+
+<tr class="color1">
+<td>Static pool - DSL</td>
+<td>A pool of IP addresses available for one-by-one assignment to customers on 
+DSL.  Individual IPs will be "assigned" to the customer's city, but the pool 
+will remain assigned to its nominal origin.</td>
+</tr>
+
+<tr class="color2">
+<td>Static pool - Dialup</td>
+<td>A pool of IP addresses available for one-by-one assignment to dialup 
+customers.</td>
+</tr>
+
+<tr class="color1">
+<td>Static pool - Wireless</td>
+<td>A pool of IP addresses available for one-by-one assignment to customers on a 
+wireless connection.</td>
+</tr>
+
+<tr class="color2">
+<td>End-use netblock</td>
+<td>A /30 or larger allocation for arbitrary services - note this should not 
+be used for customer connections.  Use this if exact tracking of IP 
+usage in the block is not required.</td>
+</tr>
+
+<tr class="color1">
+<td>Dialup netblock</td>
+<td>Netblock assigned to one or more RAS units in a POP</td>
+</tr>
+
+<tr class="color2">
+<td>Dynamic DSL block</td>
+<td>Netblock for (mostly residential) PPPoE DSL.</td>
+</tr>
+
+<tr class="color1">
+<td>Dynamic cable block</td>
+<td>Netblock for (mostly residential) DHCP cable.</td>
+</tr>
+
+<tr class="color2">
+<td>Dynamic WiFi block</td>
+<td>Netblock for (mostly residential) (mostly) PPPoE wireless.</td>
+</tr>
+
+<tr class="color1">
+<td>Dynamic VoIP block</td>
+<td>Netblock for DHCP-assigned VoIP services.</td>
+</tr>
+
+<tr class="color2">
+<td>Static IP - LAN/POP</td>
+<td>A single IP address from a designated pool for internal LANs - either at a 
+single POP or for a VPN.</td>
+</tr>
+
+<tr class="color1">
+<td>Static IP - Managment</td>
+<td>A single IP address from a designated pool for managed devices.</td>
+</tr>
+
+<tr class="color2">
+<td>Static IP - Wifi CPE</td>
+<td>A single IP address from a designated pool for wireless CPE devices.</td>
+</tr>
+
+<tr class="color1">
+<td>Static pool - LAN/POP</td>
+<td>A pool of IP addresses available for one-by-one assignment to internal LAN 
+systems or VPNs.</td>
+</tr>
+
+<tr class="color2">
+<td>Static Pool - Managment</td>
+<td>A pool of IP addresses available for assignment to managed devices.</td>
+</tr>
+
+<tr class="color1">
+<td>Static pool - Wifi CPE</td>
+<td>A pool of IP addresses available for assignment to wireless CPE devices.</td>
+</tr>
+
+<tr class="color2">
+<td>Reserve for WAN blocks</td>
+<td>Reserve a chunk of IP space for core routers/etc.</td>
+</tr>
+
+<tr class="color1">
+<td>Reserve for dynamic-route DSL netblocks</td>
+<td>Reserve a chunk of IP space for netblocks configured on the customer end via 
+PPPoE/RADIUS.  Note that this is similar to the static DSL pool, but IP space is 
+to be allocated as /30 and larger netblocks, not single static IPs.</td>
+</tr>
+
+<tr class="color2">
+<td>Reserve for ATM</td>
+<td>Reserve a chunk of IP space for allocation to customers on ATM.</td>
+</tr>
+
+<tr class="color1">
+<td>Reserve for fibre</td>
+<td>Reserve a chunk of IP space for customers on a fibre connection.</td>
+</tr>
+
+<tr class="color2">
+<td>WAN block</td>
+<td>Individual netblock assignment for a core router.  Always taken from a
 block which has previously been reserved for such assignments.</td>
-</tr><tr class="color2">
-<td>Dynamic-route DSL netblock</td><td>Customer assignment for a RADIUS-assigned PPPoE
-"netblock".  Always taken from a block which has previously been reserved for such
-assignments.</td>
-</tr><tr class="color1">
-<td>ATM block</td><td>Customer assignment for a customer on ATM.  Always taken from a
+</tr>
+
+<tr class="color1">
+<td>Dynamic-route DSL netblock</td>
+<td>Customer assignment for a netblock configured on the customer end via 
+PPPoE/RADIUS.  Always taken from a block which has previously been reserved for 
+such assignments.</td>
+</tr>
+
+<tr class="color2">
+<td>ATM block</td>
+<td>Customer assignment for a customer on ATM.  Always taken from a
 block which has previously been reserved for such assignments.</td>
-
-</tr><tr class="color2">
-<td>Routing</td><td>Blocks not actually assigned to a service on their own, but which
+</tr>
+
+<tr class="color1">
+<td>Fibre</td>
+<td>Customer assignment for a customer on fibre. Always taken from a block 
+which has previously been reserved for such assignments.</td>
+</tr>
+
+<tr class="color2">
+<td>Routing</td>
+<td>Blocks not actually assigned to a service on their own, but which
 have been routed to individual POPs- typically /24, /23, /22</td>
-
-</tr><tr class="color1">
-<td>Master block</td><td>Our allocations from ARIN</td>
+</tr>
+
+<tr class="color1">
+<td>Master block</td>
+<td>Allocations provided by the regional registry (ARIN, RIPE, LACNIC, AfriNIC, 
+or APNIC)</td>
 </tr>
 
Index: branches/stable/cgi-bin/CommonWeb.pm
===================================================================
--- branches/stable/cgi-bin/CommonWeb.pm	(revision 444)
+++ branches/stable/cgi-bin/CommonWeb.pm	(revision 445)
@@ -8,8 +8,4 @@
 
 package CommonWeb;
-
-# 08/13/2004 kdeugau@vianet
-#	Split DB-related functions into new module;  they're not
-#	specific to CGI/web stuff.
 
 use strict;		
@@ -108,17 +104,4 @@
 }
 
-sub loginAgain
-{
-	print qq(
-	<center><p>Your session has expired. Please login again.</p>
-	<p>
-	<a href="http://hosttest.vianet.ca"> Click here to login again.</a>
-	</p>
-	</center>
-	);
-	printFooter();
-	exit(0);
-}
-
 # needs a reference to the webvar hash.
 # takes out backticks and single quotes
Index: branches/stable/cgi-bin/CustIDCK.pm
===================================================================
--- branches/stable/cgi-bin/CustIDCK.pm	(revision 444)
+++ branches/stable/cgi-bin/CustIDCK.pm	(revision 445)
@@ -34,5 +34,5 @@
 
   return 1 if $custid =~ /^STAFF$/;
-  return 1 if $custid =~ /^6750400$/;  # just in case some later change might block this
+  return 1 if $custid =~ /^5554242$/;  # just in case some later change might block this
   return 1 if $custid =~ /^\d{7}$/;
   return 1 if $custid =~ /^\d{10}$/;
Index: branches/stable/cgi-bin/IPDB.pm
===================================================================
--- branches/stable/cgi-bin/IPDB.pm	(revision 444)
+++ branches/stable/cgi-bin/IPDB.pm	(revision 445)
@@ -7,5 +7,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004-2006 - Kris Deugau
+# Copyright (C) 2004-2010 - Kris Deugau
 
 package IPDB;
@@ -20,5 +20,5 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
-$VERSION	= 2.0;
+$VERSION	= 2; ##VERSION##
 @ISA		= qw(Exporter);
 @EXPORT_OK    = qw(
@@ -53,4 +53,23 @@
 our %IPDBacl;
 
+our $org_name = 'Example Corp';
+our $smtphost = 'smtp.example.com';
+our $domain = 'example.com';
+our $defcustid = '5554242';
+# mostly for rwhois
+##fixme:  leave these blank by default?
+our $rwhoisDataPath = '/usr/local/rwhoisd/etc/rwhoisd';	# to match ./configure defaults from rwhoisd-1.5.9.6
+our $org_street = '123 4th Street';
+our $org_city = 'Anytown';
+our $org_prov_state = 'ON';
+our $org_pocode = 'H0H 0H0';
+our $org_country = 'CA';
+our $org_phone = '000-555-1234';
+our $org_techhandle = 'ISP-ARIN-HANDLE';
+our $org_email = 'noc@example.com';
+our $hostmaster = 'dns@example.com';
+
+our $syslog_facility = 'local2';
+
 # Let's initialize the globals.
 ## IPDB::initIPDBGlobals()
@@ -113,12 +132,12 @@
 # Set up for a PostgreSQL db;  could be any transactional DBMS with the
 # right changes.
-# This definition should be sub connectDB($$$) to be technically correct,
-# but this breaks.  GRR.
 sub connectDB {
-  my ($dbname,$user,$pass) = @_;
+  my $dbname = shift;
+  my $user = shift;
+  my $pass = shift;
+  my $dbhost = shift;
+
   my $dbh;
-  my $DSN = "DBI:Pg:host=ipdb-db;dbname=$dbname";
-#  my $user = 'ipdb';
-#  my $pw   = 'ipdbpwd';
+  my $DSN = "DBI:Pg:".($dbhost ? "host=$dbhost;" : '')."dbname=$dbname";
 
 # Note that we want to autocommit by default, and we will turn it off locally as necessary.
@@ -557,5 +576,5 @@
     # have to insert all pool IPs into poolips table as "unallocated".
     $sth = $dbh->prepare("insert into poolips (pool,ip,custid,city,type)".
-	" values ('$pool', ?, '6750400', '$city', '$type')");
+	" values ('$pool', ?, '$defcustid', '$city', '$type')");
     my @poolip_list = $pool->hostenum;
     if ($class eq 'all') { # (DSL-ish block - *all* IPs available
@@ -614,5 +633,5 @@
     eval {
       $msg = "Unable to deallocate $disp_alloctypes{$type} $cidr";
-      $sth = $dbh->prepare("update poolips set custid='6750400',available='y',".
+      $sth = $dbh->prepare("update poolips set custid='$defcustid',available='y',".
 	"city=(select city from allocations where cidr >>= '$cidr'".
 	" order by masklen(cidr) desc limit 1),".
@@ -704,30 +723,34 @@
       } # end alloctype general case
 
-##TEMP
-## Temporary wrapper to "properly" deallocate sIP PPPoE/DSL "netblocks" in 209.91.185.0/24
-## Note that we should really general-case this.
-my $staticpool = new NetAddr::IP "209.91.185.0/24";
-##TEMP
-if ($cidr->within($staticpool)) {
-##TEMP
-  # We've already deleted the block, now we have to stuff its IPs into the pool.
-  my $sth2 = $dbh->prepare("insert into poolips values ('209.91.185.0/24',?,'6750400','Sudbury','di','y','','','')");
-  $sth2->execute($cidr->addr);
-  foreach my $ip ($cidr->hostenum) {
-    $sth2->execute("$ip");
-  }
-  $cidr--;
-  $sth2->execute($cidr->addr);
-
-##TEMP
-} else {
-##TEMP
-
-      # Now we look for larger-or-equal-sized free blocks in the same master (routed)
-      # (super)block. If there aren't any, we can't combine blocks anyway.  If there
-      # are, we check to see if we can combine blocks.
-      # Execute the statement prepared in the if-else above.
-
-      $sth->execute;
+      ## Deallocate legacy blocks stashed in the middle of a static IP pool
+      ## This may be expandable to an even more general case of contained netblock, or other pool types.
+
+      # Find out if the block we're deallocating is within a DSL pool
+      my $sth2 = $dbh->prepare("SELECT cidr,city,type FROM allocations WHERE type LIKE '_p' AND cidr >>= ?");
+      $sth2->execute("$cidr");
+      my ($pool,$poolcity,$pooltype) = $sth2->fetchrow_array;
+
+      if ($pool || $sth2->rows) {
+	# We've already deleted the block, now we have to stuff its IPs into the pool.
+	$pooltype =~ s/p$/i/;	# change type to static IP
+	$sth2 = $dbh->prepare("INSERT INTO poolips (pool,ip,city,type,custid) values ".
+		"('$pool',?,'$poolcity','$pooltype','$defcustid')");
+##fixme:  need to not insert net, gateway, and bcast on "real netblock" pools (DHCPish)
+	# don't insert .0
+	$sth2->execute($cidr->addr) unless $cidr->addr =~ m|\.0$|;
+	foreach my $ip ($cidr->hostenum) {
+	  $sth2->execute("$ip");
+	}
+	$cidr--;
+	# don't insert .255
+	$sth2->execute($cidr->addr) unless $cidr->addr =~ m|\.255$|;
+      } else {	# done returning IPs from a block to a static DSL pool
+
+	# Now we look for larger-or-equal-sized free blocks in the same master (routed)
+	# (super)block. If there aren't any, we can't combine blocks anyway.  If there
+	# are, we check to see if we can combine blocks.
+	# Execute the statement prepared in the if-else above.
+
+	$sth->execute;
 
 # NetAddr::IP->compact() attempts to produce the smallest inclusive block
@@ -739,40 +762,38 @@
 #	$cidr=.32/27, $ip1=.96/27, $ip2=.0/27, and $ip3=.64/27.
 
-      my (@together, @combinelist);
-      my $i=0;
-      while (my @data = $sth->fetchrow_array) {
-	my $testIP = new NetAddr::IP $data[0];
-	@together = $testIP->compact($cidr);
-	my $num = @together;
-	if ($num == 1) {
-	  $cidr = $together[0];
-	  $combinelist[$i++] = $testIP;
+	my (@together, @combinelist);
+	my $i=0;
+	while (my @data = $sth->fetchrow_array) {
+	  my $testIP = new NetAddr::IP $data[0];
+	  @together = $testIP->compact($cidr);
+	  my $num = @together;
+	  if ($num == 1) {
+	    $cidr = $together[0];
+	    $combinelist[$i++] = $testIP;
+	  }
 	}
-      }
-
-      # Clear old freeblocks entries - if any.  They should all be within
-      # the $cidr determined above.
-      $sth = $dbh->prepare("delete from freeblocks where cidr <<='$cidr'");
-      $sth->execute;
-
-      # insert "new" freeblocks entry
-      if ($type eq 'rm') {
-	$sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city)".
+
+	# Clear old freeblocks entries - if any.  They should all be within
+	# the $cidr determined above.
+	$sth = $dbh->prepare("delete from freeblocks where cidr <<='$cidr'");
+	$sth->execute;
+
+	# insert "new" freeblocks entry
+	if ($type eq 'rm') {
+	  $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city)".
 		" values ('$cidr',".$cidr->masklen.",'<NULL>')");
-      } else {
-	# Magic hackery to insert "correct" data for deallocation of
-	# non-contained blocks allocated from within a container.
-	$type = 'pr' if $con_type && $con_type eq 'pc';
-
-	$sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
+	} else {
+	  # Magic hackery to insert "correct" data for deallocation of
+	  # non-contained blocks allocated from within a container.
+	  $type = 'pr' if $con_type && $con_type eq 'pc';
+
+	  $sth = $dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
 		" values ('$cidr',".$cidr->masklen.
 		",(select city from routed where cidr >>= '$cidr'),'".
 		(($type =~ /^(.)r$/) ? "$1" : 'y')."')");
-      }
-      $sth->execute;
-
-##TEMP
-}
-##TEMP
+	}
+	$sth->execute;
+
+      } # done returning IPs to the appropriate place
 
       # If we got here, we've succeeded.  Whew!
@@ -780,4 +801,5 @@
     }; # end eval
     if ($@) {
+      $msg = $@;
       eval { $dbh->rollback; };
       return ('FAIL', $msg);
@@ -806,17 +828,50 @@
 ## IPDB::mailNotify()
 # Sends notification mail to recipients regarding an IPDB operation
-sub mailNotify ($$$) {
-  my ($recip,$subj,$message) = @_;
-  my $mailer = Net::SMTP->new("smtp.example.com", Hello => "ipdb.example.com");
-
-  $mailer->mail('ipdb@example.com');
-  $mailer->to($recip);
-  $mailer->data("From: \"IP Database\" <ipdb\@example.com>\n",
+sub mailNotify {
+  my $dbh = shift;
+  my ($action,$subj,$message) = @_;
+
+##fixme: need to redesign the breakdown/processing for $action for proper handling of all cases
+
+# split action into parts for fiddlement.  nb: there are almost certainly better ways to do this.
+  my @actionbits = split //, $action;
+
+  # want to notify anyone who has specifically requested notify on *this* type ($action as passed),
+  # on "all static IP types" or "all pool types" (and other last-char-in-type groupings), on eg "all DSL types",
+  # and "all events with this action"
+  my @actionsets = ($action);
+##fixme: ick, eww.  really gotta find a better way to handle this...
+  push @actionsets, ($actionbits[0].'.'.$actionbits[2],
+	$actionbits[0].$actionbits[1].'.', $actionbits[0].'a') if $action =~ /^.{3}$/;
+
+  my $mailer = Net::SMTP->new($smtphost, Hello => "ipdb.$domain");
+
+  # get recip list from db
+  my $sth = $dbh->prepare("SELECT reciplist FROM notify WHERE action=?");
+
+  my %reciplist;
+  foreach (@actionsets) {
+    $sth->execute($_);
+##fixme - need to handle db errors
+    my ($recipsub) = $sth->fetchrow_array;
+    next if !$recipsub;
+    foreach (split(/,/, $recipsub)) {
+      $reciplist{$_}++;
+    }
+  }
+
+  return if !%reciplist;
+
+  foreach my $recip (keys %reciplist) {
+    $mailer->mail("ipdb\@$domain");
+    $mailer->to($recip);
+    $mailer->data("From: \"$org_name IP Database\" <ipdb\@$domain>\n",
 	"To: $recip\n",
 	"Date: ".strftime("%a, %d %b %Y %H:%M:%S %z",localtime)."\n",
 	"Subject: {IPDB} $subj\n",
 	"X-Mailer: IPDB Notify v".sprintf("%.1d",$IPDB::VERSION)."\n",
-	"Organization: Example Corp\n",
+	"Organization: $org_name\n",
 	"\n$message\n");
+  }
   $mailer->quit;
 }
Index: branches/stable/cgi-bin/MyIPDB.pm
===================================================================
--- branches/stable/cgi-bin/MyIPDB.pm	(revision 444)
+++ branches/stable/cgi-bin/MyIPDB.pm	(revision 445)
@@ -8,7 +8,43 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004-2006 - Kris Deugau
+# Copyright (C) 2004-2010 - Kris Deugau
+
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
 
 use IPDB 2.0 qw(:ALL);
+
+
+# DSN, user, and password for database.  These **MUST** be set.
+my $dbname = 'ipdb';
+my $dbuser = 'ipdb';
+my $dbpass = 'ipdbpwd';
+# DB host is optional.
+my $dbhost = 'ipdb-db';
+
+# Set some globals declared in IPDB.pm.  Most of these only affect mailNotify().
+# Note that while you *can* leave these at defaults, it's probably a Really Bad Idea.
+#$IPDB::org_name = "Bob's Big Bonaza";
+#$IPDB::smtphost = '127.0.0.1';
+#$IPDB::domain = 'bob.com';
+#$IPDB::defcustid = '5554242';
+# Globals for db2rwhois.pl
+#$IPDB::rwhoisDataPath = '/usr/local/rwhoisd/etc/rwhoisd';
+#$IPDB::org_street = '123 4th Street';
+#$IPDB::org_city = 'Anytown';
+#$IPDB::org_prov_state = 'ON';
+#$IPDB::org_pocode = 'H0H 0H0';
+#$IPDB::org_country = 'CA';
+#$IPDB::org_phone = '000-555-1234';
+# note: following may also just be a bare email address
+#$IPDB::org_techhandle = 'ISP-ARIN-HANDLE';
+#$IPDB::org_email = 'noc@example.com';
+#$IPDB::hostmaster = 'dns@example.com';
+
+# Logging destination.  Defaults to local2.  See your local syslog docs for valid facilities.
+# Note that the value here should have the LOG_ prefix removed, and convert to lower-case.
+# local0 through local7 and user make the most sense.
+#$IPDB::syslog_facility = 'daemon';
+
 
 ## connectDB_My()
@@ -16,5 +52,5 @@
 # Takes no arguments, returns whatever IPDB::connectDB returns.
 sub connectDB_My {
-  return connectDB("ipdb", "ipdb", "ipdbpwd");
+  return connectDB($dbname, $dbuser, $dbpass, $dbhost);
 } # end connectDB_My()
 
Index: branches/stable/cgi-bin/access-pwd-update.pl
===================================================================
--- branches/stable/cgi-bin/access-pwd-update.pl	(revision 444)
+++ branches/stable/cgi-bin/access-pwd-update.pl	(revision 445)
@@ -8,10 +8,13 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2007,2008 - Kris Deugau
+# Copyright (C) 2007-2010 - Kris Deugau
 
 use strict;
 use warnings;
 use DBI;
-use lib '/var/www/ipdb.example.com/ip/cgi-bin/';
+
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
 use MyIPDB;
 
Index: branches/stable/cgi-bin/admin.cgi
===================================================================
--- branches/stable/cgi-bin/admin.cgi	(revision 444)
+++ branches/stable/cgi-bin/admin.cgi	(revision 445)
@@ -10,5 +10,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004-2006 - Kris Deugau
+# Copyright (C) 2004-2010 - Kris Deugau
 
 use strict;
@@ -17,5 +17,4 @@
 use DBI;
 use CommonWeb qw(:ALL);
-use MyIPDB;
 use CustIDCK;
 #use POSIX qw(ceil);
@@ -24,5 +23,10 @@
 use Sys::Syslog;
 
-openlog "IPDB-admin","pid","local2";
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
+use MyIPDB;
+
+openlog "IPDB-admin","pid","$IPDB::syslog_facility";
 
 # Collect the username from HTTP auth.  If undefined, we're in a test environment.
@@ -53,5 +57,5 @@
 	qq(\t<link rel="stylesheet" type="text/css" href="/ip/local.css">\n).
 	"</head>\n<body>\n".
-	qq(Access to this tool is restricted.  Contact <a href="mailto:kdeugau\@vianet.ca">Kris</a> \n).
+	qq(Access to this tool is restricted.  Contact the <a href="mailto:ipdbadmin\@example.com">IPDB administrator</a> \n).
 	"for more information.\n</body>\n</html>\n";
   exit;
@@ -89,6 +93,4 @@
   print qq(WARNING:  There are FAR fewer controls on what you can do here.  Use the
 main interface if at all possible.
-<hr>
-<a href="admin.cgi?action=newalloc">Add allocation</a>
 <hr>
 <form action="admin.cgi" method="POST">
@@ -107,16 +109,18 @@
 Bump "last updated" timestamp on this master: <select name=whichmaster>$masterlist</select>
 <input type=submit value="Update timestamp"> (Sets timestamp to "now")</form>
-<a href="admin.cgi?action=listcust">Edit customer data for rWHOIS</a>
+<a href="admin.cgi?action=listcust">Edit customer data for rWHOIS</a> - data used for
+blocks with the SWIP box checkmarked.  Links to edit/add data are on this page.
 
 <hr><a href="admin.cgi?action=showpools">List IP Pools</a> for manual tweaking and updates
+
 <hr><a href="admin.cgi?action=showusers">Manage users</a> (add/remove users;  change
-internal access controls - note that this does NOT include IP-based limits)
+internal access controls - note that this does NOT include IP-based limits)<br>
+<a href="admin.cgi?action=emailnotice">Manage email notice options</a> (pick which events
+and allocation types cause notifications;  configure recipient lists for notices)
+
 <hr>Consistency check tools<br>
 <a href="consistency-check.pl">General</a>:  Check general netblock consistency.<br>
 <a href="freespace.pl">Free space</a>:  List total and aggregate free space.  Does not 
 include private networks (192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8)
-<hr>(r)WHOIS<br>
-<a href="list-cust.php">List customer data for WHOIS</a> - data used for blocks with the SWIP box checkmarked.
-Links to edit/add data are on this page.
 );
 } else {
@@ -149,5 +153,5 @@
       if (!$status) {
 	printError("Customer ID not valid.  Make sure the Customer ID ".
-	  "is correct.<br>\nUse STAFF for staff static IPs, and 6750400 for any other ".
+	  "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
 	  "non-customer assignments.");
 	return;
@@ -250,6 +254,5 @@
 	syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
 		"'$webvar{alloctype}'";
-	# Notify tech@example.com
-	mailNotify('tech@example.com',"$disp_alloctypes{$webvar{alloctype}} allocation",
+	mailNotify($ip_dbh, "a$webvar{alloctype}",
 	  "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer".
 	  " $webvar{custid}\n".
@@ -306,23 +309,8 @@
 <form action=admin.cgi method=POST>
 <table border=1><tr>
-<input type=hidden name=action value=newcust>
+<input type=hidden name=action value=edcust>
+<input type=hidden name=newcust value=1>
 <td>CustID:</td><td><input name=custid></td>
-<td>Name:</td><td><input name=name></td></tr>
-<tr><td>Street:</td><td><input name=street></td></tr>
-<!-- <td>Street2:</td><td><input name=street2></td> -->
-<tr><td>City:</td><td><input name=city></td>
-<td>Province: (2-letter code)</td><td><input name=province value=ON length=2 size=2></td></tr>
-<tr><td>Country: (2-letter code)</td><td><input name=country value=CA length=2 size=2></td>
-<td>Postal/ZIP Code:</td><td><input name=pocode></td></tr>
-<tr><td>Phone:</td><td><input name=phone></td>
-<!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
-<td>Description:</td><td><input name=description></td> -->
-<td>ARIN Handles:</td><td>
- Tech: <input name=tech_handle value="VH25-ORG-ARIN"><br>
- Abuse: <input name=abuse_handle><br>
- Admin: <input name=admin_handle><br>
-Note:  Only tech is required at the moment.
-</td></tr>
-<tr><td colspan=4 align=center><input type=submit value="Add"></td></tr>
+<td align=center><input type=submit value="Go to edit page for this custid"></td></tr>
 </form></table>
 );
@@ -336,43 +324,15 @@
   }
   print "</table>\n";
-} elsif ($webvar{action} eq 'newcust') {
-  if ($webvar{custid} eq '') {
-    print 'No CustID entered.  PTHBT!  (Hit "Back" and fix the problem.)';
-  } else {
-    $sth = $ip_dbh->prepare("insert into customers ".
-	"(custid, name, street, city, province, country, pocode, ".
-	"phone, tech_handle, abuse_handle, admin_handle) values ".
-	"('$webvar{custid}', '$webvar{name}', '$webvar{street}', ".
-	"'$webvar{city}', '$webvar{province}', '$webvar{country}', ".
-	"'$webvar{pocode}', '$webvar{phone}', '$webvar{techhandle}', ".
-	"'$webvar{abusehandle}', '$webvar{adminhandle}')");
-    $sth->execute;
-    if ($sth->err) {
-      print "INSERT failed:  ".$sth->errstr."\n";
-    } else {
-      print "Success!  Added customer contact data:\n".
-	qq(<table border=1><tr>
-<td>CustID:</td>$webvar{custid}</td><td>Name:</td>$webvar{name}</td></tr>
-<tr><td>Street:</td><td>$webvar{street}</td></tr>
-<tr><td>City:</td><td>$webvar{city}</td><td>Province:</td><td>$webvar{province}</td></tr>
-<tr><td>Country:</td><td>$webvar{country}</td>
-<td>Postal/ZIP Code:</td><td>$webvar{pocode}</td></tr>
-<tr><td>Phone:</td><td>$webvar{phone}</td>
-<!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
-<tr><td>Description:</td><td><input name=description></td> -->
-<td>ARIN Handles:</td><td>
- Tech: $webvar{tech_handle}<br>
- Abuse: $webvar{abuse_handle}<br>
- Admin: $webvar{admin_handle}<br>
-</td></tr></table>
-);
-    } # $sth err check
-  } # bad custid
 } elsif ($webvar{action} eq 'edcust') {
+  if ($webvar{newcust}) {
+    print "got here?\n";
+    $sth = $ip_dbh->prepare("INSERT INTO customers (custid) VALUES (?)");
+    $sth->execute($webvar{custid});
+  }
   $sth = $ip_dbh->prepare("select custid,name,street,city,province,".
-	"country,pocode,phone,tech_handle,abuse_handle,admin_handle ".
+	"country,pocode,phone,tech_handle,abuse_handle,admin_handle,special ".
 	"from customers where custid='$webvar{custid}'");
   $sth->execute;
-  my ($custid, $name, $street, $city, $prov, $country, $pocode, $phone, $tech, $abuse, $admin) =
+  my ($custid, $name, $street, $city, $prov, $country, $pocode, $phone, $tech, $abuse, $admin, $special) =
 	$sth->fetchrow_array;
   print qq(<form action=admin.cgi method=POST>
@@ -381,25 +341,68 @@
 <td>CustID:</td><td>$custid<input type=hidden name=custid value=$custid></td>
 <td>Name:</td><td><input name=name value="$name"></td></tr>
-<tr><td>Street:</td><td><input name=street value="$street"></td></tr>
+<tr><td>Street:</td><td><input name=street value="$street"></td>
 <!-- <td>Street2:</td><td><input name=street2></td> -->
-<tr><td>City:</td><td><input name=city value="$city"></td>
-<td>Province: (2-letter code)</td><td><input name=province value="$prov" length=2 size=2></td></tr>
-<tr><td>Country: (2-letter code)</td><td><input name=country value="$country" length=2 size=2></td>
-<td>Postal/ZIP Code:</td><td><input name=pocode value="$pocode"></td></tr>
-<tr><td>Phone:</td><td><input name=phone value="$pocode"></td>
+<td>City:</td><td><input name=city value="$city"></td></tr>
+<tr><td>Province/State: (2-letter code)</td><td><input name=province value="$prov" length=2 size=2></td>
+<td>Country: (2-letter code)</td><td><input name=country value="$country" length=2 size=2></td></tr>
+<tr><td>Postal/ZIP Code:</td><td><input name=pocode value="$pocode"></td>
+<td>Phone:</td><td><input name=phone value="$pocode"></td></tr>
 <!-- <td>Default rDNS:</td><td><input name=def_rdns></td></tr>
 <td>Description:</td><td><input name=description></td> -->
-<td>ARIN Handles:</td><td>
+<tr><td>Contacts/ARIN Handles:</td><td>
  Tech: <input name=tech_handle value="$tech"><br>
  Abuse: <input name=abuse_handle value="$abuse"><br>
  Admin: <input name=admin_handle value="$admin"><br>
 Note:  Only tech is required at the moment.
-</td></tr>
+</td>
+<td>"Special":</td><td><textarea name=special rows=4 cols=50>$special</textarea></td>
+</tr>
 <tr><td colspan=4 align=center><input type=submit value="Update"></td></tr>
 </form></table>
+<div style="margin-left:5px">
+<h3>Explanation for "Special" field:</h3>
+This is a temporary place to define the WHOIS "net name" for a block.
+It may be removed later, more likely migrated elsewhere.
+<p>It's formatted like this, one line for each custom net name:
+<pre>NetName[CIDR block]: NET-NAME</pre>
+Example:
+<pre>NetName192.168.236.0/24: MEGAWIDGET-1</pre>
+Note:
+<ul style="margin-top: 0px;">
+<li>Spacing is important - there should only be ONE space, in between the colon and the net name.
+<li>The CIDR block name nust include all four octets - no short forms are accepted.
+<li>Net names must be all uppercase, and consist only of A-Z, 0-9, and - (same as for SWIPed net names).
+</ul>
+</div>
 );
 
 } elsif ($webvar{action} eq 'updcust') {
-  print "Updated $webvar{custid}\n";
+  $sth = $ip_dbh->prepare("UPDATE customers SET".
+	" name=?, street=?, city=?, province=?, country=?, pocode=?,".
+	" phone=?, tech_handle=?, abuse_handle=?, admin_handle=?, special=?".
+	" WHERE custid=?");
+  $sth->execute($webvar{name}, $webvar{street}, $webvar{city}, $webvar{province}, 
+	$webvar{country}, $webvar{pocode}, $webvar{phone}, $webvar{tech_handle}, 
+	$webvar{abuse_handle}, $webvar{admin_handle}, $webvar{special}, $webvar{custid});
+  print "Updated $webvar{custid}<br>\n".
+	qq(<table border=1>
+<tr><td>CustID:</td><td>$webvar{custid}</td></tr>
+<tr><td>Name:</td><td>$webvar{name}</td></tr>
+<tr><td>Street:</td><td>$webvar{street}</td></tr>
+<tr><td>City:</td><td>$webvar{city}</td></tr>
+<tr><td>Province/State:</td><td>$webvar{province}</td></tr>
+<tr><td>Country:</td><td>$webvar{country}</td></tr>
+<tr><td>Postal/ZIP Code:</td><td>$webvar{pocode}</td></tr>
+<tr><td>Phone:</td><td>$webvar{phone}</td></tr>
+<!-- <td>Default rDNS:</td><td>$webvar{def_rdns}</td></tr> -->
+<tr><td>Contacts/ARIN Handles:</td><td>
+ Tech: $webvar{tech_handle}<br>
+ Abuse: $webvar{abuse_handle}<br>
+ Admin: $webvar{admin_handle}<br>
+</td></tr>
+<tr><td>"Special":</td><td><pre>$webvar{special}</pre></td></tr>
+</table>
+<a href="admin.cgi?action=listcust">Back</a> to rWHOIS customer list<br>\n);
+
 } elsif ($webvar{action} eq 'showpools') {
   print "IP Pools currently allocated:\n".
@@ -516,4 +519,127 @@
   print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
 
+} elsif ($webvar{action} eq 'emailnotice') {
+  print "<h4>Email notice management:</h4>\nClick the email addresses to edit that list.";
+  $sth = $ip_dbh->prepare("SELECT action,reciplist FROM notify");
+  $sth->execute;
+
+  print "<table border=1>\n";
+  while (my ($notice_code,$reciplist) = $sth->fetchrow_array() ) {
+##fixme: hairy mess, only a few things call mailNotify() anyway, so many possible notices won't work.
+    my $action_out = dispNoticeCode($notice_code);
+    print "<tr><td>$action_out</td>".
+	qq(<td><a href="admin.cgi?action=ednotice&code=$notice_code">$reciplist</a></td>).
+	qq(<td><a href="admin.cgi?action=delnotice&code=$notice_code">Delete</a></tr>\n);
+  }
+  print qq(<tr><td colspan=2>Known "special" codes:<br>
+<ul style="margin-top: 0px; margin-bottom: 0px;">
+	<li>swi: Notify if block being updated has SWIP flag set</li>
+</ul></td></tr>
+</table>
+);
+
+# add new entries from this tangle:
+  print "<h4>Add new notification:</h4>\n".
+	"Note:  Failure notices on most conditions are not yet supported.\n";
+
+  print qq(<table border=1><form action=admin.cgi method="POST">
+<input type=hidden name=action value=addnotice>
+<tr>
+<td>Recipients</td><td colspan=3><textarea name=reciplist cols=50 rows=5></textarea></td></tr>
+<tr><td>Action</td><td>
+	<table><tr>
+		<td><input type=radio name=msgaction value=a>Add &nbsp;
+		<input type=radio name=msgaction value=u>Update &nbsp;
+		<input type=radio name=msgaction value=d>Delete &nbsp;
+		<input type=radio name=msgaction value=n>New listitem</td>
+	</tr><tr>
+		<td>
+		<input type=radio name=msgaction value=s:>Special: <input name=special>(requires code changes)
+	</td></tr></table>
+</td>
+<td>Failure?</td><td><input type=checkbox name=onfail></td></tr>
+<tr><td>Event/Allocation type:</td><td colspan=3>
+	<table>
+	<tr>
+		<td><input type=radio name=alloctype value=a>All allocations</td>
+		<td><input type=radio name=alloctype value=.i>All static IPs</td>
+		<td><input type=radio name=alloctype value=ci>New city</td>
+		<td><input type=radio name=alloctype value=no>New node</td>
+	</tr>
+	<tr>
+);
+
+  $sth = $ip_dbh->prepare("SELECT type,dispname FROM alloctypes WHERE listorder < 500 ".
+	"ORDER BY listorder");
+  $sth->execute;
+  my $i=0;
+  while (my ($type,$disp) = $sth->fetchrow_array) {
+    print "		<td><input type=radio name=alloctype value=$type>$disp</td>";
+    $i++;
+    print "	</tr>\n\t<tr>"
+	if ($i % 4 == 0);
+  }
+
+  print qq(	</tr>
+	</table>
+</tr>
+<tr><td colspan=4 align=center><input type=submit value="Add notice"></td></tr>
+</table>
+</form>
+);
+  ## done spitting out add-new-spam-me-now table
+
+} elsif ($webvar{action} eq 'addnotice') {
+  $webvar{alloctype} = $webvar{special} if $webvar{msgaction} eq 's:';
+  if ($webvar{msgaction} && $webvar{alloctype} && $webvar{reciplist}) {
+    $webvar{reciplist} =~ s/[\r\n]+/,/g;
+    $webvar{msgaction} = "f:$webvar{msgaction}" if $webvar{onfail};
+    print "Adding notice to $webvar{reciplist} for ".dispNoticeCode($webvar{msgaction}.$webvar{alloctype}).":\n";
+    $sth = $ip_dbh->prepare("INSERT INTO notify (action, reciplist) VALUES (?,?)");
+##fixme:  automagically merge reciplists iff action already exists
+    $sth->execute($webvar{msgaction}.$webvar{alloctype}, $webvar{reciplist});
+    if ($sth->err) {
+      print "Failed:  DB error: ".$sth->errstr."\n";
+    } else {
+      print "OK!<br>\n"
+    }
+  } else {
+    print "Need to specify at least one recipient, an action, and an allocation type. ".
+	qq{("Special" content is considered an allocation type).  Hit the Back button and try again.<br>\n};
+  }
+  print qq(<a href="admin.cgi?action=emailnotice">Back to email notice list</a>\n);
+
+} elsif ($webvar{action} eq 'delnotice') {
+  print "Deleting notices on ".dispNoticeCode($webvar{code}.$webvar{alloctype}).":\n";
+  $sth = $ip_dbh->prepare("DELETE FROM notify WHERE action=?");
+  $sth->execute($webvar{code});
+  if ($sth->err) {
+    print "Failed:  DB error: ".$sth->errstr."\n";
+  } else {
+    print "OK!<br>\n"
+  }
+  print qq(<a href="admin.cgi?action=emailnotice">Back to email notice list</a>\n);
+
+} elsif ($webvar{action} eq 'ednotice') {
+  print "<h4>Editing recipient list for '".dispNoticeCode($webvar{code})."':</h4>\n";
+  $sth = $ip_dbh->prepare("SELECT reciplist FROM notify WHERE action=?");
+  $sth->execute($webvar{code});
+  my ($reciplist) = $sth->fetchrow_array;
+  $reciplist =~ s/,/\n/g;
+  print qq(<form action=admin.cgi method=POST><input type=hidden name=code value="$webvar{code}">\n).
+	qq(<input type=hidden name=action value="updnotice"><table border=1><tr><td>).
+	qq(<textarea cols="40" rows="5" name=reciplist>$reciplist</textarea></td><td><input type=submit value="Update">\n).
+	"</td></tr></table></form>\n";
+} elsif ($webvar{action} eq 'updnotice') {
+  print "<h4>Updating recipient list for '".dispNoticeCode($webvar{code})."':</h4>\n";
+  $sth = $ip_dbh->prepare("UPDATE notify SET reciplist=? WHERE action=?");
+  $webvar{reciplist} =~ s/[\r\n]+/,/g;
+  $sth->execute($webvar{reciplist}, $webvar{code});
+  if ($sth->err) {
+    print "Failed:  DB error: ".$sth->errstr."\n";
+  } else {
+    print "OK!<br>\n"
+  }
+  print qq(<a href="admin.cgi?action=emailnotice">Back to email notice list</a>\n);
 } elsif ($webvar{action} ne '<NULL>') {
   print "webvar{action} check failed: Don't know how to $webvar{action}";
@@ -668,2 +794,38 @@
   print "</form></table>\n";
 }
+
+
+# interpret the notify codes
+sub dispNoticeCode {
+  my $code = shift;
+  my $action_out = '';
+
+  if ($code =~ /^s:/) {
+    $code =~ s/^s:/Special: /;
+    return $code;
+  }
+  if ($code =~ /^f:(.+)$/) {
+    $code =~ s/^f://;
+    $action_out = "Failure on ";
+  }
+  if (my $target = $code =~ /^n(.+)/) {
+    $action_out .= "New ";
+    if ($1 eq 'ci') { $action_out .= "city"; }
+    elsif ($1 eq 'no') { $action_out .= "node"; }
+    else { $action_out .= '&lt;unknown&gt;'; }
+  } else {
+    my ($action,$target) = ($code =~ /^(.)(.+)$/);
+    if ($action eq 'a')      { $action_out .= 'Add '; }
+    elsif ($action eq 'u')   { $action_out .= 'Update '; }
+    elsif ($action eq 'd')   { $action_out .= 'Delete '; }
+##fixme:  what if we get something funky?
+# What about the eleventy-billion odd combinations possible?
+# this should give an idea of the structure tho
+    if ($target eq 'a') { $action_out .= "all"; }
+    elsif ($target eq '.i') {
+      $action_out .= "all static IPs";
+    }
+    else { $action_out .= $disp_alloctypes{$target}; }
+  }
+  return $action_out;
+}
Index: branches/stable/cgi-bin/allocate.pl
===================================================================
--- branches/stable/cgi-bin/allocate.pl	(revision 444)
+++ branches/stable/cgi-bin/allocate.pl	(revision 445)
@@ -10,16 +10,16 @@
 use strict;
 use warnings;
-#use CGI::Carp qw(fatalsToBrowser);
-use Carp;
 use DBI;
 use CommonWeb qw(:ALL);
-use MyIPDB;
-use IBLink;
-use POSIX qw(ceil);
 use NetAddr::IP;
 
 use Sys::Syslog;
 
-openlog "IPDBshell","pid","local2";
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
+use MyIPDB;
+
+openlog "IPDBshell","pid","$IPDB::syslog_facility";
 
 # Collect the username from the environment.  If undefined, something
Index: branches/stable/cgi-bin/checkcusts.pl
===================================================================
--- branches/stable/cgi-bin/checkcusts.pl	(revision 444)
+++ branches/stable/cgi-bin/checkcusts.pl	(revision 445)
@@ -7,5 +7,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004-2006 Kris Deugau
+# Copyright (C) 2004-2010 Kris Deugau
 
 use DBI;
@@ -33,5 +33,5 @@
   push @def_custids, $data[0];
 }
-$sth = $dbh->prepare("select cidr,custid from searchme where not (custid='6750400') ".
+$sth = $dbh->prepare("select cidr,custid from searchme where not (custid='$IPDB::defcustid') ".
 	"and not (custid='STAFF') order by cidr");
 #$sth = $dbh->prepare("select cidr,custid from searchme order by cidr");
Index: branches/stable/cgi-bin/combineblocks.pl
===================================================================
--- branches/stable/cgi-bin/combineblocks.pl	(revision 444)
+++ branches/stable/cgi-bin/combineblocks.pl	(revision 445)
@@ -14,9 +14,11 @@
 use DBI;
 #use CommonWeb qw(:ALL);
-use MyIPDB;
 #use POSIX qw(ceil);
 use NetAddr::IP;
 
-#use Sys::Syslog;
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
+use MyIPDB;
 
 my $null = new NetAddr::IP "255.255.255.255/32";
Index: branches/stable/cgi-bin/consistency-check.pl
===================================================================
--- branches/stable/cgi-bin/consistency-check.pl	(revision 444)
+++ branches/stable/cgi-bin/consistency-check.pl	(revision 445)
@@ -8,9 +8,13 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004 - Kris Deugau
+# Copyright (C) 2004-2010 - Kris Deugau
 
 use DBI;
+use NetAddr::IP;
+
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
 use MyIPDB;
-use NetAddr::IP;
 
 print "Content-type: text/plain\n\n";
@@ -230,5 +234,5 @@
 print "Checking for customer blocks with 'bad' CustIDs:\n";
 # Make sure cn-type ("customer netblock") blocks have "real" CustIDs.
-$sth = $dbh->prepare("select cidr,type,custid from allocations where type='cn' and (custid='6750400' or custid='STAFF') order by cidr");
+$sth = $dbh->prepare("select cidr,type,custid from allocations where type='cn' and (custid='$IPDB::defcustid' or custid='STAFF') order by cidr");
 $sth->execute;
 while (@data = $sth->fetchrow_array) {
Index: branches/stable/cgi-bin/editcust.php
===================================================================
--- branches/stable/cgi-bin/editcust.php	(revision 444)
+++ 	(revision )
@@ -1,78 +1,0 @@
-<?php
-/* editcust.php
-** Show customer data in form for editing.
-*****
-** SVN revision info
-** $Date$
-** SVN revision $Rev$
-** Last update by $Author$
-*****
-** Copyright (C) 2006 - Kris Deugau
-*/
-?>
-<html><head>
-<title>[IPDB admin] Edit customer data for rWHOIS export</title>
-</head>
-<body>
-<h2>Edit customer data for rWHOIS export</h2>
-<a href="/ip/cgi-bin/admin.cgi">Back</a> to admin<br>
-<a href="/ip/cgi-bin/list-cust.php">Back</a> to WHOIS customer list
-<form action=updatecust.php method=post>
-<?
-  $db_conn = pg_connect("dbname=ipdb user=ipdb password=ipdbpwd host=ipdb-db");
-
-  if (!$db_conn) {
-    echo ("<H1>Failed connection to db ipdb.  Can't continue.</H1>");
-    echo "db err: ". pg_last_error() ."\n";
-    exit;
-  }
-
-// snag form data into local vars.  Not being excessively paranoid because we're
-// buried deep and this is a hack anyway.
-  $newcust = $_REQUEST['newcust'];
-  $custid = $_REQUEST['custid'];
-
-  if ($newcust==1) {
-    echo "New customer.  Creating blank record in the database...\n";
-    $qu = pg_exec ($db_conn, "INSERT INTO customers (custid) VALUES ('$custid')");
-  }
-
-  $qu = pg_exec ($db_conn, "SELECT * FROM customers WHERE custid='$custid'");
-  if (!$qu) {
-    echo "DB error - select on customers.  Save this page and tell Kris.<BR>";
-  }
-
-  $data = pg_fetch_array($qu, 0);
-
-  echo "<table border=2 cellpadding=2>".
-	"<tr><td align=right>CustID</td><td>$data[0]<input type=hidden name=custid value=$data[0]></td></tr>\n".
-	"<tr><td>Name</td><td><input name=name value=\"$data[1]\"></td></tr>\n".
-	"<tr><td>Street address</td><td><input name=addr1 value=\"$data[2]\"></td></tr>\n".
-	"<tr><td>Address 2</td><td><input name=addr2 value=\"$data[3]\"></td></tr>\n".
-	"<tr><td>City</td><td><input name=city value=\"$data[4]\"></td></tr>\n".
-	"<tr><td>Province</td><td><input name=prov value=\"$data[5]\"></td></tr>\n".
-	"<tr><td>Country</td><td><input name=country value=\"$data[6]\"></td></tr>\n".
-	"<tr><td>Postal code</td><td><input name=pocode value=\"$data[7]\"></td></tr>\n".
-	"<tr><td>Phone</td><td><input name=phone value=\"$data[8]\"></td></tr>\n".
-	"<tr><td>Tech handle</td><td><input name=tech value=\"$data[9]\"></td></tr>\n".
-	"<tr><td>Abuse handle</td><td><input name=abuse value=\"$data[10]\"></td></tr>\n".
-	"<tr><td>Admin handle</td><td><input name=admin value=\"$data[11]\"></td></tr>\n".
-	"<tr><td>Default rDNS</td><td><input name=rdns value=\"$data[12]\"></td></tr>\n".
-	"<tr><td>\"Special\"</td><td><textarea name=special rows=4 cols=40>$data[13]</textarea></td></tr>\n".
-	'<tr><td colspan=2 align=center><input type=submit value="Add/update customer data"></td></tr>'.
-	"\n</table></form><br>\n";
-
-?>
-<h3>Explanation for "Special" field:</h3>
-This is the field I've mangled into providing a custom WHOIS netname identifier for blocks tagged "SWIP".
-It may be removed later.
-<p>It's formatted like this, one line for each custom net name:
-<pre>NetName[CIDR block]: NET-NAME</pre>
-Example:
-<pre>NetName209.91.133.0/24: CYBERSUDBURY-1</pre>
-Note:
-<li>Spacing is important - there should only be ONE space, in between the colon and the net name.
-<li>The CIDR block name nust include all four octets - no short forms are accepted.
-<li>Net names must be all uppercase, and consist only of A-Z, 0-9, and - (same as for SWIPed net names).
-</body>
-</html>
Index: branches/stable/cgi-bin/extras/db2rwhois.pl
===================================================================
--- branches/stable/cgi-bin/extras/db2rwhois.pl	(revision 444)
+++ branches/stable/cgi-bin/extras/db2rwhois.pl	(revision 445)
@@ -10,5 +10,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004-2007 - Kris Deugau
+# Copyright (C) 2004-2010 - Kris Deugau
 
 use strict;
@@ -16,15 +16,18 @@
 use DBI;
 use NetAddr::IP;
+use File::Path 'rmtree';
+use POSIX qw(strftime);
+
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
 use MyIPDB;
-use File::Path 'rmtree';
-
-$ENV{"PATH"} = "/bin;/usr/bin";
-
-my $rwhoisDataPath = "/etc/rwhoisd";
+
+#$ENV{"PATH"} = "/bin;/usr/bin";
 
 my @autharea;
 my $authrw;
 # Use the template file to allow us to keep persistent nodes aside from netblock data
-open AUTHTEMPLATE, "<$rwhoisDataPath/rwhoisd.auth_template";
+open AUTHTEMPLATE, "<$IPDB::rwhoisDataPath/rwhoisd.auth_template";
 my $template_persist;
 while (<AUTHTEMPLATE>) {
@@ -43,5 +46,5 @@
 
 # Get the list of live directories for potential deletion
-opendir RWHOISROOT, $rwhoisDataPath;
+opendir RWHOISROOT, $IPDB::rwhoisDataPath;
 my %rwhoisdirs;
 foreach (readdir RWHOISROOT) {
@@ -91,6 +94,5 @@
   print "$masterblocks[$i] $ctime $mtime\n";
 
-  my $date;
-  chomp ($date = `/bin/date +"%Y-%m-%d"`);
+  my $date = strftime("%Y-%m-%d", localtime);
 
   my $rwnet = "net-".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen;
@@ -100,5 +102,5 @@
 
 # Hokay.  Gonna do checks *here* to see if we need to create new master trees
-  my $netdatadir = "$rwhoisDataPath/$rwnet";
+  my $netdatadir = "$IPDB::rwhoisDataPath/$rwnet";
   if (! -e $netdatadir) {
     print " New master $masterblocks[$i]!\n";
@@ -111,7 +113,7 @@
     mkdir "$netdatadir/data/referral";
 
-    my $serial;
-    chomp ($serial = `/bin/date '+%Y%m%d'000000000`);
-
+    my $serial = strftime("%Y%m%d%H%M%S000", localtime);
+
+##fixme: SOA should be different every time data changes, therefore need to rewrite this ~~ every export :(
     print "  Creating SOA...\n";
     open SOAFILE, ">$netdatadir/soa";
@@ -121,6 +123,6 @@
 Retry-Interval: 1800
 Time-To-Live: 86400
-Primary-Server: rwhois.example.com:4321
-Hostmaster: dns\@example.com
+Primary-Server: rwhois.$IPDB::domain:4321
+Hostmaster: $IPDB::hostmaster
 );
     close SOAFILE;
@@ -147,17 +149,19 @@
 
     print "  Copying template files...\n";
-    qx { /bin/cp $rwhoisDataPath/skel/attribute_defs/* $netdatadir/attribute_defs/ };
-
+##fixme: find a way to do this without a shell (or functional equivalent)
+    qx { /bin/cp $IPDB::rwhoisDataPath/skel/attribute_defs/* $netdatadir/attribute_defs/ };
+
+##fixme: not sure if this is even necessary, since it's not referenced anywhere I can recall...
     print "  Creating org data...\n";
-    open ORGDATAFILE, ">$netdatadir/data/org/friendlyisp.txt";
+    open ORGDATAFILE, ">$netdatadir/data/org/ourorg.txt";
     print ORGDATAFILE qq(ID: NETBLK-ISP.$masterblocks[$i]
 Auth-Area: $masterblocks[$i]
-Org-Name: Friendly ISP
-Street-Address: 123 4th Street
-City: Anytown
-State: ON
-Postal-Code: H0H 0H0
-Country-Code: CA
-Phone: 000-555-1234
+Org-Name: $IPDB::org_name
+Street-Address: $IPDB::org_street
+City: $IPDB::org_city
+State: $IPDB::org_prov_state
+Postal-Code: $IPDB::org_pocode
+Country-Code: $IPDB::org_country
+Phone: $IPDB::org_phone
 Created: 20040308
 Updated: 20040308
@@ -182,5 +186,5 @@
   my $masterfilename = "$rwnet/data/network/".$masterblocks[$i]->addr."-".$masterblocks[$i]->masklen.".txt";
 
-  open MASTERFILE,">$rwhoisDataPath/$masterfilename";
+  open MASTERFILE,">$IPDB::rwhoisDataPath/$masterfilename";
 
   print MASTERFILE "ID: NETBLK-ISP.$masterblocks[$i]\n".
@@ -189,14 +193,14 @@
 	"IP-Network: $masterblocks[$i]\n".
 	"IP-Network-Block: ".$masterblocks[$i]->range."\n".
-	"Org-Name: Friendly ISP\n".
-	"Street-Address: 123 4th Street\n".
-	"City: Anytown\n".
-	"StateProv: Ontario\n".
-	"Postal-Code: H0H 0H0\n".
-	"Country-Code: CA\n".
-	"Tech-Contact: ISP-ARIN-HANDLE\n".
+	"Org-Name: $IPDB::org_name\n".
+	"Street-Address: $IPDB::org_street\n".
+	"City: $IPDB::org_city\n".
+	"StateProv: $IPDB::org_prov_state\n".
+	"Postal-Code: $IPDB::org_pocode\n".
+	"Country-Code: $IPDB::org_country\n".
+	"Tech-Contact: $IPDB::org_techhandle\n".
 	"Created: $ctime\n".
 	"Updated: $mtime\n".
-	"Updated-By: noc\@example.com\n";
+	"Updated-By: $IPDB::org_email\n";
 
   # And now the subblocks
@@ -226,5 +230,5 @@
 
 # Fill in a generic entry for nameless allocations
-if ($desc =~ /^\s*$/) { $desc = 'Friendly ISP'; }
+if ($desc =~ /^\s*$/) { $desc = $IPDB::org_name; }
 
     # Fix up datestamps.  We don't *really* need sub-microsecond resolution on our exports...
@@ -257,14 +261,14 @@
 	"IP-Network: $net\n".
 	"IP-Network-Block: ".$net->range."\n".
-	"Org-Name: Friendly ISP\n".
-	"Street-Address: 123 4th Street\n".
-	"City: Anytown\n".
-	"StateProv: Ontario\n".
-	"Postal-Code: H0H 0H0\n".
-	"Country-Code: CA\n".
-	"Tech-Contact: ISP-ARIN-HANDLE\n".
+	"Org-Name: $IPDB::org_name\n".
+	"Street-Address: $IPDB::org_street\n".
+	"City: $IPDB::org_city\n".
+	"StateProv: $IPDB::org_prov_state\n".
+	"Postal-Code: $IPDB::org_pocode\n".
+	"Country-Code: $IPDB::org_country\n".
+	"Tech-Contact: $IPDB::org_techhandle\n".
 	"Created: $ctime\n".
 	"Updated: $mtime\n".
-	"Updated-By: noc\@example.com\n";
+	"Updated-By: $IPDB::org_email\n";
     } else {
       $custsth->execute($custid);
@@ -281,14 +285,14 @@
 	"IP-Network: $net\n".
 	"IP-Network-Block: ".$net->range."\n".
-	"Org-Name: ".($name ? $name : 'Friendly ISP')."\n".
-	"Street-Address: ".($street ? $street : '123 4th Street')."\n".
-	"City: ".($city ? $city : 'Anytown')."\n".
-	"StateProv: ".($prov ? $prov : 'Ontario')."\n".
-	"Postal-Code: ".($pocode ? $pocode : 'H0H 0H0')."\n".
-	"Country-Code: ".($country ? $country : 'CA')."\n".
-	"Tech-Contact: ".($tech ? $tech : 'ISP-ARIN-HANDLE')."\n".
+	"Org-Name: ".($name ? $name : $IPDB::org_name)."\n".
+	"Street-Address: ".($street ? $street : $IPDB::org_street)."\n".
+	"City: ".($city ? $city : $IPDB::org_city)."\n".
+	"StateProv: ".($prov ? $prov : $IPDB::org_prov_state)."\n".
+	"Postal-Code: ".($pocode ? $pocode : $IPDB::org_pocode)."\n".
+	"Country-Code: ".($country ? $country : $IPDB::org_country)."\n".
+	"Tech-Contact: ".($tech ? $tech : $IPDB::org_techhandle)."\n".
 	"Created: $ctime\n".
 	"Updated: $mtime\n".
-	"Updated-By: noc\@example.com\n";
+	"Updated-By: $IPDB::org_email\n";
     } # swip
 
@@ -304,5 +308,5 @@
 foreach my $netdir (keys %rwhoisdirs) {
   print "deleting obsolete directory $netdir...\n";
-  rmtree ( "$rwhoisDataPath/$netdir", { verbose => 1, error => \my $errlist } );
+  rmtree ( "$IPDB::rwhoisDataPath/$netdir", { verbose => 1, error => \my $errlist } );
   for my $diag (@$errlist) {
     my ($file, $message) = each %$diag;
@@ -317,5 +321,5 @@
 if ($authrw) {
   print "Regenerating auth_area\n";
-  open RWHOISDAUTH, ">$rwhoisDataPath/rwhoisd.auth_area";
+  open RWHOISDAUTH, ">$IPDB::rwhoisDataPath/rwhoisd.auth_area";
   print RWHOISDAUTH "# WARNING: This file is autogenerated!  Any static nodes should\n".
 		"# be entered in /etc/rwhoisd/rwhoisd.auth_template\n";
@@ -333,7 +337,7 @@
 
   # restart/reload rwhoisd
-  if (-e "$rwhoisDataPath/rwhoisd.pid") {	# no pidfile, no restart.
+  if (-e "$IPDB::rwhoisDataPath/rwhoisd.pid") {	# no pidfile, no restart.
     print "Restarting rwhoisd\n";
-    open PIDFILE, "<$rwhoisDataPath/rwhoisd.pid";
+    open PIDFILE, "<$IPDB::rwhoisDataPath/rwhoisd.pid";
     my ($rwpid) = (<PIDFILE> =~ /^(\d+)/);
     close PIDFILE;
Index: branches/stable/cgi-bin/freespace.pl
===================================================================
--- branches/stable/cgi-bin/freespace.pl	(revision 444)
+++ branches/stable/cgi-bin/freespace.pl	(revision 445)
@@ -8,9 +8,13 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004-2006 - Kris Deugau
+# Copyright (C) 2004-2010 - Kris Deugau
 
 use DBI;
+use NetAddr::IP;
+
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
 use MyIPDB;
-use NetAddr::IP;
 
 ($dbh,$errstr) = connectDB_My;
Index: branches/stable/cgi-bin/ipdb.psql
===================================================================
--- branches/stable/cgi-bin/ipdb.psql	(revision 444)
+++ branches/stable/cgi-bin/ipdb.psql	(revision 445)
@@ -137,10 +137,10 @@
 mi	Static IP - Dialup	Static dialup IP	23		ISP
 wi	Static IP - Wireless	Static wireless IP	24		ISP
-sd	Static Pool - Servers	Server pool	40	6750400	ISP
+sd	Static Pool - Servers	Server pool	40	5554242	ISP
 cd	Static Pool - Cable	Cable pool	41	CBL-BUS	ISP-STATIC-CABLE
 dp	Static Pool - DSL	DSL pool	42	DSL-BUS	ISP-STATIC-DSL
 mp	Static Pool - Dialup	Static dialup pool	43	DIAL-BUS	ISP-STATIC-DIAL
 wp	Static Pool - Wireless	Static wireless pool	44	WL-BUS	ISP-STATIC-WIFI
-en	End-use netblock	End-use netblock	100	6750400	ISP
+en	End-use netblock	End-use netblock	100	5554242	ISP
 me	Dialup netblock	Dialup netblock	101	DIAL-RES	ISP-DIAL
 de	Dynamic DSL block	Dynamic DSL block	102	DSL-RES	ISP-DSL
@@ -154,15 +154,15 @@
 ad	Static Pool - Management	Management pool	196	NOC-VPN	ISP
 bd	Static pool - Wifi CPE	Wifi CPE pool	197		ISP
-in	Internal netblock	Internal netblock	199	6750400	ISP
-wc	Reserve for CORE/WAN blocks	CORE/WAN blocks	200	6750400	ISP
-pc	Reserve for dynamic-route DSL netblocks	Dynamic-route netblocks	201	6750400	ISP-STATIC-DSL
-ac	Reserve for ATM	ATM blocks	202	6750400	ISP
-fc	Reserve for fibre	Fibre blocks	203	6750400	ISP
-wr	CORE/WAN block	CORE/WAN block	220	6750400	ISP
+in	Internal netblock	Internal netblock	199	5554242	ISP
+wc	Reserve for CORE/WAN blocks	CORE/WAN blocks	200	5554242	ISP
+pc	Reserve for dynamic-route DSL netblocks	Dynamic-route netblocks	201	5554242	ISP-STATIC-DSL
+ac	Reserve for ATM	ATM blocks	202	5554242	ISP
+fc	Reserve for fibre	Fibre blocks	203	5554242	ISP
+wr	CORE/WAN block	CORE/WAN block	220	5554242	ISP
 pr	Dynamic-route DSL netblock (cust)	Dynamic-route DSL (cust)	221		ISPCUST
 ar	ATM block	ATM block	222		ISP
 fr	Fibre	Fibre	223		ISP
-rm	Routing	Routed netblock	500	6750400	ISP
-mm	Master block	Master block	999	6750400	ISP
+rm	Routing	Routed netblock	500	5554242	ISP
+mm	Master block	Master block	999	5554242	ISP
 \.
 
@@ -226,2 +226,8 @@
     node_ip inet
 );
+
+-- Email notifications on <action>
+CREATE TABLE notify (
+    action varchar(5) NOT NULL PRIMARY KEY,
+    reciplist varchar(500)
+);
Index: branches/stable/cgi-bin/list-cust.php
===================================================================
--- branches/stable/cgi-bin/list-cust.php	(revision 444)
+++ 	(revision )
@@ -1,84 +1,0 @@
-<?php
-/* list-cust.php
-** List customer data in customers table, and allow editing, adding.  Delete
-** is sort of a null action and might Break Things.
-*****
-** SVN revision info
-** $Date$
-** SVN revision $Rev$
-** Last update by $Author$
-*****
-** Copyright (C) 2006 - Kris Deugau
-*/
-?>
-<html><head>
-<title>[IPDB admin] Customer data for rWHOIS export</title>
-</head>
-<body>
-<h2>Customer data for rWHOIS export</h2>
-<a href="/ip/cgi-bin/admin.cgi">Back</a> to admin
-<p><li>Click the CustID to edit information
-<li>Enter information below to add a new entry - it's best if this is done **BEFORE** flipping the "SWIP" option
-on the netblock.
-<form action=editcust.php method=POST>
-CustID:<input name=custid>
-<input type=submit value="Go to edit page for new customer">
-<input type=hidden name=newcust value=1>
-</form>
-<?
-  $db_conn = pg_connect("dbname=ipdb user=ipdb password=ipdbpwd host=ipdb-db");
-
-  if (!$db_conn) {
-    echo ("<H1>Failed connection to db ipdb.  Can't continue.</H1>");
-    echo "db err: ". pg_last_error() ."\n";
-    exit;
-  }
-
-  $qu = pg_exec ($db_conn, "SELECT * FROM customers order by custid");
-
-  if (!$qu) {
-    echo "DB error - select on customers.  Save this page and tell Kris.<BR>";
-  }
-
-  print "<br>".pg_NumRows($qu)." customers.\n";
-
-  echo "<table border=2 cellpadding=2>";
-  echo "<tr><td width=150>CustID<br>(Click to update)</td>".
-       "<td>Name</td>".
-       "<td>Street address</td>".
-       "<td>Address 2<br>(if needed)</td>".
-       "<td>City</td>".
-       "<td>Province</td>".
-       "<td>Country</td>".
-       "<td>Postal code</td>".
-       "<td>Phone</td>".
-       "<td>Tech handle</td>".
-       "<td>Abuse handle</td>".
-       "<td>Admin handle</td>".
-       "<td>Default rDNS<br>(not used)</td>".
-       "<td>\"Special\"</td></tr>\n";
-
-  $row = 0;
-  for ($row=0; $row < pg_NumRows($qu); $row++) {
-    $data = pg_fetch_array($qu, $row);
-    echo '<tr><td><a href="editcust.php?custid='.$data[0].'&newcust=0">'.$data[0]."</a> &nbsp; ".
-	'<a href="updatecust.php?custid='.$data[0].'&deletecust=1">(delete)</a></td>'.
-	"<td>$data[1]</td>".
-	"<td>$data[2]</td>".
-	"<td>$data[3]</td>".
-	"<td>$data[4]</td>".
-	"<td>$data[5]</td>".
-	"<td>$data[6]</td>".
-	"<td>$data[7]</td>".
-	"<td>$data[8]</td>".
-	"<td>$data[9]</td>".
-	"<td>$data[10]</td>".
-	"<td>$data[11]</td>".
-	"<td>$data[12]</td>".
-	"<td>$data[13]</td></tr>\n";
-  }
-  echo "</table><br>\n";
-
-?>
-</body>
-</html>
Index: branches/stable/cgi-bin/main.cgi
===================================================================
--- branches/stable/cgi-bin/main.cgi	(revision 444)
+++ branches/stable/cgi-bin/main.cgi	(revision 445)
@@ -1,5 +1,4 @@
 #!/usr/bin/perl
 # ipdb/cgi-bin/main.cgi
-# Started munging from noc.vianet's old IPDB 04/22/2004
 ###
 # SVN revision info
@@ -8,4 +7,5 @@
 # Last update by $Author$
 ###
+# Copyright (C) 2004-2010 - Kris Deugau
 
 use strict;		
@@ -14,5 +14,4 @@
 use DBI;
 use CommonWeb qw(:ALL);
-use MyIPDB;
 use CustIDCK;
 use POSIX qw(ceil);
@@ -21,5 +20,10 @@
 use Sys::Syslog;
 
-openlog "IPDB","pid","local2";
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
+use MyIPDB;
+
+openlog "IPDB","pid","$IPDB::syslog_facility";
 
 # Collect the username from HTTP auth.  If undefined, we're in
@@ -681,20 +685,9 @@
   if ($webvar{alloctype} =~ /^.i$/) {
     my ($base,undef) = split //, $webvar{alloctype};	# split into individual chars
-    my ($sql,$city);
-    # Check for pools in Subury, North Bay, or Toronto if DSL or server pool.
-    # Anywhere else is invalid and shouldn't be in the db in the first place.
-    # ... aside from #^%#$%#@#^%^^!!!! legacy data.  GRRR.
-    # Note that we want to retain the requested city to relate to customer info.
-    if ($base =~ /^[ds]$/) {
-      $city = "(allocations.city='Sudbury' or allocations.city='North Bay' or ".
-	"allocations.city='Toronto')";
-    } else {
-      $city = "allocations.city='$webvar{pop}'";
-    }
 
 # Ewww.  But it works.
     $sth = $ip_dbh->prepare("SELECT (SELECT city FROM allocations WHERE cidr=poolips.pool), ".
 	"poolips.pool, COUNT(*) FROM poolips,allocations WHERE poolips.available='y' AND ".
-	"poolips.pool=allocations.cidr AND $city AND poolips.type LIKE '".$base."_' ".
+	"poolips.pool=allocations.cidr AND allocations.city='$webvar{pop}' AND poolips.type LIKE '".$base."_' ".
 	"GROUP BY pool");
     $sth->execute;
@@ -750,16 +743,12 @@
 	# This does NOT include cable pools.
 	if ($webvar{alloctype} =~ /^.[pc]$/) {
-	  if (($webvar{city} !~ /^(Sudbury|North Bay|Toronto)$/) && ($webvar{alloctype} eq 'dp')) {
-	    printError("You must chose Sudbury, North Bay, or Toronto for DSL pools.");
-	    return;
-	  }
 	  $city = $webvar{city};
 	  $failmsg = "No suitable free block found.<br>\nYou will have to route another".
-	    " superblock from one of the<br>\nmaster blocks in Sudbury or chose a smaller".
+	    " superblock from one of the<br>\nmaster blocks or chose a smaller".
 	    " block size for the pool.";
 	} else {
 	  $city = $webvar{pop};
 	  $failmsg = "No suitable free block found.<br>\nYou will have to route another".
-	    " superblock to $webvar{pop}<br>\nfrom one of the master blocks in Sudbury or".
+	    " superblock to $webvar{pop}<br>\nfrom one of the master blocks or".
 	    " chose a smaller blocksize.";
 	}
@@ -891,8 +880,7 @@
 		qq(&ipdb=1&ip=$msg">Add this IP to RADIUS user table</a></div>)
 	: "</div>");
-      # Notify tech@example.com
-#      mailNotify('tech@example.com',"ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
-#	"$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
-#	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
+      mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
+	"$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
+	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
     } else {
       my $netblock = new NetAddr::IP $webvar{fullcidr};
@@ -906,7 +894,7 @@
 		qq(">Add this netblock to RADIUS user table</a></div>)
 	: "</div>");
-#      mailNotify('nocmgr@example.com',"ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
-#	"$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
-#	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
+      mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
+	"$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
+	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
     }
     syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
@@ -958,10 +946,8 @@
       if (!$status) {
 	printError("Customer ID not valid.  Make sure the Customer ID ".
-	  "is correct.<br>\nUse STAFF for staff static IPs, and 6750400 for any other ".
+	  "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
 	  "non-customer assignments.");
 	return;
       }
-#"Please enter a valid customer ID- this must be a 7- or 10-digit number, or STAFF for
-#static IPs for staff.");
     }
 #    print "<!-- [ In validateInput().  Insert customer ID cross-check here. ] -->\n";
@@ -985,8 +971,6 @@
   } else {
     $flag = 'n';
-    if ($webvar{alloctype} =~ /[wp][cr]|[ds][pi]/) {
-      # Set this forcibly rather than messing around elsewhere.  Yes, this *is* a hack.  PTHBTT!!
-      $webvar{pop} = 'Sudbury';
-    }
+##fixme:  hook to force-set POP or city on certain alloctypes
+# if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
     if ($webvar{pop} =~ /^-$/) {
       $flag = 'to route the block from/through';
@@ -1225,6 +1209,8 @@
   # If we get here, the operation succeeded.
   syslog "notice", "$authuser updated $webvar{block}";
-#mailNotify('nocmgr@example.com',"SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
-#	"$webvar{block} had SWIP status changed to \"Yes\" by $authuser");
+##fixme:  need to wedge something in to allow "update:field" notifications
+## hmm.  how to tell what changed?  O_o
+mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
+	"$webvar{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
   open (HTML, "../updated.html")
 	or croak "Could not open updated.html :$!";
@@ -1402,11 +1388,7 @@
     syslog "notice", "$authuser deallocated '$webvar{alloctype}'-type netblock $webvar{block}".
 	" $custid, $city, desc='$description'";
-    # Notify tech@ when a block/IP is deallocated
-#    mailNotify('tech@example.com',"REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
-#	"$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
-#	"CustID: $custid\nCity: $city\nDescription: $description\n");
-#    mailNotify('nocmgr@example.com',"REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
-#	"$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
-#	"CustID: $custid\nCity: $city\nDescription: $description\n");
+    mailNotify($ip_dbh, 'da', "REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
+	"$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
+	"CustID: $custid\nCity: $city\nDescription: $description\n");
   } else {
     if ($webvar{alloctype} =~ /^.i$/) {
Index: branches/stable/cgi-bin/newcity.cgi
===================================================================
--- branches/stable/cgi-bin/newcity.cgi	(revision 444)
+++ branches/stable/cgi-bin/newcity.cgi	(revision 445)
@@ -8,5 +8,5 @@
 # Last update by $Author$
 ###
-# Copyright (C) 2004,2005 - Kris Deugau
+# Copyright (C) 2004-2010 - Kris Deugau
 
 use strict;
@@ -15,5 +15,4 @@
 use DBI;
 use CommonWeb qw(:ALL);
-use MyIPDB;
 #use POSIX qw(ceil);
 use NetAddr::IP;
@@ -21,5 +20,10 @@
 use Sys::Syslog;
 
-openlog "IPDB","pid","local2";
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
+use MyIPDB;
+
+openlog "IPDB","pid","$IPDB::syslog_facility";
 
 # Collect the username from HTTP auth.  If undefined, we're in a test environment.
@@ -48,5 +52,5 @@
 if ($sth->err) {
   print "Error adding city to database: ".$sth->errstr;
-  mailNotify('kdeugau@vianet.ca',"IPDB city add failure",
+  mailNotify($dbh, 'f:nci', "IPDB city add failure",
 	"$authuser could not add city '$webvar{city}' to database: ".$sth->errstr);
   syslog "err", "$authuser could not add city '$webvar{city}' to database: ".$sth->errstr;
Index: branches/stable/cgi-bin/newnode.cgi
===================================================================
--- branches/stable/cgi-bin/newnode.cgi	(revision 444)
+++ branches/stable/cgi-bin/newnode.cgi	(revision 445)
@@ -15,11 +15,14 @@
 use DBI;
 use CommonWeb qw(:ALL);
-use MyIPDB;
 #use POSIX qw(ceil);
 use NetAddr::IP;
-
 use Sys::Syslog;
 
-openlog "IPDB","pid","local2";
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
+use MyIPDB;
+
+openlog "IPDB","pid","$IPDB::syslog_facility";
 
 # Collect the username from HTTP auth.  If undefined, we're in a test environment.
@@ -45,5 +48,5 @@
 if ($sth->err) {
   print "Error adding node to database: ".$sth->errstr;
-  mailNotify('noc@example.com',"IPDB node add failure",
+  mailNotify($dbh, 'f:nno', "IPDB node add failure",
 	"$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr);
   syslog "err", "$authuser could not add node '$webvar{nodename}','$webvar{type}' to database: ".$sth->errstr;
Index: branches/stable/cgi-bin/search.cgi
===================================================================
--- branches/stable/cgi-bin/search.cgi	(revision 444)
+++ branches/stable/cgi-bin/search.cgi	(revision 445)
@@ -9,5 +9,5 @@
 # Last update by $Author$
 ###
-# Copyright 2005,2006 Kris Deugau
+# Copyright 2005-2010 - Kris Deugau
 
 use strict;		
@@ -16,11 +16,25 @@
 use DBI;
 use CommonWeb qw(:ALL);
-use MyIPDB;
 use POSIX qw(ceil);
 use NetAddr::IP;
 
-# Don't need a username or syslog here.  syslog left active for debugging.
+# don't remove!  required for GNU/FHS-ish install from tarball
+##uselib##
+
+use MyIPDB;
+
+# Don't formally need a username or syslog here.  syslog left active for debugging.
 use Sys::Syslog;
-openlog "IPDBsearch","pid","local2";
+openlog "IPDBsearch","pid","$IPDB::syslog_facility";
+
+# ... but we do *use* the username on ACLs now.
+# Collect the username from HTTP auth.  If undefined, we're in
+# a test environment, or called without a username.
+my $authuser;
+if (!defined($ENV{'REMOTE_USER'})) {
+  $authuser = '__temptest';
+} else {
+  $authuser = $ENV{'REMOTE_USER'};
+}
 
 # Why not a global DB handle?  (And a global statement handle, as well...)
@@ -49,5 +63,8 @@
 }
 
-printHeader('Searching...');
+# Headerize!  Make sure we replace the $$EXTRA0$$ bit as needed.
+printHeader('', ($IPDBacl{$authuser} =~ /a/ ?
+	'<td align=right><a href="/ip/cgi-bin/main.cgi?action=assign">Add new assignment</a></td>' : ''
+	));
 
 if ($webvar{stype} eq 'q') {
@@ -148,5 +165,5 @@
   if ($webvar{cidr} eq '') { # We has a blank CIDR.  Ignore it.
   } elsif ($webvar{cidr} =~ /\//) {
-    # 209.91.179/26 should show all /26 subnets in 209.91.179
+    # 192.168.179/26 should show all /26 subnets in 192.168.179
     my ($net,$maskbits) = split /\//, $webvar{cidr};
     if ($webvar{cidr} =~ /^(\d{1,3}\.){3}\d{1,3}\/\d{2}$/) {
@@ -340,5 +357,5 @@
     $query =~ s/\s+//g;
     if ($query =~ /\//) {
-      # 209.91.179/26 should show all /26 subnets in 209.91.179
+      # 192.168.179/26 should show all /26 subnets in 192.168.179
       my ($net,$maskbits) = split /\//, $query;
       if ($query =~ /^(\d{1,3}\.){3}\d{1,3}\/\d{2}$/) {
Index: branches/stable/cgi-bin/updatecust.php
===================================================================
--- branches/stable/cgi-bin/updatecust.php	(revision 444)
+++ 	(revision )
@@ -1,84 +1,0 @@
-<?php
-/* updatecust.php
-** Stuff updated cust data into db
-*****
-** SVN revision info
-** $Date$
-** SVN revision $Rev$
-** Last update by $Author$
-*****
-** Copyright (C) 2006 - Kris Deugau
-*/
-
-  $db_conn = pg_connect("dbname=ipdb user=ipdb password=ipdbpwd");
-
-  if (!$db_conn) {
-    echo ("<H1>Failed connection to db ipdb.  Can't continue.</H1>");
-    exit;
-  }
-
-  $custid = $_REQUEST['custid'];
-  if (isset($_REQUEST['deletecust'])) {
-    print "<html><head><title>Deleting $custid from WHOIS</title></head><body>\n".
-	"<h2>Deleting $custid from WHOIS</h2>\n".
-	"<a href=\"/ip/cgi-bin/admin.cgi\">Back</a> to admin<br>\n".
-	"<a href=\"/ip/cgi-bin/list-cust.php\">Back</a> to WHOIS customer list\n";
-    $qu = pg_exec ("DELETE FROM customers WHERE custid='$custid'");
-    if (!$qu) {
-      print "Error deleting $custid.  Mail Kris.\n";
-    }
-    print "</body></html>\n";
-    exit;
-  }
-?>
-<html><head>
-<title>[IPDB admin] Updating WHOIS data</title>
-</head>
-<body>
-<h2>Updating WHOIS data for <? print $custid; ?></h2>
-<a href="/ip/cgi-bin/admin.cgi">Back</a> to admin<br>
-<a href="/ip/cgi-bin/list-cust.php">Back</a> to WHOIS customer list
-<?
-
-// snag form data into local vars.  Not being excessively paranoid because we're
-// buried deep and this is a hack anyway.
-
-  $name = $_REQUEST['name'];
-  $addr1 = $_REQUEST['addr1'];
-  $addr2 = $_REQUEST['addr2'];
-  $city = $_REQUEST['city'];
-  $prov = $_REQUEST['prov'];
-  $country = $_REQUEST['country'];
-  $pocode = $_REQUEST['pocode'];
-  $phone = $_REQUEST['phone'];
-  $tech = $_REQUEST['tech'];
-  $abuse = $_REQUEST['abuse'];
-  $admin = $_REQUEST['admin'];
-  $rdns = $_REQUEST['rdns'];
-  $special = $_REQUEST['special'];
-
-  $qu = pg_exec ($db_conn, "UPDATE customers SET name='$name',street='$addr1',street2='$addr2',".
-		"city='$city',province='$prov',country='$country',pocode='$pocode',phone='$phone',".
-		"tech_handle='$tech',abuse_handle='$abuse',admin_handle='$admin',".
-		"def_rdns='$rdns',special='$special' WHERE custid='$custid'");
-
-  echo "<table border=2 cellpadding=2>".
-	"<tr><td align=right>CustID</td><td>$custid</td></tr>\n".
-	"<tr><td>Name</td><td>$name</td></tr>\n".
-	"<tr><td>Street address</td><td>$addr1</td></tr>\n".
-	"<tr><td>Address 2</td><td>$addr2</td></tr>\n".
-	"<tr><td>City</td><td>$city</td></tr>\n".
-	"<tr><td>Province</td><td>$prov</td></tr>\n".
-	"<tr><td>Country</td><td>$country</td></tr>\n".
-	"<tr><td>Postal code</td><td>$pocode</td></tr>\n".
-	"<tr><td>Phone</td><td>$phone</td></tr>\n".
-	"<tr><td>Tech handle</td><td>$tech</td></tr>\n".
-	"<tr><td>Abuse handle</td><td>$abuse</td></tr>\n".
-	"<tr><td>Admin handle</td><td>$admin</td></tr>\n".
-	"<tr><td>Default rDNS</td><td>$rdns</td></tr>\n".
-	"<tr><td>\"Special\"</td><td><pre>$special</pre></td></tr>\n".
-	"</table>\n";
-
-?>
-</body>
-</html>
Index: branches/stable/changes.html
===================================================================
--- branches/stable/changes.html	(revision 444)
+++ 	(revision )
@@ -1,46 +1,0 @@
-<html><head>
-
-<title>IP Database</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-
-<link rel="stylesheet" type="text/css" href="/ip/ipdb.css" />
-<link rel="stylesheet" type="text/css" href="/ip/local.css" />
-
-</head>
-<body>
-
-<table class="regular">
-
-<tr><td class="heading" colspan=2>Changes to the IPDB</td><tr>
-
-<tr class="color2">
-<td valign=top>03/10/2005</td>
-<td>Finally!  Support for "container"/"reserve" netblocks to make tracking superblocks like
-209.91.191.0/24 easier.  Also supports "dynamically routed DSL netblocks";  ie,
-netblock-aligned chunks of static DSL IPs with netblock-ish subnet masks such as
-209.91.186.0/25.
-</td></tr>
-<tr class="color1">
-<td valign=top>02/09/2005</td>
-<td>Pool handling has been cleaned up - all PPP-ish pools (modem, DSL, WiFi) now generate a
-full list of IPs rather than reserving the network, gateway, and broadcast IPs necessary on
-a "real" subnet.  They will also not display this incorrect and useless information.
-</td></tr>
-<tr class="color2">
-<td valign=top>01/27/2005</td>
-<td>New cities/locations can now be added to the database here.
-</td></tr>
-<tr class="color1">
-<td valign=top>11/30/2004</td>
-<td>Overhauled the city listings;  they should be somewhat more complete now.  Still needs a
-mechanism to easily add new cities.
-</td></tr>
-<tr class="color2">
-<td valign=top>11/26/2004</td>
-<td>Allocating a static IP is now a little different.  Use the "Customer Location" field to
-enter the customer's actual city, and use the "Route from/through" field to pick the POP or
-cable node the IP should come from.
-</td></tr>
-</table>
-
-
-</body></html>
Index: branches/stable/footer.inc
===================================================================
--- branches/stable/footer.inc	(revision 444)
+++ branches/stable/footer.inc	(revision 445)
@@ -9,7 +9,8 @@
   <tr>
     <td nowrap="" width="0" height="0" valign="top"> 
-      <div align="right"><font face="Arial, Helvetica, sans-serif" size="1">contact: 
-        <a href="mailto:kdeugau@deepnet.cx">kdeugau@deepnet.cx</a> - (c) 2004 <a href="http://www.deepnet.cx/" target="_blank">deepnet</a><br>
-Written for standards-based browsers (eg <a href="http://www.netscape.com">Netscape</a>/<a href="http://www.mozilla.org">Mozilla</a>)</font></div>
+      <div align="right"><font face="Arial, Helvetica, sans-serif" size="1"> DeepNet
+ <a href="http://projects.deepnet.cx/trac/ipdb" target="_blank">IP Database</a> |
+ Copyright 2004-2010 <a href="mailto:kdeugau@deepnet.cx">Kris Deugau</a><br>
+Written for standards-based browsers (eg <a href="http://www.mozilla.org">Mozilla</a>)</font></div>
     </td>
   </tr>
Index: branches/stable/header.inc
===================================================================
--- branches/stable/header.inc	(revision 444)
+++ branches/stable/header.inc	(revision 445)
@@ -49,6 +49,6 @@
 <input type="button" value=" Help? " onclick="openHelp()" class="regular">
 </td><td width=10></td><td><a href="/ip/cgi-bin/search.cgi">Complex Search</a></td>
+$$EXTRA0$$
 <td width=60></td>
-$$EXTRA0$$
 </form>
 </tr>
@@ -62,6 +62,5 @@
 </tbody></table>
 <table width="98%" border=0><tr><td align=right>
-<a href="/ip/cgi-bin/main.cgi?action=nodesearch">Find by connection point</a>&nbsp; &nbsp;
-<a href="javascript:popNotes('/ip/changes.html')">Recent Changes</a>
+<a href="/ip/cgi-bin/main.cgi?action=nodesearch">Find by connection point</a>
 </td></tr></table>
 <br>
Index: branches/stable/help.html
===================================================================
--- branches/stable/help.html	(revision 444)
+++ branches/stable/help.html	(revision 445)
@@ -14,27 +14,26 @@
 
 <tr class="color1">
-<td>IP blocks</td><td>209.91.128 or 209.</td>
+<td>IP blocks</td><td>192.168.28 or 192.</td>
 <td>Lists all alloctions starting with that set of octets.  Note that matches on the
 first octet MUST include the period to be considered an IP search.</td>
 </tr>
 <tr class="color2">
-<td>CIDR blocks</td><td>209.92.128/30</br>or
-209.92.128.0/30</td><td>Lists all /30's beginning with 209.91.128 or checks for an
-exact match for 209.92.128.0/30 respectively</td>
+<td>CIDR blocks</td><td>192.168.28/30</br>or
+192.168.28.0/30</td><td>Lists all /30's beginning with 192.168.28 or checks for an
+exact match for 192.168.28.0/30 respectively</td>
 </tr>
 <tr class="color1">
-<td>IP address</td><td>209.92.128.30</td><td>Finds the alloction that IP is a
+<td>IP address</td><td>192.168.28.30</td><td>Finds the alloction that IP is a
 part of (if any)</td>
 </tr>
 <tr class="color2">
-<td>Customer ID:</td><td>705 or 6137328844 or 503101</td><td>Find all alloctions to that
-customer. Matches on prefix (area code, area code + exchange, etc).  Searches old as well as 
-new CustIDs.
+<td>Customer ID:</td><td>123456</td><td>Find all alloctions to that
+customer.  Customer IDs are assumed to be numeric for this search.
 </td>
 </tr>
 <tr class="color1">
-<td>Description:</td><td>cable or efni</td><td>Find all allocations with the search term in
+<td>Description:</td><td>cable or BigCustomer</td><td>Find all allocations with the search term in
 the description.  Note that searches for CustIDs with letters will fall under this category
-until CustIDs are all-numeric.</td>
+unless CustIDs are all-numeric.</td>
 </tr>
 
Index: branches/stable/ipdb.spec
===================================================================
--- branches/stable/ipdb.spec	(revision 445)
+++ branches/stable/ipdb.spec	(revision 445)
@@ -0,0 +1,87 @@
+# spec file for IPDB
+# $Id$
+
+%define errata 99
+
+# A collection of magic to set the release "number" such that dist upgrades will, erm, upgrade.
+%if %{?debdist:0}%{?!debdist:1}
+%define debdist etch
+%endif
+%if "%{debdist}" == "sarge"
+%define errata 0
+%endif
+%if "%{debdist}" == "dapper"
+%define errata 1
+%endif
+%if "%{debdist}" == "etch"
+%define errata 2
+%endif
+%if "%{debdist}" == "lenny"
+%define errata 3
+%endif
+%if "%{debdist}" == "squeeze"
+%define errata 4
+%endif
+%if %{?relnum:0}%{?!relnum:1}
+%define relnum 1
+%endif
+
+%define release %{relnum}.%{errata}%{debdist}
+
+Summary: IP Database
+Name: ipdb
+Version: #VERSION#
+Release: %{release}
+Group: Applications/System
+Source: ipdb-#VERSION#.tar.gz
+Packager: Kris Deugau <kdeugau@deepnet.cx>
+BuildRoot: /var/tmp/%{name}-%{version}
+License: GPL 3+
+BuildArch: noarch
+Requires: perl(NetAddr::IP) >= 4, perl(DBD:Pg)
+%if %{_vendor} == "debbuild"
+Recommends: perl(Sys::SigAction)
+%endif
+
+%description
+A web-based IP address allocation management tool
+
+%prep
+%setup
+
+%build
+
+%install
+# le sigh.  rpm's makeinstall macro includes the buildroot in the dirs, so it will break here.  :/
+make \
+        prefix=%{_prefix} \
+        exec_prefix=%{_exec_prefix} \
+        bindir=%{_bindir} \
+        sbindir=%{_sbindir} \
+        sysconfdir=%{_sysconfdir} \
+        datadir=%{_datadir} \
+        includedir=%{_includedir} \
+        libdir=%{_libdir} \
+        libexecdir=%{_libexecdir} \
+        localstatedir=%{_localstatedir} \
+        sharedstatedir=%{_sharedstatedir} \
+        mandir=%{_mandir} \
+        infodir=%{_infodir} \
+  install DESTDIR=$RPM_BUILD_ROOT
+
+%clean
+if [ "$RPM_BUILD_ROOT" != "/" ]; then
+  rm -rf $RPM_BUILD_ROOT
+fi
+
+%files
+%{_libdir}/ipdb
+%attr(-,-,0755) %{_libdir}/ipdb/cgi-bin/*.cgi
+%attr(-,-,0755) %{_libdir}/ipdb/cgi-bin/*.pl
+%attr(-,-,0755) %{_libdir}/ipdb/cgi-bin/extras/*.pl
+%config %{_sysconfdir}/ipdb/MyIPDB.pm
+%{_sysconfdir}/ipdb
+
+%changelog
+* Mon Jun 28 2010  Kris Deugau <kdeugau@deepnet.cx> 2.6-1
+- Initial package
