'Monitorr', 'enabled' => true, 'image' => 'plugins/images/tabs/monitorr.png', 'category' => 'Monitor', 'settings' => array( 'Enable' => array( array( 'type' => 'switch', 'name' => 'homepageMonitorrEnabled', 'label' => 'Enable', 'value' => $this->config['homepageMonitorrEnabled'] ), array( 'type' => 'select', 'name' => 'homepageMonitorrAuth', 'label' => 'Minimum Authentication', 'value' => $this->config['homepageMonitorrAuth'], 'options' => $this->groupOptions ) ), 'Connection' => array( array( 'type' => 'input', 'name' => 'monitorrURL', 'label' => 'URL', 'value' => $this->config['monitorrURL'], 'help' => 'URL for Monitorr. Please use the revers proxy URL i.e. https://domain.com/monitorr/.', 'placeholder' => 'http://domain.com/monitorr/' ), array( 'type' => 'select', 'name' => 'homepageMonitorrRefresh', 'label' => 'Refresh Seconds', 'value' => $this->config['homepageMonitorrRefresh'], 'options' => $this->timeOptions() ), ), 'Options' => array( array( 'type' => 'input', 'name' => 'monitorrHeader', 'label' => 'Title', 'value' => $this->config['monitorrHeader'], 'help' => 'Sets the title of this homepage module', ), array( 'type' => 'switch', 'name' => 'monitorrHeaderToggle', 'label' => 'Toggle Title', 'value' => $this->config['monitorrHeaderToggle'], 'help' => 'Shows/hides the title of this homepage module' ), array( 'type' => 'switch', 'name' => 'monitorrCompact', 'label' => 'Compact view', 'value' => $this->config['monitorrCompact'], 'help' => 'Toggles the compact view of this homepage module' ), ), ) ); } public function monitorrHomepagePermissions($key = null) { $permissions = [ 'main' => [ 'enabled' => [ 'homepageMonitorrEnabled' ], 'auth' => [ 'homepageMonitorrAuth' ], 'not_empty' => [ 'monitorrURL' ] ] ]; if (array_key_exists($key, $permissions)) { return $permissions[$key]; } elseif ($key == 'all') { return $permissions; } else { return []; } } public function homepageOrderMonitorr() { if ($this->homepageItemPermissions($this->monitorrHomepagePermissions('main'))) { return '

Loading Monitorr...

'; } } public function getMonitorrHomepageData() { if (!$this->homepageItemPermissions($this->monitorrHomepagePermissions('main'), true)) { return false; } $api = []; $url = $this->qualifyURL($this->config['monitorrURL']); $dataUrl = $url . '/assets/php/loop.php'; try { $options = $this->requestOptions($this->config['monitorrURL'], false, $this->config['homepageMonitorrRefresh']); $response = Requests::get($dataUrl, ['Token' => $this->config['organizrAPI']], $options); if ($response->success) { $html = html_entity_decode($response->body); // This section grabs the names of all services by regex $services = []; $servicesMatch = []; $servicePattern = '/
(.*)<\/div><\/div>
(Online|Offline|Unresponsive)<\/div>(:?<\/a>)?<\/div><\/div>/'; preg_match_all($servicePattern, $html, $servicesMatch); $services = array_filter($servicesMatch[1]); $status = array_filter($servicesMatch[2]); $statuses = []; foreach ($services as $key => $service) { $match = $status[$key]; $statuses[$service] = $match; if ($match == 'Online') { $statuses[$service] = [ 'status' => true ]; } else if ($match == 'Offline') { $statuses[$service] = [ 'status' => false ]; } else if ($match == 'Unresponsive') { $statuses[$service] = [ 'status' => 'unresponsive' ]; } $statuses[$service]['sort'] = $key; $imageMatch = []; $imgPattern = '/assets\/img\/\.\.(.*)" class="serviceimg" alt=.*><\/div><\/div>
' . $service . '|assets\/img\/\.\.(.*)" class="serviceimg imgoffline" alt=.*><\/div><\/div>
' . $service . '|assets\/img\/\.\.(.*)" class="serviceimg" alt=.*><\/div><\/div>