diff --git a/.env.example b/.env.example deleted file mode 100644 index c5186bb..0000000 --- a/.env.example +++ /dev/null @@ -1,10 +0,0 @@ -DB_NAME=pontusmail -DB_USER=root -DB_PASSWORD=passwdhere -DB_HOST=127.0.0.1 -DB_PORT=3306 -SESSION_SECRET=secretkeyhere -ADMIN_USERNAME=admin -ADMIN_PASSWORD=admin -INTERNAL_PORT=3000 -MC_API_KEY=mailcowapikeyhere \ No newline at end of file diff --git a/app.js b/app.js index edaf39f..249a50b 100644 --- a/app.js +++ b/app.js @@ -2,8 +2,6 @@ const express = require('express'); const bodyParser = require('body-parser'); const path = require('path'); const fs = require('fs'); -const session = require('express-session'); -const { Sequelize, DataTypes } = require('sequelize'); const axios = require('axios'); const NodeCache = require('node-cache'); const cache = new NodeCache({ stdTTL: 1800 }); @@ -16,81 +14,47 @@ app.set('views', path.join(__dirname, 'src')); app.use(bodyParser.urlencoded({ extended: false })); app.use(express.static(path.join(__dirname, 'public'))); -app.use(session({ - secret: process.env.SESSION_SECRET, - resave: false, - saveUninitialized: true -})); -const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, { - host: process.env.DB_HOST || '127.0.0.1', // pulls from .env or defaults to localhost - port: process.env.DB_PORT || 3306, // pulls from .env or defaults to 3306 - dialect: 'mysql' -}); +//async function fetchDomainData() { +// const cachedData = cache.get('domainData'); +// if (cachedData) { +// return cachedData; +// } +// +// try { +// const response = await axios.get('https://user.p0ntus.com/api/v1/get/domain/all', { +// headers: { +// 'accept': 'application/json', +// 'X-API-Key': process.env.MC_API_KEY +// } +// }); +// const domainData = response.data; +// cache.set('domainData', domainData); +// return domainData; +// } catch (error) { +// console.error('Error fetching domain data:', error); +// return []; +// } +//} -sequelize.authenticate() - .then(() => console.log('Database connected')) - .catch(err => console.log('Error: ' + err)); - -const Request = sequelize.define('Request', { - fullName: DataTypes.STRING, - email: DataTypes.STRING, - reason: DataTypes.TEXT, - telegram: DataTypes.STRING, - status: { - type: DataTypes.STRING, - defaultValue: 'Pending' - } -}); - -async function fetchDomainData() { - const cachedData = cache.get('domainData'); - if (cachedData) { - return cachedData; - } - - try { - const response = await axios.get('https://user.p0ntus.com/api/v1/get/domain/all', { - headers: { - 'accept': 'application/json', - 'X-API-Key': process.env.MC_API_KEY - } - }); - const domainData = response.data; - cache.set('domainData', domainData); - return domainData; - } catch (error) { - console.error('Error fetching domain data:', error); - return []; - } -} - -function getDomains() { - const domainsPath = path.join(__dirname, 'domains.txt'); - try { - const domains = fs.readFileSync(domainsPath, 'utf-8').split('\n').filter(Boolean); - return domains; - } catch (error) { - console.error('Error reading domains.txt:', error); - return []; - } -} - -// Sync DB models -sequelize.sync(); +//function getDomains() { +// const domainsPath = path.join(__dirname, 'domains.txt'); +// try { +// const domains = fs.readFileSync(domainsPath, 'utf-8').split('\n').filter(Boolean); +// return domains; +// } catch (error) { +// console.error('Error reading domains.txt:', error); +// return []; +// } +//} app.get('/', async (req, res) => { - const domainData = await fetchDomainData(); - const domainCount = Array.isArray(domainData) ? domainData.length : 0; - const accountCount = Array.isArray(domainData) ? domainData.reduce((acc, domain) => acc + domain.mboxes_in_domain, 0) : 0; - const totalData = Array.isArray(domainData) ? domainData.reduce((acc, domain) => acc + parseInt(domain.bytes_total), 0) / (1024 * 1024) : 0; + //const domainData = await fetchDomainData(); + //const domainCount = Array.isArray(domainData) ? domainData.length : 0; + //const accountCount = Array.isArray(domainData) ? domainData.reduce((acc, domain) => acc + domain.mboxes_in_domain, 0) : 0; + //const totalData = Array.isArray(domainData) ? domainData.reduce((acc, domain) => acc + parseInt(domain.bytes_total), 0) / (1024 * 1024) : 0; - res.render('index', { - currentPage: 'home', - domainCount, - accountCount, - totalData: totalData.toFixed(2) // Round to 2 decimal places - }); + res.render('index', { currentPage: 'home' }); }); app.get('/services', (req, res) => { @@ -142,133 +106,6 @@ app.get('/guides/vaultwarden/firefox', (req, res) => { res.render('guides/vaultwarden/firefox', { currentPage: 'guides' }); }); -app.get('/register', (req, res) => { - const domains = getDomains(); - res.render('register', { domains }); -}); - -app.post('/register', async (req, res) => { - const { fullName, email, domain, reason, telegram } = req.body; - const crit = /^[a-zA-Z0-9.-]+$/; // regex (see also: public/js/register.js) - - if (!crit.test(email) || /\s/.test(email) || email !== email.toLowerCase()) { - return res.render('error/500'); - } - - const fullEmail = `${email}@${domain}`; - - try { - await Request.create({ fullName, email: fullEmail, reason, telegram }); - res.render('reg-success', { currentPage: 'register' }); - } catch (error) { - console.error('Error creating request:', error); - res.render('error/500'); - } -}); - -app.get('/request', async (req, res) => { - console.log("Found!"); - const { email } = req.query; - const domains = getDomains(); - - if (!email) { - return res.render('error/email', { domains }); - } - - try { - const request = await Request.findOne({ where: { email } }); - if (!request) { - return res.status(404).render('error/notfoundemail', { email, domain }); - } - res.render('request', { request, domains }); - } catch (error) { - console.error(error); - res.render('error/500'); - } -}); - -app.post('/request', async (req, res) => { - console.log("Found!"); - const { email, domain } = req.body; - const fullEmail = `${email}@${domain}`; - const domains = getDomains(); - - if (!email || !domain) { - return res.render('error/email', { domains }); - } - - try { - const request = await Request.findOne({ where: { email: fullEmail } }); - const domains = getDomains(); - if (!request) { - return res.render('error/notfoundemail', { email, domain }); - } - res.render('request', { request, domains }); - } catch (error) { - console.error(error); - res.render('error/500'); - } -}); - -function checkAdminAuth(req, res, next) { - if (req.session.admin) { - next(); - } else { - res.redirect('/admin'); - } -} - -// Admin routes - -app.get('/admin', (req, res) => { - if (req.session.admin) { - return res.redirect('/admin/dashboard'); - } - res.render('admin/login', { currentPage: 'admin', error: null }); -}); - -app.post('/admin', (req, res) => { - const { username, password } = req.body; - if (username === process.env.ADMIN_USERNAME && password === process.env.ADMIN_PASSWORD) { - req.session.admin = true; - res.redirect('/admin/dashboard'); - } else { - res.render('admin/login', { error: 'An error occurred.' }); - } -}); - -app.get('/admin/dashboard', checkAdminAuth, async (req, res) => { - const requests = await Request.findAll(); - res.render('admin/dash', { requests, currentPage: 'admin', user: process.env.ADMIN_USERNAME }); -}); - -app.post('/admin/update-status', checkAdminAuth, async (req, res) => { - const { id, status } = req.body; - await Request.update({ status }, { where: { id } }); - res.redirect('/admin/dashboard'); -}); - -app.post('/admin/delete-request', checkAdminAuth, async (req, res) => { - const { id } = req.body; - await Request.destroy({ where: { id } }); - res.redirect('/admin/dashboard'); -}); - -app.get('/admin/edit/:id', checkAdminAuth, async (req, res) => { - const { id } = req.params; - const request = await Request.findByPk(id); - if (!request) { - return res.status(404).render('error/404'); - } - res.render('admin/edit', { request, currentPage: 'admin' }); -}); - -app.post('/admin/edit', checkAdminAuth, async (req, res) => { - const { id, fullName, email, reason, telegram } = req.body; - await Request.update({ fullName, email, reason, telegram }, { where: { id } }); - res.redirect('/admin/dashboard'); -}); - // Start server on internal port defined in .env app.listen(process.env.INTERNAL_PORT, () => { console.log(`Server started on port ${process.env.INTERNAL_PORT}`); diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..f82c034 Binary files /dev/null and b/bun.lockb differ diff --git a/package.json b/package.json index 80242e2..a05a779 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "express": "^4.21.1", "express-session": "^1.18.1", "mariadb": "^3.4.0", - "mysql2": "^3.11.5", + "mysql2": "^3.12.0", "node-cache": "^5.1.2", "sequelize": "^6.37.5", "winston": "^3.17.0" diff --git a/src/admin/dash.ejs b/src/admin/dash.ejs deleted file mode 100644 index 577c055..0000000 --- a/src/admin/dash.ejs +++ /dev/null @@ -1,58 +0,0 @@ -<%- include('shards/header', { title: 'Admin Dashboard - p0ntus mail' }) %> -
-
-

Welcome, <%= user %>!

-

You are viewing all requests

-
-
- - - - - - - - - - - - - - - <% requests.forEach(request => { %> - - - - - - - - - - - <% }); %> - -
IDFull NameEmailReasonTelegramStatusUpdate StatusDelete
<%= request.id %><%= request.fullName %><%= request.email %><%= request.reason %><%= request.telegram %><%= request.status %> -
- - - -
-
- - - -
- - -
-
-
-
-<%- include('shards/footer') %> \ No newline at end of file diff --git a/src/admin/edit.ejs b/src/admin/edit.ejs deleted file mode 100644 index c06a30b..0000000 --- a/src/admin/edit.ejs +++ /dev/null @@ -1,25 +0,0 @@ -<%- include('shards/header', { title: 'Edit Request - p0ntus mail' }) %> -
-

Edit Request

-
- -
- - -
-
- - -
-
- - -
-
- - -
- -
-
-<%- include('shards/footer') %> \ No newline at end of file diff --git a/src/admin/login.ejs b/src/admin/login.ejs deleted file mode 100644 index d023507..0000000 --- a/src/admin/login.ejs +++ /dev/null @@ -1,21 +0,0 @@ -<%- include('../shards/header', { title: 'Admin - p0ntus mail' }) %> -
- <%- include('../shards/nav', { currentPage: 'admin' }) %> - Login to administration panel -
- <% if (error) { %> -
<%= error %>
- <% } %> -
-
- - -
-
- - -
- -
-
-<%- include('../shards/footer') %> \ No newline at end of file diff --git a/src/admin/shards/footer.ejs b/src/admin/shards/footer.ejs deleted file mode 100644 index 8db4976..0000000 --- a/src/admin/shards/footer.ejs +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/admin/shards/header.ejs b/src/admin/shards/header.ejs deleted file mode 100644 index 10d5cc8..0000000 --- a/src/admin/shards/header.ejs +++ /dev/null @@ -1,37 +0,0 @@ - - - - - <%= title %> - - - - - - \ No newline at end of file diff --git a/src/error/404.ejs b/src/error/404.ejs deleted file mode 100644 index 5f7ee56..0000000 --- a/src/error/404.ejs +++ /dev/null @@ -1,7 +0,0 @@ -<%- include('../shards/header', { title: '404 Not Found - p0ntus mail', currentPage: 'err' }) %> -
- 404 Not Found -
-

The requested resource could not be found.

-
-<%- include('../shards/footer') %> \ No newline at end of file diff --git a/src/error/500.ejs b/src/error/500.ejs deleted file mode 100644 index 3221398..0000000 --- a/src/error/500.ejs +++ /dev/null @@ -1,7 +0,0 @@ -<%- include('../shards/header', { title: '500 Internal Server Error - p0ntus mail', currentPage: 'err' }) %> -
- 500 Internal Server Error -
-

An unexpected error occurred. Please try again later.

-
-<%- include('../shards/footer') %> \ No newline at end of file diff --git a/src/error/email.ejs b/src/error/email.ejs deleted file mode 100644 index f88efc7..0000000 --- a/src/error/email.ejs +++ /dev/null @@ -1,25 +0,0 @@ -<%- include('../shards/header', { title: 'Request Status - p0ntus mail', currentPage: 'err' }) %> -
- <%- include('../shards/nav', { currentPage: 'request' }) %> - We need your email -
-

We need an email to check your request. Please enter your p0ntus mail email address below:

-
-
- -
- -
- @ -
- -
-
- -
-
-<%- include('../shards/footer') %> \ No newline at end of file diff --git a/src/error/notfoundemail.ejs b/src/error/notfoundemail.ejs deleted file mode 100644 index 4415c2a..0000000 --- a/src/error/notfoundemail.ejs +++ /dev/null @@ -1,7 +0,0 @@ -<%- include('../shards/header', { title: "Couldn't find that email - p0ntus mail", currentPage: 'err' }) %> -
- We couldn't find that email -
-

We couldn't find a request under <%= email %>@<%= domain %>. Please try again later or try and register again.

-
-<%- include('../shards/footer') %> \ No newline at end of file diff --git a/src/index.ejs b/src/index.ejs index 88fcdd1..1c82d3c 100644 --- a/src/index.ejs +++ b/src/index.ejs @@ -10,33 +10,20 @@
If you aren't a current user
- Register - Check Registration Status + Register
If you are a current user
- Webmail - Account + Webmail + Account Vaultwarden Guides + Client Setup
Statistics
-
-
-

<%= domainCount %>

-

Domains Hosted

-
-
-

<%= accountCount %>

-

Accounts

-
-
-

<%= totalData %>

-

Total Data (MB)

-
-
+

As we have migrated to a new email platform, we are currently rewriting this.

Please note all domains may not be available for registration. <%- include('shards/footer') %> \ No newline at end of file diff --git a/src/privacy.ejs b/src/privacy.ejs index bc26970..8ba6a40 100644 --- a/src/privacy.ejs +++ b/src/privacy.ejs @@ -5,17 +5,15 @@

Our system collects automatically:

What I collect by choice:

What the admin has access to: