MasterVitronic / fusionpbx

Automatically exported from code.google.com/p/fusionpbx
0 stars 0 forks source link

Deleting install-time domain crashes fusionpbx #467

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Install latest using sqlite or postgres.
2. Add a couple of new tenants/domains, populate them, test them.
3. Delete the useless domain installed out of the box.

What is the expected output? What do you see instead?
Expected after "delete completed" normal operations.
Got:

Fatal error: Call to a member function fetchAll() on a non-object in 
/var/www/fusionpbx/resources/switch.php on line 172

What version of the product are you using? On what operating system?
Latest, new install, Ubuntu 13.04 server

Please provide any additional information below.
Relevant code below.  The problem is that '$_SESSION['domain_uuid']' used below 
is null after the domain is deleted.

               if (strlen($_SESSION["user_uuid"]) > 0 && count($_SESSION['user']['extension']) == 0) {
                        //get the user extension list
                                unset($_SESSION['user']['extension']);
                                $sql = "select e.extension, e.user_context, e.extension_uuid, e.outbound_caller_id_name, e.outbound_caller$
                                $sql .= "where e.domain_uuid = '".$_SESSION['domain_uuid']."' ";
                                $sql .= "and e.extension_uuid = u.extension_uuid ";
                                $sql .= "and u.user_uuid = '".$_SESSION['user_uuid']."' ";
                                $sql .= "and e.enabled = 'true' ";
                                $sql .= "order by e.extension asc ";
                                $result = $db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
                                if (count($result) > 0) {

Original issue reported on code.google.com by hgc...@gmail.com on 2 Oct 2013 at 7:21

GoogleCodeExporter commented 9 years ago
3. Delete the useless domain installed out of the box.

I don't think it is wise to delete the domain you are currently logged into. 
When you do the install your users accounts are assigned to that domain. If you 
delete it your account are deleted too. If you want to delete that domain then 
add a different domain add user accounts to a different domain then login to 
that domain and then delete the original domain.

If you want the first domain to be valid from the beginning then when you run 
the install.php part of the installation use a valid domain that you intend to 
use. Rather than an ip address or something you don't want to use.

Original comment by markjcrane@gmail.com on 2 Oct 2013 at 7:33

GoogleCodeExporter commented 9 years ago
Thanks for the reply.

Some thoughts:

I saw the old domain which had no use was cluttering up the screen, so I used 
the command to delete it and got the crash.  A hard crash too.  Only patching 
the code or going to an earlier snapshot of the whole OS could recover it.  No 
web interface possible.  Even though the domains I created had users, 
extensions and so on.  
There should be no way to make the system hard crash from the GUI.  Most would 
assume that the installtime 'superadmin' exists and would work even if there 
weren't any domains.  Or that the domain deletion command would report that it 
couldn't run if doing so would crash the system.

It would be good if somewhere in install.php it asked the question or 
documented a variable about the preferred default / original domain.

You might imagine a great many users in home offices would like one fusionpbx 
install, with a domain for the family and another for the home office.  Folk 
want to register to a dns name, not a dotted quad ipv4, soon to be gone in 
favor of ipv6.

Original comment by hgc...@gmail.com on 2 Oct 2013 at 7:43

GoogleCodeExporter commented 9 years ago
Even creating a superadmin@newtenantdomain account, then logging in as such, 
then deleting the totally unused original domain hard crashes fusionpbx so that 
no recovery is possible, not even a reboot.  Only a re-install or revert to 
backups.

I think you might better change this to a defect.  It shouldn't be possible to 
no-recovery hard-crash the system.

Original comment by hgc...@gmail.com on 2 Oct 2013 at 8:12

GoogleCodeExporter commented 9 years ago
Here's a patch:

              if (strlen($_SESSION["user_uuid"]) > 0 && count($_SESSION['user']['extension']) == 0) {
                        //get the user extension list
                                unset($_SESSION['user']['extension']);
//New line:
                                if (strlen($_SESSION['domain_uuid'])>0) {
                                  $sql = "select e.extension, e.user_context, e.extension_uuid, e.outbound_caller_id_name, $
                                  $sql .= "where e.domain_uuid = '".$_SESSION['domain_uuid']."' ";
                                  $sql .= "and e.extension_uuid = u.extension_uuid ";
                                  $sql .= "and u.user_uuid = '".$_SESSION['user_uuid']."' ";
                                  $sql .= "and e.enabled = 'true' ";
                                  $sql .= "order by e.extension asc ";
                                  $result = $db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
                                  if (count($result) > 0) {
                                        $x = 0;
                                        foreach($result as $row) {
                                                $_SESSION['user']['extension'][$x]['user'] = $row['extension'];
                                                $_SESSION['user']['extension'][$x]['extension_uuid'] = $row['extension_uuid$
                                                $_SESSION['user']['extension'][$x]['outbound_caller_id_name'] = $row['outbo$
                                                $_SESSION['user']['extension'][$x]['outbound_caller_id_number'] = $row['out$
                                                $_SESSION['user_context'] = $row["user_context"];
                                                $x++;
                                        }
//New Line
                                  }
                                }

Original comment by hgc...@gmail.com on 2 Oct 2013 at 9:14

GoogleCodeExporter commented 9 years ago
Added some additional measures, with r6064 and r6065, to prevent the deletion 
of current user account and/or domain.  Tested with single-tenant and 
multi-tenant system on Ubuntu 13.10, including the scenario mentioned by 
hgcoin's #3 comment.  

The result experienced when attempting to delete the initial domain after 
install may have been resolved in an earlier revision.  Please upgrade to the 
latest revision and advise if further issues with this topic exist.

Original comment by sevenate on 17 Jun 2014 at 10:48