*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); define('CHPASSWD_BIN','/usr/local/sbin/chpasswd'); require_once(DOKU_PLUGIN.'syntax.php'); require_once(DOKU_INC.'inc/auth.php'); class syntax_plugin_pwchange extends DokuWiki_Syntax_Plugin { function getInfo() { return array( 'author' => 'Dennis Wagelaar', 'email' => 'dennis.wagelaar@vub.ac.be', 'date' => '2008-11-13', 'name' => 'Pwchange Plugin', 'desc' => 'allows users to change their password via the passwd command', 'url' => 'http://wiki.splitbrain.org/plugin:pwchange', ); } function getType() { return 'substition'; } function getPType() { return 'block'; } function getSort() { return 98; } function connectTo($mode) { $this->Lexer->addSpecialPattern('~~PWCHANGE.*?~~', $mode, 'plugin_pwchange'); } function handle($match, $state, $pos, &$handler) { $match = substr($match, 2, -2); // strip markup list($junk, $parm) = explode(':', $match, 2); return array($parm); } function render($mode, &$renderer, $data) { global $conf; list($parm) = $data; // prevent caching to ensure the included pages are always fresh $renderer->info['cache'] = false; if ($mode == 'xhtml' ) { if ( $_SERVER['REMOTE_USER']) { // check for password change command if ($_REQUEST['pwchange']) { // do password change $result = $this->_changepw(); // print result $renderer->p_open(); $renderer->strong_open(); $renderer->doc .= $result; $renderer->strong_close(); $renderer->p_close(); } // and render the pwchange box $this->_render_pwbox($renderer); } else { $renderer->p_open(); $renderer->strong_open(); $renderer->doc .= 'You must be logged in to change your password!'; $renderer->strong_close(); $renderer->p_close(); } return true; } return false; } function _changepw() { if (!@is_executable(CHPASSWD_BIN)) { return 'Error: cannot invoke chpasswd command.'; } if ($_REQUEST['newpw'] != $_REQUEST['newpwverify']) { return 'Error: new password verification differs from new password.'; } $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr is a pipe that the child will write to ); //error_log('about to spawn process'); $process = proc_open(CHPASSWD_BIN, $descriptorspec, $pipes, $cwd, $env); if (is_resource($process)) { //error_log('process spawned'); fwrite($pipes[0], $_SERVER['REMOTE_USER'] . "\n"); fwrite($pipes[0], $_REQUEST['oldpw'] . "\n"); fwrite($pipes[0], $_REQUEST['newpw'] . "\n"); //error_log('data sent'); $out = fread($pipes[1], 8192); //error_log('stdout read'); $error = fread($pipes[2], 8192); //error_log('stderr read'); fclose($pipes[0]); //error_log('closed STDIN'); fclose($pipes[1]); //error_log('closed STDOUT'); fclose($pipes[2]); //error_log('closed STDERR'); $result = proc_close($process); //error_log('closed proc'); if (($result['exitcode'] != 0) || ($error != 'success')) { return 'Error: '.$error; } } else { return 'Error: could not find '.CHPASSWD_BIN.' command.'; } return 'Password change successful.'; } function _render_pwbox(&$renderer) { $renderer->doc .= '
'; } } // vim:ts=4:sw=4:et:enc=utf-8: