Esempio n. 1
0
function view_se()
{
    require_once __DIR__ . '/../utils.php';
    require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php';
    if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
        throw new Exception("An id must be specified");
    }
    $id = $_GET['id'];
    //get user for case that portal is read only and user is admin, so they can still see edit links
    $dn = Get_User_Principle();
    $user = \Factory::getUserService()->getUserByPrinciple($dn);
    $serv = \Factory::getServiceService();
    $params['authenticated'] = false;
    if ($user != null) {
        $params['authenticated'] = true;
    }
    $params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user);
    $se = $serv->getService($id);
    // Does current viewer have edit permissions over object ?
    $params['ShowEdit'] = false;
    if ($user != null && count($serv->authorizeAction(\Action::EDIT_OBJECT, $se, $user)) >= 1) {
        $params['ShowEdit'] = true;
    }
    $title = $se->getHostName() . " - " . $se->getServiceType()->getName();
    $params['se'] = $se;
    $params['sGroups'] = $se->getServiceGroups();
    $params['Scopes'] = $serv->getScopesWithParentScopeInfo($se);
    // Show upcoming downtimes and downtimes that started within the last thirty days
    $downtimes = $serv->getDowntimes($id, 31);
    $params['Downtimes'] = $downtimes;
    show_view("service/view_service.php", $params, $title);
}
Esempio n. 2
0
function search_ses()
{
    if (!isset($_REQUEST['term'])) {
        return "";
    } else {
        $searchTerm = strip_tags(trim($_REQUEST['term']));
    }
    if (1 === preg_match("/[';\"]/", $searchTerm)) {
        throw new Exception("Invalid char in search term");
    }
    if (substr($searchTerm, 0, 1) != '%') {
        $searchTerm = '%' . $searchTerm;
    }
    if (substr($searchTerm, -1) != '%') {
        $searchTerm = $searchTerm . '%';
    }
    require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
    try {
        $ses = \Factory::getServiceService()->getSes($searchTerm, null, null, null, null, null, null, null, null, null, null, null, true);
    } catch (Exception $ex) {
        show_view('error.php', $ex->getMessage() . "<br /><br />Please contact the " . "<a href=\"index.php?Page_Type=Static_HTML&Page=Help_And_Contact\">" . "GOCDB support team</a> if you need help with this issue.");
    }
    $params = array('ses' => $ses);
    show_view('service_group/se_search.php', $params, null, true);
}
function submit(\EndpointLocation $endpoint, \Service $service, \User $user = null)
{
    $serv = \Factory::getServiceService();
    try {
        $serv->deleteEndpoint($endpoint, $user);
    } catch (\Exception $e) {
        show_view('error.php', $e->getMessage());
        die;
    }
    $params['endpoint'] = $endpoint;
    $params['service'] = $service;
    show_view('/service/deleted_service_endpoint.php', $params);
}
Esempio n. 4
0
function se_downtimes()
{
    if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
        throw new Exception("An id must be specified");
    }
    $serviceService = \Factory::getServiceService();
    $se = $serviceService->getService($_REQUEST['id']);
    $downtimes = $serviceService->getDowntimes($_REQUEST['id'], null);
    $params['se'] = $se;
    $params['downtimes'] = $downtimes;
    $title = "Downtimes for " . $se->getHostName();
    show_view('service/se_downtimes.php', $params, $title);
    return;
}
Esempio n. 5
0
function view_site()
{
    require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
    require_once __DIR__ . '/../utils.php';
    require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php';
    $serv = \Factory::getSiteService();
    $servServ = \Factory::getServiceService();
    if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
        throw new Exception("An id must be specified");
    }
    $siteId = $_GET['id'];
    $site = $serv->getSite($siteId);
    $allRoles = $site->getRoles();
    $roles = array();
    foreach ($allRoles as $role) {
        if ($role->getStatus() == \RoleStatus::GRANTED) {
            $roles[] = $role;
        }
    }
    //get user for case that portal is read only and user is admin, so they can still see edit links
    $dn = Get_User_Principle();
    $user = \Factory::getUserService()->getUserByPrinciple($dn);
    $params['UserIsAdmin'] = false;
    if (!is_null($user)) {
        $params['UserIsAdmin'] = $user->isAdmin();
    }
    $params['authenticated'] = false;
    if ($user != null) {
        $params['authenticated'] = true;
    }
    // Does current viewer have edit permissions over Site ?
    $params['ShowEdit'] = false;
    if (count($serv->authorizeAction(\Action::EDIT_OBJECT, $site, $user)) >= 1) {
        $params['ShowEdit'] = true;
    }
    $params['Scopes'] = $serv->getScopesWithParentScopeInfo($site);
    $params['ServicesAndScopes'] = array();
    foreach ($site->getServices() as $service) {
        $params['ServicesAndScopes'][] = array('Service' => $service, 'Scopes' => $servServ->getScopesWithParentScopeInfo($service));
    }
    $params['Downtimes'] = $serv->getDowntimes($site->getId(), 31);
    $params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user);
    $title = $site->getShortName();
    $params['site'] = $site;
    $params['roles'] = $roles;
    // Add RoleActionRecords to params
    $params['RoleActionRecords'] = \Factory::getRoleService()->getRoleActionRecordsById_Type($site->getId(), 'site');
    show_view("site/view_site.php", $params, $title);
}
Esempio n. 6
0
/**
 *  Draws a form to add a new service property
 * @param \User $user current user 
 * @return null
 */
