Art-of-WiFi / UniFi-API-browser

Tool to browse data exposed by Ubiquiti's UniFi Controller API
MIT License
1.1k stars 150 forks source link

Create vouchers #10

Closed tirannilakshe closed 7 years ago

tirannilakshe commented 8 years ago

need to create vouchers and print vouchers from api

malle-pietje commented 8 years ago

Basically what you need to do is create the vouchers, then get the newly created vouchers and their details, format them on an html page and print. I can help with how to use the API client but not with the other elements; that comes down to basic HTML, CSS and PHP skills.

malle-pietje commented 8 years ago

@tirannilakshe FYI, there was a bug in the create_vouchers() function/method that is now fixed.

tiransa commented 7 years ago

i have done voucher creating. but there is a little problem. that i can only create one time use vouchers only. how can i generate multi use vouchers

malle-pietje commented 7 years ago

Are you able to create them in the controller? If so, how? I don't use them myself....

tiransa commented 7 years ago

yes. when i create voucher in controller there is a option to select multi use

On Mon, Nov 7, 2016 at 10:49 PM, malle-pietje notifications@github.com wrote:

Are you able to create them in the controller? If so, how? I don't use them myself....

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/malle-pietje/UniFi-API-browser/issues/10#issuecomment-258900297, or mute the thread https://github.com/notifications/unsubscribe-auth/AMkb_BRkttyEqyAFd3Ozf6l0ShfwDAFuks5q7120gaJpZM4JrGXd .

tiransa commented 7 years ago

untitled

malle-pietje commented 7 years ago

Ah, I see. Let me see how to efficiently enable this in the API client.

tiransa commented 7 years ago

there are some other things also how to delete vouchers, can i block and unblock guest by mac address

malle-pietje commented 7 years ago

I've added the multi-use/single-use option to the create_voucher() function below:

   /**
    * Create voucher(s)
    * -----------------
    * returns an array of vouchers codes (NOTE: without the "-" in the middle) by calling the stat_voucher method
    * required parameter <minutes> = minutes the voucher is valid after activation
    * optional parameter <number_of_vouchers_to_create> = number of vouchers to create, default value is 1
    * optional parameter <quota> = single-use or multi-use vouchers, string value '0' is for multi-use, '1' is for single-use
    * optional parameter <note> = note text to add to voucher when printing
    * optional parameter <up> = upload speed limit in kbps
    * optional parameter <down> = download speed limit in kbps
    * optional parameter <MBytes> = data transfer limit in MB
    */
   public function create_voucher($minutes, $number_of_vouchers_to_create = 1, $quota = '0', $note = NULL, $up = NULL, $down = NULL, $MBytes = NULL) {
      if (!$this->is_loggedin) return FALSE;
      $return = array();
      $json   = array('cmd' => 'create-voucher', 'expire' => $minutes, 'n' => $number_of_vouchers_to_create, 'quota' => $quota);
      /**
       * if we have received values for note/up/down/MBytes we append them to the payload array to be submitted
       */
      if (isset($note))   $json['note'] = trim($note);
      if (isset($up))     $json['up'] = $up;
      if (isset($down))   $json['down'] = $down;
      if (isset($MBytes)) $json['bytes'] = $MBytes;
      $json            = json_encode($json);
      $content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/cmd/hotspot','json='.$json));
      if ($content_decoded->meta->rc == 'ok') {
         if (is_array($content_decoded->data)) {
            $obj = $content_decoded->data[0];
            foreach ($this->stat_voucher($obj->create_time) as $voucher)  {
               $return[]= $voucher->code;
            }
         }
      }
      return $return;
   }

I would appreciate if you could test this in your environment and report back whether this works or not.

TIA

malle-pietje commented 7 years ago

@tirannilakshe A function/method to delete vouchers can certainly be added, I will do that with the new release of the API client which will also include the improved create_voucher() function after your confirmation that the above modification works.

For blocking/unblocking clients the block_sta() and unblock_sta() functions should do the trick. Have you already tried that?

tiransa commented 7 years ago

yes it is ok now thank you

On Tue, Nov 8, 2016 at 6:04 PM, malle-pietje notifications@github.com wrote:

