mirror of
				https://github.com/ShaYmez/FreeSTAR-Status-Engine.git
				synced 2025-10-30 11:30:20 -04:00 
			
		
		
		
	Re #11 - start working on an api
Also some locale negotiator bugfixes & it is now possible to serialize Service and Incident classess to JSON
This commit is contained in:
		
							parent
							
								
									416070ba5f
								
							
						
					
					
						commit
						9f7e15fcd1
					
				| @ -1,7 +1,7 @@ | ||||
| # Server status page | ||||
|  | ||||
| 
 | ||||
| Very simple server status page written in PHP that can run on **PHP 5.3+** - even on **shared webhosting**. Because why waste your money on another server (or host on a server that you might want to do maintenance on), when you can use cheap webhosting? | ||||
| Very simple server status page written in PHP that can run on **PHP 5.4+** - even on **shared webhosting**. Because why waste your money on another server (or host on a server that you might want to do maintenance on), when you can use cheap webhosting? | ||||
| 
 | ||||
| ## How do I install this thing? | ||||
| Simply put the files on your server and access it from your browser. There will be a simple install dialog waiting for you. | ||||
|  | ||||
							
								
								
									
										11
									
								
								api/incidents.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								api/incidents.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| <?php | ||||
| 
 | ||||
| if (!file_exists("../config.php")) | ||||
| { | ||||
|   header("Location: ../"); | ||||
| } | ||||
| else{ | ||||
|   require_once("../config.php"); | ||||
|   require_once("../classes/constellation.php"); | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										40
									
								
								api/status.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								api/status.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | ||||
| <?php | ||||
| 
 | ||||
| if (!file_exists("../config.php")) | ||||
| { | ||||
|   header("Location: ../"); | ||||
| } | ||||
| else{ | ||||
|   require_once("../config.php"); | ||||
|   require_once("../classes/constellation.php"); | ||||
| 
 | ||||
|   if (!isset($_GET['id'])) | ||||
|   { | ||||
| 	  $array = $constellation->render_status(true, false); | ||||
| 	  echo json_encode($array); | ||||
|   }else{ | ||||
|   	$query = $mysqli->prepare("SELECT name FROM services WHERE id=?"); | ||||
|   	$query->bind_param("i", $_GET['id']); | ||||
|   	$query->execute(); | ||||
|     $result = $query->get_result()->fetch_assoc(); | ||||
|     if (!count($result)) | ||||
|     { | ||||
|     	die(json_encode(["error" => _("Service does not exist!")])); | ||||
|     } | ||||
| 
 | ||||
|   	$sql = $mysqli->prepare("SELECT type FROM services_status INNER JOIN status ON services_status.status_id = status.id WHERE service_id = ? AND `time` <= ? AND (`end_time` >= ? OR `end_time`=0) ORDER BY `time` DESC LIMIT 1"); | ||||
| 
 | ||||
|     $sql->bind_param("iii", $id, $timestamp, $timestamp); | ||||
|     $sql->execute(); | ||||
|     $tmp = $sql->get_result(); | ||||
|     if ($tmp->num_rows) | ||||
|     { | ||||
|       $service = new Service($_GET['id'], $result['name'], $tmp->fetch_assoc()['type']); | ||||
|     } | ||||
|     else{ | ||||
|       $service = new Service($_GET['id'], $result['name']); | ||||
|     } | ||||
| 
 | ||||
|     echo json_encode($service); | ||||
|   } | ||||
| } | ||||
| @ -69,7 +69,7 @@ class Constellation | ||||
|    * @param boolean $admin | ||||
|    * @return array of services  | ||||
|    */ | ||||
|   public function render_status($admin = 0){ | ||||
|   public function render_status($admin = false, $heading = true){ | ||||
|     global $mysqli; | ||||
|      | ||||
|     $query = $mysqli->query("SELECT id, name  FROM services"); | ||||
| @ -93,8 +93,10 @@ class Constellation | ||||
|           $array[] = new Service($result['id'], $result['name']); | ||||
|         } | ||||
|       }       | ||||
| 
 | ||||
|       echo Service::current_status($array); | ||||
|       if ($heading) | ||||
|       { | ||||
|         echo Service::current_status($array); | ||||
|       } | ||||
|     } | ||||
|     else{ | ||||
|       $array[] = new Service(0, _("No services"), -1); | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
| /** | ||||
| * Class for creating and rendering an incident | ||||
| */ | ||||
| class Incident | ||||
| class Incident implements JsonSerializable | ||||
| { | ||||
|   private $id; | ||||
|   private $date; | ||||
| @ -183,4 +183,16 @@ class Incident | ||||
|       </article> | ||||
|       <?php | ||||
|   } | ||||
| 
 | ||||
|   public function jsonSerialize() { | ||||
|     return [ | ||||
|       "id" => $this->id, | ||||
|       "date" => $this->date, | ||||
|       "end_date" => $this->end_date, | ||||
|       "text" => $this->text, | ||||
|       "type" => $this->type, | ||||
|       "title" => $this->title, | ||||
|       "username" => $this->username | ||||
|     ]; | ||||
|   } | ||||
| }           | ||||
| @ -279,6 +279,8 @@ class LocaleNegotiator | ||||
| 		$best_match = false; | ||||
| 		//So we have also lang code as value
 | ||||
| 		$accepted_langs = array_flip($this->accepted_langs); | ||||
| 
 | ||||
| 		global $lang; | ||||
| 		foreach ($langs as $lang) { | ||||
| 			if (strlen($lang)>2){ | ||||
| 				if (in_array($lang, $accepted_langs)){ | ||||
| @ -292,7 +294,9 @@ class LocaleNegotiator | ||||
| 				}); | ||||
| 
 | ||||
| 				if (count($possible)){ | ||||
| 					$best_match = $possible[0]; | ||||
| 					foreach ($possible as $value) { | ||||
| 						$best_match = $value; | ||||
| 					} | ||||
| 					break; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
| /** | ||||
| * Class for managing services | ||||
| */ | ||||
| class Service | ||||
| class Service implements JsonSerializable | ||||
| { | ||||
|   private $id; | ||||
|   private $name; | ||||
| @ -167,4 +167,15 @@ class Service | ||||
|       </div> | ||||
|   <?php | ||||
|   } | ||||
| 
 | ||||
|   public function jsonSerialize() { | ||||
|     global $statuses; | ||||
|     return [ | ||||
|       "id" => $this->id, | ||||
|       "name" => $this->name, | ||||
|       "status" => $this->status, | ||||
|       "status_string" => $statuses[$this->status] | ||||
|     ]; | ||||
|   } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user