Author: : Tracy Lauren for Heimdall Networks April, 2012
Example #1
0
 function __construct($city_code = 'Palaiseau', $lang = 'fr')
 {
     $prefix_images = 'https://www.google.com/';
     $url = 'http://www.google.com/ig/api?weather=' . urlencode($city_code) . '&hl=' . $lang;
     $api = new API($url);
     $xml = simplexml_load_string($api->response());
     if ($xml === false) {
         throw new Exception("Unable to read Google Weather data");
     }
     if (isset($xml->weather->problem_cause)) {
         throw new Exception($xml->weather->problem_cause);
     }
     if (isset($xml->weather->current_conditions)) {
         $current_conditions = $xml->weather->current_conditions;
         $this->today = new WeatherConditions();
         $this->today->label = isset($current_conditions->condition) ? $this->getAttrData($current_conditions->condition) : null;
         $this->today->temperature = isset($current_conditions->temp_c) ? $this->getAttrData($current_conditions->temp_c) : null;
         $icon = isset($current_conditions->icon) ? $this->getAttrData($current_conditions->icon) : null;
         $this->today->icon = $icon ? $prefix_images . $icon : null;
     } else {
         $this->today = null;
     }
     $this->forecasts = array();
     foreach ($xml->weather->forecast_conditions as $aforecast) {
         $forecast = new WeatherConditions();
         $forecast->label = isset($aforecast->condition) ? $this->getAttrData($aforecast->condition) : null;
         $forecast->low = isset($aforecast->low) ? $this->getAttrData($aforecast->low) : null;
         $forecast->high = isset($aforecast->high) ? $this->getAttrData($aforecast->high) : null;
         $icon = isset($current_conditions->icon) ? $this->getAttrData($current_conditions->icon) : null;
         $forecast->icon = $icon ? $prefix_images . $icon : null;
         $forecast->day = isset($aforecast->day_of_week) ? $this->getAttrData($aforecast->day_of_week) : null;
         $this->forecasts[] = $forecast;
     }
 }