@tirannilakshe https://github.com/tirannilakshe A function/method to delete vouchers can certainly be added, I will do that with the new release of the API client which will also include the improved create_voucher() function after your confirmation that the above modification works.

For blocking/unblocking clients the block_sta() and unblock_sta() functions should do the trick. Have you already tried that?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/malle-pietje/UniFi-API-browser/issues/10#issuecomment-259125041, or mute the thread https://github.com/notifications/unsubscribe-auth/AMkb_CBH9y3qTg_qkHAkh2xiYQ9huaZYks5q8Gw9gaJpZM4JrGXd .

malle-pietje commented 7 years ago

You're welcome. Thanks for the feedback; I'll update the class and add the voucher delete function shortly.

malle-pietje commented 7 years ago

@tiransa I have pushed a new version of the API client class and the API browser tool. Could you please check whether the new revoke_voucher() function/method does what you wanted to achieve with regard to voucher deletion?

tiransa commented 7 years ago

revoke_voucher() ok now how about disconnect and extend in guest actions

On Wed, Nov 9, 2016 at 8:05 PM, malle-pietje notifications@github.com wrote:

@tiransa https://github.com/tiransa I have pushed a new version of the API client class and the API browser tool. Could you please check whether the new revoke_voucher() function/methods does what you wanted to achieve with regard to voucher deletion?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/malle-pietje/UniFi-API-browser/issues/10#issuecomment-259428590, or mute the thread https://github.com/notifications/unsubscribe-auth/AMkb_KAXRifgOpZdEe8Xsnl9mWAcrscnks5q8do9gaJpZM4JrGXd .

malle-pietje commented 7 years ago

Thanks for the feedback. For disconnect/extend, see my comment from 2 days ago.

tiransa commented 7 years ago

hello, can i create hotspot operator from this API Class

malle-pietje commented 7 years ago

that has not yet been implemented, only the function to list the operators list_hotspotop()

tiransa commented 7 years ago

can you do that soon please

On Mon, Nov 21, 2016 at 6:01 PM, malle-pietje notifications@github.com wrote:

that has not yet been implemented, only the function to list the operators list_hotspotop()

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/malle-pietje/UniFi-API-browser/issues/10#issuecomment-261924502, or mute the thread https://github.com/notifications/unsubscribe-auth/AMkb_HWScXzUSPbAFwUg1X_RdW4zkke4ks5rAY8PgaJpZM4JrGXd .

malle-pietje commented 7 years ago

I'm quite busy at the moment so this will take at least a week or two

tiransa commented 7 years ago

ok i will wait for that. thank you

On Mon, Nov 21, 2016 at 8:16 PM, malle-pietje notifications@github.com wrote:

I'm quite busy at the moment so this will take at least a week or two

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/malle-pietje/UniFi-API-browser/issues/10#issuecomment-261957277, or mute the thread https://github.com/notifications/unsubscribe-auth/AMkb_AkVsYrVUfzgD4wh3dEXFZRPKarFks5rAa7igaJpZM4JrGXd .

malle-pietje commented 7 years ago

@tiransa This function should let you create hotspot operators. Could you please test and confirm back if it's working?

    /**
     * Create hotspot operator
     * -----------------
     * returns TRUE upon success
     * required parameter <name>       = name for the hotspot operator
     * required parameter <x_password> = clear text password for the hotspot operator
     * optional parameter <note>       = note to attach to the hotspot operator
     */
    public function create_hotspotop($name, $x_password, $note = NULL) {
        if (!$this->is_loggedin) return FALSE;
        $return = FALSE;
        $json   = array('name' => $name, 'x_password' => $x_password);
        /**
         * if we have received a value for note, we append it to the payload array to be submitted
         */
        if (isset($note)) $json['note'] = trim($note);
        $json            = json_encode($json);
        $content_decoded = json_decode($this->exec_curl($this->baseurl.'/api/s/'.$this->site.'/rest/hotspotop','json='.$json));
        if (isset($content_decoded->meta->rc)) {
            if ($content_decoded->meta->rc == 'ok') {
                $return = TRUE;
            }
        }

        return $return;
    }
malle-pietje commented 7 years ago

@tiransa If it works I will include it in the release I have ready for the API Browser and the API client class.

malle-pietje commented 7 years ago

Added create_hotspotop() function/method several commits ago.