diff --git a/utils/lodspk.sh b/utils/lodspk.sh index a47c74705d3c80f8b15125c5ccc824b63c9d9f98..97df39703552b078dacb337ee1fa3b144e48ed2b 100755 --- a/utils/lodspk.sh +++ b/utils/lodspk.sh @@ -25,6 +25,8 @@ USAGE=$USAGE"\n===MODULES===\n" USAGE=$USAGE" Enable module:\t\t\t\t\t\t$0 enable module position\n" USAGE=$USAGE" Disable module:\t\t\t\t\t$0 disable module\n" USAGE=$USAGE" List modules:\t\t\t\t\t$0 list modules\n" +USAGE=$USAGE" \n===ADMIN USER===\n" +USAGE=$USAGE" Change password:\t\t\t\t\t$0 change password NEWPASSWORD\n" USAGE=$USAGE"\n===VERSION==\n" USAGE=$USAGE" Version:\t\t\t\t\t\t$0 version\n" USAGEDEBUG="Usage: $0 debug on|off" @@ -34,7 +36,7 @@ if [[ $# -eq 0 || "$1" == "--help" ]]; then fi DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -operations=( create delete debug backup restore default cache version enable disable add remove list details ) +operations=( create delete debug backup restore default cache version enable disable add remove list details change ) currentOperation= if [[ ${operations[@]} =~ $1 ]]; then @@ -289,3 +291,27 @@ if [[ $currentOperation == "details" ]]; then $DIR/modules/detail-component.sh $detailOperation $3 exit fi + +## Change +if [[ $currentOperation == "change" ]]; then + if [ "$#" != "3" ]; then + echo -e $USAGE + exit 1 + fi + changeOperation=( password ) + if [[ ${changeOperation[@]} =~ $2 && $2 != "" ]] + then + changeOperation=$2 + else + echo -e "Option '$2' not supported. Operation aborted\n" >&2 + echo -e $USAGE + exit 1 + fi + if [[ $3 == "" ]]; then + echo "Error: No new password given" + echo -e $USAGE; + exit 1 + fi + php $DIR/modules/change-password.php $3 + exit +fi diff --git a/utils/modules/change-password.php b/utils/modules/change-password.php new file mode 100644 index 0000000000000000000000000000000000000000..b1903c9b2d2b05028439a541601860b31a124ec5 --- /dev/null +++ b/utils/modules/change-password.php @@ -0,0 +1,27 @@ +<?php + +error_reporting(E_ERROR); +$s = 'settings.inc.php'; +$c = file_get_contents($s); + +$newPass = $argv[1]; + +$lines = explode("\n", $c); +$newLines = array(); +foreach($lines as $k => $v){ + if(preg_match("/\?>/", $v) == 0){ + if(preg_match("/[\"']admin[\"']/", $v) == 0 || + preg_match("/[\"']pass[\"']/", $v) == 0){ + + array_push($newLines,$v); + } + } +} +$newLine = "\$conf['admin']['pass'] = '".$newPass."';"; +array_push($newLines,$newLine); +array_push($newLines,"?>"); + +$c = implode("\n", $newLines); +file_put_contents($s, $c); +echo "Password changed successfully!\n\n"; +?>