[Script] Create User Accounts within Madsonic

Scripts for Madsonic
User avatar
Madsonic
Administrator
Administrator
Posts: 940
Joined: 07 Dec 2012, 03:58
Has thanked: 1116 times
Been thanked: 430 times
Contact:

[Script] Create User Accounts within Madsonic

Unread post by Madsonic » 04 Apr 2013, 13:53

Hi,

i wrote a short windows script to create User Accounts within Madsonic.

i used a special wget version which can handle self signed certificates if you use SSL.

NEW: Set Default Security GroupID & new Role searchRole

REST API 1.9.2 needed (Madsonic 5.0)

Code: Select all

::::::::::::::::::::::::::::
:: Create Madsonic Acount ::
::::::::::::::::::::::::::::

:: Create Madsonic Useraccounts
:: edit username/password/serverlink to your need

set username=admin
set password=admin
set serverlink=http://127.0.0.1:4040

:::::::::::::::::::::::::::::::::::::::::::::::::

set wgetsettings=--spider --no-check-certificate --cookies=on --keep-session-cookies --save-cookies=%temp%\cookie.txt

.\bin\wget %wgetsettings% --user-agent=Mozilla "%serverlink%/login.view?user=%username%&password=%password%" 

:: Create Backup Admin
.\bin\wget %wgetsettings% --load-cookies=%temp%\cookie.txt --referer="%serverlink%" "%serverlink%/rest/createUser.view?u=%username%&p=%password

%&v=1.9.2&c=remoteregister&username=sysop&password=sysop1$&email=sysop@home.com&adminRole=true&settingsRole=true&streamRole=true&jukeboxRole=true&downloadRole=true

&uploadRole=true&playlistRole=true&coverartRole=true&commentRole=true&podcastRole=true&shareRole=true&coverArtRole=true&commentRole=true&searchRole=true&groupId=0" 

:: Create Guest
.\bin\wget %wgetsettings% --load-cookies=%temp%\cookie.txt --referer="%serverlink%" "%serverlink%/rest/createUser.view?u=%username%&p=%password

%&v=1.9.2&c=remoteregister&username=guest&password=guest2$&email=guest@home.com&settingsRole=true&streamRole=true&settingsRole=false&jukeboxRole=false&downloadRole

=false&uploadRole=false&playlistRole=false&coverartRole=false&commentRole=false&podcastRole=false&shareRole=false&searchRole=false&groupId=1" 

:: Create Friend
.\bin\wget %wgetsettings% --load-cookies=%temp%\cookie.txt --referer="%serverlink%" "%serverlink%/rest/createUser.view?u=%username%&p=%password

%&v=1.9.2&c=remoteregister&username=friend&password=friend3$&email=friend@home.com&settingsRole=true&streamRole=true&jukeboxRole=false&downloadRole=true&uploadRole

=true&playlistRole=true&coverartRole=false&commentRole=false&podcastRole=false&shareRole=false&commentRole=true&searchRole=true&groupId=3" 
best regards
Attachments
CreateUser.zip
(1.71 MiB) Downloaded 294 times

gurutech
Contributor
Contributor
Posts: 323
Joined: 02 Jan 2013, 04:56
Has thanked: 11 times
Been thanked: 105 times

Re: [Script] Create User Accounts within Madsonic

Unread post by gurutech » 05 Apr 2013, 05:02

I've added the following to the script, so it will prompt you for a username, password (which will NOT be hidden), email address, and access level.

To implement, add the following to the beginning of the script, just after the section where you add your "admin" ID and password and the server URL:

Code: Select all

set /p user= "Username: "
set /p userpw= "Password: "
set /p useremail= "E-Mail: "

echo 0 = FULL ACCESS
echo 1 = GUEST
echo 2 = FAMILY
echo 3 = FRIENDS
echo 4 = LIMITED
echo.
set /p accesslevel= "Enter # for Access Level: "
Then add the following line at the END of the script. Comment out the three existing lines (samples) to create a new admin, guest, and friend.

Code: Select all

.\bin\wget %wgetsettings% --load-cookies=%temp%\cookie.txt --referer="%serverlink%" "%serverlink%/rest/createUser.view?u=%username%&p=%password%&v=1.9.2&c=remoteregister&username=%user%&password=%userpw%$&email=%useremail%&settingsRole=true&streamRole=true&jukeboxRole=false&downloadRole=false&uploadRole=false&playlistRole=true&coverartRole=false&commentRole=false&podcastRole=false&shareRole=true&commentRole=true&searchRole=true&groupId=%accesslevel%" >nul
I'm working on adding capability to set permissions on individual components (Jukebox, streaming, download, upload, etc...) through being prompted. Will reply again with that update.
These users thanked the author gurutech for the post:
Madsonic

e1z0
Contributor
Contributor
Posts: 11
Joined: 05 Feb 2014, 23:33
Has thanked: 1 time
Been thanked: 4 times

Re: [Script] Create User Accounts within Madsonic

Unread post by e1z0 » 23 Mar 2014, 04:09

Creating user accounts using php as easy as shell scripts for example for external php registration. So here is the code:

Code: Select all

// ADMINISTRATOR ACCOUNT INFO
$ADMIN = 'admin';
$PASS = 'verylongpassword';
$HOST = 'http://127.0.0.1:4040'; # we not use external URL for security reasons
// USER PERMISSIONS
$STREAMING='true';
$JUKEBOX='false';
$DOWNLOAD='false';
$UPLOAD='false';
$PLAYLIST='true';
$COVERART='false';
$COMMENT='false';
$PODCAST='false';
$SHARE='false';
$COMMENT='true';
$SEARCH='true';
$GROUPID='3';

Code: Select all

// function to register user to Madsonic database using external API's
function madsonic_regiser($username,$password,$email) {
    global $ADMIN, $PASS, $HOST, $STREAMING, $JUKEBOX, $DOWNLOAD, $UPLOAD, $PLAYLIST, $COVERART, $COMMENT, $PODCAST, $SHARE, $COMMENT, $SEARCH, $GROUPID, $INVITE;     
QUERY = $HOST."/rest/createUser.view?u=".$ADMIN."&p=".$PASS."&v=1.9.2&c=remoteregister&username=".$username."&password=".$password."&email=".$email."&settingsRole=true&streamRole=".$STREAMING."&jukeboxRole=".$JUKEBOX."&downloadRole=".$DOWNLOAD."&uploadRole=".$UPLOAD."&playlistRole=".$PLAYLIST."&coverartRole=".$COVERART."&commentRole=".$COMMENT."&podcastRole=".$PODCAST."&shareRole=".$SHARE."&commentRole=".$COMMENT."&searchRole=".$SEARCH."&groupId=".$GROUPID;
$ch = curl_init($QUERY);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);

Cheers!  :) 
}
These users thanked the author e1z0 for the post:
Madsonic

Post Reply