blog->settings->get(basename(__DIR__)); $pwd_file = dcCore::app()->blog->public_path . DIRECTORY_SEPARATOR . initHttpPassword::FILE_PASSWORD; $action = $_POST['action'] ?? ''; $redir = $_REQUEST['redir'] ?? ''; $part = $_REQUEST['part'] ?? 'settings'; $passwords = []; $writable = httpPassword::isWritable(); $section_menu = [ __('Settings') => 'settings', __('Logins history') => 'logins', __('Authorized users') => 'passwords', ]; if (!in_array($part, $section_menu) || !$writable) { $part = 'settings'; } if (empty($redir)) { $redir = dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__), ['part' => $part]); } if (!$writable) { dcAdminNotices::addWarningNotice( __('No write permissions on blogs directories.') ); } if ('passwords' == $part) { $lines = file($pwd_file); if (!is_array($lines)) { $lines = []; } sort($lines); foreach ($lines as $line) { [$login, $pwd] = explode(':', $line, 2); $passwords[trim($login)] = trim($pwd); } unset($lines); } if ('savesettings' == $action) { $s->put('active', !empty($_POST['active'])); $s->put('crypt', in_array((string) $_POST['crypt'], httpPassword::getCryptCombo()) ? $_POST['crypt'] : 'paintext'); $s->put('message', (string) $_POST['message']); dcCore::app()->blog->triggerBlog(); dcAdminNotices::addSuccessNotice( __('Settings successfully updated.') ); dcCore::app()->adminurl->redirect( 'admin.plugin.' . basename(__DIR__), ['part' => $part] ); } if ('savelogins' == $action) { $logs = dcCore::app()->log->getLogs(['log_table' => basename(__DIR__)]); if (!$logs->isEmpty()) { $ids = []; while ($logs->fetch()) { $ids[] = $logs->__get('log_id'); } $logs = dcCore::app()->log->delLogs($ids); dcAdminNotices::addSuccessNotice( __('Logs successfully cleared.') ); dcCore::app()->adminurl->redirect( 'admin.plugin.' . basename(__DIR__), ['part' => $part] ); } } if ('savepasswords' == $action) { $lines = []; if (!empty($_POST['login']) && !empty($_POST['password'])) { $lines[$_POST['login']] = httpPassword::crypt($_POST['password']); } foreach ($passwords as $l => $p) { // add login if (array_key_exists($l, $lines)) { continue; } // delete login if (!empty($_POST['delete']) && array_key_exists($l, $_POST['delete'])) { continue; } // change password if (!empty($_POST['edit']) && array_key_exists($l, $_POST['edit']) && !empty($_POST['newpassword']) && array_key_exists($l, $_POST['newpassword']) ) { $lines[$l] = httpPassword::crypt($_POST['newpassword'][$l]); } else { $lines[$l] = $p; } } $contents = ''; foreach ($lines as $l => $p) { $contents .= sprintf("%s:%s\r\n", $l, $p); } file_put_contents($pwd_file, $contents); dcCore::app()->blog->triggerBlog(); dcAdminNotices::addSuccessNotice( __('Logins successfully updated.') ); dcCore::app()->adminurl->redirect( 'admin.plugin.' . basename(__DIR__), ['part' => $part] ); } echo '