Skip to content

Commit

Permalink
Merge pull request #680 from wschidol/feature/statistics
Browse files Browse the repository at this point in the history
Introduce processing statistics
  • Loading branch information
Phencys authored May 21, 2024
2 parents 14beb66 + 7dd5354 commit c660413
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions Conformance-Frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<script src="./src/main-view.js"></script>
<script src="./src/tool-view.js"></script>
<script src="./src/about-view.js"></script>
<script src="./src/statistics-view.js"></script>
<script src="./src/faq-view.js"></script>
<script src="./main.js"></script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions Conformance-Frontend/src/get-access.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/usr/bin/egrep '(GET|POST) /Utils/Process_cli.php' /var/log/apache2/access.log
1 change: 1 addition & 0 deletions Conformance-Frontend/src/main-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function MainView() {
const locations = [
{ id: "home", text: "Validator", icon: "fa-solid fa-gears", view: ToolView },
{ id: "about", text: "About", icon: "fa-solid fa-info-circle", view: AboutView },
{ id: "statistics", text: "Statistics", icon: "fa-solid fa-bar-chart", view: StatisticsView },
{ id: "faq", text: "FAQ", icon: "fa-solid fa-question-circle", view: FaqView },
];

Expand Down
46 changes: 46 additions & 0 deletions Conformance-Frontend/src/statistics-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function StatisticsView() {
let instance = {};

let _state = {
markdown: null,
};

let _rootElementId;

async function loadMarkdown() {
_state.markdown = await Net.sendRequest({
method: "GET",
uri: "./static/statistics-page.php",
});
render();
}

function generateContent() {
if (!_state.markdown) return;
return Tools.markdownToHtml(_state.markdown);
}

function render(rootElementId) {
_rootElementId = rootElementId = rootElementId || _rootElementId;

let aboutView = UI.createElement({
id: rootElementId,
});

if (!_state.markdown) {
loadMarkdown();
return;
}

let content = generateContent();
aboutView.appendChild(content);

UI.replaceElement(_rootElementId, aboutView);
}

instance = {
render,
};

return instance;
}
43 changes: 43 additions & 0 deletions Conformance-Frontend/static/statistics-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

function entry($diff,$limit,$ip,&$table) {
if ($diff < $limit) {
$table[$ip] = isset($table[$ip]) ? $table[$ip]+1 : 1;
}
}

// hold accesses in the last week, month, or quarter, keyed by IP address
$ip_in_week = array();
$ip_in_month = array();
$ip_in_quarter = array();

$now = date_timestamp_get(date_create());

// parse the access log and get all lines referring to /Utils/Process_cli.php
$output = `sudo /var/www/html/Conformance-Frontend/src/get-access.sh`;

// now go through the log line by line, storing IP vs date
foreach(preg_split("/((\r?\n)|(\r\n?))/", $output) as $line) {
$ip = preg_replace("/^([^ ]*)\s.*$/", "$1", $line);
$date = preg_replace("/^.*(\[[^ ]+ [^ ]+\]).*$/","$1", $line); // [16/Jun/2023:10:22:36 +0000]
$timestamp = DateTime::createFromFormat(
'[d/M/Y:H:i:s O]',
$date,
new DateTimeZone('EST')
);

if ($timestamp !== false) {
$before = $now - $timestamp->getTimestamp();

define("SEC_IN_DAY",24*60*60);
entry($before,7*SEC_IN_DAY,$ip,$ip_in_week);
entry($before,31*SEC_IN_DAY,$ip,$ip_in_month);
entry($before,(31+31+30)*SEC_IN_DAY,$ip,$ip_in_quarter);
}
}

echo "<table><tr>accesses<th></th><th>per week</th><th>per month</th><th>per quarter</th></tr>";
echo "<tr><th>unique</th><td>",count($ip_in_week),"</td><td>",count($ip_in_month),"</td><td>",count($ip_in_quarter),"</td>";
echo "<tr><th>total</th><td>",array_sum($ip_in_week),"</td><td>",array_sum($ip_in_month),"</td><td>",array_sum($ip_in_quarter),"</td></table>";

?>
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ ENV DEBIAN_FRONTEND=noninteractive

EXPOSE 80

RUN apt-get update
RUN apt-get update -y
RUN apt -y install \
apache2 apache2-doc php php-dev php-xml php-curl php-xdebug libapache2-mod-php \
python2.7 \
openjdk-8-jdk ant \
sudo \
g++
RUN curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
RUN python2.7 get-pip.py
RUN pip2 install matplotlib
RUN update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

# let apache sudo this one specific script which filters the access logs
RUN echo >> /etc/sudoers "www-data ALL=NOPASSWD: /var/www/html/Conformance-Frontend/src/get-access.sh"

RUN rm /var/www/html/index.html
COPY --chown=www-data:www-data . /var/www/html/

COPY --chown=www-data:www-data ISOSegmentValidator /var/www/html/ISOSegmentValidator
RUN cd /var/www/html/ISOSegmentValidator/public/linux && make clean && make -j

COPY --chown=www-data:www-data Conformance-Frontend /var/www/html/Conformance-Frontend

CMD apachectl -D FOREGROUND

0 comments on commit c660413

Please sign in to comment.