Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to change vbox user password on uberspace. Thanks to @_einstein_
<?php
// Config
// Der Server auf dem dein Uberspace läuft
$server = '';
// Dein Nutzername
$username = '';
// Für aufgeschaltete Domains
// Bsp: Wenn "petrasblog.de" im Namensraum "blog" liegt:
// $display = 'petrasblog.de';
// $namespace = 'blog';
$display = '';
$namespace = '';
// Config End
// Checks whether current password is correct
// returns true/false
function setNewPassword($strMailbox, $strPassword)
{
$strPassword = utf8_decode($strPassword);
$strCommand = 'vpasswd ' . escapeshellarg($strMailbox);
$descriptorspec = array(
0 => array("pipe", "r")
);
$process = proc_open($strCommand, $descriptorspec, $pipes, NULL, NULL);
if(is_resource($process)) {
fwrite($pipes[0], $strPassword);
fclose($pipes[0]);
$return_value = proc_close($process);
if($return_value == 0) {
return true;
}
}
return false;
}
// Enforce https
if($_SERVER["HTTPS"] != "on") {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
// Init variables
$changed = false;
$success = false;
$domain = sprintf("%s.%s.uberspace.de", $username, $server);
$display = $display == '' ? $domain : $display;
// Construct part before "@"
// if namespace is given "[namespace]-name" else "name"
$name = sprintf("%s%s%s", $namespace, $namespace == '' ? '' : '-', $_POST['mail']);
$password = $_POST['oldpw'];
$newpw = $_POST['newpw'];
if( isset($name) && isset($password) && isset($newpw) ) {
$changed = true;
// Test password
$mbox = @imap_open("{localhost:993/imap/ssl/novalidate-cert}", $name.'@'.$domain, $password);
if($mbox != false) {
$success = setNewPassword($name, $newpw);
}
else $success = false;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<title>Mail-Passwort ändern</title>
<meta charset="utf-8">
<style>
.success {
color: green;
}
.failure {
color: red;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h2>Mail-Passwort ändern</h2>
<?php if($changed): ?>
<p class="<?php echo $success ? 'success' : 'failure'; ?>"><?php echo $success ? 'Passwort geändert.' : 'Ändern fehlgeschlagen (Falsches Passwort?)'; ?></p>
<?php endif; ?>
<form method="POST">
<label for="mail">Mail</label>
<div class="input-group">
<input class="form-control" type="text" name="mail"> <span class="input-group-addon">@<?php echo $display;?></span>
</div>
<label for="oldpw">Altes Passwort</label>
<input class="form-control" type="password" name="oldpw">
<label for="newpw">Neues Passwort</label>
<input class="form-control" type="password" name="newpw">
<input class="form-control" type="submit" value="Ändern">
</form>
Based on <a href="https://gist.github.com/nichdu/9047330">changemail.php</a> by user Tjark 'nichdu' Saul.
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment