arendruni / homebridge-pihole

Pi-hole switch for Homebridge
https://www.npmjs.com/package/homebridge-pihole
MIT License
158 stars 9 forks source link

[BUG] Homebridge-pihole plugin suddenly not working #64

Closed joecarpita closed 1 year ago

joecarpita commented 1 year ago

Describe the bug Recently started experiencing odd behavior with pihole plugin.

Toggling the switch in iOS home app would appear to turn the pihole off, but there would be no indication it would turn back on via home app.

Checking the webUI of pihole, the plugin appears to be working (e.g. turning off would disable pihole, which would automatically restart after 120 second interval; but home app wouldn't reflect this).

Checking the homebridge web UI I revealed a problem with the plugin. On homebridge boot, I receive the following error with the homebridge-pihole plugin:

`[12/30/2022, 10:37:36 PM] [Pihole] Error: Request failed with status code 403 at createError (/usr/lib/node_modules/homebridge-pihole/node_modules/axios/lib/core/createError.js:16:15) at settle (/usr/lib/node_modules/homebridge-pihole/node_modules/axios/lib/core/settle.js:17:12) at IncomingMessage.handleStreamEnd (/usr/lib/node_modules/homebridge-pihole/node_modules/axios/lib/adapters/http.js:269:11) at IncomingMessage.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at processTicksAndRejections (node:internal/process/task_queues:82:21) { config: { url: 'api.php', method: 'get', headers: { Accept: 'application/json, text/plain, /', 'User-Agent': 'axios/0.21.4' }, params: { status: 1, auth: '54a6673c814b32309806ff1067ede0155de1af6c0550d6ce51d6f62ba76e4101' }, baseURL: 'http://localhost:80/admin/', transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, adapter: [Function: httpAdapter], responseType: 'json', xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, httpsAgent: Agent { _events: [Object: null prototype], _eventsCount: 2, _maxListeners: undefined, defaultPort: 443, protocol: 'https:', options: [Object: null prototype], requests: [Object: null prototype] {}, sockets: [Object: null prototype] {}, freeSockets: [Object: null prototype] {}, keepAliveMsecs: 1000, keepAlive: false, maxSockets: Infinity, maxFreeSockets: 256, scheduling: 'lifo', maxTotalSockets: Infinity, totalSocketCount: 0, maxCachedSessions: 100, _sessionCache: [Object],

},
validateStatus: [Function: validateStatus],
transitional: {
  silentJSONParsing: true,
  forcedJSONParsing: true,
  clarifyTimeoutError: false
},
data: undefined

}, request: <ref 1> ClientRequest { _events: [Object: null prototype] { abort: [Function (anonymous)], aborted: [Function (anonymous)], connect: [Function (anonymous)], error: [Function (anonymous)], socket: [Function (anonymous)], timeout: [Function (anonymous)], finish: [Function: requestOnFinish] }, _eventsCount: 7, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: true, chunkedEncoding: false, shouldKeepAlive: false, maxRequestsOnConnectionReached: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: false, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, strictContentLength: false, _contentLength: 0, _hasBody: true, _trailer: '', finished: true, _headerSent: true, _closed: false, socket: Socket { connecting: false, _hadError: false, _parent: null, _host: 'localhost', _closeAfterHandlingError: false, _readableState: [ReadableState], _events: [Object: null prototype], _eventsCount: 7, _maxListeners: undefined, _writableState: [WritableState], allowHalfOpen: false, _sockname: null, _pendingData: null, _pendingEncoding: '', server: null, _server: null, parser: null, _httpMessage: [Circular 1],

  [Symbol(kHandle)]: [TCP],
  [Symbol(lastWriteQueueSize)]: 0,
  [Symbol(timeout)]: null,
  [Symbol(kBuffer)]: null,
  [Symbol(kBufferCb)]: null,
  [Symbol(kBufferGen)]: null,
  [Symbol(kCapture)]: false,
  [Symbol(kSetNoDelay)]: true,
  [Symbol(kSetKeepAlive)]: false,
  [Symbol(kSetKeepAliveInitialDelay)]: 0,
  [Symbol(kBytesRead)]: 0,
  [Symbol(kBytesWritten)]: 0
},
_header: 'GET /admin/api.php?status=1&auth=54a6673c814b32309806ff1067ede0155de1af6c0550d6ce51d6f62ba76e4101 HTTP/1.1\r\n' +
  'Accept: application/json, text/plain, */*\r\n' +
  'User-Agent: axios/0.21.4\r\n' +
  'Host: localhost\r\n' +
  'Connection: close\r\n' +
  '\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: Agent {
  _events: [Object: null prototype],
  _eventsCount: 2,
  _maxListeners: undefined,
  defaultPort: 80,
  protocol: 'http:',
  options: [Object: null prototype],
  requests: [Object: null prototype] {},
  sockets: [Object: null prototype],
  freeSockets: [Object: null prototype] {},
  keepAliveMsecs: 1000,
  keepAlive: false,
  maxSockets: Infinity,
  maxFreeSockets: 256,
  scheduling: 'lifo',
  maxTotalSockets: Infinity,
  totalSocketCount: 2,
  [Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/admin/api.php?status=1&auth=54a6673c814b32309806ff1067ede0155de1af6c0550d6ce51d6f62ba76e4101',
_ended: true,
res: IncomingMessage {
  _readableState: [ReadableState],
  _events: [Object: null prototype],
  _eventsCount: 3,
  _maxListeners: undefined,
  socket: [Socket],
  httpVersionMajor: 1,
  httpVersionMinor: 1,
  httpVersion: '1.1',
  complete: true,
  rawHeaders: [Array],
  rawTrailers: [],
  aborted: false,
  upgrade: false,
  url: '',
  method: null,
  statusCode: 403,
  statusMessage: 'Forbidden',
  client: [Socket],
  _consuming: false,
  _dumped: false,
  req: [Circular *1],
  responseUrl: 'http://localhost:80/admin/api.php?status=1&auth=54a6673c814b32309806ff1067ede0155de1af6c0550d6ce51d6f62ba76e4101',
  redirects: [],
  [Symbol(kCapture)]: false,
  [Symbol(kHeaders)]: [Object],
  [Symbol(kHeadersCount)]: 14,
  [Symbol(kTrailers)]: null,
  [Symbol(kTrailersCount)]: 0
},
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'localhost',
protocol: 'http:',
_redirectable: Writable {
  _writableState: [WritableState],
  _events: [Object: null prototype],
  _eventsCount: 2,
  _maxListeners: undefined,
  _options: [Object],
  _ended: true,
  _ending: true,
  _redirectCount: 0,
  _redirects: [],
  _requestBodyLength: 0,
  _requestBodyBuffers: [],
  _onNativeResponse: [Function (anonymous)],
  _currentRequest: [Circular *1],
  _currentUrl: 'http://localhost:80/admin/api.php?status=1&auth=54a6673c814b32309806ff1067ede0155de1af6c0550d6ce51d6f62ba76e4101',
  [Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kEndCalled)]: true,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype] {
  accept: [Array],
  'user-agent': [Array],
  host: [Array]
},
[Symbol(kUniqueHeaders)]: null

}, response: { status: 403, statusText: 'Forbidden', headers: { 'content-type': 'text/html', 'x-pi-hole': 'The Pi-hole Web interface is working!', 'x-frame-options': 'DENY', 'content-length': '341', connection: 'close', date: 'Sat, 31 Dec 2022 04:37:36 GMT', server: 'lighttpd/1.4.53' }, config: { url: 'api.php', method: 'get', headers: [Object], params: [Object], baseURL: 'http://localhost:80/admin/', transformRequest: [Array], transformResponse: [Array], timeout: 0, adapter: [Function: httpAdapter], responseType: 'json', xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, httpsAgent: [Agent], validateStatus: [Function: validateStatus], transitional: [Object], data: undefined }, request: <ref 1> ClientRequest { _events: [Object: null prototype], _eventsCount: 7, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: true, chunkedEncoding: false, shouldKeepAlive: false, maxRequestsOnConnectionReached: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: false, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, strictContentLength: false, _contentLength: 0, _hasBody: true, _trailer: '', finished: true, _headerSent: true, _closed: false, socket: [Socket], _header: 'GET /admin/api.php?status=1&auth=54a6673c814b32309806ff1067ede0155de1af6c0550d6ce51d6f62ba76e4101 HTTP/1.1\r\n' + 'Accept: application/json, text/plain, /*\r\n' + 'User-Agent: axios/0.21.4\r\n' + 'Host: localhost\r\n' + 'Connection: close\r\n' + '\r\n', _keepAliveTimeout: 0, _onPendingData: [Function: nop], agent: [Agent], socketPath: undefined, method: 'GET', maxHeaderSize: undefined, insecureHTTPParser: undefined, path: '/admin/api.php?status=1&auth=54a6673c814b32309806ff1067ede0155de1af6c0550d6ce51d6f62ba76e4101', _ended: true, res: [IncomingMessage], aborted: false, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null, reusedSocket: false, host: 'localhost', protocol: 'http:', _redirectable: [Writable],

  [Symbol(kBytesWritten)]: 0,
  [Symbol(kEndCalled)]: true,
  [Symbol(kNeedDrain)]: false,
  [Symbol(corked)]: 0,
  [Symbol(kOutHeaders)]: [Object: null prototype],
  [Symbol(kUniqueHeaders)]: null
},
data: '<?xml version="1.0" encoding="iso-8859-1"?>\n' +
  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n' +
  '         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' +
  '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n' +
  ' <head>\n' +
  '  <title>403 Forbidden</title>\n' +
  ' </head>\n' +
  ' <body>\n' +
  '  <h1>403 Forbidden</h1>\n' +
  ' </body>\n' +
  '</html>\n'

}, isAxiosError: true, toJSON: [Function: toJSON] }`

Additional context I've tried removing the homebridge-pihole plugin and re-installing, but no dice.

All software is up to date. DietPi OS - v8.12.1 Homebridge - v1.6.0 homebridge-pihole - v0.4.2 NPM - v9.2.0 Node JS - v18.12.1 Pihole - v5.14.2, FTL - v5.20, Web Interface v5.18

arendruni commented 1 year ago

Hi @joecarpita, from the logs you attached it seems that the plugin gets a 403 (Forbidden) status code when making the get status request, did you change any of your Pi-hole configuration recently?

joecarpita commented 1 year ago

Pardon the delay in replying – I don't believe any changes were made to the pi-hole configuration. Can you think of any changes that may have happened that might be causing it. Also, for context, Pi-hole & Homebridge are running on the same device.

joecarpita commented 1 year ago

Finally troubleshooting this a bit again (this pi-hole is located at a relative's house) – it seemed like changing the plugin configuration host from its default of localhost to the IP address of the pi-hole has solved the issue (even though both pi-hole & homebridage are running on the same device).

I am not sure if this is desired behavior, but I'm going to close with this comment.