liuch / dmarc-srg

A php parser, viewer and summary report generator for incoming DMARC reports.
GNU General Public License v3.0
218 stars 32 forks source link

Unable to get the web pages to work - Apache on Centos 7 #66

Closed brianread108 closed 1 year ago

brianread108 commented 1 year ago

The batch (CLI) programs run fine and the summary email is sent as expected.

However I've so far been unable to get the Apache config correct (using php-fpm). The page shows the title, and the status boxes (populated with ?) and I get a red error box "[-100] Unexpected token ':', ":{"error_c"... is not valid JSON".

I interprete my problems as being the backend php is not delivering the JSON to the JS front end.

Here is my httpd.conf contents (taken and edited from another working php program/page):

Alias /dmarc-srg /opt/dmarc-srg
<Location /dmarc-srg>
    AuthName "dmarc-srg"
    AuthType Basic
    AuthBasicProvider external
    AuthExternal pwauth
    require user admin
</Location>
<Directory /opt/dmarc-srg>
    SSLRequireSSL
    Options -Indexes
    AllowOverride None
    <RequireAll>
          Require ip 127.0.0.1 xxx.xxx.xxx.0/255.255.255.0 
    </RequireAll>   
    AddType application/x-httpd-php .php 
    <FilesMatch .php$>
      SetHandler "proxy:unix:/var/run/php-fpm/php80.sock|fcgi://localhost"
    </FilesMatch>
</Directory>

I've not been able to find any error logs that are useful (neither php nor httpd)

liuch commented 1 year ago

I think there is some error on the backend, and text of this error is inserted before the json content. You can see the details of this error in the server logs (if configured) or in the browser console, assuming that the error text goes there.

brianread108 commented 1 year ago

In the browser console, the message is truncated as per what is show on the screen.

Got any idea which server logs it might appear in?

I've looked in the Apache logs and also the php ones.

liuch commented 1 year ago

It would nice to see at which stage you got this error (what did you do before and the query string). What exactly does your browser display?

brianread108 commented 1 year ago

Screenshot from 2023-05-28 08-35-59

It is treating the error message as a JSON message thus overwriting the original message?

utils/check_config.php runs fine.

brianread108 commented 1 year ago

Actually to me it looks as though the GET of the php file from the JS is not resulting in the php being interpreted and the consequent error handling is obscuring this.

If this is the case then it comes down to my httpd.conf contents. I have copied and edited these from a set which allow phpmyadmin to run on this server, but perhaps the particular way your package uses JS and PHP might need something a bit more specific? Not my particular area of expertise...

I've put a message on the server chat, but also I hoped there might be someone here who has implemented this for Apache.

liuch commented 1 year ago

I got the same error message when I added a command that adds : to stdout at the beginning of my script. I have no idea how this could happen. Perhaps my information will give you a hint.

the browser console with error message

liuch commented 1 year ago

I found a possible reason for this error: the presence of an empty line before this this one: <?php

Check your conf.php file.

brianread108 commented 1 year ago

Ok, that was the problem - an extra character on the first line of the config file. My Bad I guess!

However now I get this:

[-1] session_start(): Setting option "cookie_httponly" failed

It is not clear to me whether I need a password for "admin" in the config file. The Apache config requires authorisation with the system password.

ok, when I remove that admin password entry in the config I seem to be working!!

Many thanks for your help.

liuch commented 1 year ago

What version of PHP are you using? It must be 7.3 or higher. Environment requirements are listed here.

added: I'm glad it worked. However, I would recommend bringing your server environment in line with the requirements to avoid other problems.

liuch commented 1 year ago

If you don't have any more questions, may I close this?

brianread108 commented 1 year ago

Sure. Thanks for the help.