Results 1 to 6 of 6
  1. #1
    Untangle Ninja
    WebFooL's Avatar
    Join Date
    Jan 2009
    Location
    Sweden (Eskilstuna)
    Posts
    5,027

    Default Stuck Scripting Generation of hundreds of users

    Our office is moving and to that date we need to get all users working VPN connections.
    So they can work from home during the move.

    The head of IT wants us to have multiple VPN servers as we have had some issues where home users devices to Untangles IPsec.

    I had an old generation script and modified that so

    Index.html
    Code:
    <HTML>
    <head>
    </head>
    <body>
    <center>
    <script language="Javascript" type="text/javascript"> 
    </script>
    <FORM method = "post" action ="nyo.php">
    <table border="0">
    <tr>
    <td>Username:</td>
    <td><input type="text" name="tags" value="User1,User2"></td>
    </tr>
    <tr>
    <td>VPN Pool Number:</td>
    <td><input type="text" name="Group" value="1" /></td>
    </tr>
    <tr>
    </table><INPUT TYPE=Submit name=Submit VALUE = "Generate">
    </FORM>
    <br />
    To import more than one site use syntax Client1,Client2,Client3
    </center>
    </body>
    </html>
    nyo.php:
    Code:
    <?php
    $Name = $_POST['Name'];
    $Group = $_POST['Group'];
    $i = 0;
        define('TAG_LIMIT', 1000);
    $vJsonFileName = "OpenVPN-Import". ".json";
    header("Content-type: application/json");
    header("Content-Disposition: attachment; filename=$vJsonFileName");
    header('Cache-Control: public');
    
    
        if(!empty($_POST['tags'])) {
            $tags = explode(",", $_POST['tags'], TAG_LIMIT);
            echo "[";
    		foreach($tags as &$tag)
    		
    		{
    		$i++;
    		echo '{"originalName":"'.$tag.'","exportNetwork":"","javaClass":"com.untangle.node.openvpn.OpenVpnRemoteClient","groupId":'.$Group.',"name":"'.$tag.'","id":'.$i.',"export":false,"enabled":true},';
    		}
    		echo "]";    }
    		
    ?>
    So now to where I am stuck.
    I currently have all users in the grid for openvpn and they have the right pool.
    But i don't want to click download on 300+ user instead i would like to do a simple bash script.

    Code:
    #!/bin/bash
    foreach user ( user1 user2 user3 user3 )
    /usr/share/untangle/bin/openvpn-generate-client-cert $user
    /usr/share/untangle/bin/openvpn-generate-client-exec $user sitename=Sitename-XXX
    done
    I can see that the certs is created in the settings folder but when nsis installer runs i tries to featch from
    "/tmp/openvpn/client-packages/client-user.ovpn" and none of the scripts pushes it to that locateion so the makensis fails.

    Looks to be the OpenVpnManager.class that makes the copy but i am not sure.

    Any pointers would be good :-)

  2. #2
    Untangler jcoffin's Avatar
    Join Date
    Aug 2008
    Location
    Sunnyvale, CA
    Posts
    5,826

    Default

    Take a look at /usr/lib/python2.7/tests/openvpn_tests.py. That script generates its own clients and even exports it to a file.

    test_040_createClientVPNTunnel
    ... appData['remoteClients']['list'].append(setUpClient())
    ... clientLink = app.getClientDistributionDownloadLink(vpnClientName,"zip")
    Attention: Support and help on the Untangle Forums is provided by
    volunteers and community members like yourself.
    If you need Untangle support please call or email support@untangle.com

  3. #3
    Untangle Ninja
    WebFooL's Avatar
    Join Date
    Jan 2009
    Location
    Sweden (Eskilstuna)
    Posts
    5,027

    Default

    Sweet looks just like what I need :-)

    Thanks

  4. #4
    Untangle Junkie dmorris's Avatar
    Join Date
    Nov 2006
    Location
    San Carlos, CA
    Posts
    16,025

    Default

    something like this will download all zips:
    Code:
    #!/usr/bin/python -u
    import sys
    import uvm
    import os
    
    
    uvm = uvm.Uvm().getUvmContext()
    
    
    nodeManager = uvm.nodeManager()
    app = nodeManager.node("untangle-node-openvpn")
    print app
    
    
    appData = app.getSettings()
    for client in appData['remoteClients']['list']:
        name = client['name']
        clientLink = app.getClientDistributionDownloadLink(name,"zip")
        result = os.system("wget -t 1 --timeout=3 http://localhost"+clientLink)
    Attention: Support and help on the Untangle Forums is provided by volunteers and community members like yourself.
    If you need Untangle support please call or email support@untangle.com

  5. #5
    Untangle Ninja
    WebFooL's Avatar
    Join Date
    Jan 2009
    Location
    Sweden (Eskilstuna)
    Posts
    5,027

    Default

    Ended up with modifying so it looks like this
    openvpn_export_all_setup.exe.py
    Code:
    #!/usr/bin/python -u
    import sys
    import uvm
    import os
    
    uvm = uvm.Uvm().getUvmContext()
    
    nodeManager = uvm.nodeManager()
    app = nodeManager.node("untangle-node-openvpn")
    print app
    
    appData = app.getSettings()
    for client in appData['remoteClients']['list']:
        name = client['name']
        clientLink = app.getClientDistributionDownloadLink(name,"exe")
        result = os.system("wget -t 1 --content-disposition --timeout=3 http://localhost"+clientLink)
    Adding --content-dispositionrename makes the download file look like "openvpn-clientname-setup.exe" instad of "setup.exe?client=clientname".

    Thanks Jcoffin and Dmorris saved me a lot of clicking :-)

  6. #6
    Untangle Ninja
    WebFooL's Avatar
    Join Date
    Jan 2009
    Location
    Sweden (Eskilstuna)
    Posts
    5,027

    Default

    Last part to copy the installers to users home folders:

    OpenVPN-push.ps1:
    Code:
    $users = Get-Content 'D:\OpenVPN\userstest.txt'
    foreach ($u in $users) 
        {
        $Source = "D:\OpenVPN\openvpn-" + $u + "-setup.exe"
        ##echo $Source
        Copy-Item $Source -Destination "D:\Users-Homfolder\$u"
        echo "done with $u"
        }
    Created a OpenVPN folder on the same drive where the home folder is and had all openvpn-client-setup.exe and a textfile with all usernames in it.

    So there now I just need to publish how to click next -> next -> next on the installer :-)


    (In short we rolled out 351 clients under 1 hour with all these scripts)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

SEO by vBSEO 3.6.0 PL2