/**
  * generate validation data (list of AuthServers)
  */
 public function eventPostLoading()
 {
     if (!array_key_exists($this->internalCacheKey, self::$internalOptionList)) {
         self::$internalOptionList[$this->internalCacheKey] = array();
         $authFactory = new \OPNsense\Auth\AuthenticationFactory();
         $allAuthServers = $authFactory->listServers();
         foreach ($allAuthServers as $key => $value) {
             // use filters to determine relevance
             $isMatched = true;
             foreach ($this->internalFilters as $filterKey => $filterData) {
                 if (isset($value[$filterKey])) {
                     $fieldData = $value[$filterKey];
                 } else {
                     // not found, might be a boolean.
                     $fieldData = "0";
                 }
                 if (!preg_match($filterData, $fieldData)) {
                     $isMatched = false;
                 }
             }
             if ($isMatched) {
                 self::$internalOptionList[$this->internalCacheKey][$key] = $key;
             }
         }
     }
 }
Ejemplo n.º 2
0
     // every action is using the sequence of the user, to keep it understandable, we will use
     // the same strategy here (although we need a username to work with)
     //
     // the client side is (jquery) generates the actual download file.
     $username = $a_user[$id]['name'];
     $authFactory = new \OPNsense\Auth\AuthenticationFactory();
     $authenticator = $authFactory->get("Local API");
     $keyData = $authenticator->createKey($username);
     if ($keyData != null) {
         echo json_encode($keyData);
     }
     exit;
 } elseif ($act == 'delApiKey' && isset($id)) {
     $username = $a_user[$id]['name'];
     if (!empty($pconfig['api_delete'])) {
         $authFactory = new \OPNsense\Auth\AuthenticationFactory();
         $authenticator = $authFactory->get("Local API");
         $authenticator->dropKey($username, $pconfig['api_delete']);
         $savemsg = gettext("API key") . " {$pconfig['api_delete']} " . gettext("removed.");
     } else {
         $savemsg = gettext('No API key found');
     }
     // redirect
     header("Location: system_usermanager.php?savemsg=" . $savemsg . "&act=edit&userid=" . $id);
     exit;
 } elseif (isset($pconfig['save'])) {
     // save user
     /* input validation */
     if (isset($id)) {
         $reqdfields = explode(" ", "usernamefld");
         $reqdfieldsn = array(gettext("Username"));
Ejemplo n.º 3
0
 *    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 *    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 *    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 *    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *    POSSIBILITY OF SUCH DAMAGE.
 *
 */
require_once "config.inc";
require_once "auth.inc";
openlog("squid", LOG_ODELAY, LOG_AUTH);
$authFactory = new \OPNsense\Auth\AuthenticationFactory();
$f = fopen("php://stdin", "r");
while ($line = fgets($f)) {
    $fields = explode(' ', trim($line));
    $username = rawurldecode($fields[0]);
    $password = rawurldecode($fields[1]);
    $isAuthenticated = false;
    if (isset($config['OPNsense']['proxy']['forward']['authentication']['method'])) {
        foreach (explode(',', $config['OPNsense']['proxy']['forward']['authentication']['method']) as $authServerName) {
            $authServer = $authFactory->get(trim($authServerName));
            if ($authServer == null) {
                // authenticator not found, use local
                $authServer = $authFactory->get('Local Database');
            }
            $isAuthenticated = $authServer->authenticate($username, $password);
            if ($isAuthenticated) {