HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2013-01-21 10f567a9c39c789931d1be8f7c564a8ef32151ea
js script dumps package configuration
1 files added
174 ■■■■■ changed files
hsarjcli/scripting/package_dump.js 174 ●●●●● patch | view | raw | blame | history
hsarjcli/scripting/package_dump.js
New file
@@ -0,0 +1,174 @@
var pacs = pac.search();
var hive = 'h91';
var password = 'p!' + (new String(Math.random())).substring(2,16) + '!';
if (pacs.length == 1 && hive != 'undef') {
    var pacname = pacs[0]['name'];
    var file = new java.io.FileWriter(pacname + '_dump.js');
    // Pac
    file.write('pac.add({set:{\n');
    file.write('name: "' + pacs[0]['name'] + '",\n');
    file.write('curinetaddr: "' + pacs[0]['curinetaddr'] + '",\n');
    file.write('customer: "' + pacs[0]['customer'] + '",\n');
    file.write('basepac: "' + pacs[0]['basepac'] + '",\n');
    file.write('hive: "' + hive + '",\n');
    file.write('password: "' + password + '"\n');
    file.write('}});\n');
    file.write('pac.update({where:{\n');
    file.write('name: "' + pacs[0]['name'] + '"\n');
    file.write('},set:{\n');
    file.write('components: {\n');
    for (var opt in pacs[0]['components']) {
        file.write('     ' + opt + ': "' + pacs[0]['components'][opt] + '",\n');
    }
    file.write('}}});\n');
    // User
    var unixusers = user.search();
    for (idx=0; idx<unixusers.length; idx++) {
        if (unixusers[idx]['name'].length() > 5) {
            file.write('user.add({set:{\n');
            file.write('name: "' + unixusers[idx]['name'] + '",\n');
            file.write('shell: "' + unixusers[idx]['shell'] + '",\n');
            file.write('userid: "' + unixusers[idx]['userid'] + '",\n');
            file.write('comment: "' + unixusers[idx]['comment'] + '",\n');
            file.write('homedir: "' + unixusers[idx]['homedir'] + '",\n');
            file.write('quota_hardlimit: "' + unixusers[idx]['quota_hardlimit'] + '",\n');
            file.write('quota_softlimit: "' + unixusers[idx]['quota_softlimit'] + '",\n');
            file.write('password: "' + password + '"\n');
            file.write('}});\n');
        }
    }
    // Domain
    var domains = domain.search();
    for (idx=0; idx<domains.length; idx++) {
        if (domains[idx]['name'] == pacname + '.hostsharing.net') {
            file.write('domain.update({where:{\n');
            file.write('name: "' + domains[idx]['name'] + '"\n');
            file.write('},set:{\n');
            file.write('domainoptions: [\n');
            if (domains[idx]['domainoptions']) {
                for (jdx=0; jdx<domains[idx]['domainoptions'].length; jdx++) {
                    file.write('     "' + domains[idx]['domainoptions'][jdx] + '",\n');
                }
            }
            file.write('  ]\n');
            file.write('}});\n');
        } else {
            file.write('domain.add({set:{\n');
            file.write('name: "' + domains[idx]['name'] + '",\n');
            file.write('user: "' + domains[idx]['user'] + '",\n');
            file.write('domainoptions: [\n');
            if (domains[idx]['domainoptions']) {
                for (jdx=0; jdx<domains[idx]['domainoptions'].length; jdx++) {
                    file.write('     "' + domains[idx]['domainoptions'][jdx] + '",\n');
                }
            }
            file.write('  ]\n');
            file.write('}});\n');
        }
    }
    // Alias
    var aliases = emailalias.search();
    for (idx=0; idx<aliases.length; idx++) {
        file.write('emailalias.add({set:{\n');
        file.write('name: "' + aliases[idx]['name'] + '",\n');
        file.write('target: [\n');
        if (aliases[idx]['target']) {
            for (jdx=0; jdx<aliases[idx]['target'].length; jdx++) {
                file.write('     "' + aliases[idx]['target'][jdx] + '",\n');
            }
        }
        file.write('  ]\n');
        file.write('}});\n');
    }
    // E-Mail Address
    var addresses = emailaddress.search();
    for (idx=0; idx<addresses.length; idx++) {
        if (addresses[idx]['domain'] == pacname + '.hostsharing.net') {
            file.write('emailaddress.update({where:{\n');
            file.write('localpart: "' + addresses[idx]['localpart'] + '",\n');
            file.write('domain: "' + addresses[idx]['domain'] + '",\n');
            if (addresses[idx]['subdomain']) {
                file.write('subdomain: "' + addresses[idx]['subdomain'] + '":q\n');
            }
            file.write('},set:{\n');
            file.write('target: [\n');
            if (addresses[idx]['target']) {
                for (jdx=0; jdx<addresses[idx]['target'].length; jdx++) {
                    file.write('     "' + addresses[idx]['target'][jdx] + '",\n');
                }
            }
            file.write('  ]\n');
            file.write('}});\n');
        } else {
            var locpart = addresses[idx]['localpart'];
            var subdom = addresses[idx]['subdomain'];
            if (subdom == null && ('abuse' == locpart || 'postmaster' == locpart || 'webmaster' == locpart)) {
                file.write('emailaddress.update({where:{\n');
                file.write('localpart: "' + addresses[idx]['localpart'] + '",\n');
                file.write('domain: "' + addresses[idx]['domain'] + '",\n');
                if (addresses[idx]['subdomain']) {
                    file.write('subdomain: "' + addresses[idx]['subdomain'] + '":q\n');
                }
                file.write('},set:{\n');
                file.write('target: [\n');
                if (addresses[idx]['target']) {
                    for (jdx=0; jdx<addresses[idx]['target'].length; jdx++) {
                        file.write('     "' + addresses[idx]['target'][jdx] + '",\n');
                    }
                }
                file.write('  ]\n');
                file.write('}});\n');
            } else {
                file.write('emailaddress.add({set:{\n');
                file.write('localpart: "' + addresses[idx]['localpart'] + '",\n');
                file.write('domain: "' + addresses[idx]['domain'] + '",\n');
                if (addresses[idx]['subdomain']) {
                    file.write('subdomain: "' + addresses[idx]['subdomain'] + '",\n');
                }
                file.write('target: [\n');
                if (addresses[idx]['target']) {
                    for (jdx=0; jdx<addresses[idx]['target'].length; jdx++) {
                        file.write('     "' + addresses[idx]['target'][jdx] + '",\n');
                    }
                }
                file.write('  ]\n');
                file.write('}});\n');
            }
        }
    }
    // PostgreSQL
    var pguserold = postgresqluser.search();
    for (idx=0; idx<pguserold.length; idx++) {
        file.write('postgresqluser.add({set:{\n');
        file.write('name: "' + pguserold[idx]['name'] + '",\n');
        file.write('password: "' + password + '"\n');
        file.write('}});\n');
    }
    var pgdbold = postgresqldb.search();
    for (idx=0; idx<pgdbold.length; idx++) {
        file.write('postgresqldb.add({set:{\n');
        file.write('name: "' + pgdbold[idx]['name'] + '",\n');
        file.write('owner: "' + pgdbold[idx]['owner'] + '",\n');
        file.write('encoding: "' + pgdbold[idx]['encoding'] + '"\n');
        file.write('}});\n');
    }
    // MySQL
    var myuserold = mysqluser.search();
    for (idx=0; idx<myuserold.length; idx++) {
        file.write('mysqluser.add({set:{\n');
        file.write('name: "' + myuserold[idx]['name'] + '",\n');
        file.write('password: "' + password + '"\n');
        file.write('}});\n');
    }
    var mydbold = mysqldb.search();
    for (idx=0; idx<mydbold.length; idx++) {
        file.write('mysqldb.add({set:{\n');
        file.write('name: "' + mydbold[idx]['name'] + '",\n');
        file.write('owner: "' + mydbold[idx]['owner'] + '",\n');
        file.write('encoding: "' + mydbold[idx]['encoding'] + '"\n');
        file.write('}});\n');
    }
    file.close();
} else {
    print('run as pac-owner!\n');
}