should not break anything. Work is still in progress

This commit is contained in:
Fran��ois Serman 2013-08-25 23:59:52 +00:00
parent 19c372a3d4
commit f3e116efe1
8 changed files with 370 additions and 25 deletions

3
.gitattributes vendored
View File

@ -312,9 +312,12 @@ bureau/admin/oldimg/powered_by_alternc.png -text
bureau/admin/phpinfo.php -text
bureau/admin/piwik_addaccount.php -text
bureau/admin/piwik_addsites.php -text
bureau/admin/piwik_site_dodel.php -text
bureau/admin/piwik_sitelist.php -text
bureau/admin/piwik_user_dodel.php -text
bureau/admin/piwik_useradmin.php -text
bureau/admin/piwik_userlist.php -text
bureau/admin/piwik_utils.php -text
bureau/admin/quota_show.php -text
bureau/admin/quotas_oneuser.php -text
bureau/admin/quotas_users.php -text

View File

@ -55,7 +55,6 @@ $infos = $piwik->user_add($account_name);
if (!$infos)
{
$error = $err->errstr();
//if (isset($error) && $error) {
echo "<p class=\"error\">$error</p>";
if (isset($fatal) && $fatal) {
@ -63,8 +62,10 @@ if (!$infos)
exit();
}
}
printVar($infos);
else
{
printf("%s %s\n", _('Successfully added piwik user'), $account_name);
}
include_once("foot.php");
?>

View File

@ -0,0 +1,77 @@
<?php
/*
$Id: piwik_site_dodel.php,v 1.2 2003/06/10 06:45:16 root Exp $
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2002 by the AlternC Development Team.
http://alternc.org/
----------------------------------------------------------------------
Based on:
Valentin Lacambre's web hosting softwares: http://altern.org/
----------------------------------------------------------------------
LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Original Author of file: François Serman
Purpose of file: Delete piwik websites
----------------------------------------------------------------------
*/
require_once("../class/config.php");
$fields = array (
"confirm_del" => array ("post", "string", ""),
"siteid" => array ("request", "integer", -1),
);
getFields($fields);
if ($siteid === -1) {
$error=_("Missing site parameters");
include('piwik_sitelist.php');
exit;
}
if(!empty($confirm_del) ) {
if (! $piwik->site_delete($siteid) ) {
$error=$err->errstr();
} else {
include_once('head.php');
__("Site supprimé avec succès\n");
}
include('piwik_sitelist.php');
exit;
}
include_once('head.php');
?>
<h3><?php __("Piwik site deletion confirm"); ?></h3>
<hr id="topbar"/>
<br />
<?php __("Do you really want to delete this Piwik website ?");?>
<br />
<br />
<form method="post" action="piwik_site_dodel.php" name="main" id="main">
<input type="hidden" name="siteid" value="<?php echo $siteid;?>" />
<input type="submit" class="inb" name="confirm_del" value="<?php __("Delete")?>" />
<input type="button" class="inb" name="cancel" value="<?php __("Cancel"); ?>" onclick="document.location='piwik_sitelist.php'" />
</form>
<?php
include_once('foot.php');
exit();
?>

View File

