function askNntpSettings() { global $settings; global $_testInstall_Ok; $serverList = simplexml_load_file('usenetservers.xml'); $form = array('name' => 'custom', 'host' => '', 'user' => '', 'pass' => '', 'port' => 119, 'enc' => false, 'submit' => ''); if (isset($_POST['nntpform'])) { $form = array_merge($form, $_POST['nntpform']); } # if /* * Dit the user press submit? If so, try to * connect to the database */ $nntpVerified = false; if ($form['submit'] === 'Verify usenet server') { try { /* * Convert the selected NNTP name to an actual * server record. */ if ($form['name'] == 'custom') { $form['buggy'] = false; $form['hdr'] = $form; $form['nzb'] = $form; $form['post'] = $form; } else { foreach ($serverList->usenetservers->server as $provider) { if (extension_loaded('openssl') && isset($provider->ssl)) { $server = $provider->ssl; } else { $server = $provider->plain; } # if if ((string) $provider['name'] == $form['name']) { # Header usenet server $form['hdr']['host'] = (string) $server->header; $form['hdr']['user'] = $form['user']; $form['hdr']['pass'] = $form['pass']; if ((string) $server->header['ssl'] == 'yes') { $form['hdr']['enc'] = 'ssl'; } else { $form['hdr']['enc'] = false; } # else $form['hdr']['port'] = (int) $server->header['port']; $form['hdr']['buggy'] = (bool) $server['buggy']; # NZB usenet server $form['nzb']['host'] = (string) $server->nzb; $form['nzb']['user'] = $form['user']; $form['nzb']['pass'] = $form['pass']; if ((string) $server->nzb['ssl'] == 'yes') { $form['nzb']['enc'] = 'ssl'; } else { $form['nzb']['enc'] = false; } # else $form['nzb']['port'] = (int) $server->nzb['port']; $form['nzb']['buggy'] = (bool) $server['buggy']; # Posting usenet server $form['post']['host'] = (string) $server->post; $form['post']['user'] = $form['user']; $form['post']['pass'] = $form['pass']; if ((string) $server->post['ssl'] == 'yes') { $form['post']['enc'] = 'ssl'; } else { $form['post']['enc'] = false; } # else $form['post']['port'] = (int) $server->post['port']; $form['post']['buggy'] = (bool) $server['buggy']; } # if } # foreach } # else /* and try to connect to the usenet server */ $nntp = new SpotNntp($form['hdr']); $nntp->validateServer(); $nntpVerified = true; /* * Store the given NNTP settings in the * SESSION object, we need it later to update * the settings in the database */ $_SESSION['spotsettings']['nntp'] = $form; /* * and call the next stage in the setup */ Header("Location: " . $_SERVER['SCRIPT_NAME'] . '?page=3'); } catch (Exception $x) { ?> <div id='error'><?php echo $x->getMessage(); ?> <br /><br /> Please correct the errors in below form and try again </div> <?php } # exception } # if if (!$nntpVerified) { ?> <form name='nntpform' method='POST'> <table summary="PHP settings"> <tr> <th> Usenet server settings </th> <th> </th> </tr> <tr> <td colspan='2'> Spotweb needs an usenet server. We have several usenet server profiles defined from which you can choose. If your server is not listed, please choose 'custom', more advanced options can be set from within Spotweb itself. </td> </tr> <tr> <td> Usenet server </td> <td> <select id='nntpselectbox' name='nntpform[name]' onchange='toggleNntpField();'> <?php foreach ($serverList->usenetservers->server as $provider) { $server = ''; /* Make sure the server is supported, eg filter out ssl only servers when openssl is not loaded */ if (extension_loaded('openssl') && isset($provider->ssl)) { $server = $provider->ssl; } elseif (isset($provider->plain)) { $server = $provider->plain; } # if if (!empty($server)) { echo "<option value='{$provider['name']}'" . ($provider['name'] == $form['name'] ? "selected='selected'" : '') . ">{$provider['name']}</option>"; } # if } # foreach ?> <option value='custom'>Custom</option> </select> </td> </tr> <tr id='customnntpfield' style='display: none;'> <td> server </td> <td> <input type='text' length='40' name='nntpform[host]' value='<?php echo htmlspecialchars($form['host']); ?> '></input> </td> </tr> <tr> <td> username </td> <td> <input type='text' length='40' name='nntpform[user]' value='<?php echo htmlspecialchars($form['user']); ?> '></input> </td> </tr> <tr> <td> password </td> <td> <input type='password' length='40' name='nntpform[pass]' value='<?php echo htmlspecialchars($form['pass']); ?> '></input> </td> </tr> <tr> <td colspan='2'> <input type='submit' name='nntpform[submit]' value='Verify usenet server'> </td> </tr> </table> </form> <br /> <?php } # else }
function validateNntpServer($server) { $result = ''; try { $testNntp = new SpotNntp($server); $testNntp->validateServer(); } catch (Exception $x) { $result = $x->getMessage(); } # catch return $result; }