Toggle Menu

Snippets

Wo gehobelt wird, da fallen Späne...

Benutzern das Ändern des MySQL Passworts ermöglichen

Wenn man mit mehreren Benutzern auf einem Datenbankserver arbeitet und die Benutzer gerne ihr eigenes Passwort benutzen möchten, so kann euch dieser Code eventuell weiterhelfen. Herunterladen

<?php

/**
 * mySQL-changePassword.php
 *
 * @author  Andreas Mueller <webmaster@am-wd.de>
 * @version 1.0-20150404
 *
 * @license MIT
 *
 * @description
 * This script allowes to modify the password of MySQL Database users
**/

// ==================================================================
// VARS
// ==================================================================
$superuser = ''; // User with full admin rights (root)
$superpass = ''; // Password for this user
$allowed_users = array(''); // Array with usernames, who are allowed to change their passwords

// enforce SSL layer encryption (HTTPS)
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') {
	header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUERST_URI']);
}

// ==================================================================
// CHANGES BELOW AT YOUR OWN RISK
// ==================================================================

// Set encoding properly
header('Content-Type: text/html;charset=UTF-8');

if (isset($_POST['action']) && $_POST['action'] == 'change') {
	if (!in_array($_POST['user'], $allowed_users)) {
		die("<strong>Error:</strong> User not allowed");
	}

		// establish connection to database
		$sql = new mysqli('localhost', $superuser, $superpass, 'mysql', 3306);
		$sql->query("SET character_set_client = 'utf8', character_set_server = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_results = 'utf8', lc_time_names = 'de_DE'");
		$res = $sql->query("SELECT COUNT(*) as count FROM mysql.user WHERE User = '".$_POST['user']."' AND Password = PASSWORD('".$_POST['old']."');");
		if ($res->fetch_object()->count != 1) {
			die("<strong>Error:</strong> Password wrong");
		}

		$sql->query("UPDATE mysql.user SET Password = PASSWORD('".$_POST['password']."') WHERE User = '".$_POST['user']."';");
		echo $sql->affected_rows . " User changed";
		$sql->close();
} else {
	?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
	<h2>Change MySQL Password</h2>
	<table>
		<tr>
			<td>User:</td>
			<td><input type="text" name="user" size="30" placeholder="MySQL Username" /></td>
		</tr>
		<tr>
			<td>Old Password:</td>
			<td><input type="password" name="old" size="30" /></td>
		</tr>
		<tr>
			<td>New Password:</td>
			<td><input type="password" name="password" size="30" /></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td><input type="submit" name="action" value="change" /></td>
		<tr>
	</table>
</form>
	<?
}
?>

MatLab 2014a unter Yosemite ausführen

MatLab 2014a prüft beim Start, ob die ProdukVersion des Systems stimmt. Doch leider geht das unter Yosemite (OS X 10.10) schief (warum auch immer). Mit diesem Skript wird vor dem Start die ProduktVersion modifiziert und dann MatLab gestartet. Herunterladen

#!/usr/bin/env bash

# ===================================================================
# MatLab.sh
#
# @author   Andreas Mueller, webmaster@am-wd.de
# @encoding UTF-8
# @editor   ViM, ts=2
# @version  1.0-20141024
#
# @license  MIT
#
# @description
# MatLab 2014a has a problem with the ProductVersion
# from Mac OS X Yosemite (10.10) so we temporarily switch
# the ProductVersion and run MatLab.
# If MatLab is terminated, the script will place back the
# correct ProductVersion
#
# On first run a backup from the original file will be made
# ===================================================================

# please set these parameters correctly
MATLAB=/Applications/MATLAB_R2014a.app
PATCHVERSION=10.90

#####################################################################
###            NO MODIFICATIONS BELOW THIS LINE                   ###
#####################################################################

# get your ID - hopefully it will be root
ID=$(id -u)

# prepare vars
FILE=/System/Library/CoreServices/SystemVersion.plist
BCKU=/System/Library/CoreServices/SystemVersion.plist.backup

# check for root permissions
# otherwise nothing is possible
if [ $ID -ne 0 ]; then
	echo "You don't have root permissions!"
	echo "Aborting"
	exit 1;
fi

# check for Backup
if [ ! -f $BCKU ]; then
	echo -n "creating backup..."
	rsync -aq $FILE $BCKU
	echo " DONE"
fi

# get old Version
OLDVERSION=$(defaults read $FILE ProductVersion)

# write new patched version into file
defaults write $FILE ProductVersion -string "$PATCHVERSION"
# convert it back from binary to xml (don't know why always want to write binary)
plutil -convert xml1 $FILE
# and reset permissions
chmod 0444 $FILE

# open up MatLab as yourself if you called only sudo
if [ "$SUDO_USER" == "" ]; then
	open $MATLAB
else
	su $SUDO_USER -c "open $MATLAB"
fi

## write back old version
#defaults write $FILE ProductVersion -string "$OLDVERSION"
## and convert it back to xml
#plutil -convert xml1 $FILE

# simpler idea: just write original file back
rsync -aq $BCKU $FILE
chmod 0444 $FILE

exit 0