| 
							
							
							
						 |  |  | @@ -1,5 +1,12 @@ | 
		
	
		
			
				|  |  |  |  | <?php | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | define(COUNT, 'count'); | 
		
	
		
			
				|  |  |  |  | define(HASH_VALUE, 'hash_value'); | 
		
	
		
			
				|  |  |  |  | define(RESPONSE_STRING, 'response_string'); | 
		
	
		
			
				|  |  |  |  | define(RESPONSE_TIME, 'response_time'); | 
		
	
		
			
				|  |  |  |  | define(START_ID, 'start_id'); | 
		
	
		
			
				|  |  |  |  | define(STOP_ID, 'stop_id'); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | ini_set("session.save_path", "/tmp"); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | $webuidir = ""; | 
		
	
	
		
			
				
					
					|  |  |  | @@ -20,15 +27,14 @@ if ( $options = getopt( $opts, $lopts ) ) | 
		
	
		
			
				|  |  |  |  |         $webuidir = $options['webui']; | 
		
	
		
			
				|  |  |  |  |     } else | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         echo("\nError: must provide path to WebUI directory\n\n"); | 
		
	
		
			
				|  |  |  |  |         echo "\nError: must provide path to WebUI directory\n\n"; | 
		
	
		
			
				|  |  |  |  |      | 
		
	
		
			
				|  |  |  |  |         display_help(); | 
		
	
		
			
				|  |  |  |  |         exit; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     | 
		
	
		
			
				|  |  |  |  |     if ( isset($options['mode']) ) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |        if($options['mode'] == 'time') { $mode = $options['mode']; } | 
		
	
		
			
				|  |  |  |  |     if ( isset($options['mode']) && $options['mode'] == 'time') { | 
		
	
		
			
				|  |  |  |  |        $mode = $options['mode']; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   | 
		
	
		
			
				|  |  |  |  |     if ( isset($options['h']) )  | 
		
	
	
		
			
				
					
					|  |  |  | @@ -36,6 +42,7 @@ if ( $options = getopt( $opts, $lopts ) ) | 
		
	
		
			
				|  |  |  |  |         display_help(); | 
		
	
		
			
				|  |  |  |  |         exit; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |     if ( isset($options['verbose']) ) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         $verbose = 1; | 
		
	
	
		
			
				
					
					|  |  |  | @@ -63,30 +70,28 @@ define('MODE', $mode); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | $data = get_hash_values(); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | //print_r($data); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | // check if we have enough messages | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | if(MODE == 'unit' && $data['count'] < TSA_STAMP_REQUEST_UNIT_SIZE) { | 
		
	
		
			
				|  |  |  |  |    syslog(LOG_INFO, "not enough messages to sign yet (" . $data['count'] . ")"); | 
		
	
		
			
				|  |  |  |  | if(MODE == 'unit' && $data[COUNT] < TSA_STAMP_REQUEST_UNIT_SIZE) { | 
		
	
		
			
				|  |  |  |  |    syslog(LOG_INFO, "not enough messages to sign yet (" . $data[COUNT] . ")"); | 
		
	
		
			
				|  |  |  |  |    exit; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | if(MODE == 'time' && $data['count'] < 1) { | 
		
	
		
			
				|  |  |  |  |    syslog(LOG_INFO, "not enough messages to sign yet (" . $data['count'] . ")"); | 
		
	
		
			
				|  |  |  |  | if(MODE == 'time' && $data[COUNT] < 1) { | 
		
	
		
			
				|  |  |  |  |    syslog(LOG_INFO, "not enough messages to sign yet (" . $data[COUNT] . ")"); | 
		
	
		
			
				|  |  |  |  |    exit; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | $requestfile_path = TrustedTimestamps::createRequestfile($data['hash_value']); | 
		
	
		
			
				|  |  |  |  | $requestfile_path = TrustedTimestamps::createRequestfile($data[HASH_VALUE]); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | $response = TrustedTimestamps::signRequestfile($requestfile_path, TSA_URL); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | $data['response_string'] = $response['response_string']; | 
		
	
		
			
				|  |  |  |  | $data['response_time'] = $response['response_time']; | 
		
	
		
			
				|  |  |  |  | $data[RESPONSE_STRING] = $response[RESPONSE_STRING]; | 
		
	
		
			
				|  |  |  |  | $data[RESPONSE_TIME] = $response[RESPONSE_TIME]; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | $rc = store_results($data); | 
		
	
		
			
				|  |  |  |  | if($rc == 1) { syslog(LOG_INFO, "signed " . $data['count'] . " messages (" . $data['start_id'] . "-" . $data['stop_id'] . ") on @" . $data['response_time']); } | 
		
	
		
			
				|  |  |  |  | else { syslog(LOG_INFO, "ERROR: failed to sign " . $data['count'] . " messages (" . $data['start_id'] . "-" . $data['stop_id'] . ") on @" . $data['response_time']); } | 
		
	
		
			
				|  |  |  |  | if($rc == 1) { syslog(LOG_INFO, "signed " . $data[COUNT] . " messages (" . $data[START_ID] . "-" . $data[STOP_ID] . ") on @" . $data[RESPONSE_TIME]); } | 
		
	
		
			
				|  |  |  |  | else { syslog(LOG_INFO, "ERROR: failed to sign " . $data[COUNT] . " messages (" . $data[START_ID] . "-" . $data[STOP_ID] . ") on @" . $data[RESPONSE_TIME]); } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |  | 
		
	
	
		
			
				
					
					|  |  |  | @@ -99,7 +104,7 @@ function get_last_entry_from_timestamp_table() { | 
		
	
		
			
				|  |  |  |  |       return 0; | 
		
	
		
			
				|  |  |  |  |    } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |    return $query->row['stop_id']; | 
		
	
		
			
				|  |  |  |  |    return $query->row[STOP_ID]; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |  | 
		
	
	
		
			
				
					
					|  |  |  | @@ -132,10 +137,10 @@ function get_hash_values() { | 
		
	
		
			
				|  |  |  |  |    if(MODE == 'time') { $stop_id = $start_id + $count - 1; } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |    return array( | 
		
	
		
			
				|  |  |  |  |                 'start_id' => $start_id, | 
		
	
		
			
				|  |  |  |  |                 'stop_id' => $stop_id, | 
		
	
		
			
				|  |  |  |  |                 'count' => $count, | 
		
	
		
			
				|  |  |  |  |                 'hash_value' => sha1($s) | 
		
	
		
			
				|  |  |  |  |                 START_ID => $start_id, | 
		
	
		
			
				|  |  |  |  |                 STOP_ID => $stop_id, | 
		
	
		
			
				|  |  |  |  |                 COUNT => $count, | 
		
	
		
			
				|  |  |  |  |                 HASH_VALUE => sha1($s) | 
		
	
		
			
				|  |  |  |  |           ); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					
					|  |  |  | @@ -144,23 +149,18 @@ function get_hash_values() { | 
		
	
		
			
				|  |  |  |  | function store_results($data = array()) { | 
		
	
		
			
				|  |  |  |  |    $db = Registry::get('db'); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |    $query = $db->query("INSERT INTO " . TABLE_TIMESTAMP . " (start_id, stop_id, hash_value, `count`, response_time, response_string) VALUES(?,?,?,?,?,?)", array($data['start_id'], $data['stop_id'], $data['hash_value'], $data['count'], $data['response_time'], $data['response_string'])); | 
		
	
		
			
				|  |  |  |  |    $db->query("INSERT INTO " . TABLE_TIMESTAMP . " (start_id, stop_id, hash_value, `count`, response_time, response_string) VALUES(?,?,?,?,?,?)", array($data[START_ID], $data[STOP_ID], $data[HASH_VALUE], $data[COUNT], $data[RESPONSE_TIME], $data[RESPONSE_STRING])); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |    $rc = $db->countAffected(); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |    return $rc; | 
		
	
		
			
				|  |  |  |  |    return $db->countAffected(); | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | function display_help() { | 
		
	
		
			
				|  |  |  |  |     $phpself = basename(__FILE__); | 
		
	
		
			
				|  |  |  |  |     echo("\nUsage: $phpself --webui [PATH] [OPTIONS...]\n\n"); | 
		
	
		
			
				|  |  |  |  |     echo("\t--webui=\"[REQUIRED: path to the Piler WebUI Directory]\"\n\n"); | 
		
	
		
			
				|  |  |  |  |     echo("options:\n"); | 
		
	
		
			
				|  |  |  |  |     echo("\t--mode time|unit (default: unit)\n"); | 
		
	
		
			
				|  |  |  |  |     echo("\t-v Provide a verbose output\n"); | 
		
	
		
			
				|  |  |  |  |     echo("\t-h Prints this help screen and exits\n"); | 
		
	
		
			
				|  |  |  |  |     echo "\nUsage: $phpself --webui [PATH] [OPTIONS...]\n\n"; | 
		
	
		
			
				|  |  |  |  |     echo "\t--webui=\"[REQUIRED: path to the Piler WebUI Directory]\"\n\n"; | 
		
	
		
			
				|  |  |  |  |     echo "options:\n"; | 
		
	
		
			
				|  |  |  |  |     echo "\t--mode time|unit (default: unit)\n"; | 
		
	
		
			
				|  |  |  |  |     echo "\t-v Provide a verbose output\n"; | 
		
	
		
			
				|  |  |  |  |     echo "\t-h Prints this help screen and exits\n"; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | ?> | 
		
	
	
		
			
				
					
					| 
							
							
							
						 |  |  |   |