-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathVultr.class.php
992 lines (826 loc) · 21.7 KB
/
Vultr.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
<?php
/**
* Vultr.com API Client
* @package vultr
* @version 1.0
* @author https://github.com/usefulz
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @see https://github.com/usefulz/vultr-api-client
*/
class Vultr
{
/**
* API Token
* @access private
* @type string $api_token Vultr.com API token
* @see https://my.vultr.com/settings/
*/
private $api_token = '';
/**
* API Endpoint
* @access public
* @type string URL for Vultr.com API
*/
public $endpoint = 'https://api.vultr.com/v1/';
/**
* Current Version
* @access public
* @type string Current version number
*/
public $version = '1.0';
/**
* User Agent
* @access public
* @type string API User-Agent string
*/
public $agent = 'Vultr.com API Client';
/**
* Debug Variable
* @access public
* @type bool Debug API requests
*/
public $debug = FALSE;
/**
* Snapshots Variable
* @access public
* @type mixed Array to store snapshot IDs
*/
public $snapshots = array();
/**
* Plans Variable
* @access public
* @type mixed Array to store VPS Plan IDs
*/
public $plans = array();
/**
* Regions Variable
* @access public
* @type mixed Array to store available regions
*/
public $regions = array();
/**
* Scripts Variable
* @access public
* @type mixed Array to store startup scripts
*/
public $scripts = array();
/**
* Servers Variable
* @access public
* @type mixed Array to store server data
*/
public $servers = array();
/**
* Account Variable
* @access public
* @type mixed Array to store account data
*/
public $account = array();
/**
* Auth Variable
* @access public
* @type mixed Array to store auth data
*/
public $auth = array();
/**
* OS List Variable
* @access public
* @type mixed Array to store OS list
*/
public $oses = array();
/**
* SSH Keys variable
* @access public
* @type mixed Array to store SSH keys
**/
public $ssh_keys = array();
/**
* Response code variable
* @access public
* @type int Holds HTTP response code from API
**/
public $response_code = 0;
/**
* Response code variable
* @access public
* @type bool Determines whether to include the response code, default: false
**/
public $get_code = false;
/**
* Cache ttl for all get requests
* @access public
* $type int TTL in seconds
*/
public $cache_ttl = 3600;
/**
* Cache folder
* @access public
* $type string Cache dir
*/
public $cache_dir = '/tmp/vultr-api-client-cache';
/**
* Constructor function
* @param string $token
* @param int $cache_ttl
* @see https://my.vultr.com/settings/
* @return void
*/
public function __construct($token, $cache_ttl = 3600)
{
$this->api_token = $token;
$this->auth = self::auth_info();
$this->account = self::account_info();
$this->snapshots = self::snapshot_list();
$this->scripts = self::startupscript_list();
$this->regions = self::regions_list();
$this->servers = self::server_list();
$this->plans = self::plans_list();
$this->oses = self::os_list();
$this->ssh_keys = self::sshkeys_list();
}
/**
* Get Account info
* @see https://www.vultr.com/api/#account_info
* @return mixed
*/
public function account_info()
{
return self::get('account/info');
}
/**
* Get Auth info
* @see https://www.vultr.com/api/#auth_info
* @return mixed
*/
public function auth_info()
{
return self::get('auth/info');
}
/**
* Get OS list
* @see https://www.vultr.com/api/#os_os_list
* @return mixed
*/
public function os_list()
{
return self::get('os/list');
}
/**
* List available snapshots
* @see https://www.vultr.com/api/#snapshot_snapshot_list
* @return mixed
*/
public function snapshot_list()
{
return self::get('snapshot/list');
}
/**
* Destroy snapshot
* @see https://www.vultr.com/api/#snapshot_destroy
* @param int $snapshot_id
* @return int HTTP response code
*/
public function snapshot_destroy($snapshot_id)
{
$args = array('SNAPSHOTID' => $snapshot_id);
return self::code('snapshot/destroy', $args);
}
/**
* Create snapshot
* @see https://www.vultr.com/api/#snapshot_create
* @param int $server_id
*/
public function snapshot_create($server_id)
{
$args = array('SUBID' => $server_id);
return self::post('snapshot/create', $args);
}
/**
* List available ISO iamges
* @see https://www.vultr.com/api/#iso_list
* @return mixed Available ISO images
**/
public function iso_list()
{
return self::get('iso/list');
}
/**
* List available plans
* @see https://www.vultr.com/api/#plans_plan_list
* @return mixed
*/
public function plans_list()
{
return self::get('plans/list');
}
/**
* List available regions
* @see https://www.vultr.com/api/#regions_region_list
* @return mixed
*/
public function regions_list()
{
return self::get('regions/list');
}
/**
* Determine region availability
* @see https://www.vultr.com/api/#regions_region_available
* @param int $datacenter_id
* @return mixed VPS plans available at given region
*/
public function regions_availability($datacenter_id)
{
$did = (int) $datacenter_id;
return self::get('regions/availability?DCID=' . $did);
}
/**
* List startup scripts
* @see https://www.vultr.com/api/#startupscript_startupscript_list
* @return mixed List of startup scripts
*/
public function startupscript_list()
{
return self::get('startupscript/list');
}
/**
* Update startup script
* @param int $script_id
* @param string $name
* @param string $script script contents
* @return int HTTP response code
**/
public function startupscript_update($script_id, $name, $script)
{
$args = array(
'SCRIPTID' => $script_id,
'name' => $name,
'script' => $script
);
return self::code('startupscript/update', $args);
}
/**
* Destroy startup script
* @see https://www.vultr.com/api/#startupscript_destroy
* @param int $script_id
* @return int HTTP respnose code
*/
public function startupscript_destroy($script_id)
{
$args = array('SCRIPTID' => $script_id);
return self::code('startupscript/destroy', $args);
}
/**
* Create startup script
* @see https://www.vultr.com/api/#startupscript_create
* @param string $script_name
* @param string $script_contents
* @return int Script ID
*/
public function startupscript_create($script_name, $script_contents)
{
$args = array(
'name' => $script_name,
'script' => $script_contents
);
$script = self::post('startupscript/create', $args);
return (int) $script['SCRIPTID'];
}
/**
* Determine server availability
* @param int $region_id Datacenter ID
* @param int $plan_id VPS Plan ID
* @return bool Server availability
* @throws Exception if VPS Plan ID is not available in specified region
*/
public function server_available($region_id, $plan_id)
{
$availability = self::regions_availability((int) $region_id);
if (!in_array((int) $plan_id, $availability))
{
throw new Exception('Plan ID ' . $plan_id . ' is not available in region ' . $region_id);
return FALSE;
} else {
return TRUE;
}
}
/**
* List servers
* @see https://www.vultr.com/api/#server_server_list
* @return mixed List of servers
*/
public function server_list()
{
return self::get('server/list');
}
/**
* Display server bandwidth
* @see https://www.vultr.com/api/#server_bandwidth
* @param int $server_id
* @return mixed Bandwidth history
*/
public function bandwidth($server_id)
{
$args = array('SUBID' => (int) $server_id);
return self::get('server/bandwidth', $args);
}
/**
* List IPv4 Addresses allocated to specified server
* @see https://www.vultr.com/api/#server_list_ipv4
* @param int $server_id
* @return mixed IPv4 address list
*/
public function list_ipv4($server_id)
{
$args = array('SUBID' => (int) $server_id);
$ipv4 = self::get('server/list_ipv4', $args);
return $ipv4[(int) $server_id];
}
/**
* Create IPv4 address
* @see https://www.vultr.com/api/#server_create_ipv4
* @param int $server_id
* @param string Reboot server after adding IP: <yes|no>, default: yes
* @return int HTTP response code
**/
public function ipv4_create($server_id, $reboot = 'yes')
{
$args = array(
'SUBID' => $server_id,
'reboot' => ($reboot == 'yes' ? 'yes' : 'no')
);
return self::code('server/create_ipv4', $args);
}
/**
* Destroy IPv4 Address
* @see https://www.vultr.com/api/#server_destroy_ipv4
* @param int $server_ID
* @param string $ip IPv4 address
* @return int HTTP response code
**/
public function destroy_ipv4($server_id, $ip4)
{
$args = array(
'SUBID' => $server_id,
'ip' => $ip4
);
return self::code('server/destroy_ipv4', $args);
}
/**
* Set Reverse DNS for IPv4 address
* @see https://www.vultr.com/api/#server_reverse_set_ipv4
* @param string $ip
* @param string $rdns
* @return int HTTP response code
*/
public function reverse_set_ipv4($ip, $rdns)
{
$args = array(
'ip' => $ip,
'entry' => $rdns
);
return self::code('server/reverse_set_ipv4', $args);
}
/**
* Set Default Reverse DNS for IPv4 address
* @see https://www.vultr.com/api/#server_reverse_default_ipv4
* @param string $server_id
* @param string $ip
* @return int HTTP response code
*/
public function reverse_default_ipv4($server_id, $ip)
{
$args = array(
'SUBID' => (int) $server_id,
'ip' => $ip
);
return self::code('server/reverse_default_ipv4', $args);
}
/**
* List IPv6 addresses for specified server
* @see https://www.vultr.com/api/#server_list_ipv6
* @param int $server_id
* @return mixed IPv6 allocation info
*/
public function list_ipv6($server_id)
{
$args = array('SUBID' => (int) $server_id);
$ipv6 = self::get('server/list_ipv6', $args);
return $ipv6[(int) $server_id];
}
/**
* Set Reverse DNS for IPv6 address
* @see https://www.vultr.com/api/#server_reverse_set_ipv6
* @param int $server_id
* @param string $ip
* @param string $rdns
* @return int HTTP response code
*/
public function reverse_set_ipv6($server_id, $ip, $rdns)
{
$args = array(
'SUBID' => (int) $server_id,
'ip' => $ip,
'entry' => $rdns
);
return self::code('server/reverse_set_ipv6', $args);
}
/**
* Delete IPv6 Reverse DNS
* @see https://www.vultr.com/api/#server_reverse_delete_ipv6
* @param int $server_id
* @param string $ip6 IPv6 address
* @return int HTTP response code
**/
public function reverse_delete_ipv6($server_id, $ip6)
{
$args = array(
'SUBID' => $server_id,
'ip' => $ip6
);
return self::code('server/reverse_delete_ipv6', $args);
}
/**
* Reboot server
* @see https://www.vultr.com/api/#server_reboot
* @param int $server_id
* @return int HTTP response code
*/
public function reboot($server_id)
{
$args = array('SUBID' => $server_id);
return self::code('server/reboot', $args);
}
/**
* Halt server
* @see https://www.vultr.com/api/#server_halt
* @param int $server_id
* @return int HTTP response code
*/
public function halt($server_id)
{
$args = array('SUBID' => (int) $server_id);
return self::code('server/halt', $args);
}
/**
* Start server
* @see https://www.vultr.com/api/#server_start
* @param int $server_id
* @return int HTTP response code
*/
public function start($server_id)
{
$args = array('SUBID' => (int) $server_id);
return self::code('server/start', $args);
}
/**
* Destroy server
* @see https://www.vultr.com/api/#server_destroy
* @param int $server_id
* @return int HTTP response code
*/
public function destroy($server_id)
{
$args = array('SUBID' => (int) $server_id);
return self::code('server/destroy', $args);
}
/**
* Reinstall OS on an instance
* @see https://www.vultr.com/api/#server_reinstall
* @param int $server_id
* @return int HTTP response code
*/
public function reinstall($server_id)
{
$args = array('SUBID' => (int) $server_id);
return self::code('server/reinstall', $args);
}
/**
* Set server label
* @see https://www.vultr.com/api/#server_label_set
* @param int $server_id
* @param string $label
* @return int HTTP response code
*/
public function label_set($server_id, $label)
{
$args = array(
'SUBID' => (int) $server_id,
'label' => $label
);
return self::code('server/label_set', $args);
}
/**
* Restore Server Snapshot
* @see https://www.vultr.com/api/#server_restore_snapshot
* @param int $server_id
* @param string $snapshot_id Hexadecimal string with Restore ID
* @return int HTTP response code
*/
public function restore_snapshot($server_id, $snapshot_id)
{
$args = array(
'SUBID' => (int) $server_id,
'SNAPSHOTID' => preg_replace('/[^a-f0-9]/', '', $snapshot_id)
);
return self::code('server/restore_snapshot', $args);
}
/**
* Restore Backup
* @param int $server_id
* @param string $backup_id
* @return int HTTP response code
**/
public function restore_backup($server_id, $backup_id)
{
$args = array(
'SUBID' => $server_id,
'BACKUPID' => $backup_id
);
return self::code('server/restore_backup', $args);
}
/**
* Create Server
* @see https://www.vultr.com/api/#server_create
* @param int $region_id
* @param int $plan_id
* @param int $os_id
* @return FALSE if plan is not available in specified region
* @return int Server ID if creation is successful
*/
public function create($config)
{
$region_id = (int) $config['DCID'];
$plan_id = (int) $config['VPSPLANID'];
$os_id = (int) $config['OSID'];
try
{
$available = self::server_available($region_id, $plan_id);
}
catch (Exception $e)
{
return FALSE;
}
$create = self::post('server/create', $config);
return (int) $create['SUBID'];
}
/**
* SSH Keys List method
* @see https://www.vultr.com/api/#sshkey_sshkey_list
* @return FALSE if no SSH keys are available
* @return mixed with whatever ssh keys get returned
*/
public function sshkeys_list()
{
$try = self::get('sshkey/list');
if (sizeof($try) < 1) return FALSE;
return $try;
}
/**
* SSH Keys Create method
* @see https://www.vultr.com/api/#sshkey_sshkey_create
* @param string $name
* @param string $key [openssh formatted public key]
* @return FALSE if no SSH keys are available
* @return mixed with whatever ssh keys get returned
*/
public function sshkey_create($name, $key)
{
$args = array(
'name' => $name,
'ssh_key' => $key
);
return self::post('sshkey/create', $args);
}
/**
* SSH Keys Update method
* @see https://www.vultr.com/api/#sshkey_sshkey_update
* @param string $key_id
* @param string $name
* @param string $key [openssh formatted public key]
* @return int HTTP response code
*/
public function sshkey_update($key_id, $name, $key)
{
$args = array(
'SSHKEYID' => $key_id,
'name' => $name,
'ssh_key' => $key
);
return self::code('sshkey/update', $args);
}
/**
* SSH Keys Destroy method
* @see https://www.vultr.com/api/#sshkey_sshkey_destroy
* @param string $key_id
* @return int HTTP response code
*/
public function sshkey_destroy($key_id)
{
$args = array('SSHKEYID' => $key_id);
return self::code('sshkey/update', $args);
}
/**
* GET Method
* @param string $method
* @param mixed $args
*/
public function get($method, $args = FALSE)
{
$this->request_type = 'GET';
$this->get_code = false;
return self::query($method, $args);
}
/**
* CODE Method
* @param string $method
* @param mixed $args
* @return mixed if no exceptions thrown
**/
public function code($method, $args = FALSE)
{
$this->request_type = 'POST';
$this->get_code = true;
return self::query($method, $args);
}
/**
* POST Method
* @param string $method
* @param mixed $args
*/
public function post($method, $args)
{
$this->request_type = 'POST';
return self::query($method, $args);
}
/**
* API Query Function
* @param string $method
* @param mixed $args
*/
private function query($method, $args)
{
$url = $this->endpoint . $method . '?api_key=' . $this->api_token;
if ($this->debug) echo $this->request_type . ' ' . $url . PHP_EOL;
$_defaults = array(
CURLOPT_USERAGENT => sprintf('%s v%s (%s)', $this->agent, $this->version, 'https://github.com/usefulz/vultr-api-client'),
CURLOPT_HEADER => 0,
CURLOPT_VERBOSE => 0,
CURLOPT_FOLLOWLOCATION => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => array('Accept: application/json')
);
$cacheable = false;
switch($this->request_type)
{
case 'POST':
$post_data = http_build_query($args);
$_defaults[CURLOPT_URL] = $url;
$_defaults[CURLOPT_POST] = 1;
$_defaults[CURLOPT_POSTFIELDS] = $post_data;
break;
case 'GET':
if ($args !== FALSE)
{
$get_data = http_build_query($args);
$_defaults[CURLOPT_URL] = $url . '&' . $get_data;
} else {
$_defaults[CURLOPT_URL] = $url;
}
$cacheable = true;
$response = $this->serveFromCache($_defaults[CURLOPT_URL]);
if ($response !== false)
{
//echo "FROM CACHE: $url\n";
return $response;
}
break;
default:break;
}
// To avoid rate limit hits
if ($this->readLast() == time())
sleep(1);
$apisess = curl_init();
curl_setopt_array($apisess, $_defaults);
$response = curl_exec($apisess);
$this->writeLast();
/**
* Check to see if there were any API exceptions thrown
* If so, then error out, otherwise, keep going.
*/
try
{
self::isAPIError($apisess, $response);
}
catch(Exception $e)
{
curl_close($apisess);
return $e->getMessage() . PHP_EOL;
}
/**
* Close our session
* Return the decoded JSON response
*/
curl_close($apisess);
$obj = json_decode($response, true);
if ($this->get_code)
{
return (int) $this->response_code;
}
if ($cacheable)
$this->saveToCache($url, $response);
else
$this->purgeCache($url);
return $obj;
}
/**
* API Error Handling
* @param cURL_Handle $response_obj
* @param string $response
* @throws Exception if invalid API location is provided
* @throws Exception if API token is missing from request
* @throws Exception if API method does not exist
* @throws Exception if Internal Server Error occurs
* @throws Exception if the request fails otherwise
*/
public function isAPIError($response_obj, $response)
{
$code = curl_getinfo($response_obj, CURLINFO_HTTP_CODE);
if ($this->get_code)
{
$this->response_code = $code;
return;
}
if ($this->debug) echo $code . PHP_EOL;
switch($code)
{
case 200: break;
case 400: throw new Exception('Invalid API location. Check the URL that you are using'); break;
case 403: throw new Exception('Invalid or missing API key. Check that your API key is present and matches your assigned key'); break;
case 405: throw new Exception('Invalid HTTP method. Check that the method (POST|GET) matches what the documentation indicates'); break;
case 500: throw new Exception('Internal server error. Try again at a later time'); break;
case 412: throw new Exception('Request failed: ' . $response); break;
case 503: throw new Exception('Rate limit hit. API requests are limited to an average of 2/s. Try your request again later.'); break;
default: break;
}
}
protected function serveFromCache($url)
{
// garbage collect 5% of the time
if (mt_rand(0, 19) == 0)
{
$files = glob("$this->cache_dir/*");
$old = time() - ($this->cache_ttl * 2);
foreach($files as $file)
{
if (filemtime($file) < $old)
unlink($old);
}
}
$hash = md5($url);
$group = $this->groupFromUrl($url);
$file = "$this->cache_dir/$group-$hash";
if (file_exists($file) && filemtime($file) > (time() - $this->cache_ttl))
{
$response = file_get_contents($file);
$obj = json_decode($response, true);
return $obj;
}
return false;
}
protected function saveToCache($url, $json)
{
if (!file_exists($this->cache_dir))
mkdir($this->cache_dir);
$hash = md5($url);
$group = $this->groupFromUrl($url);
$file = "$this->cache_dir/$group-$hash";
file_put_contents($file, $json);
}
protected function groupFromUrl($url)
{
$group = 'default';
if (preg_match('@/v1/([^/]+)/@', $url, $match))
return $match[1];
}
protected function purgeCache($url)
{
$group = $this->groupFromUrl($url);
$files = glob("$this->cache_dir/$group-*");
foreach($files as $file)
unlink($file);
}
protected function writeLast()
{
if (!file_exists($this->cache_dir))
mkdir($this->cache_dir);
file_put_contents("$this->cache_dir/last", time());
}
protected function readLast()
{
if (file_exists("$this->cache_dir/last"))
return file_get_contents("$this->cache_dir/last");
}
}
?>