Skip to content

Latest commit

 

History

History
262 lines (211 loc) · 7 KB

File metadata and controls

262 lines (211 loc) · 7 KB

Web Hosting Guide

Server Requirements

  • PHP 7.4+ with cURL extension
  • File upload enabled
  • Writable directories: temp_files, logs, output

File Structure

/
├── gemini-api.php           # Main API endpoint
├── simple-client.php        # PowerShell client
├── get-client.php          # Client proxy
├── status.php              # Health check
├── index.php               # Entry point
├── client/
│   └── gemini-bridge.ps1   # Full PowerShell client
├── temp_files/             # Upload directory
├── logs/                   # Log directory
└── .htaccess               # Security rules

Setup

1. Configuration

Edit gemini-api.php:

define('GOOGLE_API_KEY', 'your-api-key-here');

2. Permissions

chmod 755 temp_files logs output
chmod 644 *.php

3. Test Deployment

curl -X POST https://yourdomain.com/gemini-api.php -d "test=true"

Security

.htaccess Protection

# Protect sensitive files
<Files "*.log">
    Require all denied
</Files>

# Enable PowerShell script headers
<Files "*.ps1">
    Header set Content-Type "text/plain"
</Files>

PHP Configuration

  • Set appropriate upload limits
  • Enable error logging
  • Disable dangerous functions if needed

<Files "*.log"> Require all denied

Allow PowerShell scripts to be downloaded

<Files "*.ps1"> Header set Content-Type "text/plain; charset=utf-8" Header set Content-Disposition "inline"


## 🚀 Remote Usage Patterns

### 1. One-Time Setup
```powershell
# Download and run setup script
irm https://yourdomain.com/setup.ps1 | iex -ApiKey "YOUR_API_KEY"

2. Direct Client Execution

# Test connection
irm https://yourdomain.com/client/gemini-client.ps1 | iex -ApiUrl "https://yourdomain.com/api.php" -Test

# Process text directly
irm https://yourdomain.com/client/gemini-client.ps1 | iex -ApiUrl "https://yourdomain.com/api.php" -InputText "Generate a simple HTML page"

# Process a local file
irm https://yourdomain.com/client/gemini-client.ps1 | iex -ApiUrl "https://yourdomain.com/api.php" -InputFile "myfile.txt"

3. Shortened URLs (Recommended)

Use a URL shortener for easier execution:

# Instead of the long URL, use:
irm bit.ly/gemini-setup | iex -ApiKey "YOUR_KEY"
irm bit.ly/gemini-client | iex -ApiUrl "https://yourdomain.com/api.php" -Test

4. Bookmarklet for Web Browsers

Create a browser bookmark with this JavaScript:

javascript:(function(){
    var text = window.getSelection().toString() || prompt('Enter text to process:');
    if(text) {
        var ps1 = 'irm https://yourdomain.com/client/gemini-client.ps1 | iex -ApiUrl "https://yourdomain.com/api.php" -InputText "' + text.replace(/"/g, '\\"') + '"';
        navigator.clipboard.writeText(ps1).then(function() {
            alert('PowerShell command copied to clipboard!');
        });
    }
})();

📱 Cross-Platform Support

Windows PowerShell / PowerShell Core

irm https://yourdomain.com/client/gemini-client.ps1 | iex -ApiUrl "https://yourdomain.com/api.php" -InputText "Hello"

Linux/macOS with PowerShell Core

pwsh -c "irm https://yourdomain.com/client/gemini-client.ps1 | iex -ApiUrl 'https://yourdomain.com/api.php' -InputText 'Hello'"

cURL (Universal)

# Direct API call
curl -X POST https://yourdomain.com/api.php \
  -F "textFile=@myfile.txt"

# With text content
curl -X POST https://yourdomain.com/api.php \
  -H "Content-Type: text/plain" \
  -d "Generate a simple HTML page"

Python (Alternative Client)

import requests

# Test connection
response = requests.post('https://yourdomain.com/api.php', data={'test': 'true'})
print(response.json())

# Send text
response = requests.post('https://yourdomain.com/api.php', data='Your text here')
print(response.json())

🔐 Security Considerations for Web Hosting

Essential Security Measures

  1. HTTPS Only: Always use SSL/TLS encryption
  2. API Key Protection: Never expose your API key in client-side code
  3. Rate Limiting: Implement server-side rate limiting
  4. Input Validation: Validate all uploads and inputs
  5. File Cleanup: Regularly clean temporary files
  6. Access Logs: Monitor for abuse

Recommended Server Headers

Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

📊 Usage Analytics

Simple Usage Tracking

Add to your api.php:

// Log usage (add to existing logging)
$usage_log = [
    'timestamp' => date('c'),
    'ip' => $_SERVER['REMOTE_ADDR'] ?? 'unknown',
    'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'unknown',
    'input_length' => strlen($inputText)
];
file_put_contents('logs/usage.json', json_encode($usage_log) . "\n", FILE_APPEND | LOCK_EX);

🎯 Integration Examples

GitHub Actions

name: Process with Gemini AI
on: [push]
jobs:
  process:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Process files
        shell: pwsh
        run: |
          irm https://yourdomain.com/client/gemini-client.ps1 | iex -ApiUrl "https://yourdomain.com/api.php" -InputFile "README.md"

WordPress Integration

// WordPress shortcode
function gemini_ai_shortcode($atts) {
    $atts = shortcode_atts(['text' => ''], $atts);
    if (empty($atts['text'])) return '';
    
    $response = wp_remote_post('https://yourdomain.com/api.php', [
        'body' => $atts['text']
    ]);
    
    if (is_wp_error($response)) return 'Error processing request';
    
    $body = wp_remote_retrieve_body($response);
    $data = json_decode($body, true);
    
    return $data['candidates'][0]['content']['parts'][0]['text'] ?? 'No response';
}
add_shortcode('gemini_ai', 'gemini_ai_shortcode');

📈 Performance Optimization

Caching Responses

// Add to api.php for response caching
$cache_key = md5($inputText);
$cache_file = "cache/{$cache_key}.json";

if (file_exists($cache_file) && (time() - filemtime($cache_file)) < 3600) {
    // Return cached response
    echo file_get_contents($cache_file);
    exit;
}

// After API call, cache the response
file_put_contents($cache_file, $response);

CDN Integration

  • Host static files (PS1 scripts, setup) on a CDN
  • Use CDN URLs in your documentation
  • Implement proper cache headers

🛠️ Troubleshooting

Common Issues

  1. PowerShell Execution Policy: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
  2. CORS Issues: Add appropriate CORS headers to API responses
  3. File Upload Limits: Check PHP upload limits and server configuration
  4. SSL Certificate Issues: Ensure valid SSL certificates

Debug Mode

Add ?debug=1 to API calls for verbose output during testing.


This deployment guide enables flexible, remote usage of your Gemini AI Integration while maintaining security and performance.