Skip to content

Commit 4dd0405

Browse files
Merge pull request #38 from Disasters-Learning-Portal/test-password-protection
Test password protection
2 parents 4207a43 + 98fb0ae commit 4dd0405

5 files changed

Lines changed: 338 additions & 6 deletions

File tree

.github/workflows/preview.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ jobs:
2626
- run: pip install -r requirements.txt
2727
- run: quarto render --to html
2828

29+
- name: Verify auth script is present in rendered HTML
30+
run: |
31+
if grep -q "disasters_docs_auth" _site/index.html; then
32+
echo "✓ Authentication script found in rendered HTML"
33+
else
34+
echo "✗ ERROR: Authentication script not found in rendered HTML"
35+
exit 1
36+
fi
37+
38+
- name: Inject password into login page
39+
run: |
40+
# Replace {{SITE_PASSWORD}} with actual password from GitHub secret
41+
if [ -f "_site/password-protect.html" ]; then
42+
sed -i "s/{{SITE_PASSWORD}}/${{ secrets.SITE_PASSWORD }}/g" _site/password-protect.html
43+
echo "Password injected successfully"
44+
else
45+
echo "Warning: password-protect.html not found"
46+
fi
47+
env:
48+
SITE_PASSWORD: ${{ secrets.SITE_PASSWORD }}
49+
2950
- name: Deploy preview
3051
uses: rossjrw/pr-preview-action@v1
3152
with:

.github/workflows/quarto-publish.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ on:
22
push:
33
branches:
44
- main
5-
- addContent
65
workflow_dispatch:
76

87
permissions: write-all
@@ -30,6 +29,15 @@ jobs:
3029
- run: pip install -r requirements.txt
3130
- run: quarto render --to html
3231

32+
- name: Verify auth script is present in rendered HTML
33+
run: |
34+
if grep -q "disasters_docs_auth" _site/index.html; then
35+
echo "✓ Authentication script found in rendered HTML"
36+
else
37+
echo "✗ ERROR: Authentication script not found in rendered HTML"
38+
exit 1
39+
fi
40+
3341
- name: Inject password into login page
3442
run: |
3543
# Replace {{SITE_PASSWORD}} with actual password from GitHub secret

_quarto.yml

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,96 @@ format:
107107
toc-depth: 3
108108
include-in-header:
109109
- text: |
110-
<script src="auth-check.js"></script>
110+
<script>
111+
// Authentication check for all pages - inlined to ensure it's always present
112+
(function() {
113+
const SESSION_KEY = 'disasters_docs_auth';
114+
115+
// Get the base path for the current page
116+
function getBasePath() {
117+
let path = window.location.pathname;
118+
119+
// If path ends with / or is a directory, it's already the base
120+
if (path.endsWith('/')) {
121+
return path;
122+
}
123+
124+
// If path ends with .html, get the directory
125+
if (path.endsWith('.html')) {
126+
const lastSlash = path.lastIndexOf('/');
127+
return path.substring(0, lastSlash + 1);
128+
}
129+
130+
// Otherwise, assume it's a directory and add trailing slash
131+
return path + '/';
132+
}
133+
134+
function getLoginPage() {
135+
const basePath = getBasePath();
136+
return basePath + 'password-protect.html';
137+
}
138+
139+
function checkAuth() {
140+
// Skip authentication on localhost (for development)
141+
if (window.location.hostname === 'localhost' ||
142+
window.location.hostname === '127.0.0.1') {
143+
console.log('Running on localhost - skipping authentication');
144+
return;
145+
}
146+
147+
// Skip check if we're on the login page
148+
if (window.location.pathname.endsWith('password-protect.html') ||
149+
window.location.pathname.endsWith('login.html')) {
150+
return;
151+
}
152+
153+
const auth = localStorage.getItem(SESSION_KEY);
154+
155+
if (!auth) {
156+
// No authentication, redirect to login
157+
window.location.href = getLoginPage();
158+
return;
159+
}
160+
161+
try {
162+
const authData = JSON.parse(auth);
163+
const now = new Date().getTime();
164+
165+
if (authData.expires <= now || !authData.authenticated) {
166+
// Expired or invalid session
167+
localStorage.removeItem(SESSION_KEY);
168+
window.location.href = getLoginPage();
169+
return;
170+
}
171+
172+
// Valid session - allow page to load
173+
} catch (e) {
174+
// Invalid auth data
175+
localStorage.removeItem(SESSION_KEY);
176+
window.location.href = getLoginPage();
177+
}
178+
}
179+
180+
// Run check immediately
181+
checkAuth();
182+
183+
// Add logout functionality
184+
window.addEventListener('DOMContentLoaded', function() {
185+
// Add logout button to page if it doesn't exist
186+
const existingLogout = document.getElementById('logout-btn');
187+
if (!existingLogout) {
188+
const logoutBtn = document.createElement('button');
189+
logoutBtn.id = 'logout-btn';
190+
logoutBtn.textContent = 'Logout';
191+
logoutBtn.style.cssText = 'position: fixed; top: 10px; right: 10px; padding: 8px 16px; background: #e74c3c; color: white; border: none; border-radius: 5px; cursor: pointer; z-index: 9999; font-size: 14px;';
192+
logoutBtn.onclick = function() {
193+
localStorage.removeItem(SESSION_KEY);
194+
window.location.href = getLoginPage();
195+
};
196+
document.body.appendChild(logoutBtn);
197+
}
198+
});
199+
})();
200+
</script>
111201
filters:
112202
- quarto