Example #2
0
 private static function response()
 {
     try {
         $api = new API(self::$url, false);
         $xml = simplexml_load_string(utf8_decode($api->response()));
         if ($xml) {
             $response = $xml->concerts->children();
             $response2 = $xml->concerts_later->children();
         } else {
             $response = array();
         }
         $return = array();
         foreach ($response as $r) {
             //withpic true signifie avec les photos, sinon false. cela depend de la date de concerts <= 30 ou pas
             $return[] = array('withpic' => "true", 'group' => (string) $r->nom_groupe, 'link_group' => (string) $r->lien_nom_groupe, 'place' => (string) $r->nom_salle, 'link_place' => (string) $r->lien_nom_salle, 'date' => (string) $r->date, 'price' => (string) $r->prix . ' euro', 'pict' => (string) $r->img_groupe, 'link_pict' => (string) $r->lien_img_groupe);
         }
         foreach ($response2 as $r) {
             //withpic true signifie avec les photos, sinon false. cela depend de la date de concerts <= 30 ou pas
             $return[] = array('withpic' => "false", 'group' => (string) $r->nom_groupe, 'link_group' => (string) $r->lien_nom_groupe, 'place' => (string) $r->nom_salle, 'link_place' => (string) $r->lien_nom_salle, 'date' => (string) $r->date, 'price' => (string) $r->prix . ' euro', 'pict' => (string) $r->img_groupe, 'link_pict' => (string) $r->lien_img_groupe);
         }
         return $return;
     } catch (Exception $e) {
         return array();
     }
 }
 public function action_admin_bar_menu($wp_admin_bar)
 {
     $api = new API();
     $name = $api->get_site_name();
     $site_id = $api->get_site_id();
     $env = $this->get_environment();
     $title = '<img src="' . esc_url(plugins_url('assets/img/pantheon-fist-color.svg', PANTHEON_HUD_ROOT_FILE)) . '" />';
     $bits = array();
     if ($name) {
         $bits[] = $name;
     }
     $bits[] = $env;
     $title .= ' ' . esc_html(strtolower(implode(':', $bits)));
     $wp_admin_bar->add_node(array('id' => 'pantheon-hud', 'href' => false, 'title' => $title));
     $env_admins = '';
     # TODO: List envs from API to include Multidev.
     foreach (array('dev', 'test', 'live') as $e) {
         $url = $api->get_primary_environment_url($e);
         if ($url) {
             $env_admins .= '<a target="_blank" href="' . esc_url(rtrim($url) . '/wp-admin/') . '">' . esc_html($e) . '</a> | ';
         }
     }
     if (!empty($env_admins)) {
         $wp_admin_bar->add_node(array('id' => 'pantheon-hud-wp-admin-links', 'parent' => 'pantheon-hud', 'href' => false, 'title' => '<em>wp-admin links</em><br />' . rtrim($env_admins, ' |')));
     }
     $environment_details = $api->get_environment_details();
     if ($environment_details) {
         $details_html = array();
         if (isset($environment_details['web']['appserver_count'])) {
             $pluralize = $environment_details['web']['appserver_count'] > 1 ? 's' : '';
             $web_detail = $environment_details['web']['appserver_count'] . ' app container' . $pluralize;
             if (isset($environment_details['web']['php_version'])) {
                 $web_detail .= ' running ' . $environment_details['web']['php_version'];
             }
             $details_html[] = $web_detail;
         }
         if (isset($environment_details['database']['dbserver_count'])) {
             $pluralize = $environment_details['database']['dbserver_count'] > 1 ? 's' : '';
             $db_detail = $environment_details['database']['dbserver_count'] . ' db container' . $pluralize;
             if (isset($environment_details['database']['read_replication_enabled'])) {
                 $db_detail .= ' with ' . ($environment_details['database']['read_replication_enabled'] ? 'replication enabled' : 'replication disabled');
             }
             $details_html[] = $db_detail;
         }
         if (!empty($details_html)) {
             $details_html = '<em>' . esc_html__('Environment Details', 'pantheon-hud') . '</em><br /> - ' . implode('<br /> - ', $details_html);
             $wp_admin_bar->add_node(array('id' => 'pantheon-hud-environment-details', 'parent' => 'pantheon-hud', 'title' => $details_html));
         }
     }
     if ($name && $env) {
         $wp_cli_stub = sprintf('terminus wp --site=%s --env=%s', $name, $env);
         $wp_admin_bar->add_node(array('id' => 'pantheon-hud-wp-cli-stub', 'parent' => 'pantheon-hud', 'title' => '<em>' . esc_html__('WP-CLI via Terminus', 'pantheon-hud') . '</em><br /><input value="' . esc_attr($wp_cli_stub) . '">'));
     }
     if ($site_id && $env) {
         $dashboard_link = sprintf('https://dashboard.pantheon.io/sites/%s#%s/code', $site_id, $env);
         $wp_admin_bar->add_node(array('id' => 'pantheon-hud-dashboard-link', 'parent' => 'pantheon-hud', 'href' => $dashboard_link, 'title' => esc_html__('Visit Pantheon Dashboard', 'pantheon-hud'), 'meta' => array('target' => '_blank')));
     }
 }
 function parseLayout()
 {
     global $CONFIG;
     $api = new API(&$this->pdo);
     if (!$this->layoutAlreadyParsed && $this->layoutReadyForParsing) {
         require_once $CONFIG["ContentDir"] . "layouts/" . $this->currentLayoutName . ".php";
         $this->pdo->insertIntoBodyBuffer($api->getBufferContent());
     }
 }
Example #5
0
 public function index($data)
 {
     $api = new API($_SERVER["REQUEST_URI"]);
     if (isset($_SESSION["user"])) {
         $this->getDate();
     } else {
         return array("page" => $api->user->auth(), "path" => "/content/" . $api->template . "/", "menu" => $api->getMenu(), "active" => $api->link);
     }
 }
 /**
  * Validate the provided API key.
  */
 public function checkAuth()
 {
     $api = new API();
     $api->key = $_GET['key'];
     try {
         $api->validate_key();
     } catch (Exception $e) {
         json_error($e->getMessage());
         die;
     }
 }
