From mboxrd@z Thu Jan 1 00:00:00 1970 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 Content-Type: multipart/mixed; boundary="===============0389756515894624070==" List-Id: --===============0389756515894624070== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: =3D> 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. +=0C + 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.) +=0C +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. +=0C + 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. +=0C + 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 +=0C + 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-iptraff= ic.menu new file mode 100644 index 000000000..032d3eba6 --- /dev/null +++ b/config/iptraffic/EX-iptraffic.menu @@ -0,0 +1,6 @@ + $substatus->{'70.iptraffic'} =3D { + 'caption' =3D> $Lang::tr{'IPTraffic_title'}, + 'uri' =3D> '/cgi-bin/iptraffic.cgi', + 'title' =3D> $Lang::tr{'IPTraffic_title'}, + 'enabled' =3D> 1, + }; diff --git a/config/iptraffic/addon-lang/iptraffic.de.pl b/config/iptraffic/a= ddon-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 =3D (%tr, +'IPTraffic_title' =3D> 'IPTraffic', +'IPTraffic_add' =3D> 'Client hinzufügen', +'IPTraffic_no_add' =3D> 'Client ist vorhanden', +'IPTraffic_clientlist' =3D> 'IPTraffic Clientliste', +'IPTraffic_send' =3D> 'Gesendet', +'IPTraffic_load' =3D> 'Empfangen', +'IPTraffic_month' =3D> 'Monat', +'IPTraffic_week' =3D> 'Woche', +'IPTraffic_today' =3D> 'Heute', +'IPTraffic_sum' =3D> 'Gesamt', +'IPTraffic_graphs' =3D> 'Graphen anzeigen', +'IPTraffic_graphs_stat' =3D> 'Clientdiagramme', +'IPTraffic_arp_table_entries' =3D> 'Client aus der ARP-Tabelle hinzufüg= en:', +'IPTraffic_view_table' =3D> 'Tabelle einblenden', +'IPTraffic_hide_table' =3D> 'Tabelle ausblenden', +'IPTraffic_not_found' =3D> 'nicht gefunden', +'IPTraffic_delete_item' =3D> 'Möchten sie diesen Eintrag wirklich l&oum= l;schen?', +); diff --git a/config/iptraffic/addon-lang/iptraffic.en.pl b/config/iptraffic/a= ddon-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 =3D (%tr, +'IPTraffic_title' =3D> 'IPTraffic', +'IPTraffic_add' =3D> 'Add Client', +'IPTraffic_no_add' =3D> 'Client is available', +'IPTraffic_clientlist' =3D> 'IPTraffic list of clients', +'IPTraffic_send' =3D> 'Received', +'IPTraffic_load' =3D> 'Transmitted', +'IPTraffic_month' =3D> 'Month', +'IPTraffic_week' =3D> 'Week', +'IPTraffic_today' =3D> 'Today', +'IPTraffic_sum' =3D> 'Total', +'IPTraffic_graphs' =3D> 'View Graph', +'IPTraffic_graphs_stat' =3D> 'Client-Diagrams', +'IPTraffic_arp_table_entries' =3D> 'Add client from ARP-Table:', +'IPTraffic_view_table' =3D> 'Show table', +'IPTraffic_hide_table' =3D> 'Hide table', +'IPTraffic_not_found' =3D> 'not found', +'IPTraffic_delete_item' =3D> '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=C3=BCberarbeitungen + +v.0.8.1 + Fehler in der Input-, Output- und Forward-Trafficberechnung beseitigt + Anzeige in iptraffic.cgi bezieht sich jetzt auf aktuellen Monat, aktuelle W= oche und aktuellen Tag + Datenbankabfrage =C3=BCberarbeitet/optimiert + +v.0.8 + erste Portierung f=C3=BCr IPFire + +v.0.7 + IPs an roter Schnittstelle aus arp-Liste gefiltert + +v0.6 + =C3=9Cberarbeitung der Datenerfassung, um t=C3=A4gliche Neustarts zu ber=C3= =BCcksichtigen. + Fehler in der Beschriftung beseitigt + weitere Sortierm=C3=B6glichkeiten in der GUI hinzugef=C3=BCgt + Reduzierung der SQL-Abfragen -> schnellerer Seitenaufbau + +v0.5 + Fehler in der Auswertung bei >50GB/Tag beseitigt (Besonderer Dank an Wolle = f=C3=BCr die Geduld bei der Fehlersuche und den Tests) + Beschleunigung des Scripts durch Codeoptimierung + Fehler in der Chain-Regel beseitigt (Hatte sich =C3=BCber "geschlossen"-Reg= el hinweggesetzt) + Installer =C3=BCberarbeitet + Eintrag f=C3=BCr rc.event.local hinzugef=C3=BCgt + +v0.4 + Zugriff auf Datenbank optimiert + Beschleunigung des Einf=C3=BCgen 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=C3=B6glichkeit versehen + Farbliche Hervorhebung von Online-Clients + +v0.2 + Traffic aus FORWARD mit einbezogen + Wieder herstellen der Trafficermittlung nach Neustart (R=C3=BCckmeldung erw= =C3=BCnscht) + Installer =C3=BCberarbeitet + +v0.1 + Erste Version diff --git a/config/iptraffic/images/addblue.gif b/config/iptraffic/images/ad= dblue.gif new file mode 100644 index 0000000000000000000000000000000000000000..9a8ffb74c3053be7f4284a7539575= 5e7e39e37a1 GIT binary patch literal 154 zcmV;L0A>G2Nk%w1VH5xq0HXf(a)VPLrc0Qi%z^#A9a*Vos;z`&N4mH+?%A^8LW000F5 zEC2ui02BZe06+s(a)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/a= ddfaint.gif new file mode 100644 index 0000000000000000000000000000000000000000..5fda96e49581f22ab9c3360e0eda8= 45faab80aa4 GIT binary patch literal 126 zcmZ?wbhEHb6k!lySjfaMZQ8W||Nk?9f#OdVMg|5Z1|1L&B+tO)KSh4!aa~R&k8`b( zE=3D#UD>?@T^^N9RD_jY7#LdPzx&P&SEPen0 literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/addgray.gif b/config/iptraffic/images/ad= dgray.gif new file mode 100644 index 0000000000000000000000000000000000000000..3765520350f2d9781c86cb7c792a1= 0eb1abdf088 GIT binary patch literal 153 zcmV;K0A~M3Nk%w1VH5xq0Kx|V00014Sy`5rmYA5B*VotE+uQ%=3Dod5s-A^8LW3IGQH zEC2ui02BZe000ACc)Hx)1W52IC}j*l)q%NRQWpgsoVGRNzm+LiviB#k73JB*sMo0Hpl(a)lG-=3DbQ96 H@)H0%D5^hE literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/addgreen.gif b/config/iptraffic/images/a= ddgreen.gif new file mode 100644 index 0000000000000000000000000000000000000000..017d24eda57455cc3354b393ab26b= 4a14ec75b6e GIT binary patch literal 154 zcmZ?wbhEHb6k!lySoEI(2#jYMPn$N)_>8gff8*=3Ddum68O=3DfHsjia%Kx85r0ZbU-RV zY8{y4D|X#k*D%4*i9t1;{a0G+cL$-=3DMCAmDtD-+i;27}O4DDPHgtwOe$U16+{VrQd&E>>*=3Dx^df3f%^%wP=3Dw Dt=3Dl>! literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/addred.gif b/config/iptraffic/images/add= red.gif new file mode 100644 index 0000000000000000000000000000000000000000..993167d33fecdf91daa54a4b27c48= b2e3fa06719 GIT binary patch literal 154 zcmV;L0A>G2Nk%w1VH5xq0HXf@|L2_j006N70RF$fz`(%Q*VmSomH+?%A^8LW000C4 zEC2ui02BZe06+s(a)NV?pvXN(YpI3;Iy`eudqKoVtP;{gEG6?U-5mBBGG(bS?TeHMfl zu%QANFq(`EPJtIjoiXid)1w}KRMSm5OHLns=3DNu~@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..af1b54de01ead60ac45c18eb67f34= 72575742e65 GIT binary patch literal 219 zcmeAS(a)N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-Vdx(a)v7EBh@LAwhk<84C*pfI^%F z9+AZi3~~oSnDKCCNH9>4CEd~2k%3`jKlh(RRvdX$Rut!UJF!Sv%0 z*X%jYhncN*3#2KZF(a)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/grap= h.png new file mode 100644 index 0000000000000000000000000000000000000000..ac86b8cb25eff84a3f9e29f9354ff= e2bbe4bca66 GIT binary patch literal 260 zcmeAS(a)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+(a)IpGn*0=3D|G|<|{3K z!zXV0H=3D`ha`eIGq#4{|(@47Z=3Dd74gsx~^M0dTqmmtB0&y( y!(3k6*6uy=3DeV#-8_sG8oO3gQEO=3D|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..2df59fabfccc4bafaad031bf64741= e3640d117b4 GIT binary patch literal 219 zcmeAS(a)N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-Vdx(a)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=3DL>QK(a)YVzzaF~{8u)u&ZNlbX_UY|LQto#Zyve<&|wlZfbaJO;n+i*zD z+_CYVUdv66V%}NY1znd96Bp4{jlJ4m1$iT3%pZiZDE0CY=3D>EaktaVt4N;!T6#u^<2c+aGpx zJNEyHL=3DupxEU-YTf+0gqRj;^V)=3D`&Sec{vvhnm?Fd`y{FzB|NdI)OEoAwD8;a`l1* z4(Z~Da$0t>-DTZzB=3Dgy!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/imag= es/square-green.png new file mode 100644 index 0000000000000000000000000000000000000000..02ba31ea2eb94cb6b9079e64ebcfa= 5af18399140 GIT binary patch literal 163 zcmeAS(a)N?(olHy`uVBq!ia0vp^oFL4^3?%3Nf7cA8cmjMvT!FOlOylNj&Hw-Ze|3rD z4v^1S666=3Dm;PC858ivL>4nJa0`PlBg3pY5H=3DO_IsSt yBEqaGPPZ2Vg#ucttL3=3DE#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..f3c9c4a69cf6f3bf30a415400dd16= 5442f7c1ac3 GIT binary patch literal 157 zcmeAS(a)N?(olHy`uVBq!ia0vp^oFL4|3?y&GPYDK6YymzYu0Z-W1B1%$WH}&?NMQuI%?XrA34-y>*wX r0fhuST^vI=3Dt|uoXB&;~zCLzIKu#>sUH$@{FD97OG>gTe~DWM4f?c5;Z literal 0 HcmV?d00001 diff --git a/config/iptraffic/images/square-yellow.png b/config/iptraffic/ima= ges/square-yellow.png new file mode 100644 index 0000000000000000000000000000000000000000..303fddaf4476775c1a37ff6358083= bec08932e96 GIT binary patch literal 157 zcmeAS(a)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 =3D 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 =3D 'v0.8'; + +my @line; +my @iptclients; +my @get_param; +my @devs_net; +my ( %ips, %arpcache, %iptsettings, %netsettings ) =3D (); + +my $idarp =3D 0; +my $enabled_count =3D 0; +my $IPTrafficTable =3D "IPTraffic"; + +my $graphdir =3D '/graphs/iptraffic'; +my $imgsys =3D "/images"; +my $imgstatic =3D "$imgsys/iptraffic"; +my $logfile =3D "/var/log/iptraffic/iptraffic"; +my $rrdimgdir =3D "/srv/web/ipfire/html/graphs/iptraffic"; +my $rrddir =3D "/var/log/rrd/iptraffic"; +my $iptrafficdb =3D "/var/log/iptraffic/iptraffic.db"; + +## some iptraffic settings +$iptsettings{'ACTION'} =3D ''; +$iptsettings{'SORT'} =3D ''; +$iptsettings{'PARAM'} =3D ''; +$iptsettings{'CLIENTNAME'} =3D ''; + +my $contents =3D $ENV{'QUERY_STRING'}; + +&Header::getcgihash(\%iptsettings); +&General::readhash('/var/ipfire/ethernet/settings', \%netsettings); + +# add client to list +if ($iptsettings{'ACTION'} eq 'add'){ + my $client =3D $iptsettings{'PARAM'}; + my $name =3D $iptsettings{'HOST'}; + setClientAction($client,'ADD',$name); + siteReload(); +} +# delete client from list +if ($iptsettings{'ACTION'} eq 'del'){ + my $client =3D $iptsettings{'PARAM'}; + + setClientAction($client,'DEL'); + siteReload(); +} +# set trafficlimit on +if ($iptsettings{'ACTION'} eq 'ON'){ + my $client =3D $iptsettings{'PARAM'}; + + setClientAction($client,'ON'); +# siteReload(); +} +# set trafficlimit off +if ($iptsettings{'ACTION'} eq 'OFF'){ + my $client =3D $iptsettings{'PARAM'}; + + setClientAction($client,'OFF'); +# siteReload(); +} +# set sort direction +if ($contents) { + @get_param =3D split(/=3D/,$contents); + $iptsettings{'SORT'} =3D $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 =3D 0; + foreach my $line (sort keys %iptsettings) { + print "$line =3D $iptsettings{$line}
\n"; + $debugCount++; + } + print " Count: $debugCount
\n"; + print " Contents: $contents
"; + print " Get-param: @get_param
"; + + hrline(); + + my $netdebug =3D 0; + foreach (sort keys %netsettings) { + print"$_ =3D $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 =3D '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 =3D $iptsettings{'PARAM'}; + my $tmpHost =3D getHostnameFromTable($client); + my $host =3D length($tmpHost) > 1 ? $tmpHost : $client ; + my $back =3D ""; + + &Header::openbox('100%', 'center', "$Lang::tr{'IPTraffic_graphs_stat'}"); + print " + $back3D'$Lang::tr{'back'}' +
"; + + if (-e "$rrdimgdir/$client-day.png") { + print " + 3D'$host-$Lang::tr= + 3D'$host-$Lang::tr{= + 3D'$host-$Lang::tr= + 3D'$host-$Lang::t= + 3D'$host-$Lang::tr= +
+ $back3D'$Lang::tr{'back'}' +"; + } + 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 =3D $sortarrowhn =3D $sortarrowou =3D $sortarrowouM =3D $sorta= rrowouW =3D $sortarrowouD =3D $sortarrowin =3D $sortarrowinM =3D $sortarrowin= W =3D $sortarrowinD =3D ' '; + my ($sum_incoming_all, $sum_incoming_month, $sum_incoming_week, $sum_incomi= ng_day) =3D 0; + my ($sum_outgoing_all, $sum_outgoing_month, $sum_outgoing_week, $sum_outgoi= ng_day) =3D 0; + my ($ipsort, $hnsort, $insort, $ousort, $insortM, $ousortM, $insortW, $ouso= rtW, $insortD, $ousortD) =3D ''; + my ($i, $count) =3D 0; + my @sorted_ip =3D ''; + my %traffic =3D getAllTrafficFromTable(); + my @ips =3D getIPfromTable(); + splice(@ips, $i, 1) if ($ips[$i] eq ''); + my $sort =3D $iptsettings{'SORT'}; + chomp $sort; + if (length($sort) < 1) { $sort =3D 'IPup'; } + + $ipsort =3D 'IPdown'; + $hnsort =3D 'HNdown'; + $insort =3D 'INdown'; + $ousort =3D 'OUdown'; + $insortM =3D 'INdownM'; + $ousortM =3D 'OUdownM'; + $insortW =3D 'INdownW'; + $ousortW =3D 'OUdownW'; + $insortD =3D 'INdownD'; + $ousortD =3D 'OUdownD'; + + SWITCH: { + if ($sort eq 'IPup') { + $sortarrowip .=3D '▲'; + $ipsort =3D 'IPdown'; + @sorted_ip =3D map {sprintf "%d.%d.%d.%d", split /[,.]/} sort map {sprint= f "%03d.%03d.%03d.%03d", split /[,.]/} @ips; + last SWITCH; + } + if ($sort eq 'IPdown') { + $sortarrowip .=3D '▼'; + $ipsort =3D 'IPup'; + @sorted_ip =3D map {sprintf "%d.%d.%d.%d", split /[,.]/} reverse sort map= {sprintf "%03d.%03d.%03d.%03d", split /[,.]/} @ips; + last SWITCH; + } + if ($sort eq 'HNup') { + $sortarrowhn .=3D '▲'; + $hnsort =3D 'HNdown'; + @sorted_ip =3D map { $_->[1] } sort { lc($a->[0]) cmp lc($b->[0]) } map {= [ $traffic{$_}{'hostname'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'HNdown') { + $sortarrowhn .=3D '▼'; + $hnsort =3D 'HNup'; + @sorted_ip =3D map { $_->[1] } sort { lc($b->[0]) cmp lc($a->[0]) } map {= [ $traffic{$_}{'hostname'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUup') { + $sortarrowou .=3D '▲'; + $ousort =3D 'OUdown'; + @sorted_ip =3D map { $_->[1] } sort { $a->[0] <=3D> $b->[0] } map { [ $tr= affic{$_}{'alloutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUdown') { + $sortarrowou .=3D '▼'; + $ousort =3D 'OUup'; + @sorted_ip =3D map { $_->[1] } sort { $b->[0] <=3D> $a->[0] } map { [ $tr= affic{$_}{'alloutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUupM') { + $sortarrowouM .=3D '▲'; + $ousortM =3D 'OUdownM'; + @sorted_ip =3D map { $_->[1] } sort { $a->[0] <=3D> $b->[0] } map { [ $tr= affic{$_}{'monthoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUdownM') { + $sortarrowouM .=3D '▼'; + $ousortM =3D 'OUupM'; + @sorted_ip =3D map { $_->[1] } sort { $b->[0] <=3D> $a->[0] } map { [ $tr= affic{$_}{'monthoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUupW') { + $sortarrowouW .=3D '▲'; + $ousortW =3D 'OUdownW'; + @sorted_ip =3D map { $_->[1] } sort { $a->[0] <=3D> $b->[0] } map { [ $tr= affic{$_}{'weekoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUdownW') { + $sortarrowouW .=3D '▼'; + $ousortW =3D 'OUupW'; + @sorted_ip =3D map { $_->[1] } sort { $b->[0] <=3D> $a->[0] } map { [ $tr= affic{$_}{'weekoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUupD') { + $sortarrowouD .=3D '▲'; + $ousortD =3D 'OUdownD'; + @sorted_ip =3D map { $_->[1] } sort { $a->[0] <=3D> $b->[0] } map { [ $tr= affic{$_}{'dayoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'OUdownD') { + $sortarrowouD .=3D '▼'; + $ousortD =3D 'OUupD'; + @sorted_ip =3D map { $_->[1] } sort { $b->[0] <=3D> $a->[0] } map { [ $tr= affic{$_}{'dayoutput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INup') { + $sortarrowin .=3D '▲'; + $insort =3D 'INdown'; + @sorted_ip =3D map { $_->[1] } sort { $a->[0] <=3D> $b->[0] } map { [ $tr= affic{$_}{'allinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INdown') { + $sortarrowin .=3D '▼'; + $insort =3D 'INup'; + @sorted_ip =3D map { $_->[1] } sort { $b->[0] <=3D> $a->[0] } map { [ $tr= affic{$_}{'allinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INupM') { + $sortarrowinM .=3D '▲'; + $insortM =3D 'INdownM'; + @sorted_ip =3D map { $_->[1] } sort { $a->[0] <=3D> $b->[0] } map { [ $tr= affic{$_}{'monthinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INdownM') { + $sortarrowinM .=3D '▼'; + $insortM =3D 'INupM'; + @sorted_ip =3D map { $_->[1] } sort { $b->[0] <=3D> $a->[0] } map { [ $tr= affic{$_}{'monthinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INupW') { + $sortarrowinW .=3D '▲'; + $insortW =3D 'INdownW'; + @sorted_ip =3D map { $_->[1] } sort { $a->[0] <=3D> $b->[0] } map { [ $tr= affic{$_}{'weekinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INdownW') { + $sortarrowinW .=3D '▼'; + $insortW =3D 'INupW'; + @sorted_ip =3D map { $_->[1] } sort { $b->[0] <=3D> $a->[0] } map { [ $tr= affic{$_}{'weekinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INupD') { + $sortarrowinD .=3D '▲'; + $insortD =3D 'INdownD'; + @sorted_ip =3D map { $_->[1] } sort { $a->[0] <=3D> $b->[0] } map { [ $tr= affic{$_}{'dayinput'}, $_ ] } keys %traffic; + last SWITCH; + } + if ($sort eq 'INdownD') { + $sortarrowinD .=3D '▼'; + $insortD =3D 'INupD'; + @sorted_ip =3D map { $_->[1] } sort { $b->[0] <=3D> $a->[0] } map { [ $tr= affic{$_}{'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'} = =3D 0; } + if ( !defined ( $traffic{$ip}{'alloutput'})) { $traffic{$ip}{'alloutput'}= =3D 0; } + if ( !defined ( $traffic{$ip}{'monthinput'})) { $traffic{$ip}{'monthinput= '} =3D 0; } + if ( !defined ( $traffic{$ip}{'monthoutput'})) { $traffic{$ip}{'monthoutp= ut'} =3D 0; } + if ( !defined ( $traffic{$ip}{'weekinput'})) { $traffic{$ip}{'weekinput'}= =3D 0; } + if ( !defined ( $traffic{$ip}{'weekoutput'})) { $traffic{$ip}{'weekoutput= '} =3D 0; } + if ( !defined ( $traffic{$ip}{'dayinput'})) { $traffic{$ip}{'dayinput'} = =3D 0; } + if ( !defined ( $traffic{$ip}{'dayoutput'})) { $traffic{$ip}{'dayoutput'}= =3D 0; } + + $sum_incoming_all +=3D $traffic{$ip}{'allinput'}; + $sum_outgoing_all +=3D $traffic{$ip}{'alloutput'}; + $sum_incoming_month +=3D $traffic{$ip}{'monthinput'}; + $sum_outgoing_month +=3D $traffic{$ip}{'monthoutput'}; + $sum_incoming_week +=3D $traffic{$ip}{'weekinput'}; + $sum_outgoing_week +=3D $traffic{$ip}{'weekoutput'}; + $sum_incoming_day +=3D $traffic{$ip}{'dayinput'}; + $sum_outgoing_day +=3D $traffic{$ip}{'dayoutput'}; + + my $netColor =3D getNetworkColor($ip); + my $hostname =3D defined ($traffic{$ip}{'hostname'}) ? $traffic{$ip}{'hos= tname'} : ' '; + + print " + + + + + + + + + + + + + + + + + "; + } + print " + + + + + + + + + + + + +
#$Lang::tr{'network'}$Lang::tr{'ip address'}".($sortarrowip eq '&nb= sp;' ? '' : $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."3D'$netColo=$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{'IPTraff= ic_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 =3D `/sbin/ip neigh list`; + my @clientlist =3D getIPfromTable(); + my $count =3D 0; + + foreach my $line (split(/\n/, $output)){ + if ($line =3D~ m/^(.*) dev ([^ ]+) lladdr ([0-9a-f:]*) (.*)$/ || $line =3D= ~ m/^(.*) dev ([^ ]+) (.*)$/) { + my $hostname =3D gethostbyaddr(inet_aton($1), AF_INET); + $arpcache{$1} =3D $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 =3D split (/\,/, $arpcache{$key}); + my $netname =3D (split(/-/,$line[0]))[0]; + chop $netname; + next if ($netname eq 'red'); + chomp $line[1]; + print" + + + + + + "; + } + + print" +
$Lang::tr{'network'}$Lang::tr{'ip address'}= $Lang::tr{'hostname'}$Lang::tr{'action'}<= /td> +
3D'$line[0]'=$key$line[1]"; + if (grep /^$key$/, @clientlist){ + print " + 3D'$Lang::tr{'IPTraffic_no_add'}="; + } + else { + print " +
+ + + + +
"; + } + print " +
+
+ +"; + + &Header::closebox(); +} + +sub calcTraffic { + my $value =3D shift; + my @unit =3D ('', 'K', 'M', 'G', 'T', 'P'); + my $i =3D 0; + + while ($value > 1000){ + $value =3D sprintf ( "%.1f", $value/1024); + $i++; + } + return ($value < 0 ? "0" : $value+0 )." $unit[$i]B"; +} + +sub setClientAction { + my $client =3D shift; + my $action =3D shift; + my $host =3D shift; + + my $sql =3D ''; + if ($action eq 'ADD'){ + if (defined $host){ + $sql =3D "INSERT INTO '".$IPTrafficTable."' (`client`, `hostname`, `date`= ) VALUES ( '".$client."', '".$host."', date('now'));"; + } + else { + $sql =3D "INSERT INTO '".$IPTrafficTable."' (`client`, `date`) VALUES ( '= ".$client."', date('now'));"; + } + } + + if ($action eq 'DEL'){ + $sql =3D "UPDATE '".$IPTrafficTable."' SET `traflimit` =3D 'DEL' WHERE `cl= ient` =3D '".$client."';"; + } + my $dbh =3D DBI->connect("dbi:SQLite:dbname=3D$iptrafficdb", "", "", {Raise= Error =3D> 1, AutoCommit=3D>1}); + my $Action=3D $dbh->prepare($sql); + $Action->execute(); + $Action->finish(); +} + +## get network color +sub getNetworkColor { + my $ipaddress =3D shift; + my %devs_color =3D ('GREEN' =3D> 'green', 'BLUE' =3D> 'blue', 'ORANGE' =3D>= 'orange', 'RED' =3D> 'red', 'GRAY' =3D> '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"}, $n= etsettings{$color."_NETMASK"}) ) { + return substr($netsettings{$color."_DEV"}, 0, -1); + } + } + } + return 'gray'; +} +sub getHostnameFromTable { + my $client =3D shift; + my ($host, $sql); + my $dbh =3D DBI->connect("dbi:SQLite:dbname=3D/var/log/iptraffic/iptraffic.= db", "", "", {RaiseError =3D> 1}); + $sql =3D "SELECT DISTINCT `hostname` FROM `".$IPTrafficTable."` WHERE `clie= nt` =3D '".$client."';"; + my $Statement =3D $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 =3D ''; + my ($client, $traflimit, $sql); + my $dbh =3D DBI->connect("dbi:SQLite:dbname=3D/var/log/iptraffic/iptraffic.= db", "", "", {RaiseError =3D> 1}); + $sql =3D "SELECT DISTINCT `client`, `traflimit` FROM `".$IPTrafficTable."` = WHERE `date` =3D date('now');"; + my $Statement =3D $dbh->prepare($sql); + $Statement->execute; + $Statement->bind_columns(\$client, \$traflimit); + while($Statement->fetch()){ + $client =3D 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 =3D getIPfromTable(); + my ($client, $hostname, $date, $input, $output, $dayinput, $dayoutput, $wee= kinput, $weekoutput, $monthinput, $monthoutput, $traflimit, $port); + + my $dbh =3D DBI->connect("dbi:SQLite:dbname=3D/var/log/iptraffic/iptraffic.= db", "", "", {RaiseError =3D> 1}); + my $sql =3D ''; + my $Statement =3D $dbh->prepare($sql); + foreach $client ( @iplist) { + $client =3D trim($client); + if (length($client) > 0){ + $sql =3D "SELECT `hostname`, sum(`input`), sum(`output`), "; + $sql.=3D "(SELECT sum(input) from '".$IPTrafficTable."' WHERE `client` = =3D '".$client."' AND `date` =3D date('now')) as `dayinput`, "; + $sql.=3D "(SELECT sum(output) from '".$IPTrafficTable."' WHERE `client` = =3D '".$client."' AND `date` =3D date('now')) as `dayoutput`, "; + $sql.=3D "(SELECT sum(input) from '".$IPTrafficTable."' WHERE `client` = =3D '".$client."' AND `date` BETWEEN date('now', 'weekday 1', '-7 day') AND d= ate('now')) as `weekinput`, "; + $sql.=3D "(SELECT sum(output) from '".$IPTrafficTable."' WHERE `client` = =3D '".$client."' AND `date` BETWEEN date('now', 'weekday 1', '-7 day') AND d= ate('now')) as `weekoutput`, "; + $sql.=3D "(SELECT sum(input) from '".$IPTrafficTable."' WHERE `client` = =3D '".$client."' AND `date` BETWEEN date('now', 'start of month') AND date('= now')) as `monthinput`, "; + $sql.=3D "(SELECT sum(output) from '".$IPTrafficTable."' WHERE `client` = =3D '".$client."' AND `date` BETWEEN date('now', 'start of month') AND date('= now')) as `monthoutput`, "; + $sql.=3D "`traflimit`, `port` from '".$IPTrafficTable."' WHERE `client` = =3D '".$client."';"; + $Statement =3D $dbh->prepare($sql); + $Statement->execute; + $Statement->bind_columns(\$hostname, \$input, \$output, \$dayinput, \$day= output, \$weekinput, \$weekoutput, \$monthinput, \$monthoutput, \$traflimit, = \$port); + while($Statement->fetch()) { + $traffic{$client} =3D {'hostname' =3D> $hostname, 'allinput' =3D> $input= , 'alloutput' =3D> $output, 'dayinput' =3D> $dayinput, 'dayoutput' =3D> $dayo= utput, 'weekinput' =3D> $weekinput, 'weekoutput' =3D> $weekoutput, 'monthinpu= t' =3D> $monthinput, 'monthoutput' =3D> $monthoutput, 'limit' =3D> $traflimit= , 'port' =3D> $port}; + } + } + } + $Statement->finish(); + $dbh->disconnect() or warn $dbh->errstr; + + return %traffic; +} + +sub trim() { + my $str =3D shift; + if (defined $str) {$str =3D~ 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 =3D 'v0.8'; +my $gruppe =3D getgrnam("nobody"); +my $user =3D getpwnam("nobody"); +my $FW =3D '/sbin/iptables'; +my $logdir =3D "/var/log/iptraffic"; +my $iptrafficdb =3D "$logdir/iptraffic.db"; +my $IPTrafficTable =3D "IPTraffic"; +my $rrdimgdir =3D "/srv/web/ipfire/html/graphs/iptraffic"; +my $rrddir =3D "/var/log/rrd/iptraffic"; +my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $J= ahrestag, $Sommerzeit) =3D localtime(time); +my $heute =3D sprintf("%4d%02d%02d", $Jahr+1900, ++$Monat, $Monatstag); +($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahr= estag, $Sommerzeit) =3D localtime(time - 86400); +my $gestern =3D sprintf("%4d%02d%02d", $Jahr+1900, ++$Monat, $Monatstag); + +foreach (@ARGV) { + if ( $_ eq '-d' || $_ eq '--debug') { $debug =3D 1; } + if ( $_ eq '-h' || $_ eq '--help' ) { print help(); exit 1; } +} + +# read from iptables +my $a_output =3D `$FW -nvx -L CUSTOMOUTPUT`; +my $a_forward =3D `$FW -nvx -L CUSTOMFORWARD`; +my $a_input =3D `$FW -nvx -L CUSTOMINPUT`; + +if ($debug =3D=3D 1){ print "Eintr=C3=A4ge in iptables:\n" } + +# extract Traffic from iptables +my %output =3D extractTraffic($a_output); +my %forward =3D extractTraffic($a_forward); +my %input =3D extractTraffic($a_input); + +if ($debug =3D=3D 1){ startdebug(); } + +# create/check Table in DB +my $dbh =3D DBI->connect("dbi:SQLite:dbname=3D$iptrafficdb", "", "", {RaiseE= rror =3D> 1}); +my $sql =3D "CREATE TABLE IF NOT EXISTS '".$IPTrafficTable."'(client VARCHAR= (16), hostname VARCHAR(25) default NULL, date INT UNSIGNED, input INT UNSIGNE= D, output INT UNSIGNED, traflimit INT UNSIGNED, port INT UNSIGNED);"; +my $Statement =3D $dbh->prepare($sql); +$Statement->execute(); +$Statement->finish(); + +my @iptclients =3D getIPTrafficClientlist(); + +foreach (sort @iptclients){ + chomp; + my ($clientIP, $hostname, $tmpdate) =3D ''; + my ($date, $clientoutput, $clientinput, $traflimit, $clientinputsum, $clien= toutputsum) =3D 0; + my @buffer =3D (); + my %dbTraffic; + ($clientIP, $hostname, $date, $clientinput, $clientoutput, $traflimit) =3D = split( /,/, $_ ); + + if (trim($traflimit) eq 'DEL') { + clientDelete($clientIP); + if ($debug =3D=3D 1){print "Client $clientIP deleted \n";} + next; + } + + ($tmpdate =3D $date) =3D~ s/-//g; + if ($tmpdate < $heute) {next;}; + + # not Line in iptables: create item and set starttraffic =3D 0 + unless (exists($output{$clientIP})) { `$FW -A CUSTOMOUTPUT -d $clientIP -j = RETURN`; $output{$clientIP}{'destination'} =3D 0;} + unless (exists($forward{$clientIP})) { + `$FW -A CUSTOMFORWARD -d $clientIP -j RETURN`; $forward{$clientIP}{'destin= ation'} =3D 0; + `$FW -A CUSTOMFORWARD -s $clientIP -j RETURN`; $forward{$clientIP}{'source= '} =3D 0; + } + unless (exists($input{$clientIP})) { `$FW -A CUSTOMINPUT -s $clientIP -j RE= TURN`; $input{$clientIP}{'source'} =3D 0;} + +# %dbTraffic =3D getNowIPTrafficFromTable($clientIP); +# $clientinputsum =3D $input{$clientIP}{'destination'}+$forward{$clientIP}{'= destination'} + (($clientinputsum < $dbTraffic{'dayinput'}) ? $dbTraffic{'day= input'} : 0); +# $clientoutputsum =3D $output{$clientIP}{'source'}+$forward{$clientIP}{'sou= rce'} + (($clientoutputsum < $dbTraffic{'dayoutput'}) ? $dbTraffic{'dayoutput= '} : 0); + + $clientoutputsum =3D $input{$clientIP}{'source'} + $forward{$clientIP}{'sou= rce'}; + $clientinputsum =3D $output{$clientIP}{'destination'} + $forward{$clientIP}= {'destination'}; + + if ($debug =3D=3D 1){ + printf ("%15s%15s%15s%15s%15s%15s%15s\n", $clientIP, $output{$clientIP}{'d= estination'}, $input{$clientIP}{'source'}, $forward{$clientIP}{'destination'}= , $forward{$clientIP}{'source'}, $clientinputsum, $clientoutputsum); + } + updateTrafficCount($clientIP, $hostname, $heute, $clientinputsum, $clientou= tputsum, $traflimit); + updateiptrafficdata($clientIP, $clientinputsum, $clientoutputsum); + + $hostname =3D ($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 =3D ''; + my ($date, $output, $input, $traflimit, $port, $trafficReset) =3D 0; + my $clientIPfirst =3D ''; + my @clientlist =3D ''; + + my $sql =3D "SELECT * FROM '".$IPTrafficTable."' WHERE date =3D date('now')= OR date =3D date('now', '-1 day') ORDER by date DESC;"; + $Statement =3D $dbh->prepare($sql); + $Statement->bind_columns(\$clientIP, \$hostname, \$date, \$input, \$output,= \$traflimit, \$port); + $Statement->execute(); + while( $Statement->fetch()){ + my $sql =3D "SELECT COUNT(*) FROM `".$IPTrafficTable."` WHERE `client` =3D= '".$clientIP."' AND `date` =3D date('now');"; + my $cStatement =3D $dbh->prepare($sql); + $cStatement->execute; + my $count =3D $cStatement->fetchrow; + $cStatement->finish(); + + unless ( $count > 0){ + $sql =3D "INSERT INTO '".$IPTrafficTable."' (`client`, `hostname`, `date`= , `input`, `output`, `traflimit`) VALUES ( '".$clientIP."', '".$hostname."', = date('now'), '".$input."', '".$output."', '".$traflimit."');"; + my $Insert=3D $dbh->prepare($sql); + $Insert->execute(); + $Insert->finish(); + $trafficReset =3D 1; + } + push (@clientlist, "$clientIP, $hostname, $date, $input, $output, $traflim= it \n"); + } + $Statement->finish(); + + # daily reset count traffic + if ( $trafficReset =3D=3D 1) { + my $reset; + $reset =3D `$FW -Z CUSTOMFORWARD`; + $reset =3D `$FW -Z CUSTOMOUTPUT`; + $reset =3D `$FW -Z CUSTOMINPUT`; + } + return @clientlist; +} + +sub getNowIPTrafficFromTable { + my $client =3D shift; + my %traffic; + my ($input, $output, $sql, $Statement); + + if (defined ($client)){ + $sql =3D "SELECT `input`, `output` from '".$IPTrafficTable."' WHERE `clien= t` =3D '".$client."' AND `date` =3D date('now');"; + $Statement =3D $dbh->prepare($sql); + $Statement->execute; + $Statement->bind_columns(\$input, \$output); + while($Statement->fetch()) { + $traffic{ 'dayinput' } =3D $input; + $traffic{ 'dayoutput' } =3D $output ; + } + } + $Statement->finish(); + + return %traffic; +} + +sub updateTrafficCount { + my $client =3D shift; + my $hostname =3D shift; + my $date =3D shift; + my $input =3D shift; + my $output =3D shift; + my $traflimit =3D shift; + + $hostname =3D (length($hostname) <=3D 2) ? gethostbyaddr(inet_aton($client)= , AF_INET) : $hostname; + + my $sql =3D "UPDATE '".$IPTrafficTable."' SET `client` =3D '".$client."', `= hostname` =3D '".trim($hostname)."', `input` =3D '".$input."', `output` =3D '= ".$output."', `traflimit` =3D '".trim($traflimit)."' WHERE `client` =3D '".$c= lient."' AND `date` =3D date('now');"; + my $Update =3D $dbh->prepare($sql); + $Update->execute(); + $Update->finish(); +} + +sub updateiptrafficdata { + my $ip =3D $_[0]; + my $incoming =3D int($_[1]/8); + my $outgoing =3D int($_[2]/8); + + if ( !-e "$rrddir/$ip.rrd" ) { + RRDs::create( + "$rrddir/$ip.rrd", "--step=3D60", + "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 =3D RRDs::error; + print "Error in RRD::create for IP-Traffic: $ERROR\n" if $ERROR; + } + + RRDs::update("$rrddir/$ip.rrd", "-t", "incoming:outgoing", "N:$incoming:$ou= tgoing"); + + my $error =3D RRDs::error; + if ($error) { &General::log("iptraffic","$error"); } +} + +sub updateiptrafficgraph { + my $ip =3D $_[0]; + my $client =3D $_[1]; + my $period =3D $_[2]; + chomp($client); + + if (length($client) < 2) {$client =3D $ip;} + my $comment =3D sprintf("%-40s%-20s%-30s%-25s%-25s\\j", $Lang::tr{'caption'= }, $Lang::tr{'maximal'}, $Lang::tr{'average'}, $Lang::tr{'minimal'}, $Lang::t= r{'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=3D$rrddir/$ip.rrd:incoming:AVERAGE", + "DEF:outgoing=3D$rrddir/$ip.rrd:outgoing:AVERAGE", + "CDEF:incomingbits=3Dincoming,8,*", + "CDEF:outgoingbits=3Doutgoing,8,*", + "CDEF:outgoingnegbits=3Doutgoing,-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 =3D RRDs::error; + print "Error in RRD::create for IP-Traffic: $ERROR\n" if $ERROR; + + my $error =3D RRDs::error; + + if ($error) { &General::log("iptraffic","$error"); } +} + +sub rrd_lastupdate { + my $result =3D []; + + push @$result, "COMMENT: \\r"; + push @$result, "COMMENT:IPTr= affic 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 =3D shift; + return undef if not defined $text; + $text =3D~ s/\\/\\\\/g; + $text =3D~ s/:/\\:/g; + return $text; +} + +sub clientDelete { + my $client =3D shift; + my @ok =3D (); + # remove client item from iptables + $ok[0] =3D `$FW -D CUSTOMOUTPUT -d $client -j RETURN`; + $ok[1] =3D `$FW -D CUSTOMINPUT -s $client -j RETURN`; + $ok[2] =3D `$FW -D CUSTOMFORWARD -d $client -j RETURN`; + $ok[3] =3D `$FW -D CUSTOMFORWARD -s $client -j RETURN`; + + # remove client graphs + my @removefiles =3D ("$rrdimgdir/$client-hour.png", "$rrdimgdir/$client-day= .png", "$rrdimgdir/$client-week.png", "$rrdimgdir/$client-month.png", "$rrdim= gdir/$client-year.png"); + $ok[4] =3D unlink (@removefiles); + + # remove client rrd-file + $ok[5] =3D unlink ("$rrddir/$client.rrd"); + + # remove client from database + my $sql =3D "DELETE FROM `".$IPTrafficTable."` WHERE `client` =3D '".$clien= t."';"; + my $Delete =3D $dbh->prepare($sql); + $Delete->execute(); + $Delete->finish(); +} + +sub extractTraffic { + my $page =3D shift; + my %clientHash; + my @buffer; + my @line =3D split('\n',$page); + + foreach (sort @line){ + chomp; + @buffer =3D split(/\s+/, trim($_)); + if ($buffer[0] eq 'pkts' || $buffer[0] eq 'Chain') {next;}; + if ($debug =3D=3D 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'} = =3D $buffer[1];} + if ($buffer[8] eq '0.0.0.0/0') {$clientHash{"$buffer[7]"}{'source'} =3D $b= uffer[1];} + } + return %clientHash; +} + +sub trim { + my $str =3D shift; + $str =3D~ 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 =3D 0.8.2 + +THISAPP =3D iptraffic-$(VER) +DIR_APP =3D $(DIR_SRC)/$(THISAPP) +TARGET =3D $(DIR_INFO)/$(THISAPP) +PROG =3D iptraffic +PAK_VER =3D 1 + +DEPS =3D "" + +############################################################################= ### +# Top-level Rules +############################################################################= ### + +install : $(TARGET) + +check :=20 + +download : + +md5 :=20 + +dist:=20 + $(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 } =20 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 --=20 2.18.0 --===============0389756515894624070==--