egzozcu Posted July 9, 2022 Share Posted July 9, 2022 Hello there, Like the title says. is there a thing that does the same job like in Windows? I have a folder that contains a file with .log extention and another one with .leases extention. And I have this command line: exec('openssl ts -verify -data /tmp/' . $log_type . '.log -in /tmp/' . $log_type . '.l*.der -token_in -CAfile /CA/cacert.pem -untrusted /CA/tsacert.pem', $result); when I run the above command line it starts varification process only on the file that has .log extention. And if I change the bold marked .log in the above command line with .leases then re run the command line then it start the same varification process but this time only on the file that has .leases extention. What I want here is that whenever I run the command line it detects both the files in the folder and start the verification process, no matter it is .log or .leases extention. So what is the thing I should write in the place of the bold marked .log to make it detect any extention? I have tried *.* or '.' or * or .l* but non of these worked Any help would be much appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/315015-is-there-a-just-like-in-windows/ Share on other sites More sharing options...
kicken Posted July 9, 2022 Share Posted July 9, 2022 Either .*, .l* would work to match your .log and .lease files. The command you're executing has to be capable of processing multiple files though and as far as I can see reading the man page for openssl ts it doesn't seem like it can. Quote -data file_to_hash The response or token must be verified against file_to_hash. The file is hashed with the message digest algorithm specified in the token. The -digest and -queryfile options must not be specified with this one. (Optional) Note it says file_to_hash, singular. So you'd need to find your .log and .lease files yourself, then run that command for each one individually. Quote Link to comment https://forums.phpfreaks.com/topic/315015-is-there-a-just-like-in-windows/#findComment-1598095 Share on other sites More sharing options...
egzozcu Posted July 10, 2022 Author Share Posted July 10, 2022 (edited) 16 hours ago, kicken said: Either .*, .l* would work to match your .log and .lease files. The command you're executing has to be capable of processing multiple files though and as far as I can see reading the man page for openssl ts it doesn't seem like it can. Note it says file_to_hash, singular. So you'd need to find your .log and .lease files yourself, then run that command for each one individually. this is the complete script : <?php $file = $_POST['file']; $exploded = explode('.', basename($file)); $log_type = $exploded[0]; chdir('/tmp'); exec('cp /var/imzali_kayitlar/' . $file . ' ./'); exec('tar zxvf ' . basename($file)); // Doğrulama komutu exec('openssl ts -verify -data /tmp/' . $log_type . '.log -in /tmp/' . $log_type . '.log.der -token_in -CAfile /CA/cacert.pem -untrusted /CA/tsacert.pem', $result); if ($result[0] == 'Verification: OK') { $imza = file_get_contents($log_type . '.log.imza'); echo '<p class="success">Doğrulama başarılı!</p>'; echo '<div>' . nl2br($imza) . '</div>'; } else { echo '<p class="error">Doğrulama başarısız!</p>'; } exec('rm ' . $log_type . '.l*'); exit; I have the .log and .leases files inside a folder, and to run the script I have a webpage that I go there where there is a button beside every file then I click on the button then it runs the above script in the backgroud and shows the result if the verification is ok or not. here is some pics of the files and the webpage: when I change .log to .leases then the above will be opposite. .* or .l* doesnt work. Edited July 10, 2022 by egzozcu Quote Link to comment https://forums.phpfreaks.com/topic/315015-is-there-a-just-like-in-windows/#findComment-1598110 Share on other sites More sharing options...
kicken Posted July 10, 2022 Share Posted July 10, 2022 (edited) Quote And here it gave failed because the .log is written in the script Don't hard-code the .log then. You have access to the full file name including the extension in your script. You use it to generate your $log_type variable. The extension you need can similarly be extracted and used in the script rather than a hard-coded value. You have: $file = $_POST['file']; $exploded = explode('.', basename($file)); $log_type = $exploded[0]; I'm assuming that $_POST['file'] is the full name shown in the image, ie dhcpd.leases.20220708-030000.tar.gz. Given that, then when you explode it on the dots, you get an array with the different components. You're taking $exploded[0] which is the first part (dhcpd). $exploded[1] would be the second part, the extension you want (leases). Use them both to assemble your command later. $file = $_POST['file']; $exploded = explode('.', basename($file)); $log_type = $exploded[0]; $log_extension = $exploded[1]; //... exec('openssl ts -verify -data /tmp/' . $log_type . '.' . $log_extension . ' -in /tmp/' . $log_type . '.' . $log_extension . '.der -token_in -CAfile /CA/cacert.pem -untrusted /CA/tsacert.pem', $result); Edited July 10, 2022 by kicken 1 Quote Link to comment https://forums.phpfreaks.com/topic/315015-is-there-a-just-like-in-windows/#findComment-1598114 Share on other sites More sharing options...
egzozcu Posted July 11, 2022 Author Share Posted July 11, 2022 it worked! thanks alot kicken. 😀 Quote Link to comment https://forums.phpfreaks.com/topic/315015-is-there-a-just-like-in-windows/#findComment-1598128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.