networking.php 5.77 KB
Newer Older
1 2 3 4 5
<?php
/**
 *
 * @package    mahara
 * @subpackage admin
6
 * @author     Catalyst IT Ltd
7 8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
9 10 11 12 13
 *
 */

define('INTERNAL', 1);
define('ADMIN', 1);
14
define('MENUITEM', 'configsite/networking');
15 16 17
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'networking');
18 19

require(dirname(dirname(dirname(__FILE__))) . '/init.php');
20
require_once(get_config('docroot') . 'api/xmlrpc/lib.php');
21 22 23 24
require_once('pieforms/pieform.php');
require_once('searchlib.php');
define('TITLE', get_string('networking', 'admin'));

25 26 27 28 29 30 31 32 33 34 35
$opensslext = extension_loaded('openssl');
$curlext    = extension_loaded('curl');
$xmlrpcext  = extension_loaded('xmlrpc');

if (!$opensslext || !$curlext || !$xmlrpcext) {
    $smarty = smarty();
    $missingextensions = array();
    !$opensslext && $missingextensions[] = 'openssl';
    !$curlext    && $missingextensions[] = 'curl';
    !$xmlrpcext  && $missingextensions[] = 'xmlrpc';
    $smarty->assign('missingextensions', $missingextensions);
36
    $smarty->display('admin/site/networking.tpl');
37 38 39
    exit;
}

40 41 42 43 44 45 46 47 48 49
$openssl = OpenSslRepo::singleton();

$yesno = array(true  => get_string('yes'),
               false => get_string('no'));

$networkingform = pieform(
    array(
        'name'     => 'networkingform',
        'jsform'   => true,
        'elements' => array(
50 51 52
            'wwwroot' => array(
                'type'         => 'html',
                'title'        => get_string('wwwroot','admin'),
53
                'description'  => get_string('wwwrootdescription', 'admin'),
54 55
                'value'        => get_config('wwwroot')
            ),
56 57 58
            'pubkey' => array(
                'type'         => 'html',
                'title'        => get_string('publickey','admin'),
59
                'description'  => get_string('publickeydescription2', 'admin', 365),
60
                'value'        => '<pre style="font-size: 0.7em; white-space: pre;">'.$openssl->certificate.'</pre>'
61
            ),
62 63 64 65 66 67 68 69 70 71
            'sha1fingerprint' => array(
                'type'         => 'html',
                'title'        => 'SHA1 Fingerprint',
                'value'        => $openssl->sha1_fingerprint
            ),
            'md5fingerprint' => array(
                'type'         => 'html',
                'title'        => 'MD5 Fingerprint',
                'value'        => $openssl->md5_fingerprint
            ),
72 73 74
            'expires' => array(
                'type'         => 'html',
                'title'        => get_string('publickeyexpires','admin'),
75
                'value'        => format_date($openssl->expires)
76 77 78 79 80 81 82 83
            ),
            'enablenetworking' => array(
                'type'         => 'select',
                'title'        => get_string('enablenetworking','admin'),
                'description'  => get_string('enablenetworkingdescription','admin'),
                'defaultvalue' => get_config('enablenetworking'),
                'options'      => $yesno,
            ),
84 85 86 87 88 89 90
            'promiscuousmode' => array(
                'type'         => 'select',
                'title'        => get_string('promiscuousmode','admin'),
                'description'  => get_string('promiscuousmodedescription','admin'),
                'defaultvalue' => get_config('promiscuousmode'),
                'options'      => $yesno,
            ),
91 92 93
            'submit' => array(
                'type'  => 'submit',
                'value' => get_string('savechanges','admin')
94 95 96 97 98
            ),
            'deletesubmit' => array(
                'type'  => 'submit',
                'title' => get_string('deletekey', 'admin'),
                'value' => get_string('delete')
99 100 101 102 103 104
            )
        )
    )
);

function networkingform_fail(Pieform $form) {
105 106 107 108
    $form->reply(PIEFORM_ERR, array(
        'message' => get_string('enablenetworkingfailed','admin'),
        'goto'    => '/admin/site/networking.php',
    ));
109 110 111
}

function networkingform_submit(Pieform $form, $values) {
112
    $reply = '';
Donal McMullan's avatar
WIP  
Donal McMullan committed
113

114 115 116 117 118 119 120 121 122 123 124
    if (isset($values['deletesubmit'])) {
        global $SESSION;
        $openssl = OpenSslRepo::singleton();
        $openssl->get_keypair(true);
        $SESSION->add_info_msg(get_string('keydeleted', 'admin'));
        // Using cancel here as a hack to get it to redirect so it shows the new keys
        $form->reply(PIEFORM_CANCEL, array(
            'location'    => get_config('wwwroot') . 'admin/site/networking.php'
        ));
    }

125 126 127
    if (get_config('enablenetworking') != $values['enablenetworking']) {
        if (!set_config('enablenetworking', $values['enablenetworking'])) {
            networkingform_fail($form);
128 129
        }
        else {
130
            if (empty($values['enablenetworking'])) {
131
                $reply .= get_string('networkingdisabled','admin');
132 133
            }
            else {
134
                $reply .= get_string('networkingenabled','admin');
135 136
            }
        }
137 138
    }

139 140 141
    if (get_config('promiscuousmode') != $values['promiscuousmode']) {
        if (!set_config('promiscuousmode', $values['promiscuousmode'])) {
            networkingform_fail($form);
142 143
        }
        else {
144
            if (empty($values['promiscuousmode'])) {
145
                $reply .= get_string('promiscuousmodedisabled','admin');
146 147
            }
            else {
148
                $reply .= get_string('promiscuousmodeenabled','admin');
149 150
            }
        }
151
    }
152

153 154 155 156
    $form->reply(PIEFORM_OK, array(
        'message' => ($reply == '') ? get_string('networkingunchanged','admin') : $reply,
        'goto'    => '/admin/site/networking.php',
    ));
157 158 159
}

$smarty = smarty();
160
$smarty->assign('networkingform', $networkingform);
161
$smarty->assign('PAGEHEADING', TITLE);
162
$smarty->display('admin/site/networking.tpl');