24 require_once(
"$MODDIR/lib/php/common-cli.php");
26 require_once(
"$MODDIR/lib/php/common-users.php");
28 error_reporting(E_ALL);
30 $usage =
"Usage: " . basename($argv[0]) .
" [options] 31 --username = admin/user with user-creation permissions 32 --password = admin/user password 33 --uname = username to create if not exists 34 --gname = groupname to create if not exists 35 --upasswd = password of created user 36 --permlvl = group permission level (-1: None, ".UserDao::USER.
": User, ".UserDao::ADMIN.
": Admin, ".UserDao::ADVISOR.
": Advisor) 38 --folder = root folder 40 $opts = getopt(
"h", array(
'username:',
'password:',
'uname:',
'gname:',
'upasswd:',
'permlvl:',
'accesslvl:',
'folder:'));
42 if (array_key_exists(
'h',$opts)) {
47 $adminName = array_key_exists(
"username", $opts) ? $opts[
"username"] : null;
48 $passwd = array_key_exists(
"password", $opts) ? $opts[
"password"] : null;
50 print
"Fossology login failure\n";
53 print
"Logged in as user $adminName\n";
57 $userDao = $GLOBALS[
'container']->get(
"dao.user");
59 $folderDao = $GLOBALS[
'container']->get(
"dao.folder");
61 $adminRow = $userDao->getUserByName($adminName);
63 print
"You have no permission to admin the user group thingy\n";
67 $uName = array_key_exists(
"uname", $opts) ? $opts[
"uname"] :
'';
68 $user = $uName ? $userDao->getUserByName($uName) :
false;
69 if ($user !==
false) {
70 print
"The user already exists, and updates in permissions not done from the commandline, we will only add group rights\n";
73 if ($uName && !$user) {
74 $pass = array_key_exists(
'upasswd', $opts) ? $opts[
'upasswd'] :
'';
75 $seed = rand() . rand();
76 $hash = sha1($seed . $pass);
77 $desc =
'created via cli';
78 $perm = array_key_exists(
'accesslvl', $opts) ? intval($opts[
'accesslvl']) : 0;
79 if (array_key_exists(
'folder', $opts)) {
80 $folder = $opts[
'folder'];
81 $folderid = $folderDao->getFolderId($folder);
83 if ($folderid == null) {
84 $folderid = $folderDao->insertFolder($folder,
'Cli generated folder');
91 $email = $emailNotify =
'';
92 add_user($uName, $desc, $seed, $hash, $perm, $email, $emailNotify, $agentList, $folderid);
93 $user = $userDao->getUserByName($uName);
94 print
"added user $uName\n";
97 $gName = array_key_exists(
"gname", $opts) ? $opts[
"gname"] :
'';
99 $sql =
"SELECT group_pk FROM groups WHERE group_name=$1";
100 $groupRow = $dbManager->getSingleRow($sql, array($gName), __FILE__ . __LINE__);
101 $groupId = $groupRow ? $groupRow[
'group_pk'] : $userDao->addGroup($gName);
106 $permLvl = array_key_exists(
"permlvl", $opts) ? intval($opts[
"permlvl"]) : 0;
107 if ($user && $groupId) {
108 $sql =
"SELECT group_user_member_pk id FROM group_user_member WHERE user_fk=$1 AND group_fk=$2";
109 $gumRow = $dbManager->getSingleRow($sql,array($user[
'user_pk'],$groupId),__FILE__.__LINE__);
112 if ($user && $groupId && $permLvl<0 && $gumRow) {
113 $dbManager->prepare($stmt = __FILE__.__LINE__,
114 "delete from group_user_member where group_user_member_pk=$1");
115 $dbManager->freeResult($dbManager->execute($stmt, array($gumRow[
'id'])));
116 print
"deleted membership of $uName in $gName\n";
117 }
else if ($user && $groupId && $permLvl>=0 && $gumRow) {
118 $dbManager->getSingleRow(
"update group_user_member set group_perm=$1 where group_user_member_pk=$2",
119 array($permLvl, $gumRow[
'id']), __FILE__.__LINE__);
120 print
"update membership of $uName in $gName\n";
121 }
else if ($user && $groupId && $permLvl>=0) {
122 $dbManager->insertTableRow(
'group_user_member',
123 array(
'group_perm'=>$permLvl,
'user_fk'=>$user[
'user_pk'],
'group_fk'=>$groupId));
124 print
"inserted membership of $uName in $gName\n";
account_check(&$user, &$passwd, &$group="")
check if this account is correct
userAgents()
Read the UI form and format the user selected agents into a comma separated list. ...
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
#define PERM_NONE
User has no permission (not logged in)
add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
#define PERM_READ
Read-only permission.
#define PERM_ADMIN
Administrator.
#define PERM_WRITE
Read-Write permission.