function draw(\User $user = null)
{
    if (is_null($user)) {
        throw new Exception("Unregistered users can't add a service property.");
    }
    if (!isset($_REQUEST['se']) || !is_numeric($_REQUEST['se'])) {
        throw new Exception("An id must be specified");
    }
    $serv = \Factory::getServiceService();
    $service = $serv->getService($_REQUEST['se']);
    //get service by id
    //Check user has permissions to add service property
    $serv->validateAddEditDeleteActions($user, $service);
    $params['serviceid'] = $_REQUEST['se'];
    show_view("service/add_service_property.php", $params);
}
Esempio n. 7
0
/**
 * Controller for a delete service request
 * @return null
 */
function delete()
{
    $dn = Get_User_Principle();
    $user = \Factory::getUserService()->getUserByPrinciple($dn);
    if ($user == null) {
        throw new \Exception("Unregistered users can't delete services. ");
    }
    //Check the portal is not in read only mode, returns exception if it is and user is not an admin
    checkPortalIsNotReadOnlyOrUserIsAdmin($user);
    if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
        throw new Exception("An id must be specified");
    }
    $serv = \Factory::getServiceService();
    $se = $serv->getService($_REQUEST['id']);
    $serv->deleteService($se, $user);
    show_view('service/service_deleted.php');
}
function submit(\ServiceProperty $property, \Service $service, \User $user = null)
{
    if (is_null($user)) {
        throw new Exception("Unregistered users can't delete a service property.");
    }
    $params['prop'] = $property;
    $params['service'] = $service;
    //remove site property
    try {
        $serv = \Factory::getServiceService();
        $serv->deleteServiceProperty($service, $user, $property);
    } catch (\Exception $e) {
        show_view('error.php', $e->getMessage());
        die;
    }
    show_view('/service/deleted_service_property.php', $params);
}
Esempio n. 9
0
/**
 * Processes an edit endpoint request from a web request
 * @param \User $user current user
 * return null
 */
function submit(\User $user = null)
{
    try {
        $newValues = getEndpointDataFromWeb();
        $serviceID = $newValues['SERVICEENDPOINT']['SERVICE'];
        $endpointID = $newValues['SERVICEENDPOINT']['ENDPOINTID'];
        $serv = \Factory::getServiceService();
        $endpoint = $serv->getEndpoint($endpointID);
        $service = $serv->getService($serviceID);
        $serv->editEndpoint($service, $user, $endpoint, $newValues);
        $params['serviceid'] = $serviceID;
        $params['endpointid'] = $endpointID;
        show_view('service/service_endpoint_updated.php', $params);
    } catch (Exception $e) {
        show_view('error.php', $e->getMessage());
        die;
    }
}
Esempio n. 10
0
/**
 * Validates the user's input, removes the services and
 * returns the object ID of the removed service 
 * @global array $_REQUEST only set if the browser has sent parameters
 * @param \User $user current User
 * @return null
 */
