bfabiszewski / ulogger-server

μlogger • web viewer for tracks uploaded with μlogger mobile client
GNU General Public License v3.0
538 stars 85 forks source link

Creating user issues error, but user is created #96

Closed theAkito closed 4 years ago

theAkito commented 4 years ago

Firefox:

XML Parsing Error: no element found
Location: https://url.tld:1234/utils/handleuser.php
Line Number 1, Column 1:

Chrome:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
:1234/utils/handleuser.php:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
admin.js:117 POST https://url.tld:1234/utils/handleuser.php 500 (Internal Server Error)

Trying to create additional user with my admin account and I always get a popup saying Something went wrong + the above messages in the respective console. I tried to fix this error for a long time, just to find out, that nothing went actually wrong and the users get created correctly. Very frustrating.

admin.js

/* μlogger
 *
 * Copyright(C) 2017 Bartek Fabiszewski (www.fabiszewski.net)
 *
 * This is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

function addUser() {
  var form = '<form id="userForm" method="post" onsubmit="submitUser(\'add\'); return false">';
  form += '<label><b>' + lang['username'] + '</b></label><input type="text" placeholder="' + lang['usernameenter'] + '" name="login" required>';
  form += '<label><b>' + lang['password'] + '</b></label><input type="password" placeholder="' + lang['passwordenter'] + '" name="pass" required>';
  form += '<label><b>' + lang['passwordrepeat'] + '</b></label><input type="password" placeholder="' + lang['passwordenter'] + '" name="pass2" required>';
  form += '<div class="buttons"><button type="button" onclick="removeModal()">' + lang['cancel'] + '</button><button type="submit">' + lang['submit'] + '</button></div>';
  form += '</form>';
  showModal(form);
}

function editUser() {
  var userForm = document.getElementsByName('user')[0];
  var userLogin = (userForm !== undefined) ? userForm.options[userForm.selectedIndex].text : auth;
  if (userLogin == auth) {
    alert(lang['selfeditwarn']);
    return;
  }
  var message = '<div style="float:left">' + sprintf(lang['editinguser'], '<b>' + htmlEncode(userLogin) + '</b>') + '</div>';
  message += '<div class="red-button"><b><a href="javascript:void(0);" onclick="submitUser(\'delete\'); return false">' + lang['deluser'] + '</a></b></div>';
  message += '<div style="clear: both; padding-bottom: 1em;"></div>';

  var form = '<form id="userForm" method="post" onsubmit="submitUser(\'update\'); return false">';
  form += '<input type="hidden" name="login" value="' + htmlEncode(userLogin) + '">';
  form += '<label><b>' + lang['password'] + '</b></label><input type="password" placeholder="' + lang['passwordenter'] + '" name="pass" required>';
  form += '<label><b>' + lang['passwordrepeat'] + '</b></label><input type="password" placeholder="' + lang['passwordenter'] + '" name="pass2" required>';
  form += '<div class="buttons"><button type="button" onclick="removeModal()">' + lang['cancel'] + '</button><button type="submit">' + lang['submit'] + '</button></div>';
  form += '</form>';
  showModal(message + form);
}

function confirmedDelete(login) {
  return confirm(sprintf(lang['userdelwarn'], '"' + login + '"'));
}

function submitUser(action) {
  var form = document.getElementById('userForm');
  var login = form.elements['login'].value.trim();
  if (!login) {
      alert(lang['allrequired']);
      return;
  }
  var pass = null;
  var pass2 = null;
  if (action != 'delete') {
    pass = form.elements['pass'].value;
    pass2 = form.elements['pass2'].value;
    if (!pass || !pass2) {
      alert(lang['allrequired']);
      return;
    }
    if (pass != pass2) {
      alert(lang['passnotmatch']);
      return;
    }
    if (!pass_regex.test(pass)) {
      alert(lang['passlenmin'] + '\n' + lang['passrules']);
      return;
    }
  } else {
    if (!confirmedDelete(login)) {
      return;
    }
  }
  var xhr = getXHR();
  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
      var error = true;
      var message = '';
      if (xhr.status == 200) {
        var xml = xhr.responseXML;
        if (xml) {
          var root = xml.getElementsByTagName('root');
          if (root.length && getNode(root[0], 'error') == 0) {
            removeModal();
            alert(lang['actionsuccess']);
            if (action == 'delete') {
              // select current user in users form
              var f = document.getElementsByName('user')[0];
              f.remove(f.selectedIndex);
              selectUser(f);
            }
            error = false;
          } else if (root.length) {
            errorMsg = getNode(root[0], 'message');
            if (errorMsg) { message = errorMsg; }
          }
        }
      }
      if (error) {
        alert(lang['actionfailure'] + '\n' + message);
      }
      xhr = null;
    }
  }
  xhr.open('POST', 'utils/handleuser.php', true);
  xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  var params = 'action=' + action + '&login=' + encodeURIComponent(login) + '&pass=' + encodeURIComponent(pass);
  params = params.replace(/%20/g, '+');
  xhr.send(params);
  return;
}

Chrome says that xhr.send(params); is responsible for creating the internal server error. Combining that with the error seen in Firefox, apparently the handleuser.php thinks it has an empty string, though it actually processes the request correctly.

bfabiszewski commented 4 years ago

Strange. I see you also reported problems in two other important functions. This makes me believe you have some problem with system setup, maybe a database issue.

Do you use latest git version, or some older release? How did you install? Which version of PHP? Which database engine and database version?

theAkito commented 4 years ago

@bfabiszewski

PostgreSQL: 11 Git: 2.20.1 PHP: 7.3.9

Above packages are the standard stable packages you get for the Raspberry Pi running on Buster.

I was following the absolutely terrible and agonizing installation instructions in the README.md file. Yesterday, after ~5 hours of setting up the server, I somehow managed to make it run just to see how in the end, not even a single tracking dot is shown on the map. I am still frustrated with the setup, as this was definitely uncalled for.

bfabiszewski commented 4 years ago

I assume you are using latest git version of ulogger-server and you followed instructions in this README. As you say it took you 5 hours you obviously ran into some problems. What exactly went wrong during setup?

bfabiszewski commented 4 years ago

Looking at the errors you get your PHP may not have XML support. Please make sure to install php-xml package or any respective package for your distro.

theAkito commented 4 years ago

What exactly went wrong during setup?

Please make sure to install php-xml package

https://github.com/bfabiszewski/ulogger-server#requirements

Things like this aren't even mentioned. That is the problem with the instructions. The instructions are only meaningful if you actually made the software yourself (which you did) but for someone who looks at it from outside, it is meaningless.

https://github.com/bfabiszewski/ulogger-server#install

Make sure you have a web server running with PHP and chosen database

For example this one bullet point is something that should be explained in detail, in like 10 bullet points, at least. There is no need to explain a basic set up much, but at least give a hint on what you mean by that.

Create a copy of config.default.php and rename it to config.php. Customize it and add database credentials

What do you mean by customize it? I added the credentials and what else could I customize there? Also why is there a database password? It should say database user password.

I also had an error saying driver not found, check your config.php which I worked on for 1 hour just to find out that I misspelled pgsql like psql, because I had the config file on a really small monitor with bad resolution. Why is this error not clearer? Speaking of errors, Something went wrong is the worst possible error description in the software world.

Move it to your web server directory (unzip if needed)

You could at least mention something like /var/www. Preferably also mention how one could also change the root directive within an Nginx config to your target directory, for example.

The point is, that I tried to set up ulogger about half a year ago. > Did not work. I tried to set it up a couple of months ago, again. > Did not work.

Yesterday, I said that I will finish it so I sat on it for about 5 hours to actually make it work. After all, I don't need this server anymore, because it has disappointed me too much, but I wanted to finish successfully and win the challenge.

This is one of the hardest server set ups I ever had to accomplish. I think the only one that was tougher was setting up Mattermost with a custom compiled PHP.

I have more than 20 different servers running at my home and none of them was as hard to set up as this one (no, I don't use Docker for my servers, at all), mainly because of lacking documentation. Now, after 5 hours of hard work, I get to understand the software and understand its quirks, but this should not be mandatory. One should just point and click and let it install by itself, even if you don't use Docker.

That said, your app description on F-Driod makes different claims than the server mentions. It is confusing as to what ulogger actually does.

bfabiszewski commented 4 years ago

I am sorry you feel disappointed. Maybe some day I will manage to make better documentation. Or someone else finds time to contribute it. Now that is all I can do with the limited time I have.