Subversion Repositories portal2

Rev

Rev 699 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/*  emg - Energy Monitoring & Graphing
*  Copyright (C) 2006-2012 Romain Lievin
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

?>

<?php
include_once('auth_check.php');
?>

<?php

//var_dump($_POST);

$form_token = md5(uniqid('auth', true));
$_SESSION['form_token'] = $form_token;

$error = new Error();

if(!isset($_POST['form_device_key']))
{
        $error->push(_('One or more fields are missing.'));
}

/*** check the device name is the correct length ***/
elseif(strlen( $_POST['form_device_key']) > 64 || strlen($_POST['form_device_key']) < 4)
{
        $error->push(_('Name must have [4-64] characters.'));
}

else
{
        // retrieve device name
        $form_device_key = filter_var($_POST['form_device_key'], FILTER_SANITIZE_STRING);

        // retrieve device
        $park            = $_SESSION['park'];
        $device          = $park->getDevice($form_device_key);

        $form_device_name= $device->getName();
        $form_device_url = $device->getRoute()->getTarget();
        $form_device_type= $device->getRoute()->getType();

        if($device->getRoute()->getType() != RouteFactory::FILE)
        {
                $form_device_ssl_enabled = $device->getRoute()->get_ssl_enabled();
                $form_device_ssl_crt     = $device->getRoute()->get_ssl_crt();
                $form_device_ssl_key     = $device->getRoute()->get_ssl_key();
                $form_device_ssl_ca      = $device->getRoute()->get_ssl_ca();
        }
        else
        {
                $form_device_ssl_enabled = '';
                $form_device_ssl_crt     = '';
                $form_device_ssl_key     = '';
                $form_device_ssl_ca      = '';
        }

        $iterator = new DirectoryIterator($_SESSION['root_folder']['ssl']['']);
        foreach($iterator as $fileinfo)
        {
                if($fileinfo->isFile())
                {
                        $filename = $fileinfo->getFilename();

                        if($filename == '.' || $filename == '..')
                        {
                                continue;
                        }

                        $filename = $fileinfo->getFilename();
                        //echo "[$filename]";                           echo " < br/>";

                        if(!strcmp($filename, 'ca.crt'))
                        {
                                $form_device_ssl_ca = $filename;
                        }
                        else
                        if(strstr($filename, '.key') !== false)
                        {
                                $form_device_ssl_key = $filename;
                        }
                        else
                        if(strstr($filename, '.crt') !== false)
                        {
                                $form_device_ssl_crt = $filename;
                        }
                }
        }
}
?>

<div id="page_form_devices_modify">
        <h1>
                <?php echo _('Modify device'); ?>
        </h1>

        <?php

        $id = link_get_id_from_filename("form_devices_modify_submit.php");
        echo "<form action=\"index.php?id_page=$id\" method=\"post\">";
        ?>
        <fieldset>
                <legend>
                        <?php echo _('Information'); ?>
                </legend>

                <label for="form_device_name">
                        <?php echo _('Name'); ?>:
                </label>
                <input type="text" id="form_device_name" name="form_device_name" value=<?php echo "\"$form_device_name\""; ?> />
                <br/>

                <label for="form_device_url">
                        <?php echo _('URL'); ?>:
                </label>
                <input type="text" id="form_device_ipaddr" name="form_device_url" value=<?php echo "\"$form_device_url\""; ?> />
                <br/>

                <label for="form_device_ssl_enabled">
                        <?php echo _('SSL enabled'); ?>
                </label>
                <input type="checkbox" id="form_device_ssl_enabled" name="form_device_ssl_enabled" <?php
                if($form_device_ssl_enabled) echo "checked=\"checked\""; ?> />

                <div id="form_device_subpart">
                        <br/>
                        <label for="form_device_ssl_crt">
                                <?php echo _('SSL certificate'); ?>:
                        </label>
                        <input type="text" id="form_device_ssl_crt" name="form_device_ssl_crt" value=<?php echo "\"$form_device_ssl_crt\""; ?> readonly  />
                        <br/>

                        <label for="form_device_ssl_key">
                                <?php echo _('SSL key'); ?>:
                        </label>
                        <input type="text" id="form_device_ssl_key" name="form_device_ssl_key" value=<?php echo "\"$form_device_ssl_key\""; ?> readonly  />
                        <br/>

                        <label for="form_device_ssl_ca">
                                <?php echo _('SSL CA'); ?>:
                        </label>
                        <input type="text" id="form_device_ssl_ca" name="form_device_ssl_ca" value=<?php echo "\"$form_device_ssl_ca\""; ?> readonly  />
                        <br/>
                </div>

                <hr/>
                <div class="buttons">
                        <input type="hidden" name="form_device_type" value="<?php echo $form_device_type; ?>" />
                        <input type="hidden" name="form_device_key" value="<?php echo $form_device_key; ?>" />
                        <input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />
                        <input type="submit" value=<?php echo _('OK'); ?> id="form_device_modify" name="form_device_modify" alt="update" />
                        <input type="submit" value=<?php echo _('Cancel');?> id="form_device_cancel" name="form_device_cancel" alt="cancel" />
                </div>

        </fieldset>

        <?php

        if($form_device_ssl_ca == '' || $form_device_ssl_key == '' || $form_device_ssl_crt == '')
        {
                $error->push(_('One or more certificates files are missing. You will not be able to enable SSL connection.'));
        }
        ?>

        </form>

        <?php echo $error->display(); ?>

</div>

<script src="form_devices_add.js">
</script>