2013年8月17日星期六

【原创】bulk adding users in owncloud automatically

http://forum.owncloud.org/viewtopic.php?f=3&t=2477 presented a way to add a lot of users into owncloud automatically. But I have a another way to do it. My solution is use chrome extension. You can download source code of this extension from https://www.dropbox.com/s/gj0cwzrklel6vkj/ownCloudUsers.zip.
Extract to folder "d:\", it will create a folder named "ownCloudUsers",open the folder and open file named popup.js.

CODE: SELECT ALL
$(document).ready(function(){
    $("#showAnnotation").click(function(){
          chrome.tabs.getSelected(null,function(tab) {
               var usernames=["jsjx","wlgcx","rjgcx","szjsx","jcjxb","zxsys","xsgzbgs","jwbgs","xyxz","jsjxy"];
               for(i=0;i                    var execode='addUser("' + usernames[i] + '")';
                    chrome.tabs.executeScript(null,{code:execode});
                    setTimeout("donothing()",3000);
            }
        });
    });
});

function donothing(){
}


We see an array named usernames stored all user name that we want to add. change content of this array. The password of all new users is setted to "123456" which can be modified in file contentscript.js.

CODE: SELECT ALL
function addUser(userid){
   $('#newusername').val(userid);
   $('#newuserpassword').val('123456');
   $('#newuser input:submit').click();
}


You can modify the usernames array to a two-dimension array so that it can store username and password at same time. and pass username and password to function addUser so that you can specify different password for every user.
Open file named manifest.json and change YourDomain to actually value or IP address, then save it.

CODE: SELECT ALL
{  
  "name": "ownCloud bulk users",
  "version": "0.0.1",  
  "manifest_version": 2,
  "description": "ownCloud  bulk users",
  "browser_action": {
        "default_title": "ownCloud  bulk users",
        "default_icon": "add.png",
        "default_popup": "popup.html"
  },
  "permissions": [
    "tabs","http://YourDomain/owncloud/index.php/settings/users"
  ],
  "content_scripts": [
    {
      "matches": ["http://YourDomain/owncloud/index.php/settings/users"],
      "js": ["jquery-1.8.3.js","contentscript.js"]
    }
  ],
  "web_accessible_resources":["add.png","images/*.png"]
}


Open chrome broswer, open menu item Tools|extensions, Then click button "load unpacked extension" and select folder "d:\ownCloudUsers". A new icon will appear at right-top position of chrome. Log into owncloud web app and go to user manage interface. click the icon of extension just installed, there will be a small popup window with an button inside. click the button, users will be added automatically.

Notice: the extension can't specify group for user.

没有评论:

发表评论