Example #7
0
 protected function loadFile($url)
 {
     $api = new API($url, false);
     $photos = simplexml_load_string(utf8_decode($api->response()));
     //charset fix
     $res = array();
     foreach ($photos as $photo) {
         $res[] = array("urlPage" => "http://pix/photo/" . $photo->id, "imgThumb" => "http://pix/media/photo/thumb/" . $photo->author->id . "/" . $photo->link, "imgFull" => "http://pix/media/photo/view/" . $photo->author->id . "/" . $photo->link, "title" => htmlspecialchars($photo->title . " par " . $photo->author->name . " " . $photo->author->surname), "text" => htmlspecialchars($photo->title . " par " . $photo->author->name . " " . $photo->author->surname) . "<br/><a href='http://pix/photo/" . $photo->id . "'>voir dans piX</a>");
     }
     return $res;
 }
 /**
  * Function send data to DPD API about carrier pickup
  */
 private function sendDataToCarrier()
 {
     $api = new API();
     $parameters = array('action' => 'dpdis/pickupOrdersSave', 'payerName' => Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_ADDRESS_NAME'), 'senderName' => Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_ADDRESS_NAME'), 'senderAddress' => Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_ADDRESS_STREET'), 'senderPostalCode' => Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_ADDRESS_ZIP'), 'senderCountry' => $this->context->language->iso_code, 'senderCity' => Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_ADDRESS_CITY'), 'senderContact' => Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_ADDRESS_NAME'), 'senderPhone' => Configuration::get(DynamicParcelDistribution::CONST_PREFIX . 'PICKUP_ADDRESS_PHONE'), 'parcelsCount' => Tools::getValue('Po_parcel_qty'), 'palletsCount' => Tools::getValue('Po_pallet_qty'), 'nonStandard' => Tools::getValue('Po_remark'));
     $responce = $api->postData($parameters);
     if (strip_tags($responce) == 'DONE') {
         $this->context->cookie->__set('redirect_success', Tools::displayError($this->l('Call courier success')));
     } else {
         $this->context->cookie->__set('redirect_errors', Tools::displayError($this->l('Call courier error: ' . strip_tags($responce))));
     }
     Tools::redirectAdmin('?controller=AdminOrders&token=' . Tools::getValue('parentToken'));
 }
 /**
  * Returns the parent categories.
  */
 public function get_parents()
 {
     $data = $this->data;
     if (empty($data[Parser::INDEX_PARENT_SPEC])) {
         return array();
     }
     // Okay. We first grab all of our categories.
     $categories = array();
     foreach ($data[Parser::INDEX_PARENT_SPEC] as $category) {
         $categories[] = $this->api->get_category($category['value']);
     }
     return $categories;
 }
function get_Categories($subj_ID, $Types)
{
    $API = new API();
    $found = "";
    if (isset($API->get_all_category_for_subject($subj_ID, $Types)['result'])) {
        $Materials = $API->get_all_category_for_subject($subj_ID, $Types)['result'];
        foreach ($Materials as $material) {
            $found = $found . '<li><a href="#"><strong  style="color: dimgray">' . $material['category'] . '</strong></a>' . get_Material_Lists($subj_ID, $material['category']) . '</li>';
        }
        $found = '<ul>' . $found . '</ul>';
    }
    return $found;
}
Example #11
0
 public function render($template, $data=true)
 {   
     $data=$this->createView($data);
     return $this->m->render("{{# render}}$template{{/ render}}",[
         'session'=>[
             'debug'=>DEBUG,
             'hc'=> 
                 $this->api->estAuthentifier()?
                 $this->api->compteConnecte()->contraste:
                 false,
             'pages'=>$this->api->API_pages_lister(),
             'compte'=>$this->api->compteConnecte(),
             'estAuthentifier'=>$this->api->estAuthentifier(),
             'estAdministrateur'=>$this->api->estAdmin(),
             'estDesactive'=>$this->api->estDésactivé(),
             'estLibreService'=>$this->api->estLibreService(),
             'estNouveau'=>$this->api->estNouveau(),
             //'estPanier'=>$this->api->estPanier(),
             //'estPremium'=>$this->api->estPremium(),
             'peutCommander'=>$this->api->peutCommander(),
             'peutModifierCommande'=>function($value){
                 return $this->api->peutModifierCommande($value);
             }
         ],
         'data'=>$data
     ]);
     
 }
 /**
  * Import template screens.
  *
  * @param array $allScreens
  *
  * @return void
  */
 public function import(array $allScreens)
 {
     $screensToCreate = array();
     $screensToUpdate = array();
     foreach ($allScreens as $template => $screens) {
         // TODO: select all at once out of loop
         $dbScreens = DBselect('SELECT s.screenid,s.name FROM screens s WHERE' . ' s.templateid=' . zbx_dbstr($this->referencer->resolveTemplate($template)) . ' AND ' . dbConditionString('s.name', array_keys($screens)));
         while ($dbScreen = DBfetch($dbScreens)) {
             $screens[$dbScreen['name']]['screenid'] = $dbScreen['screenid'];
         }
         foreach ($screens as $screen) {
             $screen = $this->resolveScreenReferences($screen);
             if (isset($screen['screenid'])) {
                 $screensToUpdate[] = $screen;
             } else {
                 $screen['templateid'] = $this->referencer->resolveTemplate($template);
                 $screensToCreate[] = $screen;
             }
         }
     }
     if ($this->options['templateScreens']['createMissing'] && $screensToCreate) {
         API::TemplateScreen()->create($screensToCreate);
     }
     if ($this->options['templateScreens']['updateExisting'] && $screensToUpdate) {
         API::TemplateScreen()->update($screensToUpdate);
     }
 }
