2016-04-19 03:38:38 +00:00
< ? php
namespace Zotlabs\Module ;
2018-06-05 01:40:11 +00:00
use Zotlabs\Lib\Libsync ;
2018-11-21 02:55:33 +00:00
use Zotlabs\Web\Controller ;
2016-04-19 03:38:38 +00:00
2018-11-21 02:55:33 +00:00
class Pconfig extends Controller {
2016-04-19 03:38:38 +00:00
function post () {
2021-03-17 03:06:35 +00:00
if ( ! local_channel ()) {
2016-04-19 03:38:38 +00:00
return ;
2021-03-17 03:06:35 +00:00
}
2016-04-19 03:38:38 +00:00
2021-03-17 03:06:35 +00:00
if ( isset ( $_SESSION [ 'delegate' ]) && $_SESSION [ 'delegate' ]) {
2016-04-19 03:38:38 +00:00
return ;
2021-03-17 03:06:35 +00:00
}
2016-04-19 03:38:38 +00:00
check_form_security_token_redirectOnErr ( '/pconfig' , 'pconfig' );
2021-03-17 03:06:35 +00:00
$cat = trim ( escape_tags (( isset ( $_POST [ 'cat' ]) && $_POST [ 'cat' ]) ? $_POST [ 'cat' ] : EMPTY_STR ));
$k = trim ( escape_tags (( isset ( $_POST [ 'k' ]) && $_POST [ 'k' ]) ? $_POST [ 'k' ] : EMPTY_STR ));
$v = trim (( isset ( $_POST [ 'v' ]) && $_POST [ 'v' ]) ? $_POST [ 'v' ] : EMPTY_STR );
$aj = intval (( isset ( $_POST [ 'aj' ]) && $_POST [ 'aj' ]) ? $_POST [ 'aj' ] : 0 );
2018-11-21 02:55:33 +00:00
// Do not store "serialized" data received in the $_POST
2016-04-19 03:38:38 +00:00
2018-11-21 02:55:33 +00:00
if ( preg_match ( '|^a:[0-9]+:{.*}$|s' , $v )) {
return ;
}
2021-03-17 03:06:35 +00:00
if ( in_array ( argv ( 2 ), $this -> disallowed_pconfig ())) {
2016-04-19 03:38:38 +00:00
notice ( t ( 'This setting requires special processing and editing has been blocked.' ) . EOL );
return ;
}
2021-03-17 03:06:35 +00:00
if ( strpos ( $k , 'password' ) !== false ) {
2019-04-05 02:55:17 +00:00
$v = obscurify ( $v );
2016-04-19 03:38:38 +00:00
}
set_pconfig ( local_channel (), $cat , $k , $v );
2018-06-05 01:40:11 +00:00
Libsync :: build_sync_packet ();
2016-04-19 03:38:38 +00:00
2021-03-17 03:06:35 +00:00
if ( $aj ) {
2018-11-21 02:55:33 +00:00
killme ();
}
2016-04-19 03:38:38 +00:00
goaway ( z_root () . '/pconfig/' . $cat . '/' . $k );
}
2018-11-21 02:55:33 +00:00
function get () {
2016-04-19 03:38:38 +00:00
2021-03-17 03:06:35 +00:00
if ( ! local_channel ()) {
2016-04-19 03:38:38 +00:00
return login ();
}
$content = '<h3>' . t ( 'Configuration Editor' ) . '</h3>' ;
$content .= '<div class="descriptive-paragraph">' . t ( 'Warning: Changing some settings could render your channel inoperable. Please leave this page unless you are comfortable with and knowledgeable about how to correctly use this feature.' ) . '</div>' . EOL . EOL ;
if ( argc () == 3 ) {
$content .= '<a href="pconfig">pconfig[' . local_channel () . ']</a>' . EOL ;
$content .= '<a href="pconfig/' . escape_tags ( argv ( 1 )) . '">pconfig[' . local_channel () . '][' . escape_tags ( argv ( 1 )) . ']</a>' . EOL . EOL ;
$content .= '<a href="pconfig/' . escape_tags ( argv ( 1 )) . '/' . escape_tags ( argv ( 2 )) . '" >pconfig[' . local_channel () . '][' . escape_tags ( argv ( 1 )) . '][' . escape_tags ( argv ( 2 )) . ']</a> = ' . get_pconfig ( local_channel (), escape_tags ( argv ( 1 )), escape_tags ( argv ( 2 ))) . EOL ;
2016-04-20 02:09:35 +00:00
if ( in_array ( argv ( 2 ), $this -> disallowed_pconfig ())) {
2016-04-19 03:38:38 +00:00
notice ( t ( 'This setting requires special processing and editing has been blocked.' ) . EOL );
return $content ;
}
else
$content .= $this -> pconfig_form ( escape_tags ( argv ( 1 )), escape_tags ( argv ( 2 )));
}
if ( argc () == 2 ) {
$content .= '<a href="pconfig">pconfig[' . local_channel () . ']</a>' . EOL ;
load_pconfig ( local_channel (), escape_tags ( argv ( 1 )));
2018-10-20 09:03:31 +00:00
if ( \App :: $config [ local_channel ()][ escape_tags ( argv ( 1 ))]) {
foreach ( \App :: $config [ local_channel ()][ escape_tags ( argv ( 1 ))] as $k => $x ) {
$content .= '<a href="pconfig/' . escape_tags ( argv ( 1 )) . '/' . $k . '" >pconfig[' . local_channel () . '][' . escape_tags ( argv ( 1 )) . '][' . $k . ']</a> = ' . escape_tags ( $x ) . EOL ;
}
2016-04-19 03:38:38 +00:00
}
}
if ( argc () == 1 ) {
$r = q ( " select * from pconfig where uid = " . local_channel ());
if ( $r ) {
foreach ( $r as $rr ) {
$content .= '<a href="' . 'pconfig/' . escape_tags ( $rr [ 'cat' ]) . '/' . escape_tags ( $rr [ 'k' ]) . '" >pconfig[' . local_channel () . '][' . escape_tags ( $rr [ 'cat' ]) . '][' . escape_tags ( $rr [ 'k' ]) . ']</a> = ' . escape_tags ( $rr [ 'v' ]) . EOL ;
}
}
}
return $content ;
}
function pconfig_form ( $cat , $k ) {
$o = '<form action="pconfig" method="post" >' ;
$o .= '<input type="hidden" name="form_security_token" value="' . get_form_security_token ( 'pconfig' ) . '" />' ;
$v = get_pconfig ( local_channel (), $cat , $k );
if ( strpos ( $k , 'password' ) !== false )
2019-04-05 02:55:17 +00:00
$v = unobscurify ( $v );
2016-04-19 03:38:38 +00:00
$o .= '<input type="hidden" name="cat" value="' . $cat . '" />' ;
$o .= '<input type="hidden" name="k" value="' . $k . '" />' ;
2021-05-27 11:04:16 +00:00
2016-04-19 03:38:38 +00:00
if ( strpos ( $v , " \n " ))
$o .= '<textarea name="v" >' . escape_tags ( $v ) . '</textarea>' ;
2021-05-27 11:04:16 +00:00
else {
if ( is_array ( $v )) {
$o .= '<code><pre>' . " \n " . print_array ( $v ) . '</pre></code>' ;
$o .= '<input type="hidden" name="v" value="' . serialise ( $v ) . '" />' ;
}
else {
$o .= '<input type="text" name="v" value="' . escape_tags ( $v ) . '" />' ;
}
}
2016-04-19 03:38:38 +00:00
$o .= EOL . EOL ;
$o .= '<input type="submit" name="submit" value="' . t ( 'Submit' ) . '" />' ;
$o .= '</form>' ;
return $o ;
}
function disallowed_pconfig () {
return array (
'permissions_role'
);
}
}