@ -1,6 +1,6 @@
<?php
/*
$Id: piwik_userlist.php, author: squidly
$Id: piwik_userlist.php, author: François Serman <fser>
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2002 by the AlternC Development Team.
@ -23,21 +23,62 @@
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Purpose of file: listing of mail accounts
Purpose of file: listing of piwik site, and manage associated credentials
----------------------------------------------------------------------
*/
require_once("../class/config.php");
include_once("head.php");
include_once("piwik_utils.php");
$fields = array (
"site_id" => array ("request", "integer", -1), // alternc ID of the piwik site
"right" => array ("post", "array", FALSE), // array of rights associated foreach user of $site_id
);
getFields($fields);
/* Get once alternc users and sites */
$piwik_alternc_users = $piwik->get_alternc_users();
$piwik_alternc_sites = $piwik->get_alternc_sites();
/* Form was submitted, need to deal with work to do. */
if ($right !== FALSE) {
// Should this stay here, or in the API?
if (!in_array($site_id, $piwik_alternc_sites))
$error = _("You don't own this piwik site!");
else {
/* Foreach row of right, extract user, and selected credential */
foreach ($right AS $user => $cred)
{
/* Ensures that the user is legitimate for that user */
/* If not, we just break the loop, and set error message */
if (!in_array($user, $piwik_alternc_users)) {
$error = sprintf('%s "%s"', _('You dont own user'), $user);
break;
}
/* Ok, current user has right to manage this piwik user. Update rights. */
printf ("%s -> %s<br />\n", $user, $cred);
if (!$piwik->site_set_user_right($site_id, $user, $cred)) {
$error = $err->errstr();
break;
}
}
}
}
/* If something went wrong, display error message, but continue with the page rendering */
if (isset($error) && $error) {
echo "<p class=\"error\">$error</p>";
}
/* Does current user still has quota ? */
if ($quota->cancreate("piwik")) {
$quotapiwik=$quota->getquota('piwik');
/* If quota are still available, display form to let user add a new site */
if ($quotapiwik['u']>0) {
?>
<h3><?php __("Add a new website");?></h3>
<form method="post" action="piwik_addsites.php" id="main" name="addsites" >
@ -50,20 +91,33 @@ if ($quota->cancreate("piwik")) {
<?php
} // quotapiwik > 0
} // cancreate piwik
/* In that part, we'll manage the rights associated to a selected piwik site. */
/* The output is the following: */
/* [ site [v]] */
/* - user1 no access () view () admin () */
/* - user2 no access () view () admin () */
/* [ submit ] */
?>
<h3><?php __("Existing Piwik monitored websites"); ?></h3>
<?php
/* Get the list of piwik sites for current user */
$sitelist = $piwik->site_list();
/* If user didn't add a website, just do nothing but display there's no site */
if (empty($sitelist)){
__("No existing Piwik users");
__("No existing Piwik websites");
} else {
/* Otherwize, display the html form, [ sitename, url, javascript code ] */
?>
<table class="tlist">
<tr><th/><th><?php __("Site name");?></th><th align=center><?php __("Site url"); ?></th></tr>
<tr><th/><th><?php __("Site name");?></th><th align=center><?php __("Site url"); ?></th><th>Javascript Code</th></tr>
<?php
$col=1;
@ -71,14 +125,52 @@ foreach ($sitelist as $site ){
$col=3-$col;
?>
<tr class="lst_clic<?php echo $col; ?>">
<td><div class="ina"><a href="#"><img src="images/delete.png" alt="<?php __("Delete"); ?>" /><?php __("Delete"); ?></a></div></td>
<td><div class="ina"><a href="/piwik_site_dodel.php?siteid=<?php echo $site->id; ?>"><img src="images/delete.png" alt="<?php __("Delete"); ?>" /><?php __("Delete"); ?></a></div></td>
<td align=right><?php echo $site->name ?></td>
<td><?php echo $site->main_url ?></td>
<td><textarea><?php echo $piwik->site_js_tag($site->id); ?></textarea></td>
</tr>
<?php
} // foreach userlist
} // foreach sitelist
/* We'll now manage credentials for piwik sites */
/* We first create a select item to choose the piwik site to administrate */
/* Then we display a list of users, and associated rights. */
/* To achieve this, we select all piwik users available for current alternc user */
/* If a piwik user has no rights on that site, its rights are set to "noaccess" */
?>
</table>
<h3><?php __("Credentials management"); ?></h3>
<form method="get">
<select name="site_id">
<?php
foreach ($sitelist as $site)
printf ('<option value="%d"%s>%s</option>', $site->id, ($site->id == $site_id) ? ' selected ' : '', $site->name);
?>
</select>&nbsp;
<input type="submit" class="inb" value="ok" />
</form>
<?php
// If a site was selected
if ($site_id != -1 && in_array($site_id, $piwik_alternc_sites)) {
echo '<form method="post">';
echo '<dl>';
foreach ($piwik->get_users_access_from_site($site_id) AS $piwik_user => $cred) {
printf("<dt>%s:</dt>\n\t<dd>%s</dd>\n", $piwik_user, piwik_right_widget('right', $piwik_user, $cred));
}
echo '</dl>';
echo '<input type="submit" name="valid" class="inb" value="' , _("submit"), '" />';
echo '</form>';
}
} // empty userlist
?>
</table>
<?php include_once("foot.php"); ?>

View File