Example #13
0
 public function put_login()
 {
     $auth = API::post(array('auth', 'login'), Input::all());
     if ($auth->code == 400) {
         return Redirect::to(prefix('admin') . 'auth/login')->with('errors', new Messages($auth->get()))->with_input('except', array());
     }
 }
 public function create()
 {
     $companies = Company::where("user_id", Auth::user()->id)->get();
     if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) {
         $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_admin->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
         $this->data['operators'] = API::getDepartmentOperators($department_admin->department_id);
     } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) {
         $department_admin = OperatorsDepartment::where('user_id', Auth::user()->id)->first();
         $this->data['department'] = Department::where('id', $department_admin->department_id)->first();
         $this->data["company"] = Company::where('id', $this->data['department']->company_id)->first();
         $this->data['operator'] = User::where('id', $department_admin->user_id)->first();
     } else {
         $this->data['departments'] = [];
         $this->data['operators'] = [];
         if (sizeof($companies) > 0) {
             $company_departments = API::getCompanyDepartments($companies[0]->id);
             if (sizeof($company_departments) > 0) {
                 $this->data['departments'] = $company_departments;
                 $this->data['operators'] = API::getDepartmentOperators($company_departments[0]->id);
             }
         }
         $this->data["companies"] = $companies;
     }
     return View::make('canned_messages.create', $this->data);
 }
Example #15
0
 public function testEmptyTag()
 {
     $json = API::getItemTemplate("book");
     $json->tags[] = array("tag" => "", "type" => 1);
     $response = API::postItem($json);
     $this->assert400($response);
 }
Example #16
0
 public static function checkAuthentication($sessionId)
 {
     try {
         if ($sessionId !== null) {
             self::$data = API::User()->checkAuthentication(array($sessionId));
         }
         if ($sessionId === null || empty(self::$data)) {
             self::setDefault();
             self::$data = API::User()->login(array('user' => ZBX_GUEST_USER, 'password' => '', 'userData' => true));
             if (empty(self::$data)) {
                 clear_messages(1);
                 throw new Exception();
             }
             $sessionId = self::$data['sessionid'];
         }
         if (self::$data['gui_access'] == GROUP_GUI_ACCESS_DISABLED) {
             throw new Exception();
         }
         self::setSessionCookie($sessionId);
         return $sessionId;
     } catch (Exception $e) {
         self::setDefault();
         return false;
     }
 }
Example #17
0
 public static function checkAuthentication($sessionid)
 {
     try {
         if ($sessionid !== null) {
             self::$data = API::User()->checkAuthentication($sessionid);
         }
         if ($sessionid === null || empty(self::$data)) {
             self::setDefault();
             self::$data = API::User()->login(array('user' => ZBX_GUEST_USER, 'password' => '', 'userData' => true));
             if (empty(self::$data)) {
                 clear_messages(1);
                 throw new Exception();
             }
             $sessionid = self::$data['sessionid'];
         }
         if (self::$data['gui_access'] == GROUP_GUI_ACCESS_DISABLED) {
             error(_('GUI access disabled.'));
             throw new Exception();
         }
         zbx_setcookie('zbx_sessionid', $sessionid, self::$data['autologin'] ? time() + SEC_PER_DAY * 31 : 0);
         return true;
     } catch (Exception $e) {
         self::setDefault();
         return false;
     }
 }