function submit(\User $user = null)
{
    $serv = \Factory::getServiceGroupService();
    if (!isset($_REQUEST['sgId']) || !is_numeric($_REQUEST['sgId'])) {
        throw new Exception("An id must be specified");
    }
    if (!isset($_REQUEST['seId']) || !is_numeric($_REQUEST['seId'])) {
        throw new Exception("An id must be specified");
    }
    // The service group to remove SEs from
    $sg = $serv->getServiceGroup($_REQUEST['sgId']);
    $se = \Factory::getServiceService()->getService($_REQUEST['seId']);
    try {
        /* If the service is siteless and was created under this
         * service group then we delete it */
        if (is_null($se->getParentSite())) {
            // TODO: v5 implementation
            // If 0 was returned above then the SE doesn't have a hosting site
            //             $hostingVSite = \Factory::getServiceService()->
            //                 getHostVirtualSite($endpointId, $gridId);
            //             /* If this service group created the endpoint then delete
            //              * it */
            //             if($hostingVSite == $vSiteId) {
            //                 $db = ConnectionFactory::getNewConnection();
            //                 $promAPI = PromAPIFactory::getPromAPI($db);
            //                 $returned_object_id = $promAPI->DeleteObject($endpointId, $gridId, null);
            //                 if(!$promAPI->commit()) throw new Exception("Could not commit");
            //                 ConnectionFactory::managedClose($db);
            //                 show_view('vsite/return_removed_se.php', array('removedSe' => $_REQUEST['endpointId']), null, true);
            //                 die();
            //             }
        }
        /* If the SE isn't siteless and created under this service group
         * remove it as normal */
        $serv->removeService($sg, $se, $user);
    } catch (Exception $e) {
        show_view('error.php', $e->getMessage());
        die;
    }
    show_view('service_group/return_removed_se.php', array('se' => $se), null, true);
    die;
}
Esempio n. 11
0
/**
 * Processes an edit site property request from a web request
 * @param \User $user current user
 * return null
 */
function submit(\User $user = null)
{
    try {
        $newValues = getSerPropDataFromWeb();
        $serviceID = $newValues['SERVICEPROPERTIES']['SERVICE'];
        $propID = $newValues['SERVICEPROPERTIES']['PROP'];
        if ($newValues['SERVICEPROPERTIES']['NAME'] == null || $newValues['SERVICEPROPERTIES']['VALUE'] == null) {
            show_view('error.php', "A property name and value must be provided.");
            die;
        }
        $property = \Factory::getServiceService()->getProperty($propID);
        $service = \Factory::getServiceService()->getService($serviceID);
        $service = \Factory::getServiceService()->editServiceProperty($service, $user, $property, $newValues);
        $params['serviceid'] = $serviceID;
        show_view('service/service_property_updated.php', $params);
    } catch (Exception $e) {
        show_view('error.php', $e->getMessage());
        die;
    }
}
Esempio n. 12
0
/**
 * Processes an edit endpoint property request from a web request
 * @param \User $user current user
 * return null
 */
function submit(\User $user = null)
{
    try {
        $newValues = getEndpointPropDataFromWeb();
        $endpointID = $newValues['ENDPOINTPROPERTIES']['ENDPOINTID'];
        $propID = $newValues['ENDPOINTPROPERTIES']['PROP'];
        if ($newValues['ENDPOINTPROPERTIES']['NAME'] == null || $newValues['ENDPOINTPROPERTIES']['VALUE'] == null) {
            show_view('error.php', "A property name and value must be provided.");
            die;
        }
        $property = \Factory::getServiceService()->getEndpointProperty($propID);
        $service = $property->getParentEndpoint()->getService();
        \Factory::getServiceService()->editEndpointProperty($service, $user, $property, $newValues);
        $params['endpointid'] = $endpointID;
        show_view('service/endpoint_property_updated.php', $params);
    } catch (Exception $e) {
        show_view('error.php', $e->getMessage());
        die;
    }
}
Esempio n. 13
0
/**
 * Draw the edit site form. 
 * @param \User $user
 * @throws \Exception
 */
