Merge pull request #2293 from fraenki/plugins_1586

add new plugin: emulators/qemu-guest-agent
This commit is contained in:
Frank Wall
2021-03-22 12:03:47 +01:00
committed by GitHub
16 changed files with 491 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
PLUGIN_NAME= qemu-guest-agent
PLUGIN_VERSION= 0.1
PLUGIN_DEVEL= yes
PLUGIN_COMMENT= QEMU Guest Agent for OPNsense
PLUGIN_DEPENDS= qemu-guest-agent
PLUGIN_MAINTAINER= opnsense@moov.de
.include "../../Mk/plugins.mk"
+5
View File
@@ -0,0 +1,5 @@
QEMU Guest Agent for FreeBSD
Port homepage https://github.com/aborche/qemu-guest-agent
WWW: http://wiki.qemu.org/Main_Page
@@ -0,0 +1,70 @@
<?php
/**
* Copyright (C) 2021 Frank Wall
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function qemuguestagent_enabled()
{
global $config;
return isset($config['OPNsense']['QemuGuestAgent']['general']['Enabled']) &&
$config['OPNsense']['QemuGuestAgent']['general']['Enabled'] == 1;
}
/**
* register legacy service
* @return array
*/
function qemuguestagent_services()
{
$services = array();
if (!qemuguestagent_enabled()) {
return $services;
}
$services[] = array(
'description' => gettext('QEMU Guest Agent'),
'pidfile' => '/var/run/qemu-ga.pid',
'configd' => array(
'restart' => array('qemuguestagent restart'),
'start' => array('qemuguestagent start'),
'stop' => array('qemuguestagent stop'),
),
'name' => 'qemu-ga',
);
return $services;
}
function qemuguestagent_xmlrpc_sync()
{
$result = array();
$result['id'] = 'qemuguestagent';
$result['section'] = 'OPNsense.QemuGuestAgent';
$result['description'] = gettext('QEMU Guest Agent');
return array($result);
}
@@ -0,0 +1,46 @@
<?php
/**
* Copyright (C) 2021 Frank Wall
* Copyright (C) 2015 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\QemuGuestAgent\Api;
use OPNsense\Base\ApiMutableServiceControllerBase;
/**
* Class ServiceController
* @package OPNsense\QemuGuestAgent
*/
class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\OPNsense\QemuGuestAgent\QemuGuestAgent';
protected static $internalServiceTemplate = 'OPNsense/QemuGuestAgent';
protected static $internalServiceEnabled = 'general.Enabled';
protected static $internalServiceName = 'qemuguestagent';
}
@@ -0,0 +1,46 @@
<?php
/**
* Copyright (C) 2021 Frank Wall
* Copyright (C) 2015-2019 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\QemuGuestAgent\Api;
use OPNsense\Base\ApiMutableModelControllerBase;
use OPNsense\Core\Config;
use OPNsense\ZabbixAgent\ZabbixAgent;
/**
* settings controller for QemuGuestAgent
* @package OPNsense\QemuGuestAgent
*/
class SettingsController extends ApiMutableModelControllerBase
{
protected static $internalModelName = 'qemuguestagent';
protected static $internalModelClass = 'OPNsense\QemuGuestAgent\QemuGuestAgent';
}
@@ -0,0 +1,47 @@
<?php
/**
* Copyright (C) 2021 Frank Wall
* Copyright (C) 2015 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\QemuGuestAgent;
/**
* Class IndexController
* @package OPNsense\QemuGuestAgent
*/
class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
// pick the template to serve
$this->view->pick('OPNsense/QemuGuestAgent/index');
// fetch form data "general" in
$this->view->generalForm = $this->getForm("general");
}
}
@@ -0,0 +1,23 @@
<form>
<field>
<id>qemuguestagent.general.Enabled</id>
<label>Enable Service</label>
<type>checkbox</type>
<help>Enable the QEMU guest agent service.</help>
</field>
<field>
<id>qemuguestagent.general.LogDebug</id>
<label>Debug Logging</label>
<type>checkbox</type>
<help>Log extra debugging information.</help>
</field>
<field>
<id>qemuguestagent.general.DisabledRPCs</id>
<label>Disabled RPCs</label>
<type>select_multiple</type>
<style>tokenize</style>
<allownew>true</allownew>
<sortable>true</sortable>
<help>A list of RPCs to disable.</help>
</field>
</form>
@@ -0,0 +1,11 @@
<acl>
<page-services-qemuguestagent>
<name>Services: QEMU Guest Agent</name>
<patterns>
<pattern>ui/qemuguestagent/*</pattern>
<pattern>api/qemuguestagent/*</pattern>
<pattern>ui/diagnostics/log/core/qemu-ga/*</pattern>
<pattern>api/diagnostics/log/core/qemu-ga/*</pattern>
</patterns>
</page-services-qemuguestagent>
</acl>
@@ -0,0 +1,8 @@
<menu>
<Services>
<QemuGuestAgent VisibleName="QEMU Guest Agent" cssClass="fa fa-cog fa-fw">
<Settings order="10" url="/ui/qemuguestagent"/>
<Logs order="20" url="/ui/diagnostics/log/core/qemu-ga"/>
</QemuGuestAgent>
</Services>
</menu>
@@ -0,0 +1,49 @@
<?php
/**
* Copyright (C) 2021 Frank Wall
* Copyright (C) 2015 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\QemuGuestAgent;
use OPNsense\Base\BaseModel;
class QemuGuestAgent extends BaseModel
{
/**
* check if service is enabled
* @return bool is the QemuGuestAgent service enabled
*/
public function isEnabled()
{
if ((string)$this->general->Enabled === "1") {
return true;
}
return false;
}
}
@@ -0,0 +1,60 @@
<model>
<mount>//OPNsense/QemuGuestAgent</mount>
<version>1.0.0</version>
<description>QEMU Guest Agent for OPNsense</description>
<items>
<general>
<Enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</Enabled>
<LogDebug type="BooleanField">
<default>0</default>
<Required>N</Required>
</LogDebug>
<DisabledRPCs type="OptionField">
<Required>N</Required>
<default></default>
<Sorted>Y</Sorted>
<Multiple>Y</Multiple>
<OptionValues>
<guest-exec>guest-exec</guest-exec>
<guest-exec-status>guest-exec-status</guest-exec-status>
<guest-file-close>guest-file-close</guest-file-close>
<guest-file-flush>guest-file-flush</guest-file-flush>
<guest-file-open>guest-file-open</guest-file-open>
<guest-file-read>guest-file-read</guest-file-read>
<guest-file-seek>guest-file-seek</guest-file-seek>
<guest-file-write>guest-file-write</guest-file-write>
<guest-fsfreeze-freeze>guest-fsfreeze-freeze</guest-fsfreeze-freeze>
<guest-fsfreeze-freeze-list>guest-fsfreeze-freeze-list</guest-fsfreeze-freeze-list>
<guest-fsfreeze-status>guest-fsfreeze-status</guest-fsfreeze-status>
<guest-fsfreeze-thaw>guest-fsfreeze-thaw</guest-fsfreeze-thaw>
<guest-fstrim>guest-fstrim</guest-fstrim>
<guest-get-fsinfo>guest-get-fsinfo</guest-get-fsinfo>
<guest-get-host-name>guest-get-host-name</guest-get-host-name>
<guest-get-memory-block-info>guest-get-memory-block-info</guest-get-memory-block-info>
<guest-get-memory-blocks>guest-get-memory-blocks</guest-get-memory-blocks>
<guest-get-osinfo>guest-get-osinfo</guest-get-osinfo>
<guest-get-time>guest-get-time</guest-get-time>
<guest-get-timezone>guest-get-timezone</guest-get-timezone>
<guest-get-users>guest-get-users</guest-get-users>
<guest-get-vcpus>guest-get-vcpus</guest-get-vcpus>
<guest-info>guest-info</guest-info>
<guest-network-get-interfaces>guest-network-get-interfaces</guest-network-get-interfaces>
<guest-ping>guest-ping</guest-ping>
<guest-set-memory-blocks>guest-set-memory-blocks</guest-set-memory-blocks>
<guest-set-time>guest-set-time</guest-set-time>
<guest-set-user-password>guest-set-user-password</guest-set-user-password>
<guest-set-vcpus>guest-set-vcpus</guest-set-vcpus>
<guest-shutdown>guest-shutdown</guest-shutdown>
<guest-suspend-disk>guest-suspend-disk</guest-suspend-disk>
<guest-suspend-hybrid>guest-suspend-hybrid</guest-suspend-hybrid>
<guest-suspend-ram>guest-suspend-ram</guest-suspend-ram>
<guest-sync>guest-sync</guest-sync>
<guest-sync-delimited>guest-sync-delimited</guest-sync-delimited>
</OptionValues>
</DisabledRPCs>
</general>
</items>
</model>
@@ -0,0 +1,63 @@
{#
OPNsense® is Copyright © 2021 Frank Wall
OPNsense® is Copyright © 2014 2015 by Deciso B.V.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
#}
<script>
$( document ).ready(function() {
// load initial data
var data_get_map = {'frm_GeneralSettings':"/api/qemuguestagent/settings/get"};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
// link apply button to API set action
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/qemuguestagent/settings/set",formid='frm_GeneralSettings',callback_ok=function(){
// reconfigure service
ajaxCall(url="/api/qemuguestagent/service/reconfigure", sendData={}, callback=function(data,status) {
});
});
});
});
</script>
<div class="alert alert-info hidden" role="alert" id="responseMsg">
</div>
<div class="col-md-12">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_GeneralSettings'])}}
</div>
<div class="col-md-12">
<hr/>
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Apply') }}</b></button>
<br/>
<br/>
</div>
@@ -0,0 +1,10 @@
#!/bin/sh
# Check if the kernel module exists
KERNMOD='virtio_console'
if [ -e /boot/kernel/${KERNMOD}.ko ]; then
# Load module
kldload $KERNMOD 2>&1
fi
exit 0
@@ -0,0 +1,29 @@
[start]
command:/usr/local/opnsense/scripts/OPNsense/QemuGuestAgent/setup.sh; /usr/local/etc/rc.d/qemu-guest-agent start
parameters:
type:script
message:starting qemu-guest-agent
[stop]
command:/usr/local/etc/rc.d/qemu-guest-agent stop; exit 0
parameters:
type:script
message:stopping qemu-guest-agent
[restart]
command:/usr/local/opnsense/scripts/OPNsense/QemuGuestAgent/setup.sh; /usr/local/etc/rc.d/qemu-guest-agent restart
parameters:
type:script
message:restarting qemu-guest-agent
[reload]
command:/usr/local/opnsense/scripts/OPNsense/QemuGuestAgent/setup.sh; /usr/local/etc/rc.d/qemu-guest-agent restart
parameters:
type:script
message:restarting qemu-guest-agent
[status]
command:/usr/local/etc/rc.d/qemu-guest-agent status; exit 0
parameters:
type:script_output
message:requesting qemu-guest-agent status
@@ -0,0 +1 @@
rc.conf.d:/etc/rc.conf.d/qemu_guest_agent
@@ -0,0 +1,15 @@
{# Default setting is enabled, so that no GUI interaction is required. #}
{% if not (helpers.exists('OPNsense.QemuGuestAgent.general.LogDebug')) or OPNsense.QemuGuestAgent.general.Enabled|default("0") != "0" %}
{% set optional_flags = [] %}
{% do optional_flags.append('-d -l /var/log/qemu-ga.log') %}
{% if helpers.exists('OPNsense.QemuGuestAgent.general.LogDebug') and OPNsense.QemuGuestAgent.general.LogDebug|default("0") == "1" %}
{% do optional_flags.append('-v') %}
{% endif %}
{% if helpers.exists('OPNsense.QemuGuestAgent.general.DisabledRPCs') and not helpers.empty('OPNsense.QemuGuestAgent.general.DisabledRPCs') %}
{% do optional_flags.append('--blacklist=' ~ OPNsense.QemuGuestAgent.general.DisabledRPCs) %}
{% endif %}
qemu_guest_agent_enable="YES"
qemu_guest_agent_flags="{{optional_flags|join(' ')}}"
{% else %}
qemu_guest_agent_enable="NO"
{% endif %}