uiconfig.php
changeset 71 8663af0e27c7
parent 64 ee64bb096f56
child 78 08f8a72b1f7b
equal deleted inserted replaced
70:efabb54a418d 71:8663af0e27c7
    53     }
    53     }
    54   }
    54   }
    55   
    55   
    56   if ( $authed && isset($_POST['submit']) )
    56   if ( $authed && isset($_POST['submit']) )
    57   {
    57   {
       
    58     $tried = true;
    58     $need_reboot = ( isset($_POST['public']) !== $GLOBALS['public'] ||
    59     $need_reboot = ( isset($_POST['public']) !== $GLOBALS['public'] ||
       
    60                      isset($_POST['ipv6']) !== $GLOBALS['enable_ipv6'] ||
    59                      isset($_POST['allow_fork']) !== $GLOBALS['allow_fork']);
    61                      isset($_POST['allow_fork']) !== $GLOBALS['allow_fork']);
    60     
    62     
    61     // compile the new config file
    63     // compile the new config file
    62     $public = ( isset($_POST['public']) ) ? 'true' : 'false';
    64     $public = ( isset($_POST['public']) ) ? 'true' : 'false';
    63     $allowcontrol = ( isset($_POST['allowcontrol']) ) ? 'true' : 'false';
    65     $allowcontrol = ( isset($_POST['allowcontrol']) ) ? 'true' : 'false';
    64     $allow_fork = ( isset($_POST['allow_fork']) ) ? 'true' : 'false';
    66     $allow_fork = ( isset($_POST['allow_fork']) ) ? 'true' : 'false';
    65     $use_auth = ( isset($_POST['use_auth']) ) ? 'true' : 'false';
    67     $use_auth = ( isset($_POST['use_auth']) ) ? 'true' : 'false';
       
    68     $ipv6_settings = ( isset($_POST['ipv6']) ) ? '$GLOBALS[\'enable_ipv4\'] = false;
       
    69 $GLOBALS[\'enable_ipv6\'] = true;' : '$GLOBALS[\'enable_ipv4\'] = true;
       
    70 $GLOBALS[\'enable_ipv6\'] = false;';
       
    71     $GLOBALS['enable_ipv6'] = isset($_POST['ipv6']);
    66     
    72     
    67     // for auth_data, we're going to merge the data from POST with the current auth_data array.
    73     // for auth_data, we're going to merge the data from POST with the current auth_data array.
    68     $auth_data = $GLOBALS['auth_data'];
    74     $auth_data = $GLOBALS['auth_data'];
    69     $auth_changed = false;
    75     $auth_changed = false;
    70     foreach ( $auth_data as $user => $pass )
    76     if ( isset($_POST['users']) )
    71     {
    77     {
    72       if ( !in_array($user, $_POST['users']) )
    78       foreach ( $auth_data as $user => $pass )
    73       {
    79       {
       
    80         if ( !in_array($user, $_POST['users']) )
       
    81         {
       
    82           $auth_changed = true;
       
    83           unset($auth_data[$user]);
       
    84         }
       
    85       }
       
    86     }
       
    87     else
       
    88     {
       
    89       if ( !empty($auth_data) )
       
    90       {
       
    91         $auth_data = array();
    74         $auth_changed = true;
    92         $auth_changed = true;
    75         unset($auth_data[$user]);
    93       } 
    76       }
       
    77     }
    94     }
    78     if ( isset($_POST['users_add']) )
    95     if ( isset($_POST['users_add']) )
    79     {
    96     {
    80       foreach ( $_POST['users_add'] as $user => $pass )
    97       foreach ( $_POST['users_add'] as $user => $pass )
    81       {
    98       {
    83         $auth_data[$user] = $pass;
   100         $auth_data[$user] = $pass;
    84       }
   101       }
    85     }
   102     }
    86     $auth_data = var_export_string($auth_data);
   103     $auth_data = var_export_string($auth_data);
    87     
   104     
    88     $new_configpass = ( isset($_POST['configpass']) && is_string($_POST['newconfigpass']) && $_POST['newconfigpass'] != '____________________' ) ? sha1($_POST['newconfigpass']) : $GLOBALS['configpass'];
   105     $new_configpass = ( isset($_POST['newconfigpass']) && is_string($_POST['newconfigpass']) && $_POST['newconfigpass'] != '____________________' ) ? sha1($_POST['newconfigpass']) : $GLOBALS['configpass'];
       
   106     if ( isset($_POST['newconfigpass']) && $_POST['newconfigpass'] === true )
       
   107       $new_configpass = '';
       
   108     
       
   109     $needpass = ( $new_configpass != '' );
    89     
   110     
    90     $config_file = <<<EOF
   111     $config_file = <<<EOF
    91 <?php
   112 <?php
    92 
   113 
    93 //
   114 //
   117 // valid users and passwords
   138 // valid users and passwords
   118 \$GLOBALS['auth_data'] = $auth_data;
   139 \$GLOBALS['auth_data'] = $auth_data;
   119 
   140 
   120 // password for site configuration
   141 // password for site configuration
   121 \$GLOBALS['configpass'] = '$new_configpass';
   142 \$GLOBALS['configpass'] = '$new_configpass';
       
   143 
       
   144 // IPv4 and IPv6
       
   145 $ipv6_settings
   122 
   146 
   123 EOF;
   147 EOF;
   124     $error = 'Couldn\'t write to the config file (./greyhound-config.php).';
   148     $error = 'Couldn\'t write to the config file (./greyhound-config.php).';
   125     
   149     
   126     $fp = @fopen('./greyhound-config.php', 'w');
   150     $fp = @fopen('./greyhound-config.php', 'w');
   134       {
   158       {
   135         $rebootblurb = $need_reboot ? "\n<small>Since you changed some core configuration values, the Greyhound server has been restarted.</small>\n<small>If Greyhound doesn't respond, wait 20 seconds and then restart it using Amarok's script manager.</small>" : '';
   159         $rebootblurb = $need_reboot ? "\n<small>Since you changed some core configuration values, the Greyhound server has been restarted.</small>\n<small>If Greyhound doesn't respond, wait 20 seconds and then restart it using Amarok's script manager.</small>" : '';
   136       }
   160       }
   137       else
   161       else
   138       {
   162       {
   139         $rebootblurb = $need_reboot ? "\n<small>Please restart Greyhound using Amarok's script manager for public IP and multithreading options to take effect.</small>" : '';
   163         $rebootblurb = $need_reboot ? "\n<small>Please restart Greyhound using Amarok's script manager for public IP, multithreading, and IPv6 options to take effect.</small>" : '';
   140       }
   164       }
   141       $success = "Configuration changes successful.{$passblurb}{$rebootblurb}";
   165       $success = "Configuration changes successful.{$passblurb}{$rebootblurb}";
   142       $httpd->threader->ipc_send(array('action' => 'reloadconfig', 'propagate' => true));
   166       if ( $httpd->threader->is_child() )
       
   167       {
       
   168         $httpd->threader->ipc_send(array('action' => 'reloadconfig', 'propagate' => true));
       
   169       }
       
   170       else
       
   171       {
       
   172         grey_reload_config();
       
   173       }
   143       
   174       
   144       if ( $need_reboot && REBOOT_SUPPORT )
   175       if ( $need_reboot && REBOOT_SUPPORT )
   145       {
   176       {
   146         $addr = $GLOBALS['public'] ? '0.0.0.0' : '127.0.0.1';
   177         if ( $GLOBALS['enable_ipv6'] )
   147         $fork = $GLOBALS['allow_fork'];
   178         {
       
   179           $addr = isset($_POST['public']) ? '::' : '::1';
       
   180         }
       
   181         else
       
   182         {
       
   183           $addr = isset($_POST['public']) ? '0.0.0.0' : '127.0.0.1';
       
   184         }
       
   185         $fork = isset($_POST['allow_fork']);
   148         $httpd->reboot($addr, null, $fork);
   186         $httpd->reboot($addr, null, $fork);
   149       }
   187       }
   150     }
   188     }
   151   }
   189   }
   152   
   190   
   165   $smarty->assign('tried', $tried);
   203   $smarty->assign('tried', $tried);
   166   $smarty->assign('success', $success);
   204   $smarty->assign('success', $success);
   167   $smarty->assign('needpass', $needpass);
   205   $smarty->assign('needpass', $needpass);
   168   $smarty->assign('use_auth', $use_auth);
   206   $smarty->assign('use_auth', $use_auth);
   169   $smarty->assign('public', $GLOBALS['public']);
   207   $smarty->assign('public', $GLOBALS['public']);
       
   208   $smarty->assign('ipv6', $GLOBALS['enable_ipv6']);
   170   $smarty->assign('allowcontrol', $GLOBALS['allowcontrol']);
   209   $smarty->assign('allowcontrol', $GLOBALS['allowcontrol']);
   171   $smarty->assign('allow_fork', $GLOBALS['allow_fork']);
   210   $smarty->assign('allow_fork', $GLOBALS['allow_fork']);
   172   $smarty->assign('use_auth', $GLOBALS['use_auth']);
   211   $smarty->assign('use_auth', $GLOBALS['use_auth']);
   173   $smarty->assign('users', $GLOBALS['auth_data']);
   212   $smarty->assign('users', $GLOBALS['auth_data']);
       
   213   $smarty->assign('reboot_support', REBOOT_SUPPORT);
   174   $smarty->assign('error', $error);
   214   $smarty->assign('error', $error);
   175   $smarty->display('config.tpl');
   215   $smarty->display('config.tpl');
   176 }
   216 }