Skip to content

Commit 5b8b617

Browse files
author
Niklas Spanring
committed
ADD: Proxy
1 parent 9812a2e commit 5b8b617

18 files changed

+234
-97
lines changed

class/cap.form.class.php

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,49 @@ function InputStandard($type, $status_arr = "")
14391439
$out.= '<input '.$status_theme.' type="text" name="conf[webservice][WS_DOL_URL]" value="'.$configuration->conf["webservice"]["WS_DOL_URL"].'">';
14401440
break;
14411441

1442+
case 'proxy_conf':
1443+
if($configuration->conf["proxy"]["proxyOn"] == 1) $onoroff = 'checked=""';
1444+
else $onoroff = '';
1445+
1446+
$out.= '<div data-role="collapsible" id="conf-proxy-detail" data-theme="b" data-content-theme="a">';
1447+
$out.= '<h2>'.$langs->trans("ProxyConfiguration").'</h2>';
1448+
$out.= '<ul data-role="listview">';
1449+
1450+
// switch On
1451+
$out.= '<li id="proxy_switchDIV" class="ui-field-contain">';
1452+
$out.= '<legend>'.$langs->trans("LabelProxy").': '.$this->tooltip($type.'tool', $langs->trans("LabelProxyDesc")).'</legend>';
1453+
$out.= '<input '.$status_theme.' type="checkbox" data-role="flipswitch" name="conf[proxy][proxyOn]" id="proxy_switch" '.$onoroff.' data-theme="b">';
1454+
$out.= '</li>';
1455+
1456+
// IP
1457+
$out.= '<li id="proxyIPDIV" class="ui-field-contain">';
1458+
$out.= '<legend>'.$langs->trans("LabelProxy_ip").': '.$this->tooltip($type.'tool', $langs->trans("LabelProxy_ipDesc")).'</legend>';
1459+
$out.= '<input '.$status_theme.' type="text" name="conf[proxy][proxyIP]" value="'.$configuration->conf["proxy"]["proxyIP"].'">';
1460+
$out.= '</li>';
1461+
1462+
// Port
1463+
$out.= '<li id="proxyPortDIV" class="ui-field-contain">';
1464+
$out.= '<legend>'.$langs->trans("LabelProxy_port").': '.$this->tooltip($type.'tool', $langs->trans("LabelProxy_portDesc")).'</legend>';
1465+
$out.= '<input '.$status_theme.' type="text" name="conf[proxy][proxyPort]" value="'.$configuration->conf["proxy"]["proxyPort"].'">';
1466+
$out.= '</li>';
1467+
1468+
// UserName
1469+
$out.= '<li id="proxyUserNameDIV" class="ui-field-contain">';
1470+
$out.= '<legend>'.$langs->trans("LabelProxy_username").': '.$this->tooltip($type.'tool', $langs->trans("LabelProxy_usernameDesc")).'</legend>';
1471+
$out.= '<input '.$status_theme.' type="text" name="conf[proxy][proxyUserName]" value="'.$configuration->conf["proxy"]["proxyUserName"].'">';
1472+
$out.= '</li>';
1473+
1474+
// UserPass
1475+
$out.= '<li id="proxyUserPassDIV" class="ui-field-contain">';
1476+
$out.= '<legend>'.$langs->trans("LabelProxy_password").': '.$this->tooltip($type.'tool', $langs->trans("LabelProxy_passwordDesc")).'</legend>';
1477+
$out.= '<input '.$status_theme.' type="text" name="conf[proxy][proxyUserPass]" value="'.$configuration->conf["proxy"]["proxyUserPass"].'">';
1478+
$out.= '</li>';
1479+
1480+
$out.= '</ul>';
1481+
$out.= '</div>'; // DETAILS
1482+
1483+
break;
1484+
14421485
case 'capview':
14431486
$out = '<textarea id="capviewtextarea" readonly name="capeditfield"></textarea>';
14441487
$out.= '<input type="button" value="edit" onclick="$(\'#capviewtextarea\').prop(\'readonly\', \'\'); $(\'#capedit\').val(true)">';
@@ -2493,11 +2536,11 @@ function Webservice($ID)
24932536
$out.= '<div data-theme="a" data-form="ui-body-a" class="ui-body ui-body-a ui-corner-all">';
24942537

24952538
// decryp password
2496-
$configuration->set("webservice", "password", $this->encrypt_decrypt(2, $configuration->conf["webservice"]["password"]));
2539+
$configuration->setValue("webservice", "password", $this->encrypt_decrypt(2, $configuration->conf["webservice"]["password"]));
24972540

