net/shadowsocks: New plugin (#469)

This commit is contained in:
Michael
2018-01-05 17:59:03 +01:00
committed by Franco Fichtner
parent bd71845fbc
commit 9d963dcdb4
16 changed files with 407 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
PLUGIN_NAME= shadowsocks
PLUGIN_VERSION= 0.1
PLUGIN_COMMENT= A secure socks5 proxy designed to protect your Internet traffic
PLUGIN_DEPENDS= shadowsocks-libev
PLUGIN_MAINTAINER= m.muenz@gmail.com
PLUGIN_DEVEL= yes
.include "../../Mk/plugins.mk"
+11
View File
@@ -0,0 +1,11 @@
A secure socks5 proxy, designed to protect your Internet traffic.
Bleeding edge techniques using Asynchronous I/O and Event-driven
programming. Secured with industry level encryption algorithm.
Flexible to support custom algorithms. Optimized for mobile device
and wireless network, without any keep-alive connections.
Totally free and open source. A worldwide community devoted to
deliver bug-free code and long-term support.
WWW: https://shadowsocks.org
@@ -0,0 +1,49 @@
<?php
/*
Copyright (C) 2018 Michael Muenz
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 shadowsocks_services()
{
global $config;
$services = array();
if (isset($config['OPNsense']['shadowsocks']['general']['enabled']) && $config['OPNsense']['shadowsocks']['general']['enabled'] == 1) {
$services[] = array(
'description' => gettext('shadowsocks daemon'),
'configd' => array(
'restart' => array('shadowsocks restart'),
'start' => array('shadowsocks start'),
'stop' => array('shadowsocks stop'),
),
'name' => 'shadowsocks',
'pidfile' => '/var/run/shadowsocks-libev.pid'
);
}
return $services;
}
@@ -0,0 +1,40 @@
<?php
/**
* Copyright (C) 2015 - 2018 Deciso B.V.
* Copyright (C) 2018 Michael Muenz
*
* 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\Shadowsocks\Api;
use OPNsense\Base\ApiMutableModelControllerBase;
class GeneralController extends ApiMutableModelControllerBase
{
static protected $internalModelClass = '\OPNsense\Shadowsocks\General';
static protected $internalModelName = 'general';
}
@@ -0,0 +1,42 @@
<?php
/**
* Copyright (C) 2015 - 2018 Deciso B.V.
* Copyright (C) 2018 Michael Muenz
*
* 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\Shadowsocks\Api;
use OPNsense\Base\ApiMutableServiceControllerBase;
class ServiceController extends ApiMutableServiceControllerBase
{
static protected $internalServiceClass = '\OPNsense\Shadowsocks\General';
static protected $internalServiceTemplate = 'OPNsense/Shadowsocks';
static protected $internalServiceEnabled = 'enabled';
static protected $internalServiceName = 'shadowsocks';
}
@@ -0,0 +1,38 @@
<?php
/*
Copyright (C) 2018 Michael Muenz
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\Shadowsocks;
class GeneralController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->generalForm = $this->getForm("general");
$this->view->pick('OPNsense/Shadowsocks/general');
}
}
@@ -0,0 +1,32 @@
<form>
<field>
<id>general.enabled</id>
<label>Enable ShadowSocks Proxy</label>
<type>checkbox</type>
<help>This will activate the ShadowSocks Proxy service.</help>
</field>
<field>
<id>general.serveraddress</id>
<label>Server Address</label>
<type>text</type>
<help>IP address or hostname of the server.</help>
</field>
<field>
<id>general.serverport</id>
<label>Server Port</label>
<type>text</type>
<help>Port of the server.</help>
</field>
<field>
<id>general.localport</id>
<label>Local Port</label>
<type>text</type>
<help>The local port of the daemon, default is fine.</help>
</field>
<field>
<id>general.password</id>
<label>Password</label>
<type>text</type>
<help>Password to authenticate against the server.</help>
</field>
</form>
@@ -0,0 +1,9 @@
<acl>
<page-services-shadowsocks>
<name>Services: Shadowsocks</name>
<patterns>
<pattern>ui/shadowsocks/*</pattern>
<pattern>api/shadowsocks/*</pattern>
</patterns>
</page-services-shadowsocks>
</acl>
@@ -0,0 +1,35 @@
<?php
/*
Copyright (C) 2018 Michael Muenz
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\Shadowsocks;
use OPNsense\Base\BaseModel;
class General extends BaseModel
{
}
@@ -0,0 +1,35 @@
<model>
<mount>//OPNsense/shadowsocks/general</mount>
<description>Shadowsocks configuration</description>
<version>1.0.0</version>
<items>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<serveraddress type="TextField">
<default>127.0.0.1</default>
<Required>Y</Required>
<mask>/\S*/</mask>
<ValidationMessage>Please provide a valid hostname or IP address.</ValidationMessage>
</serveraddress>
<serverport type="IntegerField">
<default>8388</default>
<Required>Y</Required>
<MinimumValue>1</MinimumValue>
<MaximumValue>65535</MaximumValue>
<ValidationMessage>Please provide a valid port number between 1 and 65535.</ValidationMessage>
</serverport>
<localport type="IntegerField">
<default>1080</default>
<Required>Y</Required>
<MinimumValue>1</MinimumValue>
<MaximumValue>65535</MaximumValue>
<ValidationMessage>Please provide a valid port number between 1 and 65535.</ValidationMessage>
</localport>
<password type="TextField">
<default>password</default>
<Required>N</Required>
</password>
</items>
</model>
@@ -0,0 +1,5 @@
<menu>
<Services>
<ShadowSocks cssClass="fa fa-eye-slash" url="/ui/shadowsocks/general/index" />
</Services>
</menu>
@@ -0,0 +1,61 @@
{#
OPNsense® is Copyright © 2014 2018 by Deciso B.V.
This file is Copyright © 2018 by Michael Muenz
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.
#}
<div class="content-box" style="padding-bottom: 1.5em;">
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_general_settings'])}}
<div class="col-md-12">
<hr />
<button class="btn btn-primary" id="saveAct" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_progress"></i></button>
</div>
</div>
<script type="text/javascript">
$( document ).ready(function() {
var data_get_map = {'frm_general_settings':"/api/shadowsocks/general/get"};
mapDataToFormUI(data_get_map).done(function(data){
formatTokenizersUI();
$('.selectpicker').selectpicker('refresh');
});
ajaxCall(url="/api/shadowsocks/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
// link save button to API set action
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/shadowsocks/general/set", formid='frm_general_settings',callback_ok=function(){
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/shadowsocks/service/reconfigure", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/shadowsocks/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
});
</script>
@@ -0,0 +1,24 @@
[start]
command:/usr/local/etc/rc.d/shadowsocks_libev start
parameters:
type:script
message:starting Shadowsocks
[stop]
command:/usr/local/etc/rc.d/shadowsocks_libev stop
parameters:
type:script
message:stopping Shadowsocks
[restart]
command:/usr/local/etc/rc.d/shadowsocks_libev restart
parameters:
type:script
message:restarting Shadowsocks
[status]
command:/usr/local/etc/rc.d/shadowsocks_libev status;exit 0
parameters:
type:script_output
message:request Shadowsocks status
@@ -0,0 +1,2 @@
shadowsocks_libev:/etc/rc.conf.d/shadowsocks_libev
shadowsocks.conf:/usr/local/etc/shadowsocks-libev/config.json
@@ -0,0 +1,10 @@
{% if helpers.exists('OPNsense.shadowsocks.general.enabled') and OPNsense.shadowsocks.general.enabled == '1' %}
{
"server":"{{ OPNsense.shadowsocks.general.serveraddress }}",
"server_port":{{ OPNsense.shadowsocks.general.serverport }},
"local_port":{{ OPNsense.shadowsocks.general.localport }},
"password":"{{ OPNsense.shadowsocks.general.password }}",
"timeout":60,
"method":"chacha20-ietf-poly1305"
}
{% endif %}
@@ -0,0 +1,6 @@
{% if helpers.exists('OPNsense.shadowsocks.general.enabled') and OPNsense.shadowsocks.general.enabled == '1' %}
shadowsocks_libev_enable="YES"
shadowsocks_libev_flags=""
{% else %}
shadowsocks_libev_enable="NO"
{% endif %}