#!/usr/bin/php connect()) { $myLog->log(LOG_WARNING, "Could not connect to database"); error_log("Could not connect to database"); exit(1); } $count=1; if($last_arg = intval(array_pop($argv))) { $count = $last_arg; } $result = $db->customQuery("SELECT id FROM clients ORDER BY id DESC LIMIT 1"); $row = $db->fetchArray($result); $db->closeCursor($result); if($row) { $next_id = $row['id']+1; } else { $next_id = 1; } $random = array_key_exists('urandom', $options) ? "/dev/urandom" : "/dev/random"; $fh = fopen($random, "r"); if(!$fh) { die("cannot open ".$random); } for ($i=0; $i<$count; $i++) { $client_id = $next_id++; if (!($rnd = fread ($fh, 20))) { die("cannot read from ".$random); } $secret = base64_encode($rnd); $params = array( "id" => $client_id, "active" => 1, "created" => time(), "secret" => $secret, "email" => array_key_exists('email', $options) ? $options['email'] : '', "notes" => array_key_exists('notes', $options) ? $options['notes'] : '', "otp" => array_key_exists('otp', $options) ? $options['otp'] : '' ); $query="INSERT INTO clients " . "(id,active,created,secret,email,notes,otp) VALUES " . "('" . $params["id"] . "', " . "'" . $params["active"] . "', " . "'" . $params['created'] . "'," . "'" . $params['secret'] . "'," . "'" . $params['email'] . "'," . "'" . $params['notes'] . "'," . "'" . $params['otp'] . "')"; if(!$db->customQuery($query)){ $myLog->log(LOG_ERR, "Failed to insert new client with query " . $query); error_log("Failed to insert new client with query " . $query); exit(1); } echo $client_id.",".$secret."\n"; } fclose($fh); $myLog->log(LOG_NOTICE, "Successfully inserted generated clients into database");