summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2012-03-06 16:48:38 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2012-03-06 16:48:38 -0500
commita7b336e3265fc59fa0c8ba56744178c7098699cf (patch)
tree04049937fd70be1c771c3205f708037547798b3d
parentca60de30bc8608b1028a7b865785edb1911f9b89 (diff)
downloadampache-a7b336e3265fc59fa0c8ba56744178c7098699cf.tar.gz
ampache-a7b336e3265fc59fa0c8ba56744178c7098699cf.tar.bz2
ampache-a7b336e3265fc59fa0c8ba56744178c7098699cf.zip
Add CLI tool for adding user accounts
-rw-r--r--bin/install/add_user.inc62
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/install/add_user.inc b/bin/install/add_user.inc
new file mode 100644
index 00000000..f22bb6f1
--- /dev/null
+++ b/bin/install/add_user.inc
@@ -0,0 +1,62 @@
+<?php
+/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
+/**
+ *
+ * LICENSE: GNU General Public License, version 2 (GPLv2)
+ * Copyright (c) 2001 - 2012 Ampache.org All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License v2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * @package Ampache
+ * @copyright 2001 - 2012 Ampache.org
+ * @license http://opensource.org/licenses/gpl-2.0 GPLv2
+ * @link http://www.ampache.org/
+ */
+
+if(php_sapi_name() != 'cli') {
+ exit(1);
+}
+
+define('NO_SESSION', 1);
+define('CLI', 1);
+
+$path = dirname(__FILE__);
+$prefix = realpath($path . '/../../');
+require_once $prefix . '/lib/init.php';
+
+$options = getopt('e:l:n:p:u:');
+if (!$options || !isset($options['u'])) {
+ echo "Usage: add_user.inc -u <username> [ -l <access level> ] [ -p <password ] [ -e <email> ] [ -n <name> ]\n";
+ exit(1);
+}
+
+$username = $options['u'];
+$password = isset($options['p']) ? $options['p'] : mt_rand();
+$access = isset($options['l']) ? $options['l'] : Config::get('auto_user');
+$access = isset($access) ? $access : 'guest';
+$email = isset($options['e']) ? $options['e'] : '';
+$name = isset($options['n']) ? $options['n'] : '';
+
+if (User::create($username, $name, $email, $password, $access)) {
+ printf(_('Created %s user %s with password %s'), _($access), $username, $password);
+ echo "\n";
+}
+else {
+ echo _('User creation failed'), "\n";
+ exit(1);
+}
+
+User::fix_preferences('-1');
+
+?>