示例#1
0
}
// you can put any additional attributes here
// $racct->putAttribute(RADIUS_ACCT_INPUT_PACKETS, 45236);
// $racct->putAttribute(RADIUS_ACCT_OUTPUT_PACKETS, 1212);
$result = $racct->send();
if (PEAR::isError($result)) {
    printf("Radius send failed: %s<br>\n", $result->getMessage());
    exit;
} else {
    if ($result === true) {
        printf("Radius Acounting succeeded<br>\n");
    } else {
        printf("Radius Acounting rejected<br>\n");
    }
}
$racct->close();
// Wait a bit, that we can put the session-time
sleep(2);
$racct = new Auth_RADIUS_Acct_Stop();
$racct->addServer('localhost', 0, 'testing123');
$racct->username = $username;
$racct->session_time = time() - $starttime;
$status = $racct->start();
if (PEAR::isError($status)) {
    printf("Radius start: %s<br>\n", $status->getMessage());
    exit;
}
// you can put any additional attributes here
// $racct->putAttribute(RADIUS_ACCT_TERMINATE_CAUSE, RADIUS_TERM_SESSION_TIMEOUT);
$result = $racct->send();
if (PEAR::isError($result)) {
 /**
  * Start accounting traffic for the user
  *
  * @param string $conn_id The connection id for the connection to work on
  * @param string $errmsg  Reference of error message
  *
  * @return bool Returns whether successful or not
  */
 public function acctStart($conn_id, &$errmsg = null)
 {
     $db = AbstractDb::getObject();
     // Init values
     $info = null;
     if (Dependency::check("Auth_RADIUS", $errmsg)) {
         $conn_id = $db->escapeString($conn_id);
         $db->execSqlUniqueRes("SELECT CURRENT_TIMESTAMP, *, CASE WHEN ((CURRENT_TIMESTAMP - reg_date) > networks.validation_grace_time) THEN true ELSE false END AS validation_grace_time_expired FROM connections JOIN users ON (users.user_id=connections.user_id) JOIN networks ON (users.account_origin = networks.network_id) WHERE connections.conn_id={$conn_id}", $info, false);
         // RADIUS accounting start
         $radius_acct = new Auth_RADIUS_Acct_Start();
         $radius_acct->addServer($this->mRadius_hostname, $this->mRadius_acct_port, $this->mRadius_secret_key);
         // Specify the user for which accounting will be done
         $radius_acct->username = $info['username'];
         // Specify the way the user has been authenticated ( via RADIUS, the class did it )
         $radius_acct->authentic = RADIUS_AUTH_RADIUS;
         // Set the session ID to the generated token
         $radius_acct->session_id = $info['token'];
         $status = $radius_acct->start();
         if (PEAR::isError($status)) {
             return false;
         }
         $result = $radius_acct->send();
         if (PEAR::isError($result)) {
             $errmsg = "Could not send accounting request to RADIUS server.";
             return false;
         } else {
             if ($result !== true) {
                 $radius_acct->close();
                 $errmsg = "Accounting request rejected by RADIUS server.";
                 return false;
             }
         }
         $radius_acct->close();
         // Run generic accounting (local traffic counters) only if RADIUS went OK
         parent::acctStart($conn_id);
         return true;
     } else {
         return false;
     }
 }