Example #18
0
File: API.php Project: jneivil/api
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #19
0
 public function action_render()
 {
     $availableChannelTypesJson = API::channel_api()->list_available_channel_types();
     $availableChannelTypes = json_decode($availableChannelTypesJson);
     $channelTypesArray = $availableChannelTypes->data->channelTypes;
     $channelsJson = API::channel_api()->get_all_channels();
     $channels = json_decode($channelsJson);
     $channelsArray = $channels->data->channels;
     $return;
     $return->channelTypes = array();
     foreach ($channelTypesArray as $channelType) {
         $t->type = $channelType->type;
         $t->subTypes = array();
         foreach ($channelType->subTypes as $subType) {
             $st->type = $subType;
             $st->sources = array();
             foreach ($channelsArray as $source) {
                 if ($source->type != $t->type || $source->subType != $st->type) {
                     continue;
                 }
                 $c->name = $source->name;
                 $c->id = $source->id;
                 $st->sources[] = $c;
                 unset($c);
             }
             $t->subTypes[] = $st;
             unset($st);
         }
         $return->channelTypes[] = $t;
         unset($t);
     }
     $this->template->channels = $return;
 }
Example #20
0
function getImageByIdent($ident)
{
    zbx_value2array($ident);
    if (!isset($ident['name'])) {
        return 0;
    }
    static $images;
    if (is_null($images)) {
        $images = array();
        $dbImages = API::Image()->get(array('output' => array('imageid', 'name'), 'nodeids' => get_current_nodeid(true)));
        foreach ($dbImages as $image) {
            if (!isset($images[$image['name']])) {
                $images[$image['name']] = array();
            }
            $nodeName = get_node_name_by_elid($image['imageid'], true);
            if (!is_null($nodeName)) {
                $images[$image['name']][$nodeName] = $image;
            } else {
                $images[$image['name']][] = $image;
            }
        }
    }
    $ident['name'] = trim($ident['name'], ' ');
    if (!isset($images[$ident['name']])) {
        return 0;
    }
    $searchedImages = $images[$ident['name']];
    if (!isset($ident['node'])) {
        return reset($searchedImages);
    } elseif (isset($searchedImages[$ident['node']])) {
        return $searchedImages[$ident['node']];
    } else {
        return 0;
    }
}
Example #21
0
    static function footer()
    {
        $me = API::me();
        ?>
            <script>
                $(document).ready(function() {
                    <?php 
        if ($me) {
            ?>
                    DreamSparkSSO.User = {
                        accountName: "<?php 
            echo $me['userPrincipalName'];
            ?>
",
                        displayName: "<?php 
            echo $me['displayName'];
            ?>
",
                        imgSrc: "<?php 
            echo isset($me['thumbnailPhoto']) ? $me['thumbnailPhoto'] : "";
            ?>
"
                    };
                    <?php 
        }
        ?>
                    DreamSparkSSO.AppLauncher.Load("#header");
                });
            </script>
        </body>
        </html>
        <?php 
    }
 public function delete()
 {
     $_api = new API();
     $_requestHeaders = $_api->manageHeaders(array($this->authHeader));
     $_requestPrepare = $_api->prepareRequest('DELETE');
     $_url = $this->constants['SERVICE_ENTRY_POINT'] . $this->constants['SERVICE_VERSION'] . '/' . $this->typeOfService . '/' . $this->processId . '/delete';
     try {
         $_scc = stream_context_create($_requestPrepare);
         $_response = @file_get_contents($_url, false, $_scc);
     } catch (Exception $e) {
         throw new Exception('HTTP request failed.');
     }
     $http_response_header = isset($http_response_header) ? $http_response_header : array();
     $_validatedResponse = $_api->validateParams('GET_PROCESS_STATUS', $http_response_header, $_response);
     return $_validatedResponse;
 }
Example #23
0
 public function testFactoryReturnAPIObject()
 {
     $api = API::factory($this->key, $this->secret, $this->version);
     $this->assertInstanceOf('Veridu\\API', $api);
     $this->assertInstanceOf('Veridu\\Storage\\StorageInterface', $api->getStorage());
     $this->assertInstanceOf('Veridu\\Signature\\SignatureInterface', $api->getSignature());
 }
