habeIchVergessen / GL-X3000

5 stars 1 forks source link

Unable to complete first run additional test (gpx-parse.php) #5

Closed cyb3rl4d closed 7 months ago

cyb3rl4d commented 7 months ago

When I attempt to run "./scripts/gpx-parse.php gpxlog.gpx" I get the following message..

root@GL-X3000:/tmp/mountd/disk1_part1# ./scripts/gpx-parse.php gpxlog.gpx url: http://localhost/gps/ parseJson: gpxlog.gpx Warning: file_get_contents(http://localhost/gps/?f=gpxlog.gpx&m=): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /tmp/mountd/disk1_part1/scripts/gpx-parse.php on line 36 got http 404**

when running "./scripts/config.sh" I get the following output, showing that gps.conf is missing, is this related?

root@GL-X3000:/tmp/mountd/disk1_part1# ./scripts/config.sh checking all files in /tmp/mountd/disk1_part1/.config name cmp status


/etc/nginx/gl-conf.d/service-gps.conf ok exists (link) /etc/php.ini exists /etc/init.d/gpsd exists /etc/php8-fpm.conf ok exists /etc/php8-fpm.d/gps.conf not exists checking required packages: ok (17 installed)

habeIchVergessen commented 7 months ago

each of the listed files must be handled. service-gps.conf is just an example. column cmp must show ok for each line.

run diff /tmp/mountd/disk1_part1/.config/etc/php.ini /etc/php.ini

cyb3rl4d commented 7 months ago

Thanks, I've ran the above command, here's the output...

root@GL-X3000:~#` diff /tmp/mountd/disk1_part1/.config/etc/php.ini /etc/php.ini 18,19c18 < ;serialize_precision = 100 < serialize_precision = 15

serialize_precision = 100 26d24 < ;highlight.bg = #FFFFFF 35a34 ;zend.exception_string_param_max_len = 0 102,103c101 < ; doc_root = "/www" < doc_root =

doc_root = "/www" 108d105 < ; -- ehl 110d106 < cgi.force_redirect = 1 112,114c108 < ; -- ehl < ;cgi.redirect_status_env = < cgi.redirect_status_env = "yes";

;cgi.redirect_status_env = 118d111 < ; -- ehl 120d112 < fastcgi.logging = 1 root@GL-X3000:~# `

habeIchVergessen commented 7 months ago

lines starting with "<" indicates my modifications compared to /etc/php.ini. the simplest solution is to copy /tmp/mountd/disk1_part1/.config/etc/php.ini to /etc/php.ini or even edit /etc/php.ini. same procedure with /etc/init.d/gpsd

not existing file /etc/php8-fpm.d/gps.conf can be linked ln -s /tmp/mountd/disk1_part1/.config/etc/php8-fpm.d/gps.conf /etc/php8-fpm.d/gps.conf

pls post outpout of config.sh

cyb3rl4d commented 7 months ago

thanks, I've done that, see the below output from config.sh...

root@GL-X3000:/tmp/mountd/disk1_part1# ./scripts/config.sh

checking all files in /tmp/mountd/disk1_part1/.config

name cmp status


/etc/nginx/gl-conf.d/service-gps.conf ok exists (link) /etc/php8-fpm.conf ok exists /etc/php8-fpm.d/gps.conf ok exists (link)

checking required packages: ok (17 installed)

root@GL-X3000:/tmp/mountd/disk1_part1#

habeIchVergessen commented 7 months ago

HTTP request works now?

cyb3rl4d commented 7 months ago

