code
stringlengths
17
296k
docstring
stringlengths
30
30.3k
func_name
stringlengths
1
89
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
153
url
stringlengths
51
209
license
stringclasses
4 values
public function toMail(mixed $notifiable) { return (new MailMessage()) ->subject('subscribed Successfully!') ->line('You have subscribed successfully!') ->line('Subscription Plan:'.$this->plan->nickname) ->line('Thank you for using Genealogia!'); }
Get the mail representation of the notification. @return \Illuminate\Notifications\Messages\MailMessage
toMail
php
liberu-ecommerce/ecommerce-old
app/Notifications/SubscribeSuccessfully.php
https://github.com/liberu-ecommerce/ecommerce-old/blob/master/app/Notifications/SubscribeSuccessfully.php
MIT
public function toArray(mixed $notifiable) { return [ ]; }
Get the array representation of the notification. @return array
toArray
php
liberu-ecommerce/ecommerce-old
app/Notifications/SubscribeSuccessfully.php
https://github.com/liberu-ecommerce/ecommerce-old/blob/master/app/Notifications/SubscribeSuccessfully.php
MIT
public function __construct($plan_id) { $stripe = new \Stripe\StripeClient(\Config::get('services.stripe.secret')); $this->plan = $stripe->plans->retrieve($plan_id); }
Create a new notification instance. @return void
__construct
php
liberu-ecommerce/ecommerce-old
app/Notifications/UnsubscribeSuccessfully.php
https://github.com/liberu-ecommerce/ecommerce-old/blob/master/app/Notifications/UnsubscribeSuccessfully.php
MIT
public function via(mixed $notifiable) { return ['mail']; }
Get the notification's delivery channels. @return array
via
php
liberu-ecommerce/ecommerce-old
app/Notifications/UnsubscribeSuccessfully.php
https://github.com/liberu-ecommerce/ecommerce-old/blob/master/app/Notifications/UnsubscribeSuccessfully.php
MIT
public function toMail(mixed $notifiable) { return (new MailMessage()) ->subject('Unsubscribed Successfully!') ->line('You have unsubscribed successfully!') ->line('Subscription Plan:'.$this->plan->nickname) ->line('Thank you for using Genealogia!'); }
Get the mail representation of the notification. @return \Illuminate\Notifications\Messages\MailMessage
toMail
php
liberu-ecommerce/ecommerce-old
app/Notifications/UnsubscribeSuccessfully.php
https://github.com/liberu-ecommerce/ecommerce-old/blob/master/app/Notifications/UnsubscribeSuccessfully.php
MIT
public function toArray(mixed $notifiable) { return [ ]; }
Get the array representation of the notification. @return array
toArray
php
liberu-ecommerce/ecommerce-old
app/Notifications/UnsubscribeSuccessfully.php
https://github.com/liberu-ecommerce/ecommerce-old/blob/master/app/Notifications/UnsubscribeSuccessfully.php
MIT
function out($string, $escaping = ESC_HTML) { if(is_null($string)) return ''; switch($escaping) { case ESC_HTML: echo htmlspecialchars($string); break; case ESC_URL: echo urlencode($string); break; case ESC_URL_ALL: echo rawurlencode($string); break; case ESC_NONE: echo $string; break; default: throw new InvalidArgumentException("Escaping format $escaping not known."); } }
Output the given string, HTML-escaped by default @param string $string to output @param integer $escaping method of escaping to use
out
php
operasoftware/ssh-key-authority
core.php
https://github.com/operasoftware/ssh-key-authority/blob/master/core.php
Apache-2.0
function rrurl($url) { global $relative_frontend_base_url; return $relative_frontend_base_url.$url; }
Generate a root-relative URL from the base URL and the given base-relative URL @param string $url base-relative URL @return string root-relative URL
rrurl
php
operasoftware/ssh-key-authority
core.php
https://github.com/operasoftware/ssh-key-authority/blob/master/core.php
Apache-2.0
function outurl($url) { out(rrurl($url)); }
Output a root-relative URL from the base URL and the given base-relative URL @param string $url relative URL
outurl
php
operasoftware/ssh-key-authority
core.php
https://github.com/operasoftware/ssh-key-authority/blob/master/core.php
Apache-2.0
function hesc($string) { return htmlspecialchars($string ?? ''); }
Short-name HTML escape convenience function @param string $string string to escape @return string HTML-escaped string
hesc
php
operasoftware/ssh-key-authority
core.php
https://github.com/operasoftware/ssh-key-authority/blob/master/core.php
Apache-2.0
function redirect($url = null, $type = '303 See other') { global $absolute_request_url, $relative_frontend_base_url; if(is_null($url)) { // Redirect is to current URL $url = $absolute_request_url; } elseif(substr($url, 0, 1) !== '#') { $url = $relative_frontend_base_url.$url; } header("HTTP/1.1 $type"); header("Location: $url"); print("\n"); exit; }
Perform an HTTP redirect to the given URL (or the current URL if none given) @param string|null $url URL to redirect to @param string $type HTTP response code/name to use
redirect
php
operasoftware/ssh-key-authority
core.php
https://github.com/operasoftware/ssh-key-authority/blob/master/core.php
Apache-2.0
public function __destruct() { global $sync_request_dir; if(!is_null($this->request)) { $sync_request_dir->delete_sync_request($this->request); } }
Delete the request that triggered this sync
__destruct
php
operasoftware/ssh-key-authority
scripts/sync-common.php
https://github.com/operasoftware/ssh-key-authority/blob/master/scripts/sync-common.php
Apache-2.0
function sig_handler($signo) { global $signal; $signal = $signo; }
Handle process control signals
sig_handler
php
operasoftware/ssh-key-authority
scripts/syncd.php
https://github.com/operasoftware/ssh-key-authority/blob/master/scripts/syncd.php
Apache-2.0
function dlog($txt) { global $options; if(isset($options['systemd'])) { echo "{$txt}\n"; } else { echo date('c')." {$txt}\n"; } }
Daemon log - write log message
dlog
php
operasoftware/ssh-key-authority
scripts/syncd.php
https://github.com/operasoftware/ssh-key-authority/blob/master/scripts/syncd.php
Apache-2.0
public function &__get($field) { switch($field) { case 'group': $group = new Group($this->data['entity_id']); return $group; default: return parent::__get($field); } }
Magic getter method - if group field requested, return Group object of the affected group. @param string $field to retrieve @return mixed data stored in field
__get
php
operasoftware/ssh-key-authority
model/groupevent.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/groupevent.php
Apache-2.0
public function add_sync_request(SyncRequest $req) { $stmt = $this->database->prepare("INSERT IGNORE INTO sync_request SET server_id = ?, account_name = ?"); $stmt->bind_param('ds', $req->server_id, $req->account_name); $stmt->execute(); $req->id = $stmt->insert_id; $stmt->close(); }
Create the new sync request in the database. @param SyncRequest $req object to add
add_sync_request
php
operasoftware/ssh-key-authority
model/syncrequestdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/syncrequestdirectory.php
Apache-2.0
public function delete_sync_request(SyncRequest $req) { $stmt = $this->database->prepare("DELETE FROM sync_request WHERE id = ?"); $stmt->bind_param('s', $req->id); $stmt->execute(); $stmt->close(); }
Delete the sync request from the database. @param SyncRequest $req object to delete
delete_sync_request
php
operasoftware/ssh-key-authority
model/syncrequestdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/syncrequestdirectory.php
Apache-2.0
public function list_pending_sync_requests() { if(!isset($this->sync_list_stmt)) { $this->sync_list_stmt = $this->database->prepare("SELECT * FROM sync_request WHERE processing = 0 ORDER BY id"); } $this->sync_list_stmt->execute(); $result = $this->sync_list_stmt->get_result(); $reqs = array(); while($row = $result->fetch_assoc()) { $reqs[] = new SyncRequest($row['id'], $row); } return $reqs; }
List the sync requests stored in the database that are not being processed yet. @return array of SyncRequest objects
list_pending_sync_requests
php
operasoftware/ssh-key-authority
model/syncrequestdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/syncrequestdirectory.php
Apache-2.0
public function add_server(Server $server) { $hostname = $server->hostname; $port = $server->port; try { $stmt = $this->database->prepare("INSERT INTO server SET hostname = ?, port = ?"); $stmt->bind_param('sd', $hostname, $port); $stmt->execute(); $server->id = $stmt->insert_id; $stmt->close(); $server->log(array('action' => 'Server add')); $server->add_standard_accounts(); $server->sync_access(); } catch(mysqli_sql_exception $e) { if($e->getCode() == 1062) { // Duplicate entry throw new ServerAlreadyExistsException("Server {$server->hostname} already exists"); } else { throw $e; } } }
Create the new server in the database. @param Server $server object to add @throws ServerAlreadyExistsException if a server with that hostname already exists
add_server
php
operasoftware/ssh-key-authority
model/serverdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serverdirectory.php
Apache-2.0
public function get_server_by_id($server_id) { $stmt = $this->database->prepare("SELECT * FROM server WHERE id = ?"); $stmt->bind_param('d', $server_id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $server = new Server($row['id'], $row); } else { throw new ServerNotFoundException('Server does not exist.'); } $stmt->close(); return $server; }
Get a server from the database by its ID. @param int $id of server @return Server with specified ID @throws ServerNotFoundException if no server with that ID exists
get_server_by_id
php
operasoftware/ssh-key-authority
model/serverdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serverdirectory.php
Apache-2.0
public function get_server_by_hostname($hostname) { $stmt = $this->database->prepare("SELECT * FROM server WHERE hostname = ?"); $stmt->bind_param('s', $hostname); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $server = new Server($row['id'], $row); } else { throw new ServerNotFoundException('Server does not exist'); } $stmt->close(); return $server; }
Get a server from the database by its hostname. @param string $hostname of server @return Server with specified hostname @throws ServerNotFoundException if no server with that hostname exists
get_server_by_hostname
php
operasoftware/ssh-key-authority
model/serverdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serverdirectory.php
Apache-2.0
public function get_server_by_uuid($uuid) { $stmt = $this->database->prepare("SELECT * FROM server WHERE uuid = ?"); $stmt->bind_param('s', $uuid); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $server = new Server($row['id'], $row); } else { throw new ServerNotFoundException('Server does not exist'); } $stmt->close(); return $server; }
Get a server from the database by its uuid. @param string $uuid of server @return Server with specified uuid @throws ServerNotFoundException if no server with that uuid exists
get_server_by_uuid
php
operasoftware/ssh-key-authority
model/serverdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serverdirectory.php
Apache-2.0
public function add_admin(User $user) { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before admins can be added'); if(is_null($user->entity_id)) throw new InvalidArgumentException('User must be in directory before it can be made admin'); $entity_id = $user->entity_id; try { $stmt = $this->database->prepare("INSERT INTO entity_admin SET entity_id = ?, admin = ?"); $stmt->bind_param('dd', $this->entity_id, $entity_id); $stmt->execute(); $stmt->close(); } catch(mysqli_sql_exception $e) { if($e->getCode() == 1062) { // Duplicate entry - ignore } else { throw $e; } } }
Add the specified user as an administrator of the entity. Logging is performed by the inheriting classes. @param User $user to add as administrator
add_admin
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function delete_admin(User $user) { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before admins can be deleted'); if(is_null($user->entity_id)) throw new InvalidArgumentException('User must be in directory before it can be removed as admin'); $entity_id = $user->entity_id; $stmt = $this->database->prepare("DELETE FROM entity_admin WHERE entity_id = ? AND admin = ?"); $stmt->bind_param('dd', $this->entity_id, $entity_id); $stmt->execute(); $stmt->close(); }
Remove the specified user as an administrator of the entity. @param User $user to remove as administrator
delete_admin
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function list_admins() { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before admins can be listed'); $stmt = $this->database->prepare("SELECT admin FROM entity_admin WHERE entity_id = ?"); $stmt->bind_param('d', $this->entity_id); $stmt->execute(); $result = $stmt->get_result(); $admins = array(); while($row = $result->fetch_assoc()) { $admins[] = new User($row['admin']); } $stmt->close(); return $admins; }
List all administrators of this entity. @return array of User objects
list_admins
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function add_public_key(PublicKey $key) { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before public keys can be added'); $key->get_openssh_info(); $key_type = $key->type; $key_keydata = $key->keydata; $key_comment = $key->comment; $key_size = $key->keysize; $key_fingerprint_md5 = $key->fingerprint_md5; $key_fingerprint_sha256 = $key->fingerprint_sha256; $key_randomart_md5 = $key->randomart_md5; $key_randomart_sha256 = $key->randomart_sha256; $stmt = $this->database->prepare(" INSERT INTO public_key SET entity_id = ?, type = ?, keydata = ?, comment = ?, keysize = ?, fingerprint_md5 = ?, fingerprint_sha256 = ?, randomart_md5 = ?, randomart_sha256 = ? "); $stmt->bind_param('dsssdssss', $this->entity_id, $key_type, $key_keydata, $key_comment, $key_size, $key_fingerprint_md5, $key_fingerprint_sha256, $key_randomart_md5, $key_randomart_sha256); $stmt->execute(); $key->id = $stmt->insert_id; $stmt->close(); $this->sync_remote_access(); }
Add a public key to this entity for use with any outbound access rules that apply to it. Emailing and logging is handled by the inheriting classes. @param PublicKey $key to be added
add_public_key
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function delete_public_key(PublicKey $key) { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before public keys can be deleted'); $stmt = $this->database->prepare("DELETE FROM public_key WHERE entity_id = ? AND id = ?"); $stmt->bind_param('dd', $this->entity_id, $key->id); $stmt->execute(); $stmt->close(); $this->sync_remote_access(); }
Delete the specified public key from this entity. @param PublicKey $key to be removed
delete_public_key
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function get_public_key_by_id($id) { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before public keys can be listed'); $stmt = $this->database->prepare("SELECT * FROM public_key WHERE entity_id = ? AND id = ?"); $stmt->bind_param('dd', $this->entity_id, $id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $key = new PublicKey($row['id'], $row); } else { throw new PublicKeyNotFoundException('Public key does not exist.'); } $stmt->close(); return $key; }
Retrieve a specific public key for this entity by its ID. @param int $id of public key to retrieve @return PublicKey matching the ID @throws PublicKeyNotFoundException if no public key exists with that ID
get_public_key_by_id
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function list_public_keys($account_name = null, $hostname = null) { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before public keys can be listed'); $stmt = $this->database->prepare(" SELECT public_key.*, COUNT(public_key_dest_rule.id) AS dest_rule_count FROM public_key LEFT JOIN public_key_dest_rule ON public_key_dest_rule.public_key_id = public_key.id WHERE entity_id = ? GROUP BY public_key.id "); $stmt->bind_param('d', $this->entity_id); $stmt->execute(); $result = $stmt->get_result(); $keys = array(); while($row = $result->fetch_assoc()) { if((is_null($account_name) && is_null($hostname)) || $row['dest_rule_count'] == 0) { $include = true; } else { $include = false; $rulestmt = $this->database->prepare("SELECT * FROM public_key_dest_rule WHERE public_key_id = ?"); $rulestmt->bind_param('d', $row['id']); $rulestmt->execute(); $ruleresult = $rulestmt->get_result(); if($ruleresult->num_rows == 0) { // Key has no destination rules defined, include it everywhere $include = true; } else { // Apply destination rules while($rule = $ruleresult->fetch_assoc()) { $filter1 = '/^'.str_replace('\*', '.*', preg_quote($rule['account_name_filter'], '/')).'$/i'; $filter2 = '/^'.str_replace('\*', '.*', preg_quote($rule['hostname_filter'], '/')).'$/i'; if(preg_match($filter1, $account_name) && preg_match($filter2, $hostname)) { $include = true; break; } } } } if($include) { $keys[] = new PublicKey($row['id'], $row); } } $stmt->close(); return $keys; }
List all public keys associated with this entity, optionally filtered by account name and hostname for any of the keys that have destination rules applied. @todo this is perhaps an unintuitive place to do this kind of filtering @param string|null $account_name to filter for in the destination rules for each key @param string|null $hostname to filter for in the destination rules for each key @return array of PublicKey objects
list_public_keys
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function get_access_by_id($id) { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before access can be listed'); $stmt = $this->database->prepare(" SELECT access.*, entity.type FROM access INNER JOIN entity ON entity.id = access.source_entity_id WHERE access.dest_entity_id = ? AND access.id = ? "); $stmt->bind_param('dd', $this->entity_id, $id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { switch($row['type']) { case 'user': $source_entity = new User($row['source_entity_id']); break; case 'server account': $source_entity = new ServerAccount($row['source_entity_id']); break; case 'group': $source_entity = new Group($row['source_entity_id']); break; } $row['granted_by'] = new User($row['granted_by']); $row['source_entity'] = $source_entity; $row['dest_entity'] = $this; $access = new Access($row['id'], $row); } else { throw new AccessNotFoundException('Access rule does not exist.'); } $stmt->close(); return $access; }
Retrieve a specific access rule towards this entity by its ID (inbound access). @param int $id to retrieve @return Access object @throws AccessNotFoundException if no access rule exists with this ID
get_access_by_id
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function list_access() { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before access can be listed'); $stmt = $this->database->prepare(" SELECT access.*, entity.type FROM access INNER JOIN entity ON entity.id = access.source_entity_id LEFT JOIN user ON user.entity_id = entity.id LEFT JOIN server_account ON server_account.entity_id = entity.id LEFT JOIN server ON server.id = server_account.server_id LEFT JOIN `group` ON `group`.entity_id = entity.id WHERE dest_entity_id = ? ORDER BY entity.type, user.uid, server.hostname, server_account.name, `group`.name "); $stmt->bind_param('d', $this->entity_id); $stmt->execute(); $result = $stmt->get_result(); $access_list = array(); while($row = $result->fetch_assoc()) { switch($row['type']) { case 'user': $source_entity = new User($row['source_entity_id']); break; case 'server account': $source_entity = new ServerAccount($row['source_entity_id']); break; case 'group': $source_entity = new Group($row['source_entity_id']); break; } $row['granted_by'] = new User($row['granted_by']); $row['source_entity'] = $source_entity; $access_list[] = new Access($row['id'], $row); } $stmt->close(); return $access_list; }
List all access rules that grant access to this entity (inbound access). @return array of Access objects
list_access
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function list_access_requests() { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before access can be listed'); $stmt = $this->database->prepare(" SELECT access_request.*, entity.type FROM access_request INNER JOIN entity ON entity.id = access_request.source_entity_id LEFT JOIN user ON user.entity_id = entity.id LEFT JOIN server_account ON server_account.entity_id = entity.id LEFT JOIN server ON server.id = server_account.server_id LEFT JOIN `group` ON `group`.entity_id = entity.id WHERE dest_entity_id = ? ORDER BY entity.type, user.uid, server.hostname, server_account.name, `group`.name "); $stmt->bind_param('d', $this->entity_id); $stmt->execute(); $result = $stmt->get_result(); $access_requests = array(); while($row = $result->fetch_assoc()) { switch($row['type']) { case 'user': $source_entity = new User($row['source_entity_id']); break; case 'server account': $source_entity = new ServerAccount($row['source_entity_id']); break; case 'group': $source_entity = new Group($row['source_entity_id']); break; } $row['requested_by'] = new User($row['requested_by']); $row['source_entity'] = $source_entity; $access_requests[] = new AccessRequest($row['id'], $row); } $stmt->close(); return $access_requests; }
List all requests for access to this entity (inbound access). @return array of AccessRequest objects
list_access_requests
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function list_remote_access() { if(is_null($this->entity_id)) throw new BadMethodCallException('Entity must be in directory before remote access can be listed'); $stmt = $this->database->prepare(" SELECT access.*, entity.type FROM access INNER JOIN entity ON access.dest_entity_id = entity.id LEFT JOIN user ON user.entity_id = entity.id LEFT JOIN server_account ON server_account.entity_id = entity.id LEFT JOIN server ON server.id = server_account.server_id LEFT JOIN `group` ON `group`.entity_id = entity.id WHERE access.source_entity_id = ? ORDER BY entity.type, user.uid, server.hostname, server_account.name, `group`.name "); $stmt->bind_param('d', $this->entity_id); $stmt->execute(); $result = $stmt->get_result(); $access_list = array(); while($row = $result->fetch_assoc()) { switch($row['type']) { case 'user': $dest_entity = new User($row['dest_entity_id']); break; case 'server account': $dest_entity = new ServerAccount($row['dest_entity_id']); break; case 'group': $dest_entity = new Group($row['dest_entity_id']); break; } $row['granted_by'] = new User($row['granted_by']); $row['dest_entity'] = $dest_entity; $access_list[] = new Access($row['id'], $row); } $stmt->close(); return $access_list; }
List all access rules that grant this entity access to other entities (outbound access). @return array of Access objects
list_remote_access
php
operasoftware/ssh-key-authority
model/entity.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entity.php
Apache-2.0
public function add_group(Group $group) { $name = $group->name; $system = $group->system; $this->database->begin_transaction(); $stmt = $this->database->prepare("INSERT INTO entity SET type = 'group'"); $stmt->execute(); $group->entity_id = $stmt->insert_id; $stmt->close(); $stmt = $this->database->prepare("INSERT INTO `group` SET entity_id = ?, name = ?, `system` = ?"); $stmt->bind_param('dsd', $group->entity_id, $name, $system); try { $stmt->execute(); $stmt->close(); $this->database->commit(); $group->log(array('action' => 'Group add')); } catch(mysqli_sql_exception $e) { $this->database->rollback(); if($e->getCode() == 1062) { // Duplicate entry throw new GroupAlreadyExistsException("Group {$group->name} already exists"); } else { throw $e; } } }
Create the new group in the database. @param Group $group object to add @throws GroupAlreadyExistsException if a group with that name already exists
add_group
php
operasoftware/ssh-key-authority
model/groupdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/groupdirectory.php
Apache-2.0
public function get_group_by_id($entity_id) { $stmt = $this->database->prepare("SELECT * FROM `group` WHERE entity_id = ?"); $stmt->bind_param('d', $entity_id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $group = new Group($row['entity_id'], $row); } else { throw new GroupNotFoundException('Group does not exist.'); } $stmt->close(); return $group; }
Get a group from the database by its entity ID. @param int $entity_id of group @return Group with specified entity ID @throws GroupNotFoundException if no group with that entity ID exists
get_group_by_id
php
operasoftware/ssh-key-authority
model/groupdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/groupdirectory.php
Apache-2.0
public function get_group_by_name($name) { $stmt = $this->database->prepare("SELECT * FROM `group` WHERE name = ?"); $stmt->bind_param('s', $name); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $group = new Group($row['entity_id'], $row); } else { throw new GroupNotFoundException('Group does not exist'); } $stmt->close(); return $group; }
Get a group from the database by its name. @param string $name of group @return Group with specified name @throws GroupNotFoundException if no group with that name exists
get_group_by_name
php
operasoftware/ssh-key-authority
model/groupdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/groupdirectory.php
Apache-2.0
public function add_user(User $user) { $user_id = $user->uid; $user_name = $user->name; $user_active = $user->active; $user_admin = $user->admin; $user_email = $user->email; $stmt = $this->database->prepare("INSERT INTO entity SET type = 'user'"); $stmt->execute(); $user->entity_id = $stmt->insert_id; $stmt = $this->database->prepare("INSERT INTO user SET entity_id = ?, uid = ?, name = ?, email = ?, active = ?, admin = ?"); $stmt->bind_param('dsssdd', $user->entity_id, $user_id, $user_name, $user_email, $user_active, $user_admin); $stmt->execute(); $stmt->close(); }
Create the new user in the database. @param User $user object to add
add_user
php
operasoftware/ssh-key-authority
model/userdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/userdirectory.php
Apache-2.0
public function get_user_by_id($id) { $stmt = $this->database->prepare("SELECT * FROM user WHERE entity_id = ?"); $stmt->bind_param('d', $id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $user = new User($row['entity_id'], $row); } else { throw new UserNotFoundException('User does not exist.'); } $stmt->close(); return $user; }
Get a user from the database by its entity ID. @param int $entity_id of user @return User with specified entity ID @throws UserNotFoundException if no user with that entity ID exists
get_user_by_id
php
operasoftware/ssh-key-authority
model/userdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/userdirectory.php
Apache-2.0
public function get_user_by_uid($uid, $login = false) { if(isset($this->cache_uid[$uid])) { return $this->cache_uid[$uid]; } $stmt = $this->database->prepare("SELECT * FROM user WHERE uid = ?"); $stmt->bind_param('s', $uid); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $user = new User($row['entity_id'], $row); $this->cache_uid[$uid] = $user; } else { $user = new User; $user->uid = $uid; $this->cache_uid[$uid] = $user; $user->get_details_from_ldap($login); } $stmt->close(); return $user; }
Get a user from the database by its uid. If it does not exist in the database, retrieve it from LDAP and store in the database. @param string $uid of user @param bool $login true if getting user as part of login process @return User with specified entity uid @throws UserNotFoundException if no user with that uid exists
get_user_by_uid
php
operasoftware/ssh-key-authority
model/userdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/userdirectory.php
Apache-2.0
public function get_public_key_by_id($id) { $stmt = $this->database->prepare(" SELECT public_key.*, entity.type AS entity_type FROM public_key INNER JOIN entity ON entity.id = public_key.entity_id WHERE public_key.id = ? "); $stmt->bind_param('d', $id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { switch($row['entity_type']) { case 'user': $row['owner'] = new User($row['entity_id']); break; case 'server account': $row['owner'] = new ServerAccount($row['entity_id']); break; } $key = new PublicKey($row['id'], $row); } else { throw new PublicKeyNotFoundException('Public key does not exist.'); } $stmt->close(); return $key; }
Retrieve a public key matching the specified ID. @param int $id of public key to retrieve @return PublicKey object with specified ID @throws PublicKeyNotFoundException if no key with that ID exists
get_public_key_by_id
php
operasoftware/ssh-key-authority
model/publickeydirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickeydirectory.php
Apache-2.0
public function set_in_progress() { $this->processing = true; $this->update(); }
Mark this request as in progress
set_in_progress
php
operasoftware/ssh-key-authority
model/syncrequest.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/syncrequest.php
Apache-2.0
public function &__get($field) { global $user_dir; switch($field) { case 'actor': $actor = new User($this->data['actor_id']); return $actor; default: return parent::__get($field); } }
Magic getter method - if actor field requested, return User object of the person who triggered the logged event. @param string $field to retrieve @return mixed data stored in field
__get
php
operasoftware/ssh-key-authority
model/entityevent.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/entityevent.php
Apache-2.0
public function get_log() { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before log entries can be listed'); $stmt = $this->database->prepare(" SELECT * FROM server_event WHERE server_id = ? ORDER BY id DESC "); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $log = array(); while($row = $result->fetch_assoc()) { $log[] = new ServerEvent($row['id'], $row); } $stmt->close(); return $log; }
List all log events for this server. @return array of ServerEvent objects
get_log
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function get_last_sync_event() { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before log entries can be listed'); $stmt = $this->database->prepare("SELECT * FROM server_event WHERE server_id = ? AND details LIKE '{\"action\":\"Sync status change\"%' ORDER BY id DESC LIMIT 1"); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $event = new ServerEvent($row['id'], $row); } else { $event = null; } $stmt->close(); return $event; }
Get the more recent log event that recorded a change in sync status. @todo In a future change we may want to move the 'action' parameter into its own database field. @return ServerEvent last sync status change event
get_last_sync_event
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function list_effective_admins() { $admins = $this->list_admins(); $e_admins = array(); foreach($admins as $admin) { switch(get_class($admin)) { case 'Group': if($admin->active) { $members = $admin->list_members(); foreach($members as $member) { if(get_class($member) == 'User') { $e_admins[] = $member; } } } break; case 'User': $e_admins[] = $admin; break; } } return $e_admins; }
Return the list of all users who can administrate this server, including via group membership of a group that has been made administrator. @return array of User objects
list_effective_admins
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function get_account_by_name($name) { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before accounts can be listed'); $stmt = $this->database->prepare("SELECT entity_id, name FROM server_account WHERE server_id = ? AND name = ?"); $stmt->bind_param('ds', $this->id, $name); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $account = new ServerAccount($row['entity_id'], $row); } else { throw new ServerAccountNotFoundException('Account does not exist.'); } $stmt->close(); return $account; }
Get a server account from the database by its name. @param string $name of account @return ServerAccount with specified name @throws ServerAccountNotFoundException if no account with that name exists
get_account_by_name
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function add_ldap_access_option(ServerLDAPAccessOption $option) { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before LDAP access options can be added'); $stmt = $this->database->prepare("INSERT INTO server_ldap_access_option SET server_id = ?, `option` = ?, value = ?"); $stmt->bind_param('dss', $this->id, $option->option, $option->value); $stmt->execute(); $stmt->close(); }
Add an access option that should be applied to all LDAP accounts on the server. Access options include "command", "from", "no-port-forwarding" etc. @param ServerLDAPAccessOption $option to be added
add_ldap_access_option
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function delete_ldap_access_option(ServerLDAPAccessOption $option) { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before LDAP access options can be deleted'); $stmt = $this->database->prepare("DELETE FROM server_ldap_access_option WHERE server_id = ? AND `option` = ?"); $stmt->bind_param('ds', $this->id, $option->option); $stmt->execute(); $stmt->close(); }
Remove an access option from all LDAP accounts on the server. Access options include "command", "from", "no-port-forwarding" etc. @param ServerLDAPAccessOption $option to be removed
delete_ldap_access_option
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function list_ldap_access_options() { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before LDAP access options can be listed'); $stmt = $this->database->prepare(" SELECT * FROM server_ldap_access_option WHERE server_id = ? ORDER BY `option` "); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $options = array(); while($row = $result->fetch_assoc()) { $options[$row['option']] = new ServerLDAPAccessOption($row['option'], $row); } $stmt->close(); return $options; }
List all current LDAP access options applied to the server. @return array of ServerLDAPAccessOption objects
list_ldap_access_options
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function add_note(ServerNote $note) { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before notes can be added'); $entity_id = $note->user->entity_id; $stmt = $this->database->prepare("INSERT INTO server_note SET server_id = ?, entity_id = ?, date = UTC_TIMESTAMP(), note = ?"); $stmt->bind_param('dds', $this->id, $entity_id, $note->note); $stmt->execute(); $stmt->close(); }
Add a note to the server. The note is a piece of text with metadata (who added it and when). @param ServerNote $note to be added
add_note
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function delete_note(ServerNote $note) { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before notes can be deleted'); $stmt = $this->database->prepare("DELETE FROM server_note WHERE server_id = ? AND id = ?"); $stmt->bind_param('dd', $this->id, $note->id); $stmt->execute(); $stmt->close(); }
Delete the specified note from the server. @param ServerNote $note to be deleted
delete_note
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function get_note_by_id($id) { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before notes can be listed'); $stmt = $this->database->prepare("SELECT * FROM server_note WHERE server_id = ? AND id = ? ORDER BY id"); $stmt->bind_param('dd', $this->id, $id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $note = new ServerNote($row['id'], $row); } else { throw new ServerNoteNotFoundException('Note does not exist.'); } $stmt->close(); return $note; }
Retrieve a specific note for this server by its ID. @param int $id of note to retrieve @return ServerNote matching the ID @throws ServerNoteNotFoundException if no note exists with that ID
get_note_by_id
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function list_notes() { if(is_null($this->id)) throw new BadMethodCallException('Server must be in directory before notes can be listed'); $stmt = $this->database->prepare("SELECT * FROM server_note WHERE server_id = ? ORDER BY id"); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $notes = array(); while($row = $result->fetch_assoc()) { $notes[] = new ServerNote($row['id'], $row); } $stmt->close(); return $notes; }
List all notes associated with this server. @return array of ServerNote objects
list_notes
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function sync_access() { global $sync_request_dir; $sync_request = new SyncRequest; $sync_request->server_id = $this->id; $sync_request->account_name = null; $sync_request_dir->add_sync_request($sync_request); }
Trigger a sync for all accounts on this server.
sync_access
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function list_sync_requests() { $stmt = $this->database->prepare("SELECT * FROM sync_request WHERE server_id = ? ORDER BY account_name"); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $reqs = array(); while($row = $result->fetch_assoc()) { $reqs[] = new SyncRequest($row['id'], $row); } return $reqs; }
List all pending sync requests for this server. @return array of SyncRequest objects
list_sync_requests
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function delete_all_sync_requests() { $stmt = $this->database->prepare("DELETE FROM sync_request WHERE server_id = ?"); $stmt->bind_param('d', $this->id); $stmt->execute(); }
Delete all pending sync requests for this server.
delete_all_sync_requests
php
operasoftware/ssh-key-authority
model/server.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/server.php
Apache-2.0
public function &__get($field) { global $user_dir; switch($field) { case 'server': $server = new Server($this->server_id); return $server; default: return parent::__get($field); } }
Magic getter method - if server field requested, return Server object @param string $field to retrieve @return mixed data stored in field
__get
php
operasoftware/ssh-key-authority
model/serveraccount.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serveraccount.php
Apache-2.0
public function get_log() { if(is_null($this->id)) throw new BadMethodCallException('Server account must be in directory before log entries can be listed'); $stmt = $this->database->prepare(" SELECT * FROM entity_event WHERE entity_id = ? ORDER BY id DESC "); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $log = array(); while($row = $result->fetch_assoc()) { $log[] = new ServerAccountEvent($row['id'], $row); } $stmt->close(); return $log; }
List all log events for this server account. @return array of ServerAccountEvent objects
get_log
php
operasoftware/ssh-key-authority
model/serveraccount.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serveraccount.php
Apache-2.0
public function list_group_membership() { global $group_dir; return $group_dir->list_group_membership($this); }
List all groups that this account is a member of. @return array of Group objects
list_group_membership
php
operasoftware/ssh-key-authority
model/serveraccount.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serveraccount.php
Apache-2.0
public function sync_access() { global $sync_request_dir; $sync_request = new SyncRequest; $sync_request->server_id = $this->server_id; $sync_request->account_name = $this->name; $sync_request_dir->add_sync_request($sync_request); }
Trigger a sync for this account.
sync_access
php
operasoftware/ssh-key-authority
model/serveraccount.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serveraccount.php
Apache-2.0
public function sync_is_pending() { $stmt = $this->database->prepare("SELECT * FROM sync_request WHERE server_id = ? AND (account_name = ? OR account_name IS NULL) ORDER BY account_name"); $stmt->bind_param('ds', $this->server_id, $this->name); $stmt->execute(); $result = $stmt->get_result(); return $result->num_rows > 0; }
Determine if a sync is currently pending for this account. @return boolean true if a sync is pending
sync_is_pending
php
operasoftware/ssh-key-authority
model/serveraccount.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serveraccount.php
Apache-2.0
public function sync_report($status) { if(is_null($this->id)) throw new BadMethodCallException('Server account must be in directory before sync reporting can be done'); if($this->sync_status != 'proposed') { $this->sync_status = $status; $this->update(); } }
Update the sync status for the account. @param string $status "sync success", "sync failure" or "sync warning"
sync_report
php
operasoftware/ssh-key-authority
model/serveraccount.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serveraccount.php
Apache-2.0
public function __construct() { global $database; $this->database = $database; }
Sets up the local $database object for use by the inheriting classes.
__construct
php
operasoftware/ssh-key-authority
model/dbdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/dbdirectory.php
Apache-2.0
public function get_openssh_info() { $filename = tempnam('/tmp', 'key-test-'); $file = fopen($filename, 'w'); fwrite($file, $this->export()); fclose($file); exec('/usr/bin/ssh-keygen -lf '.escapeshellarg($filename).' 2>/dev/null', $output); unlink($filename); if(count($output) == 1 && preg_match('|^([0-9]+) .* \(([A-Z0-9]+)\)$|', $output[0], $matches)) { $this->keysize = intval($matches[1]); return $matches[2]; } else { throw new InvalidArgumentException("Public key doesn't look valid"); } }
Determine the algorithm and keysize of a key by passing it to OpenSSH's ssh-keygen utility. @return string algorithm in use
get_openssh_info
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function export() { return "{$this->type} {$this->keydata} {$this->comment}"; }
Provide the key in OpenSSH-text-format. @return string key in OpenSSH-text-format
export
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function summarize_key_information() { global $config; $url = $config['web']['baseurl'].'/pubkeys/'.urlencode($this->id); $output = "The key fingerprint is:\n"; $output .= " MD5:{$this->fingerprint_md5}\n"; $output .= " SHA256:{$this->fingerprint_sha256}\n\n"; $output .= "The key randomart is:\n"; $randomart_md5 = explode("\n", $this->randomart_md5); $randomart_sha256 = explode("\n", $this->randomart_sha256); foreach($randomart_md5 as $ref => $line) { $output .= $line.' '.$randomart_sha256[$ref]."\n"; } $output .= "\nYou can also view the key at <$url>"; return $output; }
Provide a text summary of details about the key, including hashes, randomart and link to view it. @return string text summary
summarize_key_information
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function add_signature(PublicKeySignature $sig) { if(is_null($this->id)) throw new BadMethodCallException('Public key must be in directory before signatures can be added'); $sig->validate(); $stmt = $this->database->prepare("INSERT INTO public_key_signature SET public_key_id = ?, signature = ?, upload_date = UTC_TIMESTAMP(), fingerprint = ?, sign_date = ?"); $stmt->bind_param('dsss', $this->id, $sig->signature, $sig->fingerprint, $sig->sign_date); $stmt->execute(); $sig->id = $stmt->insert_id; $stmt->close(); $this->owner->sync_remote_access(); }
Add a GPG signature for this public key. @param PublicKeySignature $sig GPG signature to add
add_signature
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function delete_signature(PublicKeySignature $sig) { if(is_null($this->id)) throw new BadMethodCallException('Public key must be in directory before signatures can be deleted'); $stmt = $this->database->prepare("DELETE FROM public_key_signature WHERE public_key_id = ? AND id = ?"); $stmt->bind_param('dd', $this->id, $sig->id); $stmt->execute(); $stmt->close(); $this->owner->sync_remote_access(); }
Delete a GPG signature for this public key. @param PublicKeySignature $sig GPG signature to remove
delete_signature
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function list_signatures() { if(is_null($this->entity_id)) throw new BadMethodCallException('Public key must be in directory before signatures can be listed'); $stmt = $this->database->prepare("SELECT * FROM public_key_signature WHERE public_key_id = ?"); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $sigs = array(); while($row = $result->fetch_assoc()) { $sig = new PublicKeySignature($row['id'], $row); $sig->public_key = $this; $sigs[] = $sig; } $stmt->close(); return $sigs; }
List all GPG signatures stored for this public key. @return array of PublicKeySignature objects
list_signatures
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function add_destination_rule(PublicKeyDestRule $rule) { if(is_null($this->id)) throw new BadMethodCallException('Public key must be in directory before destination rules can be added'); $stmt = $this->database->prepare("INSERT INTO public_key_dest_rule SET public_key_id = ?, account_name_filter = ?, hostname_filter = ?"); $stmt->bind_param('dss', $this->id, $rule->account_name_filter, $rule->hostname_filter); $stmt->execute(); $rule->id = $stmt->insert_id; $stmt->close(); $this->owner->sync_remote_access(); }
Add a destination rule specifying where this key is allowed to be synced to. @param PublicKeyDestRule $rule destination rule to be added
add_destination_rule
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function delete_destination_rule(PublicKeyDestRule $rule) { if(is_null($this->id)) throw new BadMethodCallException('Public key must be in directory before destination rules can be added'); $stmt = $this->database->prepare("DELETE FROM public_key_dest_rule WHERE public_key_id = ? AND id = ?"); $stmt->bind_param('dd', $this->id, $rule->id); $stmt->execute(); $stmt->close(); $this->owner->sync_remote_access(); }
Delete a destination rule that specified where this key was allowed to be synced to. @param PublicKeyDestRule $rule destination rule to be removed
delete_destination_rule
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function list_destination_rules() { if(is_null($this->entity_id)) throw new BadMethodCallException('Public key must be in directory before destination rules can be listed'); $stmt = $this->database->prepare("SELECT * FROM public_key_dest_rule WHERE public_key_id = ?"); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $rules = array(); while($row = $result->fetch_assoc()) { $rules[] = new PublicKeyDestRule($row['id'], $row); } $stmt->close(); return $rules; }
List all destination rule currently applying to this key. @return array of PublicKeyDestRule objects
list_destination_rules
php
operasoftware/ssh-key-authority
model/publickey.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/publickey.php
Apache-2.0
public function &__get($field) { switch($field) { case 'account': $group = new ServerAccount($this->data['entity_id']); return $group; default: return parent::__get($field); } }
Magic getter method - if account field requested, return ServerAccount object of the affected account. @param string $field to retrieve @return mixed data stored in field
__get
php
operasoftware/ssh-key-authority
model/serveraccountevent.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serveraccountevent.php
Apache-2.0
public function &__get($field) { switch($field) { case 'user': $user = new User($this->data['entity_id']); return $user; default: return parent::__get($field); } }
Magic getter method - if group field requested, return Group object of the affected group. @param string $field to retrieve @return mixed data stored in field
__get
php
operasoftware/ssh-key-authority
model/userevent.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/userevent.php
Apache-2.0
public function get_log() { if(is_null($this->id)) throw new BadMethodCallException('Group must be in directory before log entries can be listed'); $stmt = $this->database->prepare("SELECT * FROM entity_event WHERE entity_id = ? ORDER BY id DESC"); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $log = array(); while($row = $result->fetch_assoc()) { $log[] = new GroupEvent($row['id'], $row); } $stmt->close(); return $log; }
List all log events for this group. @return array of GroupEvent objects
get_log
php
operasoftware/ssh-key-authority
model/group.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/group.php
Apache-2.0
public function list_members() { if(is_null($this->entity_id)) throw new BadMethodCallException('Group must be in directory before members can be listed'); $stmt = $this->database->prepare(" SELECT entity.id, entity.type, add_date, added_by FROM group_member INNER JOIN entity ON group_member.entity_id = entity.id LEFT JOIN user ON user.entity_id = entity.id LEFT JOIN server_account ON server_account.entity_id = entity.id LEFT JOIN server ON server.id = server_account.server_id LEFT JOIN `group` ON `group`.entity_id = entity.id WHERE group_member.group = ? ORDER BY entity.type, user.uid, server.hostname, server_account.name, `group`.name "); $stmt->bind_param('d', $this->entity_id); $stmt->execute(); $result = $stmt->get_result(); $members = array(); while($row = $result->fetch_assoc()) { $row['added_by'] = new User($row['added_by']); switch($row['type']) { case 'user': $members[] = new User($row['id'], $row); break; case 'server account': $members[] = new ServerAccount($row['id'], $row); break; case 'group': $members[] = new Group($row['id'], $row); break; } } $stmt->close(); return $members; }
List all members of the group. @todo remove nested group functionality @return array of User/ServerAccount/Group objects
list_members
php
operasoftware/ssh-key-authority
model/group.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/group.php
Apache-2.0
public function list_group_membership() { global $group_dir; return $group_dir->list_group_membership($this); }
List all groups that *this* group is a member of, searched recursively. Note: nested groups are no longer allowed by the UI. @todo remove nested group functionality @return array of Group objects
list_group_membership
php
operasoftware/ssh-key-authority
model/group.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/group.php
Apache-2.0
public function add_option(AccessOption $option) { if(is_null($this->id)) throw new BadMethodCallException('Access rule must be in directory before options can be added'); $stmt = $this->database->prepare("INSERT INTO access_option SET access_id = ?, `option` = ?, value = ?"); $stmt->bind_param('dss', $this->id, $option->option, $option->value); $stmt->execute(); $stmt->close(); }
Add an SSH access option to the access rule Access options include "command", "from", "no-port-forwarding" etc. @param AccessOption $option to be added
add_option
php
operasoftware/ssh-key-authority
model/access.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/access.php
Apache-2.0
public function delete_option(AccessOption $option) { if(is_null($this->id)) throw new BadMethodCallException('Access rule must be in directory before options can be deleted'); $stmt = $this->database->prepare("DELETE FROM access_option WHERE access_id = ? AND `option` = ?"); $stmt->bind_param('ds', $this->id, $option->option); $stmt->execute(); $stmt->close(); }
Remove an SSH option from the access rule @param AccessOption $option to be removed
delete_option
php
operasoftware/ssh-key-authority
model/access.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/access.php
Apache-2.0
public function list_options() { if(is_null($this->id)) throw new BadMethodCallException('Access rule must be in directory before options can be listed'); $stmt = $this->database->prepare(" SELECT * FROM access_option WHERE access_id = ? ORDER BY `option` "); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); $options = array(); while($row = $result->fetch_assoc()) { $options[$row['option']] = new AccessOption($row['option'], $row); } $stmt->close(); return $options; }
List all current SSH access options applied to the access rule. @return array of AccessOption objects
list_options
php
operasoftware/ssh-key-authority
model/access.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/access.php
Apache-2.0
public function &__get($field) { global $user_dir; switch($field) { case 'superior': if(is_null($this->superior_entity_id)) $superior = null; else $superior = new User($this->superior_entity_id); return $superior; default: return parent::__get($field); } }
Magic getter method - if superior field requested, return User object of user's superior @param string $field to retrieve @return mixed data stored in field
__get
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function admin_of(Record $record) { switch(get_class($record)) { case 'Server': $stmt = $this->database->prepare(" SELECT entity_id FROM group_member WHERE (`group` IN ( SELECT entity_id FROM server_admin WHERE server_id = ?) AND entity_id = ?) UNION (SELECT entity_id FROM server_admin WHERE server_id = ? AND entity_id = ?)"); $stmt->bind_param('dddd', $record->id, $this->entity_id, $record->id, $this->entity_id); $stmt->execute(); $result = $stmt->get_result(); return $result->num_rows >= 1; break; case 'Group': case 'ServerAccount': $stmt = $this->database->prepare("SELECT * FROM entity_admin WHERE admin = ? AND entity_id = ?"); $stmt->bind_param('dd', $this->entity_id, $record->entity_id); $stmt->execute(); $result = $stmt->get_result(); return $result->num_rows >= 1; break; default: throw new InvalidArgumentException('Records of type '.get_class($record).' cannot be administered'); } }
Determine if this user is an administrator of the specified entity or server. @param Record $record object to check for administration privileges @return bool true if user is an administrator of the object @throws InvalidArgumentException if a non-administratable Record is provided
admin_of
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function member_of(Group $group) { $stmt = $this->database->prepare("SELECT * FROM group_member WHERE entity_id = ? AND `group` = ?"); $stmt->bind_param('dd', $this->entity_id, $group->entity_id); $stmt->execute(); $result = $stmt->get_result(); return $result->num_rows >= 1; }
Determine if this user is a member of the specified group @param Group $group to check membership of @return bool true if user is an member of the group
member_of
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function add_alert(UserAlert $alert) { if(is_null($this->entity_id)) throw new BadMethodCallException('User must be in directory before alerts can be added'); $stmt = $this->database->prepare("INSERT INTO user_alert SET entity_id = ?, class = ?, content = ?, escaping = ?"); $stmt->bind_param('dssd', $this->entity_id, $alert->class, $alert->content, $alert->escaping); $stmt->execute(); $alert->id = $stmt->insert_id; $stmt->close(); }
Add an alert to be displayed to this user on their next normal page load. @param UserAlert $alert to be displayed
add_alert
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function pop_alerts() { if(is_null($this->entity_id)) throw new BadMethodCallException('User must be in directory before alerts can be listed'); $stmt = $this->database->prepare("SELECT * FROM user_alert WHERE entity_id = ?"); $stmt->bind_param('d', $this->entity_id); $stmt->execute(); $result = $stmt->get_result(); $alerts = array(); $alert_ids = array(); while($row = $result->fetch_assoc()) { $alerts[] = new UserAlert($row['id'], $row); $alert_ids[] = $row['id']; } $stmt->close(); if(count($alert_ids) > 0) { $this->database->query("DELETE FROM user_alert WHERE id IN (".implode(", ", $alert_ids).")"); } return $alerts; }
List all alerts for this user *and* delete them. @return array of UserAlert objects
pop_alerts
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function has_access(ServerAccount $account) { if(is_null($this->entity_id)) throw new BadMethodCallException('User must be in directory before access can be checked'); $stmt = $this->database->prepare("SELECT * FROM access WHERE source_entity_id = ? AND dest_entity_id = ?"); $stmt->bind_param('dd', $this->entity_id, $account->entity_id); $stmt->execute(); $result = $stmt->get_result(); return (bool)$result->fetch_assoc(); }
Determine if this user has been granted access to the specified account. @param ServerAccount $account to check for access @return bool true if user has access to the account
has_access
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function get_csrf_field() { return '<input type="hidden" name="csrf_token" value="'.hesc($this->get_csrf_token()).'"><!-- '.hash("sha512", mt_rand(0, mt_getrandmax())).' -->'."\n"; }
Return HTML containing the user's CSRF token for inclusion in a POST form. Also includes a random string of the same length to help guard against http://breachattack.com/ @return string HTML
get_csrf_field
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function get_csrf_token() { if(is_null($this->entity_id)) throw new BadMethodCallException('User must be in directory before CSRF token can be generated'); if(!isset($this->data['csrf_token'])) { $this->data['csrf_token'] = hash("sha512", mt_rand(0, mt_getrandmax())); $this->update(); } return $this->data['csrf_token']; }
Return the user's CSRF token. Generate one if they do not yet have one. @return string CSRF token
get_csrf_token
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function check_csrf_token($token) { return $token === $this->get_csrf_token(); }
Check the given string against the user's CSRF token. @return bool true on string match
check_csrf_token
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function get_superior_from_ldap() { global $user_dir, $config; if(is_null($this->entity_id)) throw new BadMethodCallException('User must be in directory before superior employee can be looked up'); if(!isset($config['ldap']['user_superior'])) { throw new BadMethodCallException("Cannot retrieve user's superior if user_superior is not configured"); } $ldapusers = $this->ldap->search($config['ldap']['dn_user'], LDAP::escape($config['ldap']['user_id']).'='.LDAP::escape($this->uid), array($config['ldap']['user_superior'])); if($ldapuser = reset($ldapusers)) { $superior = null; if(isset($ldapuser[strtolower($config['ldap']['user_superior'])]) && $ldapuser[strtolower($config['ldap']['user_superior'])] != $this->uid) { $superior_uid = $ldapuser[strtolower($config['ldap']['user_superior'])]; try { $superior = $user_dir->get_user_by_uid($superior_uid); } catch(UserNotFoundException $e) { } } if(is_null($superior)) { $this->superior_entity_id = null; } else { $this->superior_entity_id = $superior->entity_id; } $this->update(); } else { throw new UserNotFoundException('User does not exist.'); } }
Retrieve the user's superior from LDAP. @throws UserNotFoundException if the user is not found in LDAP
get_superior_from_ldap
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function sync_access() { }
Implements the Entity::sync_access as a no-op as it makes no sense to grant access TO a user.
sync_access
php
operasoftware/ssh-key-authority
model/user.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/user.php
Apache-2.0
public function &__get($field) { if(!array_key_exists($field, $this->data)) { // We don't have a value for this field yet if(is_null($this->id)) { // Record is not yet in the database - nothing to retrieve $result = null; return $result; } // Attempt to get data from database $stmt = $this->database->prepare("SELECT * FROM `$this->table` WHERE {$this->idfield} = ?"); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); if($result->num_rows != 1) { throw new Exception("Unexpected number of rows returned ({$result->num_rows}), expected exactly 1. Table:{$this->table}, ID field: {$this->idfield}, ID: {$this->id}"); } $data = $result->fetch_assoc(); // Populate data array for fields we do not already have a value for foreach($data as $f => $v) { if(!isset($this->data[$f])) { $this->data[$f] = $v; } } $stmt->close(); if(!array_key_exists($field, $this->data)) { // We still don't have a value, so this field doesn't exist in the database throw new Exception("Field $field does not exist in {$this->table} table."); } } return $this->data[$field]; }
Magic getter method - return the value of the specified field. Retrieve the row from the database if we do not have data for that field yet. @param string $field name of field to retrieve @return mixed data stored in field @throws Exception if the row or the field does not exist in the database
__get
php
operasoftware/ssh-key-authority
model/record.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/record.php
Apache-2.0
public function __set($field, $value) { $this->data[$field] = $value; $this->dirty = true; if($field == $this->idfield) $this->id = $value; }
Magic setter method - store the updated value and set the record as dirty. @param string $field name of field @param mixed $value data to store in field
__set
php
operasoftware/ssh-key-authority
model/record.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/record.php
Apache-2.0
public function update() { $stmt = $this->database->prepare("SELECT * FROM `$this->table` WHERE {$this->idfield} = ?"); $stmt->bind_param('d', $this->id); $stmt->execute(); $result = $stmt->get_result(); if(!($row = $result->fetch_assoc())) { throw new Exception("Record not found in database"); } $stmt->close(); $updates = array(); $fields = array(); $values = array(); $types = ''; foreach($row as $field => $value) { if(array_key_exists($field, $this->data) && $this->data[$field] != $value) { $update = new StdClass; $update->field = $field; $update->old_value = $value; $update->new_value = $this->data[$field]; $updates[] = $update; $fields[] = "`$field` = ?"; $values[] =& $this->data[$field]; $types .= 's'; } } if(!empty($updates)) { try { $stmt = $this->database->prepare("UPDATE `$this->table` SET ".implode(', ', $fields)." WHERE {$this->idfield} = ?"); $values[] =& $this->id; $types .= 'd'; array_unshift($values, $types); $reflection = new ReflectionClass('mysqli_stmt'); $method = $reflection->getMethod("bind_param"); $method->invokeArgs($stmt, $values); $stmt->execute(); } catch(mysqli_sql_exception $e) { if($e->getCode() == 1062) { // Duplicate entry $message = $e->getMessage(); if(preg_match("/^Duplicate entry '(.*)' for key '(.*)'$/", $message, $matches)) { $ne = new UniqueKeyViolationException($e->getMessage()); $ne->fields = explode(',', $matches[2]); $ne->values = explode(',', $matches[1]); throw $ne; } } throw $e; } } $this->dirty = false; return $updates; }
Update the database with all fields that have been modified. @return array of StdClass detailing actual updates that were applied @throws UniqueKeyViolationException if the update violated a unique key on the table
update
php
operasoftware/ssh-key-authority
model/record.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/record.php
Apache-2.0
public function get_server_account_by_id($entity_id) { $stmt = $this->database->prepare("SELECT * FROM server_account WHERE entity_id = ?"); $stmt->bind_param('d', $entity_id); $stmt->execute(); $result = $stmt->get_result(); if($row = $result->fetch_assoc()) { $account = new ServerAccount($row['entity_id'], $row); } else { throw new ServerAccountNotFoundException('Server account does not exist.'); } $stmt->close(); return $account; }
Get a server account from the database by its entity ID. @param int $entity_id of server account @return ServerAccount with specified entity ID @throws ServerAccountNotFoundException if no server account with that entity ID exists
get_server_account_by_id
php
operasoftware/ssh-key-authority
model/serveraccountdirectory.php
https://github.com/operasoftware/ssh-key-authority/blob/master/model/serveraccountdirectory.php
Apache-2.0
public static function assignSignature($text, $type) { $signature = "\n" . Config::get('larasap.telegram.channel_signature'); $signature_length = strlen($signature); $text_length = strlen($text); $max_length = ($type == 'text') ? TelegramApi::TEXT_LENGTH : TelegramApi::CAPTION_LENGTH; if ($signature_length + $text_length <= $max_length || $signature_length > $text_length) { return $text . $signature; } return substr($text, 0, $max_length - $signature_length) . $signature; }
Assign channel signature in the footer of message @param $text @param $text_type
assignSignature
php
alihesari/laravel-social-auto-posting
src/SendTo.php
https://github.com/alihesari/laravel-social-auto-posting/blob/master/src/SendTo.php
MIT
public static function x($message, $options = []) { return XApi::init()->sendMessage($message, null, $options); }
Send message to X (formerly Twitter) @param string $message @param array $options @return array
x
php
alihesari/laravel-social-auto-posting
src/SendTo.php
https://github.com/alihesari/laravel-social-auto-posting/blob/master/src/SendTo.php
MIT
public static function init() { return new self(); }
Initialize the X API with credentials @return self @throws Exception
init
php
alihesari/laravel-social-auto-posting
src/Services/X/Api.php
https://github.com/alihesari/laravel-social-auto-posting/blob/master/src/Services/X/Api.php
MIT
private function handleRateLimits($response) { $headers = $response->headers(); self::$rateLimitRemaining = (int) ($headers['x-rate-limit-remaining'][0] ?? null); self::$rateLimitReset = (int) ($headers['x-rate-limit-reset'][0] ?? null); self::$rateLimitLimit = (int) ($headers['x-rate-limit-limit'][0] ?? null); self::$rateLimitUsed = (int) ($headers['x-rate-limit-used'][0] ?? null); }
Handle rate limiting from X API response @param \Illuminate\Http\Client\Response $response @return void
handleRateLimits
php
alihesari/laravel-social-auto-posting
src/Services/X/Api.php
https://github.com/alihesari/laravel-social-auto-posting/blob/master/src/Services/X/Api.php
MIT
private function isRateLimited() { return self::$rateLimitRemaining !== null && self::$rateLimitRemaining <= 0; }
Check if we've hit rate limits @return bool
isRateLimited
php
alihesari/laravel-social-auto-posting
src/Services/X/Api.php
https://github.com/alihesari/laravel-social-auto-posting/blob/master/src/Services/X/Api.php
MIT