[
  {
    "path": ".gitignore",
    "content": "# Created by .ignore support plugin (hsz.mobi)\ncerts/*\n1.tgz\n.idea\n"
  },
  {
    "path": "LICENSE",
    "content": "GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    {one line to give the program's name and a brief idea of what it does.}\n    Copyright (C) {year}  {name of author}\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    {project}  Copyright (C) {year}  {fullname}\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>."
  },
  {
    "path": "README.md",
    "content": "## Exchange_proxy\n\nExchange_proxy是由go语言开发的Exchange安全代理，可以将内网的Exchange服务器的https服务安全地发布出去，\n支持的功能如下：\n\n- WEB端增加OTP二次认证\n- 手机端增加设备激活绑定的功能 \n- 屏蔽了PC端的EWS协议\n\n在使用该系统前，需要确保有以下基础设施的接口，并完成与代理的对接：\n\n- OTP动态口令系统\n- 短信发送接口\n- 通过员工姓名查询员工手机号的接口\n\n以上接口准备并对接完成后，正确配置conf/app.ini即可启动代理服务器了。\n\n```ini\n[mail]\nhosts = mail.xiaomi.com,mail.sec.lu\nbackend = https://10.10.10.10\nport = 443\nssl = true\ncert = certs/ca.crt\nkey = certs/ca.key\n; debug level: Fatal, Error, Warn, Info, Debug\ndebug_level = info\n\n[redis]\nhost = 10.10.10.20\nport = 6379\ndb = 0\npassword = redis_passw0rd\n\n[otp]\nurl = https://otp_api_url/chk_otp\n\n[sms]\nurl = http://sms_api_url/api/send_sms\nheader = X-SMS-Token\nkey = token\n\n[user_info]\nuser_phone = http://hr_api_url/findMobile\nactive_url = https://mail.sec.lu/a/\n\n```\n\n配置文件说明：\n\n- mail节下的配置项是配置邮箱服务器本身的\n    - hosts表示邮箱域名，支持配置多个用英文逗号分割的域名\n    - backend表示邮箱服务器地址\n    - ssl表示是否启用https，必须设为true\n    - cert和key分别表示证书的公、私钥，与nginx的证书完全兼容\n    - debug_level表示日志级别，默认为info级别\n\n- redis节表示redis服务器的配置\n- otp节为动态口令检测API的URL\n- sms节表示短信接口的API\n- user_info节下的user_phone表示查找手机的接口，active_url表示手机中激活连接的URL\n\n设置好配置文件后，可通过`./main`直接启动代理服务器，如下图所示：\n![](http://docs.xsec.io/images/mail_proxy/mail_proxy041.png)\n\nWEB通过外网访问WEB端时，要求必须输入正确的OTP口令才可以登录，如下图所示：\n![](http://docs.xsec.io/images/mail_proxy/mail_proxy03.png)\n\n通过手机端访问时，只有通过短信中的提示激活后，方可收发邮件，如下图所示：\n\n- 收到激活短信 \n![](http://docs.xsec.io/images/mail_proxy/mail_proxy04.png)\n\n- 激活确认页面\n\n![](http://docs.xsec.io/images/mail_proxy/mail_proxy05.png)\n\n- 激活成功页面\n![](http://docs.xsec.io/images/mail_proxy/mail_proxy06.png)\n\n正式上线之前，最好提供相应的管理后台并与内网的管理系统对接，邮件代理管理后台提供以下功能：\n\n- 管理员可查看、修改每个用户的账户与设备状态\n- 管理员可查看每个设备的激活进程，方便故障排查\n- 用户也可自行管理自己的设备\n\n设备数据保存在redis中，用go/python/php等语言都可以实现，我就不单独提供了。\n\n代理系统的进程可以托管在supervisor或god中，部署了该系统后，可以解决邮件服务器手机端与WEB端的安全，目前的开源版本没有电脑端的安全代理功能，建议在PC端收发邮件时拨入VPN，或者在电脑中用BlueMail客户端收发邮件。"
  },
  {
    "path": "conf/app.ini",
    "content": "[mail]\nhosts = mail.xiaomi.com,mail.sec.lu\nbackend = https://10.10.10.10\nport = 443\nssl = true\ncert = certs/ca.crt\nkey = certs/ca.key\n; debug level: Fatal, Error, Warn, Info, Debug\ndebug_level = info\n\n[redis]\nhost = 10.10.10.20\nport = 6379\ndb = 0\npassword = redis_passw0rd\n\n[otp]\nurl = https://otp_api_url/chk_otp\n\n[sms]\nurl = http://sms_api_url/api/send_sms\nheader = X-SMS-Token\nkey = token\n\n[user_info]\nuser_phone = http://hr_api_url/findMobile\nactive_url = https://mail.sec.lu\n\n"
  },
  {
    "path": "go.mod",
    "content": "module exchange_proxy\n\nrequire (\n\tgithub.com/go-redis/redis v6.15.1+incompatible\n\tgithub.com/gorilla/websocket v1.4.0 // indirect\n\tgithub.com/magicmonty/activesync-go v0.0.0-20121203123100-40f879136bcb\n\tgithub.com/magicmonty/wbxml-go v0.0.0-20121123081138-2c61d93f134b\n\tgithub.com/mailgun/timetools v0.0.0-20170619190023-f3a7b8ffff47 // indirect\n\tgithub.com/mattn/go-colorable v0.1.1 // indirect\n\tgithub.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect\n\tgithub.com/onsi/ginkgo v1.7.0 // indirect\n\tgithub.com/onsi/gomega v1.4.3 // indirect\n\tgithub.com/sirupsen/logrus v1.3.0\n\tgithub.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect\n\tgithub.com/toolkits/slice v0.0.0-20141116085117-e44a80af2484\n\tgithub.com/vulcand/oxy v0.0.0-20181130145254-c34b0c501e43\n\tgithub.com/x-cray/logrus-prefixed-formatter v0.5.2\n\tgolang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect\n\tgopkg.in/ini.v1 v1.42.0\n\tgopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect\n)\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=\ngithub.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=\ngithub.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=\ngithub.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=\ngithub.com/go-redis/redis v6.15.1+incompatible h1:BZ9s4/vHrIqwOb0OPtTQ5uABxETJ3NRuUNoSUurnkew=\ngithub.com/go-redis/redis v6.15.1+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=\ngithub.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=\ngithub.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=\ngithub.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=\ngithub.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=\ngithub.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=\ngithub.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=\ngithub.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=\ngithub.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=\ngithub.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=\ngithub.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=\ngithub.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=\ngithub.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=\ngithub.com/magicmonty/activesync-go v0.0.0-20121203123100-40f879136bcb h1:uDfElOCEXqYB1xPY5qxjJwJShKdSY5LiJMWfm6S5QVc=\ngithub.com/magicmonty/activesync-go v0.0.0-20121203123100-40f879136bcb/go.mod h1:pvQDeG1h7YU4W6x4xqPOHVLjs4UQ/Sk4X5WCrsjIcPM=\ngithub.com/magicmonty/wbxml-go v0.0.0-20121123081138-2c61d93f134b h1:dbUq4tyYWJbb+uusWCXag8wdf+fqg7hO0oSp8eC0Ypg=\ngithub.com/magicmonty/wbxml-go v0.0.0-20121123081138-2c61d93f134b/go.mod h1:k5Vtn0pkLSLO8fbQWknTKf03dbWHM29tcbEZ7+4RVlQ=\ngithub.com/mailgun/timetools v0.0.0-20170619190023-f3a7b8ffff47 h1:jlyJPTyctWqANbaxi/nXRrxX4WeeAGMPaHPj9XlO0Rw=\ngithub.com/mailgun/timetools v0.0.0-20170619190023-f3a7b8ffff47/go.mod h1:RYmqHbhWwIz3z9eVmQ2rx82rulEMG0t+Q1bzfc9DYN4=\ngithub.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=\ngithub.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=\ngithub.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw=\ngithub.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=\ngithub.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=\ngithub.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=\ngithub.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=\ngithub.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=\ngithub.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=\ngithub.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=\ngithub.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=\ngithub.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=\ngithub.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=\ngithub.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=\ngithub.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=\ngithub.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=\ngithub.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=\ngithub.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa h1:E+gaaifzi2xF65PbDmuKI3PhLWY6G5opMLniFq8vmXA=\ngithub.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU=\ngithub.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=\ngithub.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=\ngithub.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=\ngithub.com/toolkits/slice v0.0.0-20141116085117-e44a80af2484 h1:ERmNDajjCusGqV3uLhlHhRNpvQiGM1S6pd0RSe3LP+w=\ngithub.com/toolkits/slice v0.0.0-20141116085117-e44a80af2484/go.mod h1:2ZKxkgYEh//pN54EFSkJBak63sg0LxQQFjQmpEwxQx0=\ngithub.com/vulcand/oxy v0.0.0-20181130145254-c34b0c501e43 h1:2+LBGeYYE8JgE1UCKx+qRpoFyvF4NdGQpR8bFCCPfEw=\ngithub.com/vulcand/oxy v0.0.0-20181130145254-c34b0c501e43/go.mod h1:giFb8dicROVdV5W0HXlA5siMBLWKnVXZlkA4Y5ZIzrY=\ngithub.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=\ngithub.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=\ngolang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=\ngolang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=\ngolang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=\ngolang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jYthdXAmZ6PP+meazmaU=\ngolang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=\ngolang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=\ngolang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=\ngolang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=\ngolang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=\ngolang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=\ngolang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\ngopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=\ngopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=\ngopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=\ngopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=\ngopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk=\ngopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=\ngopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU=\ngopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=\ngopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=\ngopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=\ngopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=\ngopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=\n"
  },
  {
    "path": "logger/log.go",
    "content": "package logger\n\nimport (\n\t\"github.com/sirupsen/logrus\"\n\t\"github.com/x-cray/logrus-prefixed-formatter\"\n)\n\nvar (\n\tLog *logrus.Entry\n)\n\nfunc init() {\n\tlogger := logrus.New()\n\tlogger.Formatter = new(prefixed.TextFormatter)\n\tLog = logger.WithFields(logrus.Fields{\"prefix\": \"exchange proxy\"})\n\tLog.Logger.SetLevel(logrus.InfoLevel)\n}\n"
  },
  {
    "path": "main.go",
    "content": "package main\n\nimport (\n\t\"exchange_proxy/logger\"\n\t\"exchange_proxy/plugins/active_sync\"\n\t\"exchange_proxy/plugins/owa\"\n\t\"exchange_proxy/plugins/web\"\n\t\"exchange_proxy/vars\"\n\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/toolkits/slice\"\n)\n\nfunc main() {\n\tmux := http.NewServeMux()\n\tstaticFiles := http.FileServer(http.Dir(\"plugins/web/public\"))\n\tmux.Handle(\"/static/\", http.StripPrefix(\"/static/\", staticFiles))\n\tmux.HandleFunc(\"/\", owa.OwaHandler(owa.OwaRedirect))\n\tmux.HandleFunc(\"/owa/\", owa.OwaHandler(owa.OwaRedirect))\n\tmux.HandleFunc(\"/Microsoft-Server-ActiveSync\", active_sync.ActiveSyncHandler(active_sync.SyncRedirect))\n\tmux.HandleFunc(\"/a/\", web.Activation)\n\tmux.HandleFunc(\"/a/activedevice\", web.ActiveDevice)\n\tmux.HandleFunc(\"/a/ignoredevice\", web.IgnoreDevice)\n\n\tmux.HandleFunc(\"/EWS/\", web.NotFound)\n\tmux.HandleFunc(\"/ecp/\", web.NotFound)\n\tmux.HandleFunc(\"/rpc/\", web.NotFound)\n\tmux.HandleFunc(\"/Autodiscover/\", web.NotFound)\n\n\ts := &http.Server{\n\t\tAddr:    fmt.Sprintf(\":%v\", vars.MailConfig.Port),\n\t\tHandler: mux,\n\t}\n\n\tgo func() {\n\t\tlisten80Port()\n\t}()\n\n\tvar err error\n\tif vars.MailConfig.TLS {\n\t\terr = s.ListenAndServeTLS(vars.MailConfig.Cert, vars.MailConfig.Key)\n\t} else {\n\t\terr = s.ListenAndServe()\n\t}\n\tlogger.Log.Println(err)\n}\n\nfunc listen80Port() {\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tif slice.ContainsString(vars.MailConfig.Host, r.Host) {\n\t\t\tlogger.Log.Debugf(\"redirect http://%v -> https://%v\", r.Host, r.Host)\n\t\t\tw.Header().Set(\"Location\", fmt.Sprintf(\"https://%v\", r.Host))\n\t\t\tw.WriteHeader(302)\n\t\t}\n\t})\n\n\ts := &http.Server{\n\t\tAddr:    \":80\",\n\t\tHandler: mux,\n\t}\n\n\t_ = s.ListenAndServe()\n}\n"
  },
  {
    "path": "models/device.go",
    "content": "package models\n\nimport (\n\t\"exchange_proxy/util/wbxml\"\n\t\"exchange_proxy/vars\"\n\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"strconv\"\n)\n\ntype (\n\t// 移动设备信息\n\tDevice struct {\n\t\tDeviceType string `json:\"device_type\"`\n\t\tDeviceId   string `json:\"device_id\"`\n\t\tUser       string `json:\"user\"`\n\t\tState      int    `json:\"state\"`\n\t\tTime       int64  `json:\"time\"`\n\t}\n\tUserPhone struct {\n\t\tCode int    `json:\"code\"`\n\t\tData string `json:\"data\"`\n\t}\n)\n\n// 注册新设备，默认为未激活状态\nfunc NewDevice(user string, device Device) (err error) {\n\tInitRedis()\n\tv := make(map[string]interface{})\n\tv[\"user_state\"] = 0\n\tinfo, _ := json.Marshal(device)\n\tv[device.DeviceId] = string(info)\n\tkey := fmt.Sprintf(\"iuser_%v\", user)\n\t_, err = vars.RedisInstance.HMSet(key, v).Result()\n\treturn err\n}\n\n// 新建用户，默认为激活状态\nfunc NewUser(user string) (err error) {\n\tInitRedis()\n\tkey := fmt.Sprintf(\"iuser_%v\", user)\n\tv := make(map[string]interface{})\n\tv[\"user_state\"] = 0\n\t_, err = vars.RedisInstance.HMSet(key, v).Result()\n\treturn err\n}\n\n// 获取用户状态：激活与锁定\nfunc GetUserState(user string) (userState int, err error) {\n\tuserState = -1\n\tInitRedis()\n\tkey := fmt.Sprintf(\"iuser_%v\", user)\n\tret, err := vars.RedisInstance.HGet(key, \"user_state\").Result()\n\tuserState, _ = strconv.Atoi(ret)\n\treturn userState, err\n}\n\n// 获取设备状态：激活、未激活、锁定等\nfunc GetDeviceState(user, deviceId string) (state int) {\n\tstate = -1\n\tInitRedis()\n\tkey := fmt.Sprintf(\"iuser_%v\", user)\n\tret, err := vars.RedisInstance.HGet(key, deviceId).Result()\n\tif err == nil {\n\t\tvar device Device\n\t\terr := json.Unmarshal([]byte(ret), &device)\n\t\tif err == nil {\n\t\t\tstate = device.State\n\t\t}\n\t}\n\treturn state\n}\n\n// 获取设备信息\nfunc GetDeviceInfo(user, deviceId string) (err error, deviceInfo Device) {\n\tInitRedis()\n\tkey := fmt.Sprintf(\"iuser_%v\", user)\n\tinfo, err := vars.RedisInstance.HGet(key, deviceId).Result()\n\tif err == nil {\n\t\terr = json.Unmarshal([]byte(info), &deviceInfo)\n\t}\n\treturn err, deviceInfo\n}\n\n// 设置设备的状态：激活，锁定\n// ALLOW = 0\n// NEW = 1\n// LOCKED = 2\n// BLOCK = 3\nfunc SetDeviceState(user, deviceId string, state int) (err error) {\n\tInitRedis()\n\tkey := fmt.Sprintf(\"iuser_%v\", user)\n\terr, deviceInfo := GetDeviceInfo(user, deviceId)\n\tif err == nil {\n\t\tdeviceInfo.State = state\n\t\tinfo, err := json.Marshal(deviceInfo)\n\t\tv := make(map[string]interface{})\n\t\tv[deviceId] = string(info)\n\t\tif err == nil {\n\t\t\t_, err = vars.RedisInstance.HMSet(key, v).Result()\n\t\t}\n\t}\n\treturn err\n}\n\n// 激活设备\nfunc ActiveDevice(user, deviceId string) (err error) {\n\tstate := 0\n\terr = SetDeviceState(user, deviceId, state)\n\treturn err\n}\n\n// 恢复设备\nfunc RestoreDevice(user, deviceId string) (err error) {\n\tstate := 1\n\terr = SetDeviceState(user, deviceId, state)\n\treturn err\n}\n\n// 锁定设备\nfunc LockDevice(user, deviceId string) (err error) {\n\tstate := 2\n\terr = SetDeviceState(user, deviceId, state)\n\treturn err\n}\n\n// 忽略设备\nfunc IgnoreDevice(user, deviceId string) (err error) {\n\tstate := 3\n\terr = SetDeviceState(user, deviceId, state)\n\treturn err\n}\n\n// 指令检测\nfunc CheckCmd(cmd string, cmdType map[string]bool) (result bool) {\n\tif cmdType[cmd] {\n\t\tresult = true\n\t}\n\treturn result\n}\n\n// 存储手机设备的信息\nfunc SetDeviceInfo(deviceId string, deviceInfo wbxml.DeviceInfo) (err error) {\n\tm := make(map[string]interface{})\n\tdeviceInfoStr, _ := json.Marshal(deviceInfo)\n\tm[deviceId] = string(deviceInfoStr)\n\tInitRedis()\n\tkey := \"DEVICE_INFO_XSEC_MAIL\"\n\t_, err = vars.RedisInstance.HMSet(key, m).Result()\n\treturn err\n}\n\n// 通过设备ID查询手机设备的信息\nfunc GetDeviceInfoByDeviceId(deviceId string) (deviceInfo wbxml.DeviceInfo, err error) {\n\tInitRedis()\n\tkey := \"DEVICE_INFO_XSEC_MAIL\"\n\tdeviceInfoStr, err := vars.RedisInstance.HGet(key, deviceId).Result()\n\terr = json.Unmarshal([]byte(deviceInfoStr), &deviceInfo)\n\treturn deviceInfo, err\n}\n\n// 获取设备列表\nfunc GetDeviceList(username string) (devices []string, err error) {\n\tkey := fmt.Sprintf(\"iuser_%v\", username)\n\tInitRedis()\n\tdevices, err = vars.RedisInstance.HVals(key).Result()\n\treturn devices, err\n}\n\n// 获取设备数\nfunc GetDeviceNum(username string) (n int) {\n\tdevices, err := GetDeviceList(username)\n\tif err == nil {\n\t\tn = len(devices)\n\t}\n\treturn n\n}\n"
  },
  {
    "path": "models/redis.go",
    "content": "package models\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"exchange_proxy/logger\"\n\t\"exchange_proxy/vars\"\n\n\t\"github.com/go-redis/redis\"\n)\n\nfunc init() {\n\tInitRedis()\n}\n\nfunc InitRedis() () {\n\tvar err error\n\tvars.RedisInstance, err = NewRedisClient(vars.RedisConf.Host, vars.RedisConf.Port, vars.RedisConf.Db, vars.RedisConf.Password)\n\tif err != nil {\n\t\tlogger.Log.Errorf(\"connect redis failed, err: %v\", err)\n\t}\n}\n\nfunc NewRedisClient(host string, port int, db int, password string) (*redis.Client, error) {\n\tclient := redis.NewClient(&redis.Options{\n\t\tAddr:        fmt.Sprintf(\"%v:%v\", host, port),\n\t\tPassword:    password,    // no password set\n\t\tDB:          db,          // use default DB\n\t\tReadTimeout: time.Minute, // set timeout value = 60\n\t})\n\n\t_, err := client.Ping().Result()\n\treturn client, err\n}\n"
  },
  {
    "path": "plugins/active_sync/active_code.go",
    "content": "package active_sync\n\nimport (\n\t\"exchange_proxy/models\"\n\t\"exchange_proxy/util\"\n\t\"exchange_proxy/vars\"\n\t\"strings\"\n\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"time\"\n)\n\nfunc DoActiveDevice(user, deviceId, deviceType string, device models.Device) {\n\t_, isActive := GetDeviceActiveFlag(user, deviceId)\n\tif !isActive {\n\t\t// 设置进入设备激活流程的FLAG\n\t\tSetDeviceActiveFlag(user, deviceId)\n\t\t// 获取用户手机号\n\t\tphone, err := GetUserPhone(vars.UserPhoneUrl, user)\n\t\tif err == nil {\n\t\t\t// 生成激活码\n\t\t\t_, code := SetActiveCode(user, deviceId, device)\n\t\t\t// 发送激活码\n\t\t\tsmsStatus := SendCode(user, deviceId, deviceType, phone, code)\n\t\t\t// 发送成功的话删除已发送过的激活码\n\t\t\tif smsStatus {\n\t\t\t\t_ = DelActiveCodeFlag(user, deviceId)\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// logger.Log.Infof(\"%v, 已经激活过，忽略请求\", device)\n\t\t// 已经激活过，忽略请求\n\t}\n}\n\n// 获取设备激活标识\nfunc GetDeviceActiveFlag(username, deviceId string) (err error, result bool) {\n\tmodels.InitRedis()\n\tkey := fmt.Sprintf(\"active_%v_%v\", username, deviceId)\n\tv, err := vars.RedisInstance.Exists(key).Result()\n\tif v == 1 {\n\t\tresult = true\n\t}\n\t// logger.Log.Infof(\"key:%v, v: %v, err: %v, result: %v\", key, v, err, result)\n\treturn err, result\n}\n\n// 设置设备激活标识\nfunc SetDeviceActiveFlag(username, deviceId string) {\n\tmodels.InitRedis()\n\tkey := fmt.Sprintf(\"active_%v_%v\", username, deviceId)\n\t_, _ = vars.RedisInstance.Set(key, deviceId, 60*time.Second).Result()\n}\n\n// 激活码是否生成过，生成过的话返回老激活码\nfunc GetActiveCodeFlag(username, deviceId string) (has bool, code string) {\n\tkey := fmt.Sprintf(\"icodeF_%v_%v\", username, deviceId)\n\tmodels.InitRedis()\n\tret, err := vars.RedisInstance.Get(key).Result()\n\n\tif err == nil && ret != \"\" {\n\t\thas = true\n\t\tcode = ret\n\t}\n\treturn has, code\n}\n\n// 设置验证码的标识，判断是否生成过验证码，12小时后失效\nfunc SetActiveCodeFlag(username, deviceId, code string) {\n\tkey := fmt.Sprintf(\"icodeF_%v_%v\", username, deviceId)\n\tmodels.InitRedis()\n\tvars.RedisInstance.Set(key, code, 60*60*12*time.Second)\n}\n\n// 删除生成激活码的标识\nfunc DelActiveCodeFlag(username, deviceId string) (err error) {\n\tkey := fmt.Sprintf(\"icodeF_%v_%v\", username, deviceId)\n\tmodels.InitRedis()\n\t_, err = vars.RedisInstance.Del(key).Result()\n\treturn err\n}\n\n// 设置激活码的值及超时时间，该函数不对外公开\nfunc setActiveCode(device models.Device, code string) (err error) {\n\tkey := fmt.Sprintf(\"icode_%v\", code)\n\tdeviceStr, err := json.Marshal(device)\n\tv := fmt.Sprintf(\"%v-_-%v\", device.User, string(deviceStr))\n\tmodels.InitRedis()\n\t_, err = vars.RedisInstance.Set(key, v, 60*60*12*time.Second).Result()\n\treturn err\n}\n\n// 激活码保存到redis中，有效期为8小时，不会多次生成\nfunc SetActiveCode(username, deviceId string, device models.Device) (err error, code string) {\n\thas, oldCode := GetActiveCodeFlag(username, deviceId)\n\tif has {\n\t\tcode = oldCode\n\t\terr = setActiveCode(device, oldCode)\n\t} else {\n\t\tcode = util.GenerateAtiveCode(username, deviceId)\n\t\tSetActiveCodeFlag(username, deviceId, code)\n\t\terr = setActiveCode(device, code)\n\t}\n\treturn err, code\n}\n\n// 删除激活码\nfunc RemoveActiveCode(code string) (err error) {\n\tkey := fmt.Sprintf(\"icode_%v\", code)\n\tmodels.InitRedis()\n\t_, err = vars.RedisInstance.Del(key).Result()\n\treturn err\n}\n\n// 获取激活码的值\nfunc getActiveCodeValue(code string) (err error, has bool, user string, deviceInfo models.Device) {\n\tkey := fmt.Sprintf(\"icode_%v\", code)\n\tmodels.InitRedis()\n\tc, err := vars.RedisInstance.Get(key).Result()\n\tif err == nil {\n\t\tt := strings.Split(c, \"-_-\")\n\t\tif len(t) == 2 {\n\t\t\tuser = t[0]\n\t\t\tdeviceStr := t[1]\n\t\t\terr = json.Unmarshal([]byte(deviceStr), &deviceInfo)\n\t\t\tif err == nil {\n\t\t\t\thas = true\n\t\t\t}\n\t\t}\n\t}\n\treturn err, has, user, deviceInfo\n}\n\n// 检测激活码\nfunc CheckActiveCode(code string) (err error, has bool, user string, deviceInfo models.Device) {\n\terr, has, user, deviceInfo = getActiveCodeValue(code)\n\treturn err, has, user, deviceInfo\n}\n\n// 激活时，验证激活码\nfunc VerifyActiveCode(code string) (result bool, user string, device models.Device) {\n\terr, has, user, deviceInfo := CheckActiveCode(code)\n\tif err == nil && has {\n\t\tstatus := deviceInfo.State\n\t\tif status == 1 {\n\t\t\tresult = true\n\t\t}\n\t}\n\treturn result, user, deviceInfo\n}\n\n// 在激活流程中使用过激活码后重置激活码的状态，设为已激活并在2小时后自动删除\nfunc ResetActiveCodeStatus(code, username string, device models.Device, state int) (result bool, err error) {\n\tmodels.InitRedis()\n\tkey := fmt.Sprintf(\"icode_%v\", code)\n\tdevice.State = state\n\terr = setActiveCode(device, code)\n\tif err == nil {\n\t\tresult, err = vars.RedisInstance.Expire(key, 60*60*2*time.Second).Result()\n\t\terr = ResetSmsStatus(username, device.DeviceId)\n\t}\n\treturn result, err\n}\n"
  },
  {
    "path": "plugins/active_sync/active_sync.go",
    "content": "package active_sync\n\nimport (\n\t\"bytes\"\n\t\"crypto/tls\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\t\"strings\"\n\t\"time\"\n\n\t\"exchange_proxy/logger\"\n\t\"exchange_proxy/models\"\n\t\"exchange_proxy/util/wbxml\"\n\t\"exchange_proxy/vars\"\n\n\t\"github.com/toolkits/slice\"\n\t\"github.com/vulcand/oxy/forward\"\n\t\"github.com/vulcand/oxy/testutils\"\n)\n\nfunc filterCmd(resp *http.Response) (err error) {\n\tvar bodyBytes []byte\n\tbodyBytes, err = ioutil.ReadAll(resp.Request.Body)\n\t// 恢复Req.body的值给ParseForm函数使用\n\tresp.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))\n\tvalues := resp.Request.URL.Query()\n\tif len(values) == 4 {\n\t\tcmd := values[\"Cmd\"][0]\n\t\tmail := values[\"User\"][0]\n\t\tdeviceId := values[\"DeviceId\"][0]\n\t\tuser := \"\"\n\t\t// 取邮箱前缀\n\t\tu := strings.Split(mail, \"@\")\n\t\tif len(u) == 2 {\n\t\t\tuser = u[0]\n\t\t}\n\t\t// 取域的\\后面部分\n\t\tu1 := strings.Split(mail, \"\\\\\")\n\t\tif len(u1) == 2 {\n\t\t\tuser = u1[1]\n\t\t}\n\n\t\tdeviceState := models.GetDeviceState(user, deviceId)\n\t\tlogger.Log.Infof(\"in filterCmd, user: %v, deviceId: %v, deviceState: %v\", user, deviceId, deviceState)\n\t\t// 设备未激活时，过滤掉特定指令的返回值\n\t\tif deviceState != 0 {\n\t\t\tif models.CheckCmd(cmd, vars.ResponseCmds) {\n\t\t\t\tresp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(\"\")))\n\t\t\t}\n\t\t}\n\t}\n\n\t// 恢复Req.body的值传到下一个处理器中\n\tresp.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))\n\treturn err\n}\n\nfunc SyncRedirect(w http.ResponseWriter, req *http.Request) {\n\tif slice.ContainsString(vars.MailConfig.Host, req.Host) {\n\t\treq.URL = testutils.ParseURI(vars.MailConfig.Backend)\n\t\tvars.FwdSync.ServeHTTP(w, req)\n\t} else {\n\t\tw.WriteHeader(444)\n\t}\n}\n\nfunc ActiveSyncHandler(h http.HandlerFunc) http.HandlerFunc {\n\treturn func(w http.ResponseWriter, req *http.Request) {\n\n\t\tif vars.MailConfig.TLS {\n\t\t\tr := forward.RoundTripper(\n\t\t\t\t&http.Transport{\n\t\t\t\t\tTLSClientConfig: &tls.Config{InsecureSkipVerify: true},\n\t\t\t\t},\n\t\t\t)\n\t\t\t// 对手机设备的处理逻辑\n\t\t\tif strings.HasPrefix(req.RequestURI, \"/Microsoft-Server-ActiveSync\") {\n\t\t\t\tvalues := req.URL.Query()\n\t\t\t\tif len(values) > 0 {\n\t\t\t\t\tmail := values[\"User\"][0]\n\t\t\t\t\tdeviceId := values[\"DeviceId\"][0]\n\t\t\t\t\tdeviceType := values[\"DeviceType\"][0]\n\t\t\t\t\tcmd := values[\"Cmd\"][0]\n\n\t\t\t\t\tuser := \"\"\n\t\t\t\t\t// 取邮箱前缀\n\t\t\t\t\tu := strings.Split(mail, \"@\")\n\t\t\t\t\tif len(u) == 2 {\n\t\t\t\t\t\tuser = u[0]\n\t\t\t\t\t}\n\t\t\t\t\t// 取域的\\后面部分\n\t\t\t\t\tu1 := strings.Split(mail, \"\\\\\")\n\t\t\t\t\tif len(u1) == 2 {\n\t\t\t\t\t\tuser = u1[1]\n\t\t\t\t\t}\n\n\t\t\t\t\tdevice := models.Device{User: user, DeviceId: deviceId, DeviceType: deviceType,\n\t\t\t\t\t\tState: 1, Time: time.Now().Unix()}\n\n\t\t\t\t\t// 如果设备ID为0或为空，直接退出请求\n\t\t\t\t\tif len(deviceId) <= 1 {\n\t\t\t\t\t\tw.WriteHeader(444)\n\t\t\t\t\t}\n\n\t\t\t\t\t// 获取设备信息的详细信息\n\t\t\t\t\tvar bodyBytes []byte\n\t\t\t\t\tbodyBytes, err := ioutil.ReadAll(req.Body)\n\t\t\t\t\tif err == nil {\n\t\t\t\t\t\t// 判断大小，否则可能会把邮件的附件传进来处理\n\t\t\t\t\t\tif len(bodyBytes) < 500 {\n\t\t\t\t\t\t\tdeviceInfo, err := wbxml.Parse(bodyBytes)\n\t\t\t\t\t\t\tif err == nil && deviceInfo.Model != \"\" {\n\t\t\t\t\t\t\t\tlogger.Log.Debugf(\"deviceInfo: %v, err: %v\", deviceInfo, err)\n\t\t\t\t\t\t\t\t_ = models.SetDeviceInfo(deviceId, deviceInfo)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// 用完后恢复req.Body的值，否则之后的处理器不能再用了\n\t\t\t\t\treq.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))\n\n\t\t\t\t\tuserState, _ := models.GetUserState(user)\n\t\t\t\t\t// logger.Log.Infof(\"user: %v, state: %v\", user, userState)\n\t\t\t\t\t// 用户状态为1，表示已经锁定的账户，直接退出请求\n\t\t\t\t\tif userState == 1 {\n\t\t\t\t\t\tw.WriteHeader(444)\n\t\t\t\t\t} else if userState < 0 {\n\t\t\t\t\t\t_ = models.NewUser(user)\n\t\t\t\t\t}\n\n\t\t\t\t\tdeviceState := models.GetDeviceState(user, deviceId)\n\t\t\t\t\tlogger.Log.Debugf(\"user: %v, deviceId: %v, deviceState: %v, deviceType: %v, Cmd: %v\",\n\t\t\t\t\t\tuser, deviceId, deviceState, deviceType, cmd)\n\t\t\t\t\tif deviceState < 0 {\n\t\t\t\t\t\t// 设置不存在时，创建设备\n\t\t\t\t\t\t_ = models.NewDevice(user, device)\n\t\t\t\t\t\t// 未激活前需要过滤掉可以返回给客户端数据的指令及返回的数据\n\t\t\t\t\t\tvars.FwdSync, _ = forward.New(forward.PassHostHeader(true), forward.Logger(logger.Log.Logger),\n\t\t\t\t\t\t\tr, forward.ResponseModifier(filterCmd))\n\t\t\t\t\t\th(w, req)\n\t\t\t\t\t} else if deviceState == 0 {\n\t\t\t\t\t\t// 设备已激活就直接放行\n\t\t\t\t\t\tvars.FwdSync, _ = forward.New(forward.PassHostHeader(true), forward.Logger(logger.Log.Logger), r, forward.Stream(true))\n\t\t\t\t\t\th(w, req)\n\t\t\t\t\t} else if deviceState == 1 {\n\t\t\t\t\t\t// 设备未激活时，进入激活流程\n\t\t\t\t\t\tDoActiveDevice(user, deviceId, deviceType, device)\n\n\t\t\t\t\t\t// 未激活前需要过滤掉可以返回给客户端数据的指令及返回的数据\n\t\t\t\t\t\tvars.FwdSync, _ = forward.New(forward.PassHostHeader(true), forward.Logger(logger.Log.Logger),\n\t\t\t\t\t\t\tr, forward.ResponseModifier(filterCmd))\n\t\t\t\t\t\th(w, req)\n\t\t\t\t\t\tif models.CheckCmd(cmd, vars.RequestCmds) {\n\t\t\t\t\t\t\tw.WriteHeader(401)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// 其他状态为锁定或阻止，不代理到后端，在代理层面直接返回\n\t\t\t\t\t\tw.WriteHeader(200)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// 对于OPTIONS指令，暂时直接透传到后端\n\t\t\t\t\tvars.FwdSync, _ = forward.New(forward.PassHostHeader(true), forward.Logger(logger.Log.Logger), r)\n\t\t\t\t\th(w, req)\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "plugins/active_sync/sms.go",
    "content": "package active_sync\n\nimport (\n\t\"exchange_proxy/logger\"\n\t\"exchange_proxy/models\"\n\t\"exchange_proxy/vars\"\n\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n)\n\nfunc SendCode(user, deviceId, deviceType, phone, code string) (status bool) {\n\tstatus = true\n\tkey := fmt.Sprintf(\"sms_%v_%v_%v\", user, deviceId, phone)\n\tmodels.InitRedis()\n\tret, err := vars.RedisInstance.HMGet(key, \"times\", \"send_time\").Result()\n\t// logger.Log.Infof(\"key: %v, ret: %v, len(ret): %v, err: %v\", key, ret, len(ret), err)\n\tnow := time.Now().Unix()\n\tif err == nil && len(ret) == 2 {\n\t\tt, _ := ret[0].(string)\n\t\ttimes, _ := strconv.Atoi(t)\n\t\tst, _ := ret[1].(string)\n\t\tiSendTime, _ := strconv.Atoi(st)\n\t\tsendTime := int64(iSendTime)\n\n\t\tif times <= 5 && now-sendTime > 60*60*10 {\n\t\t\tcontent := generateSmsContent(user, deviceId, code, \"\", deviceType)\n\t\t\t_, ok := SendSmsAPI(user, phone, deviceId, code, content, \"\")\n\t\t\tstatus = ok\n\t\t\ttimes = times + 1\n\t\t\tsendTime = now\n\t\t\tv := make(map[string]interface{})\n\t\t\tv[\"times\"] = times\n\t\t\tv[\"send_time\"] = sendTime\n\t\t\t_, _ = vars.RedisInstance.HMSet(key, v).Result()\n\t\t} else {\n\t\t\tstatus = false\n\t\t}\n\t}\n\n\treturn status\n}\n\n// 重置短信状态，保证激活之后能再次收到短信，否则要等8小时之后了\nfunc ResetSmsStatus(user, deviceId string) (err error) {\n\tphone, err := GetUserPhone(vars.UserPhoneUrl, user)\n\tif err == nil {\n\t\tkey := fmt.Sprintf(\"sms_%v_%v_%v\", user, deviceId, phone)\n\t\tmodels.InitRedis()\n\t\tvars.RedisInstance.Del(key)\n\t}\n\treturn err\n}\n\n// 发送短信\nfunc SendSmsAPI(username, phone, deviceId, code, content, srcIp string) (err error, result bool) {\n\tclient := &http.Client{}\n\tpostData := strings.NewReader(fmt.Sprintf(\"recipients=%s&content=%s\", phone, content))\n\treq, err := http.NewRequest(\"POST\", vars.SmsApiUrl, postData)\n\tif err == nil {\n\t\treq.Header.Add(vars.SmsApiHeader, vars.SmsApiKey)\n\t\treq.Header.Add(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\n\t\tresp, err := client.Do(req)\n\t\tif err == nil {\n\t\t\tresult = true\n\t\t\tdefer resp.Body.Close()\n\t\t\tret, err := ioutil.ReadAll(resp.Body)\n\t\t\tlogger.Log.Infof(\"user:%v, deviceId: %v, code: %v, sms send result: %v, err: %v\",\n\t\t\t\tusername, deviceId, code, strings.TrimSpace(string(ret)), err)\n\t\t}\n\t}\n\treturn err, result\n}\n\n// 生成短信内容\nfunc generateSmsContent(username, deviceId, code, srcIp, deviceType string) (smsContent string) {\n\t// 获取用户手机设备信息\n\tdeviceInfo, err := models.GetDeviceInfoByDeviceId(deviceId)\n\tif err == nil {\n\t\tphone := deviceInfo.PhoneNumber\n\t\tif deviceInfo.Model != \"\" {\n\t\t\tdeviceType = deviceInfo.Model\n\t\t}\n\t\tif len(phone) > 5 {\n\t\t\tsmsContent = fmt.Sprintf(\"您的邮箱 %v 正在一台新的设备（%v，手机号码为：%v）上登录，请点击链接查看详情并允许或拒绝，%v/a/?c=%v （此链接8小时后失效）\",\n\t\t\t\tusername, deviceType, phone, vars.ActiveUrl, code)\n\t\t}\n\t} else {\n\t\tsmsContent = fmt.Sprintf(\"您的邮箱 %v 正在一台新的设备（%v）上登录，请点击链接查看详情并允许或拒绝，%v/a/?c=%v （此链接8小时后失效）\",\n\t\t\tusername, deviceType, vars.ActiveUrl, code)\n\t}\n\n\treturn smsContent\n}\n\n"
  },
  {
    "path": "plugins/active_sync/user_info.go",
    "content": "package active_sync\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\n\t\"exchange_proxy/models\"\n)\n\n// 获取手机号\nfunc GetUserPhone(url, user string) (phone string, err error) {\n\tvar userPhone models.UserPhone\n\tresp, err := http.Get(fmt.Sprintf(\"%v?username=%v\", url, user))\n\tif err == nil {\n\t\tdefer resp.Body.Close()\n\t\tbody, err := ioutil.ReadAll(resp.Body)\n\t\tif err == nil {\n\t\t\terr = json.Unmarshal(body, &userPhone)\n\t\t\tif err == nil && userPhone.Code == 200 {\n\t\t\t\tphone = userPhone.Data\n\t\t\t}\n\t\t}\n\t}\n\treturn phone, err\n}\n"
  },
  {
    "path": "plugins/owa/owa.go",
    "content": "package owa\n\nimport (\n\t\"bytes\"\n\t\"crypto/tls\"\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/toolkits/slice\"\n\t\"github.com/vulcand/oxy/forward\"\n\t\"github.com/vulcand/oxy/testutils\"\n\n\t\"exchange_proxy/logger\"\n\t\"exchange_proxy/util\"\n\t\"exchange_proxy/vars\"\n)\n\nfunc addOtp(resp *http.Response) error {\n\tb, err := ioutil.ReadAll(resp.Body)\n\tif err == nil {\n\t\terr = resp.Body.Close()\n\n\t\toldHtml := \"<div class=\\\"showPasswordCheck signInCheckBoxText\\\">\"\n\t\tnewHtml := \"<div class=\\\"signInInputLabel\\\" id=\\\"passwordLabel\\\" aria-hidden=\\\"true\\\">动态口令:</div><div><input id=\\\"customToken\\\" onfocus=\\\"g_fFcs=0\\\" name=\\\"customToken\\\" value=\\\"\\\" type=\\\"password\\\" class=\\\"signInInputText\\\" aria-labelledby=\\\"passwordLabel\\\"></div>\"\n\t\tb = bytes.Replace(b, []byte(oldHtml), []byte(newHtml), -1) // replace html\n\n\t\tbody := ioutil.NopCloser(bytes.NewReader(b))\n\t\tresp.Body = body\n\t\tresp.ContentLength = int64(len(b))\n\t\tresp.Header.Set(\"Content-Length\", strconv.Itoa(len(b)))\n\t}\n\treturn err\n}\n\nfunc OwaRedirect(w http.ResponseWriter, req *http.Request) {\n\n\tif slice.ContainsString(vars.MailConfig.Host, req.Host) {\n\t\treq.URL = testutils.ParseURI(vars.MailConfig.Backend)\n\t\tvars.FwdOWA.ServeHTTP(w, req)\n\t} else {\n\t\tu := fmt.Sprintf(\"https://%v//owa/auth/logon.aspx\", vars.MailConfig.Host[0])\n\t\tw.Header().Set(\"Location\", u)\n\t\tw.WriteHeader(302)\n\t}\n}\n\nfunc OwaHandler(h http.HandlerFunc) http.HandlerFunc {\n\treturn func(w http.ResponseWriter, req *http.Request) {\n\n\t\t// 内网用户不用验证OTP口令\n\t\tif strings.HasPrefix(req.RemoteAddr, \"10.\") || strings.HasPrefix(req.RemoteAddr, \"192.\") {\n\t\t\tr := forward.RoundTripper(\n\t\t\t\t&http.Transport{\n\t\t\t\t\tTLSClientConfig: &tls.Config{InsecureSkipVerify: true},\n\t\t\t\t},\n\t\t\t)\n\t\t\tvars.FwdOWA, _ = forward.New(forward.PassHostHeader(true), forward.Logger(logger.Log.Logger), r)\n\t\t\th(w, req)\n\t\t} else {\n\t\t\tif vars.MailConfig.TLS {\n\t\t\t\tr := forward.RoundTripper(\n\t\t\t\t\t&http.Transport{\n\t\t\t\t\t\tTLSClientConfig: &tls.Config{InsecureSkipVerify: true},\n\t\t\t\t\t},\n\t\t\t\t)\n\n\t\t\t\tif req.Method == \"GET\" && strings.HasPrefix(req.RequestURI, \"/owa/auth/logon.aspx\") {\n\t\t\t\t\tvars.FwdOWA, _ = forward.New(forward.PassHostHeader(true), forward.Logger(logger.Log.Logger),\n\t\t\t\t\t\tr, forward.ResponseModifier(addOtp))\n\t\t\t\t\th(w, req)\n\n\t\t\t\t} else if req.Method == \"POST\" && strings.HasPrefix(req.RequestURI, \"/owa/auth/logon.aspx\") {\n\t\t\t\t\tvar bodyBytes []byte\n\t\t\t\t\tif req.Body != nil {\n\t\t\t\t\t\tbodyBytes, _ = ioutil.ReadAll(req.Body)\n\n\t\t\t\t\t\t// 恢复Req.body的值给ParseForm函数使用\n\t\t\t\t\t\treq.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))\n\t\t\t\t\t\t_ = req.ParseForm()\n\t\t\t\t\t\tusername := req.FormValue(\"username\")\n\t\t\t\t\t\tcustomToken := req.FormValue(\"customToken\")\n\n\t\t\t\t\t\t// 恢复Req.body的值传到下一个处理器中\n\t\t\t\t\t\treq.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))\n\n\t\t\t\t\t\tresult, err := util.CheckToken(vars.OtpUrl, username, customToken)\n\t\t\t\t\t\tlogger.Log.Printf(\"user: %v, token: %v, result: %v\", username, customToken, result)\n\t\t\t\t\t\tif err == nil && result {\n\t\t\t\t\t\t\tvars.FwdOWA, _ = forward.New(forward.PassHostHeader(true), forward.Logger(logger.Log.Logger), r)\n\t\t\t\t\t\t\th(w, req)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tw.Header().Set(\"Location\", \"/owa/auth/logon.aspx\")\n\t\t\t\t\t\t\tw.WriteHeader(302)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tvars.FwdOWA, _ = forward.New(forward.PassHostHeader(true), forward.Logger(logger.Log.Logger), r)\n\t\t\t\t\th(w, req)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "plugins/web/public/css/common.css",
    "content": "﻿*{margin:0;padding:0}a,a:hover{text-decoration:none;color:#09f}body{font-size:14px;font-family:arial, \"Hiragino Sans GB\", \"Microsoft YaHei\", \"微軟正黑體\", \"儷黑 Pro\", sans-serif;color:#000;background-color:#fff}.tac{text-align:center}.fl{float:left}.fr{float:right}ul{list-style:none}.clearfix:before,.clearfix:after{content:\" \";display:table}.clearfix:after{clear:both}.container{padding:20px;max-width:400px;margin:auto}.mi_logo{width:48px;height:48px;margin:30px auto}.dear_user{font-size:16px;font-weight:bold;padding:10px 0}.help_phone{padding:10px 0}.modal{display:none;opacity:0;position:fixed;z-index:999;left:0;top:0;height:100%;width:100%;transition:opacity .5s}.allow_btn{margin-top:60px}.modal.visible{display:block;opacity:1}.modal_mask{position:absolute;left:0;top:0;width:100%;height:100%;opacity:.4;filter:alpha(opacity=40);background-color:black}.modal_box{text-align:center;position:absolute;bottom:-30px;width:90%;left:50%;box-shadow:0 1px 8px rgba(128,128,128,0.3);border:1px solid #d1d1d1;border-radius:10px;overflow:hidden;background-color:white;transition:width .5s ease, height .5s ease;-webkit-transform:translate(-50%, -50%);transform:translate(-50%, -50%);-webkit-transform:translate(-50%, -50%, 0);transform:translate(-50%, -50%, 0);_top:0;_left:0;_margin-left:0;_margin-top:0;max-width:400px}.modal_body{margin:20px;text-align:left}.modal_footer{display:flex;border-top:1px solid #f8f8f8}.modal_btn{flex:1;padding:15px 0}.modal_btn_ok{color:#ff6700;border-left:1px solid #f8f8f8}.btn{margin-bottom:20px;text-align:center;padding:12px 0;border-radius:6px}.btn_ok{background-color:#ff6700;color:#fff}.btn_no{background-color:#fff;color:#999;border:1px solid #d3d3d3}.state{margin-top:30px}.state img{width:100px;height:100px;margin-top:40px}.state dd{font-size:30px;margin:20px 0}.device_list{margin:20px 0 20px 30px;list-style-type:disc}.device_list.gray{width:220px;color:#999;margin:40px auto 0 auto}.caution{margin:30px 0}.caution .line{width:100%;margin-bottom:-10px;border-bottom:1px solid #f0f0f0}.caution .txt{color:#999;background-color:#fff;padding:5px 10px}.tips{margin:20px 0}.icon_gter{width:10%;height:16px;display:block;position:relative}.icon_gter:after{content:\"\";width:12px;height:12px;border-width:1px;border-style:solid;border-color:transparent transparent rgba(0,0,0,0.3) rgba(0,0,0,0.3);-webkit-transform:rotate(-135deg);transform:rotate(-135deg);position:absolute;left:5px;top:4px}.icon_lser{width:10%;height:16px;display:block;position:relative}.icon_lser:after{content:\"\";width:12px;height:12px;border-width:1px;border-style:solid;border-color:transparent transparent rgba(0,0,0,0.3) rgba(0,0,0,0.3);-webkit-transform:rotate(45deg);transform:rotate(45deg);position:absolute;left:5px;top:4px}.active_tips{text-align:center}.more_tips .tips{height:60px;overflow:auto}.more_sec_info{font-size:12px}.lang-select-list{height:20px;line-height:20px;text-align:center}.lang-select-list li{font-size:14px;display:inline-block}.lang-select-list li a{padding:10px;color:#999}.lang-select-list li a.current{color:#ef5b00}.outlook_tips{color:#f66;font-size:12px;padding-bottom:20px;display:none}\n/*# sourceMappingURL=common.css.map */\n"
  },
  {
    "path": "plugins/web/public/i18n/i18n.js",
    "content": "var txt = {\n  cn: {\n    \"doc_title\": \"邮箱激活系统\",\n    \"dear_user\": \"亲爱的<span class='email'></span>:\",\n    \"new_device\": \"您的邮箱 <span class='email'></span>正在一台新的设备（<span class='device'></span>）上登录，详情如下\",\n    \"device_name\": \"设备名称\",\n    \"device_model\": \"设备型号\",\n    \"device_type\": \"设备类型\",\n    \"device_id\": \"设备ID\",\n    \"imei_id\": \"IMEI\",\n    \"phone_number\":\"手机号码\",\n    \"ip_address\": \"新设备IP地址\",\n    \"change_pwd\": \"如果这不是您本人操作，您的邮箱密码可能已经泄露，请修改密码并拒绝该请求。\",\n    \"help_phone\": \"如需协助请联系IT部门\",\n    \"outlook_tips\": \"您使用的是outlook客户端，用户名和密码会被保存到第三方微软公司的服务器中，存在安全风险，推荐使用手机自带的邮件客户端\",\n    \"allow\": \" 允许\",\n    \"reject\": \" 拒绝\",\n    \"allow_confirm_tips\": \"确定后，将同步您的邮箱到该设备，如需禁用该设备，请登录内网帐号中心的“手机邮箱”中进行操作\",\n    \"cancel\": \" 取消\",\n    \"ok\": \"确定\",\n    \"reject_manage_account\": \"拒绝后，将无法同步您的邮箱到该设备。如需重新激活该设备，请登录内网帐号中心的“手机邮箱”中进行操作\",\n    \"device_actived\": \"设备已授权\",\n    \"device_rejected\": \"设备已拒绝\",\n    \"device_exceed\": \"设备数已超出限制\",\n    \"page_not_found\": \"页面未找到\",\n    \"link_invalid\": \"激活链接无效或已过期\",\n    \"caution\": \"温馨提示\",\n    \"auth_to_mis_manage\": \"已授权设备请登录到内网账号中心的“手机邮箱”中进行管理\",\n    \"reject_to_mis_manage\": \"已拒绝设备请登录到内网账号中心的“手机邮箱”中进行管理\",\n    \"to_mis_change_pwd\": \"如果这不是您本人操作，您的邮箱密码可能已泄露，并且有人正在尝试登陆您的邮箱，请立即点拒绝访问，并修改密码。\",\n    \"devices_exceeds_the_limit\": \"已经激活的设备数超出了10台的限制，请中删除不再使用的设备\",\n    \"more_sec_info\": \"更多安全知识，请访问<a href='https://sec.xiaomi.com/'> 小米安全中心 </a>\",\n    \"new_ip\": \"您的邮箱 <span class='email'></span>正在使用（<span class='device'></span>）客户端进行同步邮件，详情如下\",\n    \"client_type\": \"客户端类型\",\n    \"device_ip\": \"移动设备IP地址\",\n    \"client_ip\": \"客户端IP地址\",\n    \"expire_tips\": \"该客户端 IP 有效期为 8 个小时，过期后需要重新进行授权\",\n    \"allow_confirm_tips_ip\": \"确定后，将同步您的邮箱到该客户端，该客户端 IP 有效期为 8 个小时，如需禁用该 IP，请登录到“邮箱管理中心”中对 IP 进行管理\",\n    \"reject_manage_account_ip\": \"拒绝后，将无法同步您的邮箱到该客户端。如需重新激活该 IP，请登录到“邮箱管理中心”中对 IP 进行管理\",\n    \"ip_actived\": \"客户端 IP 已激活\",\n    \"ip_rejected\": \"客户端 IP 已拒绝\",\n    \"auth_to_mis_manage_ip\": \"已授权 IP 请登录到“邮箱管理中心”中对 IP 进行管理\",\n    \"reject_to_mis_manage_ip\": \"已拒绝 IP 请登录到“邮箱管理中心”中对 IP 进行管理\",\n    \"to_mis_change_pwd_ip\": \"如果该客户端 IP 不是您的 IP ，您的密码可能已经泄露，请立即修改密码\"\n  }\n};\n$(function() {\n  var $i18n = $.i18n();\n  $i18n.load(txt).done(function() {\n    $('html').i18n();\n    $(\"[data-i18n^='[html]']\").html(function() {\n      return $.i18n($(this).attr('data-i18n').replace('\\[html\\]', ''));\n    });\n  })\n})"
  },
  {
    "path": "plugins/web/public/js/jquery.i18n/1.0.4/jquery.i18n.js",
    "content": "/**\n * jQuery Internationalization library\n *\n * Copyright (C) 2012 Santhosh Thottingal\n *\n * jquery.i18n is dual licensed GPLv2 or later and MIT. You don't have to do\n * anything special to choose one license or the other and you don't have to\n * notify anyone which license you are using. You are free to use\n * UniversalLanguageSelector in commercial projects as long as the copyright\n * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.\n *\n * @licence GNU General Public Licence 2.0 or later\n * @licence MIT License\n */\n\n( function ( $ ) {\n\t'use strict';\n\n\tvar nav, I18N,\n\t\tslice = Array.prototype.slice;\n\t/**\n\t * @constructor\n\t * @param {Object} options\n\t */\n\tI18N = function ( options ) {\n\t\t// Load defaults\n\t\tthis.options = $.extend( {}, I18N.defaults, options );\n\n\t\tthis.parser = this.options.parser;\n\t\tthis.locale = this.options.locale;\n\t\tthis.messageStore = this.options.messageStore;\n\t\tthis.languages = {};\n\n\t\tthis.init();\n\t};\n\n\tI18N.prototype = {\n\t\t/**\n\t\t * Initialize by loading locales and setting up\n\t\t * String.prototype.toLocaleString and String.locale.\n\t\t */\n\t\tinit: function () {\n\t\t\tvar i18n = this;\n\n\t\t\t// Set locale of String environment\n\t\t\tString.locale = i18n.locale;\n\n\t\t\t// Override String.localeString method\n\t\t\tString.prototype.toLocaleString = function () {\n\t\t\t\tvar localeParts, localePartIndex, value, locale, fallbackIndex,\n\t\t\t\t\ttryingLocale, message;\n\n\t\t\t\tvalue = this.valueOf();\n\t\t\t\tlocale = i18n.locale;\n\t\t\t\tfallbackIndex = 0;\n\n\t\t\t\twhile ( locale ) {\n\t\t\t\t\t// Iterate through locales starting at most-specific until\n\t\t\t\t\t// localization is found. As in fi-Latn-FI, fi-Latn and fi.\n\t\t\t\t\tlocaleParts = locale.split( '-' );\n\t\t\t\t\tlocalePartIndex = localeParts.length;\n\n\t\t\t\t\tdo {\n\t\t\t\t\t\ttryingLocale = localeParts.slice( 0, localePartIndex ).join( '-' );\n\t\t\t\t\t\tmessage = i18n.messageStore.get( tryingLocale, value );\n\n\t\t\t\t\t\tif ( message ) {\n\t\t\t\t\t\t\treturn message;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlocalePartIndex--;\n\t\t\t\t\t} while ( localePartIndex );\n\n\t\t\t\t\tif ( locale === 'en' ) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tlocale = ( $.i18n.fallbacks[i18n.locale] && $.i18n.fallbacks[i18n.locale][fallbackIndex] ) ||\n\t\t\t\t\t\ti18n.options.fallbackLocale;\n\t\t\t\t\t$.i18n.log( 'Trying fallback locale for ' + i18n.locale + ': ' + locale );\n\n\t\t\t\t\tfallbackIndex++;\n\t\t\t\t}\n\n\t\t\t\t// key not found\n\t\t\t\treturn '';\n\t\t\t};\n\t\t},\n\n\t\t/*\n\t\t * Destroy the i18n instance.\n\t\t */\n\t\tdestroy: function () {\n\t\t\t$.removeData( document, 'i18n' );\n\t\t},\n\n\t\t/**\n\t\t * General message loading API This can take a URL string for\n\t\t * the json formatted messages. Example:\n\t\t * <code>load('path/to/all_localizations.json');</code>\n\t\t *\n\t\t * To load a localization file for a locale:\n\t\t * <code>\n\t\t * load('path/to/de-messages.json', 'de' );\n\t\t * </code>\n\t\t *\n\t\t * To load a localization file from a directory:\n\t\t * <code>\n\t\t * load('path/to/i18n/directory', 'de' );\n\t\t * </code>\n\t\t * The above method has the advantage of fallback resolution.\n\t\t * ie, it will automatically load the fallback locales for de.\n\t\t * For most usecases, this is the recommended method.\n\t\t * It is optional to have trailing slash at end.\n\t\t *\n\t\t * A data object containing message key- message translation mappings\n\t\t * can also be passed. Example:\n\t\t * <code>\n\t\t * load( { 'hello' : 'Hello' }, optionalLocale );\n\t\t * </code>\n\t\t *\n\t\t * A source map containing key-value pair of languagename and locations\n\t\t * can also be passed. Example:\n\t\t * <code>\n\t\t * load( {\n\t\t * bn: 'i18n/bn.json',\n\t\t * he: 'i18n/he.json',\n\t\t * en: 'i18n/en.json'\n\t\t * } )\n\t\t * </code>\n\t\t *\n\t\t * If the data argument is null/undefined/false,\n\t\t * all cached messages for the i18n instance will get reset.\n\t\t *\n\t\t * @param {String|Object} source\n\t\t * @param {String} locale Language tag\n\t\t * @returns {jQuery.Promise}\n\t\t */\n\t\tload: function ( source, locale ) {\n\t\t\tvar fallbackLocales, locIndex, fallbackLocale, sourceMap = {};\n\t\t\tif ( !source && !locale ) {\n\t\t\t\tsource = 'i18n/' + $.i18n().locale + '.json';\n\t\t\t\tlocale = $.i18n().locale;\n\t\t\t}\n\t\t\tif ( typeof source === 'string'\t&&\n\t\t\t\tsource.split( '.' ).pop() !== 'json'\n\t\t\t) {\n\t\t\t\t// Load specified locale then check for fallbacks when directory is specified in load()\n\t\t\t\tsourceMap[locale] = source + '/' + locale + '.json';\n\t\t\t\tfallbackLocales = ( $.i18n.fallbacks[locale] || [] )\n\t\t\t\t\t.concat( this.options.fallbackLocale );\n\t\t\t\tfor ( locIndex in fallbackLocales ) {\n\t\t\t\t\tfallbackLocale = fallbackLocales[locIndex];\n\t\t\t\t\tsourceMap[fallbackLocale] = source + '/' + fallbackLocale + '.json';\n\t\t\t\t}\n\t\t\t\treturn this.load( sourceMap );\n\t\t\t} else {\n\t\t\t\treturn this.messageStore.load( source, locale );\n\t\t\t}\n\n\t\t},\n\n\t\t/**\n\t\t * Does parameter and magic word substitution.\n\t\t *\n\t\t * @param {string} key Message key\n\t\t * @param {Array} parameters Message parameters\n\t\t * @return {string}\n\t\t */\n\t\tparse: function ( key, parameters ) {\n\t\t\tvar message = key.toLocaleString();\n\t\t\t// FIXME: This changes the state of the I18N object,\n\t\t\t// should probably not change the 'this.parser' but just\n\t\t\t// pass it to the parser.\n\t\t\tthis.parser.language = $.i18n.languages[$.i18n().locale] || $.i18n.languages['default'];\n\t\t\tif ( message === '' ) {\n\t\t\t\tmessage = key;\n\t\t\t}\n\t\t\treturn this.parser.parse( message, parameters );\n\t\t}\n\t};\n\n\t/**\n\t * Process a message from the $.I18N instance\n\t * for the current document, stored in jQuery.data(document).\n\t *\n\t * @param {string} key Key of the message.\n\t * @param {string} param1 [param...] Variadic list of parameters for {key}.\n\t * @return {string|$.I18N} Parsed message, or if no key was given\n\t * the instance of $.I18N is returned.\n\t */\n\t$.i18n = function ( key, param1 ) {\n\t\tvar parameters,\n\t\t\ti18n = $.data( document, 'i18n' ),\n\t\t\toptions = typeof key === 'object' && key;\n\n\t\t// If the locale option for this call is different then the setup so far,\n\t\t// update it automatically. This doesn't just change the context for this\n\t\t// call but for all future call as well.\n\t\t// If there is no i18n setup yet, don't do this. It will be taken care of\n\t\t// by the `new I18N` construction below.\n\t\t// NOTE: It should only change language for this one call.\n\t\t// Then cache instances of I18N somewhere.\n\t\tif ( options && options.locale && i18n && i18n.locale !== options.locale ) {\n\t\t\tString.locale = i18n.locale = options.locale;\n\t\t}\n\n\t\tif ( !i18n ) {\n\t\t\ti18n = new I18N( options );\n\t\t\t$.data( document, 'i18n', i18n );\n\t\t}\n\n\t\tif ( typeof key === 'string' ) {\n\t\t\tif ( param1 !== undefined ) {\n\t\t\t\tparameters = slice.call( arguments, 1 );\n\t\t\t} else {\n\t\t\t\tparameters = [];\n\t\t\t}\n\n\t\t\treturn i18n.parse( key, parameters );\n\t\t} else {\n\t\t\t// FIXME: remove this feature/bug.\n\t\t\treturn i18n;\n\t\t}\n\t};\n\n\t$.fn.i18n = function () {\n\t\tvar i18n = $.data( document, 'i18n' );\n\n\t\tif ( !i18n ) {\n\t\t\ti18n = new I18N();\n\t\t\t$.data( document, 'i18n', i18n );\n\t\t}\n\t\tString.locale = i18n.locale;\n\t\treturn this.each( function () {\n\t\t\tvar $this = $( this ),\n\t\t\t\tmessageKey = $this.data( 'i18n' );\n\n\t\t\tif ( messageKey ) {\n\t\t\t\t$this.text( i18n.parse( messageKey ) );\n\t\t\t} else {\n\t\t\t\t$this.find( '[data-i18n]' ).i18n();\n\t\t\t}\n\t\t} );\n\t};\n\n\tString.locale = String.locale || $( 'html' ).attr( 'lang' );\n\n\tif ( !String.locale ) {\n\t\tif ( typeof window.navigator !== undefined ) {\n\t\t\tnav = window.navigator;\n\t\t\tString.locale = nav.language || nav.userLanguage || '';\n\t\t} else {\n\t\t\tString.locale = '';\n\t\t}\n\t}\n\n\t$.i18n.languages = {};\n\t$.i18n.messageStore = $.i18n.messageStore || {};\n\t$.i18n.parser = {\n\t\t// The default parser only handles variable substitution\n\t\tparse: function ( message, parameters ) {\n\t\t\treturn message.replace( /\\$(\\d+)/g, function ( str, match ) {\n\t\t\t\tvar index = parseInt( match, 10 ) - 1;\n\t\t\t\treturn parameters[index] !== undefined ? parameters[index] : '$' + match;\n\t\t\t} );\n\t\t},\n\t\temitter: {}\n\t};\n\t$.i18n.fallbacks = {};\n\t$.i18n.debug = false;\n\t$.i18n.log = function ( /* arguments */ ) {\n\t\tif ( window.console && $.i18n.debug ) {\n\t\t\twindow.console.log.apply( window.console, arguments );\n\t\t}\n\t};\n\t/* Static members */\n\tI18N.defaults = {\n\t\tlocale: String.locale,\n\t\tfallbackLocale: 'en',\n\t\tparser: $.i18n.parser,\n\t\tmessageStore: $.i18n.messageStore\n\t};\n\n\t// Expose constructor\n\t$.i18n.constructor = I18N;\n}( jQuery ) );\n"
  },
  {
    "path": "plugins/web/public/js/jquery.i18n/1.0.4/jquery.i18n.messagestore.js",
    "content": "/**\n * jQuery Internationalization library - Message Store\n *\n * Copyright (C) 2012 Santhosh Thottingal\n *\n * jquery.i18n is dual licensed GPLv2 or later and MIT. You don't have to do anything special to\n * choose one license or the other and you don't have to notify anyone which license you are using.\n * You are free to use UniversalLanguageSelector in commercial projects as long as the copyright\n * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.\n *\n * @licence GNU General Public Licence 2.0 or later\n * @licence MIT License\n */\n\n( function ( $, window, undefined ) {\n\t'use strict';\n\n\tvar MessageStore = function () {\n\t\tthis.messages = {};\n\t\tthis.sources = {};\n\t};\n\n\t/**\n\t * See https://github.com/wikimedia/jquery.i18n/wiki/Specification#wiki-Message_File_Loading\n\t */\n\tMessageStore.prototype = {\n\n\t\t/**\n\t\t * General message loading API This can take a URL string for\n\t\t * the json formatted messages.\n\t\t * <code>load('path/to/all_localizations.json');</code>\n\t\t *\n\t\t * This can also load a localization file for a locale <code>\n\t\t * load( 'path/to/de-messages.json', 'de' );\n\t\t * </code>\n\t\t * A data object containing message key- message translation mappings\n\t\t * can also be passed Eg:\n\t\t * <code>\n\t\t * load( { 'hello' : 'Hello' }, optionalLocale );\n\t\t * </code> If the data argument is\n\t\t * null/undefined/false,\n\t\t * all cached messages for the i18n instance will get reset.\n\t\t *\n\t\t * @param {String|Object} source\n\t\t * @param {String} locale Language tag\n\t\t * @return {jQuery.Promise}\n\t\t */\n\t\tload: function ( source, locale ) {\n\t\t\tvar key = null,\n\t\t\t\tdeferred = null,\n\t\t\t\tdeferreds = [],\n\t\t\t\tmessageStore = this;\n\n\t\t\tif ( typeof source === 'string' ) {\n\t\t\t\t// This is a URL to the messages file.\n\t\t\t\t$.i18n.log( 'Loading messages from: ' + source );\n\t\t\t\tdeferred = jsonMessageLoader( source )\n\t\t\t\t\t.done( function ( localization ) {\n\t\t\t\t\t\tmessageStore.set( locale, localization );\n\t\t\t\t\t} );\n\n\t\t\t\treturn deferred.promise();\n\t\t\t}\n\n\t\t\tif ( locale ) {\n\t\t\t\t// source is an key-value pair of messages for given locale\n\t\t\t\tmessageStore.set( locale, source );\n\n\t\t\t\treturn $.Deferred().resolve();\n\t\t\t} else {\n\t\t\t\t// source is a key-value pair of locales and their source\n\t\t\t\tfor ( key in source ) {\n\t\t\t\t\tif ( Object.prototype.hasOwnProperty.call( source, key ) ) {\n\t\t\t\t\t\tlocale = key;\n\t\t\t\t\t\t// No {locale} given, assume data is a group of languages,\n\t\t\t\t\t\t// call this function again for each language.\n\t\t\t\t\t\tdeferreds.push( messageStore.load( source[key], locale ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn $.when.apply( $, deferreds );\n\t\t\t}\n\n\t\t},\n\n\t\t/**\n\t\t * Set messages to the given locale.\n\t\t * If locale exists, add messages to the locale.\n\t\t * @param locale\n\t\t * @param messages\n\t\t */\n\t\tset: function ( locale, messages ) {\n\t\t\tif ( !this.messages[locale] ) {\n\t\t\t\tthis.messages[locale] = messages;\n\t\t\t} else {\n\t\t\t\tthis.messages[locale] = $.extend( this.messages[locale], messages );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t *\n\t\t * @param locale\n\t\t * @param messageKey\n\t\t * @returns {Boolean}\n\t\t */\n\t\tget: function ( locale, messageKey ) {\n\t\t\treturn this.messages[locale] && this.messages[locale][messageKey];\n\t\t}\n\t};\n\n\tfunction jsonMessageLoader( url ) {\n\t\tvar deferred = $.Deferred();\n\n\t\t$.getJSON( url )\n\t\t\t.done( deferred.resolve )\n\t\t\t.fail( function ( jqxhr, settings, exception ) {\n\t\t\t\t$.i18n.log( 'Error in loading messages from ' + url + ' Exception: ' + exception );\n\t\t\t\t// Ignore 404 exception, because we are handling fallabacks explicitly\n\t\t\t\tdeferred.resolve();\n\t\t\t} );\n\n\t\treturn deferred.promise();\n\t}\n\n\t$.extend( $.i18n.messageStore, new MessageStore() );\n}( jQuery, window ) );\n"
  },
  {
    "path": "plugins/web/public/js/jquery.i18n.fallbacks.js",
    "content": "/*!\n * jQuery Internationalization library\n *\n * Copyright (C) 2012 Santhosh Thottingal\n *\n * jquery.i18n is dual licensed GPLv2 or later and MIT. You don't have to do anything special to\n * choose one license or the other and you don't have to notify anyone which license you are using.\n * You are free to use UniversalLanguageSelector in commercial projects as long as the copyright\n * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.\n *\n * @licence GNU General Public Licence 2.0 or later\n * @licence MIT License\n */\n( function ( $ ) {\n\t'use strict';\n\n\t$.i18n = $.i18n || {};\n\t$.extend( $.i18n.fallbacks, {\n\t\tab: [ 'ru' ],\n\t\tace: [ 'id' ],\n\t\taln: [ 'sq' ],\n\t\t// Not so standard - als is supposed to be Tosk Albanian,\n\t\t// but in Wikipedia it's used for a Germanic language.\n\t\tals: [ 'gsw', 'de' ],\n\t\tan: [ 'es' ],\n\t\tanp: [ 'hi' ],\n\t\tarn: [ 'es' ],\n\t\tarz: [ 'ar' ],\n\t\tav: [ 'ru' ],\n\t\tay: [ 'es' ],\n\t\tba: [ 'ru' ],\n\t\tbar: [ 'de' ],\n\t\t'bat-smg': [ 'sgs', 'lt' ],\n\t\tbcc: [ 'fa' ],\n\t\t'be-x-old': [ 'be-tarask' ],\n\t\tbh: [ 'bho' ],\n\t\tbjn: [ 'id' ],\n\t\tbm: [ 'fr' ],\n\t\tbpy: [ 'bn' ],\n\t\tbqi: [ 'fa' ],\n\t\tbug: [ 'id' ],\n\t\t'cbk-zam': [ 'es' ],\n\t\tce: [ 'ru' ],\n\t\tcrh: [ 'crh-latn' ],\n\t\t'crh-cyrl': [ 'ru' ],\n\t\tcsb: [ 'pl' ],\n\t\tcv: [ 'ru' ],\n\t\t'de-at': [ 'de' ],\n\t\t'de-ch': [ 'de' ],\n\t\t'de-formal': [ 'de' ],\n\t\tdsb: [ 'de' ],\n\t\tdtp: [ 'ms' ],\n\t\tegl: [ 'it' ],\n\t\teml: [ 'it' ],\n\t\tff: [ 'fr' ],\n\t\tfit: [ 'fi' ],\n\t\t'fiu-vro': [ 'vro', 'et' ],\n\t\tfrc: [ 'fr' ],\n\t\tfrp: [ 'fr' ],\n\t\tfrr: [ 'de' ],\n\t\tfur: [ 'it' ],\n\t\tgag: [ 'tr' ],\n\t\tgan: [ 'gan-hant', 'zh-hant', 'zh-hans' ],\n\t\t'gan-hans': [ 'zh-hans' ],\n\t\t'gan-hant': [ 'zh-hant', 'zh-hans' ],\n\t\tgl: [ 'pt' ],\n\t\tglk: [ 'fa' ],\n\t\tgn: [ 'es' ],\n\t\tgsw: [ 'de' ],\n\t\thif: [ 'hif-latn' ],\n\t\thsb: [ 'de' ],\n\t\tht: [ 'fr' ],\n\t\tii: [ 'zh-cn', 'zh-hans' ],\n\t\tinh: [ 'ru' ],\n\t\tiu: [ 'ike-cans' ],\n\t\tjut: [ 'da' ],\n\t\tjv: [ 'id' ],\n\t\tkaa: [ 'kk-latn', 'kk-cyrl' ],\n\t\tkbd: [ 'kbd-cyrl' ],\n\t\tkhw: [ 'ur' ],\n\t\tkiu: [ 'tr' ],\n\t\tkk: [ 'kk-cyrl' ],\n\t\t'kk-arab': [ 'kk-cyrl' ],\n\t\t'kk-latn': [ 'kk-cyrl' ],\n\t\t'kk-cn': [ 'kk-arab', 'kk-cyrl' ],\n\t\t'kk-kz': [ 'kk-cyrl' ],\n\t\t'kk-tr': [ 'kk-latn', 'kk-cyrl' ],\n\t\tkl: [ 'da' ],\n\t\t'ko-kp': [ 'ko' ],\n\t\tkoi: [ 'ru' ],\n\t\tkrc: [ 'ru' ],\n\t\tks: [ 'ks-arab' ],\n\t\tksh: [ 'de' ],\n\t\tku: [ 'ku-latn' ],\n\t\t'ku-arab': [ 'ckb' ],\n\t\tkv: [ 'ru' ],\n\t\tlad: [ 'es' ],\n\t\tlb: [ 'de' ],\n\t\tlbe: [ 'ru' ],\n\t\tlez: [ 'ru' ],\n\t\tli: [ 'nl' ],\n\t\tlij: [ 'it' ],\n\t\tliv: [ 'et' ],\n\t\tlmo: [ 'it' ],\n\t\tln: [ 'fr' ],\n\t\tltg: [ 'lv' ],\n\t\tlzz: [ 'tr' ],\n\t\tmai: [ 'hi' ],\n\t\t'map-bms': [ 'jv', 'id' ],\n\t\tmg: [ 'fr' ],\n\t\tmhr: [ 'ru' ],\n\t\tmin: [ 'id' ],\n\t\tmo: [ 'ro' ],\n\t\tmrj: [ 'ru' ],\n\t\tmwl: [ 'pt' ],\n\t\tmyv: [ 'ru' ],\n\t\tmzn: [ 'fa' ],\n\t\tnah: [ 'es' ],\n\t\tnap: [ 'it' ],\n\t\tnds: [ 'de' ],\n\t\t'nds-nl': [ 'nl' ],\n\t\t'nl-informal': [ 'nl' ],\n\t\tno: [ 'nb' ],\n\t\tos: [ 'ru' ],\n\t\tpcd: [ 'fr' ],\n\t\tpdc: [ 'de' ],\n\t\tpdt: [ 'de' ],\n\t\tpfl: [ 'de' ],\n\t\tpms: [ 'it' ],\n\t\tpt: [ 'pt-br' ],\n\t\t'pt-br': [ 'pt' ],\n\t\tqu: [ 'es' ],\n\t\tqug: [ 'qu', 'es' ],\n\t\trgn: [ 'it' ],\n\t\trmy: [ 'ro' ],\n\t\t'roa-rup': [ 'rup' ],\n\t\true: [ 'uk', 'ru' ],\n\t\truq: [ 'ruq-latn', 'ro' ],\n\t\t'ruq-cyrl': [ 'mk' ],\n\t\t'ruq-latn': [ 'ro' ],\n\t\tsa: [ 'hi' ],\n\t\tsah: [ 'ru' ],\n\t\tscn: [ 'it' ],\n\t\tsg: [ 'fr' ],\n\t\tsgs: [ 'lt' ],\n\t\tsli: [ 'de' ],\n\t\tsr: [ 'sr-ec' ],\n\t\tsrn: [ 'nl' ],\n\t\tstq: [ 'de' ],\n\t\tsu: [ 'id' ],\n\t\tszl: [ 'pl' ],\n\t\ttcy: [ 'kn' ],\n\t\ttg: [ 'tg-cyrl' ],\n\t\ttt: [ 'tt-cyrl', 'ru' ],\n\t\t'tt-cyrl': [ 'ru' ],\n\t\tty: [ 'fr' ],\n\t\tudm: [ 'ru' ],\n\t\tug: [ 'ug-arab' ],\n\t\tuk: [ 'ru' ],\n\t\tvec: [ 'it' ],\n\t\tvep: [ 'et' ],\n\t\tvls: [ 'nl' ],\n\t\tvmf: [ 'de' ],\n\t\tvot: [ 'fi' ],\n\t\tvro: [ 'et' ],\n\t\twa: [ 'fr' ],\n\t\two: [ 'fr' ],\n\t\twuu: [ 'zh-hans' ],\n\t\txal: [ 'ru' ],\n\t\txmf: [ 'ka' ],\n\t\tyi: [ 'he' ],\n\t\tza: [ 'zh-hans' ],\n\t\tzea: [ 'nl' ],\n\t\tzh: [ 'zh-hans' ],\n\t\t'zh-classical': [ 'lzh' ],\n\t\t'zh-cn': [ 'zh-hans' ],\n\t\t'zh-hant': [ 'zh-hans' ],\n\t\t'zh-hk': [ 'zh-hant', 'zh-hans' ],\n\t\t'zh-min-nan': [ 'nan' ],\n\t\t'zh-mo': [ 'zh-hk', 'zh-hant', 'zh-hans' ],\n\t\t'zh-my': [ 'zh-sg', 'zh-hans' ],\n\t\t'zh-sg': [ 'zh-hans' ],\n\t\t'zh-tw': [ 'zh-hant', 'zh-hans' ],\n\t\t'zh-yue': [ 'yue' ]\n\t} );\n}( jQuery ) );\n"
  },
  {
    "path": "plugins/web/public/js/jquery.i18n.js",
    "content": "/*!\n * jQuery Internationalization library\n *\n * Copyright (C) 2012 Santhosh Thottingal\n *\n * jquery.i18n is dual licensed GPLv2 or later and MIT. You don't have to do\n * anything special to choose one license or the other and you don't have to\n * notify anyone which license you are using. You are free to use\n * UniversalLanguageSelector in commercial projects as long as the copyright\n * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.\n *\n * @licence GNU General Public Licence 2.0 or later\n * @licence MIT License\n */\n\n( function ( $ ) {\n\t'use strict';\n\n\tvar I18N,\n\t\tslice = Array.prototype.slice;\n\t/**\n\t * @constructor\n\t * @param {Object} options\n\t */\n\tI18N = function ( options ) {\n\t\t// Load defaults\n\t\tthis.options = $.extend( {}, I18N.defaults, options );\n\n\t\tthis.parser = this.options.parser;\n\t\tthis.locale = this.options.locale;\n\t\tthis.messageStore = this.options.messageStore;\n\t\tthis.languages = {};\n\t};\n\n\tI18N.prototype = {\n\t\t/**\n\t\t * Localize a given messageKey to a locale.\n\t\t * @param {String} messageKey\n\t\t * @return {String} Localized message\n\t\t */\n\t\tlocalize: function ( messageKey ) {\n\t\t\tvar localeParts, localePartIndex, locale, fallbackIndex,\n\t\t\t\ttryingLocale, message;\n\n\t\t\tlocale = this.locale;\n\t\t\tfallbackIndex = 0;\n\n\t\t\twhile ( locale ) {\n\t\t\t\t// Iterate through locales starting at most-specific until\n\t\t\t\t// localization is found. As in fi-Latn-FI, fi-Latn and fi.\n\t\t\t\tlocaleParts = locale.split( '-' );\n\t\t\t\tlocalePartIndex = localeParts.length;\n\n\t\t\t\tdo {\n\t\t\t\t\ttryingLocale = localeParts.slice( 0, localePartIndex ).join( '-' );\n\t\t\t\t\tmessage = this.messageStore.get( tryingLocale, messageKey );\n\n\t\t\t\t\tif ( message ) {\n\t\t\t\t\t\treturn message;\n\t\t\t\t\t}\n\n\t\t\t\t\tlocalePartIndex--;\n\t\t\t\t} while ( localePartIndex );\n\n\t\t\t\tif ( locale === 'en' ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tlocale = ( $.i18n.fallbacks[ this.locale ] &&\n\t\t\t\t\t\t$.i18n.fallbacks[ this.locale ][ fallbackIndex ] ) ||\n\t\t\t\t\t\tthis.options.fallbackLocale;\n\t\t\t\t$.i18n.log( 'Trying fallback locale for ' + this.locale + ': ' + locale + ' (' + messageKey + ')' );\n\n\t\t\t\tfallbackIndex++;\n\t\t\t}\n\n\t\t\t// key not found\n\t\t\treturn '';\n\t\t},\n\n\t\t/*\n\t\t * Destroy the i18n instance.\n\t\t */\n\t\tdestroy: function () {\n\t\t\t$.removeData( document, 'i18n' );\n\t\t},\n\n\t\t/**\n\t\t * General message loading API This can take a URL string for\n\t\t * the json formatted messages. Example:\n\t\t * <code>load('path/to/all_localizations.json');</code>\n\t\t *\n\t\t * To load a localization file for a locale:\n\t\t * <code>\n\t\t * load('path/to/de-messages.json', 'de' );\n\t\t * </code>\n\t\t *\n\t\t * To load a localization file from a directory:\n\t\t * <code>\n\t\t * load('path/to/i18n/directory', 'de' );\n\t\t * </code>\n\t\t * The above method has the advantage of fallback resolution.\n\t\t * ie, it will automatically load the fallback locales for de.\n\t\t * For most usecases, this is the recommended method.\n\t\t * It is optional to have trailing slash at end.\n\t\t *\n\t\t * A data object containing message key- message translation mappings\n\t\t * can also be passed. Example:\n\t\t * <code>\n\t\t * load( { 'hello' : 'Hello' }, optionalLocale );\n\t\t * </code>\n\t\t *\n\t\t * A source map containing key-value pair of languagename and locations\n\t\t * can also be passed. Example:\n\t\t * <code>\n\t\t * load( {\n\t\t * bn: 'i18n/bn.json',\n\t\t * he: 'i18n/he.json',\n\t\t * en: 'i18n/en.json'\n\t\t * } )\n\t\t * </code>\n\t\t *\n\t\t * If the data argument is null/undefined/false,\n\t\t * all cached messages for the i18n instance will get reset.\n\t\t *\n\t\t * @param {string|Object} source\n\t\t * @param {string} locale Language tag\n\t\t * @return {jQuery.Promise}\n\t\t */\n\t\tload: function ( source, locale ) {\n\t\t\tvar fallbackLocales, locIndex, fallbackLocale, sourceMap = {};\n\t\t\tif ( !source && !locale ) {\n\t\t\t\tsource = 'i18n/' + $.i18n().locale + '.json';\n\t\t\t\tlocale = $.i18n().locale;\n\t\t\t}\n\t\t\tif ( typeof source === 'string' &&\n\t\t\t\t// source extension should be json, but can have query params after that.\n\t\t\t\tsource.split( '?' )[ 0 ].split( '.' ).pop() !== 'json'\n\t\t\t) {\n\t\t\t\t// Load specified locale then check for fallbacks when directory is\n\t\t\t\t// specified in load()\n\t\t\t\tsourceMap[ locale ] = source + '/' + locale + '.json';\n\t\t\t\tfallbackLocales = ( $.i18n.fallbacks[ locale ] || [] )\n\t\t\t\t\t.concat( this.options.fallbackLocale );\n\t\t\t\tfor ( locIndex = 0; locIndex < fallbackLocales.length; locIndex++ ) {\n\t\t\t\t\tfallbackLocale = fallbackLocales[ locIndex ];\n\t\t\t\t\tsourceMap[ fallbackLocale ] = source + '/' + fallbackLocale + '.json';\n\t\t\t\t}\n\t\t\t\treturn this.load( sourceMap );\n\t\t\t} else {\n\t\t\t\treturn this.messageStore.load( source, locale );\n\t\t\t}\n\n\t\t},\n\n\t\t/**\n\t\t * Does parameter and magic word substitution.\n\t\t *\n\t\t * @param {string} key Message key\n\t\t * @param {Array} parameters Message parameters\n\t\t * @return {string}\n\t\t */\n\t\tparse: function ( key, parameters ) {\n\t\t\tvar message = this.localize( key );\n\t\t\t// FIXME: This changes the state of the I18N object,\n\t\t\t// should probably not change the 'this.parser' but just\n\t\t\t// pass it to the parser.\n\t\t\tthis.parser.language = $.i18n.languages[ $.i18n().locale ] || $.i18n.languages[ 'default' ];\n\t\t\tif ( message === '' ) {\n\t\t\t\tmessage = key;\n\t\t\t}\n\t\t\treturn this.parser.parse( message, parameters );\n\t\t}\n\t};\n\n\t/**\n\t * Process a message from the $.I18N instance\n\t * for the current document, stored in jQuery.data(document).\n\t *\n\t * @param {string} key Key of the message.\n\t * @param {string} param1 [param...] Variadic list of parameters for {key}.\n\t * @return {string|$.I18N} Parsed message, or if no key was given\n\t * the instance of $.I18N is returned.\n\t */\n\t$.i18n = function ( key, param1 ) {\n\t\tvar parameters,\n\t\t\ti18n = $.data( document, 'i18n' ),\n\t\t\toptions = typeof key === 'object' && key;\n\n\t\t// If the locale option for this call is different then the setup so far,\n\t\t// update it automatically. This doesn't just change the context for this\n\t\t// call but for all future call as well.\n\t\t// If there is no i18n setup yet, don't do this. It will be taken care of\n\t\t// by the `new I18N` construction below.\n\t\t// NOTE: It should only change language for this one call.\n\t\t// Then cache instances of I18N somewhere.\n\t\tif ( options && options.locale && i18n && i18n.locale !== options.locale ) {\n\t\t\ti18n.locale = options.locale;\n\t\t}\n\n\t\tif ( !i18n ) {\n\t\t\ti18n = new I18N( options );\n\t\t\t$.data( document, 'i18n', i18n );\n\t\t}\n\n\t\tif ( typeof key === 'string' ) {\n\t\t\tif ( param1 !== undefined ) {\n\t\t\t\tparameters = slice.call( arguments, 1 );\n\t\t\t} else {\n\t\t\t\tparameters = [];\n\t\t\t}\n\n\t\t\treturn i18n.parse( key, parameters );\n\t\t} else {\n\t\t\t// FIXME: remove this feature/bug.\n\t\t\treturn i18n;\n\t\t}\n\t};\n\n\t$.fn.i18n = function () {\n\t\tvar i18n = $.data( document, 'i18n' );\n\n\t\tif ( !i18n ) {\n\t\t\ti18n = new I18N();\n\t\t\t$.data( document, 'i18n', i18n );\n\t\t}\n\n\t\treturn this.each( function () {\n\t\t\tvar $this = $( this ),\n\t\t\t\tmessageKey = $this.data( 'i18n' ),\n\t\t\t\tlBracket, rBracket, type, key;\n\n\t\t\tif ( messageKey ) {\n\t\t\t\tlBracket = messageKey.indexOf( '[' );\n\t\t\t\trBracket = messageKey.indexOf( ']' );\n\t\t\t\tif ( lBracket !== -1 && rBracket !== -1 && lBracket < rBracket ) {\n\t\t\t\t\ttype = messageKey.slice( lBracket + 1, rBracket );\n\t\t\t\t\tkey = messageKey.slice( rBracket + 1 );\n\t\t\t\t\tif ( type === 'html' ) {\n\t\t\t\t\t\t$this.html( i18n.parse( key ) );\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$this.attr( type, i18n.parse( key ) );\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t$this.text( i18n.parse( messageKey ) );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t$this.find( '[data-i18n]' ).i18n();\n\t\t\t}\n\t\t} );\n\t};\n\n\tfunction getDefaultLocale() {\n\t\tvar nav, locale = $( 'html' ).attr( 'lang' );\n\n\t\tif ( !locale ) {\n\t\t\tif ( typeof window.navigator !== undefined ) {\n\t\t\t\tnav = window.navigator;\n\t\t\t\tlocale = nav.language || nav.userLanguage || '';\n\t\t\t} else {\n\t\t\t\tlocale = '';\n\t\t\t}\n\t\t}\n\t\treturn locale;\n\t}\n\n\t$.i18n.languages = {};\n\t$.i18n.messageStore = $.i18n.messageStore || {};\n\t$.i18n.parser = {\n\t\t// The default parser only handles variable substitution\n\t\tparse: function ( message, parameters ) {\n\t\t\treturn message.replace( /\\$(\\d+)/g, function ( str, match ) {\n\t\t\t\tvar index = parseInt( match, 10 ) - 1;\n\t\t\t\treturn parameters[ index ] !== undefined ? parameters[ index ] : '$' + match;\n\t\t\t} );\n\t\t},\n\t\temitter: {}\n\t};\n\t$.i18n.fallbacks = {};\n\t$.i18n.debug = false;\n\t$.i18n.log = function ( /* arguments */ ) {\n\t\tif ( window.console && $.i18n.debug ) {\n\t\t\twindow.console.log.apply( window.console, arguments );\n\t\t}\n\t};\n\t/* Static members */\n\tI18N.defaults = {\n\t\tlocale: getDefaultLocale(),\n\t\tfallbackLocale: 'en',\n\t\tparser: $.i18n.parser,\n\t\tmessageStore: $.i18n.messageStore\n\t};\n\n\t// Expose constructor\n\t$.i18n.constructor = I18N;\n}( jQuery ) );\n"
  },
  {
    "path": "plugins/web/public/js/jquery.i18n.messagestore.js",
    "content": "/*!\n * jQuery Internationalization library - Message Store\n *\n * Copyright (C) 2012 Santhosh Thottingal\n *\n * jquery.i18n is dual licensed GPLv2 or later and MIT. You don't have to do anything special to\n * choose one license or the other and you don't have to notify anyone which license you are using.\n * You are free to use UniversalLanguageSelector in commercial projects as long as the copyright\n * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.\n *\n * @licence GNU General Public Licence 2.0 or later\n * @licence MIT License\n */\n\n( function ( $ ) {\n\t'use strict';\n\n\tvar MessageStore = function () {\n\t\tthis.messages = {};\n\t\tthis.sources = {};\n\t};\n\n\tfunction jsonMessageLoader( url ) {\n\t\tvar deferred = $.Deferred();\n\n\t\t$.getJSON( url )\n\t\t\t.done( deferred.resolve )\n\t\t\t.fail( function ( jqxhr, settings, exception ) {\n\t\t\t\t$.i18n.log( 'Error in loading messages from ' + url + ' Exception: ' + exception );\n\t\t\t\t// Ignore 404 exception, because we are handling fallabacks explicitly\n\t\t\t\tdeferred.resolve();\n\t\t\t} );\n\n\t\treturn deferred.promise();\n\t}\n\n\t/**\n\t * See https://github.com/wikimedia/jquery.i18n/wiki/Specification#wiki-Message_File_Loading\n\t */\n\tMessageStore.prototype = {\n\n\t\t/**\n\t\t * General message loading API This can take a URL string for\n\t\t * the json formatted messages.\n\t\t * <code>load('path/to/all_localizations.json');</code>\n\t\t *\n\t\t * This can also load a localization file for a locale <code>\n\t\t * load( 'path/to/de-messages.json', 'de' );\n\t\t * </code>\n\t\t * A data object containing message key- message translation mappings\n\t\t * can also be passed Eg:\n\t\t * <code>\n\t\t * load( { 'hello' : 'Hello' }, optionalLocale );\n\t\t * </code> If the data argument is\n\t\t * null/undefined/false,\n\t\t * all cached messages for the i18n instance will get reset.\n\t\t *\n\t\t * @param {string|Object} source\n\t\t * @param {string} locale Language tag\n\t\t * @return {jQuery.Promise}\n\t\t */\n\t\tload: function ( source, locale ) {\n\t\t\tvar key = null,\n\t\t\t\tdeferred = null,\n\t\t\t\tdeferreds = [],\n\t\t\t\tmessageStore = this;\n\n\t\t\tif ( typeof source === 'string' ) {\n\t\t\t\t// This is a URL to the messages file.\n\t\t\t\t$.i18n.log( 'Loading messages from: ' + source );\n\t\t\t\tdeferred = jsonMessageLoader( source )\n\t\t\t\t\t.done( function ( localization ) {\n\t\t\t\t\t\tmessageStore.set( locale, localization );\n\t\t\t\t\t} );\n\n\t\t\t\treturn deferred.promise();\n\t\t\t}\n\n\t\t\tif ( locale ) {\n\t\t\t\t// source is an key-value pair of messages for given locale\n\t\t\t\tmessageStore.set( locale, source );\n\n\t\t\t\treturn $.Deferred().resolve();\n\t\t\t} else {\n\t\t\t\t// source is a key-value pair of locales and their source\n\t\t\t\tfor ( key in source ) {\n\t\t\t\t\tif ( Object.prototype.hasOwnProperty.call( source, key ) ) {\n\t\t\t\t\t\tlocale = key;\n\t\t\t\t\t\t// No {locale} given, assume data is a group of languages,\n\t\t\t\t\t\t// call this function again for each language.\n\t\t\t\t\t\tdeferreds.push( messageStore.load( source[ key ], locale ) );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn $.when.apply( $, deferreds );\n\t\t\t}\n\n\t\t},\n\n\t\t/**\n\t\t * Set messages to the given locale.\n\t\t * If locale exists, add messages to the locale.\n\t\t *\n\t\t * @param {string} locale\n\t\t * @param {Object} messages\n\t\t */\n\t\tset: function ( locale, messages ) {\n\t\t\tif ( !this.messages[ locale ] ) {\n\t\t\t\tthis.messages[ locale ] = messages;\n\t\t\t} else {\n\t\t\t\tthis.messages[ locale ] = $.extend( this.messages[ locale ], messages );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t *\n\t\t * @param {string} locale\n\t\t * @param {string} messageKey\n\t\t * @return {boolean}\n\t\t */\n\t\tget: function ( locale, messageKey ) {\n\t\t\treturn this.messages[ locale ] && this.messages[ locale ][ messageKey ];\n\t\t}\n\t};\n\n\t$.extend( $.i18n.messageStore, new MessageStore() );\n}( jQuery ) );\n"
  },
  {
    "path": "plugins/web/public/scss/common.scss",
    "content": "@import \"reset\";\n\n.container {\n  padding: 20px;\n  max-width: 400px;\n  margin: auto;\n}\n\n.mi_logo {\n  width: 48px;\n  height: 48px;\n  margin: 30px auto;\n}\n\n.dear_user {\n  font-size: 16px;\n  font-weight: bold;\n  padding: 10px 0;\n}\n\n.help_phone {\n  padding: 10px 0;\n}\n\n.modal {\n  display: none;\n  opacity: 0;\n  position: fixed;\n  z-index: 999;\n  left: 0;\n  top: 0;\n  height: 100%;\n  width: 100%;\n  transition: opacity .5s;\n}\n\n.allow_btn {\n  margin-top: 60px;\n}\n\n.modal.visible {\n  display: block;\n  opacity: 1;\n}\n\n.modal_mask {\n  position: absolute;\n  left: 0;\n  top: 0;\n  width: 100%;\n  height: 100%;\n  opacity: .4;\n  filter: alpha(opacity=40);\n  background-color: black;\n}\n\n.modal_box {\n  text-align: center;\n  position: absolute;\n  bottom: -30px;\n  width: 90%;\n  left: 50%;\n  box-shadow: 0 1px 8px rgba(128, 128, 128, 0.3);\n  border: 1px solid #d1d1d1;\n  border-radius: 10px;\n  overflow: hidden;\n  background-color: white;\n  transition: width .5s ease, height .5s ease;\n  -webkit-transform: translate(-50%, -50%);\n  transform: translate(-50%, -50%);\n  -webkit-transform: translate(-50%, -50%, 0);\n  transform: translate(-50%, -50%, 0);\n  _top: 0;\n  _left: 0;\n  _margin-left: 0;\n  _margin-top: 0;\n  max-width: 400px;\n}\n\n.modal_body {\n  margin: 20px;\n  text-align: left;\n}\n\n.modal_footer {\n  display: flex;\n  border-top: 1px solid #f8f8f8;\n}\n\n.modal_btn {\n  flex: 1;\n  padding: 15px 0;\n}\n\n.modal_btn_ok {\n  color: #ff6700;\n  border-left: 1px solid #f8f8f8;\n}\n\n.btn {\n  margin-bottom: 20px;\n  text-align: center;\n  padding: 12px 0;\n  border-radius: 6px;\n}\n\n.btn_ok {\n  background-color: #ff6700;\n  color: #fff;\n}\n\n.btn_no {\n  background-color: #fff;\n  color: #999;\n  border: 1px solid #d3d3d3;\n}\n\n.state {\n  margin-top: 30px;\n  img {\n    width: 100px;\n    height: 100px;\n    margin-top: 40px;\n  }\n  dd {\n    font-size: 30px;\n    margin: 20px 0;\n  }\n}\n\n\n.device_list {\n  margin: 20px 0 20px 30px;\n  list-style-type: disc;\n  &.gray {\n    width: 220px;\n    color: #999;\n    margin: 40px auto 0 auto;\n  }\n}\n\n.caution {\n  margin: 30px 0;\n  .line {\n    width: 100%;\n    margin-bottom: -10px;\n    border-bottom: 1px solid #f0f0f0;\n  }\n  .txt {\n    color: #999;\n    background-color: #fff;\n    padding: 5px 10px;\n  }\n}\n\n.tips {\n  margin: 20px 0;\n}\n\n.icon_gter {\n  width: 10%;\n  height: 16px;\n  display: block;\n  position: relative;\n  &:after {\n    content: \"\";\n    width: 12px;\n    height: 12px;\n    border-width: 1px;\n    border-style: solid;\n    border-color: transparent transparent rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3);\n    -webkit-transform: rotate(-135deg);\n    transform: rotate(-135deg);\n    position: absolute;\n    left: 5px;\n    top: 4px;\n  }\n}\n\n.icon_lser {\n  width: 10%;\n  height: 16px;\n  display: block;\n  position: relative;\n  &:after {\n    content: \"\";\n    width: 12px;\n    height: 12px;\n    border-width: 1px;\n    border-style: solid;\n    border-color: transparent transparent rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.3);\n    -webkit-transform: rotate(45deg);\n    transform: rotate(45deg);\n    position: absolute;\n    left: 5px;\n    top: 4px;\n  }\n}\n\n.active_tips {\n  text-align: center;\n}\n\n.more_tips {\n  .tips {\n    height: 60px;\n    overflow: auto;\n  }\n}\n\n.more_sec_info {\n  font-size: 12px;\n}\n\n\n.lang-select-list {\n  height: 20px;\n  line-height: 20px;\n  text-align: center;\n  li {\n    font-size: 14px;\n    display: inline-block;\n    a {\n      padding: 10px;\n      color: #999;\n      &.current {\n        color: #ef5b00;\n      }\n    }\n  }\n}\n\n.outlook_tips {\n  color: #f66;\n  font-size: 12px;\n  padding-bottom: 20px;\n  display: none;\n}"
  },
  {
    "path": "plugins/web/public/scss/reset.scss",
    "content": "  * {\n    margin: 0;\n    padding: 0;\n  }\n\n  a,\n  a:hover {\n    text-decoration: none;\n    color: #09f;\n  }\n\n  body {\n    font-size: 14px;\n    font-family: arial, \"Hiragino Sans GB\", \"Microsoft YaHei\", \"微軟正黑體\", \"儷黑 Pro\", sans-serif;\n    color: #000;\n    background-color: #fff;\n  }\n\n  .tac {\n    text-align: center;\n  }\n\n  .fl {\n    float: left;\n  }\n\n  .fr {\n    float: right\n  }\n\n  ul {\n    list-style: none;\n  }\n\n  .clearfix {\n    &:before,\n    &:after {\n      content: \" \";\n      display: table;\n    }\n    &:after {\n      clear: both;\n    }\n  }"
  },
  {
    "path": "plugins/web/templates/activeSync.html",
    "content": "<!DOCTYPE html>\n<html lang=\"cn\">\n\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0,user-scalable=no\">\n  <title data-i18n=\"doc_title\">邮箱激活系统</title>\n  <link rel=\"stylesheet\" href=\"/static/css/common.css\">\n  <link rel=\"icon\" href=\"/static/favicon.ico\">\n  <script src=\"/static/js/jquery/1.8.1/jquery.min.js\"></script>\n  <script src=\"/static/js/jquery.i18n/1.0.4/jquery.i18n.js\"></script>\n  <script src=\"/static/js/jquery.i18n/1.0.4/jquery.i18n.messagestore.js\"></script>\n  <script src=\"/static/i18n/i18n.js\"></script>\n</head>\n\n<body>\n  <div class=\"container\">\n    <div class=\"mi_logo tac\">\n      <svg width=\"100%\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n        <rect width=\"48\" height=\"48\" rx=\"3\" ry=\"3\" style=\"fill:#ff6700\"></rect>\n        <rect x=\"10\" y=\"15\" width=\"4.2\" height=\"18\" style=\"fill:#FFFFFF\"></rect>\n        <rect x=\"33.75\" y=\"15\" width=\"4.2\" height=\"18\" style=\"fill:#FFFFFF\"></rect>\n        <rect x=\"11.25\" y=\"15\" width=\"15\" height=\"4.1\" style=\"fill:#FFFFFF\"></rect>\n        <rect x=\"26.2\" y=\"20.55\" width=\"4.2\" height=\"12.5\" style=\"fill:#FFFFFF\"></rect>\n        <rect x=\"20.6\" y=\"15\" width=\"9.8\" height=\"9.8\" rx=\"4.4\" ry=\"4.4\" style=\"fill:#FFFFFF\"></rect>\n        <rect x=\"20.2\" y=\"19\" width=\"6\" height=\"6\" rx=\"2\" ry=\"2\" style=\"fill:#ff6700\"></rect>\n        <rect x=\"18\" y=\"19.1\" width=\"4\" height=\"2.2\" style=\"fill:#ff6700\"></rect>\n        <rect x=\"24.2\" y=\"23\" width=\"1.94\" height=\"10\" style=\"fill:#ff6700\"></rect>\n        <rect x=\"18.1\" y=\"22.8\" width=\"4.2\" height=\"10.2\" style=\"fill:#FFFFFF\"></rect>\n      </svg>\n    </div>\n    <p class=\"dear_user\" data-i18n=\"[html]dear_user\">亲爱的<span class=\"email\"></span></p>\n    <p data-i18n=\"[html]new_device\">您的邮箱 <span class='email'></span>正在一台新的设备（<span class='device'></span>）上登录，详情如下\n    </p>\n    <ul class=\"device_list\"></ul>\n    <p class=\"outlook_tips\" data-i18n=\"outlook_tips\">您使用的是outlook客户端，用户名和密码会被保存到第三方微软公司的服务器中，存在安全风险，推荐使用手机自带的邮件客户端</p>\n    <p data-i18n=\"[html]change_pwd\">如果这不是您本人操作，您的邮箱密码可能已经泄露，请登录到内网帐号中心修改密码并拒绝该请求</p>\n    <p class=\"help_phone\" data-i18n=\"[html]help_phone\">如需协助请联系IT部门</p>\n    <div class=\"btn btn_ok allow_btn\" data-i18n=\"allow\">允许</div>\n    <div class=\"btn btn_no reject_btn\" data-i18n=\"reject\">拒绝</div>\n    <div class=\"modal ok_modal\">\n      <div class=\"modal_mask\"></div>\n      <div class=\"modal_box\">\n        <div class=\"modal_body\" data-i18n=\"[html]allow_confirm_tips\">确定后，将同步您的邮箱到该设备，如需禁用该设备，请登录内网帐号中心的手机邮箱中进行操作</div>\n        <div class=\"modal_footer\">\n          <div class=\"modal_btn_no modal_btn\" data-i18n=\"cancel\">取消</div>\n          <div class=\"modal_btn_ok modal_btn\" data-i18n=\"ok\">确定</div>\n        </div>\n      </div>\n    </div>\n    <div class=\"modal no_modal\">\n      <div class=\"modal_mask\"></div>\n      <div class=\"modal_box\">\n        <div class=\"modal_body\" data-i18n=\"[html]reject_manage_account\">拒绝后，将无法同步您的邮箱到该设备。如需重新激活该设备，请登录内网帐号中心的手机邮箱中进行操作</div>\n        <div class=\"modal_footer\">\n          <div class=\"modal_btn_no modal_btn\" data-i18n=\"cancel\">取消</div>\n          <div class=\"modal_btn_ok modal_btn\" data-i18n=\"reject\">拒绝</div>\n        </div>\n      </div>\n    </div>\n  </div>\n  <script>\n  $(function() {\n    var data = {\n      email: '{{.Name}}',\n      device: '{{.DeviceType}}',\n      deviceInfo: [{\n        name: $.i18n('device_model'),\n        value: '{{.DeviceType}}'\n      }, {\n        name: $.i18n('device_id'),\n        value: '{{.DeviceId}}'\n      }, {\n      name: $.i18n('IMEI'),\n      value: '{{.Imei}}'\n    },{\n      name: $.i18n('phone_number'),\n      value: '{{.PhoneNumber}}'\n    }]\n    };\n    $('.username').text(data.name);\n    $('.email').text(data.email);\n    $('.device').text(data.device);\n    if (data.device == 'Outlook') {\n      $('.outlook_tips').show();\n    }\n    var deviceListHtml = [];\n    for (var i = data.deviceInfo.length - 1; i >= 0; i--) {\n      var li = '<li>' + data.deviceInfo[i].name + ' : ' + data.deviceInfo[i].value + '</li>';\n      deviceListHtml.push(li);\n    }\n    deviceListHtml = deviceListHtml.join('');\n    $('.device_list').html(deviceListHtml);\n    $('.allow_btn').on('click', function() {\n      $('.ok_modal').addClass('visible');\n    });\n    $('.reject_btn').on('click', function() {\n      $('.no_modal').addClass('visible');\n    });\n    $('.ok_modal .modal_btn_ok').on('click', function() {\n      $.ajax({\n          url: '/a/activedevice',\n          type: 'POST',\n          dataType: 'json',\n          timeout: 10000,\n          data: {\n            c: '{{.Code}}'\n          }\n        })\n        .success(function() {\n          location.reload();\n        });\n    });\n    $('.no_modal .modal_btn_ok').on('click', function() {\n      $.ajax({\n          url: '/a/ignoredevice',\n          type: 'POST',\n          dataType: 'json',\n          timeout: 10000,\n          data: {\n            c: '{{.Code}}'\n          }\n        })\n        .success(function() {\n          location.reload();\n        });\n    });\n    $('.modal_btn_no,.modal_mask').on('click', function() {\n      $('.modal').removeClass('visible');\n    });\n  });\n  </script>\n</body>\n\n</html>"
  },
  {
    "path": "plugins/web/templates/deviceState.html",
    "content": "<!DOCTYPE html>\n<html lang=\"cn\">\n\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0,user-scalable=no\">\n  <title data-i18n=\"doc_title\">邮箱激活系统</title>\n  <link rel=\"stylesheet\" href=\"/static/css/common.css\">\n  <link rel=\"icon\" href=\"/static/favicon.ico\">\n  <script src=\"/static/js/jquery/1.8.1/jquery.min.js\"></script>\n  <script src=\"/static/js/jquery.i18n/1.0.4/jquery.i18n.js\"></script>\n  <script src=\"/static/js/jquery.i18n/1.0.4/jquery.i18n.messagestore.js\"></script>\n  <script src=\"/static/i18n/i18n.js\"></script>\n</head>\n\n<body>\n  <div class=\"container\">\n    <dl class=\"state tac\">\n      <dt><img alt=\"state_logo\"></dt>\n      <dd></dd>\n    </dl>\n    <ul class=\"device_list gray\"></ul>\n    <div class=\"caution\">\n      <div class=\"line\"></div>\n      <div class=\"tac\"><span class=\"txt\" data-i18n=\"caution\">温馨提示</span></div>\n      <p class=\"active_tips tips\" data-i18n=\"[html]auth_to_mis_manage\">已授权设备请登录到内网账号中心中的“手机邮箱”中进行管理\n      </p>\n      <div class=\"reject_tips\">\n        <p class=\"tips\" data-i18n=\"[html]to_mis_change_pwd\">如果该设备不是您的设备，您的密码可能已经泄漏，请登录到内网账号中心修改密码</p>\n        <p class=\"tips\" data-i18n=\"[html]reject_to_mis_manage\">已拒绝设备请登录到内网账号中心中的“手机邮箱”中进行管理\n        </p>\n      </div>\n      <div class=\"exceed_tips\">\n        <p class=\"tips\" data-i18n=\"[html]devices_exceeds_the_limit\">已经激活的设备数超出了10台的限制，请登录到内网账号中心，在“手机邮箱”中删除不再使用的设备\n        </p>\n      </div>\n      <div class=\"more_tips\">\n        <div class=\"tips\">\n          <p class=\"current\"></p>\n        </div>\n        <p class=\"more_sec_info tac\" data-i18n=\"[html]more_sec_info\">更多安全知识，请访问<a href=\"https://sec.xiaomi.com\">小米安全中心</a></p>\n      </div>\n    </div>\n  </div>\n  <script>\n  $(function() {\n    $('.active_tips, .reject_tips, .exceed_tips, .more_tips, .device_list').hide();\n    var deviceInfo = [{\n      name: $.i18n('device_model'),\n      value: '{{.DeviceType}}'\n    }, {\n      name: $.i18n('device_id'),\n      value: '{{.DeviceId}}'\n    }, {\n      name: $.i18n('IMEI'),\n      value: '{{.Imei}}'\n    },{\n      name: $.i18n('phone_number'),\n      value: '{{.PhoneNumber}}'\n    }];\n    var secTips = [];\n    var res = {\n      STATE_ACTIVED: {\n        title: $.i18n('device_actived'),\n        img: '/static/imgs/actived.png',\n      },\n      STATE_REJECTED: {\n        title: $.i18n('device_rejected'),\n        img: '/static/imgs/refused.png'\n      },\n      STATE_EXCEED: {\n        title: $.i18n('device_exceed'),\n        img: '/static/imgs/refused.png'\n      },\n      STATE_NOTFOUND: {\n        title: $.i18n('page_not_found'),\n        img: '/static/imgs/refused.png'\n      },\n      STATE_INVALID: {\n        title: $.i18n('link_invalid'),\n        img: '/static/imgs/refused.png'\n      }\n    };\n    var state = '{{.ActiveStatus}}';\n    var data = res[state];\n    $('.state img').attr({\n      src: data.img\n    });\n    $('.state dd').text(data.title);\n    var deviceListHtml = [];\n    for (var i = 0; i < deviceInfo.length; i++) {\n      var li = '<li>' + deviceInfo[i].name + ' : ' + deviceInfo[i].value + '</li>';\n      deviceListHtml.push(li);\n    }\n    deviceListHtml = deviceListHtml.join('');\n    $('.device_list').html(deviceListHtml);\n    switch (state) {\n      case 'STATE_ACTIVED':\n        $('.active_tips,.device_list').show();\n        break;\n      case 'STATE_REJECTED':\n        $('.reject_tips,.device_list').show();\n        break;\n      case 'STATE_EXCEED':\n        $('.exceed_tips').show();\n        break;\n      case 'STATE_INVALID':\n      case 'STATE_NOTFOUND':\n        $('.more_tips').show();\n        break;\n    }\n    var tipsIndex = 0,\n      timeInterval = 2000;\n    $('.tips .current').text(secTips[tipsIndex]);\n    var nextTip = function() {\n      if (tipsIndex == secTips.length - 1) {\n        tipsIndex = 0;\n      } else {\n        tipsIndex++;\n      }\n      $('.tips .current').text(secTips[tipsIndex]);\n    }\n    var lastTip = function() {\n      if (tipsIndex == 0) {\n        tipsIndex = secTips.length - 1;\n      } else {\n        tipsIndex--;\n      }\n      $('.tips .current').text(secTips[tipsIndex]);\n    }\n    setInterval(nextTip, timeInterval);\n    $('.pre').on('click', lastTip);\n    $('.next').on('click', nextTip);\n  })\n  </script>\n</body>\n\n</html>"
  },
  {
    "path": "plugins/web/web.go",
    "content": "package web\n\nimport (\n\t\"exchange_proxy/logger\"\n\t\"exchange_proxy/models\"\n\t\"exchange_proxy/plugins/active_sync\"\n\n\t\"encoding/json\"\n\t\"html/template\"\n\t\"net/http\"\n)\n\ntype (\n\tApiData struct {\n\t\tName         string\n\t\tDeviceModel  string\n\t\tDeviceType   string\n\t\tDeviceId     string\n\t\tImei         string\n\t\tPhoneNumber  string\n\t\tActiveStatus string\n\t\tCode         string\n\t}\n\n\tRespData struct {\n\t\tCode    int\n\t\tData    string\n\t\tMessage string\n\t}\n)\n\nfunc Activation(w http.ResponseWriter, r *http.Request) {\n\t_ = r.ParseForm()\n\tc := r.FormValue(\"c\")\n\n\ttSync, _ := template.ParseFiles(\"plugins/web/templates/activeSync.html\")\n\ttState, _ := template.ParseFiles(\"plugins/web/templates/deviceState.html\")\n\n\tvar (\n\t\tdeviceName string\n\t\tdeviceMode string\n\t\timei       string\n\t\tdeviceId   string\n\t\tdeviceNum  int\n\n\t\tapiDate ApiData\n\t)\n\n\tif c != \"\" {\n\t\t// 检查激活码\n\t\terr, has, user, deviceInfo := active_sync.CheckActiveCode(c)\n\t\t// 激活码是存在的\n\t\tif err == nil && has {\n\t\t\t// 获取当前用户的设备数\n\t\t\tdeviceNum = models.GetDeviceNum(user)\n\t\t\tdeviceId = deviceInfo.DeviceId\n\n\t\t\tapiDate.Name = user\n\t\t\tapiDate.DeviceId = deviceId\n\t\t\tapiDate.DeviceModel = deviceInfo.DeviceType\n\t\t\tapiDate.DeviceType = deviceInfo.DeviceType\n\t\t\tapiDate.Code = c\n\n\t\t\t// 取出手机端通过WBXML协议获取的数据\n\t\t\twbxmlInfo, err := models.GetDeviceInfoByDeviceId(deviceId)\n\t\t\tif err == nil {\n\t\t\t\tdeviceName = wbxmlInfo.FriendlyName\n\t\t\t\tdeviceName = wbxmlInfo.Model\n\t\t\t\timei = wbxmlInfo.IMEI\n\t\t\t\tphone := wbxmlInfo.PhoneNumber\n\n\t\t\t\tapiDate.DeviceModel = deviceMode\n\t\t\t\tapiDate.Imei = imei\n\t\t\t\tapiDate.DeviceType = deviceName\n\t\t\t\tapiDate.PhoneNumber = phone\n\t\t\t}\n\t\t\tCodeStatus := deviceInfo.State\n\t\t\tdeviceStatue := models.GetDeviceState(user, deviceId)\n\t\t\tlogger.Log.Infof(\"user: %v, deviceId: %v, CodeStatus: %v, deviceStatue: %v\", user, deviceId, CodeStatus, deviceStatue)\n\t\t\tswitch CodeStatus {\n\t\t\tcase 0:\n\t\t\t\t// 显示已激活的状态页面\n\t\t\t\tif deviceStatue == 0 {\n\t\t\t\t\tapiDate.ActiveStatus = \"STATE_ACTIVED\"\n\t\t\t\t\t_ = tState.Execute(w, apiDate)\n\t\t\t\t\t// 显示已拒绝状态的页面\n\t\t\t\t} else if deviceStatue == 3 {\n\t\t\t\t\tapiDate.ActiveStatus = \"STATE_REJECTED\"\n\t\t\t\t\t_ = tState.Execute(w, apiDate)\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\t// 激活的设备数已经超过10个\n\t\t\t\tif deviceNum >= 10 {\n\t\t\t\t\tapiDate.ActiveStatus = \"STATE_EXCEED\"\n\t\t\t\t\t_ = tState.Execute(w, apiDate)\n\t\t\t\t} else {\n\t\t\t\t\t// 显示激活页面\n\t\t\t\t\t_ = tSync.Execute(w, apiDate)\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// 激活码不存在\n\t\t\tapiDate.ActiveStatus = \"STATE_INVALID\"\n\t\t\t_ = tState.Execute(w, apiDate)\n\t\t}\n\t} else {\n\t\t//\t激活码为空\n\t\tapiDate.ActiveStatus = \"STATE_INVALID\"\n\t\t_ = tState.Execute(w, apiDate)\n\t}\n}\n\nfunc ActiveDevice(w http.ResponseWriter, r *http.Request) {\n\tif r.Method == \"POST\" {\n\t\t_ = r.ParseForm()\n\t\tc := r.FormValue(\"c\")\n\t\trespData := RespData{Code: 500, Data: \"\", Message: \"设备不存在\"}\n\t\tif c != \"\" {\n\t\t\tresult, user, device := active_sync.VerifyActiveCode(c)\n\t\t\tif result {\n\t\t\t\t_ = models.ActiveDevice(user, device.DeviceId)\n\t\t\t\t_, _ = active_sync.ResetActiveCodeStatus(c, user, device, 0)\n\t\t\t\trespData.Code = 200\n\t\t\t\trespData.Message = \"已经允许设备访问\"\n\t\t\t}\n\t\t}\n\t\tdata, _ := json.Marshal(respData)\n\t\t_, _ = w.Write(data)\n\t}\n}\n\nfunc IgnoreDevice(w http.ResponseWriter, r *http.Request) {\n\tif r.Method == \"POST\" {\n\t\t_ = r.ParseForm()\n\t\tc := r.FormValue(\"c\")\n\t\trespData := RespData{Code: 500, Data: \"\", Message: \"设备不存在\"}\n\t\tif c != \"\" {\n\t\t\tresult, user, device := active_sync.VerifyActiveCode(c)\n\t\t\tif result {\n\t\t\t\t_ = models.IgnoreDevice(user, device.DeviceId)\n\t\t\t\t_, _ = active_sync.ResetActiveCodeStatus(c, user, device, 3)\n\t\t\t\trespData.Code = 200\n\t\t\t\trespData.Message = \"已忽略该设备\"\n\t\t\t}\n\t\t}\n\t\tdata, _ := json.Marshal(respData)\n\t\t_, _ = w.Write(data)\n\t}\n}\n\nfunc NotFound(w http.ResponseWriter, r *http.Request) {\n\tw.WriteHeader(404)\n}\n"
  },
  {
    "path": "settings/settings.go",
    "content": "package settings\n\nimport (\n\t\"exchange_proxy/logger\"\n\t\"gopkg.in/ini.v1\"\n)\n\nvar (\n\tCfg *ini.File\n)\n\nfunc init() {\n\tvar err error\n\tsource := \"conf/app.ini\"\n\tCfg, err = ini.Load(source)\n\n\tif err != nil {\n\t\tlogger.Log.Panicln(err)\n\t}\n}\n"
  },
  {
    "path": "util/http_client.go",
    "content": "package util\n\nimport (\n\t\"encoding/json\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\t\"net/url\"\n)\n\ntype TokenResult struct {\n\tCode int    `json:\"code\"`\n\tData string `json:\"data\"`\n}\n\nfunc CheckToken(urlOtp, username, token string) (result bool, err error) {\n\tusers := make([]string, 0)\n\tusers = append(users, username)\n\ttokens := make([]string, 0)\n\ttokens = append(tokens, token)\n\tresp, err := http.PostForm(urlOtp, url.Values{\"username\": users, \"verificationCode\": tokens})\n\tif err == nil {\n\t\tdefer resp.Body.Close()\n\t\tret, err := ioutil.ReadAll(resp.Body)\n\n\t\tif err == nil {\n\t\t\ttokenResult := TokenResult{}\n\t\t\terr = json.Unmarshal(ret, &tokenResult)\n\t\t\tif err == nil {\n\t\t\t\tif tokenResult.Code == 200 && tokenResult.Data == \"success\" {\n\t\t\t\t\tresult = true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn result, err\n}\n"
  },
  {
    "path": "util/lib.go",
    "content": "package util\n\nimport (\n\t\"crypto/md5\"\n\t\"fmt\"\n\t\"io\"\n\t\"math/rand\"\n\t\"time\"\n)\n\n// md5\nfunc MD5(s string) (m string) {\n\th := md5.New()\n\t_, _ = io.WriteString(h, s)\n\treturn fmt.Sprintf(\"%x\", h.Sum(nil))\n}\n\n// 生成固定的随机字符串\nfunc RandomString(n int) string {\n\tvar letter = []rune(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\")\n\n\tb := make([]rune, n)\n\tfor i := range b {\n\t\tb[i] = letter[rand.Intn(len(letter))]\n\t}\n\treturn string(b)\n}\n\n// 生成激活码\nfunc GenerateAtiveCode(username, deviceId string) (code string) {\n\trandString := RandomString(10)\n\tt := fmt.Sprintf(\"%v%v%v%v\", username, deviceId, randString, time.Now().UnixNano())\n\tcode = MD5(t)[5:17]\n\treturn code\n\n}\n"
  },
  {
    "path": "util/wbxml/wbxml.go",
    "content": "package wbxml\n\nimport (\n\t\"bytes\"\n\t\"encoding/xml\"\n\t\"regexp\"\n\n\t\"exchange_proxy/logger\"\n\n\t. \"github.com/magicmonty/activesync-go/activesync\"\n\t. \"github.com/magicmonty/activesync-go/activesync/base\"\n\t. \"github.com/magicmonty/wbxml-go/wbxml\"\n)\n\n/*\n```\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<O:Provision xmlns:O=\"Provision\" xmlns:S=\"Settings\">\n    <S:DeviceInformation>\n        <S:Set>\n            <S:Model>MIX 2</S:Model>\n            <S:IMEI>888833336669999</S:IMEI>\n            <S:FriendlyName>MIX 2</S:FriendlyName>\n            <S:OS>Android 8.0.0</S:OS>\n            <S:PhoneNumber>+8618599999999</S:PhoneNumber>\n            <S:UserAgent>Android/8.0.0-EAS-1.3</S:UserAgent>\n            <S:MobileOperator>中国联通 (46001)</S:MobileOperator>\n        </S:Set>\n    </S:DeviceInformation>\n    <O:Policies>\n        <O:Policy>\n            <O:PolicyType>MS-EAS-Provisioning-WBXML</O:PolicyType>\n        </O:Policy>\n    </O:Policies>\n</O:Provision>\n```\n*/\n\ntype (\n\tProvision struct {\n\t\tXMLName           xml.Name `xml:\"Provision\"`\n\t\tText              string   `xml:\",chardata\"`\n\t\tO                 string   `xml:\"O,attr\"`\n\t\tS                 string   `xml:\"S,attr\"`\n\t\tDeviceInformation struct {\n\t\t\tText string `xml:\",chardata\"`\n\t\t\tSet  struct {\n\t\t\t\tText           string `xml:\",chardata\"`\n\t\t\t\tModel          string `xml:\"Model\"`\n\t\t\t\tIMEI           string `xml:\"IMEI\"`\n\t\t\t\tFriendlyName   string `xml:\"FriendlyName\"`\n\t\t\t\tOS             string `xml:\"OS\"`\n\t\t\t\tPhoneNumber    string `xml:\"PhoneNumber\"`\n\t\t\t\tUserAgent      string `xml:\"UserAgent\"`\n\t\t\t\tMobileOperator string `xml:\"MobileOperator\"`\n\t\t\t} `xml:\"Set\"`\n\t\t} `xml:\"DeviceInformation\"`\n\t\tPolicies struct {\n\t\t\tText   string `xml:\",chardata\"`\n\t\t\tPolicy struct {\n\t\t\t\tText       string `xml:\",chardata\"`\n\t\t\t\tPolicyType string `xml:\"PolicyType\"`\n\t\t\t} `xml:\"Policy\"`\n\t\t} `xml:\"Policies\"`\n\t}\n\n\tDeviceInfo struct {\n\t\tModel          string `json:\"model\"`\n\t\tIMEI           string `json:\"imei\"`\n\t\tFriendlyName   string `json:\"friendly_name\"`\n\t\tPhoneNumber    string `json:\"phone_number\"`\n\t\tMobileOperator string `json:\"mobile_operator\"`\n\t}\n)\n\nfunc removeInvalidChars(b []byte) []byte {\n\tre := regexp.MustCompile(\"[^\\x09\\x0A\\x0D\\x20-\\uD7FF\\uE000-\\uFFFD\\u10000-\\u10FFFF]\")\n\treturn re.ReplaceAll(b, []byte{})\n}\n\nfunc EncodeXML(xmlString []byte) {\n\txmlString = removeInvalidChars([]byte(xmlString))\n\tw := bytes.NewBuffer(make([]byte, 0))\n\te := NewEncoder(\n\t\tMakeCodeBook(PROTOCOL_VERSION_14_1),\n\t\tstring(xmlString),\n\t\tw)\n\terr := e.Encode()\n\tif err != nil {\n\t\tlogger.Log.Println(err.Error())\n\t} else {\n\t\tlogger.Log.Println(w)\n\t}\n}\n\nfunc getDecodeResult(data ...byte) string {\n\tvar result string\n\tresult, _ = Decode(bytes.NewBuffer(data), MakeCodeBook(PROTOCOL_VERSION_14_1))\n\treturn result\n}\n\nfunc Parse(data []byte) (deviceInfo DeviceInfo, err error) {\n\txmldata := getDecodeResult(data...)\n\n\tout := Provision{}\n\terr = xml.Unmarshal([]byte(xmldata), &out)\n\tif err == nil {\n\t\tlogger.Log.Debugf(\"Model: %v\", out.DeviceInformation.Set.Model)\n\t\tlogger.Log.Debugf(\"Imie: %v\", out.DeviceInformation.Set.IMEI)\n\t\tlogger.Log.Debugf(\"FriendlyName: %v\", out.DeviceInformation.Set.FriendlyName)\n\t\tlogger.Log.Debugf(\"PhoneNumber: %v\", out.DeviceInformation.Set.PhoneNumber)\n\t\tlogger.Log.Debugf(\"MobileOperator: %v\", out.DeviceInformation.Set.MobileOperator)\n\n\t\tdeviceInfo.Model = out.DeviceInformation.Set.Model\n\t\tdeviceInfo.IMEI = out.DeviceInformation.Set.IMEI\n\t\tdeviceInfo.FriendlyName = out.DeviceInformation.Set.FriendlyName\n\t\tdeviceInfo.PhoneNumber = out.DeviceInformation.Set.PhoneNumber\n\t\tdeviceInfo.MobileOperator = out.DeviceInformation.Set.MobileOperator\n\t}\n\n\treturn deviceInfo, err\n}\n"
  },
  {
    "path": "vars/vars.go",
    "content": "package vars\n\nimport (\n\t\"exchange_proxy/logger\"\n\t\"exchange_proxy/settings\"\n\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/go-redis/redis\"\n\t\"github.com/sirupsen/logrus\"\n\t\"github.com/vulcand/oxy/forward\"\n)\n\ntype (\n\tConfig struct {\n\t\tHost       []string\n\t\tBackend    string\n\t\tPort       int\n\t\tTLS        bool\n\t\tCert       string\n\t\tKey        string\n\t\tDebugLevel string\n\t}\n\n\tRedisConfig struct {\n\t\tHost     string\n\t\tPort     int\n\t\tDb       int\n\t\tPassword string\n\t}\n)\n\nvar (\n\tFwdOWA  *forward.Forwarder\n\tFwdSync *forward.Forwarder\n\n\tRedisInstance *redis.Client\n\n\tMailConfig Config\n\tRedisConf  RedisConfig\n\n\tRequestCmds  = make(map[string]bool)\n\tResponseCmds = make(map[string]bool)\n\tCurDir       string\n)\n\n// 代理用到的API接口的信息\nvar (\n\t// 用户激活的URL\n\tActiveUrl string\n\n\t//OTP接口\n\tOtpUrl string\n\n\t// 短信接口的URL，header头名称与值\n\tSmsApiUrl    string\n\tSmsApiHeader string\n\tSmsApiKey    string\n\n\t// 根据用户名查找手机号的接口的URL\n\tUserPhoneUrl string\n)\n\nfunc init() {\n\n\tsec := settings.Cfg.Section(\"mail\")\n\thosts := sec.Key(\"hosts\").MustString(\"mail.xsec.io\")\n\tMailConfig.Host = strings.Split(hosts, \",\")\n\tMailConfig.Port = sec.Key(\"port\").MustInt(443)\n\tMailConfig.Backend = sec.Key(\"backend\").MustString(\"https://8.8.8.8\")\n\tMailConfig.TLS = sec.Key(\"ssl\").MustBool(true)\n\tMailConfig.Cert = sec.Key(\"cert\").MustString(\"certs/ca.crt\")\n\tMailConfig.Key = sec.Key(\"key\").MustString(\"certs/ca.key\")\n\tMailConfig.DebugLevel = sec.Key(\"debug_level\").MustString(\"info\")\n\n\tsecRedis := settings.Cfg.Section(\"redis\")\n\tRedisConf.Host = secRedis.Key(\"host\").MustString(\"127.0.0.1\")\n\tRedisConf.Port = secRedis.Key(\"port\").MustInt(6379)\n\tRedisConf.Db = secRedis.Key(\"db\").MustInt(0)\n\tRedisConf.Password = secRedis.Key(\"password\").MustString(\"passw0rd\")\n\n\tFwdOWA, _ = forward.New()\n\tFwdSync, _ = forward.New()\n\n\t// 获取当前目录\n\tCurDir, _ = GetCurDir()\n\t// 初始化过滤指令列表\n\tinitActiveSyncCmds()\n\t// 初始化代理用的到API接口的值\n\tinitApiInfo()\n\t// 初始化日志级别\n\tinitDebugLevel()\n\n\tlogger.Log.Printf(\"host: %v, port: %v, ssl: %v, path: %v\", strings.Join(MailConfig.Host, \",\"), MailConfig.Port, MailConfig.TLS, CurDir)\n\n}\n\n// 手机端未激活前的过滤指令列表\nfunc initActiveSyncCmds() {\n\t// 请求的指令\n\tRequestCmds[\"SendMail\"] = true\n\tRequestCmds[\"FolderCreate\"] = true\n\tRequestCmds[\"FolderDelete\"] = true\n\tRequestCmds[\"FolderUpdate\"] = true\n\tRequestCmds[\"MeetingResponse\"] = true\n\tRequestCmds[\"ItemOperations\"] = true\n\tRequestCmds[\"SmartForward\"] = true\n\tRequestCmds[\"SmartReply\"] = true\n\tRequestCmds[\"MoveItems\"] = true\n\n\t// 响应的指令\n\tResponseCmds[\"Sync\"] = true\n\tResponseCmds[\"Search\"] = true\n\tResponseCmds[\"GetAttachment\"] = true\n\tResponseCmds[\"GetItemEstimate\"] = true\n\tResponseCmds[\"MeetingResponse\"] = true\n}\n\n// 初始化API接口的值\nfunc initApiInfo() {\n\tsec := settings.Cfg.Section(\"otp\")\n\tOtpUrl = sec.Key(\"url\").MustString(\"\")\n\n\tsec = settings.Cfg.Section(\"sms\")\n\tSmsApiUrl = sec.Key(\"url\").MustString(\"\")\n\tSmsApiHeader = sec.Key(\"header\").MustString(\"\")\n\tSmsApiKey = sec.Key(\"key\").MustString(\"\")\n\n\tsecUserInfo := settings.Cfg.Section(\"user_info\")\n\tUserPhoneUrl = secUserInfo.Key(\"user_phone\").MustString(\"\")\n\tActiveUrl = secUserInfo.Key(\"active_url\").MustString(\"\")\n}\n\n// 初始化log的级别\nfunc initDebugLevel() {\n\tlevel := strings.ToLower(MailConfig.DebugLevel)\n\tswitch level {\n\tcase \"info\":\n\t\tlogger.Log.Logger.SetLevel(logrus.InfoLevel)\n\tcase \"debug\":\n\t\tlogger.Log.Logger.SetLevel(logrus.DebugLevel)\n\tcase \"warn\":\n\t\tlogger.Log.Logger.SetLevel(logrus.WarnLevel)\n\tcase \"error\":\n\t\tlogger.Log.Logger.SetLevel(logrus.ErrorLevel)\n\tcase \"fatal\":\n\t\tlogger.Log.Logger.SetLevel(logrus.FatalLevel)\n\tdefault:\n\t\tlogger.Log.Logger.SetLevel(logrus.InfoLevel)\n\t}\n}\n\nfunc GetCurDir() (path string, err error) {\n\tpath, err = filepath.Abs(\".\")\n\treturn path, err\n}\n"
  }
]