function draw(\User $user = null)
{
    if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
        throw new Exception("An id must be specified");
    }
    $id = $_REQUEST['id'];
    $serv = \Factory::getServiceService();
    $se = $serv->getService($id);
    if (count(Factory::getServiceService()->authorizeAction(\Action::EDIT_OBJECT, $se, $user)) == 0) {
        throw new \Exception("You do not have permission over {$se}.");
    }
    $configservice = \Factory::getConfigService();
    //get parent scope ids to generate warning message in view
    $params["parentScopeIds"] = array();
    foreach ($se->getParentSite()->getScopes() as $scope) {
        $params["parentScopeIds"][] = $scope->getId();
    }
    $params['se'] = $se;
    $params['serviceTypes'] = $serv->getServiceTypes();
    $params['scopes'] = \Factory::getScopeService()->getScopesSelectedArray($se->getScopes());
    $params['numberOfScopesRequired'] = $configservice->getMinimumScopesRequired('service');
    show_view('service/edit_service.php', $params);
}
Esempio n. 14
0
function drawSEs()
{
    define("RECORDS_PER_PAGE", 30);
    require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
    $seServ = \Factory::getServiceService();
    $exServ = \Factory::getExtensionsService();
    $startRecord = 1;
    if (isset($_REQUEST['record'])) {
        $startRecord = $_REQUEST['record'];
    }
    // Validation, ensure start record >= 1
    if ($startRecord < 1) {
        $startRecord = 1;
    }
    $searchTerm = "";
    if (!empty($_REQUEST['searchTerm'])) {
        $searchTerm = $_REQUEST['searchTerm'];
    }
    //strip leading and trailing whitespace off search term
    $searchTerm = strip_tags(trim($searchTerm));
    if (1 === preg_match("/[';\"]/", $searchTerm)) {
        throw new Exception("Invalid char in search term");
    }
    $serviceType = "";
    if (isset($_REQUEST['serviceType'])) {
        $serviceType = $_REQUEST['serviceType'];
    }
    $production = "";
    if (isset($_REQUEST['production'])) {
        $production = $_REQUEST['production'];
    }
    $monitored = "";
    if (isset($_REQUEST['monitored'])) {
        $monitored = $_REQUEST['monitored'];
    }
    $scope = "";
    if (isset($_REQUEST['scope'])) {
        $scope = $_REQUEST['scope'];
    }
    $ngi = "";
    if (isset($_REQUEST['ngi'])) {
        $ngi = $_REQUEST['ngi'];
    }
    //must be done before the if certstatus in the block that sets $certStatus
    $showClosed = false;
    if (isset($_REQUEST['showClosed'])) {
        $showClosed = true;
    }
    $servKeyNames = "";
    if (isset($_REQUEST['servKeyNames'])) {
        $servKeyNames = $_REQUEST['servKeyNames'];
    }
    $servKeyValues = "";
    if (isset($_REQUEST['selectedServKeyValue'])) {
        $servKeyValues = $_REQUEST['selectedServKeyValue'];
    }
    $certStatus = "";
    if (!empty($_REQUEST['certificationStatus'])) {
        $certStatus = $_REQUEST['certificationStatus'];
        //set show closed as true if production status selected is 'closed' - otherwise
        // there will be no results
        if ($certStatus == 'Closed') {
            $showClosed = true;
        }
    }
    $thisPage = 'index.php?Page_Type=Services';
    if ($serviceType != "") {
        $thisPage .= '&serviceType=' . $serviceType;
    }
    if ($searchTerm != "") {
        $thisPage .= '&searchTerm=' . $searchTerm;
    }
    if ($production != "") {
        $thisPage .= '&production=' . $production;
    }
    if ($monitored != "") {
        $thisPage .= '&monitored=' . $monitored;
    }
    if ($scope != "") {
        $thisPage .= '&scope=' . $scope;
    }
    if ($ngi != "") {
        $thisPage .= '&ngi=' . $ngi;
    }
    if ($certStatus != "") {
        $thisPage .= '&certStatus=' . $certStatus;
    }
    if ($showClosed != "") {
        $thisPage .= '&showClosed=' . $showClosed;
    }
    if ($servKeyNames != "") {
        $thisPage .= '&servKeyNames=' . $servKeyNames;
    }
    if ($servKeyValues != "") {
        $thisPage .= '&servKeyValues=' . $servKeyValues;
    }
    if ($searchTerm != null || $searchTerm != "") {
        if (substr($searchTerm, 0, 1) != '%') {
            $searchTerm = '%' . $searchTerm;
        }
        if (substr($searchTerm, -1) != '%') {
            $searchTerm = $searchTerm . '%';
        }
    }
    $numResults = $seServ->getSesCount($searchTerm, $serviceType, $production, $monitored, $scope, $ngi, $certStatus, $showClosed, $servKeyNames, $servKeyValues, null, null, false);
    $firstLink = $thisPage . "&record=1";
    // Set the "previous" link
    if ($startRecord > RECORDS_PER_PAGE) {
        // Not showing the first page of results so enable the previous link
        $previousLink = $thisPage . "&record=" . ($startRecord - RECORDS_PER_PAGE);
    } else {
        // First page of results, disable previous button
        $previousLink = $thisPage . "&record=" . 0;
    }
    // Set the "Next" link
    // not the last page of results, normal next link
    if ($numResults - $startRecord > RECORDS_PER_PAGE) {
        $nextLink = $thisPage . "&record=" . ($startRecord + RECORDS_PER_PAGE);
    } else {
        // last page of results, disable next link
        $nextLink = $thisPage . '&record=' . ($numResults - RECORDS_PER_PAGE + 1);
    }
    $lastLink = $thisPage . "&record=" . ($numResults + 1 - RECORDS_PER_PAGE);
    // $startRecord + RECORDS_PER_PAGE "-1" because record 1 in the web portal == record 0 from DB
    $ses = $seServ->getSes($searchTerm, $serviceType, $production, $monitored, $scope, $ngi, $certStatus, $showClosed, $servKeyNames, $servKeyValues, $startRecord - 1, RECORDS_PER_PAGE, false);
    $endRecord = $startRecord + RECORDS_PER_PAGE - 1;
    /* Due to differences in counting, startRecord is still set to 1
     * even if there are zero results. If this is the case it's
     * zero here to display accurately in the portal.  */
    if (count($ses) == 0) {
        $startRecord = 0;
    }
    /* Doctrine will provide keynames that are the same even when selecting distinct becase the object
     * is distinct even though the name is not unique. To avoid showing the same name repeatdly in the filter
     * we will load all the keynames into an array before making it unique
     */
    $keynames = array();
    foreach ($exServ->getServiceExtensionsKeyNames() as $extension) {
        $keynames[] = $extension->getKeyName();
    }
    $keynames = array_unique($keynames);
    $serv = \Factory::getSiteService();
    $params['scopes'] = \Factory::getScopeService()->getScopes();
    $params['serviceTypes'] = $seServ->getServiceTypes();
    $params['servKeyNames'] = $keynames;
    $params['selectedServiceType'] = $serviceType;
    $params['searchTerm'] = $searchTerm;
    $params['services'] = $ses;
    $params['totalServices'] = $numResults;
    $params['startRecord'] = $startRecord;
    $params['endRecord'] = $endRecord;
    $params['firstLink'] = $firstLink;
    $params['previousLink'] = $previousLink;
    $params['nextLink'] = $nextLink;
    $params['lastLink'] = $lastLink;
    $params['ngis'] = \Factory::getNgiService()->getNGIs();
    $params['certStatuses'] = $serv->getCertStatuses();
    $params['showClosed'] = $showClosed;
    $params['selectedProduction'] = $production;
    $params['selectedMonitored'] = $monitored;
    $params['selectedScope'] = $scope;
    $params['selectedNgi'] = $ngi;
    $params['selectedClosed'] = $showClosed;
    $params['selectedCertStatus'] = $certStatus;
    $params['selectedServKeyNames'] = $servKeyNames;
    $params['selectedServKeyValue'] = $servKeyValues;
    show_view("service/view_all.php", $params, "Services");
}
Esempio n. 15
0
/**
 *  Draw the add service form
 * @param \User $user current user 
 * @return null
 */