24982541
include("lib/cap.webservices.php");
24992542

2500-
$configuration->set("webservice", "password",$this->encrypt_decrypt(1, $configuration->conf["webservice"]["password"]));
2543+
$configuration->setValue("webservice", "password",$this->encrypt_decrypt(1, $configuration->conf["webservice"]["password"]));
25012544

25022545
$out.= '</div>';
25032546

@@ -2688,7 +2731,7 @@ function PostToConf($post)
26882731
*/
26892732
if(!empty($post['user']['lang']))
26902733
{
2691-
$configuration->set("user", "language", $post['user']['lang']);
2734+
$configuration->setValue("user", "language", $post['user']['lang']);
26922735
}
26932736

26942737
// set langs
@@ -2736,31 +2779,31 @@ function PostToConf($post)
27362779
// specifie the automatic time set
27372780
if($post['identifier']['time']['on'] == "on")
27382781
{
2739-
$configuration->set("identifier", "time_on", 1);
2782+
$configuration->setValue("identifier", "time_on", 1);
27402783
}
27412784
else
27422785
{
2743-
$configuration->set("identifier", "time_on", 0);
2786+
$configuration->setValue("identifier", "time_on", 0);
27442787
}
27452788
unset($post['identifier']['time']);
27462789

27472790
if($post['cap']['save'] == "on")
27482791
{
2749-
$configuration->set("cap", "save", 1);
2792+
$configuration->setValue("cap", "save", 1);
27502793
}
27512794
else
27522795
{
2753-
$configuration->set("cap", "save", 0);
2796+
$configuration->setValue("cap", "save", 0);
27542797
}
27552798
unset($post['cap']['save']);
27562799

27572800
if($post['webservice']['on'] == "on")
27582801
{
2759-
$configuration->set("webservice", "service_on", 1);
2802+
$configuration->setValue("webservice", "service_on", 1);
27602803
}
27612804
else
27622805
{
2763-
$configuration->set("webservice", "service_on", 0);
2806+
$configuration->setValue("webservice", "service_on", 0);
27642807
}
27652808
unset($post['webservice']['on']);
27662809

@@ -2771,14 +2814,30 @@ function PostToConf($post)
27712814
}
27722815
else
27732816
{
2774-
$configuration->set("webservice", "password", $this->encrypt_decrypt(1, $post['webservice']['password']));
2817+
$configuration->setValue("webservice", "password", $this->encrypt_decrypt(1, $post['webservice']['password']));
27752818
unset($post['webservice']['password']);
27762819
}
27772820

2821+
if($post['proxy']['proxyOn'] == "on")
2822+
{
2823+
$configuration->setValue("proxy", "proxyOn", 1);
2824+
}
2825+
else
2826+
{
2827+
$configuration->setValue("proxy", "proxyOn", 0);
2828+
}
2829+
unset($post['proxy']['proxyOn']);
2830+
2831+
// crypt pass
2832+
if($configuration->conf["proxy"]["proxyUserPass"] != $post['proxy']['proxyUserPass'])
2833+
{
2834+
$configuration->setValue("proxy", "proxyUserPass", $post['proxy']['proxyUserPass']);
2835+
unset($post['proxy']['proxyUserPass']);
2836+
}
27782837

27792838
if(!empty($post['timezone']))
27802839
{
2781-
$configuration->set("installed", "timezone", $post['timezone']);
2840+
$configuration->setValue("installed", "timezone", $post['timezone']);
27822841
}
27832842

