1<?php
2
3$fopenAllowed = ini_get('allow_url_fopen');
4
5if (!empty($_POST['apikey'])) {
6    if (!verifyToken()) {
7        echo Error($GLOBALS['I18N']->get('No Access'));
8
9        return;
10    }
11    $streamContext = stream_context_create(array(
12        'http' => // even though we use https, this has to be http
13            array(
14                'timeout' => 10, // this should be fast, so let's not wait too long
15            ),
16    ));
17
18    $check = @file_get_contents(PQAPI_URL.'&cmd=verifykey&key='.trim($_POST['apikey']), false, $streamContext);
19    $check = trim($check);
20    if (!empty($check) && strpos($check, 'KEYPASS') !== false) {
21        SaveConfig('PQAPIkey', trim(str_replace('"', '', strip_tags($_POST['apikey']))), 0);
22        SaveConfig('pqchoice', 'phplistdotcom', 0);
23        //# if we have active campaigns, start them now
24        $_SESSION['action_result'] = s('Remote queue processing settings were saved successfully');
25        $count = Sql_Fetch_Row_Query(sprintf("select count(*) from %s where status not in ('draft', 'sent', 'prepared', 'suspended') and embargo <= now()",
26            $tables['message']));
27        if ($count[0] > 0) {
28            $_SESSION['action_result'] .= '<br/>'.activateRemoteQueue();
29        }
30        Redirect('messages&tab=active');
31    } else {
32        if (!empty($http_response_header[0]) && strpos($http_response_header[0], '200 OK') !== false) {
33            $_SESSION['action_result'] = s('Error, the API key is incorrect');
34        } else {
35            $_SESSION['action_result'] = s('Error, unable to connect to the phpList.com server for checking. Please verify that your webserver is able to connect to https://pqapi.phplist.com').'<br/><a href="./?page=processqueue&pqchoice=local" class="button">'.s('Use local processing instead').'</a>';
36        }
37        Redirect('hostedprocessqueuesetup');
38    }
39}
40
41$existingKey = getConfig('PQAPIkey');
42
43echo '<h2>'.s('Process the queue using the service from phpList.com').'</h2>';
44
45if ($fopenAllowed) {
46    echo '<p>'.s('This is only possible if your phpList installation is not behind a firewall').'</p>';
47} else {
48    echo '<p>'.s('Your PHP settings do not allow this functionality. Please set "allow_url_fopen" in your php.ini to be "on" to continue.').'</p>';
49    echo '  <a href="./?page=processqueue&pqchoice=local" class="button">'.s('Use local processing instead').'</a>';
50
51    return;
52}
53echo formStart();
54
55echo '<h3>Step 1. Create an account on phpList.com </h3>';
56echo '<p>For the purpose of remote processing go to <a href="https://www.phplist.com/createaccount" target="_blank" class="button">Create Account</a> and follow the steps.</p>';
57echo '<p>If you use the normal registration procedure it will create a phpList Hosted account for you, which is not what you need for remote processing.</p>';
58echo '<p>Once you are registered, go to your account page and request an API key</p>';
59echo '<h3>Step 2. Enter the API key here</h3>';
60
61echo '<label for="apikey">'.s('API key from phpList.com').'</label><input type="text" name="apikey" value="'.$existingKey.'">';
62echo '<button type="submit" class="button">'.s('Continue setup').'</button>';
63echo '</form>';
64