function draw($user)
{
    if (is_null($user)) {
        throw new Exception("Unregistered users can't add a service .");
    }
    /* Optional site parameter is set if a user clicked
     * "add SE to this site" on the view site page */
    $site = null;
    if (isset($_REQUEST['siteId'])) {
        $site = \Factory::getSiteService()->getSite($_REQUEST['siteId']);
        if ($site == null) {
            throw new Exception('Invalid site');
        }
        if (count(\Factory::getSiteService()->authorizeAction(\Action::SITE_ADD_SERVICE, $site, $user)) == 0) {
            throw new Exception('You do not have permission to add a service to this site');
        }
    }
    // Add sites which user has required action permission to array.
    $allUserSites = \Factory::getUserService()->getSitesFromRoles($user);
    $sites = array();
    foreach ($allUserSites as $s) {
        if (count(\Factory::getSiteService()->authorizeAction(\Action::SITE_ADD_SERVICE, $s, $user)) != 0) {
            $sites[] = $s;
        }
    }
    //For admin users, return all sites instead.
    if ($user->isAdmin()) {
        $sites = \Factory::getSiteService()->getSitesBy();
    }
    if (count($sites) == 0 and !$user->isAdmin()) {
        throw new Exception("You need at least one NGI or Site level role to add a new service.");
    }
    $serviceTypes = \Factory::getServiceService()->getServiceTypes();
    //If a site has been specified get scopes wit that sites scopes selected, otherwise get the default
    if (!is_null($serviceTypes) && $site instanceof \Site) {
        $scopes = \Factory::getScopeService()->getScopesSelectedArray($site->getScopes());
    } else {
        $scopes = \Factory::getScopeService()->getDefaultScopesSelectedArray();
    }
    //get the number of scopes that we require
    $numberScopesRequired = \Factory::getConfigService()->getMinimumScopesRequired('service');
    // remove the deprecated CE type (temp hack)
    foreach ($serviceTypes as $key => $st) {
        if ($st->getName() == "CE") {
            unset($serviceTypes[$key]);
        }
    }
    $params = array('sites' => $sites, 'serviceTypes' => $serviceTypes, 'scopes' => $scopes, 'site' => $site, 'numberOfScopesRequired' => $numberScopesRequired);
    //Check that there is at least one Site available before allowing a user to add a service.
    if ($params['sites'] == null) {
        show_view('error.php', "GocDB requires one or more Sites to be able to add a service.");
    }
    show_view("service/add_service.php", $params);
}
Esempio n. 16
0
/**
 * Draws a form to add a new downtime
 * @param \User $user current user 
 * @return null
 */
