From patchwork Thu Jan 28 10:03:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthias Fischer X-Patchwork-Id: 3823 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4DRGK56VhSz3wxm for ; Thu, 28 Jan 2021 10:04:09 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4DRGK42Tl1z1g2; Thu, 28 Jan 2021 10:04:08 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4DRGK41Sjwz2xmx; Thu, 28 Jan 2021 10:04:08 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4DRGK2062Tz2xh3 for ; Thu, 28 Jan 2021 10:04:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4DRGK000bvzsj; Thu, 28 Jan 2021 10:04:03 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1611828244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=naZV0rXker6+qEnLxPNpp1naiAWkbAu0hbDl6OA62Dw=; b=n1EgN5MFtpgTRqZzTnyO/IHMluxd0X1SZhPG2X2KE2HopNcdoH6VOAfI/1Jc+MjjS7GS9i zMvprbE/5FH3ZXBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1611828244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=naZV0rXker6+qEnLxPNpp1naiAWkbAu0hbDl6OA62Dw=; b=NWp4VLljsGkMe4oz9zk1Hzq6eKwqezZbsCEkg+MsGyRg5J8nfgTXoipwGo9+V2Jc9jWSxS gibjvRBaCY8B5dw8kD9X7Dy70MRNIbdBpHoguTsXNoUMz5vt72MKnBKAbHMuUThZYXiw/N 4ZirdBblZwFmlrYOs/7K5JYv/kOQEInWzmheQ6Fq6hKovYKJ7Wwb/GdJu0u5a0sj5iSNT6 ah/nrfsYP89I49uxuF7zFraGL3tsXckv9awuqFRXbrTqTO6KT1RUS4ZU93TighGp37AURx 0KyQe8JfkAYt8kAuMRu7lLd7YPXyTAzr1ILe/rd/65xXKqq24LWQbkznD3HNAg== From: Matthias Fischer To: development@lists.ipfire.org Subject: [PATCH] IPTraffic 0.8.2 - v2 Date: Thu, 28 Jan 2021 11:03:59 +0100 Message-Id: <20210128100359.12374-1-matthias.fischer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Frank Mainz Errors-To: development-bounces@lists.ipfire.org Sender: "Development" From: Frank Mainz This is actually just a different way to publish the already published 'IPTraffic'-addon. The code is identical, I just deleted a few trailing spaces and some unnecessary tabs. For discussion and reasons see: => https://lists.ipfire.org/pipermail/development/2021-January/009153.html ff. I now rewrote the build process so I could drop the former used tarball. The code is now more transparent - I'm hoping that "someone" is willing/able to start reworking or integrate it as an addon or as part of the core system. Signed-off-by: Matthias Fischer --- config/iptraffic/COPYING | 340 ++++++++++ config/iptraffic/EX-iptraffic.menu | 6 + config/iptraffic/addon-lang/iptraffic.de.pl | 19 + config/iptraffic/addon-lang/iptraffic.en.pl | 19 + config/iptraffic/changelog | 48 ++ config/iptraffic/images/addblue.gif | Bin 0 -> 154 bytes config/iptraffic/images/addfaint.gif | Bin 0 -> 126 bytes config/iptraffic/images/addgray.gif | Bin 0 -> 153 bytes config/iptraffic/images/addgreen.gif | Bin 0 -> 154 bytes config/iptraffic/images/addorange.gif | Bin 0 -> 153 bytes config/iptraffic/images/addred.gif | Bin 0 -> 154 bytes config/iptraffic/images/blue.png | Bin 0 -> 219 bytes config/iptraffic/images/graph.png | Bin 0 -> 260 bytes config/iptraffic/images/gray.png | Bin 0 -> 219 bytes config/iptraffic/images/green.png | Bin 0 -> 217 bytes config/iptraffic/images/orange.png | Bin 0 -> 223 bytes config/iptraffic/images/red.png | Bin 0 -> 216 bytes config/iptraffic/images/square-green.png | Bin 0 -> 163 bytes config/iptraffic/images/square-red.png | Bin 0 -> 157 bytes config/iptraffic/images/square-yellow.png | Bin 0 -> 157 bytes config/iptraffic/iptraffic.cgi | 678 ++++++++++++++++++++ config/iptraffic/iptraffic.pl | 354 ++++++++++ config/rootfiles/packages/iptraffic | 22 + lfs/iptraffic | 86 +++ make.sh | 1 + src/paks/iptraffic/install.sh | 40 ++ src/paks/iptraffic/uninstall.sh | 28 + src/paks/iptraffic/update.sh | 26 + 28 files changed, 1667 insertions(+) create mode 100644 config/iptraffic/COPYING create mode 100644 config/iptraffic/EX-iptraffic.menu create mode 100644 config/iptraffic/addon-lang/iptraffic.de.pl create mode 100644 config/iptraffic/addon-lang/iptraffic.en.pl create mode 100644 config/iptraffic/changelog create mode 100644 config/iptraffic/images/addblue.gif create mode 100644 config/iptraffic/images/addfaint.gif create mode 100644 config/iptraffic/images/addgray.gif create mode 100644 config/iptraffic/images/addgreen.gif create mode 100644 config/iptraffic/images/addorange.gif create mode 100644 config/iptraffic/images/addred.gif create mode 100644 config/iptraffic/images/blue.png create mode 100644 config/iptraffic/images/graph.png create mode 100644 config/iptraffic/images/gray.png create mode 100644 config/iptraffic/images/green.png create mode 100644 config/iptraffic/images/orange.png create mode 100644 config/iptraffic/images/red.png create mode 100644 config/iptraffic/images/square-green.png create mode 100644 config/iptraffic/images/square-red.png create mode 100644 config/iptraffic/images/square-yellow.png create mode 100644 config/iptraffic/iptraffic.cgi create mode 100644 config/iptraffic/iptraffic.pl create mode 100644 config/rootfiles/packages/iptraffic create mode 100644 lfs/iptraffic create mode 100644 src/paks/iptraffic/install.sh create mode 100644 src/paks/iptraffic/uninstall.sh create mode 100644 src/paks/iptraffic/update.sh diff --git a/config/iptraffic/COPYING b/config/iptraffic/COPYING new file mode 100644 index 000000000..d60c31a97 --- /dev/null +++ b/config/iptraffic/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/config/iptraffic/EX-iptraffic.menu b/config/iptraffic/EX-iptraffic.menu new file mode 100644 index 000000000..032d3eba6 --- /dev/null +++ b/config/iptraffic/EX-iptraffic.menu @@ -0,0 +1,6 @@ + $substatus->{'70.iptraffic'} = { + 'caption' => $Lang::tr{'IPTraffic_title'}, + 'uri' => '/cgi-bin/iptraffic.cgi', + 'title' => $Lang::tr{'IPTraffic_title'}, + 'enabled' => 1, + }; diff --git a/config/iptraffic/addon-lang/iptraffic.de.pl b/config/iptraffic/addon-lang/iptraffic.de.pl new file mode 100644 index 000000000..e46e9c50a --- /dev/null +++ b/config/iptraffic/addon-lang/iptraffic.de.pl @@ -0,0 +1,19 @@ +%tr = (%tr, +'IPTraffic_title' => 'IPTraffic', +'IPTraffic_add' => 'Client hinzufügen', +'IPTraffic_no_add' => 'Client ist vorhanden', +'IPTraffic_clientlist' => 'IPTraffic Clientliste', +'IPTraffic_send' => 'Gesendet', +'IPTraffic_load' => 'Empfangen', +'IPTraffic_month' => 'Monat', +'IPTraffic_week' => 'Woche', +'IPTraffic_today' => 'Heute', +'IPTraffic_sum' => 'Gesamt', +'IPTraffic_graphs' => 'Graphen anzeigen', +'IPTraffic_graphs_stat' => 'Clientdiagramme', +'IPTraffic_arp_table_entries' => 'Client aus der ARP-Tabelle hinzufügen:', +'IPTraffic_view_table' => 'Tabelle einblenden', +'IPTraffic_hide_table' => 'Tabelle ausblenden', +'IPTraffic_not_found' => 'nicht gefunden', +'IPTraffic_delete_item' => 'Möchten sie diesen Eintrag wirklich löschen?', +); diff --git a/config/iptraffic/addon-lang/iptraffic.en.pl b/config/iptraffic/addon-lang/iptraffic.en.pl new file mode 100644 index 000000000..b77bd2af6 --- /dev/null +++ b/config/iptraffic/addon-lang/iptraffic.en.pl @@ -0,0 +1,19 @@ +%tr = (%tr, +'IPTraffic_title' => 'IPTraffic', +'IPTraffic_add' => 'Add Client', +'IPTraffic_no_add' => 'Client is available', +'IPTraffic_clientlist' => 'IPTraffic list of clients', +'IPTraffic_send' => 'Received', +'IPTraffic_load' => 'Transmitted', +'IPTraffic_month' => 'Month', +'IPTraffic_week' => 'Week', +'IPTraffic_today' => 'Today', +'IPTraffic_sum' => 'Total', +'IPTraffic_graphs' => 'View Graph', +'IPTraffic_graphs_stat' => 'Client-Diagrams', +'IPTraffic_arp_table_entries' => 'Add client from ARP-Table:', +'IPTraffic_view_table' => 'Show table', +'IPTraffic_hide_table' => 'Hide table', +'IPTraffic_not_found' => 'not found', +'IPTraffic_delete_item' => 'Do you really want to delete this entry?', +); diff --git a/config/iptraffic/changelog b/config/iptraffic/changelog new file mode 100644 index 000000000..8eb47440d --- /dev/null +++ b/config/iptraffic/changelog @@ -0,0 +1,48 @@ +changelog +v.0.8.2 + Traffic-Einheit in den Graphen korrigiert + Filter zum Ausblender der roten Schnittstelle eingebaut + diverse Codeüberarbeitungen + +v.0.8.1 + Fehler in der Input-, Output- und Forward-Trafficberechnung beseitigt + Anzeige in iptraffic.cgi bezieht sich jetzt auf aktuellen Monat, aktuelle Woche und aktuellen Tag + Datenbankabfrage überarbeitet/optimiert + +v.0.8 + erste Portierung für IPFire + +v.0.7 + IPs an roter Schnittstelle aus arp-Liste gefiltert + +v0.6 + Überarbeitung der Datenerfassung, um tägliche Neustarts zu berücksichtigen. + Fehler in der Beschriftung beseitigt + weitere Sortiermöglichkeiten in der GUI hinzugefügt + Reduzierung der SQL-Abfragen -> schnellerer Seitenaufbau + +v0.5 + Fehler in der Auswertung bei >50GB/Tag beseitigt (Besonderer Dank an Wolle für die Geduld bei der Fehlersuche und den Tests) + Beschleunigung des Scripts durch Codeoptimierung + Fehler in der Chain-Regel beseitigt (Hatte sich über "geschlossen"-Regel hinweggesetzt) + Installer überarbeitet + Eintrag für rc.event.local hinzugefügt + +v0.4 + Zugriff auf Datenbank optimiert + Beschleunigung des Einfügen und Entfernen von Client-IPs in die Liste + Rechenfehler beseitigt + Fehler in der Darstellung beseitigt + +v0.3 + Werte in SQLite-Datenbank speichern + GUI mit Sortiermöglichkeit versehen + Farbliche Hervorhebung von Online-Clients + +v0.2 + Traffic aus FORWARD mit einbezogen + Wieder herstellen der Trafficermittlung nach Neustart (Rückmeldung erwünscht) + Installer überarbeitet + +v0.1 + Erste Version diff --git a/config/iptraffic/images/addblue.gif b/config/iptraffic/images/addblue.gif new file mode 100644 index 0000000000000000000000000000000000000000..9a8ffb74c3053be7f4284a75395755e7e39e37a1 GIT binary patch literal 154 zcmV;L0A>G2Nk%w1VH5xq0HXf@VPLrc0Qi%z^#A9a*Vos;z`&N4mH+?%A^8LW000F5 zEC2ui02BZe06+s@Si0PEPJtIjoiXid)1w}KRMSm5OHQz#mdu~@frWCvxqFo@~s IQVR(HJ6pm(bpQYW literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/addfaint.gif b/config/iptraffic/images/addfaint.gif new file mode 100644 index 0000000000000000000000000000000000000000..5fda96e49581f22ab9c3360e0eda845faab80aa4 GIT binary patch literal 126 zcmZ?wbhEHb6k!lySjfaMZQ8W||Nk?9f#OdVMg|5Z1|1L&B+tO)KSh4!aa~R&k8`b( zE=#UD>?@T^^N9RD_jY7#LdPzx&P&SEPen0 literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/addgray.gif b/config/iptraffic/images/addgray.gif new file mode 100644 index 0000000000000000000000000000000000000000..3765520350f2d9781c86cb7c792a10eb1abdf088 GIT binary patch literal 153 zcmV;K0A~M3Nk%w1VH5xq0Kx|V00014Sy`5rmYA5B*VotE+uQ%=od5s-A^8LW3IGQH zEC2ui02BZe000ACc)Hx)1W52IC}j*l)q%NRQWpgsoVGRNzm+LiviB#k73JB*sMo0Hpl@lG-=bQ96 H@)H0%D5^hE literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/addgreen.gif b/config/iptraffic/images/addgreen.gif new file mode 100644 index 0000000000000000000000000000000000000000..017d24eda57455cc3354b393ab26b4a14ec75b6e GIT binary patch literal 154 zcmZ?wbhEHb6k!lySoEI(2#jYMPn$N)_>8gff8*=dum68O=fHsjia%Kx85r0ZbU-RV zY8{y4D|X#k*D%4*i9t1;{a0G+cL$-=MCAmDtD-+i;27}O4DDPHgtwOe$U16+{VrQd&E>>*=x^df3f%^%wP=w Dt=l>! literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/addred.gif b/config/iptraffic/images/addred.gif new file mode 100644 index 0000000000000000000000000000000000000000..993167d33fecdf91daa54a4b27c48b2e3fa06719 GIT binary patch literal 154 zcmV;L0A>G2Nk%w1VH5xq0HXf@|L2_j006N70RF$fz`(%Q*VmSomH+?%A^8LW000C4 zEC2ui02BZe06+s@NV?pvXN(YpI3;Iy`eudqKoVtP;{gEG6?U-5mBBGG(bS?TeHMfl zu%QANFq(`EPJtIjoiXid)1w}KRMSm5OHLns=Nu~@frWCvxqFo@~s IQV9tFJ3xIuEC2ui literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/blue.png b/config/iptraffic/images/blue.png new file mode 100644 index 0000000000000000000000000000000000000000..af1b54de01ead60ac45c18eb67f3472575742e65 GIT binary patch literal 219 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-Vdx@v7EBh@LAwhk<84C*pfI^%F z9+AZi3~~oSnDKCCNH9>4CEd~2k%3`jKlh(RRvdX$Rut!UJF!Sv%0 z*X%jYhncN*3#2KZF@2$TK-JG!oUe|#Js^%v)bWXwQ)k>SW`?aF6ywSgdHI00GI+ZB KxvXhx literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/graph.png b/config/iptraffic/images/graph.png new file mode 100644 index 0000000000000000000000000000000000000000..ac86b8cb25eff84a3f9e29f9354ffe2bbe4bca66 GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAd3?%E9GuQzs_7YEDSN5A65*(6(i)V8$0Sa*z zctjR6FvuMQVaCImA;CaFmUKs7M+SzC{oH>NS%G|^0G|-o0|yRl+O+A+nKM8E28RFp z85mC5Z~6{oGL{7S1v5B2yO9RuWO%wbhE&|j?Yqd^puodg$UI+@IpGn*0=|G|<|{3K z!zXV0H=`ha`eIGq#4{|(@47Z=d74gsx~^M0dTqmmtB0&y( y!(3k6*6uy=eV#-8_sG8oO3gQEO=|i-Q8`ZkzreK literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/gray.png b/config/iptraffic/images/gray.png new file mode 100644 index 0000000000000000000000000000000000000000..2df59fabfccc4bafaad031bf64741e3640d117b4 GIT binary patch literal 219 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-Vdx@v7EBh@LAwhi|--Cu96Bp4{jlJ4m1$iT3%pZiZDE0CYz>EaktaVt4N;!T6#u^<2c+cQ6Q zIrjgF#3%dz_R0baq)r$#HtHOHuz(>+OnB>FpDB&}OmYo|S9zA~;%2|%AXdUyli2F( zm)OiSH96Bp4{jlJ4m1$iT3%pZiZDE0CY(>EaktaVt4N;!T6#u^<2c+aEsc zbnO2V38nl0=L>QK@YVzzaF~{8u)u&ZNlbX_UY|LQto#Zyve<&|wlZfbaJO;n+i*zD z+_CYVUdv66V%}NY1znd96Bp4{jlJ4m1$iT3%pZiZDE0CY=>EaktaVt4N;!T6#u^<2c+aGpx zJNEyHL=upxEU-YTf+0gqRj;^V)=`&Sec{vvhnm?Fd`y{FzB|NdI)OEoAwD8;a`l1* z4(Z~Da$0t>-DTZzB=gy!gZU2xPMuz$)Dh#XanZY;fgzk-KCXV2#c!aM44$rjF6*2U FngI8#Moa(z literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/square-green.png b/config/iptraffic/images/square-green.png new file mode 100644 index 0000000000000000000000000000000000000000..02ba31ea2eb94cb6b9079e64ebcfa5af18399140 GIT binary patch literal 163 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4^3?%3Nf7cA8cmjMvT!FOlOylNj&Hw-Ze|3rD z4v^1S666=m;PC858ivL>4nJa0`PlBg3pY5H=O_IsSt yBEqaGPPZ2Vg#ucttL3=E#GelF{r5}E*YRVl>) literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/square-red.png b/config/iptraffic/images/square-red.png new file mode 100644 index 0000000000000000000000000000000000000000..f3c9c4a69cf6f3bf30a415400dd165442f7c1ac3 GIT binary patch literal 157 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4|3?y&GPYDK6YymzYu0Z-W1B1%$WH}&?NMQuI%?XrA34-y>*wX r0fhuST^vI=t|uoXB&;~zCLzIKu#>sUH$@{FD97OG>gTe~DWM4f?c5;Z literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/square-yellow.png b/config/iptraffic/images/square-yellow.png new file mode 100644 index 0000000000000000000000000000000000000000..303fddaf4476775c1a37ff6358083bec08932e96 GIT binary patch literal 157 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4|3?y&GPYDK6YymzYu0Z<#OkYh7ML)4rAl` r0SXCtx;Tb#Tu)9&NLX>aO+tdfU?+2xZ;D1VP>#XV)z4*}Q$iB}kpLo0 literal 0 HcmV?d00001 diff --git a/config/iptraffic/iptraffic.cgi b/config/iptraffic/iptraffic.cgi new file mode 100644 index 000000000..dee935e9a --- /dev/null +++ b/config/iptraffic/iptraffic.cgi @@ -0,0 +1,678 @@ +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007 Michael Tremer & Christian Schmidt # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### +# +# +# This file is AddOn of the IPFire Firewall base on IPCop-Addon IPTraffic +# +# $Id: iptraffic.cgi, v0.8.2 2021-01-16 22:16:00 RadioCarbon $ +# + +my $debug = 0; +# enable only the following on debugging purpose +use warnings; +use strict; +# needs Perl-DBI-Addon +use DBI; +use Carp (); +use CGI::Carp 'fatalsToBrowser'; +use Socket; +use Fatal qw/ open /; + +require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/lang.pl"; +require "${General::swroot}/header.pl"; + +my $version = 'v0.8'; + +my @line; +my @iptclients; +my @get_param; +my @devs_net; +my ( %ips, %arpcache, %iptsettings, %netsettings ) = (); + +my $idarp = 0; +my $enabled_count = 0; +my $IPTrafficTable = "IPTraffic"; + +my $graphdir = '/graphs/iptraffic'; +my $imgsys = "/images"; +my $imgstatic = "$imgsys/iptraffic"; +my $logfile = "/var/log/iptraffic/iptraffic"; +my $rrdimgdir = "/srv/web/ipfire/html/graphs/iptraffic"; +my $rrddir = "/var/log/rrd/iptraffic"; +my $iptrafficdb = "/var/log/iptraffic/iptraffic.db"; + +## some iptraffic settings +$iptsettings{'ACTION'} = ''; +$iptsettings{'SORT'} = ''; +$iptsettings{'PARAM'} = ''; +$iptsettings{'CLIENTNAME'} = ''; + +my $contents = $ENV{'QUERY_STRING'}; + +&Header::getcgihash(\%iptsettings); +&General::readhash('/var/ipfire/ethernet/settings', \%netsettings); + +# add client to list +if ($iptsettings{'ACTION'} eq 'add'){ + my $client = $iptsettings{'PARAM'}; + my $name = $iptsettings{'HOST'}; + setClientAction($client,'ADD',$name); + siteReload(); +} +# delete client from list +if ($iptsettings{'ACTION'} eq 'del'){ + my $client = $iptsettings{'PARAM'}; + + setClientAction($client,'DEL'); + siteReload(); +} +# set trafficlimit on +if ($iptsettings{'ACTION'} eq 'ON'){ + my $client = $iptsettings{'PARAM'}; + + setClientAction($client,'ON'); +# siteReload(); +} +# set trafficlimit off +if ($iptsettings{'ACTION'} eq 'OFF'){ + my $client = $iptsettings{'PARAM'}; + + setClientAction($client,'OFF'); +# siteReload(); +} +# set sort direction +if ($contents) { + @get_param = split(/=/,$contents); + $iptsettings{'SORT'} = $get_param[1]; +} + +&Header::showhttpheaders(); +&Header::openpage($Lang::tr{'IPTraffic_title'}, 1, ''); +&Header::openbigbox('100%', 'left'); + +######################################################### +# START DEBUG DEBUG +if ($debug) { + &Header::openbox('100%', 'left', 'DEBUG'); + my $debugCount = 0; + foreach my $line (sort keys %iptsettings) { + print "$line = $iptsettings{$line}
\n"; + $debugCount++; + } + print " Count: $debugCount
\n"; + print " Contents: $contents
"; + print " Get-param: @get_param
"; + + hrline(); + + my $netdebug = 0; + foreach (sort keys %netsettings) { + print"$_ = $netsettings{$_}
\n"; + $netdebug++; + } + &Header::closebox(); +} +# END DEBUG DEBUG +######################################################### + +### Call funktions, default List with Arplist +if ($iptsettings{'ACTION'} eq 'GRAPH'){ + disp_singleclient(); +} +else{ +# disp_config(); + disp_clientlist(); + disp_arp(); +} + +&Header::closebigbox(); +&Header::closepage(); + +######################################################### +# subroutines + +### reload self +sub siteReload { + print "Status: 302 Found\n"; + print "Location: $ENV{'SCRIPT_NAME'}\n"; + print "URI: <$ENV{'SCRIPT_NAME'}>\n"; + print "Content-type: text/html\r\n\r\n"; +} + +### display config area +sub disp_config { + my $title = 'Konfiguration'; + + &Header::openbox('100%', 'left', "$title Titel"); + print < + +   + Device to limit: + Device max(MBit/sek): + Device limit(kBit/sek): + Version: $version + + +END +; + &Header::closebox(); +} + +### display single client graphs +sub disp_singleclient { + my $client = $iptsettings{'PARAM'}; + my $tmpHost = getHostnameFromTable($client); + my $host = length($tmpHost) > 1 ? $tmpHost : $client ; + my $back = ""; + + &Header::openbox('100%', 'center', "$Lang::tr{'IPTraffic_graphs_stat'}"); + print " + $back$Lang::tr{ +
"; + + if (-e "$rrdimgdir/$client-day.png") { + print " + $host-$Lang::tr{ + $host-$Lang::tr{ + $host-$Lang::tr{ + $host-$Lang::tr{ + $host-$Lang::tr{ +
+ $back$Lang::tr{ +"; + } + else { + print " +
+
$rrdimgdir/$client-day.png $Lang::tr{'IPTraffic_not_found'}

+ $Lang::tr{'no information available'}
+
"; + } + &Header::closebox(); +} + +sub disp_clientlist { + my ($sortarrowip, $sortarrowhn, $sortarrowou, $sortarrowouM, $sortarrowouW, $sortarrowouD, $sortarrowin, $sortarrowinM, $sortarrowinW, $sortarrowinD); + $sortarrowip = $sortarrowhn = $sortarrowou = $sortarrowouM = $sortarrowouW = $sortarrowouD = $sortarrowin = $sortarrowinM = $sortarrowinW = $sortarrowinD = ' '; + my ($sum_incoming_all, $sum_incoming_month, $sum_incoming_week, $sum_incoming_day) = 0; + my ($sum_outgoing_all, $sum_outgoing_month, $sum_outgoing_week, $sum_outgoing_day) = 0; + my ($ipsort, $hnsort, $insort, $ousort, $insortM, $ousortM, $insortW, $ousortW, $insortD, $ousortD) = ''; + my ($i, $count) = 0; + my @sorted_ip = ''; + my %traffic = getAllTrafficFromTable(); + my @ips = getIPfromTable(); + splice(@ips, $i, 1) if ($ips[$i] eq ''); + my $sort = $iptsettings{'SORT'}; + chomp $sort; + if (length($sort) < 1) { $sort = 'IPup'; } + + $ipsort = 'IPdown'; + $hnsort = 'HNdown'; + $insort = 'INdown'; + $ousort = 'OUdown'; + $insortM = 'INdownM'; + $ousortM = 'OUdownM'; + $insortW = 'INdownW'; + $ousortW = 'OUdownW'; + $insortD = 'INdownD'; + $ousortD = 'OUdownD'; + + SWITCH: { + if ($sort eq 'IPup') { + $sortarrowip .= '▲'; + $ipsort = 'IPdown'; + @sorted_ip = map {sprintf "%d.%d.%d.%d", split /[,.]/} sort map {sprintf "%03d.%03d.%03d.%03d", split /[,.]/} @ips; + last SWITCH; + } + if ($sort eq 'IPdown') { + $sortarrowip .= '▼'; + $ipsort = 'IPup'; + @sorted_ip = map {sprintf "%d.%d.%d.%d", split /[,.]/} reverse sort map {sprintf "%03d.%03d.%03d.%03d", split /[,.]/} @ips; + last SWITCH; + } + if ($sort eq 'HNup') { + $sortarrowhn .= '▲'; + $hnsort = 'HNdown'; + @sorted_ip = map { $_->[1] } sort { lc($a->[0]) cmp lc($b->[0]) } map { [ $traffic{$_}{'hostname'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'HNdown') { + $sortarrowhn .= '▼'; + $hnsort = 'HNup'; + @sorted_ip = map { $_->[1] } sort { lc($b->[0]) cmp lc($a->[0]) } map { [ $traffic{$_}{'hostname'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUup') { + $sortarrowou .= '▲'; + $ousort = 'OUdown'; + @sorted_ip = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $traffic{$_}{'alloutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUdown') { + $sortarrowou .= '▼'; + $ousort = 'OUup'; + @sorted_ip = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $traffic{$_}{'alloutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUupM') { + $sortarrowouM .= '▲'; + $ousortM = 'OUdownM'; + @sorted_ip = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $traffic{$_}{'monthoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUdownM') { + $sortarrowouM .= '▼'; + $ousortM = 'OUupM'; + @sorted_ip = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $traffic{$_}{'monthoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUupW') { + $sortarrowouW .= '▲'; + $ousortW = 'OUdownW'; + @sorted_ip = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $traffic{$_}{'weekoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUdownW') { + $sortarrowouW .= '▼'; + $ousortW = 'OUupW'; + @sorted_ip = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $traffic{$_}{'weekoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUupD') { + $sortarrowouD .= '▲'; + $ousortD = 'OUdownD'; + @sorted_ip = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $traffic{$_}{'dayoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUdownD') { + $sortarrowouD .= '▼'; + $ousortD = 'OUupD'; + @sorted_ip = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $traffic{$_}{'dayoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INup') { + $sortarrowin .= '▲'; + $insort = 'INdown'; + @sorted_ip = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $traffic{$_}{'allinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INdown') { + $sortarrowin .= '▼'; + $insort = 'INup'; + @sorted_ip = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $traffic{$_}{'allinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INupM') { + $sortarrowinM .= '▲'; + $insortM = 'INdownM'; + @sorted_ip = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $traffic{$_}{'monthinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INdownM') { + $sortarrowinM .= '▼'; + $insortM = 'INupM'; + @sorted_ip = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $traffic{$_}{'monthinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INupW') { + $sortarrowinW .= '▲'; + $insortW = 'INdownW'; + @sorted_ip = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $traffic{$_}{'weekinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INdownW') { + $sortarrowinW .= '▼'; + $insortW = 'INupW'; + @sorted_ip = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $traffic{$_}{'weekinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INupD') { + $sortarrowinD .= '▲'; + $insortD = 'INdownD'; + @sorted_ip = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $traffic{$_}{'dayinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INdownD') { + $sortarrowinD .= '▼'; + $insortD = 'INupD'; + @sorted_ip = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $traffic{$_}{'dayinput'}, $_ ] } keys %traffic; + last SWITCH; + } + } + + + &Header::openbox('100%', 'left', "$Lang::tr{'IPTraffic_clientlist'}:"); + print" + + + + + + + + + + + + + + + + + + + + + "; + + foreach my $ip (@sorted_ip) { + next if (!defined ($ip) || $ip eq '0.0.0.0'); + if (defined($traffic{$ip}{'limit'})) { + next if (trim($traffic{$ip}{'limit'}) eq 'DEL'); + } + + if ( !defined ( $traffic{$ip}{'allinput'})) { $traffic{$ip}{'allinput'} = 0; } + if ( !defined ( $traffic{$ip}{'alloutput'})) { $traffic{$ip}{'alloutput'} = 0; } + if ( !defined ( $traffic{$ip}{'monthinput'})) { $traffic{$ip}{'monthinput'} = 0; } + if ( !defined ( $traffic{$ip}{'monthoutput'})) { $traffic{$ip}{'monthoutput'} = 0; } + if ( !defined ( $traffic{$ip}{'weekinput'})) { $traffic{$ip}{'weekinput'} = 0; } + if ( !defined ( $traffic{$ip}{'weekoutput'})) { $traffic{$ip}{'weekoutput'} = 0; } + if ( !defined ( $traffic{$ip}{'dayinput'})) { $traffic{$ip}{'dayinput'} = 0; } + if ( !defined ( $traffic{$ip}{'dayoutput'})) { $traffic{$ip}{'dayoutput'} = 0; } + + $sum_incoming_all += $traffic{$ip}{'allinput'}; + $sum_outgoing_all += $traffic{$ip}{'alloutput'}; + $sum_incoming_month += $traffic{$ip}{'monthinput'}; + $sum_outgoing_month += $traffic{$ip}{'monthoutput'}; + $sum_incoming_week += $traffic{$ip}{'weekinput'}; + $sum_outgoing_week += $traffic{$ip}{'weekoutput'}; + $sum_incoming_day += $traffic{$ip}{'dayinput'}; + $sum_outgoing_day += $traffic{$ip}{'dayoutput'}; + + my $netColor = getNetworkColor($ip); + my $hostname = defined ($traffic{$ip}{'hostname'}) ? $traffic{$ip}{'hostname'} : ' '; + + print " + + + + + + + + + + + + + + + + + "; + } + print " + + + + + + + + + + + + +
#$Lang::tr{'network'}$Lang::tr{'ip address'}".($sortarrowip eq ' ' ? '' : $sortarrowip)."$Lang::tr{'hostname'}".($sortarrowhn eq ' ' ? '' : $sortarrowhn)."$Lang::tr{'IPTraffic_load'}$Lang::tr{'IPTraffic_send'}$Lang::tr{'action'}
$Lang::tr{'IPTraffic_sum'}".($sortarrowin eq ' ' ? '' : $sortarrowin)."$Lang::tr{'IPTraffic_month'}".($sortarrowinM eq ' ' ? '' : $sortarrowinM)."$Lang::tr{'IPTraffic_week'}".($sortarrowinW eq ' ' ? '' : $sortarrowinW)."$Lang::tr{'IPTraffic_today'}".($sortarrowinD eq ' ' ? '' : $sortarrowinD)."$Lang::tr{'IPTraffic_sum'}".($sortarrowou eq ' ' ? '' : $sortarrowou)."$Lang::tr{'IPTraffic_month'}".($sortarrowouM eq ' ' ? '' : $sortarrowouM)."$Lang::tr{'IPTraffic_week'}".($sortarrowouW eq ' ' ? '' : $sortarrowouW)."$Lang::tr{'IPTraffic_today'}".($sortarrowouD eq ' ' ? '' : $sortarrowouD)."
".$count."$netColor$ip$hostname".calcTraffic($traffic{$ip}{'allinput'})."".calcTraffic($traffic{$ip}{'monthinput'})."".calcTraffic($traffic{$ip}{'weekinput'})."".calcTraffic($traffic{$ip}{'dayinput'})."".calcTraffic($traffic{$ip}{'alloutput'})."".calcTraffic($traffic{$ip}{'monthoutput'})."".calcTraffic($traffic{$ip}{'weekoutput'})."".calcTraffic($traffic{$ip}{'dayoutput'})." +
+ + + +
+
+
+ + + +
+
$Lang::tr{'IPTraffic_sum'}".calcTraffic($sum_incoming_all)."".calcTraffic($sum_incoming_month)."".calcTraffic($sum_incoming_week)."".calcTraffic($sum_incoming_day)."".calcTraffic($sum_outgoing_all)."".calcTraffic($sum_outgoing_month)."".calcTraffic($sum_outgoing_week)."".calcTraffic($sum_outgoing_day)." 
"; + + &Header::closebox(); +} + +## arp table entries +sub disp_arp { + my $output = `/sbin/ip neigh list`; + my @clientlist = getIPfromTable(); + my $count = 0; + + foreach my $line (split(/\n/, $output)){ + if ($line =~ m/^(.*) dev ([^ ]+) lladdr ([0-9a-f:]*) (.*)$/ || $line =~ m/^(.*) dev ([^ ]+) (.*)$/) { + my $hostname = gethostbyaddr(inet_aton($1), AF_INET); + $arpcache{$1} = $2.",".( $hostname ? $hostname : '' )."\n"; + } + } + + &Header::openbox('100%', 'left', "$Lang::tr{'IPTraffic_add'}:"); + print" + +
+$Lang::tr{'IPTraffic_arp_table_entries'} + +
+
+ + + + + + + +"; + foreach my $key (sort keys %arpcache) { + chomp ($key); + @line = split (/\,/, $arpcache{$key}); + my $netname = (split(/-/,$line[0]))[0]; + chop $netname; + next if ($netname eq 'red'); + chomp $line[1]; + print" + + + + + + "; + } + + print" + +
+ +"; + + &Header::closebox(); +} + +sub calcTraffic { + my $value = shift; + my @unit = ('', 'K', 'M', 'G', 'T', 'P'); + my $i = 0; + + while ($value > 1000){ + $value = sprintf ( "%.1f", $value/1024); + $i++; + } + return ($value < 0 ? "0" : $value+0 )." $unit[$i]B"; +} + +sub setClientAction { + my $client = shift; + my $action = shift; + my $host = shift; + + my $sql = ''; + if ($action eq 'ADD'){ + if (defined $host){ + $sql = "INSERT INTO '".$IPTrafficTable."' (`client`, `hostname`, `date`) VALUES ( '".$client."', '".$host."', date('now'));"; + } + else { + $sql = "INSERT INTO '".$IPTrafficTable."' (`client`, `date`) VALUES ( '".$client."', date('now'));"; + } + } + + if ($action eq 'DEL'){ + $sql = "UPDATE '".$IPTrafficTable."' SET `traflimit` = 'DEL' WHERE `client` = '".$client."';"; + } + my $dbh = DBI->connect("dbi:SQLite:dbname=$iptrafficdb", "", "", {RaiseError => 1, AutoCommit=>1}); + my $Action= $dbh->prepare($sql); + $Action->execute(); + $Action->finish(); +} + +## get network color +sub getNetworkColor { + my $ipaddress = shift; + my %devs_color = ('GREEN' => 'green', 'BLUE' => 'blue', 'ORANGE' => 'orange', 'RED' => 'red', 'GRAY' => 'gray'); + + for my $color (keys %devs_color) { + if (exists($netsettings{$color."_DEV"})){ + next if ( $netsettings{$color."_DEV"} eq 'red0'); + + if ( &General::IpInSubnet($ipaddress, $netsettings{$color."_ADDRESS"}, $netsettings{$color."_NETMASK"}) ) { + return substr($netsettings{$color."_DEV"}, 0, -1); + } + } + } + return 'gray'; +} +sub getHostnameFromTable { + my $client = shift; + my ($host, $sql); + my $dbh = DBI->connect("dbi:SQLite:dbname=/var/log/iptraffic/iptraffic.db", "", "", {RaiseError => 1}); + $sql = "SELECT DISTINCT `hostname` FROM `".$IPTrafficTable."` WHERE `client` = '".$client."';"; + my $Statement = $dbh->prepare($sql); + $Statement->execute; + $Statement->bind_columns(\$host); + $Statement->fetch(); + $Statement->finish(); + $dbh->disconnect() or warn $dbh->errstr; + return $host; +} + +sub getIPfromTable { + my @clients = ''; + my ($client, $traflimit, $sql); + my $dbh = DBI->connect("dbi:SQLite:dbname=/var/log/iptraffic/iptraffic.db", "", "", {RaiseError => 1}); + $sql = "SELECT DISTINCT `client`, `traflimit` FROM `".$IPTrafficTable."` WHERE `date` = date('now');"; + my $Statement = $dbh->prepare($sql); + $Statement->execute; + $Statement->bind_columns(\$client, \$traflimit); + while($Statement->fetch()){ + $client = trim($client); + if(length($client) > 0) {push(@clients, "$client");} + } + $Statement->finish(); + $dbh->disconnect() or warn $dbh->errstr; + return @clients; +} + +sub getAllTrafficFromTable { + my %traffic; + my @iplist = getIPfromTable(); + my ($client, $hostname, $date, $input, $output, $dayinput, $dayoutput, $weekinput, $weekoutput, $monthinput, $monthoutput, $traflimit, $port); + + my $dbh = DBI->connect("dbi:SQLite:dbname=/var/log/iptraffic/iptraffic.db", "", "", {RaiseError => 1}); + my $sql = ''; + my $Statement = $dbh->prepare($sql); + foreach $client ( @iplist) { + $client = trim($client); + if (length($client) > 0){ + $sql = "SELECT `hostname`, sum(`input`), sum(`output`), "; + $sql.= "(SELECT sum(input) from '".$IPTrafficTable."' WHERE `client` = '".$client."' AND `date` = date('now')) as `dayinput`, "; + $sql.= "(SELECT sum(output) from '".$IPTrafficTable."' WHERE `client` = '".$client."' AND `date` = date('now')) as `dayoutput`, "; + $sql.= "(SELECT sum(input) from '".$IPTrafficTable."' WHERE `client` = '".$client."' AND `date` BETWEEN date('now', 'weekday 1', '-7 day') AND date('now')) as `weekinput`, "; + $sql.= "(SELECT sum(output) from '".$IPTrafficTable."' WHERE `client` = '".$client."' AND `date` BETWEEN date('now', 'weekday 1', '-7 day') AND date('now')) as `weekoutput`, "; + $sql.= "(SELECT sum(input) from '".$IPTrafficTable."' WHERE `client` = '".$client."' AND `date` BETWEEN date('now', 'start of month') AND date('now')) as `monthinput`, "; + $sql.= "(SELECT sum(output) from '".$IPTrafficTable."' WHERE `client` = '".$client."' AND `date` BETWEEN date('now', 'start of month') AND date('now')) as `monthoutput`, "; + $sql.= "`traflimit`, `port` from '".$IPTrafficTable."' WHERE `client` = '".$client."';"; + $Statement = $dbh->prepare($sql); + $Statement->execute; + $Statement->bind_columns(\$hostname, \$input, \$output, \$dayinput, \$dayoutput, \$weekinput, \$weekoutput, \$monthinput, \$monthoutput, \$traflimit, \$port); + while($Statement->fetch()) { + $traffic{$client} = {'hostname' => $hostname, 'allinput' => $input, 'alloutput' => $output, 'dayinput' => $dayinput, 'dayoutput' => $dayoutput, 'weekinput' => $weekinput, 'weekoutput' => $weekoutput, 'monthinput' => $monthinput, 'monthoutput' => $monthoutput, 'limit' => $traflimit, 'port' => $port}; + } + } + } + $Statement->finish(); + $dbh->disconnect() or warn $dbh->errstr; + + return %traffic; +} + +sub trim() { + my $str = shift; + if (defined $str) {$str =~ s/^\s+|\s+$//g;} + return $str; +} +############################################################################################################################ + +sub hrline { + +print"

"; + +} + diff --git a/config/iptraffic/iptraffic.pl b/config/iptraffic/iptraffic.pl new file mode 100644 index 000000000..9aeb5c45e --- /dev/null +++ b/config/iptraffic/iptraffic.pl @@ -0,0 +1,354 @@ +#!/usr/bin/perl +# +# This file is AddOn of the IPFire Firewall. +# +# IPFire is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# IPFire is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with IPFire. If not, see . +# +# $Id: iptraffic.pl, v0.8.2 2021-01-17 14:45:00 RadioCarbon $ +# + +use strict; +use DBI; +use RRDs; +use Socket; +use Fatal qw/ open /; + +require '/var/ipfire/general-functions.pl'; +require '/var/ipfire/lang.pl'; + +my $debug; +my $version = 'v0.8'; +my $gruppe = getgrnam("nobody"); +my $user = getpwnam("nobody"); +my $FW = '/sbin/iptables'; +my $logdir = "/var/log/iptraffic"; +my $iptrafficdb = "$logdir/iptraffic.db"; +my $IPTrafficTable = "IPTraffic"; +my $rrdimgdir = "/srv/web/ipfire/html/graphs/iptraffic"; +my $rrddir = "/var/log/rrd/iptraffic"; +my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time); +my $heute = sprintf("%4d%02d%02d", $Jahr+1900, ++$Monat, $Monatstag); +($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time - 86400); +my $gestern = sprintf("%4d%02d%02d", $Jahr+1900, ++$Monat, $Monatstag); + +foreach (@ARGV) { + if ( $_ eq '-d' || $_ eq '--debug') { $debug = 1; } + if ( $_ eq '-h' || $_ eq '--help' ) { print help(); exit 1; } +} + +# read from iptables +my $a_output = `$FW -nvx -L CUSTOMOUTPUT`; +my $a_forward = `$FW -nvx -L CUSTOMFORWARD`; +my $a_input = `$FW -nvx -L CUSTOMINPUT`; + +if ($debug == 1){ print "Einträge in iptables:\n" } + +# extract Traffic from iptables +my %output = extractTraffic($a_output); +my %forward = extractTraffic($a_forward); +my %input = extractTraffic($a_input); + +if ($debug == 1){ startdebug(); } + +# create/check Table in DB +my $dbh = DBI->connect("dbi:SQLite:dbname=$iptrafficdb", "", "", {RaiseError => 1}); +my $sql = "CREATE TABLE IF NOT EXISTS '".$IPTrafficTable."'(client VARCHAR(16), hostname VARCHAR(25) default NULL, date INT UNSIGNED, input INT UNSIGNED, output INT UNSIGNED, traflimit INT UNSIGNED, port INT UNSIGNED);"; +my $Statement = $dbh->prepare($sql); +$Statement->execute(); +$Statement->finish(); + +my @iptclients = getIPTrafficClientlist(); + +foreach (sort @iptclients){ + chomp; + my ($clientIP, $hostname, $tmpdate) = ''; + my ($date, $clientoutput, $clientinput, $traflimit, $clientinputsum, $clientoutputsum) = 0; + my @buffer = (); + my %dbTraffic; + ($clientIP, $hostname, $date, $clientinput, $clientoutput, $traflimit) = split( /,/, $_ ); + + if (trim($traflimit) eq 'DEL') { + clientDelete($clientIP); + if ($debug == 1){print "Client $clientIP deleted \n";} + next; + } + + ($tmpdate = $date) =~ s/-//g; + if ($tmpdate < $heute) {next;}; + + # not Line in iptables: create item and set starttraffic = 0 + unless (exists($output{$clientIP})) { `$FW -A CUSTOMOUTPUT -d $clientIP -j RETURN`; $output{$clientIP}{'destination'} = 0;} + unless (exists($forward{$clientIP})) { + `$FW -A CUSTOMFORWARD -d $clientIP -j RETURN`; $forward{$clientIP}{'destination'} = 0; + `$FW -A CUSTOMFORWARD -s $clientIP -j RETURN`; $forward{$clientIP}{'source'} = 0; + } + unless (exists($input{$clientIP})) { `$FW -A CUSTOMINPUT -s $clientIP -j RETURN`; $input{$clientIP}{'source'} = 0;} + +# %dbTraffic = getNowIPTrafficFromTable($clientIP); +# $clientinputsum = $input{$clientIP}{'destination'}+$forward{$clientIP}{'destination'} + (($clientinputsum < $dbTraffic{'dayinput'}) ? $dbTraffic{'dayinput'} : 0); +# $clientoutputsum = $output{$clientIP}{'source'}+$forward{$clientIP}{'source'} + (($clientoutputsum < $dbTraffic{'dayoutput'}) ? $dbTraffic{'dayoutput'} : 0); + + $clientoutputsum = $input{$clientIP}{'source'} + $forward{$clientIP}{'source'}; + $clientinputsum = $output{$clientIP}{'destination'} + $forward{$clientIP}{'destination'}; + + if ($debug == 1){ + printf ("%15s%15s%15s%15s%15s%15s%15s\n", $clientIP, $output{$clientIP}{'destination'}, $input{$clientIP}{'source'}, $forward{$clientIP}{'destination'}, $forward{$clientIP}{'source'}, $clientinputsum, $clientoutputsum); + } + updateTrafficCount($clientIP, $hostname, $heute, $clientinputsum, $clientoutputsum, $traflimit); + updateiptrafficdata($clientIP, $clientinputsum, $clientoutputsum); + + $hostname = ($hostname eq '') ? $clientIP : $hostname; + if ( -e "$rrddir/$clientIP.rrd" ) { + updateiptrafficgraph("$clientIP", "$hostname", "hour"); + updateiptrafficgraph("$clientIP", "$hostname", "day"); + updateiptrafficgraph("$clientIP", "$hostname", "week"); + updateiptrafficgraph("$clientIP", "$hostname", "month"); + updateiptrafficgraph("$clientIP", "$hostname", "year"); + } +} + +$dbh->disconnect() or warn $dbh->errstr; + +sub getIPTrafficClientlist{ + my $clientIP; + my $hostname = ''; + my ($date, $output, $input, $traflimit, $port, $trafficReset) = 0; + my $clientIPfirst = ''; + my @clientlist = ''; + + my $sql = "SELECT * FROM '".$IPTrafficTable."' WHERE date = date('now') OR date = date('now', '-1 day') ORDER by date DESC;"; + $Statement = $dbh->prepare($sql); + $Statement->bind_columns(\$clientIP, \$hostname, \$date, \$input, \$output, \$traflimit, \$port); + $Statement->execute(); + while( $Statement->fetch()){ + my $sql = "SELECT COUNT(*) FROM `".$IPTrafficTable."` WHERE `client` = '".$clientIP."' AND `date` = date('now');"; + my $cStatement = $dbh->prepare($sql); + $cStatement->execute; + my $count = $cStatement->fetchrow; + $cStatement->finish(); + + unless ( $count > 0){ + $sql = "INSERT INTO '".$IPTrafficTable."' (`client`, `hostname`, `date`, `input`, `output`, `traflimit`) VALUES ( '".$clientIP."', '".$hostname."', date('now'), '".$input."', '".$output."', '".$traflimit."');"; + my $Insert= $dbh->prepare($sql); + $Insert->execute(); + $Insert->finish(); + $trafficReset = 1; + } + push (@clientlist, "$clientIP, $hostname, $date, $input, $output, $traflimit \n"); + } + $Statement->finish(); + + # daily reset count traffic + if ( $trafficReset == 1) { + my $reset; + $reset = `$FW -Z CUSTOMFORWARD`; + $reset = `$FW -Z CUSTOMOUTPUT`; + $reset = `$FW -Z CUSTOMINPUT`; + } + return @clientlist; +} + +sub getNowIPTrafficFromTable { + my $client = shift; + my %traffic; + my ($input, $output, $sql, $Statement); + + if (defined ($client)){ + $sql = "SELECT `input`, `output` from '".$IPTrafficTable."' WHERE `client` = '".$client."' AND `date` = date('now');"; + $Statement = $dbh->prepare($sql); + $Statement->execute; + $Statement->bind_columns(\$input, \$output); + while($Statement->fetch()) { + $traffic{ 'dayinput' } = $input; + $traffic{ 'dayoutput' } = $output ; + } + } + $Statement->finish(); + + return %traffic; +} + +sub updateTrafficCount { + my $client = shift; + my $hostname = shift; + my $date = shift; + my $input = shift; + my $output = shift; + my $traflimit = shift; + + $hostname = (length($hostname) <= 2) ? gethostbyaddr(inet_aton($client), AF_INET) : $hostname; + + my $sql = "UPDATE '".$IPTrafficTable."' SET `client` = '".$client."', `hostname` = '".trim($hostname)."', `input` = '".$input."', `output` = '".$output."', `traflimit` = '".trim($traflimit)."' WHERE `client` = '".$client."' AND `date` = date('now');"; + my $Update = $dbh->prepare($sql); + $Update->execute(); + $Update->finish(); +} + +sub updateiptrafficdata { + my $ip = $_[0]; + my $incoming = int($_[1]/8); + my $outgoing = int($_[2]/8); + + if ( !-e "$rrddir/$ip.rrd" ) { + RRDs::create( + "$rrddir/$ip.rrd", "--step=60", + "DS:incoming:DERIVE:600:0:125000000", "DS:outgoing:DERIVE:600:0:125000000", + "RRA:AVERAGE:0.5:1:576", "RRA:AVERAGE:0.5:6:672", + "RRA:AVERAGE:0.5:24:732", "RRA:AVERAGE:0.5:144:1460" + ); + chown($user, $gruppe, "$rrddir/$ip.rrd"); + my $ERROR = RRDs::error; + print "Error in RRD::create for IP-Traffic: $ERROR\n" if $ERROR; + } + + RRDs::update("$rrddir/$ip.rrd", "-t", "incoming:outgoing", "N:$incoming:$outgoing"); + + my $error = RRDs::error; + if ($error) { &General::log("iptraffic","$error"); } +} + +sub updateiptrafficgraph { + my $ip = $_[0]; + my $client = $_[1]; + my $period = $_[2]; + chomp($client); + + if (length($client) < 2) {$client = $ip;} + my $comment = sprintf("%-40s%-20s%-30s%-25s%-25s\\j", $Lang::tr{'caption'}, $Lang::tr{'maximal'}, $Lang::tr{'average'}, $Lang::tr{'minimal'}, $Lang::tr{'current'}); + + RRDs::graph( + "$rrdimgdir/$ip-$period.png", + "--start", "-1$period", "-aPNG", "-i", "-z", + "--alt-y-grid", "-w 807", "-h 171", + "-v ".$Lang::tr{'bytes per second'}, + "--font", "TITLE:0:sans mono bold oblique", + "--pango-markup", + "--interlaced", + "--color", "SHADEA#FEFEFE", + "--color", "SHADEB#FEFEFE", + "--color", "BACK#FEFEFE", + "-t $client $Lang::tr{'graph per'} $Lang::tr{$period}", + "DEF:incoming=$rrddir/$ip.rrd:incoming:AVERAGE", + "DEF:outgoing=$rrddir/$ip.rrd:outgoing:AVERAGE", + "CDEF:incomingbits=incoming,8,*", + "CDEF:outgoingbits=outgoing,8,*", + "CDEF:outgoingnegbits=outgoing,-8,*", + "HRULE:0#000000", + "COMMENT:$comment", + "AREA:incomingbits#00FF00:".sprintf("%-20s",$Lang::tr{'incoming traffic in bytes per second'}), + "GPRINT:incomingbits:MAX:%8.1lf %sBps", + "GPRINT:incomingbits:AVERAGE:%8.1lf %sBps", + "GPRINT:incomingbits:MIN:%8.1lf %sBps", + "GPRINT:incomingbits:LAST:%8.1lf %sBps\\j", + "AREA:outgoingnegbits#FF0000:".sprintf("%-20s",$Lang::tr{'outgoing traffic in bytes per second'}), + "GPRINT:outgoingbits:MAX:%8.1lf %sBps", + "GPRINT:outgoingbits:AVERAGE:%8.1lf %sBps", + "GPRINT:outgoingbits:MIN:%8.1lf %sBps", + "GPRINT:outgoingbits:LAST:%8.1lf %sBps\\j", + @{&rrd_lastupdate()} + ); + chown($user, $gruppe, "$rrdimgdir/$ip-$period.png"); + + my $ERROR = RRDs::error; + print "Error in RRD::create for IP-Traffic: $ERROR\n" if $ERROR; + + my $error = RRDs::error; + + if ($error) { &General::log("iptraffic","$error"); } +} + +sub rrd_lastupdate { + my $result = []; + + push @$result, "COMMENT: \\r"; + push @$result, "COMMENT:IPTraffic by IPFire.org\\u"; + push @$result, "COMMENT:Last update\\: ". RRDescape(scalar localtime()) ."\\r"; + + return $result; +} +# This from munin-graph which is: Copyright (C) 2002-2004 Jimmy Olsen, Audun Ytterdal +# Munin has some pretty cool RRD graphing. +sub RRDescape { + my $text = shift; + return undef if not defined $text; + $text =~ s/\\/\\\\/g; + $text =~ s/:/\\:/g; + return $text; +} + +sub clientDelete { + my $client = shift; + my @ok = (); + # remove client item from iptables + $ok[0] = `$FW -D CUSTOMOUTPUT -d $client -j RETURN`; + $ok[1] = `$FW -D CUSTOMINPUT -s $client -j RETURN`; + $ok[2] = `$FW -D CUSTOMFORWARD -d $client -j RETURN`; + $ok[3] = `$FW -D CUSTOMFORWARD -s $client -j RETURN`; + + # remove client graphs + my @removefiles = ("$rrdimgdir/$client-hour.png", "$rrdimgdir/$client-day.png", "$rrdimgdir/$client-week.png", "$rrdimgdir/$client-month.png", "$rrdimgdir/$client-year.png"); + $ok[4] = unlink (@removefiles); + + # remove client rrd-file + $ok[5] = unlink ("$rrddir/$client.rrd"); + + # remove client from database + my $sql = "DELETE FROM `".$IPTrafficTable."` WHERE `client` = '".$client."';"; + my $Delete = $dbh->prepare($sql); + $Delete->execute(); + $Delete->finish(); +} + +sub extractTraffic { + my $page = shift; + my %clientHash; + my @buffer; + my @line = split('\n',$page); + + foreach (sort @line){ + chomp; + @buffer = split(/\s+/, trim($_)); + if ($buffer[0] eq 'pkts' || $buffer[0] eq 'Chain') {next;}; + if ($debug == 1) {printf "0:%10s 1:%15s 2:%9s 3:%6s 4:%4s 5:%3s 6:%2s 7:%15s 8:%15s\n", $buffer[0], $buffer[1], $buffer[2], $buffer[3], $buffer[4], $buffer[5], $buffer[6], $buffer[7], $buffer[8];} + if ($buffer[7] eq '0.0.0.0/0') {$clientHash{"$buffer[8]"}{'destination'} = $buffer[1];} + if ($buffer[8] eq '0.0.0.0/0') {$clientHash{"$buffer[7]"}{'source'} = $buffer[1];} + } + return %clientHash; +} + +sub trim { + my $str = shift; + $str =~ s/^\s+|\s+$//g; + return $str; +} + +sub startdebug { + +printf " +Hole Traffic von iptables ... + +%15s%15s%15s%15s%15s%15s%15s +---------------------------------------------------------------------------------------------------------- +", "IP-Adresse", "IN", "OUT", "FWD IN", "FWD OUT", "Sum IN", "Sum OUT"; +} + +sub help { + return " +IPTraffic $version +Created 2014/2019 by Frank Mainz (RadioCarbon) +mail: ipfire\@cybermainzel.de + +use option -d or --debug for debugging +use option -h or --help for help\n\n"; +} diff --git a/config/rootfiles/packages/iptraffic b/config/rootfiles/packages/iptraffic new file mode 100644 index 000000000..b860cd9aa --- /dev/null +++ b/config/rootfiles/packages/iptraffic @@ -0,0 +1,22 @@ +etc/fcron.minutely/update-iptraffic +srv/web/ipfire/html/images/iptraffic +srv/web/ipfire/cgi-bin/iptraffic.cgi +srv/web/ipfire/html/images/iptraffic/addblue.gif +srv/web/ipfire/html/images/iptraffic/addfaint.gif +srv/web/ipfire/html/images/iptraffic/addgray.gif +srv/web/ipfire/html/images/iptraffic/addgreen.gif +srv/web/ipfire/html/images/iptraffic/addorange.gif +srv/web/ipfire/html/images/iptraffic/addred.gif +srv/web/ipfire/html/images/iptraffic/blue.png +srv/web/ipfire/html/images/iptraffic/graph.png +srv/web/ipfire/html/images/iptraffic/gray.png +srv/web/ipfire/html/images/iptraffic/green.png +srv/web/ipfire/html/images/iptraffic/orange.png +srv/web/ipfire/html/images/iptraffic/red.png +srv/web/ipfire/html/images/iptraffic/square-green.png +srv/web/ipfire/html/images/iptraffic/square-red.png +srv/web/ipfire/html/images/iptraffic/square-yellow.png +usr/local/bin/iptraffic.pl +var/ipfire/addon-lang/iptraffic.de.pl +var/ipfire/addon-lang/iptraffic.en.pl +var/ipfire/menu.d/EX-iptraffic.menu diff --git a/lfs/iptraffic b/lfs/iptraffic new file mode 100644 index 000000000..25fab3ed8 --- /dev/null +++ b/lfs/iptraffic @@ -0,0 +1,86 @@ +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2020 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +############################################################################### +# Definitions +############################################################################### + +include Config + +VER = 0.8.2 + +THISAPP = iptraffic-$(VER) +DIR_APP = $(DIR_SRC)/$(THISAPP) +TARGET = $(DIR_INFO)/$(THISAPP) +PROG = iptraffic +PAK_VER = 1 + +DEPS = "" + +############################################################################### +# Top-level Rules +############################################################################### + +install : $(TARGET) + +check : + +download : + +md5 : + +dist: + $(PAK) + +############################################################################### +# Installation Details +############################################################################### + +$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) + @$(PREBUILD) + + # Install GUI + install -v -m 755 $(DIR_SRC)/config/iptraffic/iptraffic.cgi \ + /srv/web/ipfire/cgi-bin/iptraffic.cgi + + # Install images + -mkdir -p /srv/web/ipfire/html/images/iptraffic + install -v -m 644 $(DIR_SRC)/config/iptraffic/images/* \ + /srv/web/ipfire/html/images/iptraffic/ + + # Install iptraffic script + install -v -m 755 $(DIR_SRC)/config/iptraffic/iptraffic.pl \ + /usr/local/bin/iptraffic.pl + + # Install language files + install -v -m 004 $(DIR_SRC)/config/iptraffic/addon-lang/iptraffic.* \ + /var/ipfire/addon-lang/ + + # Install menu entry + install -v -m 644 $(DIR_SRC)/config/iptraffic/EX-iptraffic.menu \ + /var/ipfire/menu.d/EX-iptraffic.menu + chown nobody.nobody /var/ipfire/menu.d/EX-iptraffic.menu + + # Create symlink for one minute updates + ln -sf /usr/local/bin/iptraffic.pl \ + /etc/fcron.minutely/update-iptraffic + + @rm -rf $(DIR_APP) + @$(POSTBUILD) diff --git a/make.sh b/make.sh index a9db53edf..267e1b09a 100755 --- a/make.sh +++ b/make.sh @@ -1654,6 +1654,7 @@ buildipfire() { lfsmake2 ncdu lfsmake2 lshw lfsmake2 socat + lfsmake2 iptraffic } buildinstaller() { diff --git a/src/paks/iptraffic/install.sh b/src/paks/iptraffic/install.sh new file mode 100644 index 000000000..a9f857784 --- /dev/null +++ b/src/paks/iptraffic/install.sh @@ -0,0 +1,40 @@ +#!/bin/bash +############################################################################ +# # +# This file is part of the IPFire Firewall. # +# # +# IPFire is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# IPFire is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with IPFire; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +# Copyright (C) 2020 IPFire-Team . # +# # +############################################################################ +# +. /opt/pakfire/lib/functions.sh +extract_files + +mkdir -p /srv/web/ipfire/html/graphs/iptraffic +mkdir -p /var/log/iptraffic +mkdir -p /var/log/rrd/iptraffic + +touch /var/log/iptraffic/iptraffic.db + +restore_backup ${NAME} + +chown -R nobody.nobody /var/log/iptraffic +chown -R nobody.nobody /var/log/rrd/iptraffic +chown root.nobody /usr/local/bin/iptraffic.pl +chown nobody.nobody /var/ipfire/menu.d/EX-iptraffic.menu + +/usr/local/bin/update-lang-cache diff --git a/src/paks/iptraffic/uninstall.sh b/src/paks/iptraffic/uninstall.sh new file mode 100644 index 000000000..dac570c05 --- /dev/null +++ b/src/paks/iptraffic/uninstall.sh @@ -0,0 +1,28 @@ +#!/bin/bash +############################################################################ +# # +# This file is part of the IPFire Firewall. # +# # +# IPFire is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# IPFire is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with IPFire; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +# Copyright (C) 2007 IPFire-Team . # +# # +############################################################################ +# +. /opt/pakfire/lib/functions.sh + +remove_files + +/usr/local/bin/update-lang-cache diff --git a/src/paks/iptraffic/update.sh b/src/paks/iptraffic/update.sh new file mode 100644 index 000000000..89c40d0d7 --- /dev/null +++ b/src/paks/iptraffic/update.sh @@ -0,0 +1,26 @@ +#!/bin/bash +############################################################################ +# # +# This file is part of the IPFire Firewall. # +# # +# IPFire is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# IPFire is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with IPFire; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +# Copyright (C) 2007 IPFire-Team . # +# # +############################################################################ +# +. /opt/pakfire/lib/functions.sh +./uninstall.sh +./install.sh