+ Post New Thread
Results 1 to 7 of 7
Coding Thread, creating WLC users via custom made PHP scipt which uses SNMP in Coding and Web Development; Hello, so basically i am not very experienced in PHP and this script is becoming the biggest challenge for me, ...
  1. #1

    Join Date
    Oct 2013
    Posts
    5
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Question creating WLC users via custom made PHP scipt which uses SNMP

    Hello,
    so basically i am not very experienced in PHP and this script is becoming the biggest challenge for me, probably because I lack of knowledge in PHP, so I am asking for some help and explanations.

    Explanation of what I am doing
    :
    I am trying to create a php script which gonna have a html form to create WIFI user on cisco WLC.
    I know that WLC it self got this kind of thing, but the reason I want to do it is that I dont want to allow any staff members to connect to WLC even knowing that they are going to have limited rights and so on.
    So I came-up with this idea that I am going to make this PHP script and HTML form which uses SNMP to create wifi user accounts, that's how I am planning to bypass using WLC interface.

    So the first thing which drives me nuts is that I need to convert entered time from HTML form to seconds, this form has days, hours, minutes.
    See attachment.
    Basically I want to "echo" entered time period in seconds at the bottom of php script but I dont know how.

    I know that this code is messy and ugly, but the idea itself covers that

    Code looks like that:
    HTML Code:
    <tr>
                <td class="valid" width="50" align=right>Lifetime: </td>
                <td colspan="2">
                  <table><tr>
                    <td class="valid1">
                        <INPUT type=TEXT name="lifetime_days" SIZE="2" MAXLENGTH="2" VALUE="1">
                            days &nbsp;
                    </td>
                    <td class="valid2">
                        <INPUT type=TEXT name="lifetime_hours" SIZE="2" MAXLENGTH="2" VALUE="0">
                            hours &nbsp;
                    </td>
                    <td class="valid3">
                        <INPUT type=TEXT name="lifetime_mins" SIZE="2" MAXLENGTH="2" VALUE="0">
                            mins &nbsp;
                    </td>
                    </table>
                </td>
              </tr>
    overall code looks like that(it is still missing PHP_SNMP functions):

    HTML Code:
    <head>
    </head>
    <body>
    <form method="POST" action="index.php">
    <table width=400 border=3 cellspacing=2 cellpadding=2
        bgColor="#ffffcc" align=center>
    <tr><td align=right>Host: </td>
            <td> <select type=text name="host">
    <option value="IP_1">wlc-1</option>
    <option value="IP_2">wlc-2</option>
    <tr><td align=right>Username: </td>  
            <td> <input type=text name="user"></td></tr>
    <tr><td align=right>Password: </td>  
        <td> <input type=password name="password"></td></tr>
    <tr>
                <td class="valid" width="50" align=right>Lifetime: </td>
                <td colspan="2">
                  <table><tr>
                    <td class="valid1">
                        <INPUT type=TEXT name="lifetime_days" SIZE="2" MAXLENGTH="2" VALUE="1">
                            days &nbsp;
                    </td>
                    <td class="valid2">
                        <INPUT type=TEXT name="lifetime_hours" SIZE="2" MAXLENGTH="2" VALUE="0">
                            hours &nbsp;
                    </td>
                    <td class="valid3">
                        <INPUT type=TEXT name="lifetime_mins" SIZE="2" MAXLENGTH="2" VALUE="0">
                            mins &nbsp;
                    </td>
                    </table>
                </td>
              </tr>
    <tr><td align=right>Vlan: </td>
        <td> <select type=hidden name="vlan">
    <option value="ISM Studies">ISM Studies</option>
    <tr><td align=center colspan=2>
        <input type=submit value="Submit"> 
        <input type=reset value="Cancel"></td></tr>
    </table>
    </form>
    </body>
    This part of PHP script converts (username, password) input for HTML table to ascii decimal numbers that's because SNMP requires that.

    PHP Code:
    <?php
    $user 
    $_POST['user']; 
    $pass $_POST['password'];
    $host $_POST['host'];
    $arr = array($user);
    $arr2 = array($pass);
    foreach(
    $arr as $value)
        {
            
    $index 0;
            while(
    $index strlen($value))
        {
    $ascii .= '.' ord($value[$index]);
    $dot_separated implode("."$value)."<br />";
    $index++;
        }
    echo 
    $ascii."<br />";
        }
    foreach(
    $arr2 as $value)
        {
            
    $index 0;
            while(
    $index strlen($value))
        {
    $ascii2 .= '.' ord($value[$index]);
    $dot_separated implode("."$value)."<br />";
    $index++; 
        }
    echo 
    $ascii2."<br />";
        }
    echo 
    $host."<br />";

    ?>
    Attached Images Attached Images

  2. #2

    Join Date
    Sep 2012
    Location
    Somerset
    Posts
    24
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    5
    Can you just pass the input values to a php function to return the value in seconds?
    is this what you're looking to achieve?
    the user enters days hours mins and then you want this returned as how many seconds this is?

    Its early i need more coffee!

  3. #3

    Join Date
    Oct 2013
    Posts
    5
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I assume that yes.
    Lets say that user enter 10 days 0 hours 0 minutes.
    And i want to use that time in my php script as seconds.
    so 10 days = 864000 seconds.
    I would really appreciate you help.

  4. #4

    Join Date
    Sep 2012
    Location
    Somerset
    Posts
    24
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    5
    this little function i've just coded and tested, it works for in my test environment:

    PHP Code:
    <?php
    function convert_to_sec($days,$hours,$mins) {
    $sec 0;
        if(
    is_numeric($days)) {
            
    $sec += 86400*$days;
        } 
        if(
    is_numeric($hours)) {
            
    $sec += 3600*$hours;
        } 
        if(
    is_numeric($mins)) {
            
    $sec += 60*$mins;
        }
    return 
    $sec;    
    }
    ?>
    so if you call the function and then pass it the days, hours, mins to be converted it will return the correct value in seconds from my testing.

    This is very simple though, no error trapping and probably a better way to do this but its what I've quickly come up with. Will look at a better way to do it shortly.
    Last edited by ThomL; 30th October 2013 at 11:06 AM.

  5. #5

    Join Date
    Sep 2012
    Location
    Somerset
    Posts
    24
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    5
    This should work with your current html page and provide some echos to show it is working:
    PHP Code:
    <?php
    $user 
    $_POST['user']; 
    $pass $_POST['password'];
    $host $_POST['host'];
    $days $_POST['lifetime_days']; //retrieve days from user submission
    $hours $_POST['lifetime_hours']; //retrieve hours from user submission
    $mins $_POST['lifetime_mins']; //retrieve mins from user submission
    $sec 0//set seconds - stops loops from throwing error but also used for validation
    $arr = array($user);
    $arr2 = array($pass);
    foreach(
    $arr as $value)
        {
            
    $index 0;
            while(
    $index strlen($value))
        {
    $ascii .= '.' ord($value[$index]);
    $dot_separated implode("."$value)."<br />";
    $index++;
        }
    echo 
    $ascii."<br />";
        }
    foreach(
    $arr2 as $value)
        {
            
    $index 0;
            while(
    $index strlen($value))
        {
    $ascii2 .= '.' ord($value[$index]);
    $dot_separated implode("."$value)."<br />";
    $index++; 
        }
    echo 
    $ascii2."<br />";
        }
    echo 
    $host."<br />";
    if(
    is_numeric($days)) { //if users submitted days...
            
    $sec += 86400*$days//convert users submitted value from days to seconds, add resulting value to current total of seconds 

    if(
    is_numeric($hours)) { //if users submitted hours...
        
    $sec += 3600*$hours//convert users submitted value from days to seconds, add resulting value to current total of seconds 

    if(
    is_numeric($mins)) { //if users submitted mins...
        
    $sec += 60*$mins//convert users submitted value from days to seconds, add resulting value to current total of seconds 
    }
    if(
    $sec>0){ //If values received from html and converted...
    echo $sec."<br />";
    } else { 
    //if no values were received from html...
      
    echo "User did not input a time value<br />";
    }
    ?>
    The conditions on the if statements only work with numeric vales so you may want to add some validation for this.
    Last edited by ThomL; 30th October 2013 at 10:59 AM.

  6. Thanks to ThomL from:

    mantas (30th October 2013)

  7. #6

    Join Date
    Oct 2013
    Posts
    5
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    That works like a charm!! thank you

  8. #7

    Join Date
    Sep 2012
    Location
    Somerset
    Posts
    24
    Thank Post
    2
    Thanked 2 Times in 2 Posts
    Rep Power
    5
    You're welcome

    This is a slightly optimised version of the above:

    PHP Code:
    <?php
    $user 
    $_POST['user']; 
    $pass $_POST['password'];
    $host $_POST['host'];
    $days $_POST['lifetime_days']; //retrieve days from user submission
    $hours $_POST['lifetime_hours']; //retrieve hours from user submission
    $mins $_POST['lifetime_mins']; //retrieve mins from user submission
    $sec 0//set seconds - stops loops from throwing error but also used for validation
    $arr = array($user);
    $arr2 = array($pass);
    foreach(
    $arr as $value)
        {
            
    $index 0;
            while(
    $index strlen($value))
        {
    $ascii .= '.' ord($value[$index]);
    $dot_separated implode("."$value)."<br />";
    $index++;
        }
    echo 
    $ascii."<br />";
        }
    foreach(
    $arr2 as $value)
        {
            
    $index 0;
            while(
    $index strlen($value))
        {
    $ascii2 .= '.' ord($value[$index]);
    $dot_separated implode("."$value)."<br />";
    $index++; 
        }
    echo 
    $ascii2."<br />";
        }
    echo 
    $host."<br />";
    if(
    is_numeric($days) || is_numeric($hours) || is_numeric($mins)) { //checks foruser submitted numeric values...
        
    $sec = ((86400*$days)+(3600*$hours)+(60*$mins)); // conversion to seconds
        
    echo $sec."<br />";  //echo used to display converted data
    } else { //if invalid or no user submitted numeric values...
        
    echo "User did not input a time value<br />"//alerts invalid or no user submitted numeric values
    }
    ?>
    Last edited by ThomL; 30th October 2013 at 03:17 PM.

SHARE:
+ Post New Thread

Similar Threads

  1. Create Bulk users and Folders
    By DanW in forum Scripts
    Replies: 14
    Last Post: 20th September 2009, 03:08 PM
  2. Active Directory-Script for Creating Bulk Users
    By calapso in forum How do you do....it?
    Replies: 8
    Last Post: 14th January 2009, 06:32 PM
  3. Create New user groups in joomla
    By PEO in forum EduGeek Joomla 1.0 Package
    Replies: 6
    Last Post: 17th April 2008, 10:31 PM
  4. Replies: 0
    Last Post: 17th February 2007, 04:43 PM
  5. Replies: 10
    Last Post: 21st November 2006, 02:47 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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