diff --git a/LICENSE b/LICENSE index e1854e8679..1a3787f589 100644 --- a/LICENSE +++ b/LICENSE @@ -1,20 +1,166 @@ -The MIT License (MIT) - -Copyright (c) 2014-2015 almasaeed2010 - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Copyright (C) 2017 Pi-hole, LLC (https://pi-hole.net) +Pi-hole web interface + +This software is licensed under the European Union Public License (EUPL) +The license is available in the 22 official languages of the EU. The English version is included here. +Please see https://joinup.ec.europa.eu/community/eupl/og_page/eupl for official translations of the other languages. + +This license applies to the whole project EXCEPT the files located under + - styles/vendor, and + - scripts/vendor +whose licenses are located therein. + +------------------------------------------------------------- + +European Union Public Licence +V. 1.1 + +EUPL (C) the European Community 2007 + +This European Union Public Licence (the "EUPL") applies to the Work or Software (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work). + +The Original Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Original Work: + +Licensed under the EUPL V.1.1 + +or has expressed by any other mean his willingness to license under the EUPL. + +1. Definitions + +In this Licence, the following terms have the following meaning: + +- The Licence: this Licence. + +- The Original Work or the Software: the software distributed and/or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be. + +- Derivative Works: the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15. + +- The Work: the Original Work and/or its Derivative Works. + +- The Source Code: the human-readable form of the Work which is the most convenient for people to study and modify. + +- The Executable Code: any code which has generally been compiled and which is meant to be interpreted by a computer as a program. + +- The Licensor: the natural or legal person that distributes and/or communicates the Work under the Licence. + +- Contributor(s): any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work. + +- The Licensee or "You": any natural or legal person who makes any usage of the Software under the terms of the Licence. + +- Distribution and/or Communication: any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, on-line or off-line, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person. + +2. Scope of the rights granted by the Licence + +The Licensor hereby grants You a world-wide, royalty-free, non-exclusive, sub-licensable licence to do the following, for the duration of copyright vested in the Original Work: + +- use the Work in any circumstance and for all usage, +- reproduce the Work, +- modify the Original Work, and make Derivative Works based upon the Work, +- communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work, +- distribute the Work or copies thereof, +- lend and rent the Work or copies thereof, +- sub-license rights in the Work or copies thereof. + +Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so. + +In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed. + +The Licensor grants to the Licensee royalty-free, non exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence. + +3. Communication of the Source Code + +The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute and/or communicate the Work. + +4. Limitations on copyright + +Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Original Work or Software, of the exhaustion of those rights or of other applicable limitations thereto. + +5. Obligations of the Licensee + +The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following: + +Attribution right: the Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes and/or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification. + +Copyleft clause: If the Licensee distributes and/or communicates copies of the Original Works or Derivative Works based upon the Original Work, this Distribution and/or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence. + +Compatibility clause: If the Licensee Distributes and/or Communicates Derivative Works or copies thereof based upon both the Original Work and another work licensed under a Compatible Licence, this Distribution and/or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, "Compatible Licence" refers to the licences listed in the appendix attached to this Licence. Should the Licensee’s obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail. + +Provision of Source Code: When distributing and/or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute and/or communicate the Work. + +Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice. + +6. Chain of Authorship + +The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence. + +Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence. + +Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions to the Work, under the terms of this Licence. + +7. Disclaimer of Warranty + +The Work is a work in progress, which is continuously improved by numerous contributors. It is not a finished work and may therefore contain defects or "bugs" inherent to this type of software development. + +For the above reason, the Work is provided under the Licence on an "as is" basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence. + +This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work. + +8. Disclaimer of Liability + +Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, the Licensor will be liable under statutory product liability laws as far such laws apply to the Work. + +9. Additional agreements + +While distributing the Original Work or Derivative Works, You may choose to conclude an additional agreement to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or services consistent with this Licence. However, in accepting such obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any such warranty or additional liability. + +10. Acceptance of the Licence + +The provisions of this Licence can be accepted by clicking on an icon "I agree" placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions. + +Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution and/or Communication by You of the Work or copies thereof. + +11. Information to the public + +In case of any Distribution and/or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee. + +12. Termination of the Licence + +The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence. + +Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence. + +13. Miscellaneous + +Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work licensed hereunder. + +If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed and/or reformed so as necessary to make it valid and enforceable. + +The European Commission may publish other linguistic versions and/or new versions of this Licence, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number. + +All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice. + +14. Jurisdiction + +Any litigation resulting from the interpretation of this License, arising between the European Commission, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Communities, as laid down in article 238 of the Treaty establishing the European Community. + +Any litigation arising between Parties, other than the European Commission, and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business. + +15. Applicable Law + +This Licence shall be governed by the law of the European Union country where the Licensor resides or has his registered office. + +This licence shall be governed by the Belgian law if: + +- a litigation arises between the European Commission, as a Licensor, and any Licensee; +- the Licensor, other than the European Commission, has no residence or registered office inside a European Union country. + + +=== +Appendix + +"Compatible Licences" according to article 5 EUPL are: +- GNU General Public License (GNU GPL) v. 2 +- Open Software License (OSL) v. 2.1, v. 3.0 +- Common Public License v. 1.0 +- Eclipse Public License v. 1.0 +- Cecill v. 2.0 diff --git a/api.php b/api.php index 589ae0bd54..e8703cc741 100644 --- a/api.php +++ b/api.php @@ -1,4 +1,11 @@ "enabled" - )); + $data = array_merge($data, array("status" => "enabled")); + unlink("../custom_disable_timer"); } - elseif (isset($_GET['disable'], $_GET['token']) && $auth) { - check_csrf($_GET['token']); + elseif (isset($_GET['disable']) && $auth) { + if(isset($_GET["auth"])) + { + if($_GET["auth"] !== $pwhash) + die("Not authorized!"); + } + else + { + // Skip token validation if explicit auth string is given + check_csrf($_GET['token']); + } $disable = intval($_GET['disable']); // intval returns the integer value on success, or 0 on failure if($disable > 0) { + $timestamp = time(); exec("sudo pihole disable ".$disable."s"); + file_put_contents("../custom_disable_timer",($timestamp+$disable)*1000); } else { exec('sudo pihole disable'); + unlink("../custom_disable_timer"); } - $data = array_merge($data, Array( - "status" => "disabled" - )); + $data = array_merge($data, array("status" => "disabled")); } if (isset($_GET['getGravityDomains'])) { diff --git a/debug.php b/debug.php new file mode 100644 index 0000000000..84416cff05 --- /dev/null +++ b/debug.php @@ -0,0 +1,19 @@ + + + + +

Upload debug log and provide token once finished

+

Once you click this button a debug log will be generated and can automatically be uploaded if we detect a working internet connection.

+ + + + + + + diff --git a/gravity.php b/gravity.php index a0ece64ee0..15f6e605ca 100644 --- a/gravity.php +++ b/gravity.php @@ -1,3 +1,9 @@ + diff --git a/help.php b/help.php index 6f19ad6043..66818b104e 100644 --- a/help.php +++ b/help.php @@ -1,3 +1,9 @@ +
-

Main page

-

On the main page, you can see various Pi-hole statistics:

+

Dashboard

+

On the dashboard, you can see various Pi-hole statistics:

-

Note that the login session does not expire on the main page, as the summary is updated every 10 seconds which refreshes the session.

+

Note that the login session does not expire on the dashboard, as the summary is updated every 10 seconds which refreshes the session.

@@ -123,7 +129,7 @@

Authentication system (currently enableddisabled)

-

Using the command

sudo pihole -a -p pa22w0rd
where pa22w0rd is the password to be set in this example, one can enable the authentication system of this web interface. Thereafter, a login is required for most pages (the main page will show a limited amount of statistics). Note that the authentication system may be disabled again, by setting an empty password using the command shown above. The Help center will show more details concerning the authentication system only if it is enabled

+

Using the command

sudo pihole -a -p pa22w0rd
where pa22w0rd is the password to be set in this example, one can enable the authentication system of this web interface. Thereafter, a login is required for most pages (the dashboard will show a limited amount of statistics). Note that the authentication system may be disabled again, by setting an empty password using the command shown above. The Help center will show more details concerning the authentication system only if it is enabled

diff --git a/index.php b/index.php index 0651a6459d..659a868a10 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,9 @@ + - - } + diff --git a/queries.php b/queries.php index e466e825dd..8e81c677ef 100644 --- a/queries.php +++ b/queries.php @@ -1,3 +1,9 @@ + diff --git a/scripts/pi-hole/js/debug.js b/scripts/pi-hole/js/debug.js new file mode 100644 index 0000000000..c0db2ce01d --- /dev/null +++ b/scripts/pi-hole/js/debug.js @@ -0,0 +1,65 @@ +// Credit: http://stackoverflow.com/a/10642418/2087442 +function httpGet(ta,theUrl) +{ + var xmlhttp; + if (window.XMLHttpRequest) + { + // code for IE7+ + xmlhttp = new XMLHttpRequest(); + } + else + { + // code for IE6, IE5 + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() + { + if (xmlhttp.readyState === 4 && xmlhttp.status === 200) + { + ta.show(); + ta.empty(); + ta.append(xmlhttp.responseText); + } + }; + xmlhttp.open("GET", theUrl, false); + xmlhttp.send(); +} + +function eventsource() { + var ta = $("#output"); + var upload = $( "#upload" ); + var checked = ""; + + if(upload.prop("checked")) + { + checked = "upload"; + } + + // IE does not support EventSource - load whole content at once + if (typeof EventSource !== "function") { + httpGet(ta,"/admin/scripts/pi-hole/php/debug.php?IE&"+checked); + return; + } + + var host = window.location.host; + var source = new EventSource("/admin/scripts/pi-hole/php/debug.php?"+checked); + + // Reset and show field + ta.empty(); + ta.show(); + + source.addEventListener("message", function(e) { + ta.append(e.data); + }, false); + + // Will be called when script has finished + source.addEventListener("error", function(e) { + source.close(); + }, false); +} + +$("#debugBtn").on("click", function(){ + $("#debugBtn").attr("disabled", true); + $("#upload").attr("disabled", true); + eventsource(); +}); diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 6dd4ce65e6..20866b850b 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ // User menu toggle $("#dropdown-menu a").on("click", function(event) { $(this).parent().toggleClass("open"); @@ -8,6 +14,35 @@ $("body").on("click", function(event) { } }); +//The following functions allow us to display time until pi-hole is enabled after disabling. +//Works between all pages + +function secondsTimeSpanToHMS(s) { + var h = Math.floor(s/3600); //Get whole hours + s -= h*3600; + var m = Math.floor(s/60); //Get remaining minutes + s -= m*60; + return h+":"+(m < 10 ? "0"+m : m)+":"+(s < 10 ? "0"+s : s); //zero padding on minutes and seconds +} + +function countDown(){ + var ena = $("#enableLabel"); + var enaT = $("#enableTimer"); + var target = new Date(parseInt(enaT.html())); + var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000); + + if(seconds > 0){ + setTimeout(countDown,1000); + ena.text("Enable (" + secondsTimeSpanToHMS(seconds) + ")"); + } + else + { + ena.text("Enable"); + piholeChanged("enabled"); + localStorage.removeItem("countDownTarget"); + } +} + function piholeChanged(action) { var status = $("#status"); @@ -16,17 +51,17 @@ function piholeChanged(action) switch(action) { case "enabled": - status.html(" Active"); - ena.hide(); - dis.show(); - dis.removeClass("active"); - break; + status.html(" Active"); + ena.hide(); + dis.show(); + dis.removeClass("active"); + break; case "disabled": - status.html(" Offline"); - ena.show(); - dis.hide(); - break; + status.html(" Offline"); + ena.show(); + dis.hide(); + break; } } @@ -34,36 +69,53 @@ function piholeChanged(action) function piholeChange(action, duration) { var token = encodeURIComponent($("#token").html()); + var enaT = $("#enableTimer"); var btnStatus; switch(action) { case "enable": - btnStatus = $("#flip-status-enable"); - btnStatus.html(" "); - $.getJSON("api.php?enable&token=" + token, function(data) { - if(data.status === "enabled") { - btnStatus.html(""); - piholeChanged("enabled"); - } - }); - break; + btnStatus = $("#flip-status-enable"); + btnStatus.html(" "); + $.getJSON("api.php?enable&token=" + token, function(data) { + if(data.status === "enabled") { + btnStatus.html(""); + piholeChanged("enabled"); + } + }); + break; case "disable": - btnStatus = $("#flip-status-disable"); - btnStatus.html(" "); - $.getJSON("api.php?disable=" + duration + "&token=" + token, function(data) { - if(data.status === "disabled") { - btnStatus.html(""); - piholeChanged("disabled"); - } - }); - break; + btnStatus = $("#flip-status-disable"); + btnStatus.html(" "); + $.getJSON("api.php?disable=" + duration + "&token=" + token, function(data) { + if(data.status === "disabled") { + btnStatus.html(""); + piholeChanged("disabled"); + if(duration > 0) + { + enaT.html(new Date().getTime() + duration * 1000); + setTimeout(countDown,100); + } + } + }); + break; } } +$( document ).ready(function() { + var enaT = $("#enableTimer"); + var target = new Date(parseInt(enaT.html())); + var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000); + if (seconds > 0) + { + setTimeout(countDown,100); + } +}); + // Handle Enable/Disable $("#pihole-enable").on("click", function(e){ e.preventDefault(); + localStorage.removeItem("countDownTarget"); piholeChange("enable",""); }); $("#pihole-disable-permanently").on("click", function(e){ @@ -73,19 +125,23 @@ $("#pihole-disable-permanently").on("click", function(e){ $("#pihole-disable-10s").on("click", function(e){ e.preventDefault(); piholeChange("disable","10"); - setTimeout(function(){piholeChanged("enabled");},10000); }); $("#pihole-disable-30s").on("click", function(e){ e.preventDefault(); piholeChange("disable","30"); - setTimeout(function(){piholeChanged("enabled");},30000); }); $("#pihole-disable-5m").on("click", function(e){ e.preventDefault(); piholeChange("disable","300"); - setTimeout(function(){piholeChanged("enabled");},300000); +}); +$("#pihole-disable-custom").on("click", function(e){ + e.preventDefault(); + var custVal = $("#customTimeout").val(); + custVal = $("#btnMins").hasClass("active") ? custVal * 60 : custVal; + piholeChange("disable",custVal); }); + var piholeVersion = $("#piholeVersion").html(); var webVersion = $("#webVersion").html(); @@ -194,15 +250,15 @@ else // Hide "exact match" button on queryads.php page if version is 2.9.5 or lower if(versionCompare(piholeVersion, "v2.9.5") < 1) { - $("#btnSearchExact").hide(); + $("#btnSearchExact").hide(); } // Handle Strg + Enter button on Login page $(document).keypress(function(e) { - if((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $("#loginpw").is(":focus")) { - $("#loginform").attr("action", "settings.php"); - $("#loginform").submit(); - } + if((e.keyCode === 10 || e.keyCode === 13) && e.ctrlKey && $("#loginpw").is(":focus")) { + $("#loginform").attr("action", "settings.php"); + $("#loginform").submit(); + } }); function testCookies() diff --git a/scripts/pi-hole/js/gravity.js b/scripts/pi-hole/js/gravity.js index 02c91e3c7d..20cf9fcd5d 100644 --- a/scripts/pi-hole/js/gravity.js +++ b/scripts/pi-hole/js/gravity.js @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ function eventsource() { var alInfo = $("#alInfo"); var alSuccess = $("#alSuccess"); diff --git a/scripts/pi-hole/js/header.js b/scripts/pi-hole/js/header.js index 132f4fa2f3..e9f0478a61 100644 --- a/scripts/pi-hole/js/header.js +++ b/scripts/pi-hole/js/header.js @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ // Remove JS warning var jswarn = document.getElementById("js-warn-exit"); jswarn.parentNode.removeChild(jswarn); diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 89b1d2ba06..537188fbd1 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ // Define global variables var timeLineChart, queryTypeChart, forwardDestinationChart; diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index d0dc387d24..00a0b2efd6 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ // IE likes to cache too much :P $.ajaxSetup({cache: false}); @@ -201,3 +207,12 @@ $(function(){ $(this).closest("." + $(this).attr("data-hide")).hide(); }); }); + +$(document).ready(function () { + if (screen.width < 576) { + $(".input-group-btn").css("display", "initial"); + } + else { + $(".input-group-btn").css("display", "table-cell"); + } +}); diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 569122492e..8a7d45a7af 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ var tableApi; function escapeRegex(text) { diff --git a/scripts/pi-hole/js/queryads.js b/scripts/pi-hole/js/queryads.js index 6bf5e4696b..1b32856622 100644 --- a/scripts/pi-hole/js/queryads.js +++ b/scripts/pi-hole/js/queryads.js @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ var exact = ""; function quietfilter(ta,data) @@ -62,7 +68,7 @@ function eventsource() { if(q.val() === "yes") { quiet = true; - exact = "&exact"; + exact = "exact"; } // IE does not support EventSource - load whole content at once @@ -72,7 +78,7 @@ function eventsource() { } var host = window.location.host; - var source = new EventSource("/admin/scripts/pi-hole/php/queryads.php?domain="+domain.val().toLowerCase()+exact); + var source = new EventSource("/admin/scripts/pi-hole/php/queryads.php?domain="+domain.val().toLowerCase()+"&"+exact); // Reset and show field ta.empty(); diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 36a12ccd64..bce784dac2 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -1,18 +1,22 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ $(function () { - $("[data-mask]").inputmask(); -}); - -$(function(){ - $("#custom1val").ipAddress({s:4}); - $("#custom2val").ipAddress({s:4}); - $("#custom3val").ipAddress({v:6}); - $("#custom4val").ipAddress({v:6}); + $("[data-mask]").inputmask(); - $("#DHCPfrom").ipAddress({s:4}); - $("#DHCPto").ipAddress({s:4}); - $("#DHCProuter").ipAddress({s:4}); + $("[data-static]").on("click", function(){ + var row = $(this).closest("tr"); + var mac = row.find("#MAC").text(); + var ip = row.find("#IP").text(); + var host = row.find("#HOST").text(); + $("input[name=\"AddHostname\"]").val(host); + $("input[name=\"AddIP\"]").val(ip); + $("input[name=\"AddMAC\"]").val(mac); + }); }); - $(".confirm-reboot").confirm({ text: "Are you sure you want to send a reboot command to your Pi-Hole?", title: "Confirmation required", @@ -64,18 +68,35 @@ $(".confirm-flushlogs").confirm({ dialogClass: "modal-dialog modal-mg" }); +$(".api-token").confirm({ + text: "Make sure that nobody else can scan this code around you. They will have full access to the API without having to know the password. Note that the generation of the QR code will take some time.", + title: "Confirmation required", + confirm(button) { + window.open("scripts/pi-hole/php/api_token.php"); + }, + cancel(button) { + // nothing to do + }, + confirmButton: "Yes, show API token", + cancelButton: "No, go back", + post: true, + confirmButtonClass: "btn-danger", + cancelButtonClass: "btn-success", + dialogClass: "modal-dialog modal-mg" +}); + $("#DHCPchk").click(function() { $("input.DHCPgroup").prop("disabled", !this.checked); $("#dhcpnotice").prop("hidden", !this.checked).addClass("lookatme"); }); -var leasetable; +var leasetable, staticleasetable; $(document).ready(function() { if(document.getElementById("DHCPLeasesTable")) { leasetable = $("#DHCPLeasesTable").DataTable({ - dom: "<'row'<'col-sm-6'i><'col-sm-6'f>>" + - "<'row'<'col-sm-12'tr>>", + dom: "<'row'<'col-sm-12'tr>><'row'<'col-sm-6'i><'col-sm-6'f>>", + "columnDefs": [ { "bSortable": false, "orderable": false, targets: -1} ], "paging": false, "scrollCollapse": true, "scrollY": "200px", @@ -85,6 +106,20 @@ $(document).ready(function() { setTimeout(function(){leasetable.draw();},100); } ); } + if(document.getElementById("DHCPStaticLeasesTable")) + { + staticleasetable = $("#DHCPStaticLeasesTable").DataTable({ + dom: "<'row'<'col-sm-12'tr>><'row'<'col-sm-12'i>>", + "columnDefs": [ { "bSortable": false, "orderable": false, targets: -1} ], + "paging": false, + "scrollCollapse": true, + "scrollY": "200px", + "scrollX" : true + }); + $("#leaseexpand").on( "click", function () { + setTimeout(function(){staticleasetable.draw();},100); + } ); + } } ); // Handle hiding of alerts diff --git a/scripts/pi-hole/js/taillog.js b/scripts/pi-hole/js/taillog.js index 00cbfb15d5..ffe370fc5d 100644 --- a/scripts/pi-hole/js/taillog.js +++ b/scripts/pi-hole/js/taillog.js @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ var offset, timer, pre, scrolling = true; // Check every 200msec for fresh data diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php index 62c930efeb..d4ca64db3f 100644 --- a/scripts/pi-hole/php/add.php +++ b/scripts/pi-hole/php/add.php @@ -1,3 +1,11 @@ + + + 0) + { + require_once("../../vendor/qrcode.php"); + $qr = QRCode::getMinimumQRCode($pwhash, QR_ERROR_CORRECT_LEVEL_Q); + $qr->printHTML("10px"); + } + else + { + ?>