27842843
/*
@@ -2798,26 +2857,26 @@ function PostToConf($post)
27982857
{
27992858
foreach($obj_2_val as $obj_3_name => $obj_3_val)
28002859
{
2801-
$configuration->set($obj_name, $obj_2_name."_".$obj_3_name, $obj_3_val);
2860+
$configuration->setValue($obj_name, $obj_2_name."_".$obj_3_name, $obj_3_val);
28022861
} // Level 2
28032862
}
28042863
else
28052864
{
2806-
$configuration->set($obj_name, $obj_2_name, $obj_2_val);
2865+
$configuration->setValue($obj_name, $obj_2_name, $obj_2_val);
28072866
}
28082867

28092868
} // Level 1
28102869
}
28112870
else
28122871
{
2813-
$configuration->set($obj_name, $obj_1_name, $obj_1_val);
2872+
$configuration->setValue($obj_name, $obj_1_name, $obj_1_val);
28142873
}
28152874

28162875
} // Base
28172876
}
28182877
else
28192878
{
2820-
$configuration->set($obj_name, "", $obj_val);
2879+
$configuration->setValue($obj_name, "", $obj_val);
28212880
}
28222881

28232882
}

class/conf.class.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
function __construct($path){
88
$this->path = $path;
99
$this->conf = parse_ini_file($path, true); // config.ini
10+
$this->setExtra();
1011

1112
### Check the version of the conf file
1213
if(file_exists(dirname($path)."/standard.conf.ini")){
@@ -21,7 +22,7 @@ function __construct($path){
2122
}
2223

2324
// key name value
24-
function set($k, $n, $v){
25+
function setValue($k, $n, $v){
2526
if(!empty($n)){
2627
$this->conf[$k][$n] = $v;
2728
} else {
@@ -42,6 +43,7 @@ function get($k, $n){
4243

4344
function write_php_ini()
4445
{
46+
$this->unsetExtra(); // encrypting
4547
$res = array();
4648
foreach($this->conf as $key => $val)
4749
{
@@ -53,6 +55,7 @@ function write_php_ini()
5355
else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.$val.'"');
5456
}
5557
$this->safefilerewrite($this->path, implode("\r\n", $res));
58+
$this->setExtra();
5659
}
5760

5861
function safefilerewrite($fileName, $dataToSave)
@@ -75,5 +78,53 @@ function safefilerewrite($fileName, $dataToSave)
7578
}
7679

7780
}
81+
82+
function setExtra(){
83+
if($this->conf["proxy"]["proxyOn"] == 1){
84+
$this->conf["proxy"]["proxyUserPass"] = $this->encrypt_decrypt(2, $this->conf["proxy"]["proxyUserPass"]);
85+
}else{
86+
$this->conf["proxy"]["proxyIP"] = false;
87+
$this->conf["proxy"]["proxyPort"] = false;
88+
$this->conf["proxy"]["proxyUserName"] = false;
89+
$this->conf["proxy"]["proxyUserPass"] = false;
90+
}
91+
}
92+
93+
function unsetExtra(){
94+
if($this->conf["proxy"]["proxyOn"] == 1){
95+
$this->conf["proxy"]["proxyUserPass"] = $this->encrypt_decrypt(1, $this->conf["proxy"]["proxyUserPass"]);
96+
}
97+
}
98+
99+
/**
100+
* encrypt and decrypt function for passwords
101+
*
102+
* @return string
103+
*/
104+
function encrypt_decrypt($action, $string, $key = "")
105+
{
106+
$output = false;
107+
108+
$encrypt_method = "AES-256-CBC";
109+
$secret_key = ($key?$key:'NjZvdDZtQ3ZSdVVUMXFMdnBnWGt2Zz09');
110+
111+
$secret_iv = ($this->conf["webservice"]["securitykey"] ? $this->conf["webservice"]["securitykey"] : 'WebTagServices#hash');
112+
113+
// hash
114+
$key = hash('sha256', $secret_key);
115+
116+
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
117+
$iv = substr(hash('sha256', $secret_iv), 0, 16);
118+
119+
if( $action == 1 ) {
120+
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
121+
$output = base64_encode($output);
122+
}
123+
else if( $action == 2 ){
124+
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
125+
}
126+
127+
return $output;
128+
}
78129
}
79130
?>

conf/standard.conf.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,16 @@ APIkey = ""
103103
[Validator]
104104
url = "http://validator.meteoalarm.eu/validate"
105105

106+
[proxy]
107+
proxyOn=0
108+
proxyIP=""
109+
proxyPort=""
110+
proxyUserName=""
111+
proxyUserPass=""
112+
106113
[PHPVersion]
107114
min = 5.5
108115
max = 7.0
109116

110117
[ConfVersion]
111-
ver = 1.2.3
118+
ver = 1.5.3

includes/nusoap/lib/nusoap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,9 +2365,9 @@ function connect($connection_timeout=0,$response_timeout=30){
23652365

23662366
// open socket
23672367
if($connection_timeout > 0){
2368-
$this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout);
2368+
$this->fp = @fsockopen( $host, $port, $this->errno, $this->error_str, $connection_timeout);
23692369
} else {
2370-
$this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str);
2370+
$this->fp = @fsockopen( $host, $port, $this->errno, $this->error_str);
23712371
}
23722372

23732373
// test pointer

0 commit comments

Comments
 (0)