_site/_quarto.yml

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
project:
2+
type: website
3+
resources:
4+
- password-protect.html
5+
- auth-check.js
6+
7+
website:
8+
page-navigation: true
9+
back-to-top-navigation: true
10+
title: "NASA Disasters Documentation"
11+
site-url: "https://us-ghg-center.github.io/ghgc-docs" #should I change these
12+
repo-url: https://github.com/us-ghg-center/ghgc-docs
13+
repo-actions: [edit, issue]
14+
15+
page-footer:
16+
right: "This page is built with [Quarto](https://quarto.org/)."
17+
left: "&copy; CC-By US GHG Center, 2022-2023" #how should I change this
18+
19+
sidebar:
20+
logo: "logo/disasters_logo.png"
21+
pinned: true
22+
align: center
23+
tools:
24+
# - icon: info-circle
25+
# href: https://www.earthdata.nasa.gov/esds/veda
26+
# text: "earthdata.nasa.gov/esds/veda"
27+
- icon: globe-americas
28+
href: https://disasters.openveda.cloud/
29+
text: "NASA Disasters Portal"
30+
- icon: github
31+
href: https://github.com/Disasters-Learning-Portal
32+
text: "Repository home"
33+
34+
style: "docked"
35+
search: true
36+
collapse-level: 1
37+
contents:
38+
- href: index.qmd
39+
text: Welcome
40+
- section: aws.qmd
41+
text: AWS
42+
contents:
43+
- AWS/AWS_SSO_Setup_Guide.qmd
44+
- AWS/AWS_SSO_Remote_Server.qmd
45+
- AWS/aws-mfa-setup.qmd
46+
- AWS/aws-s3-commands-guide.qmd
47+
- section: git-github-comprehensive-guide.qmd
48+
text: GitHub
49+
contents:
50+
- text: "The VEDA Project"
51+
href: GitHub/veda-preview.qmd
52+
- GitHub/setup.qmd
53+
- GitHub/commands.qmd
54+
- GitHub/resources.qmd
55+
- section: jupyterhub.qmd
56+
text: JupyterHub
57+
contents:
58+
- Jupyterhub/jupyterhub-training-guide.qmd
59+
- Jupyterhub/setup-disaster-repo.qmd
60+
- Jupyterhub/convert_to_geotiff.qmd
61+
- Jupyterhub/simple_disaster_template.ipynb
62+
- section: workflow2.qmd
63+
text: Data Workflow Diagrams
64+
contents:
65+
- data_workflow2/NRT_data_download.qmd
66+
- data_workflow2/NRT_directory_structure.qmd
67+
- section: Documentation
68+
contents:
69+
- text: "Quarto Guide for Beginners"
70+
href: quarto-guide.qmd
71+
- section: User Services
72+
contents:
73+
- services/apis.qmd
74+
- services/jupyterhub.qmd
75+
- section: Presentations
76+
contents:
77+
- section: PowerPoints
78+
contents:
79+
- text: "Disasters Logo and Template Overview"
80+
href: Presentations/disasters-powerpoint-template.qmd
81+
- text: "AWS and Grafana Monitoring Tutorial"
82+
href: Presentations/aws-grafana-tutorial.qmd
83+
- text: "JupyterHub and Data Conversions Tutorial"
84+
href: Presentations/jupyterhub-data-conversions-tutorial.qmd
85+
- text: "STAC Database and Apache Airflow Tutorial"
86+
href: Presentations/stac-airflow-tutorial.qmd
87+
# - href: datausage.qmd
88+
# text: Data Usage Notebooks
89+
# - href: datatransformation.qmd
90+
# text: Data Transformation Documentation
91+
# - href: processingreport.qmd
92+
# text: Processing and Verification Reports
93+
# - href: workflow.qmd
94+
# text: Data Workflow
95+
# - href: advanceduser.qmd
96+
# text: Advanced User Notebooks
97+
- section: datausage.qmd
98+
text: Data Usage Notebooks
99+
contents:
100+
- section: Disaster Case Studies
101+
contents:
102+
- text: "Texas Flood 2025"
103+
href: user_data_notebooks/Texas_Flood_2025.ipynb
104+
- text: "New Mexico Fire 2025"
105+
href: user_data_notebooks/New_Mexico_Fire_2025.ipynb
106+
- section: Community-Contributed Tutorials
107+
contents:
108+
- section: datatransformationcode.qmd
109+
text: Data Transformation Notebooks
110+
contents:
111+
- cog_transformation/eccodarwin-co2flux-monthgrid-v5.ipynb
112+
- text: Atmospheric Carbon Dioxide and Methane Concentrations from the NOAA Global Monitoring Laboratory
113+
href: cog_transformation/noaa-gggrn-concentrations.ipynb
114+
- cog_transformation/influx-testbed-ghg-concentrations.ipynb
115+
- cog_transformation/lam-testbed-ghg-concentrations.ipynb
116+
- cog_transformation/nec-testbed-ghg-concentrations.ipynb
117+
- cog_transformation/ct-ch4-monthgrid-v2023.ipynb
118+
- cog_transformation/emit-ch4plume-v1.ipynb
119+
- cog_transformation/goes-ch4plume-v1.ipynb
120+
- cog_transformation/gosat-based-ch4budget-yeargrid-v1.ipynb
121+
- cog_transformation/gra2pes-ghg-monthgrid-v1.ipynb
122+
- cog_transformation/oco2geos-co2-daygrid-v10r.ipynb
123+
- cog_transformation/oco2-mip-co2budget-yeargrid-v1.ipynb
124+
- cog_transformation/odiac-ffco2-monthgrid-v2024.ipynb
125+
- text: "SEDAC Gridded World Population Density"
126+
href: cog_transformation/sedac-popdensity-yeargrid5yr-v4.11.ipynb
127+
- cog_transformation/epa-ch4emission-grid-v2express.ipynb
128+
- cog_transformation/vulcan-ffco2-yeargrid-v4.ipynb
129+
- section: processingreport.qmd
130+
text: Processing and Verification Reports
131+
contents:
132+
- processing_and_verification_reports/eccodarwin-co2flux-monthgrid-v5_Processing and Verification Report.qmd
133+
- text: "Atmospheric Carbon Dioxide Concentrations from the NOAA Global Monitoring Laboratory"
134+
href: processing_and_verification_reports/noaa-gggrn-co2-concentrations_Processing and Verification Report.qmd
135+
- processing_and_verification_reports/noaa-gggrn-ch4-concentrations_Processing and Verification Report.qmd
136+
- processing_and_verification_reports/influx-testbed-ghg-concentrations_Processing and Verification Report.qmd
137+
- processing_and_verification_reports/lam-testbed-ghg-concentrations_Processing and Verification Report.qmd
138+
- processing_and_verification_reports/nec-testbed-ghg-concentrations_Processing and Verification Report.qmd
139+
- processing_and_verification_reports/ct-ch4-monthgrid-v2023_Processing and Verification Report.qmd
140+
- processing_and_verification_reports/emit-ch4plume-v1_Processing and Verification Report.qmd
141+
- processing_and_verification_reports/goes-ch4plume-v1_Processing and Verification Report.qmd
142+
- processing_and_verification_reports/gosat-based-ch4budget-yeargrid-v1_Processing and Verification Report.qmd
143+
- processing_and_verification_reports/gra2pes-ghg-monthgrid-v1_Processing and Verification Report.qmd
144+
- processing_and_verification_reports/micasa-carbonflux-daygrid-v1_Processing and Verification Report.qmd
145+
- processing_and_verification_reports/oco2geos-co2-daygrid-v10r_Processing and Verification Report.qmd
146+
- processing_and_verification_reports/oco2-mip-co2budget-yeargrid-v1_Processing and Verification Report.qmd
147+
- processing_and_verification_reports/odiac-ffco2-monthgrid-v2024_Processing and Verification Report.qmd
148+
- processing_and_verification_reports/sedac-popdensity-yeargrid5yr-v4.11_Processing and Verification Report.qmd
149+
- processing_and_verification_reports/epa-ch4emission-grid-v2express_Processing and Verification Report.qmd
150+
- processing_and_verification_reports/vulcan-ffco2-yeargrid-v4_Processing and Verification Report.qmd
151+
- processing_and_verification_reports/lpjeosim-wetlandch4-grid-v1_Processing and Verification Report.qmd
152+
- section: workflow.qmd
153+
text: Data Flow Diagrams
154+
contents:
155+
- data_workflow/eccodarwin-co2flux-monthgrid-v5_Data_Flow.qmd
156+
- data_workflow/noaa-gggrn-co2-concentrations_Data_Flow.qmd
157+
- data_workflow/noaa-gggrn-ch4-concentrations_Data_Flow.qmd
158+
- data_workflow/influx-testbed-ghg-concentrations_Data_Flow.qmd
159+
- data_workflow/lam-testbed-ghg-concentrations_Data_Flow.qmd
160+
- data_workflow/nec-testbed-ghg-concentrations_Data_Flow.qmd
161+
- data_workflow/ct-ch4-monthgrid-v2023_Data_Flow.qmd
162+
- data_workflow/emit-ch4plume-v1_Data_Flow.qmd
163+
- data_workflow/goes-ch4plume-v1_Data_Flow.qmd
164+
- data_workflow/gosat-based-ch4budget-yeargrid-v1_Data_Flow.qmd
165+
- data_workflow/gra2pes-ghg-monthgrid-v1_Data_Flow.qmd
166+
- data_workflow/micasa-carbonflux-daygrid-v1_Data_Flow.qmd
167+
- data_workflow/oco2geos-co2-daygrid-v10r_Data_Flow.qmd
168+
- data_workflow/oco2-mip-co2budget-yeargrid-v1_Data_Flow.qmd
169+
- data_workflow/odiac-ffco2-monthgrid-v2024_Data_Flow.qmd
170+
- text: "SEDAC Gridded World Population Density"
171+
href: data_workflow/sedac-popdensity-yeargrid5yr-v4.11_Data_Flow.qmd
172+
- text: "U.S. Gridded Anthropogenic Methane Emissions Inventory"
173+
href: data_workflow/epa-ch4emission-grid-v2express_Data_Flow.qmd
174+
- data_workflow/vulcan-ffco2-yeargrid-v4_Data_Flow.qmd
175+
- data_workflow/lpjeosim-wetlandch4-grid-v1_Data_Flow.qmd
176+
177+
format:
178+
html:
179+
grid:
180+
sidebar-width: 25vw
181+
body-width: 900px
182+
theme:
183+
light: [flatly]
184+
dark: [darkly]
185+
css: styles.css
186+
code-copy: true
187+
code-overflow: wrap
188+
toc: true
189+
toc-depth: 3
190+
include-in-header:
191+
- text: |
192+
<script src="auth-check.js"></script>
193+
filters:
194+
- quarto

0 commit comments

Comments
 (0)