function draw(\User $user = null)
{
    if (is_null($user)) {
        throw new Exception("Unregistered users can't add a downtime.");
    }
    $nowUtcDateTime = new \DateTime(null, new \DateTimeZone("UTC"));
    //$twoDaysAgoUtcDateTime = $nowUtcDateTime->sub(\DateInterval::createFromDateString('2 days'));
    //$twoDaysAgoUtc = $twoDaysAgoUtcDateTime->format('d/m/Y H:i'); //e.g.  02/10/2013 13:20
    // URL mapping
    // Return the specified site's timezone label and the offset from now in UTC
    // Used in ajax requests for display purposes
    if (isset($_GET['siteid_timezone']) && is_numeric($_GET['siteid_timezone'])) {
        $site = \Factory::getSiteService()->getSite($_GET['siteid_timezone']);
        if ($site != null) {
            $siteTzId = $site->getTimeZoneId();
            if (!empty($siteTzId)) {
                $nowInTargetTz = new \DateTime(null, new \DateTimeZone($siteTzId));
                $offsetInSecsFromUtc = $nowInTargetTz->getOffset();
            } else {
                $siteTzId = 'UTC';
                $offsetInSecsFromUtc = 0;
                // assume 0 (no offset from UTC)
            }
            $timezoneId_Offset = array($siteTzId, $offsetInSecsFromUtc);
            die(json_encode($timezoneId_Offset));
        }
        die(json_encode(array('UTC', 0)));
    } else {
        if (isset($_GET['site'])) {
            $site = \Factory::getSiteService()->getSite($_GET['site']);
            //old way: \Factory::getSiteService()->edit Authorization($site, $user);
            if (count(\Factory::getSiteService()->authorizeAction(\Action::EDIT_OBJECT, $site, $user)) == 0) {
                throw new \Exception("You don't have permission over {$site}");
            }
            $ses = $site->getServices();
            $params = array('ses' => $ses, 'nowUtc' => $nowUtcDateTime->format('H:i T'), 'selectAll' => true);
            show_view("downtime/add_downtime.php", $params);
            die;
        } else {
            if (isset($_GET['se'])) {
                $se = \Factory::getServiceService()->getService($_GET['se']);
                $site = \Factory::getSiteService()->getSite($se->getParentSite()->getId());
                if (count(\Factory::getServiceService()->authorizeAction(\Action::EDIT_OBJECT, $se, $user)) == 0) {
                    throw new \Exception("You do not have permission over {$se}.");
                }
                //$ses = array($se);
                $ses = $site->getServices();
                $params = array('ses' => $ses, 'nowUtc' => $nowUtcDateTime->format('H:i T'), 'selectAll' => true);
                show_view("downtime/add_downtime.php", $params);
                die;
            } else {
                $ses = array();
                if ($user->isAdmin()) {
                    //If a user is an admin, return all SEs instead
                    $ses = \Factory::getServiceService()->getAllSesJoinParentSites();
                } else {
                    //$allSites = \Factory::getUserService()->getSitesFromRoles($user);
                    // Get all ses where the user has a GRANTED role over one of its
                    // parent OwnedObjects (includes Site and NGI but not currently Project)
                    $sesAll = \Factory::getRoleService()->getReachableServicesFromOwnedObjectRoles($user);
                    // drop the ses where the user does not have edit permissions over
                    foreach ($sesAll as $se) {
                        if (count(\Factory::getServiceService()->authorizeAction(\Action::EDIT_OBJECT, $se, $user)) > 0) {
                            $ses[] = $se;
                        }
                    }
                }
                if (empty($ses)) {
                    throw new Exception("You don't hold a role over a NGI " . "or site with child services.");
                }
                $params = array('ses' => $ses, 'nowUtc' => $nowUtcDateTime->format('H:i T'));
                show_view("downtime/add_downtime.php", $params);
                die;
            }
        }
    }
}
Esempio n. 17
0
/**
 * 
 * @param \User $user current user
 * @throws Exception
 */
