mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-04-29 02:22:28 +00:00
Compare commits
5 Commits
7e7e077ce1
...
c0598c5827
Author | SHA1 | Date | |
---|---|---|---|
|
c0598c5827 | ||
|
407cee1d70 | ||
|
95c6c0e1e1 | ||
|
2fb1daab99 | ||
|
392d1f0277 |
@ -2,13 +2,17 @@ const axios = require('axios');
|
||||
const cheerio = require('cheerio');
|
||||
const qs = require('querystring');
|
||||
|
||||
|
||||
const PIHOLE_PASSWORD = process.env.PIHOLE_PASSWORD;
|
||||
const PIHOLE_LOGIN_URL = 'http://'+process.env.PIHOLE_IP+'/admin/index.php';
|
||||
const PIHOLE_CUSTOMDNS_URL = 'http://'+process.env.PIHOLE_IP+'/admin/scripts/pi-hole/php/customdns.php';
|
||||
const PIHOLE_PLUGIN_ENABLED = process.env.PIHOLE_PLUGIN_ENABLED === 'true';
|
||||
const PIHOLE_PASSWORD = process.env.PIHOLE_PASSWORD;
|
||||
const PIHOLE_LOGIN_URL = 'http://'+process.env.PIHOLE_IP+'/admin/index.php';
|
||||
const PIHOLE_CUSTOMDNS_URL = 'http://'+process.env.PIHOLE_IP+'/admin/scripts/pi-hole/php/customdns.php';
|
||||
|
||||
// Function to update Pi-hole with domain and IP
|
||||
async function updatePihole(domain, ip) {
|
||||
async function updatePihole(domain, ip, action) {
|
||||
// Check if the Pi-hole plugin is enabled
|
||||
if (!PIHOLE_PLUGIN_ENABLED) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Step 1: Login to Pi-hole to get session cookie
|
||||
const loginResponse = await axios.post(PIHOLE_LOGIN_URL, qs.stringify({
|
||||
@ -22,7 +26,6 @@ async function updatePihole(domain, ip) {
|
||||
});
|
||||
|
||||
if (loginResponse.status === 200) {
|
||||
console.log('Login successful');
|
||||
// Extract session cookie (PHPSESSID)
|
||||
const cookies = loginResponse.headers['set-cookie'];
|
||||
const sessionCookie = cookies.find((cookie) => cookie.startsWith('PHPSESSID'));
|
||||
@ -44,7 +47,6 @@ async function updatePihole(domain, ip) {
|
||||
// Extract token value from element with ID "token"
|
||||
const token = $('#token').text().trim();
|
||||
|
||||
console.log('Token retrieved:', token);
|
||||
|
||||
// Step 3: Add custom DNS record with explicit session cookie and token
|
||||
const headers = {
|
||||
@ -60,7 +62,7 @@ async function updatePihole(domain, ip) {
|
||||
|
||||
// Request data including token
|
||||
const requestData = {
|
||||
action: 'add',
|
||||
action: action,
|
||||
ip: ip,
|
||||
domain: domain,
|
||||
token: token // Use the token retrieved from the HTML page
|
||||
@ -71,7 +73,7 @@ async function updatePihole(domain, ip) {
|
||||
headers: headers
|
||||
});
|
||||
|
||||
console.log('Custom DNS record added:', addRecordResponse.data);
|
||||
console.log('PiHole API:', addRecordResponse.data);
|
||||
} else {
|
||||
console.error('Login failed:', loginResponse.statusText);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ const internalProxyHost = {
|
||||
|
||||
// Update PiHole
|
||||
for (let i = 0; i < row.domain_names.length; i++) {
|
||||
piHole.updatePihole(row.domain_names[i], row.forward_host);
|
||||
piHole.updatePihole(row.domain_names[i], row.forward_host, 'add').then();
|
||||
}
|
||||
|
||||
return row;
|
||||
@ -77,7 +77,7 @@ const internalProxyHost = {
|
||||
|
||||
// Update PiHole
|
||||
for (let i = 0; i < row.domain_names.length; i++) {
|
||||
piHole.updatePihole(row.domain_names[i], row.forward_host);
|
||||
piHole.updatePihole(row.domain_names[i], row.forward_host, 'add').then();
|
||||
}
|
||||
|
||||
return row;
|
||||
@ -166,9 +166,18 @@ const internalProxyHost = {
|
||||
data.certificate_id = cert.id;
|
||||
})
|
||||
.then(() => {
|
||||
// Update PiHole
|
||||
for (let i = 0; i < row.domain_names.length; i++) {
|
||||
piHole.updatePihole(row.domain_names[i], row.forward_host, 'delete').then();
|
||||
}
|
||||
return row;
|
||||
});
|
||||
} else {
|
||||
// Update PiHole
|
||||
for (let i = 0; i < row.domain_names.length; i++) {
|
||||
piHole.updatePihole(row.domain_names[i], row.forward_host, 'delete').then();
|
||||
|
||||
}
|
||||
return row;
|
||||
}
|
||||
})
|
||||
@ -194,6 +203,7 @@ const internalProxyHost = {
|
||||
meta: data
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
return saved_row;
|
||||
});
|
||||
});
|
||||
@ -213,6 +223,9 @@ const internalProxyHost = {
|
||||
.then((new_meta) => {
|
||||
row.meta = new_meta;
|
||||
row = internalHost.cleanRowCertificateMeta(row);
|
||||
for (let i = 0; i < row.domain_names.length; i++) {
|
||||
piHole.updatePihole(row.domain_names[i], row.forward_host, 'add').then();
|
||||
}
|
||||
return _.omit(row, omissions());
|
||||
});
|
||||
});
|
||||
@ -288,6 +301,11 @@ const internalProxyHost = {
|
||||
is_deleted: 1
|
||||
})
|
||||
.then(() => {
|
||||
// Update PiHole
|
||||
|
||||
for (let i = 0; i < row.domain_names.length; i++) {
|
||||
piHole.updatePihole(row.domain_names[i], row.forward_host, 'delete').then();
|
||||
}
|
||||
// Delete Nginx Config
|
||||
return internalNginx.deleteConfig('proxy_host', row)
|
||||
.then(() => {
|
||||
|
@ -29,6 +29,11 @@ services:
|
||||
DB_MYSQL_NAME: 'npm'
|
||||
# DB_SQLITE_FILE: "/data/database.sqlite"
|
||||
# DISABLE_IPV6: "true"
|
||||
# pihole:
|
||||
# PIHOLE_PLUGIN_ENABLED: 'true'
|
||||
# PIHOLE_PASSWORD: 'password'
|
||||
# PIHOLE_IP: '192.168.10.2'
|
||||
|
||||
volumes:
|
||||
- npm_data:/data
|
||||
- le_data:/etc/letsencrypt
|
||||
|
Loading…
x
Reference in New Issue
Block a user