Esempio n. 1
0
 public static function defaultInstance(HereAuth $main)
 {
     $opts = new self();
     $opts->autoSecret = $main->getConfig()->getNested("DefaultSettings.AutoAuth.ClientSecretAuth", true);
     $opts->autoIp = $main->getConfig()->getNested("DefaultSettings.AutoAuth.IPAuth", false);
     $opts->autoUuid = $main->getConfig()->getNested("DefaultSettings.AutoAuth.UUIDAuth", false);
     $opts->maskLoc = $main->getConfig()->getNested("DefaultSettings.Masking.Location.Enabled", false);
     $opts->maskLocPos = $main->getConfig()->getNested("DefaultSettings.Masking.Location.Value", "?spawn?@?current?");
     if (!preg_match('#^((\\?spawn\\?)|((\\-)?[0-9]+,(\\-)?[0-9]+,(\\-)?[0-9]+))@[^/\\\\]+$#', $opts->maskLocPos)) {
         $main->getLogger()->alert("Incorrect syntax for location-masking position (DefaultSettings.Masking.Location.Value)! Assuming as \"?spawn?@?current?\".");
         $opts->maskLocPos = "?spawn?@?current?";
     }
     return $opts;
 }
Esempio n. 2
0
 public function __construct(HereAuth $main)
 {
     $dir = rtrim($main->getConfig()->getNested("AuditLogger.LogFolder", "audit"), "/") . "/";
     if ($dir[0] !== "/" and strpos($dir, "://") === false) {
         $dir = $main->getDataFolder() . $dir;
     }
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     foreach ($entries = ["register", "login", "push", "bump", "invalid", "timeout", "factor"] as $entry) {
         $value = $main->getConfig()->getNested("AuditLogger.Log." . ucfirst($entry), ($isWin = Utils::getOS() === "win") ? "/NUL" : "/dev/null");
         if ($value === "/NUL" and !$isWin or $value === "/dev/null" and $isWin) {
             $main->getLogger()->warning("Your OS is " . ($isWin ? "Windows" : "not Windows") . ", where {$value} is not a special file! HereAuth will attempt to create that file!");
         }
         if ($value[0] !== "/") {
             $value = $dir . $value;
         }
         $this->{$entry} = $stream = $this->getStream($value);
         //			fwrite($stream, date(self::DATE_FORMAT) . " Start logging $entry\n");
     }
 }
Esempio n. 3
0
 /**
  * @param MySQLCredentials $crd
  * @param HereAuth         $main
  *
  * @return \mysqli
  */
 public static function createMysqliInstance(MySQLCredentials $crd, HereAuth $main = null)
 {
     /** @noinspection PhpUsageOfSilenceOperatorInspection */
     $db = @new \mysqli($crd->host, $crd->username, $crd->password, $crd->schema, $crd->port, $crd->socket);
     if ($db->connect_error === "Unknown database '{$crd->schema}'") {
         /** @noinspection PhpUsageOfSilenceOperatorInspection */
         $db = @new \mysqli($crd->host, $crd->username, $crd->password, "", $crd->port, $crd->socket);
         $createSchema = true;
     }
     if ($db->connect_error) {
         throw new \InvalidKeyException($db->connect_error);
     }
     if (isset($createSchema)) {
         if ($main !== null) {
             $main->getLogger()->notice("Creating nonexistent `{$crd->schema}`...");
         }
         $db->query("CREATE SCHEMA `{$crd->schema}`");
         if (isset($db->error)) {
             throw new \InvalidKeyException("Schema does not exist and cannot be created");
         }
     }
     return $db;
 }