Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISPConfig
Modules
Commits
bad4ffeb
Commit
bad4ffeb
authored
Nov 15, 2018
by
kobuki
Browse files
cosmetic fixes, formatting
parent
e4cb5a46
Changes
2
Hide whitespace changes
Inline
Side-by-side
ispc_acmeproxy/web/acmeproxy.php
View file @
bad4ffeb
...
...
@@ -3,7 +3,8 @@
require_once
'../config/config.inc.php'
;
require_once
'utils.php'
;
class
AcmeWrapper
{
class
AcmeWrapper
{
private
$sessionId
;
private
$client
;
...
...
@@ -12,7 +13,8 @@ class AcmeWrapper {
private
$username
;
private
$config
;
function
__construct
(
$config
)
{
function
__construct
(
$config
)
{
$this
->
config
=
$config
;
$resp
=
$this
->
jsonCall
(
'login'
,
[
...
...
@@ -25,7 +27,8 @@ class AcmeWrapper {
$this
->
sessionId
=
$resp
->
response
;
}
public
function
jsonCall
(
$function
,
$data
=
null
)
{
public
function
jsonCall
(
$function
,
$data
=
null
)
{
if
(
empty
(
$data
))
{
$data
=
new
stdClass
();
}
else
{
...
...
@@ -35,9 +38,10 @@ class AcmeWrapper {
return
jsonRequest
(
"
{
$this
->
config
[
'apiUrl'
]
}
?
$function
"
,
$data
);
}
public
function
initClient
(
$username
,
$password
,
$sessionId
)
{
public
function
initClient
(
$username
,
$password
,
$sessionId
)
{
if
(
!
$username
&&
!
$sessionId
)
{
throw
new
Runtime
Exception
(
"Invalid credentials"
);
throw
new
InvalidArgument
Exception
(
"Invalid credentials"
);
}
if
(
$sessionId
)
{
session_id
(
$sessionId
);
...
...
@@ -53,7 +57,7 @@ class AcmeWrapper {
$this
->
client
=
$this
->
clientZones
=
$this
->
clientZoneNames
=
null
;
$this
->
username
=
$username
;
$client
=
$this
->
jsonCall
(
'client_get_by_username'
,
[
'username'
=>
$username
]);
if
(
$client
->
code
!=
'ok'
||
!
$this
->
check
_c
rypt
_v
alue
(
$password
,
$client
->
response
->
passwort
))
{
if
(
$client
->
code
!=
'ok'
||
!
$this
->
check
C
rypt
V
alue
(
$password
,
$client
->
response
->
passwort
))
{
throw
new
InvalidArgumentException
(
"Invalid credentials"
);
}
$this
->
client
=
$client
->
response
;
...
...
@@ -66,7 +70,8 @@ class AcmeWrapper {
return
$sessionId
;
}
function
__destruct
()
{
function
__destruct
()
{
if
(
$this
->
sessionId
)
{
$this
->
jsonCall
(
'logout'
);
}
...
...
@@ -77,14 +82,15 @@ class AcmeWrapper {
* @param $saved_password
* @return bool
*/
private
static
function
check_crypt_value
(
$password
,
$saved_password
)
{
if
(
$saved_password
[
0
]
==
'{'
)
{
private
static
function
checkCryptValue
(
$password
,
$saved_password
)
{
if
(
$saved_password
[
0
]
==
'{'
)
{
// remove Dovecot-style password prefix (used for email user logins)
// example: {MD5-CRYPT}$1$12345678$MfjBLH.L2J1K2v0dXHkeJ/
$saved_password
=
substr
(
$saved_password
,
strpos
(
$saved_password
,
'}'
)
+
1
);
}
if
(
$saved_password
[
0
]
==
'$'
)
{
if
(
$saved_password
[
0
]
==
'$'
)
{
// assume prefixed crypt() hash
// $saved_password can be used as the salt, as php ignores the part after the last $ character
return
crypt
(
stripslashes
(
$password
),
$saved_password
)
==
$saved_password
;
...
...
@@ -99,7 +105,8 @@ class AcmeWrapper {
* @param $message
* @param string $data
*/
private
function
returnJson
(
$code
,
$message
,
$data
=
''
)
{
private
function
returnJson
(
$code
,
$message
,
$data
=
''
)
{
$ret
=
new
stdClass
;
$ret
->
code
=
$code
;
$ret
->
message
=
$message
;
...
...
@@ -109,34 +116,37 @@ class AcmeWrapper {
echo
json_encode
(
$ret
);
}
private
function
proxyCall
(
$method
,
$data
)
{
private
function
proxyCall
(
$method
,
$data
)
{
$resp
=
$this
->
jsonCall
(
$method
,
$data
);
$this
->
returnJson
(
$resp
->
code
,
$resp
->
message
,
$resp
->
response
);
}
public
function
incrementZoneSerial
(
$zoneId
)
{
$soa
=
$this
->
jsonCall
(
'dns_zone_get'
,
[
'primary_id'
=>
$zoneId
])
->
response
;
$serial
=
$soa
->
serial
;
$serial_date
=
intval
(
substr
(
$serial
,
0
,
8
));
$count
=
intval
(
substr
(
$serial
,
8
,
2
));
$current_date
=
date
(
"Ymd"
);
if
(
$serial_date
>=
$current_date
){
$count
+=
1
;
if
(
$count
>
99
)
{
$serial_date
+=
1
;
$count
=
0
;
}
$count
=
str_pad
(
$count
,
2
,
"0"
,
STR_PAD_LEFT
);
$new_serial
=
$serial_date
.
$count
;
}
else
{
$new_serial
=
$current_date
.
'01'
;
}
$soa
->
serial
=
$new_serial
;
$this
->
jsonCall
(
'dns_zone_update'
,
[
'client_id'
=>
$this
->
client
->
client_id
,
'primary_id'
=>
$soa
->
id
,
'params'
=>
$soa
]);
}
public
function
handleJson
()
{
if
(
!
isset
(
$_GET
)
||
!
is_array
(
$_GET
)
||
count
(
$_GET
)
<
1
)
{
public
function
incrementZoneSerial
(
$zoneId
)
{
$soa
=
$this
->
jsonCall
(
'dns_zone_get'
,
[
'primary_id'
=>
$zoneId
])
->
response
;
$serial
=
$soa
->
serial
;
$serial_date
=
intval
(
substr
(
$serial
,
0
,
8
));
$count
=
intval
(
substr
(
$serial
,
8
,
2
));
$current_date
=
date
(
"Ymd"
);
if
(
$serial_date
>=
$current_date
)
{
$count
+=
1
;
if
(
$count
>
99
)
{
$serial_date
+=
1
;
$count
=
0
;
}
$count
=
str_pad
(
$count
,
2
,
"0"
,
STR_PAD_LEFT
);
$new_serial
=
$serial_date
.
$count
;
}
else
{
$new_serial
=
$current_date
.
'01'
;
}
$soa
->
serial
=
$new_serial
;
$this
->
jsonCall
(
'dns_zone_update'
,
[
'client_id'
=>
$this
->
client
->
client_id
,
'primary_id'
=>
$soa
->
id
,
'params'
=>
$soa
]);
}
public
function
handleJson
()
{
if
(
!
isset
(
$_GET
)
||
!
is_array
(
$_GET
)
||
count
(
$_GET
)
<
1
)
{
$this
->
returnJson
(
'invalid_method'
,
'Method not provided in json call'
);
return
;
}
...
...
@@ -154,7 +164,7 @@ class AcmeWrapper {
break
;
case
'dns_zone_get'
:
$this
->
initClient
(
null
,
null
,
$data
->
session_id
);
if
(
!
array_key_exists
(
$data
->
primary_id
->
origin
,
$this
->
getC
lientZoneNames
()
))
{
if
(
!
array_key_exists
(
$data
->
primary_id
->
origin
,
$this
->
c
lientZoneNames
))
{
throw
new
RuntimeException
(
'Permission denied'
);
}
$this
->
proxyCall
(
$method
,
$data
);
...
...
@@ -198,34 +208,13 @@ class AcmeWrapper {
throw
new
RuntimeException
(
'Permission denied'
);
}
$this
->
proxyCall
(
$method
,
$data
);
$this
->
incrementZoneSerial
(
$record
->
zone
);
$this
->
incrementZoneSerial
(
$record
->
zone
);
break
;
}
}
catch
(
Exception
$e
)
{
$this
->
returnJson
(
'invalid_data'
,
$e
->
getMessage
());
}
}
/**
* @return mixed
*/
public
function
getClient
()
{
return
$this
->
client
;
}
/**
* @return mixed
*/
public
function
getClientZones
()
{
return
$this
->
clientZones
;
}
/**
* @return mixed
*/
public
function
getClientZoneNames
()
{
return
$this
->
clientZoneNames
;
}
}
$acme
=
new
AcmeWrapper
(
$config
);
...
...
ispc_acmeproxy/web/utils.php
View file @
bad4ffeb
...
...
@@ -51,7 +51,8 @@ function endsWith($string, $endString)
return
(
substr
(
$string
,
-
$len
)
===
$endString
);
}
function
jsonRequest
(
$url
,
$data
)
{
function
jsonRequest
(
$url
,
$data
)
{
$request
=
array
(
'http'
=>
array
(
'method'
=>
'POST'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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