gluon-web-remote

Web remote Administration for big size of gluon routers
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-web-remote.git
Log | Files | Refs | README

Publickey.php (2302B)


      1 <?php
      2 
      3 namespace Ssh;
      4 
      5 use RuntimeException;
      6 
      7 /**
      8  * Wrapper for the SSH publickey subsystem
      9  *
     10  * @author Antoine Hérault <antoine.herault@gmail.com>
     11  */
     12 class Publickey extends Subsystem
     13 {
     14     /**
     15      * Adds an authorized publickey
     16      *
     17      * @param  string  $algoname   The algorithm (e.g: ssh-dss, ssh-rsa)
     18      * @param  string  $blob       The blob as binary data
     19      * @param  Boolean $overwrite  Whether to overwrite the key if it already
     20      *                             exist
     21      * @param  array   $attributes An associative array of attributes to assign
     22      *                             to the publickey. To mark an attribute as
     23      *                             mandatory, precede its name with an asterisk.
     24      *                             If the server is unable to support an
     25      *                             attribute marked mandatory, it will abort
     26      *                             the add process.
     27      *
     28      * @return Boolean TRUE on success, or FALSE on failure
     29      */
     30     public function add($algoname, $blob, $overwrite = false, array $attributes = array())
     31     {
     32         return ssh2_publickey_add($this->getResource(), $algoname, $blob, $overwrite, $attributes);
     33     }
     34 
     35     /**
     36      * Lists the currently authorized publickeys
     37      *
     38      * @return array A numerically indexed array of keys, each of which is an
     39      *               associative array containing: name, blob, and attrs
     40      *               elements.
     41      */
     42     public function getList()
     43     {
     44         return ssh2_publickey_list($this->getResource());
     45     }
     46 
     47     /**
     48      * Removes an authorized publickey
     49      *
     50      * @param  string $algoname The algorithm (e.g: ssh-dss, ssh-rsa)
     51      * @param  string $blob     The blob as binary data
     52      *
     53      * @return Boolean TRUE on success, or FALSE on failure
     54      */
     55     public function remove($algoname, $blob)
     56     {
     57         return ssh2_publickey_remove($this->getResource(), $algoname, $blob);
     58     }
     59 
     60     /**
     61      * {@inheritDoc}
     62      */
     63     public function createResource()
     64     {
     65         $resource = ssh2_publickey_init($this->getSessionResource());
     66 
     67         if (!is_resource($resource)) {
     68             throw new RuntimeException('The initialization of the publickey subsystem failed.');
     69         }
     70 
     71         $this->resource = $resource;
     72     }
     73 }