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 '' . __('Http password') . '' . dcPage::jsPageTabs() . dcPage::jsModuleLoad(basename(__DIR__) . '/js/index.js') . '' . dcPage::breadcrumb([ __('Plugins') => '', __('Http password') => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), array_search($part, $section_menu) => '', ]) . dcPage::notices() . # Filters select menu list '
' . '

' . form::combo('part', $section_menu, $part) . ' ' . '' . form::hidden('p', basename(__DIR__)) . '

' . '
' . '

' . array_search($part, $section_menu) . '

'; if ('settings' == $part) { echo '

' . form::combo('crypt', httpPassword::getCryptCombo(), (string) $s->get('crypt')) . '

' . __('Some web servers does not surpport plaintext (no) encryption.') . ' ' . __('If you change crypt algo, you must edit and resave each users passwords.') . '

' . form::field('message', 60, 255, html::escapeHTML((string) $s->get('message'))) . '

' . dcCore::app()->formNonce() . form::hidden(['action'], 'savesettings') . form::hidden(['part'], $part) . '

'; } if ('logins' == $part) { $logs = dcCore::app()->log->getLogs(['log_table' => basename(__DIR__)]); if ($logs->isEmpty()) { echo '

' . __('Logins history is empty.') . '

'; } else { echo '

' . dcCore::app()->formNonce() . form::hidden(['action'], 'savelogins') . form::hidden(['part'], $part) . '

' . '
' . '' . '' . '' . '' . ''; while ($logs->fetch()) { echo '' . '' . '' . ''; } echo '
' . sprintf(__('List of %s last logins.'), $logs->count()) . '
' . __('Login') . '' . __('Date') . '
' . html::escapeHTML($logs->__get('log_msg')) . '' . html::escapeHTML(dt::dt2str(__('%Y-%m-%d %H:%M'), $logs->__get('log_dt'))) . '
'; } } if ('passwords' == $part) { if (empty($passwords)) { echo '

' . __('Authorized users list is empty.') . '

'; } else { echo '
' . '
' . '' . '' . '' . '' . '' . ''; foreach ($passwords as $login => $pwd) { echo '' . '' . '' . '' . ''; } echo '
' . sprintf(__('List of %s authorized users.'), count($passwords)) . '
' . __('Login') . '' . __('New password') . '' . __('Action') . '
' . html::escapeHTML($login) . '' . form::field(['newpassword[' . html::escapeHTML($login) . ']'], 60, 255, '') . '' . ' ' . '' . '

' . dcCore::app()->formNonce() . form::hidden(['action'], 'savepasswords') . form::hidden(['part'], $part) . '

'; } echo '

' . __('Add a user') . '

' . form::field('login', 60, 255, '') . '

' . form::field('password', 60, 255, '') . '

' . dcCore::app()->formNonce() . form::hidden(['action'], 'savepasswords') . form::hidden(['part'], $part) . '

'; } echo '';