Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
8762e8bd
Commit
8762e8bd
authored
Feb 25, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some code for proxy feature, work in progress
parent
79e657ab
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
497 additions
and
0 deletions
+497
-0
ServiceController.php
.../app/controllers/OPNsense/Proxy/Api/ServiceController.php
+94
-0
IndexController.php
...se/mvc/app/controllers/OPNsense/Proxy/IndexController.php
+41
-0
BooleanField.php
.../mvc/app/models/OPNsense/Base/FieldTypes/BooleanField.php
+65
-0
IntegerField.php
.../mvc/app/models/OPNsense/Base/FieldTypes/IntegerField.php
+104
-0
IntegerValidator.php
.../app/models/OPNsense/Base/Validators/IntegerValidator.php
+50
-0
MinMaxValidator.php
...c/app/models/OPNsense/Base/Validators/MinMaxValidator.php
+52
-0
General.php
src/opnsense/mvc/app/models/OPNsense/Proxy/General.php
+35
-0
General.xml
src/opnsense/mvc/app/models/OPNsense/Proxy/General.xml
+18
-0
index.volt
src/opnsense/mvc/app/views/OPNsense/Proxy/index.volt
+22
-0
actions_service.proxy.conf
...pnsense/service/conf/actions.d/actions_service.proxy.conf
+6
-0
+MANIFEST
src/opnsense/service/templates/OPNsense/Proxy/+MANIFEST
+8
-0
+TARGETS
src/opnsense/service/templates/OPNsense/Proxy/+TARGETS
+1
-0
rc.conf.d
src/opnsense/service/templates/OPNsense/Proxy/rc.conf.d
+1
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php
0 → 100644
View file @
8762e8bd
<?php
/**
* 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\Proxy\Api
;
use
\OPNsense\Base\ApiControllerBase
;
use
\OPNsense\Core\Backend
;
/**
* Class ServiceController
* @package OPNsense\Proxy
*/
class
ServiceController
extends
ApiControllerBase
{
/**
* start proxy service
* @return array
*/
public
function
startAction
()
{
$backend
=
new
Backend
();
$response
=
$backend
->
sendEvent
(
"service start proxy"
);
return
array
(
"response"
=>
$response
);
}
/**
* stop proxy service
* @return array
*/
public
function
stopAction
()
{
$backend
=
new
Backend
();
$response
=
$backend
->
sendEvent
(
"service stop proxy"
);
return
array
(
"response"
=>
$response
);
}
/**
* restart proxy service
* @return array
*/
public
function
restartAction
()
{
$backend
=
new
Backend
();
$response
=
$backend
->
sendEvent
(
"service restart proxy"
);
return
array
(
"response"
=>
$response
);
}
/**
* retrieve status of squid proxy
* @return array
* @throws \Exception
*/
public
function
statusAction
()
{
$backend
=
new
Backend
();
$response
=
$backend
->
sendEvent
(
"service status proxy"
);
if
(
strpos
(
$response
,
"not running"
)
>
0
)
{
$status
=
"stopped"
;
}
elseif
(
strpos
(
$response
,
"not running"
)
>
0
)
{
$status
=
"running"
;
}
else
{
$status
=
"unkown"
;
}
return
array
(
"status"
=>
$status
);
}
}
src/opnsense/mvc/app/controllers/OPNsense/Proxy/IndexController.php
0 → 100644
View file @
8762e8bd
<?php
/**
* 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\Proxy
;
/**
* Class IndexController
* @package OPNsense\Proxy
*/
class
IndexController
extends
\OPNsense\Base\IndexController
{
public
function
indexAction
()
{
$this
->
view
->
pick
(
'OPNsense/Proxy/index'
);
}
}
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BooleanField.php
0 → 100644
View file @
8762e8bd
<?php
/**
* 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\Base\FieldTypes
;
use
Phalcon\Validation\Validator\Regex
;
/**
* Class TextField
* @package OPNsense\Base\FieldTypes
*/
class
BooleanField
extends
BaseField
{
/**
* @var bool marks if this is a data node or a container
*/
protected
$internalIsContainer
=
false
;
/**
* @return array returns Text/regex validator
*/
public
function
getValidators
()
{
// regexp for validating boolean values.
$regex_mask
=
"/^([0,1])
{
1
}
$/"
;
if
(
$this
->
internalValidationMessage
==
null
)
{
$msg
=
"value should be a boolean (0,1)"
;
}
else
{
$msg
=
$this
->
internalValidationMessage
;
}
if
(
$this
->
internalIsRequired
==
true
||
$this
->
internalValue
!=
null
)
{
return
array
(
new
Regex
(
array
(
'message'
=>
$msg
,
'pattern'
=>
trim
(
$regex_mask
))));
}
else
{
// empty field and not required, skip this validation.
return
array
();
}
}
}
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/IntegerField.php
0 → 100644
View file @
8762e8bd
<?php
/**
* 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\Base\FieldTypes
;
use
OPNsense\Base\Validators\MinMaxValidator
;
use
OPNsense\Base\Validators\IntegerValidator
;
/**
* Class TextField
* @package OPNsense\Base\FieldTypes
*/
class
IntegerField
extends
BaseField
{
/**
* @var bool marks if this is a data node or a container
*/
protected
$internalIsContainer
=
false
;
/**
* maximum value for this field
* @var integer
*/
private
$maximum_value
=
PHP_INT_MAX
;
/**
* minimum value for this field
* @var integer
*/
private
$minimum_value
=
PHP_INT_MAX
*-
1
;
/**
* setter for maximum value
* @param integer $value
*/
public
function
setMaximumValue
(
$value
)
{
if
(
is_numeric
(
$value
))
{
$this
->
maximum_value
=
$value
;
}
}
/**
* setter for minimum value
* @param integer $value
*/
public
function
setMinimumValue
(
$value
)
{
if
(
is_numeric
(
$value
))
{
$this
->
minimum_value
=
$value
;
}
}
/**
* @return array returns Text/regex validator
*/
public
function
getValidators
()
{
if
(
$this
->
internalValidationMessage
==
null
)
{
$msg
=
"invalid integer value"
;
}
else
{
$msg
=
$this
->
internalValidationMessage
;
}
if
((
$this
->
internalIsRequired
==
true
||
$this
->
internalValue
!=
null
))
{
$result
=
array
();
$result
[]
=
new
MinMaxValidator
(
array
(
'message'
=>
$msg
,
"min"
=>
$this
->
minimum_value
,
"max"
=>
$this
->
maximum_value
));
$result
[]
=
new
IntegerValidator
(
array
(
'message'
=>
$msg
));
return
$result
;
}
else
{
// empty field and not required, skip this validation.
return
array
();
}
}
}
src/opnsense/mvc/app/models/OPNsense/Base/Validators/IntegerValidator.php
0 → 100644
View file @
8762e8bd
<?php
/**
* 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\Base\Validators
;
use
\Phalcon\Validation\Validator
;
use
\Phalcon\Validation\ValidatorInterface
;
use
\Phalcon\Validation\Message
;;
class
IntegerValidator
extends
Validator
implements
ValidatorInterface
{
public
function
validate
(
$validator
,
$attribute
)
{
$value
=
$validator
->
getValue
(
$attribute
);
$msg
=
$this
->
getOption
(
'message'
);
if
(
ctype_digit
(
strval
((
$value
)))
==
false
)
{
$validator
->
appendMessage
(
new
Message
(
$msg
,
$attribute
,
'IntegerValidator'
));
return
false
;
}
return
true
;
}
}
src/opnsense/mvc/app/models/OPNsense/Base/Validators/MinMaxValidator.php
0 → 100644
View file @
8762e8bd
<?php
/**
* 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\Base\Validators
;
use
\Phalcon\Validation\Validator
;
use
\Phalcon\Validation\ValidatorInterface
;
use
\Phalcon\Validation\Message
;;
class
MinMaxValidator
extends
Validator
implements
ValidatorInterface
{
public
function
validate
(
$validator
,
$attribute
)
{
$value
=
$validator
->
getValue
(
$attribute
);
$min
=
$this
->
getOption
(
'min'
);
$max
=
$this
->
getOption
(
'max'
);
$msg
=
$this
->
getOption
(
'message'
);
if
(
is_numeric
(
$value
)
==
false
||
$value
<
$min
||
$value
>
$max
)
{
$validator
->
appendMessage
(
new
Message
(
$msg
,
$attribute
,
'MaxMinValidator'
));
return
false
;
}
return
true
;
}
}
src/opnsense/mvc/app/models/OPNsense/Proxy/General.php
0 → 100644
View file @
8762e8bd
<?php
/**
* 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\Proxy
;
use
OPNsense\Base\BaseModel
;
class
General
extends
BaseModel
{
}
src/opnsense/mvc/app/models/OPNsense/Proxy/General.xml
0 → 100644
View file @
8762e8bd
<model>
<mount>
//OPNsense/proxy/general
</mount>
<description>
(squid) proxy general settings
</description>
<items>
<enabled
type=
"BooleanField"
>
<default>
0
</default>
<Required>
Y
</Required>
</enabled>
<port
type=
"IntegerField"
>
<default>
3128
</default>
<MinimumValue>
1
</MinimumValue>
<MaximumValue>
65535
</MaximumValue>
<Required>
Y
</Required>
</port>
</items>
</model>
src/opnsense/mvc/app/views/OPNsense/Proxy/index.volt
0 → 100644
View file @
8762e8bd
<button class="btn btn-default" id="restcall" type="button">do REST call!</button>
<br/>
API call result : <div id="msgid"></div>
<script type="text/javascript">
$( "#restcall" ).click( function() {
$.ajax({
type: "POST",
url: "/api/proxy/service/status",
success: function(data){
$("#msgid").html( data.status );
},
data:{}
});
});
</script>
src/opnsense/service/conf/actions.d/actions_service.proxy.conf
View file @
8762e8bd
...
...
@@ -15,3 +15,9 @@ command:/usr/local/etc/rc.d/squid restart
parameters
:
type
:
script
message
:
restarting
proxy
[
status
.
proxy
]
command
:/
usr
/
local
/
etc
/
rc
.
d
/
squid
status
parameters
:
type
:
script_output
message
:
restarting
proxy
src/opnsense/service/templates/OPNsense/Proxy/+MANIFEST
0 → 100644
View file @
8762e8bd
name: opnsense-proxy
version: 0.1
origin: opnsense/proxy
comment: Squid proxy configuration
desc: configuration templates for squid proxy
maintainer: ad@opnsense.org
www: https://opnsense.org
prefix: /
src/opnsense/service/templates/OPNsense/Proxy/+TARGETS
0 → 100644
View file @
8762e8bd
rc.conf.d:/etc/rc.conf.d/squid
src/opnsense/service/templates/OPNsense/Proxy/rc.conf.d
0 → 100644
View file @
8762e8bd
squid_enable
=
YES
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment