Beispiel #1
0
function importFile($file, $meta)
{
    $user = new User();
    $name = decodeName($file);
    $name = preg_replace('/\\s+\\d+$/', "", $name);
    if ($_REQUEST['group']) {
        $name = $_REQUEST['group'] . $GLOBALS['pie']['group_delimiter'] . $name;
    }
    if ($meta['user']) {
        // Old style author.
        $meta['author'] = $meta['user'];
        unset($meta['user']);
    }
    if (!$meta['stamp']) {
        $meta['stamp'] = filemtime($file);
    }
    if (!$meta['type']) {
        // Determine file type.
        if (preg_match('/\\.([0-9A-Za-z]{1,5})$/', $name, $match)) {
            // File type can be determined by file name suffix.
            $map = new MapFile();
            if ($type = $map->read($GLOBALS['pie']['library_path'] . "/share/suffix.map", strtolower($match[1]))) {
                $meta['type'] = $type;
            }
        } elseif (function_exists("mime_content_type")) {
            $meta['type'] = mime_content_type($file);
        }
    }
    // User mapping.
    if (!$meta['author'] && $_REQUEST['author']) {
        $meta['author'] = $_REQUEST['author'];
    }
    if (!$user->exists($meta['author']) && $_REQUEST['author']) {
        $meta['author'] = $_REQUEST['author'];
    }
    $temp = pieTempName("_import");
    if (!copy($file, $temp)) {
        return false;
    }
    $f = new File();
    $f->name = $name;
    $f->meta = $meta;
    return $f->write($temp);
}
Beispiel #2
0
 function write($user, $key, $value)
 {
     if (!$key && !$value) {
         $map = new MapFile();
         return $map->write($GLOBALS['pie']['run_path'] . "/user/pref.map", $user, '');
     }
     // Read and update the cache.
     $this->cache = array();
     $this->user = $user;
     $this->read($user, $key);
     $this->cache[$key] = $value;
     if (!@$this->cache['stamp']) {
         $this->cache['stamp'] = time();
     }
     $data = "";
     ksort($this->cache);
     foreach ($this->cache as $k => $v) {
         $v = str_replace("|", "/", $v);
         $data .= "|{$k}={$v}";
     }
     $data = substr($data, 1);
     $map = new MapFile();
     return $map->write($GLOBALS['pie']['run_path'] . "/user/pref.map", $user, $data);
 }
Beispiel #3
0
pieRequireUser();
pieHead("edit");
if (@$_REQUEST['user']) {
    // A user has been specified.
    $_REQUEST['user'] = pieGetOption($_REQUEST['user']);
    $user = new User();
    if (!$user->isValidName($_REQUEST['user'])) {
        pieError("BadUser");
    }
    if (!$user->exists($_REQUEST['user'])) {
        pieError("BadUser");
    }
} elseif ($_SESSION['user']) {
    // No user has been specified:
    // display information about myself.
    $_REQUEST['user'] = $_SESSION['user'];
}
if (!@$_REQUEST['user']) {
    pieError("NoUser");
}
$map = new MapFile();
$data = array('user' => htmlspecialchars($_REQUEST['user']), 'realname' => "—", 'lastlogin' => date($GLOBALS['pie']['time_format'], $map->read($GLOBALS['pie']['run_path'] . "/user/login.map", $_REQUEST['user'])));
$pref = new UserPref();
if (($val = $pref->read(@$_REQUEST['user'], 'realname')) !== false) {
    $data['realname'] = $val;
}
if (($val = $pref->read(@$_REQUEST['user'], 'registered')) !== false) {
    $data['registered'] = date($GLOBALS['pie']['time_format'], $val);
}
pieNotice("UserData", $data);
pieTail();
Beispiel #4
0
        if ($pw != crypt($_REQUEST['password'], $salt)) {
            // The entered password is just wrong.
            pieLog("error");
            pieHead("browse");
            pieError("FailureForm");
        }
        // Update user record with new style password.
        $user->write($_REQUEST['username'], $user->encrypt($_REQUEST['password']));
    }
    // The login succeeded.
    $session = new Session();
    if (!$session->start()) {
        pieHead("browse");
        pieError("SessionError");
    }
    $_SESSION['user'] = $_REQUEST['username'];
    $map = new MapFile();
    $lastlogin = $map->read($GLOBALS['pie']['run_path'] . '/user/login.map', $_REQUEST['username']);
    $map->write($GLOBALS['pie']['run_path'] . '/user/login.map', $_REQUEST['username'], time());
    pieLog("user");
    pieHead("browse");
    if (!$_REQUEST['todo']) {
        $_REQUEST['todo'] = 'page';
        $_REQUEST['page'] = $GLOBALS['pie']['default_page'];
    }
    pieError("SuccessForm", array('lastlogin' => date($GLOBALS['pie']['time_format'], $lastlogin)));
} else {
    // Print the login form.
    pieHead("browse");
    pieError("LoginForm");
}
Beispiel #5
0
}
// Prepare meta data of the file:
$file->name = $name;
$file->meta = array('stamp' => time(), 'author' => $GLOBALS['pie']['user']);
// .. file size
if ($_FILES['upload']['size']) {
    $file->meta['size'] = $_FILES['upload']['size'];
} else {
    $file->meta['size'] = filesize(pieTempName("_upload"));
}
// .. file type
if (preg_match('/^[a-z]+\\/[a-z]+[\\w\\-\\+\\.]*\\w+$/', $_FILES['upload']['type'])) {
    $file->meta['type'] = $_FILES['upload']['type'];
} elseif (preg_match('/\\.([0-9A-Za-z]{1,5})$/', $name, $match)) {
    // File type is determined by file name suffix.
    $map = new MapFile();
    if ($type = $map->read("{$lib}/share/suffix.map", strtolower($match[1]))) {
        $file->meta['type'] = $type;
    }
} elseif (function_exists("mime_content_type")) {
    $file->meta['type'] = mime_content_type(pieTempName("_upload"));
}
if (@$_REQUEST['comment']) {
    $file->meta['comment'] = pieGetOption($_REQUEST['comment']);
}
if (!$file->write(pieTempName("_upload"))) {
    pieError("FileWriteError");
}
pieLog("edit");
pieNotice("UploadComplete");
pieTail();
Beispiel #6
0
        $pref->write($user, 'realname', pieGetOption(@$_REQUEST['realname']));
    }
    if ($_REQUEST['mail']) {
        $pref->write($user, 'mail', pieGetOption(@$_REQUEST['mail']));
    }
    if ($_REQUEST['cols']) {
        $pref->write($user, 'cols', intval(@$_REQUEST['cols']));
    }
    if ($_REQUEST['rows']) {
        $pref->write($user, 'rows', intval(@$_REQUEST['rows']));
    }
    pieLog("user");
    pieNotice("UpdateSuccessful");
} else {
    // Display the form.
    $data = array('user' => htmlspecialchars($user), 'admin' => "—", 'registered' => 0, 'cols' => 80, 'rows' => 20);
    $map = new MapFile();
    $data['lastlogin'] = date($GLOBALS['pie']['time_format'], $map->read($GLOBALS['pie']['run_path'] . "/user/login.map", $user));
    $data['updated'] = date($GLOBALS['pie']['time_format'], $pref->read($user, 'stamp'));
    $data['registered'] = date($GLOBALS['pie']['time_format'], $pref->read($user, 'registered'));
    if (pieIsSuperuser($user)) {
        $data['admin'] = "√";
    }
    foreach (array('realname', 'mail', 'cols', 'rows') as $i) {
        if (($val = $pref->read($user, $i)) !== false) {
            $data[$i] = $val;
        }
    }
    pieNotice("PreferencesForm", $data);
}
pieTail();
Beispiel #7
0
 function write($user, $password)
 {
     $map = new MapFile();
     return $map->write($this->root . '/password.map', $user, $password);
 }
Beispiel #8
0
<?php

/*
 *	Display a list of available users.
 */
include_once "{$lib}/class/mapfile.php";
include_once "{$lib}/class/user.php";
include_once "{$lib}/share/auth.php";
include_once "{$lib}/share/link.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
pieRequireUser();
pieHead("edit");
pieNotice("TableHead");
$user = new User();
$map = new MapFile();
$n = 0;
for ($name = $user->first(); $name; $name = $user->next()) {
    $login = $map->read($GLOBALS['pie']['run_path'] . "/user/login.map", $name);
    $n++;
    print '<tr class="' . ($n % 2 ? "oddRow" : "evenRow") . '">' . "<td>" . pieMakeLink(htmlspecialchars($name), array('user' => $name, 'action' => "userinfo"), array('class' => "itemLink")) . "</td>" . "<td>" . ($login ? date($GLOBALS['pie']['time_format'], $login) : "&mdash;") . "</td>" . "</tr>\n";
}
pieNotice("TableFoot", array('count' => $n));
pieTail();