function submit(\User $user = null)
{
    //Check if this is a confirmed submit or intial submit
    $confirmed = $_POST['CONFIRMED'];
    if ($confirmed == true) {
        //Downtime is confirmed, submit it
        $downtimeInfo = json_decode($_POST['newValues'], TRUE);
        $serv = \Factory::getDowntimeService();
        $dt = $serv->getDowntime($downtimeInfo['DOWNTIME']['EXISTINGID']);
        unset($downtimeInfo['DOWNTIME']['EXISTINGID']);
        unset($downtimeInfo['isEdit']);
        $params['dt'] = $serv->editDowntime($dt, $downtimeInfo, $user);
        show_view("downtime/edited_downtime.php", $params);
    } else {
        //Show user confirmation screen with their input
        $downtimeInfo = getDtDataFromWeb();
        //Need to sort the impacted_ids into impacted services and impacted endpoints
        $impactedids = $downtimeInfo['IMPACTED_IDS'];
        $services = array();
        $endpoints = array();
        //For each impacted id sort between endpoints and services using the prepended letter
        foreach ($impactedids as $id) {
            if (strpos($id, 's') !== FALSE) {
                //This is a service id
                $services[] = str_replace('s', '', $id);
                //trim off the identifying char before storing in array
            } else {
                //This is an endpoint id
                $endpoints[] = str_replace('e', '', $id);
                //trim off the identifying char before storing in array
            }
        }
        unset($downtimeInfo['IMPACTED_IDS']);
        //Delete the unsorted Ids from the downtime info
        $downtimeInfo['Impacted_Endpoints'] = $endpoints;
        $serv = \Factory::getServiceService();
        /** For endpoint put into downtime we want the parent service also. If a user has selected
         * endpoints but not the parent service here we will add the service to maintain the link beteween
         * a downtime having both the service and the endpoint.
         */
        foreach ($downtimeInfo['Impacted_Endpoints'] as $endpointIds) {
            $endpoint = $serv->getEndpoint($endpointIds);
            $services[] = $endpoint->getService()->getId();
        }
        //Remove any duplicate service ids and store the array of ids
        $services = array_unique($services);
        //Assign the impacted services and endpoints to their own arrays for us by the addDowntime method
        $downtimeInfo['Impacted_Services'] = $services;
        //Pass the edit variable so the confirm_add view works as the confirm edit view.
        $downtimeInfo['isEdit'] = true;
        show_view("downtime/confirm_add_downtime.php", $downtimeInfo);
    }
}
Esempio n. 18
0
}
?>
    	</ul>
    </li>
    <?php 
