149f2871cSAndreas Gohr<?php 21da41c8bSAndreas Gohr 31da41c8bSAndreas Gohruse chrisbliss18\phpico\PHPIco; 41da41c8bSAndreas Gohruse dokuwiki\Extension\AdminPlugin; 51da41c8bSAndreas Gohruse dokuwiki\Form\Form; 61da41c8bSAndreas Gohruse splitbrain\RingIcon\RingIcon; 71da41c8bSAndreas Gohr 849f2871cSAndreas Gohr/** 949f2871cSAndreas Gohr * DokuWiki Plugin farmer (Admin Component) 1049f2871cSAndreas Gohr * 111da41c8bSAndreas Gohr * Create new animals 121da41c8bSAndreas Gohr * 1349f2871cSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 1449f2871cSAndreas Gohr * @author Michael Große <grosse@cosmocode.de> 1549f2871cSAndreas Gohr */ 161da41c8bSAndreas Gohrclass admin_plugin_farmer_new extends AdminPlugin 171da41c8bSAndreas Gohr{ 1849f2871cSAndreas Gohr /** @var helper_plugin_farmer $helper */ 1949f2871cSAndreas Gohr protected $helper; 2049f2871cSAndreas Gohr 2149f2871cSAndreas Gohr /** 2249f2871cSAndreas Gohr * admin_plugin_farmer_new constructor. 2349f2871cSAndreas Gohr */ 241da41c8bSAndreas Gohr public function __construct() 251da41c8bSAndreas Gohr { 2649f2871cSAndreas Gohr $this->helper = plugin_load('helper', 'farmer'); 2749f2871cSAndreas Gohr } 2849f2871cSAndreas Gohr 29*341a2d35SAndreas Gohr /** @inheritdoc */ 30*341a2d35SAndreas Gohr public function showInMenu() 31*341a2d35SAndreas Gohr { 32*341a2d35SAndreas Gohr return false; 33*341a2d35SAndreas Gohr } 34*341a2d35SAndreas Gohr 3549f2871cSAndreas Gohr /** 3649f2871cSAndreas Gohr * Should carry out any processing required by the plugin. 3749f2871cSAndreas Gohr */ 381da41c8bSAndreas Gohr public function handle() 391da41c8bSAndreas Gohr { 4049f2871cSAndreas Gohr global $INPUT; 4149f2871cSAndreas Gohr global $ID; 4249f2871cSAndreas Gohr if (!$INPUT->has('farmer__submit')) return; 4349f2871cSAndreas Gohr 4449f2871cSAndreas Gohr $data = $this->validateAnimalData(); 4549f2871cSAndreas Gohr if (!$data) return; 461da41c8bSAndreas Gohr if ( 471da41c8bSAndreas Gohr $this->createNewAnimal( 481da41c8bSAndreas Gohr $data['name'], 491da41c8bSAndreas Gohr $data['admin'], 501da41c8bSAndreas Gohr $data['pass'], 511da41c8bSAndreas Gohr $data['template'], 521da41c8bSAndreas Gohr $data['aclpolicy'], 531da41c8bSAndreas Gohr $data['allowreg'] 541da41c8bSAndreas Gohr ) 551da41c8bSAndreas Gohr ) { 560336ab2aSAndreas Gohr $url = $this->helper->getAnimalURL($data['name']); 570336ab2aSAndreas Gohr $link = '<a href="' . $url . '">' . hsc($data['name']) . '</a>'; 580336ab2aSAndreas Gohr 590336ab2aSAndreas Gohr msg(sprintf($this->getLang('animal creation success'), $link), 1); 601da41c8bSAndreas Gohr $link = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => 'new'], true, '&'); 6149f2871cSAndreas Gohr send_redirect($link); 6249f2871cSAndreas Gohr } 6349f2871cSAndreas Gohr } 6449f2871cSAndreas Gohr 6549f2871cSAndreas Gohr /** 6649f2871cSAndreas Gohr * Render HTML output, e.g. helpful text and a form 6749f2871cSAndreas Gohr */ 681da41c8bSAndreas Gohr public function html() 691da41c8bSAndreas Gohr { 706348ab5bSMichael Grosse global $lang; 711272da0cSAndreas Gohr $farmconfig = $this->helper->getConfig(); 7249f2871cSAndreas Gohr 731da41c8bSAndreas Gohr $form = new Form(); 7449f2871cSAndreas Gohr $form->addClass('plugin_farmer')->id('farmer__create_animal_form'); 7549f2871cSAndreas Gohr 7649f2871cSAndreas Gohr $form->addFieldsetOpen($this->getLang('animal configuration')); 7723164e01SAndreas Gohr $form->addTextInput('animalname', $this->getLang('animal')); 7849f2871cSAndreas Gohr $form->addFieldsetClose(); 7949f2871cSAndreas Gohr 80801ebaa1SAndreas Gohr $animals = $this->helper->getAllAnimals(); 81801ebaa1SAndreas Gohr array_unshift($animals, ''); 82801ebaa1SAndreas Gohr $form->addFieldsetOpen($this->getLang('animal template')); 831da41c8bSAndreas Gohr $form->addDropdown('animaltemplate', $animals) 841da41c8bSAndreas Gohr ->addClass('farmer_chosen_animals'); 85801ebaa1SAndreas Gohr $form->addFieldsetClose(); 86801ebaa1SAndreas Gohr 876348ab5bSMichael Grosse $form->addFieldsetOpen($lang['i_policy'])->attr('id', 'aclPolicyFieldset'); 881da41c8bSAndreas Gohr $policyOptions = ['open' => $lang['i_pol0'], 'public' => $lang['i_pol1'], 'closed' => $lang['i_pol2']]; 891da41c8bSAndreas Gohr $form->addDropdown('aclpolicy', $policyOptions) 901da41c8bSAndreas Gohr ->addClass('acl_chosen'); 916348ab5bSMichael Grosse if ($farmconfig['inherit']['main']) { 921da41c8bSAndreas Gohr $form->addRadioButton('allowreg', $this->getLang('inherit user registration')) 931da41c8bSAndreas Gohr ->val('inherit') 941da41c8bSAndreas Gohr ->attr('checked', 'checked'); 951da41c8bSAndreas Gohr $form->addRadioButton('allowreg', $this->getLang('enable user registration')) 961da41c8bSAndreas Gohr ->val('allow'); 971da41c8bSAndreas Gohr $form->addRadioButton('allowreg', $this->getLang('disable user registration')) 981da41c8bSAndreas Gohr ->val('disable'); 996348ab5bSMichael Grosse } else { 1001da41c8bSAndreas Gohr $form->addCheckbox('allowreg', $lang['i_allowreg']) 1011da41c8bSAndreas Gohr ->attr('checked', 'checked'); 1026348ab5bSMichael Grosse } 1036348ab5bSMichael Grosse 1046348ab5bSMichael Grosse $form->addFieldsetClose(); 1056348ab5bSMichael Grosse 10649f2871cSAndreas Gohr $form->addFieldsetOpen($this->getLang('animal administrator')); 1071da41c8bSAndreas Gohr 1081da41c8bSAndreas Gohr $btn = $form->addRadioButton('adminsetup', $this->getLang('noUsers')) 1091da41c8bSAndreas Gohr ->val('noUsers'); 1101272da0cSAndreas Gohr if ($farmconfig['inherit']['users']) { 1111272da0cSAndreas Gohr $btn->attr('checked', 'checked'); // default when inherit available 1121a130845SAndreas Gohr } else { 1131a130845SAndreas Gohr // no user copying when inheriting 1141da41c8bSAndreas Gohr $form->addRadioButton('adminsetup', $this->getLang('importUsers')) 1151da41c8bSAndreas Gohr ->val('importUsers'); 1161da41c8bSAndreas Gohr $form->addRadioButton('adminsetup', $this->getLang('currentAdmin')) 1171da41c8bSAndreas Gohr ->val('currentAdmin'); 1181a130845SAndreas Gohr } 1191da41c8bSAndreas Gohr $btn = $form->addRadioButton('adminsetup', $this->getLang('newAdmin')) 1201da41c8bSAndreas Gohr ->val('newAdmin'); 1211272da0cSAndreas Gohr if (!$farmconfig['inherit']['users']) { 1221272da0cSAndreas Gohr $btn->attr('checked', 'checked'); // default when inherit not available 1231272da0cSAndreas Gohr } 12449f2871cSAndreas Gohr $form->addPasswordInput('adminPassword', $this->getLang('admin password')); 12549f2871cSAndreas Gohr $form->addFieldsetClose(); 12649f2871cSAndreas Gohr 1271da41c8bSAndreas Gohr $form->addButton('farmer__submit', $this->getLang('submit')) 1281da41c8bSAndreas Gohr ->attr('type', 'submit') 1291da41c8bSAndreas Gohr ->val('newAnimal'); 13049f2871cSAndreas Gohr echo $form->toHTML(); 13149f2871cSAndreas Gohr } 13249f2871cSAndreas Gohr 13349f2871cSAndreas Gohr /** 13449f2871cSAndreas Gohr * Validate the data for a new animal 13549f2871cSAndreas Gohr * 13649f2871cSAndreas Gohr * @return array|bool false on errors, clean data otherwise 13749f2871cSAndreas Gohr */ 1381da41c8bSAndreas Gohr protected function validateAnimalData() 1391da41c8bSAndreas Gohr { 14049f2871cSAndreas Gohr global $INPUT; 14149f2871cSAndreas Gohr 14249f2871cSAndreas Gohr $animalname = $INPUT->filter('trim')->str('animalname'); 14349f2871cSAndreas Gohr $adminsetup = $INPUT->str('adminsetup'); 14449f2871cSAndreas Gohr $adminpass = $INPUT->filter('trim')->str('adminPassword'); 145801ebaa1SAndreas Gohr $template = $INPUT->filter('trim')->str('animaltemplate'); 1466348ab5bSMichael Grosse $aclpolicy = $INPUT->filter('trim')->str('aclpolicy'); 1476348ab5bSMichael Grosse $allowreg = $INPUT->str('allowreg'); 14849f2871cSAndreas Gohr 1491da41c8bSAndreas Gohr $errors = []; 15049f2871cSAndreas Gohr 15149f2871cSAndreas Gohr if ($animalname === '') { 15249f2871cSAndreas Gohr $errors[] = $this->getLang('animalname_missing'); 15349f2871cSAndreas Gohr } elseif (!$this->helper->validateAnimalName($animalname)) { 15449f2871cSAndreas Gohr $errors[] = $this->getLang('animalname_invalid'); 15549f2871cSAndreas Gohr } 15649f2871cSAndreas Gohr 15749f2871cSAndreas Gohr if ($adminsetup === 'newAdmin' && $adminpass === '') { 15849f2871cSAndreas Gohr $errors[] = $this->getLang('adminPassword_empty'); 15949f2871cSAndreas Gohr } 16049f2871cSAndreas Gohr 16149f2871cSAndreas Gohr if ($animalname !== '' && file_exists(DOKU_FARMDIR . '/' . $animalname)) { 16249f2871cSAndreas Gohr $errors[] = $this->getLang('animalname_preexisting'); 16349f2871cSAndreas Gohr } 16449f2871cSAndreas Gohr 1651da41c8bSAndreas Gohr if (!is_dir(DOKU_FARMDIR . $template) && !in_array($aclpolicy, ['open', 'public', 'closed'])) { 1666348ab5bSMichael Grosse $errors[] = $this->getLang('aclpolicy missing/bad'); 1676348ab5bSMichael Grosse } 1686348ab5bSMichael Grosse 16949f2871cSAndreas Gohr if ($errors) { 17049f2871cSAndreas Gohr foreach ($errors as $error) { 17149f2871cSAndreas Gohr msg($error, -1); 17249f2871cSAndreas Gohr } 17349f2871cSAndreas Gohr return false; 17449f2871cSAndreas Gohr } 17549f2871cSAndreas Gohr 1768262a4cbSAndreas Gohr if (!is_dir(DOKU_FARMDIR . $template)) { 177801ebaa1SAndreas Gohr $template = ''; 178801ebaa1SAndreas Gohr } 1796348ab5bSMichael Grosse if ($template != '') { 1806348ab5bSMichael Grosse $aclpolicy = ''; 1816348ab5bSMichael Grosse } 182801ebaa1SAndreas Gohr 1831da41c8bSAndreas Gohr return [ 18449f2871cSAndreas Gohr 'name' => $animalname, 18549f2871cSAndreas Gohr 'admin' => $adminsetup, 186801ebaa1SAndreas Gohr 'pass' => $adminpass, 1876348ab5bSMichael Grosse 'template' => $template, 1886348ab5bSMichael Grosse 'aclpolicy' => $aclpolicy, 1896348ab5bSMichael Grosse 'allowreg' => $allowreg 1901da41c8bSAndreas Gohr ]; 19149f2871cSAndreas Gohr } 19249f2871cSAndreas Gohr 19349f2871cSAndreas Gohr /** 19449f2871cSAndreas Gohr * Create a new animal 19549f2871cSAndreas Gohr * 19649f2871cSAndreas Gohr * @param string $name name/title of the animal, will be the directory name for htaccess setup 19749f2871cSAndreas Gohr * @param string $adminSetup newAdmin, currentAdmin or importUsers 19849f2871cSAndreas Gohr * @param string $adminPassword required if $adminSetup is newAdmin 199801ebaa1SAndreas Gohr * @param string $template name of animal to copy 2006348ab5bSMichael Grosse * @param $aclpolicy 2016348ab5bSMichael Grosse * @param $userreg 20249f2871cSAndreas Gohr * @return bool true if successful 2036348ab5bSMichael Grosse * @throws Exception 20449f2871cSAndreas Gohr */ 2051da41c8bSAndreas Gohr protected function createNewAnimal($name, $adminSetup, $adminPassword, $template, $aclpolicy, $userreg) 2061da41c8bSAndreas Gohr { 2078262a4cbSAndreas Gohr $animaldir = DOKU_FARMDIR . $name; 20849f2871cSAndreas Gohr 20949f2871cSAndreas Gohr // copy basic template 2101da41c8bSAndreas Gohr $ok = $this->helper->copyDir(__DIR__ . '/../_animal', $animaldir); 21149f2871cSAndreas Gohr if (!$ok) { 21249f2871cSAndreas Gohr msg($this->getLang('animal creation error'), -1); 21349f2871cSAndreas Gohr return false; 21449f2871cSAndreas Gohr } 21549f2871cSAndreas Gohr 216801ebaa1SAndreas Gohr // copy animal template 217801ebaa1SAndreas Gohr if ($template != '') { 2181da41c8bSAndreas Gohr foreach (['conf', 'data/pages', 'data/media', 'data/meta', 'data/media_meta', 'index'] as $dir) { 2198262a4cbSAndreas Gohr $templatedir = DOKU_FARMDIR . $template . '/' . $dir; 220801ebaa1SAndreas Gohr if (!is_dir($templatedir)) continue; 221801ebaa1SAndreas Gohr // do not copy changelogs in meta 222801ebaa1SAndreas Gohr if (substr($dir, -4) == 'meta') { 223801ebaa1SAndreas Gohr $exclude = '/\.changes$/'; 224801ebaa1SAndreas Gohr } else { 225801ebaa1SAndreas Gohr $exclude = ''; 226801ebaa1SAndreas Gohr } 2271da41c8bSAndreas Gohr if (!$this->helper->copyDir($templatedir, $animaldir . '/' . $dir, $exclude)) { 228801ebaa1SAndreas Gohr msg(sprintf($this->getLang('animal template copy error'), $dir), -1); 229801ebaa1SAndreas Gohr // we go on anyway 230801ebaa1SAndreas Gohr } 231801ebaa1SAndreas Gohr } 232801ebaa1SAndreas Gohr } 233801ebaa1SAndreas Gohr 23449f2871cSAndreas Gohr // append title to local config 23549f2871cSAndreas Gohr $ok &= io_saveFile($animaldir . '/conf/local.php', "\n" . '$conf[\'title\'] = \'' . $name . '\';' . "\n", true); 23649f2871cSAndreas Gohr 2374eba53bcSAndreas Gohr // create a random logo and favicon 2384eba53bcSAndreas Gohr if (!class_exists('\splitbrain\RingIcon\RingIcon', false)) { 2394eba53bcSAndreas Gohr require(__DIR__ . '/../3rdparty/RingIcon.php'); 2404eba53bcSAndreas Gohr } 2414eba53bcSAndreas Gohr if (!class_exists('\chrisbliss18\phpico\PHPIco', false)) { 2424eba53bcSAndreas Gohr require(__DIR__ . '/../3rdparty/PHPIco.php'); 2434eba53bcSAndreas Gohr } 2444eba53bcSAndreas Gohr try { 245b263debeSAndreas Gohr if (function_exists('imagecreatetruecolor')) { 246c3bd7eb3SAndreas Gohr $logo = $animaldir . '/data/media/wiki/logo.png'; 247c3bd7eb3SAndreas Gohr if (!file_exists($logo)) { 2481da41c8bSAndreas Gohr $ringicon = new RingIcon(64); 249c3bd7eb3SAndreas Gohr $ringicon->createImage($animaldir, $logo); 250c3bd7eb3SAndreas Gohr } 251c3bd7eb3SAndreas Gohr 252c3bd7eb3SAndreas Gohr $icon = $animaldir . '/data/media/wiki/favicon.ico'; 253c3bd7eb3SAndreas Gohr if (!file_exists($icon)) { 2541da41c8bSAndreas Gohr $icongen = new PHPIco($logo); 2551da41c8bSAndreas Gohr $icongen->saveIco($icon); 256c3bd7eb3SAndreas Gohr } 257b263debeSAndreas Gohr } 2584eba53bcSAndreas Gohr } catch (\Exception $ignore) { 2594eba53bcSAndreas Gohr // something went wrong, but we don't care. this is a nice to have feature only 2604eba53bcSAndreas Gohr } 26149f2871cSAndreas Gohr 26249f2871cSAndreas Gohr // create admin user 26349f2871cSAndreas Gohr if ($adminSetup === 'newAdmin') { 26449f2871cSAndreas Gohr $users = "# <?php exit()?>\n" . $this->makeAdminLine($adminPassword) . "\n"; 26549f2871cSAndreas Gohr } elseif ($adminSetup === 'currentAdmin') { 26649f2871cSAndreas Gohr $users = "# <?php exit()?>\n" . $this->getAdminLine() . "\n"; 2671272da0cSAndreas Gohr } elseif ($adminSetup === 'noUsers') { 268801ebaa1SAndreas Gohr if (file_exists($animaldir . '/conf/users.auth.php')) { 269801ebaa1SAndreas Gohr // a user file exists already, probably from animal template - don't overwrite 270801ebaa1SAndreas Gohr $users = ''; 271801ebaa1SAndreas Gohr } else { 272801ebaa1SAndreas Gohr // create empty user file 2731272da0cSAndreas Gohr $users = "# <?php exit()?>\n"; 274801ebaa1SAndreas Gohr } 27549f2871cSAndreas Gohr } else { 27649f2871cSAndreas Gohr $users = io_readFile(DOKU_CONF . 'users.auth.php'); 27749f2871cSAndreas Gohr } 278801ebaa1SAndreas Gohr if ($users) { 27949f2871cSAndreas Gohr $ok &= io_saveFile($animaldir . '/conf/users.auth.php', $users); 280801ebaa1SAndreas Gohr } 28149f2871cSAndreas Gohr 2826348ab5bSMichael Grosse if ($aclpolicy != '') { 2836348ab5bSMichael Grosse $aclfile = file($animaldir . '/conf/acl.auth.php'); 2842b85f30dSAndreas Gohr $aclfile = array_map('trim', $aclfile); 2856348ab5bSMichael Grosse array_pop($aclfile); 2866348ab5bSMichael Grosse switch ($aclpolicy) { 2876348ab5bSMichael Grosse case 'open': 2886348ab5bSMichael Grosse $aclfile[] = "* @ALL 8"; 2896348ab5bSMichael Grosse break; 2906348ab5bSMichael Grosse case 'public': 2916348ab5bSMichael Grosse $aclfile[] = "* @ALL 1"; 2926348ab5bSMichael Grosse $aclfile[] = "* @user 8"; 2936348ab5bSMichael Grosse break; 2946348ab5bSMichael Grosse case 'closed': 2956348ab5bSMichael Grosse $aclfile[] = "* @ALL 0"; 2966348ab5bSMichael Grosse $aclfile[] = "* @user 8"; 2976348ab5bSMichael Grosse break; 2986348ab5bSMichael Grosse default: 2996348ab5bSMichael Grosse throw new Exception('Undefined aclpolicy given'); 3006348ab5bSMichael Grosse } 3011da41c8bSAndreas Gohr $ok &= io_saveFile($animaldir . '/conf/acl.auth.php', implode("\n", $aclfile) . "\n"); 3026348ab5bSMichael Grosse 3036348ab5bSMichael Grosse global $conf; 3046348ab5bSMichael Grosse switch ($userreg) { 3056348ab5bSMichael Grosse case 'allow': 3061da41c8bSAndreas Gohr $disableactions = implode(',', array_diff(explode(',', $conf['disableactions']), ['register'])); 3071da41c8bSAndreas Gohr $ok &= io_saveFile( 3081da41c8bSAndreas Gohr $animaldir . '/conf/local.php', 3091da41c8bSAndreas Gohr "\n" . '$conf[\'disableactions\'] = \'' . $disableactions . '\';' . "\n", 3101da41c8bSAndreas Gohr true 3111da41c8bSAndreas Gohr ); 3126348ab5bSMichael Grosse break; 3136348ab5bSMichael Grosse case 'disable': 3141da41c8bSAndreas Gohr $disableactions = implode(',', array_merge(explode(',', $conf['disableactions']), ['register'])); 3151da41c8bSAndreas Gohr $ok &= io_saveFile( 3161da41c8bSAndreas Gohr $animaldir . '/conf/local.php', 3171da41c8bSAndreas Gohr "\n" . '$conf[\'disableactions\'] = \'' . $disableactions . '\';' . "\n", 3181da41c8bSAndreas Gohr true 3191da41c8bSAndreas Gohr ); 3206348ab5bSMichael Grosse break; 3216348ab5bSMichael Grosse case 'inherit': 3226348ab5bSMichael Grosse case true: 3236348ab5bSMichael Grosse // nothing needs to be done 3246348ab5bSMichael Grosse break; 3256348ab5bSMichael Grosse default: 3261da41c8bSAndreas Gohr $ok &= io_saveFile( 3271da41c8bSAndreas Gohr $animaldir . '/conf/local.php', 3281da41c8bSAndreas Gohr "\n" . '$conf[\'disableactions\'] = \'register\';' . "\n", 3291da41c8bSAndreas Gohr true 3301da41c8bSAndreas Gohr ); 3316348ab5bSMichael Grosse } 3326348ab5bSMichael Grosse } 3336348ab5bSMichael Grosse 3344664a1d2SAndreas Gohr // deactivate plugins by default FIXME this should be nicer 33549f2871cSAndreas Gohr $deactivatedPluginsList = explode(',', $this->getConf('deactivated plugins')); 3364664a1d2SAndreas Gohr $deactivatedPluginsList = array_map('trim', $deactivatedPluginsList); 3374664a1d2SAndreas Gohr $deactivatedPluginsList = array_unique($deactivatedPluginsList); 3384664a1d2SAndreas Gohr $deactivatedPluginsList = array_filter($deactivatedPluginsList); 33949f2871cSAndreas Gohr foreach ($deactivatedPluginsList as $plugin) { 340af1c6dd8SAndreas Gohr $this->helper->setPluginState(trim($plugin), $name, 0); 34149f2871cSAndreas Gohr } 34249f2871cSAndreas Gohr 34349f2871cSAndreas Gohr return $ok; 34449f2871cSAndreas Gohr } 34549f2871cSAndreas Gohr 34649f2871cSAndreas Gohr /** 34749f2871cSAndreas Gohr * Creates a new user line 34849f2871cSAndreas Gohr * 34949f2871cSAndreas Gohr * @param $password 35049f2871cSAndreas Gohr * @return string 35149f2871cSAndreas Gohr */ 3521da41c8bSAndreas Gohr protected function makeAdminLine($password) 3531da41c8bSAndreas Gohr { 35449f2871cSAndreas Gohr $pass = auth_cryptPassword($password); 3551da41c8bSAndreas Gohr $line = implode( 3561da41c8bSAndreas Gohr ':', 3571da41c8bSAndreas Gohr ['admin', $pass, 'Administrator', 'admin@example.org', 'admin,user'] 3581272da0cSAndreas Gohr ); 35949f2871cSAndreas Gohr return $line; 36049f2871cSAndreas Gohr } 36149f2871cSAndreas Gohr 36249f2871cSAndreas Gohr /** 36349f2871cSAndreas Gohr * Copies the current user as new admin line 36449f2871cSAndreas Gohr * 36549f2871cSAndreas Gohr * @return string 36649f2871cSAndreas Gohr */ 3671da41c8bSAndreas Gohr protected function getAdminLine() 3681da41c8bSAndreas Gohr { 36949f2871cSAndreas Gohr $currentAdmin = $_SERVER['REMOTE_USER']; 37049f2871cSAndreas Gohr $masterUsers = file_get_contents(DOKU_CONF . 'users.auth.php'); 37149f2871cSAndreas Gohr $masterUsers = ltrim(strstr($masterUsers, "\n" . $currentAdmin . ":")); 3721da41c8bSAndreas Gohr 37349f2871cSAndreas Gohr $newAdmin = substr($masterUsers, 0, strpos($masterUsers, "\n") + 1); 37449f2871cSAndreas Gohr return $newAdmin; 37549f2871cSAndreas Gohr } 37649f2871cSAndreas Gohr} 377