<?php
/**
* class AdminController
*/
class AdminController extends Zend_Controller_Action
{
function init()
{
$this->initView();
$this->view->baseUrl = $this->_request->getBaseUrl();
$this->defaultNamespace = new Zend_Session_Namespace('Default');
/* load "general" configuration from settings.ini */
$this->cfg = new Zend_Config_Ini('../app/config/settings.ini', 'general');
}
public function getResourceId()
{
return 'admin';
}
/**
* function indexAction
*/
public function indexAction()
{
$userlist = array();
if($handle = opendir($this->cfg->userpath))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && $file != "admin.xml" && strpos($file, '.xml',1))
{
array_push($userlist, $file);
}
}
closedir($handle);
sort($userlist);
}
$view = new Zend_View();
$acl = new AclPlugin();
$view->assign('acl', $acl);
$view->setScriptPath('../app/views/scripts');
// the controller script assign necessary variables to the view
// before it hands over control to the view script
$view->assign('baseUrl', (string) $this->cfg->baseUrl);
$view->assign('domain', (string) $this->cfg->domain);
$view->assign('identity', (array) $this->defaultNamespace->identity);
$view->assign('pagetitle', (string) $this->cfg->pagetitle);
$view->assign('pagesubtitle', (string) $this->cfg->pagesubtitle);
$view->assign('layout', (string) $this->cfg->layout);
$view->assign('userlist', (array) $userlist);
$view->assign('userpath', (string) $this->cfg->userpath);
// render a script
echo $view->render('admin/index.php');
}
/**
* function deleteUserAction
*/
public function deleteUserAction()
{
$user = $this->getRequest()->getParam('id');
$file = $this->cfg->userpath . $user;
unlink($file);
$username = substr($user, 0, strlen($user)-4);
$passwordfile = file('../app/controllers/password.txt');
foreach($passwordfile as $line)
{
if($username == substr($line, 0, strlen($username)))
{
}
else
{
$pwd .= $line;
}
}
$fp = fopen('../app/controllers/password.txt', "w");
fwrite($fp, $pwd);
$this->_redirect($this->cfg->baseUrl . 'admin/index');
}
/**
* function adminUserAction
*/
public function adminUserAction()
{
$user = $this->getRequest()->getParam('id');
$file = $this->cfg->userpath . $user;
$profile = simplexml_load_file($file);
// create changed userprofil
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$xml .= "<profil>\n";
$xml .= " <username>" . $profile->username . "</username>\n";
$xml .= " <email>" . $profile->email . "</email>\n";
$xml .= " <status>admin</status>\n";
$xml .= "</profil>";
$fp = fopen($file, "w");
fwrite($fp, $xml);
$username = substr($user, 0, strlen($user)-4);
$passwordfile = file('../app/controllers/password.txt');
// create new password
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '';
while ($i <= 7)
{
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
//send mail
$message = "your new password for your account " . $username . ":";
$message .= "\n\n" . $pass;
$betreff = "new password for your account";
mail($profile->email, $betreff, $message, "From: atuin administration <hide@address.com>");
// update password.txt
$pwd = '';
foreach($passwordfile as $line)
{
if($username == substr($line, 0, strlen($username)))
{
$str = $username . ':' . "admin" . ':' . $pass;
$md5 = md5($str);
$new = $username . ':' . "admin" . ':' . $md5 . "\n";
$pwd .= $new;
}
else
{
$pwd .= $line;
}
}
$fp = fopen('../app/controllers/password.txt', "w");
fwrite($fp, $pwd);
//echo $pass; exit();
$this->_redirect($this->cfg->baseUrl . 'admin/index');
}
/**
* function memberUserAction
*/
public function memberUserAction()
{
$user = $this->getRequest()->getParam('id');
$file = $this->cfg->userpath . $user;
$profile = simplexml_load_file($file);
// create changed userprofil
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$xml .= "<profil>\n";
$xml .= " <username>" . $profile->username . "</username>\n";
$xml .= " <email>" . $profile->email . "</email>\n";
$xml .= " <status>member</status>\n";
$xml .= "</profil>";
$fp = fopen($file, "w");
fwrite($fp, $xml);
$username = substr($user, 0, strlen($user)-4);
$passwordfile = file('../app/controllers/password.txt');
// create new password
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '';
while ($i <= 7)
{
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
//send mail
$message = "your new password for your account " . $username . ":";
$message .= "\n\n" . $pass;
$betreff = "new password for your account";
mail($profile->email, $betreff, $message, "From: atuin administration <hide@address.com>");
// update password.txt
$pwd = '';
foreach($passwordfile as $line)
{
if($username == substr($line, 0, strlen($username)))
{
$str = $username . ':' . "member" . ':' . $pass;
$md5 = md5($str);
$new = $username . ':' . "member" . ':' . $md5 . "\n";
$pwd .= $new;
}
else
{
$pwd .= $line;
}
}
$fp = fopen('../app/controllers/password.txt', "w");
fwrite($fp, $pwd);
//echo $pass; exit();
$this->_redirect($this->cfg->baseUrl . 'admin/index');
}
}
?>