no :-(

root@GL-X3000:/tmp/mountd/disk1_part1# ./scripts/gpx-parse.php gpxlog.gpx

url: http://localhost/gps/

parseJson: gpxlog.gpx

Warning: file_get_contents(http://localhost/gps/?f=gpxlog.gpx&m=): Failed to open stream: HTTP request failed! HTTP/1.1 502 Bad Gateway in /tmp/mountd/disk1_part1/scripts/gpx-parse.php on line 36 got http 502

root@GL-X3000:/tmp/mountd/disk1_part1#

habeIchVergessen commented 7 months ago

pls post last 10 lines of /var/log/php8-fpm.log

cyb3rl4d commented 7 months ago

php8-fpm.log isnt present, I've searched for it but cant find it.

I've just started it via /etc/init.d/php8-fpm start and have the following...

root@GL-X3000:/etc/init.d# /etc/init.d/php8-fpm start root@GL-X3000:/etc/init.d# /etc/init.d/php8-fpm enabled root@GL-X3000:/etc/init.d# ps | grep php8-fpm 3595 root 1240 S grep php8-fpm 14968 root 15572 S {php8-fpm} php-fpm: master process (/etc/php8-fpm.conf) 14970 nobody 15592 S {php8-fpm} php-fpm: pool www 14971 nobody 15592 S {php8-fpm} php-fpm: pool www root@GL-X3000:/tmp/log#

cyb3rl4d commented 7 months ago

after starting the service the log has been created with the following output...

root@GL-X3000:/tmp/log# tail php8-fpm.log [03-Apr-2024 14:06:24] NOTICE: fpm is running, pid 14968 [03-Apr-2024 14:06:24] NOTICE: ready to handle connections

I've attempted to run the gpx-parse.php again and get the following....

root@GL-X3000:/tmp/mountd/disk1_part1# ./scripts/gpx-parse.php gpxlog.gpx

url: http://localhost/gps/

parseJson: gpxlog.gpx

Warning: file_get_contents(http://localhost/gps/?f=gpxlog.gpx&m=): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not found in /tmp/mountd/disk1_part1/scripts/gpx-parse.php on line 36 got http 404

root@GL-X3000:/tmp/mountd/disk1_part1#

habeIchVergessen commented 7 months ago

any additional informations in the log-file? also look around for nginx-logs (no access to my device at the moment)

cyb3rl4d commented 7 months ago

the nginx error log shows unable to bind, my router (admin web portal) is using port 80 to serve the default web interface already, do you have your router running on another port by default, therefore does this allow the additional web service you're setting up to bind to port 80?

root@GL-X3000:/tmp/log/nginx# tail error.log 2024/04/03 15:20:16 [emerg] 18327#0: bind() to [::]:443 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: bind() to 0.0.0.0:80 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: bind() to [::]:80 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: bind() to 0.0.0.0:443 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: bind() to [::]:443 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: bind() to 0.0.0.0:80 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: bind() to [::]:80 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: bind() to 0.0.0.0:443 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: bind() to [::]:443 failed (98: Address in use) 2024/04/03 15:20:16 [emerg] 18327#0: still could not bind() root@GL-X3000:/tmp/log/nginx#

habeIchVergessen commented 7 months ago

i'm using openwrt-x3000-4.0-release50402-0908-1694145767.bin in this build nginx is the default web server

which build do you use? which process is listing on port 80? ps w | grep `netstat -anpt | grep :80 | awk ' { print $7 } ' | awk -F "/" ' { print $1 } ' | uniq`

cyb3rl4d commented 7 months ago

In the GL.iNet Admin Panel it tells me the following... Current Firmware Version: 4.0 Firmware Type: 0406release1 Compile Time: 2024-01-23 15:20:08(UTC+08:00)

In OpenWrt interface it tells me.... OpenWrt 21.02-SNAPSHOT r15812+879-46b6ee7ffc / LuCI openwrt-21.02 branch git-22.245.77575-63bfee6

I believe its nginx listening on port 80...

root@GL-X3000:~# netstat -anpt | grep :80 | awk ' { print $7 } ' | awk -F "/" ' { print $1 } ' | uniq 7247

root@GL-X3000:~# ps w | grep 7247 7247 root 8256 S nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf -g daemon off;

habeIchVergessen commented 7 months ago

pls post output of nginx -T

cyb3rl4d commented 7 months ago

root@GL-X3000:~# nginx -T nginx: [alert] lua_code_cache is off; this will hurt performance in /etc/nginx/conf.d/gl.conf:6 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

configuration file /etc/nginx/nginx.conf:

user root; worker_processes auto;

pid /var/run/nginx.pid;

events { worker_connections 1024; }

http { include mime.types; default_type application/octet-stream;

sendfile on;
keepalive_timeout 5;

client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 1G;
large_client_header_buffers 2 1k;

gzip_static on;

root /www;

access_log off;

include /etc/nginx/conf.d/*.conf;

}

configuration file /etc/nginx/mime.types:

types { text/html html htm shtml; text/css css; text/xml xml; image/gif gif; image/jpeg jpeg jpg; application/javascript js; application/atom+xml atom; application/rss+xml rss;

text/mathml                                      mml;
text/plain                                       txt;
text/vnd.sun.j2me.app-descriptor                 jad;
text/vnd.wap.wml                                 wml;
text/x-component                                 htc;

image/png                                        png;
image/svg+xml                                    svg svgz;
image/tiff                                       tif tiff;
image/vnd.wap.wbmp                               wbmp;
image/webp                                       webp;
image/x-icon                                     ico;
image/x-jng                                      jng;
image/x-ms-bmp                                   bmp;

font/woff                                        woff;
font/woff2                                       woff2;

application/java-archive                         jar war ear;
application/json                                 json;
application/mac-binhex40                         hqx;
application/msword                               doc;
application/pdf                                  pdf;
application/postscript                           ps eps ai;
application/rtf                                  rtf;
application/vnd.apple.mpegurl                    m3u8;
application/vnd.google-earth.kml+xml             kml;
application/vnd.google-earth.kmz                 kmz;
application/vnd.ms-excel                         xls;
application/vnd.ms-fontobject                    eot;
application/vnd.ms-powerpoint                    ppt;
application/vnd.oasis.opendocument.graphics      odg;
application/vnd.oasis.opendocument.presentation  odp;
application/vnd.oasis.opendocument.spreadsheet   ods;
application/vnd.oasis.opendocument.text          odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                 pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                 xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                 docx;
application/vnd.wap.wmlc                         wmlc;
application/x-7z-compressed                      7z;
application/x-cocoa                              cco;
application/x-java-archive-diff                  jardiff;
application/x-java-jnlp-file                     jnlp;
application/x-makeself                           run;
application/x-perl                               pl pm;
application/x-pilot                              prc pdb;
application/x-rar-compressed                     rar;
application/x-redhat-package-manager             rpm;
application/x-sea                                sea;
application/x-shockwave-flash                    swf;
application/x-stuffit                            sit;
application/x-tcl                                tcl tk;
application/x-x509-ca-cert                       der pem crt;
application/x-xpinstall                          xpi;
application/xhtml+xml                            xhtml;
application/xspf+xml                             xspf;
application/zip                                  zip;

application/octet-stream                         bin exe dll;
application/octet-stream                         deb;
application/octet-stream                         dmg;
application/octet-stream                         iso img;
application/octet-stream                         msi msp msm;

audio/midi                                       mid midi kar;
audio/mpeg                                       mp3;
audio/ogg                                        ogg;
audio/x-m4a                                      m4a;
audio/x-realaudio                                ra;

video/3gpp                                       3gpp 3gp;
video/mp2t                                       ts;
video/mp4                                        mp4;
video/mpeg                                       mpeg mpg;
video/quicktime                                  mov;
video/webm                                       webm;
video/x-flv                                      flv;
video/x-m4v                                      m4v;
video/x-mng                                      mng;
video/x-ms-asf                                   asx asf;
video/x-ms-wmv                                   wmv;
video/x-msvideo                                  avi;

}

configuration file /etc/nginx/conf.d/gl.conf:

index gl_home.html;

lua_shared_dict shmem 12k; lua_shared_dict nonces 16k; lua_shared_dict sessions 16k; lua_code_cache off;

init_by_lua_file /usr/share/gl-ngx/oui-init.lua;

server { listen 80; listen [::]:80;

listen 443 ssl;
listen [::]:443 ssl;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:DHE+AESGCM:DHE:!RSA!aNULL:!eNULL:!LOW:!RC4:!3DES:!MD5:!EXP:!PSK:!SR    P:!DSS:!CAMELLIA:!SEED";
ssl_session_tickets off;

ssl_certificate /etc/nginx/nginx.cer;
ssl_certificate_key /etc/nginx/nginx.key;

resolver 127.0.0.1;

rewrite ^/index.html / permanent;

location = /rpc {
    content_by_lua_file /usr/share/gl-ngx/oui-rpc.lua;
}

location = /upload {
    content_by_lua_file /usr/share/gl-ngx/oui-upload.lua;
}

location = /download {
    content_by_lua_file /usr/share/gl-ngx/oui-download.lua;
}

location /cgi-bin/ {
    include fastcgi_params;
    fastcgi_read_timeout 300;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
}

location ~.*\.(html|png|jpg|svg)$ {
    add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}

include /etc/nginx/gl-conf.d/*.conf;

}

configuration file /etc/nginx/fastcgi_params:

fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name;

PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param REDIRECT_STATUS 200;

configuration file /etc/nginx/gl-conf.d/access.conf:

location / { access_by_lua_file /usr/share/gl-ngx/oui-access.lua; }

configuration file /etc/nginx/gl-conf.d/adg.conf:

location /control/ { proxy_pass http://127.0.0.1:3000; }

configuration file /etc/nginx/gl-conf.d/service-gps.conf:

location ~ /gps/ { root /tmp/mountd/disk1_part1/.www;

fastcgi_split_path_info ^(.+?\.php)(/.*)$;

# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";

fastcgi_pass unix:/var/run/php8-fpm.sock;
fastcgi_index index.php;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param   SCRIPT_FILENAME         $document_root/gps/index.php;

}

root@GL-X3000:~#

habeIchVergessen commented 7 months ago

config looks good

try wget http://localhost/gps/ -O -

cyb3rl4d commented 7 months ago

root@GL-X3000:~# wget http://localhost/gps/ -O - Downloading 'http://localhost/gps/' Connecting to ::1:80 Writing to stdout <!DOCTYPE html>GPS

habeIchVergessen commented 7 months ago

can you try to edit file /tmp/mountd/disk1_part1/.www/gps/index.php and modify line 158 as followed

old: } else if (count($lastDirE) > 0 && $lastDirE[0] != "") {

new: } else if (isset($lastDirE) && count($lastDirE) > 0 && $lastDirE[0] != "") {

cyb3rl4d commented 7 months ago

root@GL-X3000:/tmp/mountd/disk1_part1# ./scripts/gpx-parse.php gpxlog.gpx

url: http://localhost/gps/

parseJson: gpxlog.gpx

Warning: file_get_contents(http://localhost/gps/?f=gpxlog.gpx&m=): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not found in /tmp/mountd/disk1_part1/scripts/gpx-parse.php on line 36 got http 404

root@GL-X3000:/tmp/mountd/disk1_part1#

root@GL-X3000:/tmp/mountd/disk1_part1# wget http://localhost/gps/ -O - Downloading 'http://localhost/gps/' Connecting to ::1:80 Writing to stdout <!DOCTYPE html>GPS


Download completed (341 bytes) root@GL-X3000:/tmp/mountd/disk1_part1#

habeIchVergessen commented 7 months ago

wget http://localhost/gps/?f=gpxlog_2024-04-03_13-04-30.gpx&m= -O -

cyb3rl4d commented 7 months ago

I deleted the gpxlog_2024-04-03_13-04-30.gpx file in the .gps directory then ran ./scripts/gpxlogger-cron.sh again, it created the gpxlog.gpx again and it looks like its worked..

root@GL-X3000:/tmp/mountd/disk1_part1# ./scripts/gpxlogger-cron.sh 03.04.2024 17:25.23 BST: starting gpxlogger root@GL-X3000:/tmp/mountd/disk1_part1# logread -e gpx && date Wed Apr 3 17:25:23 2024 user.notice gpxlogger-cron.sh: starting gpxlogger Wed Apr 3 17:25:30 BST 2024 root@GL-X3000:/tmp/mountd/disk1_part1# ./scripts/gpx-parse.php gpxlog.gpx

url: http://localhost/gps/

parseJson: gpxlog.gpx

gpx: version 1.1 name: , time 03.04.2024 17:25:23 BST bounds 11.111111111, -1.111111111 - 11.111111111, -1.111111111 (0x0)

tracks: 1 trk: # , time 03.04.2024 17:25:24 BST, trkpts 1, length: 0 km bounds 11.111111111, -1.111111111 - 11.111111111, -1.111111111 (0x0)

http: 0.034 s xml: 0.021 s gpx: 0.001 s memory: 475952

root@GL-X3000:/tmp/mountd/disk1_part1#

cyb3rl4d commented 7 months ago

browsing to the router I can now see the gpx whooop!!! Thanks!!

I think one of the scripts renames the gpx file when you try to start it again, if I remember correctly, maybe that was the issue as well as the line I needed to change.

Thanks for all your help.

now onto the next steps!! :-)

cyb3rl4d commented 7 months ago

I guess I need to change path in the crontab example to match the dis1_part1 location?

root@GL-X3000:/tmp/mountd/disk1_part1# nano /tmp/mountd/disk1_part1/.cron/crontab

/1 * /root/scripts/gpxlogger-cron.sh >> /var/log/gpxlogger-cron.log 2>&1

/5 * /root/scripts/gpx-upload.php

/1 * /root/scripts/gpx-alert.sh

habeIchVergessen commented 7 months ago

or you create a link /root/scripts that points to /tmp/mountd/disk1_part1/scripts/ (see README.md)

cyb3rl4d commented 7 months ago

oh yes sorry missed that thanks!!

habeIchVergessen commented 7 months ago

bugfix .www/gps/index.php line 158