@ -23,8 +23,8 @@
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Original Author of file: Benjamin Sonntag
Purpose of file: Delete ftp accounts
Original Author of file: François Serman
Purpose of file: Delete piwik accounts
----------------------------------------------------------------------
*/
require_once("../class/config.php");
@ -36,20 +36,25 @@ $fields = array (
getFields($fields);
if (empty($login)) {
$error=_("Missing login parameters");
include('piwik_userlist.php');
exit;
}
$error=_("Missing login parameters");
include('piwik_userlist.php');
exit;
}
if(!empty($confirm_del) ) {
if(!empty($confirm_del)) {
if (! $piwik->user_delete($login) ) {
$error=$err->errstr();
include('piwik_userlist.php');
exit;
} else {
include_once('head.php');
printf("Utilisateur %s supprimé avec succès\n", $login);
}
} else {
include_once('head.php');
include('piwik_userlist.php');
exit;
}
include_once('head.php');
?>
<h3><?php __("Piwik accounts deletion confirm"); ?></h3>
<hr id="topbar"/>
@ -67,6 +72,4 @@ if(!empty($confirm_del) ) {
<?php
include_once('foot.php');
exit();
}
?>

View File

@ -0,0 +1,145 @@
<?php
/*
$Id: piwik_userlist.php, author: François Serman <fser>
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2002 by the AlternC Development Team.
http://alternc.org/
----------------------------------------------------------------------
Based on:
Valentin Lacambre's web hosting softwares: http://altern.org/
----------------------------------------------------------------------
LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Purpose of file: Admin piwik users right for piwik sites
----------------------------------------------------------------------
*/
require_once("../class/config.php");
include_once("head.php");
$fields = array (
"user_name" => array ("request", "string", FALSE),
"site_id" => array ("post", "integer", -1),
"right" => array ("post", "string", FALSE),
);
getFields($fields);
if ($user_name === FALSE)
{
$error = _('No piwik user specified');
}
else
{
// Add a user to a piwik website
if ($site_id != -1 && $right !== FALSE) {
$db->query("SELECT COUNT(*) AS ok FROM piwik_sites WHERE uid='$cuid' AND piwik_id='$site_id'");
$db->next_record();
if ($db->f('ok')!=1)
{
$error = _("You don't own this piwik website");
}
else
{
$db->query("SELECT COUNT(*) AS ok FROM piwik_users WHERE uid='$cuid' AND login='$user_name'");
$db->next_record();
if ($db->f('ok')!=1)
{
$error = _("You don't own this piwik user");
}
else
{
$piwik_rights = array("noaccess", "view", "admin");
if (in_array($right, $piwik_rights))
{
$api_data = $piwik->site_set_user_right($site_id, $user_name, $right);
if ($api_data === FALSE)
echo $error;
else
__('success');
}
else
{
$error = _("This right does not exist");
}
}
}
}
$user_piwik_sites = array();
$db->query("SELECT piwik_id FROM piwik_sites WHERE uid='$cuid'");
while ($db->next_record())
array_push($user_piwik_sites, $db->f('piwik_id'));
// Weird behaviour of php: array_push products an array such as:
// array_push(array(1,2,3) , 4) produces
// array(0 => 1, 1 => 2, 2 => 3, 3 => 4)
// So for further comparison, we need to exchange keys and values
$user_piwik_sites = array_flip($user_piwik_sites);
$user_piwik_users = array();
$db->query("SELECT login FROM piwik_users WHERE uid='$cuid'");
while ($db->next_record())
array_push ($user_piwik_users, $db->f('login'));
// Swap keys and values, see user_piwik_sites
$user_piwik_users = array_flip($user_piwik_users);
}
if (isset($error) && $error) {
echo "<p class=\"error\">$error</p>";
exit;
}
?>
<h3><?php printf('%s "%s"', _("Rights for user"), $user_name); ?></h3>
<?php
$raw_sites = $piwik->get_site_list();
$piwik_sites = array();
foreach ($raw_sites AS $site) {
$piwik_sites[ $site->idsite ] = array('name' => $site->name, 'url' => $site->main_url);
}
$raw_access = $piwik->get_site_access($user_name);
$piwik_user_sites = array_intersect_ukey($piwik_sites, $user_piwik_sites, "strcmp");
$available_user_sites = $piwik_user_sites;
echo '<ul>';
foreach ($raw_access AS $access)
{
unset($available_user_sites[ $access->site ]);
printf("<li>%s -> %s</li>\n", $piwik_sites[ $access->site ]['name'], $access->access);
}
echo '</ul>';
if (count($available_user_sites)>0)
{
?>
<h3><?php printf('%s "%s"', _("Add rights to user"), $user_name); ?></h3>
<ul>
<?php
foreach ($available_user_sites AS $current_id_site => $available_user_site)
{
printf('<li>%s <form method="post"><input type="hidden" name="site_id" value="%d">
<select name="right">
<option value="noaccess">%s</option>
<option value="view">%s</option>
<option value="admin">%s</option>
</select>
<input type="submit" name="add" value="ajouter" class="inb" /></form></li>', $available_user_site['name'], $current_id_site, _("noacces"), _("view"), _("admin"));
}
?>
</li>
<?php
}
include_once("foot.php"); ?>

View File

@ -47,7 +47,6 @@ if ($quota->cancreate("piwik")) {
<br/>
<hr/>
<?php
} // cancreate piwik
if ($quotapiwik['u']>0) {
?>
@ -60,6 +59,7 @@ if ($quotapiwik['u']>0) {
<br/>
<hr/>
<?php
} // quota > 0
} // cancreate piwik
?>

View File

@ -0,0 +1,24 @@
<?php
$piwik_available_rights = array('noaccess', 'view', 'admin');
function piwik_right_widget($name, $subname, $cred) {
global $piwik_available_rights;
$elem = '';
$i = 1;
foreach ($piwik_available_rights AS $piwik_right) {
$elem .= sprintf('<input type="radio" id="%s-%d" name="%s[%s]" value="%s" %s/>', $name . $subname, $i, $name, $subname, $piwik_right, (($cred === $piwik_right) ? ' checked ' : ''));
$elem .= sprintf('<label for="%s-%d">%s</label>', $name . $subname, $i++, _($piwik_right));
}
return $elem;
}
function piwik_select_element($name, $credz = 'noaccess') {
$elem = '<select name="' . $name . '">';
foreach (array('noaccess', 'view', 'admin') AS $cred)
$elem .= "\t" . '<option value="' . $cred . '"' . (($cred === $credz) ? ' selected ' : '') . '>' . $cred . '</option>' . "\n";
$elem .= '</select>';
return $elem;
}