Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. 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);
  2. 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.
  3. I'd suggest spending some time learning how to use the developer tools so you can look at something like this and see how it's being done. In this case, assuming there's not some mis-understanding to what you're referring, it's simply three things: Multiple versions of the background image served with @media rules. This allows for crisp images at various screen sizes. Telling the browser to make the background image fit the element exactly by using background-size: cover Applying the background image to an element that is the size of the browsers view port and positioned below the rest of the page content. See position: fixed, vh/vw units, z-index / stacking contexts.
  4. In addition to the media queries to serve different resolutions of the image, it uses background-size: cover; to make whatever the current image is fit the space.
  5. You are currently looping from 1 to $number_of_pages when displaying your page numbers. What you want to do is loop from $page - 2 to $page + 2, taking care not to go below 0 or above $number_of_pages in the process. Get your range of pages to loop over with some simple math and the help of the min/max functions then loop over that range. $start = max(1, $page - 2); $end = min($number_of_pages, $page + 2); for ($p=$start; $p<=$end; $p++){ //... }
  6. Have backups and a process to restore them. Also verify your backups periodically by attempting to restore them. Make sure that when your scripts fail due to the hacker dropping the table they don't spit out error details for the hacker to then see, just show a generic error. Trying to check and re-create tables is a bit silly as if the table suddenly disappeared then so did all it's data. You can easily re-create the table, but you can't just re-generate the data that was in it, you have to restore that from a backup. The only time I bother with checking if tables/columns exist are for scripts that get run to upgrade a database to a newer schema. Even then, I do this primarily for ease of development as it allows me to simply re-run the script when I make more changes rather than having to undo the last run somehow first. I use SQL Server though so I can't really answer how to accomplish such a task in MySql.
  7. I mean opening your include files in your browser directly. Accessing them directly to see if there are any errors is at best pointless and at worst misleading. It's pointless because any errors that exist would be shown by PHP when it tries to parse the file during the include process. It can be misleading because the file might depend on variables/functions defined in the main file which are not available when accessed directly and cause errors that otherwise wouldn't exist. If you use require_once, then PHP will essentially ignore any attempts to require the same file after the first attempt. This can allow you to simply require the file and not worry about if it was already required elsewhere or not. Ideally you would re-structure the code so that the file is only required a single time, but using require_once would be a quick solution while you work towards something better later.
  8. You should be using require here, not include. The script cannot continue if the file fails to be included so you should just let it fail on the error of not finding the include file rather than a later undefined function error that can get you confused as to what the real problem might be. Opening your include (like db_inc.php) files directly usually isn't going to give you any helpful information, and might just send you down a wrong path. If there's an error with the file it will show up when you include it into the main script you want to run. The session start errors you are seeing suggest you may have PHP configured with session.auto_start=1, either disable the automatic session start or remove your session_start calls. The re-defined function error suggests you are either including your db_inc.php twice. Looks like in marina.php you include header.php and header.php includes db_inc.php. Later on in marina.php you again include db_inc.php which results in the error. You could change your code to use require_once to avoid this problem, or re-structure it so you only include the file once.
  9. If you have working SSL connections then mod_ssl is already enabled and working. What you need to do is configure it to setup those environment variables if you want access to them. It doesn't by default because generally speaking the application doesn't need to know that information so making it available would waste time and resources. To enable them, you use the configuration directive SSLOptions +StdEnvVars. Put this into either your main server configuration file or a .htaccess file in your website.
  10. I don't think that tag is even relevant anymore. Search engines scan the actual content of the page for keywords rather than use whatever list you want to give them.
  11. I recommend that you do your development work with the developer tools open and cache disabled. If after disabling your browser cache you still have issues then there might be some other cache either on the server or a proxy you're using that is causing problems.
  12. Output the values you get separately so you can verify if they are what you expect. <p>End date: <?=$callEvents['end_date']?></p> <p>End timestamp: <?=strtotime($callEvents['end_date'])?></p> <input type="datetime-local" class="form-control datetime" name="end_date" value="<?=date('Y-m-d H:i:s', strtotime($callEvents['end_date']))?>">
  13. You need to download dependencies to analyze them, since what dependencies you get can depend on the environment you're project is installed into. So you need to start with a project that requires packages that you want. Trying to analyze dependencies without a project doesn't really make sense. If for some reason you don't want to make a project but want to know what packages my/b depends on, you can download my/b and run composer show -t within it's directory. Every package is a composer project with it's own composer.json that defines it's details. There's no way at all to get a list of which packages are dependent on my/b since doing so would require scanning every project ever created by every person on the planet.
  14. Since you're using windows server, you could setup and use IIS instead. It's relatively simple to do and works fine. If you really want to use Apache, I'd suggest installing and configuring it manually rather than via WAMP. Go to Apache Lounge to get windows builds of apache and some help with getting it all configured properly.
  15. if ($_POST['clientNameNew']) This will check if the value is a truthy value or not, but the key still needs to exist or you'll get an undefined index notice. You can avoid the notice in various ways. In modern PHP versions, the simplest is to use the null coalescing operator. if ($_POST['clientNameNew'] ?? '') Other ways to check are with isset, empty, or array_key_exists. Alternatively, you could just force them to exist.
  16. As it says in the error, you need to create a composer.json file that contains the details for your project, including what it requires. For example: { "require": { "my/a": "dev-master" } } I suggest you read through that Getting Started section as was advised.
  17. Use the -t option to get a tree view of your packages. $ composer show -t my/a dev-master └──my/b dev-master └──my/c dev-master
  18. When you use the quotes like in quote_id = ':quoteId' You're asking mysql to search for rows where the column quote_id is equal to the value :quoteId, literally. The quotes prevent it from being used as a parameter placeholder and cause it to be a literal value in the query. Removing the quotes allows the :quoteId to be seen as a parameter placeholder and replaced correctly with the bound value when the query is executed.
  19. PHP doesn't assume something afaik. useradd does though. If you don't explicitly specify a home directory, it defaults to appending the username to the base directory, which is /home by default. And I'd probably go with option three if I were setting up a system with a separate user per site. Makes the most sense to me. For my personal setup where I host myself and a few friends I just created separate users for the different people I host then symlink their sites in /var/www in their normal home directory. Each user has their own PHP-FPM pool and all their sites use their pool.
  20. As an example of a simple but fairly effective solution, my contact form just has an input labeled "Secret Code" and instructs the user to type "nospam" in that field. <div> <label for="secretCode">Secret Code:</label> <input type="text" name="secretCode" id="secretCode" placeholder="Type nospam here"> <br>Type "nospam" above. </div> In your script, just check that the user typed the correct value in the field and show an error if not. $errors = []; //Other validation stuff. if ($_POST['secretCode'] != 'nospam'){ $errors[] = 'You did not enter the correct secret code.'; } if ($errors){ echo "Your message could not be sent because some errors were discovered in the information you provided. "; echo "\r\n"; foreach ($errors as $e){ echo "\r\n* {$e}"; } echo "\r\nPlease click back in your browser, correct the errors and try again."; exit; } I would also suggest you look into an emailing library rather than use the mail function directly. The libraries will help with the other security issues mentioned by properly constructing the headers and other data related the email with the inputs you provide. I'm a fan of Swift Mailer (now Symfony Mailer), but there are others you could try as well.
  21. The intent is to essentially create a single instance script, similar to single-instance applications on the desktop. If you try and launch a second instance, it detects the first instance and either doesn't run or does something different. One possible scenario for this is if you have some cron job that runs every minute. If for some reason it takes longer than a minute to run, sometimes it's easier to just prevent the second instance from starting than to write the scripts in such a way that they don't cause problems. @peter844, assuming that is an accurate description of your goal, file_exists is not really the correct way to solve the problem. If you actually ran both scripts at the exact same moment, it's possible for them both to pass the file_exists test before either of them has a chance to actually create the file. A better solution is to use fopen with mode x flag to create the file. In this mode, fopen will fail if the file already exists, or create the file if it does not. Your script can use that to determine if the other instance is already running. Example: $lockFile = __DIR__.'/monkey.tmp'; $fp = @fopen($lockFile, 'x'); if (!$fp){ die('Script already running.'); } register_shutdown_function(function() use ($fp, $lockFile){ fclose($fp); unlink($lockFile); }); An even better solution, is to use flock to obtain an exclusive lock on the file. If the lock cannot be obtained then that means there is a script still running holding the lock. Example: $lockFile = __DIR__.'/monkey.tmp'; $fp = @fopen($lockFile, 'c'); if (!$fp){ die('Unable to access lock file'); } if (!flock($fp, LOCK_EX|LOCK_NB)){ die('Script is already running.'); } register_shutdown_function(function() use ($fp, $lockFile){ flock($fp, LOCK_UN); fclose($fp); unlink($lockFile); });
  22. Make sure that your regex is correctly matching the end of the output. Sounds like your connection is stalling out because it doesn't detect the end of the output and ends up looping until it hits the script timeout. In addition to the regex, you could add another test that $line contains some data. That should break the loop if fgets times out due to no data to read. do { $line = fgets($this->fp); $r .= $line; } while ($line && !preg_match('/\d{1,4} Bridge Interfaces displayed/', $line));
  23. A remote server will not have access to your local file system, so no you cannot have your remote PHP script copy files to your local system.
  24. I started with PHP somewhere around 2000 or 2001, don't remember exactly when. I was still in high school at that time so I don't know if I'd qualify as an "old fart" though.
  25. This is pointless the way you have it: $file=basename($_GET['f']); $file=__DIR__.'/download/'.$file; You're still using $_GET['f'] when you call the function below. You need to change it to use $file. if (!file_exists($file)) { die; } else { //... } While it's fine to have it, you don't need the else block here since the if branch will cause the script to end. The code is cleaner looking without it IMO.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.