From: Frank Mainz frank@cybermainzel.de
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 matthias.fischer@ipfire.org --- 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. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 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. + + <signature of Ty Coon>, 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@Si0P<M~DyrI3#Cx`euapKoVtP<1q}?6?U-5mBBGG(bS?TeG-Ki zu%Q|lFq(`<vq0XSidP4^2>EPJtIjoiXid)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&S<RTXu{25-LHQnT}Te|vOcnOf&(4dq|+0(yc9 ZW$#M3JebDqyhexHz@5crF+VGVH30W>EPen0
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*<S;Shvb;p$rfk=?wsji(Fs;rCx1Z;umo9l~K z2$z!p6}A-a5Lq?=2F>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<EaPE2JsFuHhUk!Gz}yZDBMMjQsS zdfYcV+?&@G&c2J|XO92sbEY*JzUMA(ZxShrc<|&?v4+&djS<_6Q`l2?7<9aR5ya2Q GU=09V9zAdX
literal 0 HcmV?d00001
diff --git a/config/iptraffic/images/addorange.gif b/config/iptraffic/images/addorange.gif new file mode 100644 index 0000000000000000000000000000000000000000..e0218c18af490402f41ccc26ba2bf96c7f06b2d8 GIT binary patch literal 153 zcmZ?wbhEHb6k!lyIK%(~bNm?YhcFyTVwg5<+V$(#|39At6jc1l!pOzI&Y%NQ0aDAr z99OaH&OKI-4_X3AJW-KHq7IZEpUT@9G2#Bob#o<Gt?6N6&1rlw`*n91$MnezqT58? z2}GJPu$_H-eTm+Jz|>-+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(`<vq0XSidP4^2>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(RRv<si)5S5Q;#P8k#G3}eV?X}?w{K2* zbnyQZiK6;_w#otvq*hEQXwW&F@Zca5`-VuLE8mO)+2k?;7?M{>dX$Rut!UJF!Sv%0 z*X%jYhncN*3#2KZF@2$TK-JG!oUe|#Js^%v)bWXwQ)k>SW`?aF6ywSgdHI00GI+ZB KxvX<aXaWGPV?>hx
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<C3)y%|=5g-V4iUu-w>&y( y!(3k6*6uy=eV#-8_sG8oO3gQEO=|i-Q8`ZkzreK<YquT)ImXk~&t;ucLK6U6*<HQ>
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|--Cu<fI^%F z9+AZi4E&ZL%xKl{YduhqCEd~2k%3`jKlh(RRv<si)5S5Q;#P8k#G3}eV?X}?w|7oS zc~W1*6S=R(QdwYul!Tz5<FrJB4M|72HbnYd`DPTzR#sBdV0e{h$u4g8D-L2Mj5Ud^ zzUvk(YC5Oaa+9N&cNcd-=jAi4&G!!|PMPlLDzLLHVA1q{3=D$3N_NSc=j#G(W$<+M Kb6Mw<&;$TA{6;DO
literal 0 HcmV?d00001
diff --git a/config/iptraffic/images/green.png b/config/iptraffic/images/green.png new file mode 100644 index 0000000000000000000000000000000000000000..fc4240a7af59c173520570405583f2bf56241525 GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-Vdx@v7EBh@LApv8Nrm}rN5eCiz zkH}&M2DyVE%y>96Bp4{jlJ4m1$iT3%pZiZDE0CYz>EaktaVt4N;!T6#u^<2c+cQ6Q zIrjgF#3%dz_R0baq)r$#HtHOHuz(>+OnB>FpDB&}OmYo|S9zA~;%2|%AXdUyli2F( zm)OiSH<n|w;4`Tb@drZ7XL7UeZ*<nsZ|+hk;$7&X|Cf;=zEwf)+k<V{AeVW%`njxg HN@xNA)=5L$
literal 0 HcmV?d00001
diff --git a/config/iptraffic/images/orange.png b/config/iptraffic/images/orange.png new file mode 100644 index 0000000000000000000000000000000000000000..87865a4feea034566173b2a9d8c4d3d149a20143 GIT binary patch literal 223 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-Vdx@v7EBh@LAwdIf)rnn<Kq1Zo zkH}&M2DyVE%y>96Bp4{jlJ4m1$iT3%pZiZDE0CY(>EaktaVt4N;!T6#u^<2c+aEsc zbnO2V38nl0=L>QK@YVzzaF~{8u)u&ZNlbX_UY|LQto#Zyve<&|wlZfbaJO;n+i*zD z+_CYVUdv66V%}NY1znd<wKm^(5SwFUafoBN#o4_)T1_WRTZHz0VQ0ATMY6G9Epr9X OW(H4JKbLh*2~7ZlqDWBy
literal 0 HcmV?d00001
diff --git a/config/iptraffic/images/red.png b/config/iptraffic/images/red.png new file mode 100644 index 0000000000000000000000000000000000000000..afd5b81880f8d8433576066619b3f8c61ac0f864 GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-Vdx@v7EBh@LAwffKo37msKq1Zo zkH}&M2DyVE%y>96Bp4{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;PC858i<qR?e4<R!7A$k<Zu>vL>4nJa0`PlBg3pY5<o%r5>H=O_IsSt yBEqaGPPZ2Vg#<iZ978y+Cnqp4T@1J*!NFkinCW@>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}&<u_VYZ zn8D%MjWiG^$=lt9p@UV{1IXbl@Q5sCVBi)8VMc~ob0mO*>?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<#Ok<Wcchi9^#*!ev zU<QY0H_||yByV>Yh7ML)4<LuLz$3Dlfq`2Xgc%uT&5-~KvX^-Jy0YKnlok<D>rAl` 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 http://www.gnu.org/licenses/. # +# # +############################################################################### +# +# +# 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 frank@cybermainzel.de$ +# + +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}<br />\n"; + $debugCount++; + } + print " Count: $debugCount <br>\n"; + print " Contents: $contents<br>"; + print " Get-param: @get_param<br>"; + + hrline(); + + my $netdebug = 0; + foreach (sort keys %netsettings) { + print"$_ = $netsettings{$_}<br />\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 <<END +<table width='100%' align='center' border="1"> + <tr> + <td width="5%"> </td> + <td>Device to limit:</td> + <td>Device max(MBit/sek):</td> + <td>Device limit(kBit/sek):</td> + <td width="15%">Version: $version</td> + </tr> +</table> +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 = "<a href='$ENV{'SCRIPT_NAME'}'>"; + + &Header::openbox('100%', 'center', "$Lang::tr{'IPTraffic_graphs_stat'}"); + print " + $back<img src='$imgsys/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a> + <hr />"; + + if (-e "$rrdimgdir/$client-day.png") { + print " + <img src='$graphdir/$client-hour.png' border='0' alt='$host-$Lang::tr{'hour'}' /> + <img src='$graphdir/$client-day.png' border='0' alt='$host-$Lang::tr{'day'}' /> + <img src='$graphdir/$client-week.png' border='0' alt='$host-$Lang::tr{'week'}' /> + <img src='$graphdir/$client-month.png' border='0' alt='$host-$Lang::tr{'month'}' /> + <img src='$graphdir/$client-year.png' border='0' alt='$host-$Lang::tr{'year'}' /> + <hr /> + $back<img src='$imgsys/back.png' alt='$Lang::tr{'back'}' title='$Lang::tr{'back'}' /></a> +"; + } + else { + print " +<div width='100%' align='center'> + <br>$rrdimgdir/$client-day.png $Lang::tr{'IPTraffic_not_found'}<br /><br /> + <b>$Lang::tr{'no information available'}</b><br /> +</div>"; + } + &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" +<style> +.table1colour {background-color: #d6d6d6;} +.table2colour {background-color: #f0f0f0;} +tr.table1colour:hover, tr.table2colour:hover { background: #a9a9a9; color: #fefefe;} +</style> +<table width='100%'> + <tr bgcolor='#C0C0C0' style='heigt: 20px'> + <td rowspan='2' width='30em' align='center'><b>#</b></td> + <td rowspan='2' align='center'><b>$Lang::tr{'network'}</b></td> + <td rowspan='2' width='110em' align='center'><b><a href='$ENV{'SCRIPT_NAME'}?SORT=$ipsort'>$Lang::tr{'ip address'}</a>".($sortarrowip eq ' ' ? '' : $sortarrowip)."</b></td> + <td rowspan='2' width='110em' align='center'><b><a href='$ENV{'SCRIPT_NAME'}?SORT=$hnsort'>$Lang::tr{'hostname'}</a>".($sortarrowhn eq ' ' ? '' : $sortarrowhn)."</b></td> + <td colspan='4' align='center'><b>$Lang::tr{'IPTraffic_load'}</b></td> + <td colspan='4' align='center'><b>$Lang::tr{'IPTraffic_send'}</b></td> + <td rowspan='2' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td> + </tr> + <tr bgcolor='#C0C0C0'> + <td align='center' style='width: 6em'><a href='$ENV{'SCRIPT_NAME'}?SORT=$insort'>$Lang::tr{'IPTraffic_sum'}</a>".($sortarrowin eq ' ' ? '' : $sortarrowin)."</td> + <td align='center' style='width: 6em'><a href='$ENV{'SCRIPT_NAME'}?SORT=$insortM'>$Lang::tr{'IPTraffic_month'}</a>".($sortarrowinM eq ' ' ? '' : $sortarrowinM)."</td> + <td align='center' style='width: 6em'><a href='$ENV{'SCRIPT_NAME'}?SORT=$insortW'>$Lang::tr{'IPTraffic_week'}</a>".($sortarrowinW eq ' ' ? '' : $sortarrowinW)."</td> + <td align='center' style='width: 6em'><a href='$ENV{'SCRIPT_NAME'}?SORT=$insortD'>$Lang::tr{'IPTraffic_today'}</a>".($sortarrowinD eq ' ' ? '' : $sortarrowinD)."</td> + <td align='center' style='width: 6em'><a href='$ENV{'SCRIPT_NAME'}?SORT=$ousort'>$Lang::tr{'IPTraffic_sum'}</a>".($sortarrowou eq ' ' ? '' : $sortarrowou)."</td> + <td align='center' style='width: 6em'><a href='$ENV{'SCRIPT_NAME'}?SORT=$ousortM'>$Lang::tr{'IPTraffic_month'}</a>".($sortarrowouM eq ' ' ? '' : $sortarrowouM)."</td> + <td align='center' style='width: 6em'><a href='$ENV{'SCRIPT_NAME'}?SORT=$ousortW'>$Lang::tr{'IPTraffic_week'}</a>".($sortarrowouW eq ' ' ? '' : $sortarrowouW)."</td> + <td align='center' style='width: 6em'><a href='$ENV{'SCRIPT_NAME'}?SORT=$ousortD'>$Lang::tr{'IPTraffic_today'}</a>".($sortarrowouD eq ' ' ? '' : $sortarrowouD)."</td> + </tr>"; + + 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 " + <tr class='table".($count++ % 2?1:2)."colour'> + <td align='center'>".$count."</td> + <td align='center'><img src='$imgstatic/$netColor.png' alt='$netColor' title='$netColor' /></td> + <td align='center'>$ip</td> + <td align='center'>$hostname</td> + <td align='center'>".calcTraffic($traffic{$ip}{'allinput'})."</td> + <td align='center'>".calcTraffic($traffic{$ip}{'monthinput'})."</td> + <td align='center'>".calcTraffic($traffic{$ip}{'weekinput'})."</td> + <td align='center'>".calcTraffic($traffic{$ip}{'dayinput'})."</td> + <td align='center'>".calcTraffic($traffic{$ip}{'alloutput'})."</td> + <td align='center'>".calcTraffic($traffic{$ip}{'monthoutput'})."</td> + <td align='center'>".calcTraffic($traffic{$ip}{'weekoutput'})."</td> + <td align='center'>".calcTraffic($traffic{$ip}{'dayoutput'})."</td> + <td align='center' width='5%'> + <form method='post' name='graph".$count."' action='$ENV{'SCRIPT_NAME'}'> + <input type='hidden' name='ACTION' value='GRAPH' /> + <input type='hidden' name='PARAM' value='$ip' /> + <input type='image' name='$hostname' src='$imgstatic/graph.png' alt='$Lang::tr{'IPTraffic_graphs'}' title='$Lang::tr{'IPTraffic_graphs'}' /> + </form> + </td> + <td align='center' width='5%'> + <form method='post' name='delete".$count."' action='$ENV{'SCRIPT_NAME'}'> + <input type='hidden' name='ACTION' value='del' /> + <input type='hidden' name='PARAM' value='$ip' /> + <input type='image' name='$hostname' src='$imgsys/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' onclick="return confirm('$Lang::tr{'IPTraffic_delete_item'}')"/> + </form> + </td> + </tr> + "; + } + print " + <tr bgcolor='#C0C0C0'> + <td align='right' colspan='4' style='height: 2em'>$Lang::tr{'IPTraffic_sum'}</td> + <td align='center'>".calcTraffic($sum_incoming_all)."</td> + <td align='center'>".calcTraffic($sum_incoming_month)."</td> + <td align='center'>".calcTraffic($sum_incoming_week)."</td> + <td align='center'>".calcTraffic($sum_incoming_day)."</td> + <td align='center'>".calcTraffic($sum_outgoing_all)."</td> + <td align='center'>".calcTraffic($sum_outgoing_month)."</td> + <td align='center'>".calcTraffic($sum_outgoing_week)."</td> + <td align='center'>".calcTraffic($sum_outgoing_day)."</td> + <td align='center' colspan='3'> </td> + </tr> +</table>"; + + &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" +<style> .shownone { display: none; } </style> +<div> +<span style='float: left; background-color: #D6D6D6; padding: 0.8em;'><b>$Lang::tr{'IPTraffic_arp_table_entries'}</b></span> +<span style='float: right;'><button id='shownone'>$Lang::tr{'IPTraffic_view_table'}</button></span> +</div> +<div style='margin-top: 5em'> +<table width='100%' class='shownone' style='display: none;'> +<tr style='background: #C0C0C0;'> + <td width='15%' align='center' height='20'><b>$Lang::tr{'network'}</b></td> + <td width='20%' align='center' height='20'><b>$Lang::tr{'ip address'}</b></td> + <td width='65%' align='center' height='20'><b>$Lang::tr{'hostname'}</b></td> + <td width='5%' align='center' height='20'><b>$Lang::tr{'action'}</b></td> +</tr> +"; + 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" + <tr class='table".($count++ % 2?1:2)."colour' height='20'> + <td align='center'><img src='$imgstatic/$netname.png' alt='$line[0]' title='$line[0]' /></td> + <td align='center'>$key</td> + <td align='center'>$line[1]</td> + <td align='center'>"; + if (grep /^$key$/, @clientlist){ + print " + <img src='$imgstatic/addfaint.gif' alt='$Lang::tr{'IPTraffic_no_add'}' title='$Lang::tr{'IPTraffic_no_add'}' />"; + } + else { + print " + <form method='post' name='addfromlist".($idarp++)."' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'> + <input type='hidden' name='ACTION' value='add' /> + <input type='hidden' name='PARAM' value='$key' /> + <input type='hidden' name='CLIENTNAME' value='$line[1]' /> + <input type='image' name='$netname' src='$imgstatic/add$netname.gif' alt='$Lang::tr{'IPTraffic_add'}' title='$Lang::tr{'IPTraffic_add'}' /> + </form>"; + } + print " + </td> + </tr>"; + } + + print" +</table> +</div> +<script> +var shownone = false; +document.querySelector("#shownone").onclick = function () { + if (shownone === false ) { + document.querySelectorAll(".shownone")[0].style="display: block"; + shownone = true; + this.innerHTML = "$Lang::tr{'IPTraffic_hide_table'}"; + } else { + document.querySelectorAll(".shownone")[0].style="display: none"; + shownone = false; + this.innerHTML = "$Lang::tr{'IPTraffic_view_table'}"; + } +} +</script> +"; + + &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"<table width='100%'><tr><td colspan='2' height='35'><hr></td></tr></table>"; + +} + 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 http://www.gnu.org/licenses/. +# +# $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:<span size='smaller'> </span>\r"; + push @$result, "COMMENT:<span size='smaller' foreground='darkgray'>IPTraffic by IPFire.org</span>\u"; + push @$result, "COMMENT:<span size='smaller' foreground='darkgray'>Last update\: ". RRDescape(scalar localtime()) ."</span>\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 info@ipfire.org # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + +############################################################################### +# 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 info@ipfire.org. # +# # +############################################################################ +# +. /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 info@ipfire.org. # +# # +############################################################################ +# +. /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 info@ipfire.org. # +# # +############################################################################ +# +. /opt/pakfire/lib/functions.sh +./uninstall.sh +./install.sh