Example #24
0
 public static function init()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #25
0
 public function __construct($request)
 {
     parent::__construct($request);
     // Grab the uid from Webauth, API Key lookup, etc
     if (array_key_exists("WEBAUTH_USER", $_SERVER)) {
         $this->uid = htmlentities($_SERVER["WEBAUTH_USER"]);
         $this->webauth = true;
     } else {
         if ($this->api_key) {
             $this->uid = $this->_lookupUser($this->api_key);
             $this->webauth = false;
         } else {
             if (DEBUG) {
                 $this->uid = DEBUG_USER_UID;
                 $this->webauth = true;
             } else {
                 $this->uid = false;
                 $this->webauth = false;
             }
         }
     }
     // Check if the user is a drink admin
     if ($this->uid != false) {
         $this->admin = $this->_isAdmin($this->uid);
     }
 }
 protected function doAction()
 {
     $script = [];
     $this->getInputs($script, ['scriptid', 'name', 'type', 'execute_on', 'command', 'description', 'usrgrpid', 'groupid', 'host_access']);
     $script['confirmation'] = $this->getInput('confirmation', '');
     if ($this->getInput('type', ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT) == ZBX_SCRIPT_TYPE_IPMI && $this->hasInput('commandipmi')) {
         $script['command'] = $this->getInput('commandipmi');
     }
     if ($this->getInput('hgstype', 1) == 0) {
         $script['groupid'] = 0;
     }
     DBstart();
     $result = API::Script()->update($script);
     if ($result) {
         $scriptId = reset($result['scriptids']);
         add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_SCRIPT, 'Name [' . $this->getInput('name', '') . '] id [' . $scriptId . ']');
     }
     $result = DBend($result);
     if ($result) {
         $response = new CControllerResponseRedirect('zabbix.php?action=script.list&uncheck=1');
         $response->setMessageOk(_('Script updated'));
     } else {
         $response = new CControllerResponseRedirect('zabbix.php?action=script.edit&scriptid=' . $this->getInput('scriptid'));
         $response->setFormData($this->getInputAll());
         $response->setMessageError(_('Cannot update script'));
     }
     $this->setResponse($response);
 }
 protected function doAction()
 {
     $sortField = $this->getInput('sort', CProfile::get('web.media_types.php.sort', 'description'));
     $sortOrder = $this->getInput('sortorder', CProfile::get('web.media_types.php.sortorder', ZBX_SORT_UP));
     CProfile::update('web.media_type.php.sort', $sortField, PROFILE_TYPE_STR);
     CProfile::update('web.media_types.php.sortorder', $sortOrder, PROFILE_TYPE_STR);
     $config = select_config();
     $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder];
     // get media types
     $data['mediatypes'] = API::Mediatype()->get(['output' => ['mediatypeid', 'description', 'type', 'smtp_server', 'smtp_helo', 'smtp_email', 'exec_path', 'gsm_modem', 'username', 'status'], 'limit' => $config['search_limit'] + 1, 'editable' => true, 'preservekeys' => true]);
     if ($data['mediatypes']) {
         // get media types used in actions
         $actions = API::Action()->get(['output' => ['actionid', 'name'], 'selectOperations' => ['operationtype', 'opmessage'], 'mediatypeids' => array_keys($data['mediatypes'])]);
         foreach ($data['mediatypes'] as &$mediaType) {
             $mediaType['typeid'] = $mediaType['type'];
             $mediaType['type'] = media_type2str($mediaType['type']);
             $mediaType['listOfActions'] = [];
             foreach ($actions as $action) {
                 foreach ($action['operations'] as $operation) {
                     if ($operation['operationtype'] == OPERATION_TYPE_MESSAGE && $operation['opmessage']['mediatypeid'] == $mediaType['mediatypeid']) {
                         $mediaType['listOfActions'][$action['actionid']] = ['actionid' => $action['actionid'], 'name' => $action['name']];
                     }
                 }
             }
             order_result($mediaType['listOfActions'], 'name');
         }
         unset($mediaType);
         order_result($data['mediatypes'], $sortField, $sortOrder);
     }
     $url = (new CUrl('zabbix.php'))->setArgument('action', 'mediatype.list');
     $data['paging'] = getPagingLine($data['mediatypes'], $sortOrder, $url);
     $response = new CControllerResponseData($data);
     $response->setTitle(_('Configuration of media types'));
     $this->setResponse($response);
 }