if (count($endpoints > 1)) {
    echo "<li><b>Affecting Endpoints:</b>";
} else {
    echo "<li><b>Affecting Endpoint:</b>";
}
?>
     
    	<ul>
    	<?php 
foreach ($endpoints as $id) {
    $endpoint = \Factory::getServiceService()->getEndpoint($id);
    if ($endpoint->getName() != '') {
        $name = xssafe($endpoint->getName());
    } else {
        $name = xssafe("myEndpoint");
    }
    echo "<li>" . $name . "</li>";
}
?>
    	</ul>
    </li>
 	</ul>
 	<!-- Echo out a page type of edit or add downtime depending on type.  -->
 	<?php 
if (!$edit) {
    ?>
Esempio n. 19
0
/**
 * Moves the service to the new site and then display the success view
 * @param type $movementDetails array containing the SEP and the site it is to be moved to
 * @return null
 */
function submitMoveSEP($movementDetails)
{
    //Check that some services have been specified
    if (!array_key_exists('Services', $movementDetails)) {
        throw new Exception('Please select one or more Services to move.');
    }
    //Get submitted data
    $newSite_id = $movementDetails['NewSite'];
    $service_ids = $movementDetails['Services'];
    //Convert Site id into Site object
    $newSite = \Factory::getSiteService()->getSite($newSite_id);
    //Get the users details
    $dn = Get_User_Principle();
    $user = \Factory::getUserService()->getUserByPrinciple($dn);
    $serv = \Factory::getServiceService();
    //create an array for the SEPs we can use to display the results
    // of the site move to the user
    $services = new ArrayCollection();
    //If services have been subitted, move them. Else throw exception
    //
    try {
        foreach ($service_ids as $service_id) {
            $serviceInstance = $serv->getService($service_id);
            $serv->moveService($serviceInstance, $newSite, $user);
            $services[] = $serviceInstance;
        }
    } catch (\Exception $e) {
        show_view('error.php', $e->getMessage());
        die;
    }
    //show success view
    $params['NewSite'] = $newSite;
    $params['Services'] = $services;
    show_view("admin/moved_service_end_point.php", $params);
}
Esempio n. 20
0
/**
 * Adds service to a service group
 * @global array $_REQUEST only set if the browser has sent parameters
 * @param \User $user current user
 * @return null
 */
function submit(\User $user = null)
{
    if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
        throw new Exception("An id must be specified");
    }
    $sg = \Factory::getServiceGroupService()->getServiceGroup($_REQUEST['id']);
    $ses = array();
    if (empty($_REQUEST['endpointIds'])) {
        show_view('error.php', 'No service selected');
        die;
    }
    foreach ($_REQUEST['endpointIds'] as $seId) {
        $ses[] = \Factory::getServiceService()->getService($seId);
    }
    try {
        \Factory::getServiceGroupService()->addServices($sg, $ses, $user);
        $params = array('sg' => $sg);
        show_view("service_group/submit_service_group_ses.php", $params);
    } catch (Exception $e) {
        show_view('error.php', $e->getMessage());
        die;
    }
}