diff --git a/docker-compose.yml b/docker-compose.yml
index 3f456de..b37a2c2 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,6 +3,8 @@ version: '3.9'
services:
nginx:
build: https://github.com/specify/nginx-with-github-auth.git#main
+ # build:
+ # context: ~/nginx-with-github-auth
ports:
- '80:80'
- '443:443'
@@ -10,8 +12,8 @@ services:
- './sp7-stats/config/auth.conf:/etc/nginx/auth.conf:ro'
- './sp7-stats/config/nginx.conf:/etc/nginx/conf.d/default.conf:ro'
- './sp7-stats/:/var/www/:ro'
- - './sp7-stats/config/fullchain.pem:/etc/letsencrypt/live/sp7-stats/fullchain.pem:ro'
- - './sp7-stats/config/privkey.pem:/etc/letsencrypt/live/sp7-stats/privkey.pem:ro'
+ - '/etc/letsencrypt:/etc/letsencrypt:ro'
+ - './access-logs/:/var/log/nginx/external/:rw'
networks:
- nginx
depends_on:
@@ -33,6 +35,20 @@ services:
networks:
- nginx
+ certbot:
+ image: certbot/certbot
+ container_name: certbot
+ volumes:
+ - '/etc/letsencrypt:/etc/letsencrypt'
+ - './sp7-stats/:/var/www/certbot/'
+ - '/var/run/docker.sock:/var/run/docker.sock'
+ entrypoint: >
+ sh -c "trap exit TERM; while :; do certbot renew --webroot -w /var/www/certbot --deploy-hook 'docker exec sp7-stats-nginx-1 nginx -s reload'; sleep 12h; done"
+ networks:
+ - nginx
+ depends_on:
+ - nginx
+
networks:
nginx:
diff --git a/sp7-stats/components/institutions.php b/sp7-stats/components/institutions.php
index c7ca017..6246eda 100644
--- a/sp7-stats/components/institutions.php
+++ b/sp7-stats/components/institutions.php
@@ -74,7 +74,8 @@ function compile_institutions($lines_data, $file_name){
$institution = $line_data['institution'];
$discipline = $line_data['discipline'];
$collection = $line_data['collection'];
- $isa_number = $line_data['isaNumber'];
+ // $isa_number = $line_data['isaNumber'];
+ $isa_number = $line_data['isaNumber'] ?? '';
$browser = $line_data['browser'];
$domain = $line_data['domain'];
$os = $line_data['os'];
@@ -293,4 +294,4 @@ function sort_months($x,$y){
file_put_contents(WORKING_LOCATION.'institutions_id.json',json_encode($institutions4));
file_put_contents(WORKING_LOCATION.'institutions.json',json_encode($institutions3));
-}
\ No newline at end of file
+}
diff --git a/sp7-stats/config/nginx.conf b/sp7-stats/config/nginx.conf
index 6ac09fa..d43820e 100644
--- a/sp7-stats/config/nginx.conf
+++ b/sp7-stats/config/nginx.conf
@@ -1,39 +1,81 @@
+# Outbound DNS for Lua http requests
+# resolver 1.1.1.1 8.8.8.8 valid=300s;
+# resolver_timeout 5s;
+
+# Trust store path on Alpine (nginx:alpine puts the bundle here)
+# lua_ssl_trusted_certificate /etc/ssl/cert.pem;
+# lua_ssl_verify_depth 5;
+
# See https://github.com/specify/nginx-with-github-auth
include nginx-with-github-auth/http.conf;
-# Redirect HTTP to HTTPs
+# --- HTTP (port 80) ---
server {
- listen 80 default_server;
- server_name _;
- return 301 https://$host$request_uri;
+ listen 80 default_server;
+ listen [::]:80 default_server;
+
+ server_name stats.specifycloud.org sp7-stats.specifycloud.org;
+
+ # Serve ACME challenge over HTTP without redirect
+ location ^~ /.well-known/acme-challenge/ {
+ root /var/www/;
+ try_files $uri =404;
+ }
+
+ # Everything else: redirect to HTTPS
+ location / {
+ return 301 https://$host$request_uri;
+ }
}
+# --- HTTPS (port 443) ---
server {
- listen 443 ssl default_server;
+ listen 443 ssl default_server;
+ listen [::]:443 ssl default_server;
+
+ server_name stats.specifycloud.org sp7-stats.specifycloud.org;
+
+ # Use the certbot-standard live path for THIS domain name
+ ssl_certificate /etc/letsencrypt/live/sp7-stats.specifycloud.org/fullchain.pem;
+ ssl_certificate_key /etc/letsencrypt/live/sp7-stats.specifycloud.org/privkey.pem;
+
+ ssl_session_cache shared:SSL:10m;
+ ssl_session_timeout 5m;
+ ssl_prefer_server_ciphers on;
+
+ include auth.conf;
+ include nginx-with-github-auth/server.conf;
- ssl_certificate /etc/letsencrypt/live/sp7-stats/fullchain.pem;
- ssl_certificate_key /etc/letsencrypt/live/sp7-stats/privkey.pem;
- ssl_session_cache shared:SSL:10m;
- ssl_session_timeout 5m;
- ssl_prefer_server_ciphers on;
+ index index.php index.html;
+ keepalive_timeout 70;
+ error_log /var/log/nginx/error.log;
+ access_log /var/log/nginx/access.log;
+ root /var/www/;
- include auth.conf;
- include nginx-with-github-auth/server.conf;
+ access_log /var/log/nginx/external/access.log combined;
- index index.php index.html;
- server_name sp7-stats;
- keepalive_timeout 70;
- error_log /var/log/nginx/error.log;
- access_log /var/log/nginx/access.log;
- root /var/www/;
+ location = /capture {
+ # Allow browser JS to call this cross-origin
+ add_header 'Access-Control-Allow-Origin' '*' always;
+ add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
+ add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
+ add_header 'Access-Control-Max-Age' 86400 always;
- location ~ ^/.+\.php$ {
- include nginx-with-github-auth/location.conf;
+ # Handle preflight (some browsers/frameworks trigger this)
+ if ($request_method = OPTIONS) {
+ return 204;
+ }
- include fastcgi_params;
- fastcgi_pass php:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
- }
+ access_log /var/log/nginx/external/access.log combined;
+ add_header Content-Type text/plain;
+ return 204;
+ }
+ location ~ ^/.+\.php$ {
+ include nginx-with-github-auth/location.conf;
+ include fastcgi_params;
+ fastcgi_pass php:9000;
+ fastcgi_index index.php;
+ fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
+ }
}
diff --git a/sp7-stats/cron/refresh_data.php b/sp7-stats/cron/refresh_data.php
index 6dca7c8..732374e 100644
--- a/sp7-stats/cron/refresh_data.php
+++ b/sp7-stats/cron/refresh_data.php
@@ -5,4 +5,5 @@
global $no_gui;
$no_gui = TRUE;
-require_once('../refresh_data/index.php');
\ No newline at end of file
+//require_once('../refresh_data/index.php');
+require_once __DIR__ . '/../refresh_data/index.php';
diff --git a/sp7-stats/index.php b/sp7-stats/index.php
index 385139c..3a0f978 100644
--- a/sp7-stats/index.php
+++ b/sp7-stats/index.php
@@ -8,28 +8,28 @@
$files = array_reverse($files);
if(array_key_exists('file_1',$_GET) && file_exists($target_dir.$_GET['file_1'].$target_extension) && strlen($_GET['file_1'])===5 && is_numeric($_GET['file_1']))
- $first_day = intval($_GET['file_1']);
+ $first_day = intval($_GET['file_1']);
else
- $first_day = FALSE;
+ $first_day = FALSE;
if(array_key_exists('file_2',$_GET) && file_exists($target_dir.$_GET['file_2'].$target_extension) && strlen($_GET['file_2'])===5 && is_numeric($_GET['file_2']))
- $last_day = intval($_GET['file_2']);
+ $last_day = intval($_GET['file_2']);
else
- $last_day = FALSE;
+ $last_day = FALSE;
if(array_key_exists('date',$_GET)){
- $_GET['date'] = urldecode($_GET['date']);
+ $_GET['date'] = urldecode($_GET['date']);
- $date_info = date_parse_from_format(YEAR_FORMATTER.' '.MONTH_FORMATTER.' '.DAY_FORMATTER,$_GET['date']);
+ $date_info = date_parse_from_format(YEAR_FORMATTER.' '.MONTH_FORMATTER.' '.DAY_FORMATTER,$_GET['date']);
- if(strlen($date_info['month'])==1)
- $date_info['month'] = '0'.$date_info['month'];
+ if(strlen($date_info['month'])==1)
+ $date_info['month'] = '0'.$date_info['month'];
- if(strlen($date_info['day'])==1)
- $date_info['day'] = '0'.$date_info['day'];
+ if(strlen($date_info['day'])==1)
+ $date_info['day'] = '0'.$date_info['day'];
- $unix_time = strtotime($date_info['month'].'/'.$date_info['day'].'/'.$date_info['year']);
- $first_day = $last_day = intval($unix_time/86400);
+ $unix_time = strtotime($date_info['month'].'/'.$date_info['day'].'/'.$date_info['year']);
+ $first_day = $last_day = intval($unix_time/86400);
}
@@ -41,122 +41,122 @@
$times = 0;
if(array_key_exists('hide',$_GET) && is_numeric($_GET['hide']) && $_GET['hide']>0)
- $times = intval($_GET['hide']);
+ $times = intval($_GET['hide']);
foreach($files as $file){
- $unix_time = explode('/', $file);
- $unix_time = end($unix_time);
- $unix_time = explode('.', $unix_time);
- $unix_time = intval($unix_time[0]);
+ $unix_time = explode('/', $file);
+ $unix_time = end($unix_time);
+ $unix_time = explode('.', $unix_time);
+ $unix_time = intval($unix_time[0]);
- $selected_1_append = '';
- $selected_2_append = '';
+ $selected_1_append = '';
+ $selected_2_append = '';
- if(!$first_unix_begin)
- $first_unix_begin = $unix_time;
+ if(!$first_unix_begin)
+ $first_unix_begin = $unix_time;
- if(!$first_day)
- $first_day = $unix_time;
+ if(!$first_day)
+ $first_day = $unix_time;
- if(!$last_day)
- $last_day = $unix_time;
+ if(!$last_day)
+ $last_day = $unix_time;
- if($first_day>$last_day)
- [$first_day,$last_day] = [$last_day,$first_day];
+ if($first_day>$last_day)
+ [$first_day,$last_day] = [$last_day,$first_day];
- if($unix_time == $first_day)
- $selected_1_append = 'selected';
+ if($unix_time == $first_day)
+ $selected_1_append = 'selected';
- if($unix_time == $last_day)
- $selected_2_append = 'selected';
+ if($unix_time == $last_day)
+ $selected_2_append = 'selected';
- if($unix_time >= $first_day && $unix_time <= $last_day){
+ if($unix_time >= $first_day && $unix_time <= $last_day){
- $data = json_decode(file_get_contents($file),TRUE);
- $institutions = array_merge_recursive($institutions,$data);
+ $data = json_decode(file_get_contents($file),TRUE);
+ $institutions = array_merge_recursive($institutions,$data);
- }
+ }
- $human_time = unix_days_to_human_time($unix_time);
+ $human_time = unix_days_to_human_time($unix_time);
- $result_1 .= '';
- $result_2 .= '';
+ $result_1 .= '';
+ $result_2 .= '';
}
foreach($institutions as $institution_name => &$disciplines){
- foreach($disciplines as $discipline_name => &$collections){
+ foreach($disciplines as $discipline_name => &$collections){
- foreach($collections as $collection_name => &$collection){
+ foreach($collections as $collection_name => &$collection){
- if(is_array($collection['count']))//fix array_merge_recursive creating an array out of 'count'
- $collection['count'] = array_sum($collection['count']);
+ if(is_array($collection['count']))//fix array_merge_recursive creating an array out of 'count'
+ $collection['count'] = array_sum($collection['count']);
- if($collection['count']<$times){
- unset($collections[$collection_name]);
- continue;
- }
+ if($collection['count']<$times){
+ unset($collections[$collection_name]);
+ continue;
+ }
- $cols = ['sp7_version','sp6_version','isa_number','ip_address','browser','os','domain'];
- foreach($cols as $col)
- $collection[$col] = array_unique($collection[$col]);
+ $cols = ['sp7_version','sp6_version','isa_number','ip_address','browser','os','domain'];
+ foreach($cols as $col)
+ $collection[$col] = array_unique($collection[$col]);
- }
+ }
- if(count($collections)==0)
- unset($disciplines[$discipline_name]);
+ if(count($collections)==0)
+ unset($disciplines[$discipline_name]);
- }
+ }
- if(count($disciplines)==0)
- unset($institutions[$institution_name]);
+ if(count($disciplines)==0)
+ unset($institutions[$institution_name]);
} ?>
Show results from
till
-
+
| Institution | -Discipline | -Collection | -Property | -Value | -
|---|---|---|---|---|
| Institution | +Discipline | +Collection | +Property | +Value | +',$cell_count-$last_cell).''; - $last_cell=0; - } + if($value=='') + return; - if($value=='') - return; + if($last_cell==0) + echo ' |
| ',$position-$last_cell-1).' | '.$value.' | '; - echo str_repeat('',$position-$last_cell-1).' | '.$value.' | '; + $last_cell = $position; - $last_cell = $position; + } - } + $institution_count = count($institutions); + $discipline_count = 0; + $collection_count = 0; + $report_count = 0; + foreach($institutions as $institution => $disciplines){ - $institution_count = count($institutions); - $discipline_count = 0; - $collection_count = 0; - $report_count = 0; - foreach($institutions as $institution => $disciplines){ + echo '