Example #28
0
 public function __construct()
 {
     global $CFG_GLPI, $DB;
     // construct api url
     self::$api_url = trim($CFG_GLPI['url_base_api'], "/");
     // Don't display error in result
     set_error_handler(array('Toolbox', 'userErrorHandlerNormal'));
     ini_set('display_errors', 'Off');
     // Avoid keeping messages between api calls
     $_SESSION["MESSAGE_AFTER_REDIRECT"] = '';
     // check if api is enabled
     if (!$CFG_GLPI['enable_api']) {
         $this->returnError(__("API disabled"), "", "", false);
         exit;
     }
     // retrieve ip of client
     $this->iptxt = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
     $this->ipnum = strstr($this->iptxt, ':') === false ? ip2long($this->iptxt) : '';
     // check ip access
     $apiclient = new APIClient();
     $where_ip = "";
     if ($this->ipnum) {
         $where_ip .= " AND (`ipv4_range_start` IS NULL\n                             OR (`ipv4_range_start` <= '{$this->ipnum}'\n                                 AND `ipv4_range_end` >= '{$this->ipnum}'))";
     } else {
         $where_ip .= " AND (`ipv6` IS NULL\n                             OR `ipv6` = '" . $DB->escape($this->iptxt) . "')";
     }
     $found_clients = $apiclient->find("`is_active` = '1' {$where_ip}");
     if (count($found_clients) <= 0) {
         $this->returnError(__("There isn't an active api client matching your ip adress in the configuration") . " (" . $this->iptxt . ")", "", "ERROR_NOT_ALLOWED_IP", false);
     }
     $app_tokens = array_column($found_clients, 'app_token');
     $apiclients_id = array_column($found_clients, 'id');
     $this->app_tokens = array_combine($apiclients_id, $app_tokens);
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $screen = API::Screen()->get(array('screenids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'selectScreenItems' => API_OUTPUT_EXTEND));
     $screen = reset($screen);
     $screenBuilder = new CScreenBuilder(array('isFlickerfree' => $this->isFlickerfree, 'mode' => $this->mode == SCREEN_MODE_EDIT || $this->mode == SCREEN_MODE_SLIDESHOW ? SCREEN_MODE_SLIDESHOW : SCREEN_MODE_PREVIEW, 'timestamp' => $this->timestamp, 'screen' => $screen, 'period' => $this->timeline['period'], 'stime' => $this->timeline['stimeNow'], 'profileIdx' => $this->profileIdx, 'updateProfile' => false));
     return $this->getOutput($screenBuilder->show(), true);
 }
Example #30
0
function doInit()
{
    if (Config::$pass == null) {
        Config::$pass = trim(file_get_contents(getenv("HOME") . '/.cluebotng.password.only'));
    }
    API::init();
    API::$a->login(Config::$user, Config::$pass);
    Globals::$mysql = false;
    checkMySQL();
    Globals::$tfas = 0;
    Globals::$stdin = fopen('php://stdin', 'r');
    Globals::$run = API::$q->getpage('User:'******'/Run');
    Globals::$wl = API::$q->getpage('Wikipedia:Huggle/Whitelist');
    Globals::$optin = API::$q->getpage('User:'******'/Optin');
    Globals::$aoptin = API::$q->getpage('User:'******'/AngryOptin');
    Globals::$stalk = array();
    Globals::$edit = array();
    $tmp = explode("\n", API::$q->getpage('User:'******'/CBAutostalk.js'));
    foreach ($tmp as $tmp2) {
        if (substr($tmp2, 0, 1) != '#') {
            $tmp3 = explode('|', $tmp2, 2);
            Globals::$stalk[$tmp3[0]] = trim($tmp3[1]);
        }
    }
    $tmp = explode("\n", API::$q->getpage('User:'******'/CBAutoedit.js'));
    foreach ($tmp as $tmp2) {
        if (substr($tmp2, 0, 1) != '#') {
            $tmp3 = explode('|', $tmp2, 2);
            Globals::$edit[$tmp3[0]] = trim($tmp3[1]);
        }
    }
}