No password set

Not authorized!

+ + diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index 9d83428fda..a8a64e33a5 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -1,4 +1,11 @@ 0) + { + return true; + } + return false; + } + return false; + } + function getTopItems($argument) { global $log,$setupVars,$privacyMode; @@ -136,7 +163,7 @@ function getTopItems($argument) { // Process sorted domain names foreach ($dns_domains as $key => $value) { - if(isset($gravity_domains[$key]) && $adcounter < $qty) + if(ispositive($gravity_domains[$key]) && $adcounter < $qty) { // New entry for Top Ads $topAds[$key] = $value; @@ -327,10 +354,12 @@ function setShowBlockedPermitted() } function getAllQueries($orderBy) { - global $log,$showBlocked,$showPermitted,$privacyMode; + global $log,$showBlocked,$showPermitted,$privacyMode,$setupVars; $allQueries = array("data" => array()); $dns_queries = getDnsQueries($log); + $hostnames=array(); + // Create empty array for gravity $gravity_domains = getGravity(); $wildcard_domains = getWildcardListContent(); @@ -414,23 +443,37 @@ function getAllQueries($orderBy) { if((substr($status,0,2) === "Pi" && $showBlocked) || (substr($status,0,2) === "OK" && $showPermitted)) { $type = substr($exploded[count($exploded)-4], 6, -1); - $client = $exploded[count($exploded)-1]; + + if(istrue($setupVars["API_GET_CLIENT_HOSTNAME"])) { + $ip = $exploded[count($exploded) - 1]; + + if (isset($hostnames[$ip])) { + $client = $hostnames[$ip]; + } else { + $hostnames[$ip] = gethostbyaddr($ip); + $client = $hostnames[$ip]; + } + } + else + { + $client = $exploded[count($exploded)-1]; + } if($orderBy == "orderByClientDomainTime"){ - $allQueries['data'][hasHostName($client)][$domain][$time->format('Y-m-d\TH:i:s')] = $status; + $allQueries['data'][hasHostName($client)][$domain][$time->format('Y-m-d T H:i:s')] = $status; }elseif ($orderBy == "orderByClientTimeDomain"){ - $allQueries['data'][hasHostName($client)][$time->format('Y-m-d\TH:i:s')][$domain] = $status; + $allQueries['data'][hasHostName($client)][$time->format('Y-m-d T H:i:s')][$domain] = $status; }elseif ($orderBy == "orderByTimeClientDomain"){ - $allQueries['data'][$time->format('Y-m-d\TH:i:s')][hasHostName($client)][$domain] = $status; + $allQueries['data'][$time->format('Y-m-d T H:i:s')][hasHostName($client)][$domain] = $status; }elseif ($orderBy == "orderByTimeDomainClient"){ - $allQueries['data'][$time->format('Y-m-d\TH:i:s')][$domain][hasHostName($client)] = $status; + $allQueries['data'][$time->format('Y-m-d T H:i:s')][$domain][hasHostName($client)] = $status; }elseif ($orderBy == "orderByDomainClientTime"){ - $allQueries['data'][$domain][hasHostName($client)][$time->format('Y-m-d\TH:i:s')] = $status; + $allQueries['data'][$domain][hasHostName($client)][$time->format('Y-m-d T H:i:s')] = $status; }elseif ($orderBy == "orderByDomainTimeClient"){ - $allQueries['data'][$domain][$time->format('Y-m-d\TH:i:s')][hasHostName($client)] = $status; + $allQueries['data'][$domain][$time->format('Y-m-d T H:i:s')][hasHostName($client)] = $status; }else{ array_push($allQueries['data'], array( - $time->format('Y-m-d\TH:i:s'), + $time->format('Y-m-d T H:i:s'), $type, $domain, hasHostName($client), @@ -440,6 +483,7 @@ function getAllQueries($orderBy) { } } } + return $allQueries; } @@ -669,7 +713,7 @@ function overTime($entries, $gravity_domains) { $exploded = explode(" ", $entry); $domain = trim($exploded[count($exploded) - 3]); - if(isset($gravity_domains[$domain])) + if(ispositive($gravity_domains[$domain])) { if (isset($byTimeAds[$time])) { $byTimeAds[$time]++; @@ -709,7 +753,7 @@ function overTime10mins($entries, $gravity_domains=[]) { $exploded = explode(" ", $entry); $domain = trim($exploded[count($exploded) - 3]); - if(isset($gravity_domains[$domain])) + if(ispositive($gravity_domains[$domain])) { if (isset($byTimeAds[$time])) { $byTimeAds[$time]++; diff --git a/scripts/pi-hole/php/debug.php b/scripts/pi-hole/php/debug.php new file mode 100644 index 0000000000..93ae316643 --- /dev/null +++ b/scripts/pi-hole/php/debug.php @@ -0,0 +1,26 @@ + diff --git a/scripts/pi-hole/php/footer.php b/scripts/pi-hole/php/footer.php index 8f60954d80..34d7319fae 100644 --- a/scripts/pi-hole/php/footer.php +++ b/scripts/pi-hole/php/footer.php @@ -1,6 +1,44 @@ + + + + diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index 37ef790fdb..4453d99d59 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -1,4 +1,10 @@ + + $value) { + $loaddata[$key] = round($value, 2); + } // Get number of processing units available to PHP // (may be less than the number of online processors) $nproc = shell_exec('nproc'); + if(!is_numeric($nproc)) + { + $cpuinfo = file_get_contents('/proc/cpuinfo'); + preg_match_all('/^processor/m', $cpuinfo, $matches); + $nproc = count($matches[0]); + } // Get memory usage $data = explode("\n", file_get_contents("/proc/meminfo")); @@ -174,6 +191,7 @@ +
@@ -303,7 +321,7 @@ { echo "#7FFF00"; } - echo "\"> Load:  " . $loaddata[0] . "  " . $loaddata[1] . "  ". $loaddata[2] . ""; + echo "\" title=\"Detected $nproc cores\"> Load:  " . $loaddata[0] . "  " . $loaddata[1] . "  ". $loaddata[2] . ""; ?>
class="active"> - Main Page + Dashboard @@ -398,14 +416,19 @@ For 5 minutes +
  • + + Custom time + +
  • hidden="true"> - Enable    + Enable   
  • -
  • active"> +
  • active"> Tools @@ -431,6 +454,12 @@ Tail pihole.log
  • + + class="active"> + + Generate debug log + + diff --git a/scripts/pi-hole/php/loginpage.php b/scripts/pi-hole/php/loginpage.php index f71c428d4f..856d69a518 100644 --- a/scripts/pi-hole/php/loginpage.php +++ b/scripts/pi-hole/php/loginpage.php @@ -1,3 +1,11 @@ + +
    diff --git a/scripts/pi-hole/php/password.php b/scripts/pi-hole/php/password.php index 4abe9cfc85..40095563fd 100644 --- a/scripts/pi-hole/php/password.php +++ b/scripts/pi-hole/php/password.php @@ -1,4 +1,11 @@ + 0 && validMAC($mac)) + { + if(validIP($one) && strlen($two) == 0) + // dhcp-host=mac,IP - no HOST + array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>$one, "host"=>""]); + elseif(strlen($two) == 0) + // dhcp-host=mac,hostname - no IP + array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>"", "host"=>$one]); + else + // dhcp-host=mac,IP,hostname + array_push($dhcp_static_leases,["hwaddr"=>$mac, "IP"=>$one, "host"=>$two]); + } + else if(validIP($one) && validDomain($mac)) + { + // dhcp-host=hostname,IP - no MAC + array_push($dhcp_static_leases,["hwaddr"=>"", "IP"=>$one, "host"=>$mac]); + } + } + return true; +} + $DNSserverslist = [ "8.8.8.8" => "Google (Primary)", "208.67.222.222" => "OpenDNS (Primary)", "4.2.2.1" => "Level3 (Primary)", "199.85.126.10" => "Norton (Primary)", "8.26.56.26" => "Comodo (Primary)", + "84.200.69.80" => "DNS.WATCH (Primary)", "8.8.4.4" => "Google (Secondary)", "208.67.220.220" => "OpenDNS (Secondary)", "4.2.2.2" => "Level3 (Secondary)", "199.85.127.10" => "Norton (Secondary)", - "8.20.247.20" => "Comodo (Secondary)" + "8.20.247.20" => "Comodo (Secondary)", + "84.200.70.40" => "DNS.WATCH (Secondary)", ]; $error = ""; @@ -77,7 +133,7 @@ function validDomain($domain_name) } else { - $error .= "IP (".$IP.") is invalid!
    "; + $error .= "IP (".htmlspecialchars($IP).") is invalid!
    "; } } } @@ -118,11 +174,35 @@ function validDomain($domain_name) $extra .= "no-dnssec"; } + // Check if DNSinterface is set + if(isset($_POST["DNSinterface"])) + { + if($_POST["DNSinterface"] === "single") + { + $DNSinterface = "single"; + } + elseif($_POST["DNSinterface"] === "all") + { + $DNSinterface = "all"; + } + else + { + $DNSinterface = "local"; + } + } + else + { + // Fallback + $DNSinterface = "local"; + } + $return .= exec("sudo pihole -a -i ".$DNSinterface." -web"); + // If there has been no error we can save the new DNS server IPs if(!strlen($error)) { $IPs = implode (",", $DNSservers); exec("sudo pihole -a setdns ".$IPs." ".$extra); + $success .= htmlspecialchars($return)."
    "; $success .= "The DNS settings have been updated (using ".count($DNSservers)." DNS servers)"; } else @@ -163,7 +243,7 @@ function validDomain($domain_name) { if(!validDomain($domain)) { - $error .= "Top Domains/Ads entry ".$domain." is invalid!
    "; + $error .= "Top Domains/Ads entry ".htmlspecialchars($domain)." is invalid!
    "; } if(!$first) { @@ -182,7 +262,7 @@ function validDomain($domain_name) { if(!validIP($client)) { - $error .= "Top Clients entry ".$client." is invalid (use only IP addresses)!
    "; + $error .= "Top Clients entry ".htmlspecialchars($client)." is invalid (use only IP addresses)!
    "; } if(!$first) { @@ -316,27 +396,95 @@ function validDomain($domain_name) case "DHCP": + if(isset($_POST["addstatic"])) + { + $mac = $_POST["AddMAC"]; + $ip = $_POST["AddIP"]; + $hostname = $_POST["AddHostname"]; + + if(!validMAC($mac)) + { + $error .= "MAC address (".htmlspecialchars($mac).") is invalid!
    "; + } + $mac = strtoupper($mac); + + if(!validIP($ip) && strlen($ip) > 0) + { + $error .= "IP address (".htmlspecialchars($ip).") is invalid!
    "; + } + + if(!validDomain($hostname) && strlen($hostname) > 0) + { + $error .= "Host name (".htmlspecialchars($hostname).") is invalid!
    "; + } + + if(strlen($hostname) == 0 && strlen($ip) == 0) + { + $error .= "You can not omit both the IP address and the host name!
    "; + } + + if(strlen($hostname) == 0) + $hostname = "nohost"; + + if(strlen($ip) == 0) + $ip = "noip"; + + // Test if this MAC address is already included + readStaticLeasesFile(); + foreach($dhcp_static_leases as $lease) { + if($lease["hwaddr"] === $mac) + { + $error .= "Static release for MAC address (".htmlspecialchars($mac).") already defined!
    "; + break; + } + } + + if(!strlen($error)) + { + exec("sudo pihole -a addstaticdhcp ".$mac." ".$ip." ".$hostname); + $success .= "A new static address has been added"; + } + break; + } + + if(isset($_POST["removestatic"])) + { + $mac = $_POST["removestatic"]; + if(!validMAC($mac)) + { + $error .= "MAC address (".htmlspecialchars($mac).") is invalid!
    "; + } + $mac = strtoupper($mac); + + if(!strlen($error)) + { + exec("sudo pihole -a removestaticdhcp ".$mac); + $success .= "The static address with MAC address ".htmlspecialchars($mac)." has been removed"; + } + break; + } + if(isset($_POST["active"])) { // Validate from IP $from = $_POST["from"]; if (!validIP($from)) { - $error .= "From IP (".$from.") is invalid!
    "; + $error .= "From IP (".htmlspecialchars($from).") is invalid!
    "; } // Validate to IP $to = $_POST["to"]; if (!validIP($to)) { - $error .= "To IP (".$to.") is invalid!
    "; + $error .= "To IP (".htmlspecialchars($to).") is invalid!
    "; } // Validate router IP $router = $_POST["router"]; if (!validIP($router)) { - $error .= "Router IP (".$router.") is invalid!
    "; + $error .= "Router IP (".htmlspecialchars($router).") is invalid!
    "; } $domain = $_POST["domain"]; @@ -344,7 +492,7 @@ function validDomain($domain_name) // Validate Domain name if(!validDomain($domain)) { - $error .= "Domain name ".$domain." is invalid!
    "; + $error .= "Domain name ".htmlspecialchars($domain)." is invalid!
    "; } $leasetime = $_POST["leasetime"]; @@ -352,7 +500,7 @@ function validDomain($domain_name) // Validate Lease time length if(!is_numeric($leasetime) || intval($leasetime) < 0) { - $error .= "Lease time ".$leasetime." is invalid!
    "; + $error .= "Lease time ".htmlspecialchars($leasetime)." is invalid!
    "; } if(isset($_POST["useIPv6"])) @@ -369,7 +517,7 @@ function validDomain($domain_name) if(!strlen($error)) { exec("sudo pihole -a enabledhcp ".$from." ".$to." ".$router." ".$leasetime." ".$domain." ".$ipv6); - $success .= "The DHCP server has been activated ".$type; + $success .= "The DHCP server has been activated ".htmlspecialchars($type); } } else diff --git a/scripts/pi-hole/php/sub.php b/scripts/pi-hole/php/sub.php index e09f2d0a1e..bab6e51f83 100644 --- a/scripts/pi-hole/php/sub.php +++ b/scripts/pi-hole/php/sub.php @@ -1,3 +1,11 @@ + + 35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(l($){Q.1o.1t=l(){E=/\\b(?:(?:25[0-5]|2[0-4][0-9]|[1m]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[1m]?[0-9][0-9]?)\\b/;h E.1a(p.1i())};Q.1o.1S=l(){E=/\\b([A-16-9]{1,4}:){7}([A-16-9]{1,4})\\b/i;h E.1a(p.1i())};$.1X.1h({y:l(u,c){f(p.z==0)h;f(1k u==\'1f\'){c=(1k c==\'1f\')?c:u;h p.1d(l(){f(p.18){p.1s();p.18(u,c)}w f(p.1e){t C=p.1e();C.1L(S);C.1z(\'10\',c);C.1b(\'10\',u);C.1w()}})}w{f(p[0].18){u=p[0].1u;c=p[0].1C}w f(14.12&&14.12.19){t C=14.12.19();u=0-C.1D().1b(\'10\',-1E);c=u+C.1H.z}h{u:u,c:c}}},1B:l(s){s=$.1h({v:4},s);f(s.v==4){s.W=M I(\'[0-9]\',\'g\');s.r=\'R.R.R.R\'}f(s.v==6){s.W=M I(\'[A-16-9]\',\'1x\');s.r=\'x:x:x:x:x:x:x:x\'}s.D=s.r.K(\'\').Y();s.q=s.r.X(M I(s.D,\'g\'),\'\').K(\'\').Y();s.O=s.r.K(s.q).Y();h $(p).1d(l(){t a={k:T,n:T,o:T,d:T};a.d=$(p);f(a.d.m()==\'\'||!J(a.d.m()))a.d.m(s.r);a.d.1j(\'1Z\',(s.v==4?15:1c)).1j(\'1W\',(s.v==4?15:1c));l J(o){h 24("o.21"+s.v+"()")};l P(){a.k=a.d.y();a.o=J(L(a.d.m()))?L(a.d.m()):a.o;a.n=a.d.m().K(\'\')};l 1n(o){t G=o.K(s.q);1p(t j=0;j0)G[j]+=s.D}h G.H(s.q)};l L(o){t E=M I(s.O,\'g\');t 1g=M I(s.D,\'g\');h o.X(E,\'0\').X(1g,\'\')};l 11(e){1R(e.1Q){U 8:f(a.n[a.k.c-1]!=s.q){a.n[a.k.c-1]=s.D;a.d.m(a.n.H("")).m()}a.d.y(a.k.c-1);h B;V;U 13:U 1T:a.d.17();V;U 1P:f(a.n[a.k.c]!=s.q&&a.k.c=20&&e.F<=1N)||e.F>1J){f(Q.1q(e.F).1y(s.W)){a.n[a.k.c]=Q.1q(e.F);f(!J(L(a.n.H(\'\')))){f((a.k.c==0||a.n[a.k.c-1]==s.q)){1p(t i=a.k.c+1;i 0) { - tmp = buffer.join('').substring(0, ((j + 1) - chrs.length)) + "" + tmp; - } - var isValid = opts.regex["urlpre" + (j + 1)].test(tmp); - if (!strict && !isValid) { - pos = pos - j; - for (k = 0; k < opts.defaultPrefix.length; k++) { - buffer[pos] = opts.defaultPrefix[k]; pos++; - } - for (k = 0; k < tmp.length - 1; k++) { - buffer[pos] = tmp[k]; pos++; - } - return { "pos": pos }; - } - return isValid; - } else { - return false; - } - }, cardinality: j - }; - })(); - } - return result; - })() - }, - "r": { - validator: ".", - cardinality: 50 - } - }, - insertMode: false, - autoUnmask: false - }, "ip": { //ip-address mask mask: ["[[x]y]z.[[x]y]z.[[x]y]z.x[yz]", "[[x]y]z.[[x]y]z.[[x]y]z.[[x]y][z]"], definitions: { @@ -117,6 +56,17 @@ Optional extensions on the jquery.inputmask base definitionSymbol: "i" } } - } + }//, + // "ipv6": { //ip-address mask + // mask: ["[xxxx][:xxxx][:xxxx][:xxxx][:xxxx][:xxxx][:xxxx][:xxxx]"], + // //placeholder: '____:____:____:____:____:____:____:____:____', + // definitions: { + // 'x': { + // validator: "[0-9a-f]", + // cardinality: 1, + // casing: "upper" //auto uppercasing + // } + // } + // } }); })(jQuery); diff --git a/scripts/vendor/qrcode.php b/scripts/vendor/qrcode.php new file mode 100644 index 0000000000..4afb6eacfe --- /dev/null +++ b/scripts/vendor/qrcode.php @@ -0,0 +1,1543 @@ +typeNumber = 1; + $this->errorCorrectLevel = QR_ERROR_CORRECT_LEVEL_H; + $this->qrDataList = array(); + } + + function getTypeNumber() { + return $this->typeNumber; + } + + function setTypeNumber($typeNumber) { + $this->typeNumber = $typeNumber; + } + + function getErrorCorrectLevel() { + return $this->errorCorrectLevel; + } + + function setErrorCorrectLevel($errorCorrectLevel) { + $this->errorCorrectLevel = $errorCorrectLevel; + } + + function addData($data, $mode = 0) { + + if ($mode == 0) { + $mode = QRUtil::getMode($data); + } + + switch($mode) { + + case QR_MODE_NUMBER : + $this->addDataImpl(new QRNumber($data) ); + break; + + case QR_MODE_ALPHA_NUM : + $this->addDataImpl(new QRAlphaNum($data) ); + break; + + case QR_MODE_8BIT_BYTE : + $this->addDataImpl(new QR8BitByte($data) ); + break; + + case QR_MODE_KANJI : + $this->addDataImpl(new QRKanji($data) ); + break; + + default : + trigger_error("mode:$mode", E_USER_ERROR); + } + } + + function clearData() { + $qrDataList = array(); + } + + function addDataImpl(&$qrData) { + $this->qrDataList[] = $qrData; + } + + function getDataCount() { + return count($this->qrDataList); + } + + function getData($index) { + return $this->qrDataList[$index]; + } + + function isDark($row, $col) { + if ($this->modules[$row][$col] !== null) { + return $this->modules[$row][$col]; + } else { + return false; + } + } + + function getModuleCount() { + return $this->moduleCount; + } + + // used for converting fg/bg colors (e.g. #0000ff = 0x0000FF) + // added 2015.07.27 ~ DoktorJ + function hex2rgb($hex = 0x0) { + return array( + 'r' => floor($hex / 65536), + 'g' => floor($hex / 256) % 256, + 'b' => $hex % 256 + ); + } + + function make() { + $this->makeImpl(false, $this->getBestMaskPattern() ); + } + + function getBestMaskPattern() { + + $minLostPoint = 0; + $pattern = 0; + + for ($i = 0; $i < 8; $i++) { + + $this->makeImpl(true, $i); + + $lostPoint = QRUtil::getLostPoint($this); + + if ($i == 0 || $minLostPoint > $lostPoint) { + $minLostPoint = $lostPoint; + $pattern = $i; + } + } + + return $pattern; + } + + function createNullArray($length) { + $nullArray = array(); + for ($i = 0; $i < $length; $i++) { + $nullArray[] = null; + } + return $nullArray; + } + + function makeImpl($test, $maskPattern) { + + $this->moduleCount = $this->typeNumber * 4 + 17; + + $this->modules = array(); + for ($i = 0; $i < $this->moduleCount; $i++) { + $this->modules[] = QRCode::createNullArray($this->moduleCount); + } + + $this->setupPositionProbePattern(0, 0); + $this->setupPositionProbePattern($this->moduleCount - 7, 0); + $this->setupPositionProbePattern(0, $this->moduleCount - 7); + + $this->setupPositionAdjustPattern(); + $this->setupTimingPattern(); + + $this->setupTypeInfo($test, $maskPattern); + + if ($this->typeNumber >= 7) { + $this->setupTypeNumber($test); + } + + $dataArray = $this->qrDataList; + + $data = QRCode::createData($this->typeNumber, $this->errorCorrectLevel, $dataArray); + + $this->mapData($data, $maskPattern); + } + + function mapData(&$data, $maskPattern) { + + $inc = -1; + $row = $this->moduleCount - 1; + $bitIndex = 7; + $byteIndex = 0; + + for ($col = $this->moduleCount - 1; $col > 0; $col -= 2) { + + if ($col == 6) $col--; + + while (true) { + + for ($c = 0; $c < 2; $c++) { + + if ($this->modules[$row][$col - $c] === null) { + + $dark = false; + + if ($byteIndex < count($data) ) { + $dark = ( ( ($data[$byteIndex] >> $bitIndex) & 1) == 1); + } + + $mask = QRUtil::getMask($maskPattern, $row, $col - $c); + + if ($mask) { + $dark = !$dark; + } + + $this->modules[$row][$col - $c] = $dark; + $bitIndex--; + + if ($bitIndex == -1) { + $byteIndex++; + $bitIndex = 7; + } + } + } + + $row += $inc; + + if ($row < 0 || $this->moduleCount <= $row) { + $row -= $inc; + $inc = -$inc; + break; + } + } + } + } + + function setupPositionAdjustPattern() { + + $pos = QRUtil::getPatternPosition($this->typeNumber); + + for ($i = 0; $i < count($pos); $i++) { + + for ($j = 0; $j < count($pos); $j++) { + + $row = $pos[$i]; + $col = $pos[$j]; + + if ($this->modules[$row][$col] !== null) { + continue; + } + + for ($r = -2; $r <= 2; $r++) { + + for ($c = -2; $c <= 2; $c++) { + + if ($r == -2 || $r == 2 || $c == -2 || $c == 2 + || ($r == 0 && $c == 0) ) { + $this->modules[$row + $r][$col + $c] = true; + } else { + $this->modules[$row + $r][$col + $c] = false; + } + } + } + } + } + } + + function setupPositionProbePattern($row, $col) { + + for ($r = -1; $r <= 7; $r++) { + + for ($c = -1; $c <= 7; $c++) { + + if ($row + $r <= -1 || $this->moduleCount <= $row + $r + || $col + $c <= -1 || $this->moduleCount <= $col + $c) { + continue; + } + + if ( (0 <= $r && $r <= 6 && ($c == 0 || $c == 6) ) + || (0 <= $c && $c <= 6 && ($r == 0 || $r == 6) ) + || (2 <= $r && $r <= 4 && 2 <= $c && $c <= 4) ) { + $this->modules[$row + $r][$col + $c] = true; + } else { + $this->modules[$row + $r][$col + $c] = false; + } + } + } + } + + function setupTimingPattern() { + + for ($r = 8; $r < $this->moduleCount - 8; $r++) { + if ($this->modules[$r][6] !== null) { + continue; + } + $this->modules[$r][6] = ($r % 2 == 0); + } + + for ($c = 8; $c < $this->moduleCount - 8; $c++) { + if ($this->modules[6][$c] !== null) { + continue; + } + $this->modules[6][$c] = ($c % 2 == 0); + } + } + + function setupTypeNumber($test) { + + $bits = QRUtil::getBCHTypeNumber($this->typeNumber); + + for ($i = 0; $i < 18; $i++) { + $mod = (!$test && ( ($bits >> $i) & 1) == 1); + $this->modules[floor($i / 3)][$i % 3 + $this->moduleCount - 8 - 3] = $mod; + } + + for ($i = 0; $i < 18; $i++) { + $mod = (!$test && ( ($bits >> $i) & 1) == 1); + $this->modules[$i % 3 + $this->moduleCount - 8 - 3][floor($i / 3)] = $mod; + } + } + + function setupTypeInfo($test, $maskPattern) { + + $data = ($this->errorCorrectLevel << 3) | $maskPattern; + $bits = QRUtil::getBCHTypeInfo($data); + + for ($i = 0; $i < 15; $i++) { + + $mod = (!$test && ( ($bits >> $i) & 1) == 1); + + if ($i < 6) { + $this->modules[$i][8] = $mod; + } else if ($i < 8) { + $this->modules[$i + 1][8] = $mod; + } else { + $this->modules[$this->moduleCount - 15 + $i][8] = $mod; + } + } + + for ($i = 0; $i < 15; $i++) { + + $mod = (!$test && ( ($bits >> $i) & 1) == 1); + + if ($i < 8) { + $this->modules[8][$this->moduleCount - $i - 1] = $mod; + } else if ($i < 9) { + $this->modules[8][15 - $i - 1 + 1] = $mod; + } else { + $this->modules[8][15 - $i - 1] = $mod; + } + } + + $this->modules[$this->moduleCount - 8][8] = !$test; + } + + function createData($typeNumber, $errorCorrectLevel, $dataArray) { + + $rsBlocks = QRRSBlock::getRSBlocks($typeNumber, $errorCorrectLevel); + + $buffer = new QRBitBuffer(); + + for ($i = 0; $i < count($dataArray); $i++) { + $data = $dataArray[$i]; + $buffer->put($data->getMode(), 4); + $buffer->put($data->getLength(), $data->getLengthInBits($typeNumber) ); + $data->write($buffer); + } + + $totalDataCount = 0; + for ($i = 0; $i < count($rsBlocks); $i++) { + $totalDataCount += $rsBlocks[$i]->getDataCount(); + } + + if ($buffer->getLengthInBits() > $totalDataCount * 8) { + trigger_error("code length overflow. (" + . $buffer->getLengthInBits() + . ">" + . $totalDataCount * 8 + . ")", E_USER_ERROR); + } + + // end code. + if ($buffer->getLengthInBits() + 4 <= $totalDataCount * 8) { + $buffer->put(0, 4); + } + + // padding + while ($buffer->getLengthInBits() % 8 != 0) { + $buffer->putBit(false); + } + + // padding + while (true) { + + if ($buffer->getLengthInBits() >= $totalDataCount * 8) { + break; + } + $buffer->put(QR_PAD0, 8); + + if ($buffer->getLengthInBits() >= $totalDataCount * 8) { + break; + } + $buffer->put(QR_PAD1, 8); + } + + return QRCode::createBytes($buffer, $rsBlocks); + } + + function createBytes(&$buffer, &$rsBlocks) { + + $offset = 0; + + $maxDcCount = 0; + $maxEcCount = 0; + + $dcdata = QRCode::createNullArray(count($rsBlocks) ); + $ecdata = QRCode::createNullArray(count($rsBlocks) ); + + for ($r = 0; $r < count($rsBlocks); $r++) { + + $dcCount = $rsBlocks[$r]->getDataCount(); + $ecCount = $rsBlocks[$r]->getTotalCount() - $dcCount; + + $maxDcCount = max($maxDcCount, $dcCount); + $maxEcCount = max($maxEcCount, $ecCount); + + $dcdata[$r] = QRCode::createNullArray($dcCount); + for ($i = 0; $i < count($dcdata[$r]); $i++) { + $bdata = $buffer->getBuffer(); + $dcdata[$r][$i] = 0xff & $bdata[$i + $offset]; + } + $offset += $dcCount; + + $rsPoly = QRUtil::getErrorCorrectPolynomial($ecCount); + $rawPoly = new QRPolynomial($dcdata[$r], $rsPoly->getLength() - 1); + + $modPoly = $rawPoly->mod($rsPoly); + $ecdata[$r] = QRCode::createNullArray($rsPoly->getLength() - 1); + for ($i = 0; $i < count($ecdata[$r]); $i++) { + $modIndex = $i + $modPoly->getLength() - count($ecdata[$r]); + $ecdata[$r][$i] = ($modIndex >= 0)? $modPoly->get($modIndex) : 0; + } + } + + $totalCodeCount = 0; + for ($i = 0; $i < count($rsBlocks); $i++) { + $totalCodeCount += $rsBlocks[$i]->getTotalCount(); + } + + $data = QRCode::createNullArray($totalCodeCount); + + $index = 0; + + for ($i = 0; $i < $maxDcCount; $i++) { + for ($r = 0; $r < count($rsBlocks); $r++) { + if ($i < count($dcdata[$r]) ) { + $data[$index++] = $dcdata[$r][$i]; + } + } + } + + for ($i = 0; $i < $maxEcCount; $i++) { + for ($r = 0; $r < count($rsBlocks); $r++) { + if ($i < count($ecdata[$r]) ) { + $data[$index++] = $ecdata[$r][$i]; + } + } + } + + return $data; + } + + static function getMinimumQRCode($data, $errorCorrectLevel) { + + $mode = QRUtil::getMode($data); + + $qr = new QRCode(); + $qr->setErrorCorrectLevel($errorCorrectLevel); + $qr->addData($data, $mode); + + $qrData = $qr->getData(0); + $length = $qrData->getLength(); + + for ($typeNumber = 1; $typeNumber <= 10; $typeNumber++) { + if ($length <= QRUtil::getMaxLength($typeNumber, $mode, $errorCorrectLevel) ) { + $qr->setTypeNumber($typeNumber); + break; + } + } + + $qr->make(); + + return $qr; + } + + // added $fg (foreground), $bg (background), and $bgtrans (use transparent bg) parameters + // also added some simple error checking on parameters + // updated 2015.07.27 ~ DoktorJ + function createImage($size = 2, $margin = 2, $fg = 0x000000, $bg = 0xFFFFFF, $bgtrans = false) { + + // size/margin EC + if (!is_numeric($size)) $size = 2; + if (!is_numeric($margin)) $margin = 2; + if ($size < 1) $size = 1; + if ($margin < 0) $margin = 0; + + $image_size = $this->getModuleCount() * $size + $margin * 2; + + $image = imagecreatetruecolor($image_size, $image_size); + + // fg/bg EC + if ($fg < 0 || $fg > 0xFFFFFF) $fg = 0x0; + if ($bg < 0 || $bg > 0xFFFFFF) $bg = 0xFFFFFF; + + // convert hexadecimal RGB to arrays for imagecolorallocate + $fgrgb = $this->hex2rgb($fg); + $bgrgb = $this->hex2rgb($bg); + + // replace $black and $white with $fgc and $bgc + $fgc = imagecolorallocate($image, $fgrgb['r'], $fgrgb['g'], $fgrgb['b']); + $bgc = imagecolorallocate($image, $bgrgb['r'], $bgrgb['g'], $bgrgb['b']); + if ($bgtrans) imagecolortransparent($image, $bgc); + + // update $white to $bgc + imagefilledrectangle($image, 0, 0, $image_size, $image_size, $bgc); + + for ($r = 0; $r < $this->getModuleCount(); $r++) { + for ($c = 0; $c < $this->getModuleCount(); $c++) { + if ($this->isDark($r, $c) ) { + + // update $black to $fgc + imagefilledrectangle($image, + $margin + $c * $size, + $margin + $r * $size, + $margin + ($c + 1) * $size - 1, + $margin + ($r + 1) * $size - 1, + $fgc); + } + } + } + + return $image; + } + + function printHTML($size = "2px") { + + $style = "border-style:none;border-collapse:collapse;margin:0px;padding:0px;"; + + print(""); + + for ($r = 0; $r < $this->getModuleCount(); $r++) { + + print(""); + + for ($c = 0; $c < $this->getModuleCount(); $c++) { + $color = $this->isDark($r, $c)? "#000000" : "#ffffff"; + print(""); + } + + print(""); + } + + print("
    "); + } +} + +//--------------------------------------------------------------- +// QRUtil +//--------------------------------------------------------------- + +define("QR_G15", (1 << 10) | (1 << 8) | (1 << 5) + | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0) ); + +define("QR_G18", (1 << 12) | (1 << 11) | (1 << 10) + | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0) ); + +define("QR_G15_MASK", (1 << 14) | (1 << 12) | (1 << 10) + | (1 << 4) | (1 << 1) ); + +class QRUtil { + + static $QR_MAX_LENGTH = array( + array( array(41, 25, 17, 10), array(34, 20, 14, 8), array(27, 16, 11, 7), array(17, 10, 7, 4) ), + array( array(77, 47, 32, 20), array(63, 38, 26, 16), array(48, 29, 20, 12), array(34, 20, 14, 8) ), + array( array(127, 77, 53, 32), array(101, 61, 42, 26), array(77, 47, 32, 20), array(58, 35, 24, 15) ), + array( array(187, 114, 78, 48), array(149, 90, 62, 38), array(111, 67, 46, 28), array(82, 50, 34, 21) ), + array( array(255, 154, 106, 65), array(202, 122, 84, 52), array(144, 87, 60, 37), array(106, 64, 44, 27) ), + array( array(322, 195, 134, 82), array(255, 154, 106, 65), array(178, 108, 74, 45), array(139, 84, 58, 36) ), + array( array(370, 224, 154, 95), array(293, 178, 122, 75), array(207, 125, 86, 53), array(154, 93, 64, 39) ), + array( array(461, 279, 192, 118), array(365, 221, 152, 93), array(259, 157, 108, 66), array(202, 122, 84, 52) ), + array( array(552, 335, 230, 141), array(432, 262, 180, 111), array(312, 189, 130, 80), array(235, 143, 98, 60) ), + array( array(652, 395, 271, 167), array(513, 311, 213, 131), array(364, 221, 151, 93), array(288, 174, 119, 74) ) + ); + + static $QR_PATTERN_POSITION_TABLE = array( + array(), + array(6, 18), + array(6, 22), + array(6, 26), + array(6, 30), + array(6, 34), + array(6, 22, 38), + array(6, 24, 42), + array(6, 26, 46), + array(6, 28, 50), + array(6, 30, 54), + array(6, 32, 58), + array(6, 34, 62), + array(6, 26, 46, 66), + array(6, 26, 48, 70), + array(6, 26, 50, 74), + array(6, 30, 54, 78), + array(6, 30, 56, 82), + array(6, 30, 58, 86), + array(6, 34, 62, 90), + array(6, 28, 50, 72, 94), + array(6, 26, 50, 74, 98), + array(6, 30, 54, 78, 102), + array(6, 28, 54, 80, 106), + array(6, 32, 58, 84, 110), + array(6, 30, 58, 86, 114), + array(6, 34, 62, 90, 118), + array(6, 26, 50, 74, 98, 122), + array(6, 30, 54, 78, 102, 126), + array(6, 26, 52, 78, 104, 130), + array(6, 30, 56, 82, 108, 134), + array(6, 34, 60, 86, 112, 138), + array(6, 30, 58, 86, 114, 142), + array(6, 34, 62, 90, 118, 146), + array(6, 30, 54, 78, 102, 126, 150), + array(6, 24, 50, 76, 102, 128, 154), + array(6, 28, 54, 80, 106, 132, 158), + array(6, 32, 58, 84, 110, 136, 162), + array(6, 26, 54, 82, 110, 138, 166), + array(6, 30, 58, 86, 114, 142, 170) + ); + + static function getPatternPosition($typeNumber) { + return self::$QR_PATTERN_POSITION_TABLE[$typeNumber - 1]; + } + + static function getMaxLength($typeNumber, $mode, $errorCorrectLevel) { + + $t = $typeNumber - 1; + $e = 0; + $m = 0; + + switch($errorCorrectLevel) { + case QR_ERROR_CORRECT_LEVEL_L : $e = 0; break; + case QR_ERROR_CORRECT_LEVEL_M : $e = 1; break; + case QR_ERROR_CORRECT_LEVEL_Q : $e = 2; break; + case QR_ERROR_CORRECT_LEVEL_H : $e = 3; break; + default : + trigger_error("e:$errorCorrectLevel", E_USER_ERROR); + } + + switch($mode) { + case QR_MODE_NUMBER : $m = 0; break; + case QR_MODE_ALPHA_NUM : $m = 1; break; + case QR_MODE_8BIT_BYTE : $m = 2; break; + case QR_MODE_KANJI : $m = 3; break; + default : + trigger_error("m:$mode", E_USER_ERROR); + } + + return self::$QR_MAX_LENGTH[$t][$e][$m]; + } + + static function getErrorCorrectPolynomial($errorCorrectLength) { + + $a = new QRPolynomial(array(1) ); + + for ($i = 0; $i < $errorCorrectLength; $i++) { + $a = $a->multiply(new QRPolynomial(array(1, QRMath::gexp($i) ) ) ); + } + + return $a; + } + + static function getMask($maskPattern, $i, $j) { + + switch ($maskPattern) { + + case QR_MASK_PATTERN000 : return ($i + $j) % 2 == 0; + case QR_MASK_PATTERN001 : return $i % 2 == 0; + case QR_MASK_PATTERN010 : return $j % 3 == 0; + case QR_MASK_PATTERN011 : return ($i + $j) % 3 == 0; + case QR_MASK_PATTERN100 : return (floor($i / 2) + floor($j / 3) ) % 2 == 0; + case QR_MASK_PATTERN101 : return ($i * $j) % 2 + ($i * $j) % 3 == 0; + case QR_MASK_PATTERN110 : return ( ($i * $j) % 2 + ($i * $j) % 3) % 2 == 0; + case QR_MASK_PATTERN111 : return ( ($i * $j) % 3 + ($i + $j) % 2) % 2 == 0; + + default : + trigger_error("mask:$maskPattern", E_USER_ERROR); + } + } + + static function getLostPoint($qrCode) { + + $moduleCount = $qrCode->getModuleCount(); + + $lostPoint = 0; + + + // LEVEL1 + + for ($row = 0; $row < $moduleCount; $row++) { + + for ($col = 0; $col < $moduleCount; $col++) { + + $sameCount = 0; + $dark = $qrCode->isDark($row, $col); + + for ($r = -1; $r <= 1; $r++) { + + if ($row + $r < 0 || $moduleCount <= $row + $r) { + continue; + } + + for ($c = -1; $c <= 1; $c++) { + + if ($col + $c < 0 || $moduleCount <= $col + $c) { + continue; + } + + if ($r == 0 && $c == 0) { + continue; + } + + if ($dark == $qrCode->isDark($row + $r, $col + $c) ) { + $sameCount++; + } + } + } + + if ($sameCount > 5) { + $lostPoint += (3 + $sameCount - 5); + } + } + } + + // LEVEL2 + + for ($row = 0; $row < $moduleCount - 1; $row++) { + for ($col = 0; $col < $moduleCount - 1; $col++) { + $count = 0; + if ($qrCode->isDark($row, $col ) ) $count++; + if ($qrCode->isDark($row + 1, $col ) ) $count++; + if ($qrCode->isDark($row, $col + 1) ) $count++; + if ($qrCode->isDark($row + 1, $col + 1) ) $count++; + if ($count == 0 || $count == 4) { + $lostPoint += 3; + } + } + } + + // LEVEL3 + + for ($row = 0; $row < $moduleCount; $row++) { + for ($col = 0; $col < $moduleCount - 6; $col++) { + if ($qrCode->isDark($row, $col) + && !$qrCode->isDark($row, $col + 1) + && $qrCode->isDark($row, $col + 2) + && $qrCode->isDark($row, $col + 3) + && $qrCode->isDark($row, $col + 4) + && !$qrCode->isDark($row, $col + 5) + && $qrCode->isDark($row, $col + 6) ) { + $lostPoint += 40; + } + } + } + + for ($col = 0; $col < $moduleCount; $col++) { + for ($row = 0; $row < $moduleCount - 6; $row++) { + if ($qrCode->isDark($row, $col) + && !$qrCode->isDark($row + 1, $col) + && $qrCode->isDark($row + 2, $col) + && $qrCode->isDark($row + 3, $col) + && $qrCode->isDark($row + 4, $col) + && !$qrCode->isDark($row + 5, $col) + && $qrCode->isDark($row + 6, $col) ) { + $lostPoint += 40; + } + } + } + + // LEVEL4 + + $darkCount = 0; + + for ($col = 0; $col < $moduleCount; $col++) { + for ($row = 0; $row < $moduleCount; $row++) { + if ($qrCode->isDark($row, $col) ) { + $darkCount++; + } + } + } + + $ratio = abs(100 * $darkCount / $moduleCount / $moduleCount - 50) / 5; + $lostPoint += $ratio * 10; + + return $lostPoint; + } + + static function getMode($s) { + if (QRUtil::isAlphaNum($s) ) { + if (QRUtil::isNumber($s) ) { + return QR_MODE_NUMBER; + } + return QR_MODE_ALPHA_NUM; + } else if (QRUtil::isKanji($s) ) { + return QR_MODE_KANJI; + } else { + return QR_MODE_8BIT_BYTE; + } + } + + static function isNumber($s) { + for ($i = 0; $i < strlen($s); $i++) { + $c = ord($s[$i]); + if (!(QRUtil::toCharCode('0') <= $c && $c <= QRUtil::toCharCode('9') ) ) { + return false; + } + } + return true; + } + + static function isAlphaNum($s) { + for ($i = 0; $i < strlen($s); $i++) { + $c = ord($s[$i]); + if (!(QRUtil::toCharCode('0') <= $c && $c <= QRUtil::toCharCode('9') ) + && !(QRUtil::toCharCode('A') <= $c && $c <= QRUtil::toCharCode('Z') ) + && strpos(" $%*+-./:", $s[$i]) === false) { + return false; + } + } + return true; + } + + static function isKanji($s) { + + $data = $s; + + $i = 0; + + while ($i + 1 < strlen($data) ) { + + $c = ( (0xff & ord($data[$i]) ) << 8) | (0xff & ord($data[$i + 1]) ); + + if (!(0x8140 <= $c && $c <= 0x9FFC) && !(0xE040 <= $c && $c <= 0xEBBF) ) { + return false; + } + + $i += 2; + } + + if ($i < strlen($data) ) { + return false; + } + + return true; + } + + static function toCharCode($s) { + return ord($s[0]); + } + + static function getBCHTypeInfo($data) { + $d = $data << 10; + while (QRUtil::getBCHDigit($d) - QRUtil::getBCHDigit(QR_G15) >= 0) { + $d ^= (QR_G15 << (QRUtil::getBCHDigit($d) - QRUtil::getBCHDigit(QR_G15) ) ); + } + return ( ($data << 10) | $d) ^ QR_G15_MASK; + } + + static function getBCHTypeNumber($data) { + $d = $data << 12; + while (QRUtil::getBCHDigit($d) - QRUtil::getBCHDigit(QR_G18) >= 0) { + $d ^= (QR_G18 << (QRUtil::getBCHDigit($d) - QRUtil::getBCHDigit(QR_G18) ) ); + } + return ($data << 12) | $d; + } + + static function getBCHDigit($data) { + + $digit = 0; + + while ($data != 0) { + $digit++; + $data >>= 1; + } + + return $digit; + } +} + +//--------------------------------------------------------------- +// QRRSBlock +//--------------------------------------------------------------- + +class QRRSBlock { + + var $totalCount; + var $dataCount; + + static $QR_RS_BLOCK_TABLE = array( + + // L + // M + // Q + // H + + // 1 + array(1, 26, 19), + array(1, 26, 16), + array(1, 26, 13), + array(1, 26, 9), + + // 2 + array(1, 44, 34), + array(1, 44, 28), + array(1, 44, 22), + array(1, 44, 16), + + // 3 + array(1, 70, 55), + array(1, 70, 44), + array(2, 35, 17), + array(2, 35, 13), + + // 4 + array(1, 100, 80), + array(2, 50, 32), + array(2, 50, 24), + array(4, 25, 9), + + // 5 + array(1, 134, 108), + array(2, 67, 43), + array(2, 33, 15, 2, 34, 16), + array(2, 33, 11, 2, 34, 12), + + // 6 + array(2, 86, 68), + array(4, 43, 27), + array(4, 43, 19), + array(4, 43, 15), + + // 7 + array(2, 98, 78), + array(4, 49, 31), + array(2, 32, 14, 4, 33, 15), + array(4, 39, 13, 1, 40, 14), + + // 8 + array(2, 121, 97), + array(2, 60, 38, 2, 61, 39), + array(4, 40, 18, 2, 41, 19), + array(4, 40, 14, 2, 41, 15), + + // 9 + array(2, 146, 116), + array(3, 58, 36, 2, 59, 37), + array(4, 36, 16, 4, 37, 17), + array(4, 36, 12, 4, 37, 13), + + // 10 + array(2, 86, 68, 2, 87, 69), + array(4, 69, 43, 1, 70, 44), + array(6, 43, 19, 2, 44, 20), + array(6, 43, 15, 2, 44, 16) + + ); + + function QRRSBlock($totalCount, $dataCount) { + $this->totalCount = $totalCount; + $this->dataCount = $dataCount; + } + + function getDataCount() { + return $this->dataCount; + } + + function getTotalCount() { + return $this->totalCount; + } + + static function getRSBlocks($typeNumber, $errorCorrectLevel) { + + $rsBlock = QRRSBlock::getRsBlockTable($typeNumber, $errorCorrectLevel); + $length = count($rsBlock) / 3; + + $list = array(); + + for ($i = 0; $i < $length; $i++) { + + $count = $rsBlock[$i * 3 + 0]; + $totalCount = $rsBlock[$i * 3 + 1]; + $dataCount = $rsBlock[$i * 3 + 2]; + + for ($j = 0; $j < $count; $j++) { + $list[] = new QRRSBlock($totalCount, $dataCount); + } + } + + return $list; + } + + static function getRsBlockTable($typeNumber, $errorCorrectLevel) { + + switch($errorCorrectLevel) { + case QR_ERROR_CORRECT_LEVEL_L : + return self::$QR_RS_BLOCK_TABLE[($typeNumber - 1) * 4 + 0]; + case QR_ERROR_CORRECT_LEVEL_M : + return self::$QR_RS_BLOCK_TABLE[($typeNumber - 1) * 4 + 1]; + case QR_ERROR_CORRECT_LEVEL_Q : + return self::$QR_RS_BLOCK_TABLE[($typeNumber - 1) * 4 + 2]; + case QR_ERROR_CORRECT_LEVEL_H : + return self::$QR_RS_BLOCK_TABLE[($typeNumber - 1) * 4 + 3]; + default : + trigger_error("tn:$typeNumber/ecl:$errorCorrectLevel", E_USER_ERROR); + } + } +} + +//--------------------------------------------------------------- +// QRNumber +//--------------------------------------------------------------- + +class QRNumber extends QRData { + + function QRNumber($data) { + QRData::QRData(QR_MODE_NUMBER, $data); + } + + function write(&$buffer) { + + $data = $this->getData(); + + $i = 0; + + while ($i + 2 < strlen($data) ) { + $num = QRNumber::parseInt(substr($data, $i, 3) ); + $buffer->put($num, 10); + $i += 3; + } + + if ($i < strlen($data) ) { + + if (strlen($data) - $i == 1) { + $num = QRNumber::parseInt(substr($data, $i, $i + 1) ); + $buffer->put($num, 4); + } else if (strlen($data) - $i == 2) { + $num = QRNumber::parseInt(substr($data, $i, $i + 2) ); + $buffer->put($num, 7); + } + } + } + + function getLength() { + return strlen($this->getData() ); + } + + static function parseInt($s) { + + $num = 0; + for ($i = 0; $i < strlen($s); $i++) { + $num = $num * 10 + QRNumber::parseIntAt(ord($s[$i]) ); + } + return $num; + } + + static function parseIntAt($c) { + + if (QRUtil::toCharCode('0') <= $c && $c <= QRUtil::toCharCode('9') ) { + return $c - QRUtil::toCharCode('0'); + } + + trigger_error("illegal char : $c", E_USER_ERROR); + } +} + +//--------------------------------------------------------------- +// QRKanji +//--------------------------------------------------------------- + +class QRKanji extends QRData { + + function QRKanji($data) { + QRData::QRData(QR_MODE_KANJI, $data); + } + + function write(&$buffer) { + + $data = $this->getData(); + + $i = 0; + + while ($i + 1 < strlen($data) ) { + + $c = ( (0xff & ord($data[$i]) ) << 8) | (0xff & ord($data[$i + 1]) ); + + if (0x8140 <= $c && $c <= 0x9FFC) { + $c -= 0x8140; + } else if (0xE040 <= $c && $c <= 0xEBBF) { + $c -= 0xC140; + } else { + trigger_error("illegal char at " . ($i + 1) . "/$c", E_USER_ERROR); + } + + $c = ( ($c >> 8) & 0xff) * 0xC0 + ($c & 0xff); + + $buffer->put($c, 13); + + $i += 2; + } + + if ($i < strlen($data) ) { + trigger_error("illegal char at " . ($i + 1), E_USER_ERROR); + } + } + + function getLength() { + return floor(strlen($this->getData() ) / 2); + } +} + +//--------------------------------------------------------------- +// QRAlphaNum +//--------------------------------------------------------------- + +class QRAlphaNum extends QRData { + + function QRAlphaNum($data) { + QRData::QRData(QR_MODE_ALPHA_NUM, $data); + } + + function write(&$buffer) { + + $i = 0; + $c = $this->getData(); + + while ($i + 1 < strlen($c) ) { + $buffer->put(QRAlphaNum::getCode(ord($c[$i]) ) * 45 + + QRAlphaNum::getCode(ord($c[$i + 1]) ), 11); + $i += 2; + } + + if ($i < strlen($c) ) { + $buffer->put(QRAlphaNum::getCode(ord($c[$i])), 6); + } + } + + function getLength() { + return strlen($this->getData() ); + } + + static function getCode($c) { + + if (QRUtil::toCharCode('0') <= $c + && $c <= QRUtil::toCharCode('9') ) { + return $c - QRUtil::toCharCode('0'); + } else if (QRUtil::toCharCode('A') <= $c + && $c <= QRUtil::toCharCode('Z') ) { + return $c - QRUtil::toCharCode('A') + 10; + } else { + switch ($c) { + case QRUtil::toCharCode(' ') : return 36; + case QRUtil::toCharCode('$') : return 37; + case QRUtil::toCharCode('%') : return 38; + case QRUtil::toCharCode('*') : return 39; + case QRUtil::toCharCode('+') : return 40; + case QRUtil::toCharCode('-') : return 41; + case QRUtil::toCharCode('.') : return 42; + case QRUtil::toCharCode('/') : return 43; + case QRUtil::toCharCode(':') : return 44; + default : + trigger_error("illegal char : $c", E_USER_ERROR); + } + } + + } +} + +//--------------------------------------------------------------- +// QR8BitByte +//--------------------------------------------------------------- + +class QR8BitByte extends QRData { + + function QR8BitByte($data) { + QRData::QRData(QR_MODE_8BIT_BYTE, $data); + } + + function write(&$buffer) { + + $data = $this->getData(); + for ($i = 0; $i < strlen($data); $i++) { + $buffer->put(ord($data[$i]), 8); + } + } + + function getLength() { + return strlen($this->getData() ); + } +} + +//--------------------------------------------------------------- +// QRData +//--------------------------------------------------------------- + +class QRData { + + var $mode; + + var $data; + + function QRData($mode, $data) { + $this->mode = $mode; + $this->data = $data; + } + + function getMode() { + return $this->mode; + } + + function getData() { + return $this->data; + } + + function getLength() { + trigger_error("not implemented.", E_USER_ERROR); + } + + function write(&$buffer) { + trigger_error("not implemented.", E_USER_ERROR); + } + + function getLengthInBits($type) { + + if (1 <= $type && $type < 10) { + + // 1 - 9 + + switch($this->mode) { + case QR_MODE_NUMBER : return 10; + case QR_MODE_ALPHA_NUM : return 9; + case QR_MODE_8BIT_BYTE : return 8; + case QR_MODE_KANJI : return 8; + default : + trigger_error("mode:$this->mode", E_USER_ERROR); + } + + } else if ($type < 27) { + + // 10 - 26 + + switch($this->mode) { + case QR_MODE_NUMBER : return 12; + case QR_MODE_ALPHA_NUM : return 11; + case QR_MODE_8BIT_BYTE : return 16; + case QR_MODE_KANJI : return 10; + default : + trigger_error("mode:$this->mode", E_USER_ERROR); + } + + } else if ($type < 41) { + + // 27 - 40 + + switch($this->mode) { + case QR_MODE_NUMBER : return 14; + case QR_MODE_ALPHA_NUM : return 13; + case QR_MODE_8BIT_BYTE : return 16; + case QR_MODE_KANJI : return 12; + default : + trigger_error("mode:$this->mode", E_USER_ERROR); + } + + } else { + trigger_error("mode:$this->mode", E_USER_ERROR); + } + } + +} + +//--------------------------------------------------------------- +// QRMath +//--------------------------------------------------------------- + +class QRMath { + + static $QR_MATH_EXP_TABLE = null; + static $QR_MATH_LOG_TABLE = null; + + static function init() { + + self::$QR_MATH_EXP_TABLE = QRMath::createNumArray(256); + + for ($i = 0; $i < 8; $i++) { + self::$QR_MATH_EXP_TABLE[$i] = 1 << $i; + } + + for ($i = 8; $i < 256; $i++) { + self::$QR_MATH_EXP_TABLE[$i] = self::$QR_MATH_EXP_TABLE[$i - 4] + ^ self::$QR_MATH_EXP_TABLE[$i - 5] + ^ self::$QR_MATH_EXP_TABLE[$i - 6] + ^ self::$QR_MATH_EXP_TABLE[$i - 8]; + } + + self::$QR_MATH_LOG_TABLE = QRMath::createNumArray(256); + + for ($i = 0; $i < 255; $i++) { + self::$QR_MATH_LOG_TABLE[self::$QR_MATH_EXP_TABLE[$i] ] = $i; + } + } + + static function createNumArray($length) { + $num_array = array(); + for ($i = 0; $i < $length; $i++) { + $num_array[] = 0; + } + return $num_array; + } + + static function glog($n) { + + if ($n < 1) { + trigger_error("log($n)", E_USER_ERROR); + } + + return self::$QR_MATH_LOG_TABLE[$n]; + } + + static function gexp($n) { + + while ($n < 0) { + $n += 255; + } + + while ($n >= 256) { + $n -= 255; + } + + return self::$QR_MATH_EXP_TABLE[$n]; + } +} + +// init static table +QRMath::init(); + +//--------------------------------------------------------------- +// QRPolynomial +//--------------------------------------------------------------- + +class QRPolynomial { + + var $num; + + function QRPolynomial($num, $shift = 0) { + + $offset = 0; + + while ($offset < count($num) && $num[$offset] == 0) { + $offset++; + } + + $this->num = QRMath::createNumArray(count($num) - $offset + $shift); + for ($i = 0; $i < count($num) - $offset; $i++) { + $this->num[$i] = $num[$i + $offset]; + } + } + + function get($index) { + return $this->num[$index]; + } + + function getLength() { + return count($this->num); + } + + // PHP5 + function __toString() { + return $this->toString(); + } + + function toString() { + + $buffer = ""; + + for ($i = 0; $i < $this->getLength(); $i++) { + if ($i > 0) { + $buffer .= ","; + } + $buffer .= $this->get($i); + } + + return $buffer; + } + + function toLogString() { + + $buffer = ""; + + for ($i = 0; $i < $this->getLength(); $i++) { + if ($i > 0) { + $buffer .= ","; + } + $buffer .= QRMath::glog($this->get(i) ); + } + + return $buffer; + } + + function multiply($e) { + + $num = QRMath::createNumArray($this->getLength() + $e->getLength() - 1); + + for ($i = 0; $i < $this->getLength(); $i++) { + for ($j = 0; $j < $e->getLength(); $j++) { + $num[$i + $j] ^= QRMath::gexp(QRMath::glog($this->get($i) ) + QRMath::glog($e->get($j) ) ); + } + } + + return new QRPolynomial($num); + } + + function mod($e) { + + if ($this->getLength() - $e->getLength() < 0) { + return $this; + } + + $ratio = QRMath::glog($this->get(0) ) - QRMath::glog($e->get(0) ); + + $num = QRMath::createNumArray($this->getLength() ); + for ($i = 0; $i < $this->getLength(); $i++) { + $num[$i] = $this->get($i); + } + + for ($i = 0; $i < $e->getLength(); $i++) { + $num[$i] ^= QRMath::gexp(QRMath::glog($e->get($i) ) + $ratio); + } + + $newPolynomial = new QRPolynomial($num); + return $newPolynomial->mod($e); + } +} + +//--------------------------------------------------------------- +// Mode +//--------------------------------------------------------------- + +define("QR_MODE_NUMBER", 1 << 0); +define("QR_MODE_ALPHA_NUM", 1 << 1); +define("QR_MODE_8BIT_BYTE", 1 << 2); +define("QR_MODE_KANJI", 1 << 3); + +//--------------------------------------------------------------- +// MaskPattern +//--------------------------------------------------------------- + +define("QR_MASK_PATTERN000", 0); +define("QR_MASK_PATTERN001", 1); +define("QR_MASK_PATTERN010", 2); +define("QR_MASK_PATTERN011", 3); +define("QR_MASK_PATTERN100", 4); +define("QR_MASK_PATTERN101", 5); +define("QR_MASK_PATTERN110", 6); +define("QR_MASK_PATTERN111", 7); + +//--------------------------------------------------------------- +// ErrorCorrectLevel + +// 7%. +define("QR_ERROR_CORRECT_LEVEL_L", 1); +// 15%. +define("QR_ERROR_CORRECT_LEVEL_M", 0); +// 25%. +define("QR_ERROR_CORRECT_LEVEL_Q", 3); +// 30%. +define("QR_ERROR_CORRECT_LEVEL_H", 2); + + +//--------------------------------------------------------------- +// QRBitBuffer +//--------------------------------------------------------------- + +class QRBitBuffer { + + var $buffer; + var $length; + + function QRBitBuffer() { + $this->buffer = array(); + $this->length = 0; + } + + function getBuffer() { + return $this->buffer; + } + + function getLengthInBits() { + return $this->length; + } + + function __toString() { + $buffer = ""; + for ($i = 0; $i < $this->getLengthInBits(); $i++) { + $buffer .= $this->get($i)? '1' : '0'; + } + return $buffer; + } + + function get($index) { + $bufIndex = floor($index / 8); + return ( ($this->buffer[$bufIndex] >> (7 - $index % 8) ) & 1) == 1; + } + + function put($num, $length) { + + for ($i = 0; $i < $length; $i++) { + $this->putBit( ( ($num >> ($length - $i - 1) ) & 1) == 1); + } + } + + function putBit($bit) { + + $bufIndex = floor($this->length / 8); + if (count($this->buffer) <= $bufIndex) { + $this->buffer[] = 0; + } + + if ($bit) { + $this->buffer[$bufIndex] |= (0x80 >> ($this->length % 8) ); + } + + $this->length++; + } +} + +?> diff --git a/settings.php b/settings.php index fa3f4dad4e..469be26e75 100644 --- a/settings.php +++ b/settings.php @@ -1,3 +1,9 @@ +
    From
    - disabled> + disabled>
    @@ -206,7 +212,7 @@
    To
    - disabled> + disabled>
    @@ -215,7 +221,7 @@
    Router
    - disabled> + disabled>
    @@ -257,8 +263,10 @@ // Read leases file $leasesfile = true; - $dhcpleases = fopen('/etc/pihole/dhcp.leases', 'r') or $leasesfile = false; - $dhcp_leases = []; + $dhcpleases = @fopen('/etc/pihole/dhcp.leases', 'r'); + if(!is_resource($dhcpleases )) + $leasesfile = false; + $dhcp_leases = array(); function convertseconds($argument) { $seconds = round($argument); @@ -322,29 +330,55 @@ function convertseconds($argument) { $clid = "unknown"; } - array_push($dhcp_leases,["TIME"=>$time, "hwaddr"=>$line[1], "IP"=>$line[2], "host"=>$host, "clid"=>$clid, "type"=>$type]); + array_push($dhcp_leases,["TIME"=>$time, "hwaddr"=>strtoupper($line[1]), "IP"=>$line[2], "host"=>$host, "clid"=>$clid, "type"=>$type]); } } + + readStaticLeasesFile(); + ?>
    -
    +
    collapsed-box">

    DHCP leases

    + + + -
    Remaining lease time:
    DHCP UID: "> +
    Remaining lease time:
    DHCP UID: "> +
    MAC address IP address Hostname

    +
    +
    + + + + + + + + + + + + + + + +
    MAC addressIP addressHostname
    0){ ?>
    +

    Specifying the MAC address is mandatory and only one entry per MAC address is allowed. If the IP address is omitted and a host name is given, the IP address will still be generated dynamically and the specified host name will be used. If the host name is omitted, only a static release will be added.

    @@ -435,6 +469,23 @@ function convertseconds($argument) { } else { $DNSSEC = false; } + + if(isset($setupVars["DNSMASQ_LISTENING"])){ + if($setupVars["DNSMASQ_LISTENING"] === "single") + { + $DNSinterface = "single"; + } + elseif($setupVars["DNSMASQ_LISTENING"] === "all") + { + $DNSinterface = "all"; + } + else + { + $DNSinterface = "local"; + } + } else { + $DNSinterface = "local"; + } ?>
    @@ -459,25 +510,25 @@ function convertseconds($argument) {
    checked>
    - value=""> + value="">
    checked>
    - value=""> + value="">
    checked>
    - value=""> + value="">
    checked>
    - value=""> + value="">
    @@ -500,6 +551,20 @@ function convertseconds($argument) {

    Validate DNS replies and cache DNSSEC data. When forwarding DNS queries, Pi-hole requests the DNSSEC records needed to validate the replies. Use Google or Norton DNS servers when activating DNSSEC. Note that the size of your log might increase significantly when enabling DNSSEC. A DNSSEC resolver test can be found here.

    + +
    + +
    + +
    +
    + +
    +
    + +
    +
    +
    @@ -662,6 +727,7 @@ function convertseconds($argument) { @@ -801,6 +867,6 @@ function convertseconds($argument) { ?> - + diff --git a/style/pi-hole.css b/style/pi-hole.css index 9e084a642b..80ebba72f0 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -1,3 +1,9 @@ +/* Pi-hole: A black hole for Internet advertisements +* (c) 2017 Pi-hole, LLC (https://pi-hole.net) +* Network-wide ad blocking via your own hardware. +* +* This file is copyright under the latest version of the EUPL. +* Please see LICENSE file for your rights under this license. */ .small-box { -webkit-user-select: none; /* Chrome/Safari */ -moz-user-select: none; /* Firefox */ @@ -7,3 +13,6 @@ -o-user-select: none; user-select: none; } +.skin-blue .list-group-item:hover { + background: #ddd; +} diff --git a/style/vendor/LICENSE b/style/vendor/LICENSE new file mode 100644 index 0000000000..e1854e8679 --- /dev/null +++ b/style/vendor/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014-2015 almasaeed2010 + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/taillog.php b/taillog.php index 4ba15e1ef5..c2b1e5a977 100644 --- a/taillog.php +++ b/taillog.php @@ -1,3 +1,9 @@ +