Commit f625f85d authored by Jørn Åne de Jong's avatar Jørn Åne de Jong

Intial commit, import from eduroam portal

parents
/composer.phar
/vendor/
Eduroam KIND integration
========================
Library to access eduroam-related information from UNINETT KIND.
This library is generic and requires an implementing library that handles the actual reading/writing.
This makes it easier to switch out the backend when KIND gets upgraded,
or when the eduroam code is used at another national network which does not have KIND.
{
"name": "eduroam/kind-common",
"description": "Eduroam KIND integration",
"license": "Proprietary, In-house",
"authors": [
{
"name": "Jørn de Jong",
"email": "jorn.dejong@uninett.no"
}
],
"autoload": {
"files": [
"src/_autoload.php"
]
}
}
<?php
/*
* Copyright (c) 2014, Yørn de Jong <@yorn>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* Register SPL autoloading for classes and interfaces. Put this file in your
* namespace root and make sure it gets included from your PHP entry-point.
*
* There is no requirement for capitalisation for your namespaces and classes,
* but all folders and files MUST be lower-case. Class names are automatically
* lower-cased on autoload. This conforms to the PHP design philosophy that
* functions and class names must be case-insensitive.
*
* The include path is changed to prefer the current directory over the
* established include path. This is because manual include/require statements
* will likely not be used, because it will be handled by autoloading.
* Feel free to change this behaviour if that works better for you.
*
* @author Yørn de Jong <@yorn>
* @copyright Copyright (c) 2014, Yørn de Jong <@yorn>
* @link https://gist.github.com/yorn/667f2e3acc262ce6bf44
* @link http://php.net/manual/en/function.spl-autoload.php
* @license http://choosealicense.com/licenses/isc/ ISC license
*/
spl_autoload_extensions( '.php' );
spl_autoload_register( 'spl_autoload' );
set_include_path( __DIR__ . PATH_SEPARATOR . get_include_path() );
<?php namespace UNINETT\Eduroam\KIND;
/**
* Kobling mellom et tjenesteabonnement og en eduroam realm
*/
class EduroamRealm {
/**
* @var string
*/
public $navn;
}
<?php namespace UNINETT\Eduroam\KIND;
/**
* Et tjenesteabonnement knytter sammen en tjeneste og en abonnent/organisasjon)
* Object is flattened compared to KIND for easier access.
*/
class EduroamTjenesteAbonnement {
/**
* @var integer
*/
public $id;
/**
* @var string
*/
public $orgNavn;
/**
* @var string
*/
public $domain;
/**
* @var integer
*/
public $catId;
/**
* @var integer
*/
public $eduroamType;
/**
* @var string
*/
public $gateAdresse;
/**
* @var string
*/
public $postSted;
/**
* @var DateTime
*/
public $lastChange;
}
This diff is collapsed.
<?php namespace UNINETT\Eduroam\KIND;
/**
* Interface for communication with UNINETTs KIND database.
*/
interface KINDAPI {
/**
* Get all EduroamRealms associated with given EduroamTjenesteAbonnement
*
* @param EduroamTjenesteAbonnement $tjenesteAbonnement
*
* @return EduroamRealm[]
*/
function getEduroamRealmsByTjenesteAbonnement(EduroamTjenesteAbonnement $tjenesteAbonnement);
/**
* Get all EduroamTjenesteAbonnement instances
*
* @return EduroamTjenesteAbonnement[]
*/
function getAllTjenesteAbonnements();
/**
* Get an EduroamTjenesteAbonnement by Realm Name
*
* @param string $realmName FQDN of realm
*
* @return EduroamTjenesteAbonnement
*/
function getTjenesteAbonnementByRealmName($realmName);
/**
* Get an EduroamTjenesteAbonnement by the domain name
* Convention is that the domain name is the same as the kortnavn in KIND
*
* @param string $realmName FQDN of realm
*
* @return EduroamTjenesteAbonnement
*/
function getTjenesteAbonnementByDomainName($domainName);
/**
* Get all EduroamTjenesteAbonnements by FeideUID
*
* @see https://kind.uninett.no/dok/README.sql.html#roller
*
* @param string $feideUid Feide ID of user
* @param integer[] $roles Matching roles (2 is Teknisk Ansvarlig)
*
* @return EduroamTjenesteAbonnement[]
*/
function getTjenesteAbonnementsByFeideUid($feideUid, array $roles = [2]);
/**
* Get all TjenesteLokasjons associated with given EduroamTjenesteAbonnement
*
* @param EduroamTjenesteAbonnement $tjenesteAbonnement
*
* @return TjenesteLokasjon[]
*/
function getTjenesteLokasjonsByTjenesteAbonnement(EduroamTjenesteAbonnement $tjenesteAbonnement);
/**
* Get all TjenesteLokasjons
*
* @return TjenesteLokasjon[]
*/
function getAllTjenesteLokasjons();
/**
* Get a TjenesteLokasjons by its id
*
* @param EduroamTjenesteAbonnement $tjenesteAbonnement
* @param integer $id
*
* @return TjenesteLokasjon
*/
function getTjenesteLokasjonById(EduroamTjenesteAbonnement $tjenesteAbonnement, $id);
/**
* Get all Rolletildelings associated with given EduroamTjenesteAbonnement
*
* @see https://kind.uninett.no/dok/README.sql.html#roller
*
* @param EduroamTjenesteAbonnement $tjenesteAbonnement
* @param integer[] $roles Matching roles (2 is Teknisk Ansvarlig)
*
* @return Rolletildeling[]
*/
function getRolletildelingsByTjenesteAbonnement(EduroamTjenesteAbonnement $tjenesteAbonnement, array $roles = [2]);
/**
* Store a new TjenesteLokasjon in KIND.
* If it has an ID, it will overwrite any existing location already in place.
*
* @param TjenesteLokasjon $tjenesteLokasjon
*/
function putTjenesteLokasjon(TjenesteLokasjon $tjenesteLokasjon);
/**
* Remove a TjenesteLokasjon from KIND.
*
* @param TjenesteLokasjon $tjenesteLokasjon
*/
function removeTjenesteLokasjon(TjenesteLokasjon $tjenesteLokasjon);
/**
* Get all Rolletildelings that are associated with the Eduroam service.
*
* @return Rolletildeling[]
*/
function getRolletildelingsByTjenesteNavn();
/**
* Get information about the Eduroam service
*
* @return ServiceInformation
*/
function getServiceInformation();
}
<?php namespace UNINETT\Eduroam\KIND;
/**
* @see https://kind.uninett.no/dok/README.sql.html#roller
* Object is flattened compared to KIND for easier access.
*/
class Rolletildeling {
/**
* @var string
*/
public $rolleNavn;
/**
* @var string
*/
public $status;
/**
* @var string
*/
public $kontaktNavn;
/**
* @var string
*/
public $kontaktEPost;
/**
* @var string
*/
public $kontaktDirekteTelefon;
/**
* @var DateTime
*/
public $start;
/**
* @var DateTime
*/
public $slutt;
/**
* @var string
*/
public $feideUid;
/**
* @var DateTime
*/
public $lastChange;
}
<?php namespace UNINETT\Eduroam\KIND;
/**
*/
class ServiceInformation {
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $descriptionUrl;
/**
* @var DateTime
*/
public $lastChange;
/**
* @var string
*/
public $streetAddress;
/**
* @var string
*/
public $city;
}
<?php namespace UNINETT\Eduroam\KIND;
use \DomainException;
/**
* Steder der eduroam er tilgjengelig
*/
class TjenesteLokasjon {
const WPA_TKIP = 'WPA/TKIP';
const WPA_AES = 'WPA/AES';
const WPA2_TKIP = 'WPA2/TKIP';
const WPA2_AES = 'WPA2/AES';
/**
* @var EduroamTjenesteAbonnement
*/
public $tjenesteAbonnement;
/**
* @var integer
*/
public $id;
/**
* @var string
*/
public $navn;
/**
* @var gPoint
*/
public $utm;
/**
* @var string
*/
public $gateAdresse;
/**
* @var string
*/
public $postSted;
/**
* @var string
*/
public $ssid;
/**
* @var string[]
*/
public $encLevel;
/**
* @var boolean
*/
public $portRestrict;
/**
* @var boolean
*/
public $transProxy;
/**
* @var boolean
*/
public $ipv6;
/**
* @var boolean
*/
public $nat;
/**
* @var integer
*/
public $apNo;
/**
* @var boolean
*/
public $wired;
/**
* @var DateTime
*/
public $lastChange;
/**
* @var string
*/
public $infoUrl;
/**
* Do a sanity check on the values in this object,
* and throw an exception if they do not make sense in any way.
*
* @throws DomainException
*/
public function validate() {
$errors = [];
if (!$this->navn || !is_string($this->navn))
$errors[] = 'Please enter a name.';
if (!($this->utm instanceof gPoint))
$errors[] = 'Illegal location.';
if (!$this->gateAdresse || !is_string($this->gateAdresse))
$errors[] = 'Please enter an address.';
if (!$this->postSted || !is_string($this->postSted))
$errors[] = 'Please enter a city.';
if (!$this->ssid || !is_string($this->ssid))
$errors[] = 'Please enter a SSID.';
if (!$this->encLevel || !is_array($this->encLevel)) {
$errors[] = 'Please enter encryption level.';
} else {
foreach($this->encLevel as $level) {
if (!in_array($level, [self::WPA_TKIP,self::WPA_AES,self::WPA2_TKIP,self::WPA2_AES])) {
$errors[] = 'Illegal encryption level: ' . $level;
break;
}
}
}
if (!is_bool($this->portRestrict))
$errors[] = 'Wrong type for Port Restrict (should be boolean).';
if (!is_bool($this->transProxy))
$errors[] = 'Wrong type for Transparent Proxy (should be boolean).';
if (!is_bool($this->ipv6))
$errors[] = 'Wrong type for IPv6 (should be boolean).';
if (!is_bool($this->nat))
$errors[] = 'Wrong type for NAT (should be boolean).';
if (intval($this->apNo) != trim($this->apNo))
$errors[] = 'Wrong type for PortRestrict (should be integer).';
if (!is_bool($this->wired))
$errors[] = 'Wrong type for Wired (should be boolean).';
if (!($this->tjenesteAbonnement instanceof EduroamTjenesteAbonnement))
$errors[] = 'Invalid TjenesteAbonnement';
if ($errors) {
throw new DomainException(implode(PHP_EOL, $errors));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment