phpDocumentor InternetAccessLog
[ class tree: InternetAccessLog ] [ index: InternetAccessLog ] [ all elements ]

Class: MySQLRandomElements

Source Location: /MySQLRandomElements.class.php

Class MySQLRandomElements

Inherited Properties, Constants, and Methods
Inherited Properties Inherited Methods Inherited Constants

Inherited From RandomElements

RandomElements::getRandomDate()
Return a random date between the two dates passes as parameters. Parameters and return value are English textual datetime descriptions 'Y-m-d H:i:s'
RandomElements::getRandomDomain()
Returns a random Internet domain (a www followed by a random string ended by a valid internet
RandomElements::getRandomFTPMethod()
Returns a semi random HTTP method (90% will be RETR)
RandomElements::getRandomHTTPMethod()
Returns a semi random HTTP method (90% will be GET)
RandomElements::getRandomIP()
Returns a random IP (string with 4 numbers between 0 and 255). No check for validity is made
RandomElements::getRandomProtocol()
Returns a random protocol (90% will be http)
RandomElements::getRandomRetourCode()
Returns a semirandom return code (90% are 200 return code)
RandomElements::getRandomSize()
Return a random size between 0 and 50K
RandomElements::getRandomString()
Returns a random string of the length demanded (10 characters by default)
RandomElements::getRandomUser()
Returns a random user, composed of one letter and 6 numbers

[ Top ]
Constant Summary
DATA_RNDDOMAINSC_NAME  
DATA_RNDIPSC_NAME  
DATA_RNDURISC_NAME  
DATA_RNDUSERSC_NAME   Default names for random data collections
DEFAULT_DB  
DEFAULT_HOST  
DEFAULT_PASSWORD  
DEFAULT_USER   Constants for default connection values
DOMAINS_REPORT_PREFIX  
FTPLOG_NAME  
NONFTPLOG_NAME  
USERS_REPORT_PREFIX   Default prefixes for monthly reports

[ Top ]
Method Summary
MySQLRandomElements   __construct()   Constructor. For creating an instance we need to pass all the parameters for the MongoDB database where the data will be stored (user, password, host & database name).
void   __destruct()   Destructor. Close the open connection to MySQL database
boolean   addFakeUser()   This function add a user to the table passed as second argument. If not collection done then the user will be added to Random_UsersList.
void   createDomains()   Save random domains in MySQL.
void   createIPs()   Save random IPs in MySQL.
filehandle   createRandomNonFTPLogEntryCSV()   Writes the first line (title) of a CSV file for non ftp log entry (NonFTP_Access_log.csv under CSV directory by default). If it exist it will be truncated. Returns the file handle
void   createURIs()   Save random URIs in MySQL.
void   createUsers()   Save random users in MySQL.
boolean   dropTable()   This function deletes a table if it exists in MySQL. If the table does not exists returns false (and does nothing)
boolean   dropTableNonFTPLogEntry()   This function deletes the table used for saving NonFTP logs. If the table does not exists returns false (and does nothing)
boolean   existUser()   This function verifies if the user exists in the collection passed as second argument. If not collection done then the user will be added to Random_UsersList.
void   exportDomainsToCSV()   Export domains table in CSV format saving it in path passed as parameter (Domains.csv under CSV directory by default)
void   exportIPsToCSV()   Export ip's table in CSV format saving it in path passed as parameter (IPs.csv under CSV directory by default)
void   exportURIsToCSV()   Export URIs table in CSV format saving it in path passed as parameter (URIs.csv under CSV directory by default)
void   exportUsersToCSV()   Export user table in CSV format saving it in path passed as parameter (Users.csv under CSV directory by default)
mysqli   getDB()   Gets the connection to MySQL
array   getDomainCollectedData()   This function returns the domain data from the reports for a year and month specified. If there is no data returns null
string   getDomainFromID()   This function returns the domain searching by the id. If the domain does not exist null is returner
integer   getDomainNumber()   This function queries the database to return the domains number (records in Random_DomainsList)
array   getOne()   Sends a query to the database and returns the first field of the first row. If no rows are got null is returned
array   getRandomFTPLogEntry()   Return a random log entry for FTP access. It is very similar to HTTP and tunnel access but with less fields (there is no protocol and return code)
array   getRandomNonFTPLogEntry()   Return a random log entry for non FTP access (http and tunnel)
mixed   getResults()   Sends a query to the database and returns the results. If no rows are got null is returned
array   getRow()   Sends a query to the database and returns the first row as an associative array. If no rows are got null is returned
array   getUserCollectedData()   This function returns the user data from the raports for a year and month specified. If there is no data returns null
string   getUserFromID()   This function returns the username searching by the id. If the user does not exist null is returner
integer   getUserNumber()   This function queries the database to return the users number (records in Random_UsersList)
void   importDomainsFromCSV()   Import Domains data in a CSV file to a MySQL table (if the table already exist it will be deleted)
void   importIPsFromCSV()   Import IPs data in a CSV file to a MySQL table (if the table already exist it will be deleted)
void   importURIsFromCSV()   Import URIs data in a CSV file to a MySQL table (if the table already exist it will be deleted)
void   importUsersFromCSV()   Import users data in a CSV file to a MySQL table (if the table already exist it will be deleted)
void   loadDataInRAM()   Create in memory tables and loads user, ips and domains data from persitent ones
boolean   randomDomains_exists()   Returns true if the "Random_DomainsList" table has records
boolean   randomIPs_exists()   Returns true if the "Random_IPsList" table has records
boolean   randomUser_exists()   Returns true if the "Random_UsersList" table has records
void   saveRandomFTPLogEntry()   Receives a FTP log entry and saves the data and, optionally, monthly and daily precalculated values in database.
void   saveRandomNonFTPLogEntry()   Receives a log entry and saves the data and, optionally, monthly and daily precalculated values in database.
void   saveRandomNonFTPLogEntryToCSV()   Adds the non ftp log entry passed as parameter to a CSV file (NonFTP_Access_log.csv under CSV directory by default).
void   saveRandomNonFTPLogEntry_fromCSV()   Gets a line with a log entry in CSV format and saves the data and, optionally, monthly and daily precalculated values in database.
string   searchDomain()   Returns a random domain
string   searchFTPMethod()   Returns a random FTP method from the generated collection
string   searchHTTPMethod()   Returns a random HTTP method from the generated collection
string   searchIP()   Returns a random IP from the generated collection
string   searchProtocol()   Returns a random protocol
integer   searchReturnCode()   Returns a random return code
integer   searchSize()   Returns a random size
string   searchURI()   Returns a random URI
string   searchUser()   Returns a random user from the generated collection

[ Top ]
Methods
Constructor __construct  [line 388]

  MySQLRandomElements __construct( [string $user = self::DEFAULT_USER], [string $password = self::DEFAULT_PASSWORD], [string $host = self::DEFAULT_HOST], [string $database = self::DEFAULT_DB]  )

Constructor. For creating an instance we need to pass all the parameters for the MongoDB database where the data will be stored (user, password, host & database name).

  • The default user and password will be mysqldb
  • The default host will be localhost
  • The default database name will be InternetAccessLog

Parameters:
string   $user: 
string   $password: 
string   $host: 
string   $database: 


[ Top ]
Destructor __destruct  [line 410]

  void __destruct( )

Destructor. Close the open connection to MySQL database



[ Top ]
addFakeUser  [line 337]

  boolean addFakeUser( string $username, [string $tablename = self::DATA_RNDUSERSC_NAME]  )

This function add a user to the table passed as second argument. If not collection done then the user will be added to Random_UsersList.

This function is coded for load tests, not for real use. The id is autonumeric Returns true if the user has been succesfull added, false if not

Parameters:
string   $username: 
string   $tablename: 

API Tags:
Access:  public


[ Top ]
createDomains  [line 579]

  void createDomains( integer $number, [boolean $use_index = TRUE], [boolean $dont_repeat = TRUE]  )

Save random domains in MySQL.

The parameters are the number of domains to create and two booleans: if we want an unique index to be created for the domain (default is TRUE) and if we want that the domain is unique (default TRUE) If the domain is going to be unique the existence of itis verified with a query before inserting a new one. The id will be autonumeric (1, 2, 3 ....)

Parameters:
integer   $number: 
boolean   $use_index: 
boolean   $dont_repeat: 


[ Top ]
createIPs  [line 501]

  void createIPs( integer $number, [boolean $use_index = TRUE], [boolean $dont_repeat = TRUE]  )

Save random IPs in MySQL.

The parameters are the number of IPs to create and two booleans: if we want an unique index to be created for the IP (default is TRUE) and if we want that the IP is unique (default TRUE) If the IP is going to be unique the existence of itis verified with a query before inserting a new one. The id will be autonumeric (1, 2, 3 ....)

Parameters:
integer   $number: 
boolean   $use_index: 
boolean   $dont_repeat: 


[ Top ]
createRandomNonFTPLogEntryCSV  [line 858]

  filehandle createRandomNonFTPLogEntryCSV( [string $filename = "CSV/NonFTP_Access_log.csv"]  )

Writes the first line (title) of a CSV file for non ftp log entry (NonFTP_Access_log.csv under CSV directory by default). If it exist it will be truncated. Returns the file handle

Parameters:
string   $filename:  filename

API Tags:
Access:  public


[ Top ]
createURIs  [line 642]

  void createURIs( integer $number  )

Save random URIs in MySQL.

The parameter is the number of URIs to create. The id will be autonumeric (1, 2, 3 ....)

Parameters:
integer   $number: 


[ Top ]
createUsers  [line 423]

  void createUsers( integer $number, [boolean $use_index = TRUE], [boolean $dont_repeat = TRUE]  )

Save random users in MySQL.

The parameters are the number of users two create and to booleans: if we want an unique index to be created for the user name (default is TRUE) and if we want that the user name is unique (default TRUE). If the user name is going to be unique the existence of the name is verified with a query before inserting a new one. The id will be autonumeric (1, 2, 3 ....)

Parameters:
integer   $number: 
boolean   $use_index: 
boolean   $dont_repeat: 


[ Top ]
dropTable  [line 150]

  boolean dropTable( string $tablename  )

This function deletes a table if it exists in MySQL. If the table does not exists returns false (and does nothing)

Parameters:
string   $tablename:  tablename

API Tags:
Access:  public


[ Top ]
dropTableNonFTPLogEntry  [line 170]

  boolean dropTableNonFTPLogEntry( string 0  )

This function deletes the table used for saving NonFTP logs. If the table does not exists returns false (and does nothing)

Parameters:
string   0:  tablename

API Tags:
Access:  public


[ Top ]
existUser  [line 364]

  boolean existUser( string $username, [string $tablename = self::RNDUSERSC_NAME]  )

This function verifies if the user exists in the collection passed as second argument. If not collection done then the user will be added to Random_UsersList.

Parameters:
string   $username: 
string   $tablename: 

API Tags:
Access:  public


[ Top ]
exportDomainsToCSV  [line 792]

  void exportDomainsToCSV( [string $filename = "CSV/Domains.csv"]  )

Export domains table in CSV format saving it in path passed as parameter (Domains.csv under CSV directory by default)

Parameters:
string   $filename: 

API Tags:
Access:  public


[ Top ]
exportIPsToCSV  [line 759]

  void exportIPsToCSV( [string $filename = "CSV/IPs.csv"]  )

Export ip's table in CSV format saving it in path passed as parameter (IPs.csv under CSV directory by default)

Parameters:
string   $filename: 

API Tags:
Access:  public


[ Top ]
exportURIsToCSV  [line 825]

  void exportURIsToCSV( [string $filename = "CSV/URIs.csv"]  )

Export URIs table in CSV format saving it in path passed as parameter (URIs.csv under CSV directory by default)

Parameters:
string   $filename: 

API Tags:
Access:  public


[ Top ]
exportUsersToCSV  [line 726]

  void exportUsersToCSV( [string $filename = "CSV/Users.csv"]  )

Export user table in CSV format saving it in path passed as parameter (Users.csv under CSV directory by default)

Parameters:
string   $filename: 

API Tags:
Access:  public


[ Top ]
getDB  [line 81]

  mysqli getDB( )

Gets the connection to MySQL


API Tags:
Access:  public


[ Top ]
getDomainCollectedData  [line 285]

  array getDomainCollectedData( string $domainname, integer $year, integer $month  )

This function returns the domain data from the reports for a year and month specified. If there is no data returns null

Parameters:
string   $domainname: 
integer   $year: 
integer   $month:  Number from 1 to 12

API Tags:
Access:  public


[ Top ]
getDomainFromID  [line 245]

  string getDomainFromID( integer $id  )

This function returns the domain searching by the id. If the domain does not exist null is returner

Parameters:
integer   $id: 

API Tags:
Access:  public


[ Top ]
getDomainNumber  [line 234]

  integer getDomainNumber( )

This function queries the database to return the domains number (records in Random_DomainsList)


API Tags:
Access:  public


[ Top ]
getOne  [line 122]

  array getOne( string $query  )

Sends a query to the database and returns the first field of the first row. If no rows are got null is returned

Parameters:
string   $query:  query

API Tags:
Access:  public


[ Top ]
getRandomFTPLogEntry  [line 1183]

  array getRandomFTPLogEntry( integer $initial_timestamp, integer $final_timestamp  )

Return a random log entry for FTP access. It is very similar to HTTP and tunnel access but with less fields (there is no protocol and return code)

It has two optional arguments, initial and final timestamps, if we want to get a random time in log entry created

Parameters:
integer   $initial_timestamp: 
integer   $final_timestamp: 


[ Top ]
getRandomNonFTPLogEntry  [line 963]

  array getRandomNonFTPLogEntry( integer $initial_timestamp, integer $final_timestamp  )

Return a random log entry for non FTP access (http and tunnel)

It has two optional arguments, initial and final timestamps, if we want to get a random time in log entry created

Parameters:
integer   $initial_timestamp: 
integer   $final_timestamp: 


[ Top ]
getResults  [line 91]

  mixed getResults( string $query  )

Sends a query to the database and returns the results. If no rows are got null is returned

Parameters:
string   $query:  query

API Tags:
Access:  public


[ Top ]
getRow  [line 111]

  array getRow( string $query  )

Sends a query to the database and returns the first row as an associative array. If no rows are got null is returned

Parameters:
string   $query:  query

API Tags:
Access:  public


[ Top ]
getUserCollectedData  [line 260]

  array getUserCollectedData( string $username, integer $year, integer $month  )

This function returns the user data from the raports for a year and month specified. If there is no data returns null

Parameters:
string   $username: 
integer   $year: 
integer   $month:  Number from 1 to 12

API Tags:
Access:  public


[ Top ]
getUserFromID  [line 222]

  string getUserFromID( integer $userid  )

This function returns the username searching by the id. If the user does not exist null is returner

Parameters:
integer   $userid: 

API Tags:
Access:  public


[ Top ]
getUserNumber  [line 211]

  integer getUserNumber( )

This function queries the database to return the users number (records in Random_UsersList)


API Tags:
Access:  public


[ Top ]
importDomainsFromCSV  [line 811]

  void importDomainsFromCSV( [string $filename = "CSV/Domains.csv"]  )

Import Domains data in a CSV file to a MySQL table (if the table already exist it will be deleted)

The MySQL user must have the global privilege FILE!

Parameters:
string   $filename: 

API Tags:
Access:  public


[ Top ]
importIPsFromCSV  [line 778]

  void importIPsFromCSV( [string $filename = "CSV/IPs.csv"]  )

Import IPs data in a CSV file to a MySQL table (if the table already exist it will be deleted)

The MySQL user must have the global privilege FILE!

Parameters:
string   $filename: 

API Tags:
Access:  public


[ Top ]
importURIsFromCSV  [line 844]

  void importURIsFromCSV( [string $filename = "CSV/URIs.csv"]  )

Import URIs data in a CSV file to a MySQL table (if the table already exist it will be deleted)

The MySQL user must have the global privilege FILE!

Parameters:
string   $filename: 

API Tags:
Access:  public


[ Top ]
importUsersFromCSV  [line 745]

  void importUsersFromCSV( [string $filename = "CSV/Users.csv"]  )

Import users data in a CSV file to a MySQL table (if the table already exist it will be deleted)

The MySQL user must have the global privilege FILE!

Parameters:
string   $filename: 

API Tags:
Access:  public


[ Top ]
loadDataInRAM  [line 664]

  void loadDataInRAM( )

Create in memory tables and loads user, ips and domains data from persitent ones



[ Top ]
randomDomains_exists  [line 616]

  boolean randomDomains_exists( )

Returns true if the "Random_DomainsList" table has records



[ Top ]
randomIPs_exists  [line 539]

  boolean randomIPs_exists( )

Returns true if the "Random_IPsList" table has records



[ Top ]
randomUser_exists  [line 461]

  boolean randomUser_exists( )

Returns true if the "Random_UsersList" table has records



[ Top ]
saveRandomFTPLogEntry  [line 1218]

  void saveRandomFTPLogEntry( array $log_entry, [boolean $create_reports = TRUE]  )

Receives a FTP log entry and saves the data and, optionally, monthly and daily precalculated values in database.

By default the reports are created. If the second argument is FALSE they will not be generated A id field autonumeric will be created.

Parameters:
array   $log_entry:  log entry as returned by getRandomNonFTPLogEntry
boolean   $create_reports: 


[ Top ]
saveRandomNonFTPLogEntry  [line 1113]

  void saveRandomNonFTPLogEntry( array $log_entry, [boolean $create_reports = TRUE]  )

Receives a log entry and saves the data and, optionally, monthly and daily precalculated values in database.

By default the reports are created. If the second argument is FALSE they will not be generated. A id field autonumeric will be created.

Parameters:
array   $log_entry:  log entry as returned by getRandomNonFTPLogEntry
boolean   $create_reports: 


[ Top ]
saveRandomNonFTPLogEntryToCSV  [line 875]

  void saveRandomNonFTPLogEntryToCSV( array $log_entry, [string $filename = "CSV/NonFTP_Access_log.csv"], [filehandle $fh = NULL]  )

Adds the non ftp log entry passed as parameter to a CSV file (NonFTP_Access_log.csv under CSV directory by default).

A third optional parameter is the file handle (to not open and close the file in a for loop which calls this function)

Parameters:
array   $log_entry:  log entry as returned by getRandomNonFTPLogEntry
string   $filename: 
filehandle   $fh: 

API Tags:
Access:  public


[ Top ]
saveRandomNonFTPLogEntry_fromCSV  [line 1160]

  void saveRandomNonFTPLogEntry_fromCSV( string $line, [boolean $create_reports = TRUE]  )

Gets a line with a log entry in CSV format and saves the data and, optionally, monthly and daily precalculated values in database.

By default the reports are created. If the second argument is FALSE they will not be generated. A id field autonumeric will be created.

Parameters:
string   $line:  Line in CSV format (clientip, user, datetime, method, protocol, domain, uri, return_code, size)
boolean   $create_reports: 


[ Top ]
searchDomain  [line 918]

  string searchDomain( )

Returns a random domain



[ Top ]
searchFTPMethod  [line 910]

  string searchFTPMethod( )

Returns a random FTP method from the generated collection



[ Top ]
searchHTTPMethod  [line 902]

  string searchHTTPMethod( )

Returns a random HTTP method from the generated collection



[ Top ]
searchIP  [line 707]

  string searchIP( )

Returns a random IP from the generated collection



[ Top ]
searchProtocol  [line 944]

  string searchProtocol( )

Returns a random protocol



[ Top ]
searchReturnCode  [line 952]

  integer searchReturnCode( )

Returns a random return code



[ Top ]
searchSize  [line 936]

  integer searchSize( )

Returns a random size



[ Top ]
searchURI  [line 927]

  string searchURI( )

Returns a random URI



[ Top ]
searchUser  [line 716]

  string searchUser( )

Returns a random user from the generated collection



[ Top ]
Constants
DATA_RNDDOMAINSC_NAME = "DATA_Random_DomainsList" [line 24]

[ Top ]
DATA_RNDIPSC_NAME = "DATA_Random_IPsList" [line 23]

[ Top ]
DATA_RNDURISC_NAME = "DATA_Random_URIsList" [line 25]

[ Top ]
DATA_RNDUSERSC_NAME = "DATA_Random_UsersList" [line 22]

Default names for random data collections


[ Top ]
DEFAULT_DB = "InternetAccessLog" [line 42]

[ Top ]
DEFAULT_HOST = "localhost" [line 41]

[ Top ]
DEFAULT_PASSWORD = "mysqldb" [line 40]

[ Top ]
DEFAULT_USER = "mysqldb" [line 39]

Constants for default connection values


[ Top ]
DOMAINS_REPORT_PREFIX = "Domains_Monthly_Report_" [line 34]

[ Top ]
FTPLOG_NAME = "FTP_Access_log" [line 28]

[ Top ]
NONFTPLOG_NAME = "NonFTP_Access_log" [line 27]

[ Top ]
USERS_REPORT_PREFIX = "Users_Monthly_Report_" [line 33]

Default prefixes for monthly reports


[ Top ]

Documentation generated on Fri, 12 Apr 2013 12:02:20 +0200 by phpDocumentor 1.4.4